s3-spoolss: Use struct pipes_struct.
[Samba/gbeck.git] / source3 / rpc_server / srv_spoolss_nt.c
blob9ef1ff153e4a0df73aa9bf60dd963e82e659e714
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.
11 * Copyright (C) Andreas Schneider 2010.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
28 up, all the errors returned are DOS errors, not NT status codes. */
30 #include "includes.h"
31 #include "nt_printing.h"
32 #include "srv_spoolss_util.h"
33 #include "../librpc/gen_ndr/srv_spoolss.h"
34 #include "../librpc/gen_ndr/cli_spoolss.h"
35 #include "rpc_client/init_spoolss.h"
36 #include "librpc/gen_ndr/messaging.h"
37 #include "librpc/gen_ndr/ndr_security.h"
38 #include "registry.h"
39 #include "registry/reg_objects.h"
40 #include "include/printing.h"
42 /* macros stolen from s4 spoolss server */
43 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
44 ((info)?ndr_size_##fn(info, level, 0):0)
46 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
47 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
49 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
50 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
52 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
54 #undef DBGC_CLASS
55 #define DBGC_CLASS DBGC_RPC_SRV
57 #ifndef MAX_OPEN_PRINTER_EXS
58 #define MAX_OPEN_PRINTER_EXS 50
59 #endif
61 static Printer_entry *printers_list;
63 typedef struct _counter_printer_0 {
64 struct _counter_printer_0 *next;
65 struct _counter_printer_0 *prev;
67 int snum;
68 uint32_t counter;
69 } counter_printer_0;
71 static counter_printer_0 *counter_list;
73 static struct rpc_pipe_client *notify_cli_pipe; /* print notify back-channel pipe handle*/
74 static uint32_t smb_connections = 0;
77 /* Map generic permissions to printer object specific permissions */
79 const struct standard_mapping printer_std_mapping = {
80 PRINTER_READ,
81 PRINTER_WRITE,
82 PRINTER_EXECUTE,
83 PRINTER_ALL_ACCESS
86 /* Map generic permissions to print server object specific permissions */
88 const struct standard_mapping printserver_std_mapping = {
89 SERVER_READ,
90 SERVER_WRITE,
91 SERVER_EXECUTE,
92 SERVER_ALL_ACCESS
95 /* API table for Xcv Monitor functions */
97 struct xcv_api_table {
98 const char *name;
99 WERROR(*fn) (TALLOC_CTX *mem_ctx, NT_USER_TOKEN *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
102 /********************************************************************
103 * Canonicalize servername.
104 ********************************************************************/
106 static const char *canon_servername(const char *servername)
108 const char *pservername = servername;
109 while (*pservername == '\\') {
110 pservername++;
112 return pservername;
115 /* translate between internal status numbers and NT status numbers */
116 static int nt_printj_status(int v)
118 switch (v) {
119 case LPQ_QUEUED:
120 return 0;
121 case LPQ_PAUSED:
122 return JOB_STATUS_PAUSED;
123 case LPQ_SPOOLING:
124 return JOB_STATUS_SPOOLING;
125 case LPQ_PRINTING:
126 return JOB_STATUS_PRINTING;
127 case LPQ_ERROR:
128 return JOB_STATUS_ERROR;
129 case LPQ_DELETING:
130 return JOB_STATUS_DELETING;
131 case LPQ_OFFLINE:
132 return JOB_STATUS_OFFLINE;
133 case LPQ_PAPEROUT:
134 return JOB_STATUS_PAPEROUT;
135 case LPQ_PRINTED:
136 return JOB_STATUS_PRINTED;
137 case LPQ_DELETED:
138 return JOB_STATUS_DELETED;
139 case LPQ_BLOCKED:
140 return JOB_STATUS_BLOCKED_DEVQ;
141 case LPQ_USER_INTERVENTION:
142 return JOB_STATUS_USER_INTERVENTION;
144 return 0;
147 static int nt_printq_status(int v)
149 switch (v) {
150 case LPQ_PAUSED:
151 return PRINTER_STATUS_PAUSED;
152 case LPQ_QUEUED:
153 case LPQ_SPOOLING:
154 case LPQ_PRINTING:
155 return 0;
157 return 0;
160 /***************************************************************************
161 Disconnect from the client
162 ****************************************************************************/
164 static void srv_spoolss_replycloseprinter(int snum, struct policy_handle *handle)
166 WERROR result;
167 NTSTATUS status;
170 * Tell the specific printing tdb we no longer want messages for this printer
171 * by deregistering our PID.
174 if (!print_notify_deregister_pid(snum))
175 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
177 /* weird if the test succeds !!! */
178 if (smb_connections==0) {
179 DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
180 return;
183 status = rpccli_spoolss_ReplyClosePrinter(notify_cli_pipe, talloc_tos(),
184 handle,
185 &result);
186 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
187 DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
188 win_errstr(result)));
190 /* if it's the last connection, deconnect the IPC$ share */
191 if (smb_connections==1) {
193 cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) );
194 notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */
196 messaging_deregister(smbd_messaging_context(),
197 MSG_PRINTER_NOTIFY2, NULL);
199 /* Tell the connections db we're no longer interested in
200 * printer notify messages. */
202 serverid_register_msg_flags(
203 messaging_server_id(smbd_messaging_context()),
204 false, FLAG_MSG_PRINT_NOTIFY);
207 smb_connections--;
210 /****************************************************************************
211 Functions to free a printer entry datastruct.
212 ****************************************************************************/
214 static int printer_entry_destructor(Printer_entry *Printer)
216 if (Printer->notify.client_connected == true) {
217 int snum = -1;
219 if ( Printer->printer_type == SPLHND_SERVER) {
220 snum = -1;
221 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
222 } else if (Printer->printer_type == SPLHND_PRINTER) {
223 snum = print_queue_snum(Printer->sharename);
224 if (snum != -1)
225 srv_spoolss_replycloseprinter(snum,
226 &Printer->notify.client_hnd);
230 Printer->notify.flags=0;
231 Printer->notify.options=0;
232 Printer->notify.localmachine[0]='\0';
233 Printer->notify.printerlocal=0;
234 TALLOC_FREE(Printer->notify.option);
235 Printer->notify.client_connected = false;
237 TALLOC_FREE(Printer->devmode);
239 /* Remove from the internal list. */
240 DLIST_REMOVE(printers_list, Printer);
241 return 0;
244 /****************************************************************************
245 find printer index by handle
246 ****************************************************************************/
248 static Printer_entry *find_printer_index_by_hnd(struct pipes_struct *p,
249 struct policy_handle *hnd)
251 Printer_entry *find_printer = NULL;
253 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
254 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
255 return NULL;
258 return find_printer;
261 /****************************************************************************
262 Close printer index by handle.
263 ****************************************************************************/
265 static bool close_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
267 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
269 if (!Printer) {
270 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
271 OUR_HANDLE(hnd)));
272 return false;
275 close_policy_hnd(p, hnd);
277 return true;
280 /****************************************************************************
281 Delete a printer given a handle.
282 ****************************************************************************/
284 static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *sharename)
286 char *cmd = lp_deleteprinter_cmd();
287 char *command = NULL;
288 int ret;
289 SE_PRIV se_printop = SE_PRINT_OPERATOR;
290 bool is_print_op = false;
292 /* can't fail if we don't try */
294 if ( !*cmd )
295 return WERR_OK;
297 command = talloc_asprintf(ctx,
298 "%s \"%s\"",
299 cmd, sharename);
300 if (!command) {
301 return WERR_NOMEM;
303 if ( token )
304 is_print_op = user_has_privileges( token, &se_printop );
306 DEBUG(10,("Running [%s]\n", command));
308 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
310 if ( is_print_op )
311 become_root();
313 if ( (ret = smbrun(command, NULL)) == 0 ) {
314 /* Tell everyone we updated smb.conf. */
315 message_send_all(smbd_messaging_context(),
316 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
319 if ( is_print_op )
320 unbecome_root();
322 /********** END SePrintOperatorPrivlege BLOCK **********/
324 DEBUGADD(10,("returned [%d]\n", ret));
326 TALLOC_FREE(command);
328 if (ret != 0)
329 return WERR_BADFID; /* What to return here? */
331 /* go ahead and re-read the services immediately */
332 become_root();
333 reload_services(false);
334 unbecome_root();
336 if ( lp_servicenumber( sharename ) > 0 )
337 return WERR_ACCESS_DENIED;
339 return WERR_OK;
342 /****************************************************************************
343 Delete a printer given a handle.
344 ****************************************************************************/
346 static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
348 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
349 WERROR result;
351 if (!Printer) {
352 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
353 OUR_HANDLE(hnd)));
354 return WERR_BADFID;
358 * It turns out that Windows allows delete printer on a handle
359 * opened by an admin user, then used on a pipe handle created
360 * by an anonymous user..... but they're working on security.... riiight !
361 * JRA.
364 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
365 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
366 return WERR_ACCESS_DENIED;
369 /* this does not need a become root since the access check has been
370 done on the handle already */
372 result = winreg_delete_printer_key(p->mem_ctx, p->server_info,
373 Printer->sharename, "");
374 if (!W_ERROR_IS_OK(result)) {
375 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
376 return WERR_BADFID;
379 return delete_printer_hook(p->mem_ctx, p->server_info->ptok,
380 Printer->sharename );
383 /****************************************************************************
384 Return the snum of a printer corresponding to an handle.
385 ****************************************************************************/
387 static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
388 int *number, struct share_params **params)
390 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
392 if (!Printer) {
393 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
394 OUR_HANDLE(hnd)));
395 return false;
398 switch (Printer->printer_type) {
399 case SPLHND_PRINTER:
400 DEBUG(4,("short name:%s\n", Printer->sharename));
401 *number = print_queue_snum(Printer->sharename);
402 return (*number != -1);
403 case SPLHND_SERVER:
404 return false;
405 default:
406 return false;
410 /****************************************************************************
411 Set printer handle type.
412 Check if it's \\server or \\server\printer
413 ****************************************************************************/
415 static bool set_printer_hnd_printertype(Printer_entry *Printer, const char *handlename)
417 DEBUG(3,("Setting printer type=%s\n", handlename));
419 if ( strlen(handlename) < 3 ) {
420 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", handlename));
421 return false;
424 /* it's a print server */
425 if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
426 DEBUGADD(4,("Printer is a print server\n"));
427 Printer->printer_type = SPLHND_SERVER;
429 /* it's a printer (set_printer_hnd_name() will handle port monitors */
430 else {
431 DEBUGADD(4,("Printer is a printer\n"));
432 Printer->printer_type = SPLHND_PRINTER;
435 return true;
438 /****************************************************************************
439 Set printer handle name.. Accept names like \\server, \\server\printer,
440 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
441 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
442 XcvDataPort() interface.
443 ****************************************************************************/
445 static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
446 struct auth_serversupplied_info *server_info,
447 Printer_entry *Printer,
448 const char *handlename)
450 int snum;
451 int n_services=lp_numservices();
452 char *aprinter;
453 const char *printername;
454 const char *servername;
455 fstring sname;
456 bool found = false;
457 struct spoolss_PrinterInfo2 *info2 = NULL;
458 WERROR result;
460 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
461 (unsigned long)strlen(handlename)));
463 aprinter = CONST_DISCARD(char *, handlename);
464 if ( *handlename == '\\' ) {
465 servername = canon_servername(handlename);
466 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
467 *aprinter = '\0';
468 aprinter++;
470 if (!is_myname_or_ipaddr(servername)) {
471 return false;
474 fstrcpy(Printer->servername, servername);
477 if (Printer->printer_type == SPLHND_SERVER) {
478 return true;
481 if (Printer->printer_type != SPLHND_PRINTER) {
482 return false;
485 DEBUGADD(5, ("searching for [%s]\n", aprinter));
487 /* check for the Port Monitor Interface */
488 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
489 Printer->printer_type = SPLHND_PORTMON_TCP;
490 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
491 found = true;
493 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
494 Printer->printer_type = SPLHND_PORTMON_LOCAL;
495 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
496 found = true;
499 /* Search all sharenames first as this is easier than pulling
500 the printer_info_2 off of disk. Don't use find_service() since
501 that calls out to map_username() */
503 /* do another loop to look for printernames */
504 for (snum = 0; !found && snum < n_services; snum++) {
505 const char *printer = lp_const_servicename(snum);
507 /* no point going on if this is not a printer */
508 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
509 continue;
512 /* ignore [printers] share */
513 if (strequal(printer, "printers")) {
514 continue;
517 fstrcpy(sname, printer);
518 if (strequal(aprinter, printer)) {
519 found = true;
520 break;
523 /* no point looking up the printer object if
524 we aren't allowing printername != sharename */
525 if (lp_force_printername(snum)) {
526 continue;
529 result = winreg_get_printer(mem_ctx,
530 server_info,
531 servername,
532 sname,
533 &info2);
534 if ( !W_ERROR_IS_OK(result) ) {
535 DEBUG(0,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
536 sname, win_errstr(result)));
537 continue;
540 printername = strrchr(info2->printername, '\\');
541 if (printername == NULL) {
542 printername = info2->printername;
543 } else {
544 printername++;
547 if (strequal(printername, aprinter)) {
548 found = true;
549 break;
552 DEBUGADD(10, ("printername: %s\n", printername));
554 TALLOC_FREE(info2);
557 if ( !found ) {
558 DEBUGADD(4,("Printer not found\n"));
559 return false;
562 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
564 fstrcpy(Printer->sharename, sname);
566 return true;
569 /****************************************************************************
570 Find first available printer slot. creates a printer handle for you.
571 ****************************************************************************/
573 static bool open_printer_hnd(struct pipes_struct *p, struct policy_handle *hnd,
574 const char *name, uint32_t access_granted)
576 Printer_entry *new_printer;
578 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
580 new_printer = TALLOC_ZERO_P(NULL, Printer_entry);
581 if (new_printer == NULL) {
582 return false;
584 talloc_set_destructor(new_printer, printer_entry_destructor);
586 if (!create_policy_hnd(p, hnd, new_printer)) {
587 TALLOC_FREE(new_printer);
588 return false;
591 /* Add to the internal list. */
592 DLIST_ADD(printers_list, new_printer);
594 new_printer->notify.option=NULL;
596 if (!set_printer_hnd_printertype(new_printer, name)) {
597 close_printer_handle(p, hnd);
598 return false;
601 if (!set_printer_hnd_name(p->mem_ctx, p->server_info, new_printer, name)) {
602 close_printer_handle(p, hnd);
603 return false;
606 new_printer->access_granted = access_granted;
608 DEBUG(5, ("%d printer handles active\n",
609 (int)num_pipe_handles(p)));
611 return true;
614 /***************************************************************************
615 check to see if the client motify handle is monitoring the notification
616 given by (notify_type, notify_field).
617 **************************************************************************/
619 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
620 uint16_t notify_field)
622 return true;
625 static bool is_monitoring_event(Printer_entry *p, uint16_t notify_type,
626 uint16_t notify_field)
628 struct spoolss_NotifyOption *option = p->notify.option;
629 uint32_t i, j;
632 * Flags should always be zero when the change notify
633 * is registered by the client's spooler. A user Win32 app
634 * might use the flags though instead of the NOTIFY_OPTION_INFO
635 * --jerry
638 if (!option) {
639 return false;
642 if (p->notify.flags)
643 return is_monitoring_event_flags(
644 p->notify.flags, notify_type, notify_field);
646 for (i = 0; i < option->count; i++) {
648 /* Check match for notify_type */
650 if (option->types[i].type != notify_type)
651 continue;
653 /* Check match for field */
655 for (j = 0; j < option->types[i].count; j++) {
656 if (option->types[i].fields[j].field == notify_field) {
657 return true;
662 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
663 p->servername, p->sharename, notify_type, notify_field));
665 return false;
668 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
669 _data->data.integer[0] = _integer; \
670 _data->data.integer[1] = 0;
673 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
674 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
675 if (!_data->data.string.string) {\
676 _data->data.string.size = 0; \
678 _data->data.string.size = strlen_m_term(_p) * 2;
680 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
681 _data->data.devmode.devmode = _devmode;
683 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
684 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
685 if (!_data->data.sd.sd) { \
686 _data->data.sd.sd_size = 0; \
688 _data->data.sd.sd_size = \
689 ndr_size_security_descriptor(_data->data.sd.sd, 0);
691 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
692 struct tm *t,
693 const char **pp,
694 uint32_t *plen)
696 struct spoolss_Time st;
697 uint32_t len = 16;
698 char *p;
700 if (!init_systemtime(&st, t)) {
701 return;
704 p = talloc_array(mem_ctx, char, len);
705 if (!p) {
706 return;
710 * Systemtime must be linearized as a set of UINT16's.
711 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
714 SSVAL(p, 0, st.year);
715 SSVAL(p, 2, st.month);
716 SSVAL(p, 4, st.day_of_week);
717 SSVAL(p, 6, st.day);
718 SSVAL(p, 8, st.hour);
719 SSVAL(p, 10, st.minute);
720 SSVAL(p, 12, st.second);
721 SSVAL(p, 14, st.millisecond);
723 *pp = p;
724 *plen = len;
727 /* Convert a notification message to a struct spoolss_Notify */
729 static void notify_one_value(struct spoolss_notify_msg *msg,
730 struct spoolss_Notify *data,
731 TALLOC_CTX *mem_ctx)
733 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
736 static void notify_string(struct spoolss_notify_msg *msg,
737 struct spoolss_Notify *data,
738 TALLOC_CTX *mem_ctx)
740 /* The length of the message includes the trailing \0 */
742 data->data.string.size = msg->len * 2;
743 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
744 if (!data->data.string.string) {
745 data->data.string.size = 0;
746 return;
750 static void notify_system_time(struct spoolss_notify_msg *msg,
751 struct spoolss_Notify *data,
752 TALLOC_CTX *mem_ctx)
754 data->data.string.string = NULL;
755 data->data.string.size = 0;
757 if (msg->len != sizeof(time_t)) {
758 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
759 msg->len));
760 return;
763 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
764 &data->data.string.string,
765 &data->data.string.size);
768 struct notify2_message_table {
769 const char *name;
770 void (*fn)(struct spoolss_notify_msg *msg,
771 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
774 static struct notify2_message_table printer_notify_table[] = {
775 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
776 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
777 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
778 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
779 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
780 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
781 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
782 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
783 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
784 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
785 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
786 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
787 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
788 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
789 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
790 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
791 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
792 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
793 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
796 static struct notify2_message_table job_notify_table[] = {
797 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
798 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
799 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
800 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
801 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
802 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
803 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
804 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
805 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
806 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
807 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
808 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
809 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
810 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
811 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
812 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
813 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
814 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
815 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
816 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
817 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
818 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
819 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
820 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
824 /***********************************************************************
825 Allocate talloc context for container object
826 **********************************************************************/
828 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
830 if ( !ctr )
831 return;
833 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
835 return;
838 /***********************************************************************
839 release all allocated memory and zero out structure
840 **********************************************************************/
842 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
844 if ( !ctr )
845 return;
847 if ( ctr->ctx )
848 talloc_destroy(ctr->ctx);
850 ZERO_STRUCTP(ctr);
852 return;
855 /***********************************************************************
856 **********************************************************************/
858 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
860 if ( !ctr )
861 return NULL;
863 return ctr->ctx;
866 /***********************************************************************
867 **********************************************************************/
869 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
871 if ( !ctr || !ctr->msg_groups )
872 return NULL;
874 if ( idx >= ctr->num_groups )
875 return NULL;
877 return &ctr->msg_groups[idx];
881 /***********************************************************************
882 How many groups of change messages do we have ?
883 **********************************************************************/
885 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
887 if ( !ctr )
888 return 0;
890 return ctr->num_groups;
893 /***********************************************************************
894 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
895 **********************************************************************/
897 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
899 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
900 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
901 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
902 int i, new_slot;
904 if ( !ctr || !msg )
905 return 0;
907 /* loop over all groups looking for a matching printer name */
909 for ( i=0; i<ctr->num_groups; i++ ) {
910 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
911 break;
914 /* add a new group? */
916 if ( i == ctr->num_groups ) {
917 ctr->num_groups++;
919 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
920 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
921 return 0;
923 ctr->msg_groups = groups;
925 /* clear the new entry and set the printer name */
927 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
928 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
931 /* add the change messages; 'i' is the correct index now regardless */
933 msg_grp = &ctr->msg_groups[i];
935 msg_grp->num_msgs++;
937 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
938 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
939 return 0;
941 msg_grp->msgs = msg_list;
943 new_slot = msg_grp->num_msgs-1;
944 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
946 /* need to allocate own copy of data */
948 if ( msg->len != 0 )
949 msg_grp->msgs[new_slot].notify.data = (char *)
950 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
952 return ctr->num_groups;
955 static void construct_info_data(struct spoolss_Notify *info_data,
956 enum spoolss_NotifyType type,
957 uint16_t field, int id);
959 /***********************************************************************
960 Send a change notication message on all handles which have a call
961 back registered
962 **********************************************************************/
964 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
966 Printer_entry *p;
967 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
968 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
969 SPOOLSS_NOTIFY_MSG *messages;
970 int sending_msg_count;
972 if ( !msg_group ) {
973 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
974 return;
977 messages = msg_group->msgs;
979 if ( !messages ) {
980 DEBUG(5,("send_notify2_changes() called with no messages!\n"));
981 return;
984 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
986 /* loop over all printers */
988 for (p = printers_list; p; p = p->next) {
989 struct spoolss_Notify *notifies;
990 uint32_t count = 0;
991 uint32_t id;
992 int i;
994 /* Is there notification on this handle? */
996 if ( !p->notify.client_connected )
997 continue;
999 DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
1001 /* For this printer? Print servers always receive
1002 notifications. */
1004 if ( ( p->printer_type == SPLHND_PRINTER ) &&
1005 ( !strequal(msg_group->printername, p->sharename) ) )
1006 continue;
1008 DEBUG(10,("Our printer\n"));
1010 /* allocate the max entries possible */
1012 notifies = TALLOC_ZERO_ARRAY(mem_ctx, struct spoolss_Notify, msg_group->num_msgs);
1013 if (!notifies) {
1014 return;
1017 /* build the array of change notifications */
1019 sending_msg_count = 0;
1021 for ( i=0; i<msg_group->num_msgs; i++ ) {
1022 SPOOLSS_NOTIFY_MSG *msg = &messages[i];
1024 /* Are we monitoring this event? */
1026 if (!is_monitoring_event(p, msg->type, msg->field))
1027 continue;
1029 sending_msg_count++;
1032 DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
1033 msg->type, msg->field, p->sharename));
1036 * if the is a printer notification handle and not a job notification
1037 * type, then set the id to 0. Other wise just use what was specified
1038 * in the message.
1040 * When registering change notification on a print server handle
1041 * we always need to send back the id (snum) matching the printer
1042 * for which the change took place. For change notify registered
1043 * on a printer handle, this does not matter and the id should be 0.
1045 * --jerry
1048 if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
1049 id = 0;
1050 else
1051 id = msg->id;
1054 /* Convert unix jobid to smb jobid */
1056 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1057 id = sysjob_to_jobid(msg->id);
1059 if (id == -1) {
1060 DEBUG(3, ("no such unix jobid %d\n", msg->id));
1061 goto done;
1065 construct_info_data( &notifies[count], msg->type, msg->field, id );
1067 switch(msg->type) {
1068 case PRINTER_NOTIFY_TYPE:
1069 if ( printer_notify_table[msg->field].fn )
1070 printer_notify_table[msg->field].fn(msg, &notifies[count], mem_ctx);
1071 break;
1073 case JOB_NOTIFY_TYPE:
1074 if ( job_notify_table[msg->field].fn )
1075 job_notify_table[msg->field].fn(msg, &notifies[count], mem_ctx);
1076 break;
1078 default:
1079 DEBUG(5, ("Unknown notification type %d\n", msg->type));
1080 goto done;
1083 count++;
1086 if ( sending_msg_count ) {
1087 NTSTATUS status;
1088 WERROR werr;
1089 union spoolss_ReplyPrinterInfo info;
1090 struct spoolss_NotifyInfo info0;
1091 uint32_t reply_result;
1093 info0.version = 0x2;
1094 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1095 info0.count = count;
1096 info0.notifies = notifies;
1098 info.info0 = &info0;
1100 status = rpccli_spoolss_RouterReplyPrinterEx(notify_cli_pipe, mem_ctx,
1101 &p->notify.client_hnd,
1102 p->notify.change, /* color */
1103 p->notify.flags,
1104 &reply_result,
1105 0, /* reply_type, must be 0 */
1106 info,
1107 &werr);
1108 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1109 DEBUG(1,("RouterReplyPrinterEx to client: %s failed: %s\n",
1110 notify_cli_pipe->srv_name_slash,
1111 win_errstr(werr)));
1113 switch (reply_result) {
1114 case 0:
1115 break;
1116 case PRINTER_NOTIFY_INFO_DISCARDED:
1117 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1118 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1119 break;
1120 default:
1121 break;
1126 done:
1127 DEBUG(8,("send_notify2_changes: Exit...\n"));
1128 return;
1131 /***********************************************************************
1132 **********************************************************************/
1134 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1137 uint32_t tv_sec, tv_usec;
1138 size_t offset = 0;
1140 /* Unpack message */
1142 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1143 msg->printer);
1145 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1146 &tv_sec, &tv_usec,
1147 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1149 if (msg->len == 0)
1150 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1151 &msg->notify.value[0], &msg->notify.value[1]);
1152 else
1153 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1154 &msg->len, &msg->notify.data);
1156 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1157 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1159 tv->tv_sec = tv_sec;
1160 tv->tv_usec = tv_usec;
1162 if (msg->len == 0)
1163 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1164 msg->notify.value[1]));
1165 else
1166 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1168 return true;
1171 /********************************************************************
1172 Receive a notify2 message list
1173 ********************************************************************/
1175 static void receive_notify2_message_list(struct messaging_context *msg,
1176 void *private_data,
1177 uint32_t msg_type,
1178 struct server_id server_id,
1179 DATA_BLOB *data)
1181 size_t msg_count, i;
1182 char *buf = (char *)data->data;
1183 char *msg_ptr;
1184 size_t msg_len;
1185 SPOOLSS_NOTIFY_MSG notify;
1186 SPOOLSS_NOTIFY_MSG_CTR messages;
1187 int num_groups;
1189 if (data->length < 4) {
1190 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1191 return;
1194 msg_count = IVAL(buf, 0);
1195 msg_ptr = buf + 4;
1197 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1199 if (msg_count == 0) {
1200 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1201 return;
1204 /* initialize the container */
1206 ZERO_STRUCT( messages );
1207 notify_msg_ctr_init( &messages );
1210 * build message groups for each printer identified
1211 * in a change_notify msg. Remember that a PCN message
1212 * includes the handle returned for the srv_spoolss_replyopenprinter()
1213 * call. Therefore messages are grouped according to printer handle.
1216 for ( i=0; i<msg_count; i++ ) {
1217 struct timeval msg_tv;
1219 if (msg_ptr + 4 - buf > data->length) {
1220 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1221 return;
1224 msg_len = IVAL(msg_ptr,0);
1225 msg_ptr += 4;
1227 if (msg_ptr + msg_len - buf > data->length) {
1228 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1229 return;
1232 /* unpack messages */
1234 ZERO_STRUCT( notify );
1235 notify2_unpack_msg( &notify, &msg_tv, msg_ptr, msg_len );
1236 msg_ptr += msg_len;
1238 /* add to correct list in container */
1240 notify_msg_ctr_addmsg( &messages, &notify );
1242 /* free memory that might have been allocated by notify2_unpack_msg() */
1244 if ( notify.len != 0 )
1245 SAFE_FREE( notify.notify.data );
1248 /* process each group of messages */
1250 num_groups = notify_msg_ctr_numgroups( &messages );
1251 for ( i=0; i<num_groups; i++ )
1252 send_notify2_changes( &messages, i );
1255 /* cleanup */
1257 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1258 (uint32_t)msg_count ));
1260 notify_msg_ctr_destroy( &messages );
1262 return;
1265 /********************************************************************
1266 Send a message to ourself about new driver being installed
1267 so we can upgrade the information for each printer bound to this
1268 driver
1269 ********************************************************************/
1271 static bool srv_spoolss_drv_upgrade_printer(const char *drivername)
1273 int len = strlen(drivername);
1275 if (!len)
1276 return false;
1278 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1279 drivername));
1281 messaging_send_buf(smbd_messaging_context(),
1282 messaging_server_id(smbd_messaging_context()),
1283 MSG_PRINTER_DRVUPGRADE,
1284 (uint8_t *)drivername, len+1);
1286 return true;
1289 /**********************************************************************
1290 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1291 over all printers, upgrading ones as necessary
1292 **********************************************************************/
1294 void do_drv_upgrade_printer(struct messaging_context *msg,
1295 void *private_data,
1296 uint32_t msg_type,
1297 struct server_id server_id,
1298 DATA_BLOB *data)
1300 TALLOC_CTX *tmp_ctx;
1301 struct auth_serversupplied_info *server_info = NULL;
1302 struct spoolss_PrinterInfo2 *pinfo2;
1303 NTSTATUS status;
1304 WERROR result;
1305 const char *drivername;
1306 int snum;
1307 int n_services = lp_numservices();
1308 size_t len;
1310 tmp_ctx = talloc_new(NULL);
1311 if (!tmp_ctx) return;
1313 status = make_server_info_system(tmp_ctx, &server_info);
1314 if (!NT_STATUS_IS_OK(status)) {
1315 DEBUG(0, ("do_drv_upgrade_printer: "
1316 "Could not create system server_info\n"));
1317 goto done;
1320 len = MIN(data->length,sizeof(drivername)-1);
1321 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, len);
1322 if (!drivername) {
1323 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1324 goto done;
1327 DEBUG(10, ("do_drv_upgrade_printer: "
1328 "Got message for new driver [%s]\n", drivername));
1330 /* Iterate the printer list */
1332 for (snum = 0; snum < n_services; snum++) {
1333 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1334 continue;
1337 result = winreg_get_printer(tmp_ctx, server_info, NULL,
1338 lp_const_servicename(snum),
1339 &pinfo2);
1341 if (!W_ERROR_IS_OK(result)) {
1342 continue;
1345 if (!pinfo2->drivername) {
1346 continue;
1349 if (strcmp(drivername, pinfo2->drivername) != 0) {
1350 continue;
1353 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1355 /* all we care about currently is the change_id */
1356 result = winreg_printer_update_changeid(tmp_ctx,
1357 server_info,
1358 pinfo2->printername);
1360 if (!W_ERROR_IS_OK(result)) {
1361 DEBUG(3, ("do_drv_upgrade_printer: "
1362 "Failed to update changeid [%s]\n",
1363 win_errstr(result)));
1367 /* all done */
1368 done:
1369 talloc_free(tmp_ctx);
1372 /********************************************************************
1373 Update the cache for all printq's with a registered client
1374 connection
1375 ********************************************************************/
1377 void update_monitored_printq_cache( void )
1379 Printer_entry *printer = printers_list;
1380 int snum;
1382 /* loop through all printers and update the cache where
1383 client_connected == true */
1384 while ( printer )
1386 if ( (printer->printer_type == SPLHND_PRINTER)
1387 && printer->notify.client_connected )
1389 snum = print_queue_snum(printer->sharename);
1390 print_queue_status( snum, NULL, NULL );
1393 printer = printer->next;
1396 return;
1399 /****************************************************************
1400 _spoolss_OpenPrinter
1401 ****************************************************************/
1403 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1404 struct spoolss_OpenPrinter *r)
1406 struct spoolss_OpenPrinterEx e;
1407 WERROR werr;
1409 ZERO_STRUCT(e.in.userlevel);
1411 e.in.printername = r->in.printername;
1412 e.in.datatype = r->in.datatype;
1413 e.in.devmode_ctr = r->in.devmode_ctr;
1414 e.in.access_mask = r->in.access_mask;
1415 e.in.level = 0;
1417 e.out.handle = r->out.handle;
1419 werr = _spoolss_OpenPrinterEx(p, &e);
1421 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1422 /* OpenPrinterEx returns this for a bad
1423 * printer name. We must return WERR_INVALID_PRINTER_NAME
1424 * instead.
1426 werr = WERR_INVALID_PRINTER_NAME;
1429 return werr;
1432 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1433 struct spoolss_DeviceMode *orig,
1434 struct spoolss_DeviceMode **dest)
1436 struct spoolss_DeviceMode *dm;
1438 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1439 if (!dm) {
1440 return WERR_NOMEM;
1443 /* copy all values, then duplicate strings and structs */
1444 *dm = *orig;
1446 dm->devicename = talloc_strdup(dm, orig->devicename);
1447 if (!dm->devicename) {
1448 return WERR_NOMEM;
1450 dm->formname = talloc_strdup(dm, orig->formname);
1451 if (!dm->formname) {
1452 return WERR_NOMEM;
1454 if (orig->driverextra_data.data) {
1455 dm->driverextra_data.data =
1456 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1457 orig->driverextra_data.length);
1458 if (!dm->driverextra_data.data) {
1459 return WERR_NOMEM;
1463 *dest = dm;
1464 return WERR_OK;
1467 /****************************************************************
1468 _spoolss_OpenPrinterEx
1469 ****************************************************************/
1471 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1472 struct spoolss_OpenPrinterEx *r)
1474 int snum;
1475 Printer_entry *Printer=NULL;
1477 if (!r->in.printername) {
1478 return WERR_INVALID_PARAM;
1481 /* some sanity check because you can open a printer or a print server */
1482 /* aka: \\server\printer or \\server */
1484 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1486 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1487 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1488 " for printer %s\n", r->in.printername));
1489 ZERO_STRUCTP(r->out.handle);
1490 return WERR_INVALID_PARAM;
1493 Printer = find_printer_index_by_hnd(p, r->out.handle);
1494 if ( !Printer ) {
1495 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1496 "handle we created for printer %s\n", r->in.printername));
1497 close_printer_handle(p, r->out.handle);
1498 ZERO_STRUCTP(r->out.handle);
1499 return WERR_INVALID_PARAM;
1503 * First case: the user is opening the print server:
1505 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1506 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1508 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1509 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1510 * or if the user is listed in the smb.conf printer admin parameter.
1512 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1513 * client view printer folder, but does not show the MSAPW.
1515 * Note: this test needs code to check access rights here too. Jeremy
1516 * could you look at this?
1518 * Second case: the user is opening a printer:
1519 * NT doesn't let us connect to a printer if the connecting user
1520 * doesn't have print permission.
1522 * Third case: user is opening a Port Monitor
1523 * access checks same as opening a handle to the print server.
1526 switch (Printer->printer_type )
1528 case SPLHND_SERVER:
1529 case SPLHND_PORTMON_TCP:
1530 case SPLHND_PORTMON_LOCAL:
1531 /* Printserver handles use global struct... */
1533 snum = -1;
1535 /* Map standard access rights to object specific access rights */
1537 se_map_standard(&r->in.access_mask,
1538 &printserver_std_mapping);
1540 /* Deny any object specific bits that don't apply to print
1541 servers (i.e printer and job specific bits) */
1543 r->in.access_mask &= SEC_MASK_SPECIFIC;
1545 if (r->in.access_mask &
1546 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1547 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1548 close_printer_handle(p, r->out.handle);
1549 ZERO_STRUCTP(r->out.handle);
1550 return WERR_ACCESS_DENIED;
1553 /* Allow admin access */
1555 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1557 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1559 if (!lp_ms_add_printer_wizard()) {
1560 close_printer_handle(p, r->out.handle);
1561 ZERO_STRUCTP(r->out.handle);
1562 return WERR_ACCESS_DENIED;
1565 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1566 and not a printer admin, then fail */
1568 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1569 !user_has_privileges(p->server_info->ptok,
1570 &se_printop ) &&
1571 !token_contains_name_in_list(
1572 uidtoname(p->server_info->utok.uid),
1573 p->server_info->info3->base.domain.string,
1574 NULL,
1575 p->server_info->ptok,
1576 lp_printer_admin(snum))) {
1577 close_printer_handle(p, r->out.handle);
1578 ZERO_STRUCTP(r->out.handle);
1579 return WERR_ACCESS_DENIED;
1582 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1584 else
1586 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1589 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1590 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1592 /* We fall through to return WERR_OK */
1593 break;
1595 case SPLHND_PRINTER:
1596 /* NT doesn't let us connect to a printer if the connecting user
1597 doesn't have print permission. */
1599 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1600 close_printer_handle(p, r->out.handle);
1601 ZERO_STRUCTP(r->out.handle);
1602 return WERR_BADFID;
1605 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1606 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1609 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1611 /* map an empty access mask to the minimum access mask */
1612 if (r->in.access_mask == 0x0)
1613 r->in.access_mask = PRINTER_ACCESS_USE;
1616 * If we are not serving the printer driver for this printer,
1617 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1618 * will keep NT clients happy --jerry
1621 if (lp_use_client_driver(snum)
1622 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1624 r->in.access_mask = PRINTER_ACCESS_USE;
1627 /* check smb.conf parameters and the the sec_desc */
1629 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1630 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1631 ZERO_STRUCTP(r->out.handle);
1632 return WERR_ACCESS_DENIED;
1635 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1636 p->server_info->ptok, snum) ||
1637 !print_access_check(p->server_info, snum,
1638 r->in.access_mask)) {
1639 DEBUG(3, ("access DENIED for printer open\n"));
1640 close_printer_handle(p, r->out.handle);
1641 ZERO_STRUCTP(r->out.handle);
1642 return WERR_ACCESS_DENIED;
1645 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1646 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1647 close_printer_handle(p, r->out.handle);
1648 ZERO_STRUCTP(r->out.handle);
1649 return WERR_ACCESS_DENIED;
1652 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1653 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1654 else
1655 r->in.access_mask = PRINTER_ACCESS_USE;
1657 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1658 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1660 winreg_create_printer(p->mem_ctx,
1661 p->server_info,
1662 Printer->servername,
1663 lp_const_servicename(snum));
1665 break;
1667 default:
1668 /* sanity check to prevent programmer error */
1669 ZERO_STRUCTP(r->out.handle);
1670 return WERR_BADFID;
1673 Printer->access_granted = r->in.access_mask;
1676 * If the client sent a devmode in the OpenPrinter() call, then
1677 * save it here in case we get a job submission on this handle
1680 if ((Printer->printer_type != SPLHND_SERVER) &&
1681 r->in.devmode_ctr.devmode) {
1682 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1683 &Printer->devmode);
1686 #if 0 /* JERRY -- I'm doubtful this is really effective */
1687 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1688 optimization in Windows 2000 clients --jerry */
1690 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1691 && (RA_WIN2K == get_remote_arch()) )
1693 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1694 sys_usleep( 500000 );
1696 #endif
1698 return WERR_OK;
1701 /****************************************************************
1702 _spoolss_ClosePrinter
1703 ****************************************************************/
1705 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1706 struct spoolss_ClosePrinter *r)
1708 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1710 if (Printer && Printer->document_started) {
1711 struct spoolss_EndDocPrinter e;
1713 e.in.handle = r->in.handle;
1715 _spoolss_EndDocPrinter(p, &e);
1718 if (!close_printer_handle(p, r->in.handle))
1719 return WERR_BADFID;
1721 /* clear the returned printer handle. Observed behavior
1722 from Win2k server. Don't think this really matters.
1723 Previous code just copied the value of the closed
1724 handle. --jerry */
1726 ZERO_STRUCTP(r->out.handle);
1728 return WERR_OK;
1731 /****************************************************************
1732 _spoolss_DeletePrinter
1733 ****************************************************************/
1735 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1736 struct spoolss_DeletePrinter *r)
1738 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1739 WERROR result;
1740 int snum;
1742 if (Printer && Printer->document_started) {
1743 struct spoolss_EndDocPrinter e;
1745 e.in.handle = r->in.handle;
1747 _spoolss_EndDocPrinter(p, &e);
1750 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
1751 winreg_delete_printer_key(p->mem_ctx,
1752 p->server_info,
1753 lp_const_servicename(snum),
1754 "");
1757 result = delete_printer_handle(p, r->in.handle);
1759 return result;
1762 /*******************************************************************
1763 * static function to lookup the version id corresponding to an
1764 * long architecture string
1765 ******************************************************************/
1767 static const struct print_architecture_table_node archi_table[]= {
1769 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1770 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1771 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1772 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
1773 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
1774 {"Windows IA64", SPL_ARCH_IA64, 3 },
1775 {"Windows x64", SPL_ARCH_X64, 3 },
1776 {NULL, "", -1 }
1779 static int get_version_id(const char *arch)
1781 int i;
1783 for (i=0; archi_table[i].long_archi != NULL; i++)
1785 if (strcmp(arch, archi_table[i].long_archi) == 0)
1786 return (archi_table[i].version);
1789 return -1;
1792 /****************************************************************
1793 _spoolss_DeletePrinterDriver
1794 ****************************************************************/
1796 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
1797 struct spoolss_DeletePrinterDriver *r)
1800 struct spoolss_DriverInfo8 *info = NULL;
1801 struct spoolss_DriverInfo8 *info_win2k = NULL;
1802 int version;
1803 WERROR status;
1804 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1806 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1807 and not a printer admin, then fail */
1809 if ( (p->server_info->utok.uid != sec_initial_uid())
1810 && !user_has_privileges(p->server_info->ptok, &se_printop )
1811 && !token_contains_name_in_list(
1812 uidtoname(p->server_info->utok.uid),
1813 p->server_info->info3->base.domain.string,
1814 NULL,
1815 p->server_info->ptok,
1816 lp_printer_admin(-1)) )
1818 return WERR_ACCESS_DENIED;
1821 /* check that we have a valid driver name first */
1823 if ((version = get_version_id(r->in.architecture)) == -1)
1824 return WERR_INVALID_ENVIRONMENT;
1826 status = winreg_get_driver(p->mem_ctx, p->server_info,
1827 r->in.architecture, r->in.driver,
1828 version, &info);
1829 if (!W_ERROR_IS_OK(status)) {
1830 /* try for Win2k driver if "Windows NT x86" */
1832 if ( version == 2 ) {
1833 version = 3;
1835 status = winreg_get_driver(p->mem_ctx, p->server_info,
1836 r->in.architecture,
1837 r->in.driver,
1838 version, &info);
1839 if (!W_ERROR_IS_OK(status)) {
1840 status = WERR_UNKNOWN_PRINTER_DRIVER;
1841 goto done;
1844 /* otherwise it was a failure */
1845 else {
1846 status = WERR_UNKNOWN_PRINTER_DRIVER;
1847 goto done;
1852 if (printer_driver_in_use(p->mem_ctx, p->server_info, info)) {
1853 status = WERR_PRINTER_DRIVER_IN_USE;
1854 goto done;
1857 if (version == 2) {
1858 status = winreg_get_driver(p->mem_ctx, p->server_info,
1859 r->in.architecture,
1860 r->in.driver, 3, &info_win2k);
1861 if (W_ERROR_IS_OK(status)) {
1862 /* if we get to here, we now have 2 driver info structures to remove */
1863 /* remove the Win2k driver first*/
1865 status = winreg_del_driver(p->mem_ctx,
1866 p->server_info,
1867 info_win2k, 3);
1868 talloc_free(info_win2k);
1870 /* this should not have failed---if it did, report to client */
1871 if (!W_ERROR_IS_OK(status)) {
1872 goto done;
1877 status = winreg_del_driver(p->mem_ctx, p->server_info, info, version);
1879 done:
1880 talloc_free(info);
1882 return status;
1885 /****************************************************************
1886 _spoolss_DeletePrinterDriverEx
1887 ****************************************************************/
1889 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
1890 struct spoolss_DeletePrinterDriverEx *r)
1892 struct spoolss_DriverInfo8 *info = NULL;
1893 struct spoolss_DriverInfo8 *info_win2k = NULL;
1894 int version;
1895 bool delete_files;
1896 WERROR status;
1897 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1899 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1900 and not a printer admin, then fail */
1902 if ( (p->server_info->utok.uid != sec_initial_uid())
1903 && !user_has_privileges(p->server_info->ptok, &se_printop )
1904 && !token_contains_name_in_list(
1905 uidtoname(p->server_info->utok.uid),
1906 p->server_info->info3->base.domain.string,
1907 NULL,
1908 p->server_info->ptok, lp_printer_admin(-1)) )
1910 return WERR_ACCESS_DENIED;
1913 /* check that we have a valid driver name first */
1914 if ((version = get_version_id(r->in.architecture)) == -1) {
1915 /* this is what NT returns */
1916 return WERR_INVALID_ENVIRONMENT;
1919 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
1920 version = r->in.version;
1922 status = winreg_get_driver(p->mem_ctx, p->server_info,
1923 r->in.architecture, r->in.driver,
1924 version, &info);
1925 if (!W_ERROR_IS_OK(status)) {
1926 status = WERR_UNKNOWN_PRINTER_DRIVER;
1929 * if the client asked for a specific version,
1930 * or this is something other than Windows NT x86,
1931 * then we've failed
1934 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
1935 goto done;
1937 /* try for Win2k driver if "Windows NT x86" */
1939 version = 3;
1940 status = winreg_get_driver(info, p->server_info,
1941 r->in.architecture,
1942 r->in.driver,
1943 version, &info);
1944 if (!W_ERROR_IS_OK(status)) {
1945 status = WERR_UNKNOWN_PRINTER_DRIVER;
1946 goto done;
1950 if (printer_driver_in_use(info, p->server_info, info)) {
1951 status = WERR_PRINTER_DRIVER_IN_USE;
1952 goto done;
1956 * we have a couple of cases to consider.
1957 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
1958 * then the delete should fail if **any** files overlap with
1959 * other drivers
1960 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
1961 * non-overlapping files
1962 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
1963 * is set, the do not delete any files
1964 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
1967 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
1969 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
1971 if (delete_files &&
1972 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
1973 printer_driver_files_in_use(info, p->server_info, info)) {
1974 /* no idea of the correct error here */
1975 status = WERR_ACCESS_DENIED;
1976 goto done;
1980 /* also check for W32X86/3 if necessary; maybe we already have? */
1982 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
1983 status = winreg_get_driver(info, p->server_info,
1984 r->in.architecture,
1985 r->in.driver, 3, &info_win2k);
1986 if (W_ERROR_IS_OK(status)) {
1988 if (delete_files &&
1989 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
1990 printer_driver_files_in_use(info, p->server_info,
1991 info_win2k)) {
1992 /* no idea of the correct error here */
1993 talloc_free(info_win2k);
1994 status = WERR_ACCESS_DENIED;
1995 goto done;
1998 /* if we get to here, we now have 2 driver info structures to remove */
1999 /* remove the Win2k driver first*/
2001 status = winreg_del_driver(info, p->server_info,
2002 info_win2k, 3);
2004 /* this should not have failed---if it did, report to client */
2006 if (!W_ERROR_IS_OK(status)) {
2007 goto done;
2011 * now delete any associated files if delete_files is
2012 * true. Even if this part failes, we return succes
2013 * because the driver doesn not exist any more
2015 if (delete_files) {
2016 delete_driver_files(p->server_info,
2017 info_win2k);
2022 status = winreg_del_driver(info, p->server_info, info, version);
2023 if (!W_ERROR_IS_OK(status)) {
2024 goto done;
2028 * now delete any associated files if delete_files is
2029 * true. Even if this part failes, we return succes
2030 * because the driver doesn not exist any more
2032 if (delete_files) {
2033 delete_driver_files(p->server_info, info);
2036 done:
2037 talloc_free(info);
2038 return status;
2042 /********************************************************************
2043 GetPrinterData on a printer server Handle.
2044 ********************************************************************/
2046 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2047 const char *value,
2048 enum winreg_Type *type,
2049 union spoolss_PrinterData *data)
2051 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2053 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2054 *type = REG_DWORD;
2055 data->value = 0x00;
2056 return WERR_OK;
2059 if (!StrCaseCmp(value, "BeepEnabled")) {
2060 *type = REG_DWORD;
2061 data->value = 0x00;
2062 return WERR_OK;
2065 if (!StrCaseCmp(value, "EventLog")) {
2066 *type = REG_DWORD;
2067 /* formally was 0x1b */
2068 data->value = 0x00;
2069 return WERR_OK;
2072 if (!StrCaseCmp(value, "NetPopup")) {
2073 *type = REG_DWORD;
2074 data->value = 0x00;
2075 return WERR_OK;
2078 if (!StrCaseCmp(value, "MajorVersion")) {
2079 *type = REG_DWORD;
2081 /* Windows NT 4.0 seems to not allow uploading of drivers
2082 to a server that reports 0x3 as the MajorVersion.
2083 need to investigate more how Win2k gets around this .
2084 -- jerry */
2086 if (RA_WINNT == get_remote_arch()) {
2087 data->value = 0x02;
2088 } else {
2089 data->value = 0x03;
2092 return WERR_OK;
2095 if (!StrCaseCmp(value, "MinorVersion")) {
2096 *type = REG_DWORD;
2097 data->value = 0x00;
2098 return WERR_OK;
2101 /* REG_BINARY
2102 * uint32_t size = 0x114
2103 * uint32_t major = 5
2104 * uint32_t minor = [0|1]
2105 * uint32_t build = [2195|2600]
2106 * extra unicode string = e.g. "Service Pack 3"
2108 if (!StrCaseCmp(value, "OSVersion")) {
2109 DATA_BLOB blob;
2110 enum ndr_err_code ndr_err;
2111 struct spoolss_OSVersion os;
2113 os.major = 5; /* Windows 2000 == 5.0 */
2114 os.minor = 0;
2115 os.build = 2195; /* build */
2116 os.extra_string = ""; /* leave extra string empty */
2118 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2119 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2120 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2121 return WERR_GENERAL_FAILURE;
2124 *type = REG_BINARY;
2125 data->binary = blob;
2127 return WERR_OK;
2131 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2132 *type = REG_SZ;
2134 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2135 W_ERROR_HAVE_NO_MEMORY(data->string);
2137 return WERR_OK;
2140 if (!StrCaseCmp(value, "Architecture")) {
2141 *type = REG_SZ;
2142 data->string = talloc_strdup(mem_ctx,
2143 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2144 W_ERROR_HAVE_NO_MEMORY(data->string);
2146 return WERR_OK;
2149 if (!StrCaseCmp(value, "DsPresent")) {
2150 *type = REG_DWORD;
2152 /* only show the publish check box if we are a
2153 member of a AD domain */
2155 if (lp_security() == SEC_ADS) {
2156 data->value = 0x01;
2157 } else {
2158 data->value = 0x00;
2160 return WERR_OK;
2163 if (!StrCaseCmp(value, "DNSMachineName")) {
2164 const char *hostname = get_mydnsfullname();
2166 if (!hostname) {
2167 return WERR_BADFILE;
2170 *type = REG_SZ;
2171 data->string = talloc_strdup(mem_ctx, hostname);
2172 W_ERROR_HAVE_NO_MEMORY(data->string);
2174 return WERR_OK;
2177 *type = REG_NONE;
2179 return WERR_INVALID_PARAM;
2182 /****************************************************************
2183 _spoolss_GetPrinterData
2184 ****************************************************************/
2186 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2187 struct spoolss_GetPrinterData *r)
2189 struct spoolss_GetPrinterDataEx r2;
2191 r2.in.handle = r->in.handle;
2192 r2.in.key_name = "PrinterDriverData";
2193 r2.in.value_name = r->in.value_name;
2194 r2.in.offered = r->in.offered;
2195 r2.out.type = r->out.type;
2196 r2.out.data = r->out.data;
2197 r2.out.needed = r->out.needed;
2199 return _spoolss_GetPrinterDataEx(p, &r2);
2202 /*********************************************************
2203 Connect to the client machine.
2204 **********************************************************/
2206 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2207 struct sockaddr_storage *client_ss, const char *remote_machine)
2209 NTSTATUS ret;
2210 struct cli_state *the_cli;
2211 struct sockaddr_storage rm_addr;
2212 char addr[INET6_ADDRSTRLEN];
2214 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2215 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2216 remote_machine));
2217 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2218 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2219 return false;
2221 print_sockaddr(addr, sizeof(addr), &rm_addr);
2222 } else {
2223 rm_addr = *client_ss;
2224 print_sockaddr(addr, sizeof(addr), &rm_addr);
2225 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2226 addr));
2229 if (ismyaddr((struct sockaddr *)&rm_addr)) {
2230 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2231 addr));
2232 return false;
2235 /* setup the connection */
2236 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2237 &rm_addr, 0, "IPC$", "IPC",
2238 "", /* username */
2239 "", /* domain */
2240 "", /* password */
2241 0, lp_client_signing(), NULL );
2243 if ( !NT_STATUS_IS_OK( ret ) ) {
2244 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2245 remote_machine ));
2246 return false;
2249 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2250 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2251 cli_shutdown(the_cli);
2252 return false;
2256 * Ok - we have an anonymous connection to the IPC$ share.
2257 * Now start the NT Domain stuff :-).
2260 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2261 if (!NT_STATUS_IS_OK(ret)) {
2262 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2263 remote_machine, nt_errstr(ret)));
2264 cli_shutdown(the_cli);
2265 return false;
2268 return true;
2271 /***************************************************************************
2272 Connect to the client.
2273 ****************************************************************************/
2275 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2276 uint32_t localprinter, uint32_t type,
2277 struct policy_handle *handle,
2278 struct sockaddr_storage *client_ss)
2280 WERROR result;
2281 NTSTATUS status;
2284 * If it's the first connection, contact the client
2285 * and connect to the IPC$ share anonymously
2287 if (smb_connections==0) {
2288 fstring unix_printer;
2290 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2292 if ( !spoolss_connect_to_client( &notify_cli_pipe, client_ss, unix_printer ))
2293 return false;
2295 messaging_register(smbd_messaging_context(), NULL,
2296 MSG_PRINTER_NOTIFY2,
2297 receive_notify2_message_list);
2298 /* Tell the connections db we're now interested in printer
2299 * notify messages. */
2300 serverid_register_msg_flags(
2301 messaging_server_id(smbd_messaging_context()),
2302 true, FLAG_MSG_PRINT_NOTIFY);
2306 * Tell the specific printing tdb we want messages for this printer
2307 * by registering our PID.
2310 if (!print_notify_register_pid(snum))
2311 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2313 smb_connections++;
2315 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2316 printer,
2317 localprinter,
2318 type,
2320 NULL,
2321 handle,
2322 &result);
2323 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2324 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2325 win_errstr(result)));
2327 return (W_ERROR_IS_OK(result));
2330 /****************************************************************
2331 ****************************************************************/
2333 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2334 const struct spoolss_NotifyOption *r)
2336 struct spoolss_NotifyOption *option;
2337 uint32_t i,k;
2339 if (!r) {
2340 return NULL;
2343 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2344 if (!option) {
2345 return NULL;
2348 *option = *r;
2350 if (!option->count) {
2351 return option;
2354 option->types = talloc_zero_array(option,
2355 struct spoolss_NotifyOptionType, option->count);
2356 if (!option->types) {
2357 talloc_free(option);
2358 return NULL;
2361 for (i=0; i < option->count; i++) {
2362 option->types[i] = r->types[i];
2364 if (option->types[i].count) {
2365 option->types[i].fields = talloc_zero_array(option,
2366 union spoolss_Field, option->types[i].count);
2367 if (!option->types[i].fields) {
2368 talloc_free(option);
2369 return NULL;
2371 for (k=0; k<option->types[i].count; k++) {
2372 option->types[i].fields[k] =
2373 r->types[i].fields[k];
2378 return option;
2381 /****************************************************************
2382 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2384 * before replying OK: status=0 a rpc call is made to the workstation
2385 * asking ReplyOpenPrinter
2387 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2388 * called from api_spoolss_rffpcnex
2389 ****************************************************************/
2391 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2392 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2394 int snum = -1;
2395 struct spoolss_NotifyOption *option = r->in.notify_options;
2396 struct sockaddr_storage client_ss;
2398 /* store the notify value in the printer struct */
2400 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2402 if (!Printer) {
2403 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2404 "Invalid handle (%s:%u:%u).\n",
2405 OUR_HANDLE(r->in.handle)));
2406 return WERR_BADFID;
2409 Printer->notify.flags = r->in.flags;
2410 Printer->notify.options = r->in.options;
2411 Printer->notify.printerlocal = r->in.printer_local;
2413 TALLOC_FREE(Printer->notify.option);
2414 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2416 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2418 /* Connect to the client machine and send a ReplyOpenPrinter */
2420 if ( Printer->printer_type == SPLHND_SERVER)
2421 snum = -1;
2422 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2423 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2424 return WERR_BADFID;
2426 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2427 "client_address is %s\n", p->client_address));
2429 if (!interpret_string_addr(&client_ss, p->client_address,
2430 AI_NUMERICHOST)) {
2431 return WERR_SERVER_UNAVAILABLE;
2434 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2435 Printer->notify.printerlocal, 1,
2436 &Printer->notify.client_hnd, &client_ss))
2437 return WERR_SERVER_UNAVAILABLE;
2439 Printer->notify.client_connected = true;
2441 return WERR_OK;
2444 /*******************************************************************
2445 * fill a notify_info_data with the servername
2446 ********************************************************************/
2448 static void spoolss_notify_server_name(int snum,
2449 struct spoolss_Notify *data,
2450 print_queue_struct *queue,
2451 struct spoolss_PrinterInfo2 *pinfo2,
2452 TALLOC_CTX *mem_ctx)
2454 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2457 /*******************************************************************
2458 * fill a notify_info_data with the printername (not including the servername).
2459 ********************************************************************/
2461 static void spoolss_notify_printer_name(int snum,
2462 struct spoolss_Notify *data,
2463 print_queue_struct *queue,
2464 struct spoolss_PrinterInfo2 *pinfo2,
2465 TALLOC_CTX *mem_ctx)
2467 /* the notify name should not contain the \\server\ part */
2468 const char *p = strrchr(pinfo2->printername, '\\');
2470 if (!p) {
2471 p = pinfo2->printername;
2472 } else {
2473 p++;
2476 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2479 /*******************************************************************
2480 * fill a notify_info_data with the servicename
2481 ********************************************************************/
2483 static void spoolss_notify_share_name(int snum,
2484 struct spoolss_Notify *data,
2485 print_queue_struct *queue,
2486 struct spoolss_PrinterInfo2 *pinfo2,
2487 TALLOC_CTX *mem_ctx)
2489 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2492 /*******************************************************************
2493 * fill a notify_info_data with the port name
2494 ********************************************************************/
2496 static void spoolss_notify_port_name(int snum,
2497 struct spoolss_Notify *data,
2498 print_queue_struct *queue,
2499 struct spoolss_PrinterInfo2 *pinfo2,
2500 TALLOC_CTX *mem_ctx)
2502 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2505 /*******************************************************************
2506 * fill a notify_info_data with the printername
2507 * but it doesn't exist, have to see what to do
2508 ********************************************************************/
2510 static void spoolss_notify_driver_name(int snum,
2511 struct spoolss_Notify *data,
2512 print_queue_struct *queue,
2513 struct spoolss_PrinterInfo2 *pinfo2,
2514 TALLOC_CTX *mem_ctx)
2516 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2519 /*******************************************************************
2520 * fill a notify_info_data with the comment
2521 ********************************************************************/
2523 static void spoolss_notify_comment(int snum,
2524 struct spoolss_Notify *data,
2525 print_queue_struct *queue,
2526 struct spoolss_PrinterInfo2 *pinfo2,
2527 TALLOC_CTX *mem_ctx)
2529 const char *p;
2531 if (*pinfo2->comment == '\0') {
2532 p = lp_comment(snum);
2533 } else {
2534 p = pinfo2->comment;
2537 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2540 /*******************************************************************
2541 * fill a notify_info_data with the comment
2542 * location = "Room 1, floor 2, building 3"
2543 ********************************************************************/
2545 static void spoolss_notify_location(int snum,
2546 struct spoolss_Notify *data,
2547 print_queue_struct *queue,
2548 struct spoolss_PrinterInfo2 *pinfo2,
2549 TALLOC_CTX *mem_ctx)
2551 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
2554 /*******************************************************************
2555 * fill a notify_info_data with the device mode
2556 * jfm:xxxx don't to it for know but that's a real problem !!!
2557 ********************************************************************/
2559 static void spoolss_notify_devmode(int snum,
2560 struct spoolss_Notify *data,
2561 print_queue_struct *queue,
2562 struct spoolss_PrinterInfo2 *pinfo2,
2563 TALLOC_CTX *mem_ctx)
2565 /* for a dummy implementation we have to zero the fields */
2566 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2569 /*******************************************************************
2570 * fill a notify_info_data with the separator file name
2571 ********************************************************************/
2573 static void spoolss_notify_sepfile(int snum,
2574 struct spoolss_Notify *data,
2575 print_queue_struct *queue,
2576 struct spoolss_PrinterInfo2 *pinfo2,
2577 TALLOC_CTX *mem_ctx)
2579 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2582 /*******************************************************************
2583 * fill a notify_info_data with the print processor
2584 * jfm:xxxx return always winprint to indicate we don't do anything to it
2585 ********************************************************************/
2587 static void spoolss_notify_print_processor(int snum,
2588 struct spoolss_Notify *data,
2589 print_queue_struct *queue,
2590 struct spoolss_PrinterInfo2 *pinfo2,
2591 TALLOC_CTX *mem_ctx)
2593 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2596 /*******************************************************************
2597 * fill a notify_info_data with the print processor options
2598 * jfm:xxxx send an empty string
2599 ********************************************************************/
2601 static void spoolss_notify_parameters(int snum,
2602 struct spoolss_Notify *data,
2603 print_queue_struct *queue,
2604 struct spoolss_PrinterInfo2 *pinfo2,
2605 TALLOC_CTX *mem_ctx)
2607 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2610 /*******************************************************************
2611 * fill a notify_info_data with the data type
2612 * jfm:xxxx always send RAW as data type
2613 ********************************************************************/
2615 static void spoolss_notify_datatype(int snum,
2616 struct spoolss_Notify *data,
2617 print_queue_struct *queue,
2618 struct spoolss_PrinterInfo2 *pinfo2,
2619 TALLOC_CTX *mem_ctx)
2621 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2624 /*******************************************************************
2625 * fill a notify_info_data with the security descriptor
2626 * jfm:xxxx send an null pointer to say no security desc
2627 * have to implement security before !
2628 ********************************************************************/
2630 static void spoolss_notify_security_desc(int snum,
2631 struct spoolss_Notify *data,
2632 print_queue_struct *queue,
2633 struct spoolss_PrinterInfo2 *pinfo2,
2634 TALLOC_CTX *mem_ctx)
2636 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2639 /*******************************************************************
2640 * fill a notify_info_data with the attributes
2641 * jfm:xxxx a samba printer is always shared
2642 ********************************************************************/
2644 static void spoolss_notify_attributes(int snum,
2645 struct spoolss_Notify *data,
2646 print_queue_struct *queue,
2647 struct spoolss_PrinterInfo2 *pinfo2,
2648 TALLOC_CTX *mem_ctx)
2650 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2653 /*******************************************************************
2654 * fill a notify_info_data with the priority
2655 ********************************************************************/
2657 static void spoolss_notify_priority(int snum,
2658 struct spoolss_Notify *data,
2659 print_queue_struct *queue,
2660 struct spoolss_PrinterInfo2 *pinfo2,
2661 TALLOC_CTX *mem_ctx)
2663 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2666 /*******************************************************************
2667 * fill a notify_info_data with the default priority
2668 ********************************************************************/
2670 static void spoolss_notify_default_priority(int snum,
2671 struct spoolss_Notify *data,
2672 print_queue_struct *queue,
2673 struct spoolss_PrinterInfo2 *pinfo2,
2674 TALLOC_CTX *mem_ctx)
2676 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
2679 /*******************************************************************
2680 * fill a notify_info_data with the start time
2681 ********************************************************************/
2683 static void spoolss_notify_start_time(int snum,
2684 struct spoolss_Notify *data,
2685 print_queue_struct *queue,
2686 struct spoolss_PrinterInfo2 *pinfo2,
2687 TALLOC_CTX *mem_ctx)
2689 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
2692 /*******************************************************************
2693 * fill a notify_info_data with the until time
2694 ********************************************************************/
2696 static void spoolss_notify_until_time(int snum,
2697 struct spoolss_Notify *data,
2698 print_queue_struct *queue,
2699 struct spoolss_PrinterInfo2 *pinfo2,
2700 TALLOC_CTX *mem_ctx)
2702 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
2705 /*******************************************************************
2706 * fill a notify_info_data with the status
2707 ********************************************************************/
2709 static void spoolss_notify_status(int snum,
2710 struct spoolss_Notify *data,
2711 print_queue_struct *queue,
2712 struct spoolss_PrinterInfo2 *pinfo2,
2713 TALLOC_CTX *mem_ctx)
2715 print_status_struct status;
2717 print_queue_length(snum, &status);
2718 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
2721 /*******************************************************************
2722 * fill a notify_info_data with the number of jobs queued
2723 ********************************************************************/
2725 static void spoolss_notify_cjobs(int snum,
2726 struct spoolss_Notify *data,
2727 print_queue_struct *queue,
2728 struct spoolss_PrinterInfo2 *pinfo2,
2729 TALLOC_CTX *mem_ctx)
2731 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
2734 /*******************************************************************
2735 * fill a notify_info_data with the average ppm
2736 ********************************************************************/
2738 static void spoolss_notify_average_ppm(int snum,
2739 struct spoolss_Notify *data,
2740 print_queue_struct *queue,
2741 struct spoolss_PrinterInfo2 *pinfo2,
2742 TALLOC_CTX *mem_ctx)
2744 /* always respond 8 pages per minutes */
2745 /* a little hard ! */
2746 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
2749 /*******************************************************************
2750 * fill a notify_info_data with username
2751 ********************************************************************/
2753 static void spoolss_notify_username(int snum,
2754 struct spoolss_Notify *data,
2755 print_queue_struct *queue,
2756 struct spoolss_PrinterInfo2 *pinfo2,
2757 TALLOC_CTX *mem_ctx)
2759 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
2762 /*******************************************************************
2763 * fill a notify_info_data with job status
2764 ********************************************************************/
2766 static void spoolss_notify_job_status(int snum,
2767 struct spoolss_Notify *data,
2768 print_queue_struct *queue,
2769 struct spoolss_PrinterInfo2 *pinfo2,
2770 TALLOC_CTX *mem_ctx)
2772 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
2775 /*******************************************************************
2776 * fill a notify_info_data with job name
2777 ********************************************************************/
2779 static void spoolss_notify_job_name(int snum,
2780 struct spoolss_Notify *data,
2781 print_queue_struct *queue,
2782 struct spoolss_PrinterInfo2 *pinfo2,
2783 TALLOC_CTX *mem_ctx)
2785 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
2788 /*******************************************************************
2789 * fill a notify_info_data with job status
2790 ********************************************************************/
2792 static void spoolss_notify_job_status_string(int snum,
2793 struct spoolss_Notify *data,
2794 print_queue_struct *queue,
2795 struct spoolss_PrinterInfo2 *pinfo2,
2796 TALLOC_CTX *mem_ctx)
2799 * Now we're returning job status codes we just return a "" here. JRA.
2802 const char *p = "";
2804 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
2805 p = "unknown";
2807 switch (queue->status) {
2808 case LPQ_QUEUED:
2809 p = "Queued";
2810 break;
2811 case LPQ_PAUSED:
2812 p = ""; /* NT provides the paused string */
2813 break;
2814 case LPQ_SPOOLING:
2815 p = "Spooling";
2816 break;
2817 case LPQ_PRINTING:
2818 p = "Printing";
2819 break;
2821 #endif /* NO LONGER NEEDED. */
2823 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2826 /*******************************************************************
2827 * fill a notify_info_data with job time
2828 ********************************************************************/
2830 static void spoolss_notify_job_time(int snum,
2831 struct spoolss_Notify *data,
2832 print_queue_struct *queue,
2833 struct spoolss_PrinterInfo2 *pinfo2,
2834 TALLOC_CTX *mem_ctx)
2836 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2839 /*******************************************************************
2840 * fill a notify_info_data with job size
2841 ********************************************************************/
2843 static void spoolss_notify_job_size(int snum,
2844 struct spoolss_Notify *data,
2845 print_queue_struct *queue,
2846 struct spoolss_PrinterInfo2 *pinfo2,
2847 TALLOC_CTX *mem_ctx)
2849 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
2852 /*******************************************************************
2853 * fill a notify_info_data with page info
2854 ********************************************************************/
2855 static void spoolss_notify_total_pages(int snum,
2856 struct spoolss_Notify *data,
2857 print_queue_struct *queue,
2858 struct spoolss_PrinterInfo2 *pinfo2,
2859 TALLOC_CTX *mem_ctx)
2861 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
2864 /*******************************************************************
2865 * fill a notify_info_data with pages printed info.
2866 ********************************************************************/
2867 static void spoolss_notify_pages_printed(int snum,
2868 struct spoolss_Notify *data,
2869 print_queue_struct *queue,
2870 struct spoolss_PrinterInfo2 *pinfo2,
2871 TALLOC_CTX *mem_ctx)
2873 /* Add code when back-end tracks this */
2874 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2877 /*******************************************************************
2878 Fill a notify_info_data with job position.
2879 ********************************************************************/
2881 static void spoolss_notify_job_position(int snum,
2882 struct spoolss_Notify *data,
2883 print_queue_struct *queue,
2884 struct spoolss_PrinterInfo2 *pinfo2,
2885 TALLOC_CTX *mem_ctx)
2887 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
2890 /*******************************************************************
2891 Fill a notify_info_data with submitted time.
2892 ********************************************************************/
2894 static void spoolss_notify_submitted_time(int snum,
2895 struct spoolss_Notify *data,
2896 print_queue_struct *queue,
2897 struct spoolss_PrinterInfo2 *pinfo2,
2898 TALLOC_CTX *mem_ctx)
2900 data->data.string.string = NULL;
2901 data->data.string.size = 0;
2903 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
2904 &data->data.string.string,
2905 &data->data.string.size);
2909 struct s_notify_info_data_table
2911 enum spoolss_NotifyType type;
2912 uint16_t field;
2913 const char *name;
2914 enum spoolss_NotifyTable variable_type;
2915 void (*fn) (int snum, struct spoolss_Notify *data,
2916 print_queue_struct *queue,
2917 struct spoolss_PrinterInfo2 *pinfo2,
2918 TALLOC_CTX *mem_ctx);
2921 /* A table describing the various print notification constants and
2922 whether the notification data is a pointer to a variable sized
2923 buffer, a one value uint32_t or a two value uint32_t. */
2925 static const struct s_notify_info_data_table notify_info_data_table[] =
2927 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2928 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2929 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
2930 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2931 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2932 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
2933 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
2934 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2935 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
2936 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2937 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2938 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2939 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
2940 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
2941 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2942 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
2943 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2944 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2945 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
2946 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
2947 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
2948 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
2949 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
2950 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2951 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
2952 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2953 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2954 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2955 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2956 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2957 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2958 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2959 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2960 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2961 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2962 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2963 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
2964 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
2965 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
2966 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
2967 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2968 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
2969 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
2970 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2971 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2972 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
2973 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
2974 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
2975 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
2978 /*******************************************************************
2979 Return the variable_type of info_data structure.
2980 ********************************************************************/
2982 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
2983 uint16_t field)
2985 int i=0;
2987 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
2988 if ( (notify_info_data_table[i].type == type) &&
2989 (notify_info_data_table[i].field == field) ) {
2990 return notify_info_data_table[i].variable_type;
2994 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
2996 return 0;
2999 /****************************************************************************
3000 ****************************************************************************/
3002 static bool search_notify(enum spoolss_NotifyType type,
3003 uint16_t field,
3004 int *value)
3006 int i;
3008 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3009 if (notify_info_data_table[i].type == type &&
3010 notify_info_data_table[i].field == field &&
3011 notify_info_data_table[i].fn != NULL) {
3012 *value = i;
3013 return true;
3017 return false;
3020 /****************************************************************************
3021 ****************************************************************************/
3023 static void construct_info_data(struct spoolss_Notify *info_data,
3024 enum spoolss_NotifyType type,
3025 uint16_t field, int id)
3027 info_data->type = type;
3028 info_data->field.field = field;
3029 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3030 info_data->job_id = id;
3033 /*******************************************************************
3035 * fill a notify_info struct with info asked
3037 ********************************************************************/
3039 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3040 struct spoolss_NotifyInfo *info,
3041 struct spoolss_PrinterInfo2 *pinfo2,
3042 int snum,
3043 const struct spoolss_NotifyOptionType *option_type,
3044 uint32_t id,
3045 TALLOC_CTX *mem_ctx)
3047 int field_num,j;
3048 enum spoolss_NotifyType type;
3049 uint16_t field;
3051 struct spoolss_Notify *current_data;
3052 print_queue_struct *queue=NULL;
3054 type = option_type->type;
3056 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3057 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3058 option_type->count, lp_servicename(snum)));
3060 for(field_num=0; field_num < option_type->count; field_num++) {
3061 field = option_type->fields[field_num].field;
3063 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3065 if (!search_notify(type, field, &j) )
3066 continue;
3068 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3069 struct spoolss_Notify,
3070 info->count + 1);
3071 if (info->notifies == NULL) {
3072 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3073 return false;
3076 current_data = &info->notifies[info->count];
3078 construct_info_data(current_data, type, field, id);
3080 DEBUG(10, ("construct_notify_printer_info: "
3081 "calling [%s] snum=%d printername=[%s])\n",
3082 notify_info_data_table[j].name, snum,
3083 pinfo2->printername));
3085 notify_info_data_table[j].fn(snum, current_data, queue,
3086 pinfo2, mem_ctx);
3088 info->count++;
3091 return true;
3094 /*******************************************************************
3096 * fill a notify_info struct with info asked
3098 ********************************************************************/
3100 static bool construct_notify_jobs_info(print_queue_struct *queue,
3101 struct spoolss_NotifyInfo *info,
3102 struct spoolss_PrinterInfo2 *pinfo2,
3103 int snum,
3104 const struct spoolss_NotifyOptionType *option_type,
3105 uint32_t id,
3106 TALLOC_CTX *mem_ctx)
3108 int field_num,j;
3109 enum spoolss_NotifyType type;
3110 uint16_t field;
3111 struct spoolss_Notify *current_data;
3113 DEBUG(4,("construct_notify_jobs_info\n"));
3115 type = option_type->type;
3117 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3118 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3119 option_type->count));
3121 for(field_num=0; field_num<option_type->count; field_num++) {
3122 field = option_type->fields[field_num].field;
3124 if (!search_notify(type, field, &j) )
3125 continue;
3127 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3128 struct spoolss_Notify,
3129 info->count + 1);
3130 if (info->notifies == NULL) {
3131 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3132 return false;
3135 current_data=&(info->notifies[info->count]);
3137 construct_info_data(current_data, type, field, id);
3138 notify_info_data_table[j].fn(snum, current_data, queue,
3139 pinfo2, mem_ctx);
3140 info->count++;
3143 return true;
3147 * JFM: The enumeration is not that simple, it's even non obvious.
3149 * let's take an example: I want to monitor the PRINTER SERVER for
3150 * the printer's name and the number of jobs currently queued.
3151 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3152 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3154 * I have 3 printers on the back of my server.
3156 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3157 * structures.
3158 * Number Data Id
3159 * 1 printer 1 name 1
3160 * 2 printer 1 cjob 1
3161 * 3 printer 2 name 2
3162 * 4 printer 2 cjob 2
3163 * 5 printer 3 name 3
3164 * 6 printer 3 name 3
3166 * that's the print server case, the printer case is even worse.
3169 /*******************************************************************
3171 * enumerate all printers on the printserver
3172 * fill a notify_info struct with info asked
3174 ********************************************************************/
3176 static WERROR printserver_notify_info(struct pipes_struct *p,
3177 struct policy_handle *hnd,
3178 struct spoolss_NotifyInfo *info,
3179 TALLOC_CTX *mem_ctx)
3181 int snum;
3182 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3183 int n_services=lp_numservices();
3184 int i;
3185 struct spoolss_NotifyOption *option;
3186 struct spoolss_NotifyOptionType option_type;
3187 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3188 WERROR result;
3190 DEBUG(4,("printserver_notify_info\n"));
3192 if (!Printer)
3193 return WERR_BADFID;
3195 option = Printer->notify.option;
3197 info->version = 2;
3198 info->notifies = NULL;
3199 info->count = 0;
3201 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3202 sending a ffpcn() request first */
3204 if ( !option )
3205 return WERR_BADFID;
3207 for (i=0; i<option->count; i++) {
3208 option_type = option->types[i];
3210 if (option_type.type != PRINTER_NOTIFY_TYPE)
3211 continue;
3213 for (snum = 0; snum < n_services; snum++) {
3214 if (!lp_browseable(snum) ||
3215 !lp_snum_ok(snum) ||
3216 !lp_print_ok(snum)) {
3217 continue; /* skip */
3220 /* Maybe we should use the SYSTEM server_info here... */
3221 result = winreg_get_printer(mem_ctx, p->server_info,
3222 Printer->servername,
3223 lp_servicename(snum),
3224 &pinfo2);
3225 if (!W_ERROR_IS_OK(result)) {
3226 DEBUG(4, ("printserver_notify_info: "
3227 "Failed to get printer [%s]\n",
3228 lp_servicename(snum)));
3229 continue;
3233 construct_notify_printer_info(Printer, info,
3234 pinfo2, snum,
3235 &option_type, snum,
3236 mem_ctx);
3238 TALLOC_FREE(pinfo2);
3242 #if 0
3244 * Debugging information, don't delete.
3247 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3248 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3249 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3251 for (i=0; i<info->count; i++) {
3252 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3253 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3254 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3256 #endif
3258 return WERR_OK;
3261 /*******************************************************************
3263 * fill a notify_info struct with info asked
3265 ********************************************************************/
3267 static WERROR printer_notify_info(struct pipes_struct *p,
3268 struct policy_handle *hnd,
3269 struct spoolss_NotifyInfo *info,
3270 TALLOC_CTX *mem_ctx)
3272 int snum;
3273 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3274 int i;
3275 uint32_t id;
3276 struct spoolss_NotifyOption *option;
3277 struct spoolss_NotifyOptionType option_type;
3278 int count,j;
3279 print_queue_struct *queue=NULL;
3280 print_status_struct status;
3281 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3282 WERROR result;
3284 DEBUG(4,("printer_notify_info\n"));
3286 if (!Printer)
3287 return WERR_BADFID;
3289 option = Printer->notify.option;
3290 id = 0x0;
3292 info->version = 2;
3293 info->notifies = NULL;
3294 info->count = 0;
3296 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3297 sending a ffpcn() request first */
3299 if ( !option )
3300 return WERR_BADFID;
3302 get_printer_snum(p, hnd, &snum, NULL);
3304 /* Maybe we should use the SYSTEM server_info here... */
3305 result = winreg_get_printer(mem_ctx, p->server_info,
3306 Printer->servername,
3307 lp_servicename(snum), &pinfo2);
3308 if (!W_ERROR_IS_OK(result)) {
3309 return WERR_BADFID;
3312 for (i=0; i<option->count; i++) {
3313 option_type = option->types[i];
3315 switch (option_type.type) {
3316 case PRINTER_NOTIFY_TYPE:
3317 if (construct_notify_printer_info(Printer, info,
3318 pinfo2, snum,
3319 &option_type, id,
3320 mem_ctx)) {
3321 id--;
3323 break;
3325 case JOB_NOTIFY_TYPE:
3327 count = print_queue_status(snum, &queue, &status);
3329 for (j=0; j<count; j++) {
3330 construct_notify_jobs_info(&queue[j], info,
3331 pinfo2, snum,
3332 &option_type,
3333 queue[j].job,
3334 mem_ctx);
3337 SAFE_FREE(queue);
3338 break;
3343 * Debugging information, don't delete.
3346 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3347 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3348 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3350 for (i=0; i<info->count; i++) {
3351 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3352 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3353 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3357 talloc_free(pinfo2);
3358 return WERR_OK;
3361 /****************************************************************
3362 _spoolss_RouterRefreshPrinterChangeNotify
3363 ****************************************************************/
3365 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3366 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3368 struct spoolss_NotifyInfo *info;
3370 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
3371 WERROR result = WERR_BADFID;
3373 /* we always have a spoolss_NotifyInfo struct */
3374 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3375 if (!info) {
3376 result = WERR_NOMEM;
3377 goto done;
3380 *r->out.info = info;
3382 if (!Printer) {
3383 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3384 "Invalid handle (%s:%u:%u).\n",
3385 OUR_HANDLE(r->in.handle)));
3386 goto done;
3389 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3392 * We are now using the change value, and
3393 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3394 * I don't have a global notification system, I'm sending back all the
3395 * informations even when _NOTHING_ has changed.
3398 /* We need to keep track of the change value to send back in
3399 RRPCN replies otherwise our updates are ignored. */
3401 Printer->notify.fnpcn = true;
3403 if (Printer->notify.client_connected) {
3404 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3405 "Saving change value in request [%x]\n",
3406 r->in.change_low));
3407 Printer->notify.change = r->in.change_low;
3410 /* just ignore the spoolss_NotifyOption */
3412 switch (Printer->printer_type) {
3413 case SPLHND_SERVER:
3414 result = printserver_notify_info(p, r->in.handle,
3415 info, p->mem_ctx);
3416 break;
3418 case SPLHND_PRINTER:
3419 result = printer_notify_info(p, r->in.handle,
3420 info, p->mem_ctx);
3421 break;
3424 Printer->notify.fnpcn = false;
3426 done:
3427 return result;
3430 /********************************************************************
3431 * construct_printer_info_0
3432 * fill a printer_info_0 struct
3433 ********************************************************************/
3435 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3436 struct auth_serversupplied_info *server_info,
3437 struct spoolss_PrinterInfo2 *info2,
3438 struct spoolss_PrinterInfo0 *r,
3439 int snum)
3441 int count;
3442 counter_printer_0 *session_counter;
3443 struct timeval setuptime;
3444 print_status_struct status;
3446 r->printername = talloc_strdup(mem_ctx, info2->printername);
3447 W_ERROR_HAVE_NO_MEMORY(r->printername);
3449 r->servername = talloc_strdup(mem_ctx, info2->servername);
3450 W_ERROR_HAVE_NO_MEMORY(r->servername);
3452 count = print_queue_length(snum, &status);
3454 /* check if we already have a counter for this printer */
3455 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3456 if (session_counter->snum == snum)
3457 break;
3460 /* it's the first time, add it to the list */
3461 if (session_counter == NULL) {
3462 session_counter = SMB_MALLOC_P(counter_printer_0);
3463 W_ERROR_HAVE_NO_MEMORY(session_counter);
3464 ZERO_STRUCTP(session_counter);
3465 session_counter->snum = snum;
3466 session_counter->counter = 0;
3467 DLIST_ADD(counter_list, session_counter);
3470 /* increment it */
3471 session_counter->counter++;
3473 r->cjobs = count;
3474 r->total_jobs = 0;
3475 r->total_bytes = 0;
3477 get_startup_time(&setuptime);
3478 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3480 /* JFM:
3481 * the global_counter should be stored in a TDB as it's common to all the clients
3482 * and should be zeroed on samba startup
3484 r->global_counter = session_counter->counter;
3485 r->total_pages = 0;
3486 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3487 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3488 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3489 r->free_build = SPOOLSS_RELEASE_BUILD;
3490 r->spooling = 0;
3491 r->max_spooling = 0;
3492 r->session_counter = session_counter->counter;
3493 r->num_error_out_of_paper = 0x0;
3494 r->num_error_not_ready = 0x0; /* number of print failure */
3495 r->job_error = 0x0;
3496 r->number_of_processors = 0x1;
3497 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3498 r->high_part_total_bytes = 0x0;
3499 winreg_printer_get_changeid(mem_ctx, server_info, info2->sharename, &r->change_id); /* ChangeID in milliseconds*/
3500 r->last_error = WERR_OK;
3501 r->status = nt_printq_status(status.status);
3502 r->enumerate_network_printers = 0x0;
3503 r->c_setprinter = 0x0;
3504 r->processor_architecture = 0x0;
3505 r->processor_level = 0x6; /* 6 ???*/
3506 r->ref_ic = 0;
3507 r->reserved2 = 0;
3508 r->reserved3 = 0;
3510 return WERR_OK;
3514 /********************************************************************
3515 * construct_printer_info1
3516 * fill a spoolss_PrinterInfo1 struct
3517 ********************************************************************/
3519 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3520 const struct spoolss_PrinterInfo2 *info2,
3521 uint32_t flags,
3522 struct spoolss_PrinterInfo1 *r,
3523 int snum)
3525 r->flags = flags;
3527 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3528 info2->printername,
3529 info2->drivername,
3530 info2->location);
3531 W_ERROR_HAVE_NO_MEMORY(r->description);
3533 if (info2->comment == NULL || info2->comment[0] == '\0') {
3534 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3535 } else {
3536 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3538 W_ERROR_HAVE_NO_MEMORY(r->comment);
3540 r->name = talloc_strdup(mem_ctx, info2->printername);
3541 W_ERROR_HAVE_NO_MEMORY(r->name);
3543 return WERR_OK;
3546 /********************************************************************
3547 * construct_printer_info2
3548 * fill a spoolss_PrinterInfo2 struct
3549 ********************************************************************/
3551 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3552 const struct spoolss_PrinterInfo2 *info2,
3553 struct spoolss_PrinterInfo2 *r,
3554 int snum)
3556 int count;
3557 print_status_struct status;
3559 count = print_queue_length(snum, &status);
3561 r->servername = talloc_strdup(mem_ctx, info2->servername);
3562 W_ERROR_HAVE_NO_MEMORY(r->servername);
3563 r->printername = talloc_strdup(mem_ctx, info2->printername);
3564 W_ERROR_HAVE_NO_MEMORY(r->printername);
3565 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3566 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3567 r->portname = talloc_strdup(mem_ctx, info2->portname);
3568 W_ERROR_HAVE_NO_MEMORY(r->portname);
3569 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
3570 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3572 if (info2->comment[0] == '\0') {
3573 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3574 } else {
3575 r->comment = talloc_strdup(mem_ctx, info2->comment);
3577 W_ERROR_HAVE_NO_MEMORY(r->comment);
3579 r->location = talloc_strdup(mem_ctx, info2->location);
3580 W_ERROR_HAVE_NO_MEMORY(r->location);
3581 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
3582 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3583 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
3584 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3585 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
3586 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3587 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
3588 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3590 r->attributes = info2->attributes;
3592 r->priority = info2->priority;
3593 r->defaultpriority = info2->defaultpriority;
3594 r->starttime = info2->starttime;
3595 r->untiltime = info2->untiltime;
3596 r->status = nt_printq_status(status.status);
3597 r->cjobs = count;
3598 r->averageppm = info2->averageppm;
3600 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3601 if (!r->devmode) {
3602 DEBUG(8,("Returning NULL Devicemode!\n"));
3605 r->secdesc = NULL;
3607 if (info2->secdesc != NULL) {
3608 /* don't use talloc_steal() here unless you do a deep steal of all
3609 the SEC_DESC members */
3611 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3614 return WERR_OK;
3617 /********************************************************************
3618 * construct_printer_info3
3619 * fill a spoolss_PrinterInfo3 struct
3620 ********************************************************************/
3622 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3623 const struct spoolss_PrinterInfo2 *info2,
3624 struct spoolss_PrinterInfo3 *r,
3625 int snum)
3627 /* These are the components of the SD we are returning. */
3629 if (info2->secdesc != NULL) {
3630 /* don't use talloc_steal() here unless you do a deep steal of all
3631 the SEC_DESC members */
3633 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3634 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3637 return WERR_OK;
3640 /********************************************************************
3641 * construct_printer_info4
3642 * fill a spoolss_PrinterInfo4 struct
3643 ********************************************************************/
3645 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
3646 const struct spoolss_PrinterInfo2 *info2,
3647 struct spoolss_PrinterInfo4 *r,
3648 int snum)
3650 r->printername = talloc_strdup(mem_ctx, info2->printername);
3651 W_ERROR_HAVE_NO_MEMORY(r->printername);
3652 r->servername = talloc_strdup(mem_ctx, info2->servername);
3653 W_ERROR_HAVE_NO_MEMORY(r->servername);
3655 r->attributes = info2->attributes;
3657 return WERR_OK;
3660 /********************************************************************
3661 * construct_printer_info5
3662 * fill a spoolss_PrinterInfo5 struct
3663 ********************************************************************/
3665 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
3666 const struct spoolss_PrinterInfo2 *info2,
3667 struct spoolss_PrinterInfo5 *r,
3668 int snum)
3670 r->printername = talloc_strdup(mem_ctx, info2->printername);
3671 W_ERROR_HAVE_NO_MEMORY(r->printername);
3672 r->portname = talloc_strdup(mem_ctx, info2->portname);
3673 W_ERROR_HAVE_NO_MEMORY(r->portname);
3675 r->attributes = info2->attributes;
3677 /* these two are not used by NT+ according to MSDN */
3678 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
3679 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
3681 return WERR_OK;
3684 /********************************************************************
3685 * construct_printer_info_6
3686 * fill a spoolss_PrinterInfo6 struct
3687 ********************************************************************/
3689 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
3690 const struct spoolss_PrinterInfo2 *info2,
3691 struct spoolss_PrinterInfo6 *r,
3692 int snum)
3694 int count;
3695 print_status_struct status;
3697 count = print_queue_length(snum, &status);
3699 r->status = nt_printq_status(status.status);
3701 return WERR_OK;
3704 /********************************************************************
3705 * construct_printer_info7
3706 * fill a spoolss_PrinterInfo7 struct
3707 ********************************************************************/
3709 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
3710 Printer_entry *print_hnd,
3711 struct spoolss_PrinterInfo7 *r,
3712 int snum)
3714 struct auth_serversupplied_info *server_info;
3715 struct GUID guid;
3716 NTSTATUS status;
3718 status = make_server_info_system(mem_ctx, &server_info);
3719 if (!NT_STATUS_IS_OK(status)) {
3720 DEBUG(0, ("construct_printer_info7: "
3721 "Could not create system server_info\n"));
3722 return WERR_NOMEM;
3725 if (is_printer_published(mem_ctx, server_info, print_hnd->servername,
3726 lp_servicename(snum), &guid, NULL)) {
3727 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
3728 r->action = DSPRINT_PUBLISH;
3729 } else {
3730 r->guid = talloc_strdup(mem_ctx, "");
3731 r->action = DSPRINT_UNPUBLISH;
3733 W_ERROR_HAVE_NO_MEMORY(r->guid);
3735 TALLOC_FREE(server_info);
3736 return WERR_OK;
3739 /********************************************************************
3740 * construct_printer_info8
3741 * fill a spoolss_PrinterInfo8 struct
3742 ********************************************************************/
3744 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
3745 const struct spoolss_PrinterInfo2 *info2,
3746 struct spoolss_DeviceModeInfo *r,
3747 int snum)
3749 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3750 if (!r->devmode) {
3751 DEBUG(8,("Returning NULL Devicemode!\n"));
3754 return WERR_OK;
3758 /********************************************************************
3759 ********************************************************************/
3761 static bool snum_is_shared_printer(int snum)
3763 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
3766 /********************************************************************
3767 Spoolss_enumprinters.
3768 ********************************************************************/
3770 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
3771 struct auth_serversupplied_info *server_info,
3772 uint32_t level,
3773 uint32_t flags,
3774 union spoolss_PrinterInfo **info_p,
3775 uint32_t *count_p)
3777 int snum;
3778 int n_services = lp_numservices();
3779 union spoolss_PrinterInfo *info = NULL;
3780 uint32_t count = 0;
3781 WERROR result = WERR_OK;
3783 *count_p = 0;
3784 *info_p = NULL;
3786 for (snum = 0; snum < n_services; snum++) {
3788 const char *printer;
3789 struct spoolss_PrinterInfo2 *info2;
3791 if (!snum_is_shared_printer(snum)) {
3792 continue;
3795 printer = lp_const_servicename(snum);
3797 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
3798 printer, snum));
3800 result = winreg_create_printer(mem_ctx,
3801 server_info,
3802 NULL,
3803 printer);
3804 if (!W_ERROR_IS_OK(result)) {
3805 goto out;
3808 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
3809 union spoolss_PrinterInfo,
3810 count + 1);
3811 if (!info) {
3812 result = WERR_NOMEM;
3813 goto out;
3816 result = winreg_get_printer(mem_ctx, server_info,
3817 NULL, printer, &info2);
3818 if (!W_ERROR_IS_OK(result)) {
3819 goto out;
3822 switch (level) {
3823 case 0:
3824 result = construct_printer_info0(info, server_info, info2,
3825 &info[count].info0, snum);
3826 break;
3827 case 1:
3828 result = construct_printer_info1(info, info2, flags,
3829 &info[count].info1, snum);
3830 break;
3831 case 2:
3832 result = construct_printer_info2(info, info2,
3833 &info[count].info2, snum);
3834 break;
3835 case 4:
3836 result = construct_printer_info4(info, info2,
3837 &info[count].info4, snum);
3838 break;
3839 case 5:
3840 result = construct_printer_info5(info, info2,
3841 &info[count].info5, snum);
3842 break;
3844 default:
3845 result = WERR_UNKNOWN_LEVEL;
3846 goto out;
3849 if (!W_ERROR_IS_OK(result)) {
3850 goto out;
3853 count++;
3856 *count_p = count;
3857 *info_p = info;
3859 out:
3860 if (!W_ERROR_IS_OK(result)) {
3861 TALLOC_FREE(info);
3862 return result;
3865 *info_p = info;
3867 return WERR_OK;
3870 /********************************************************************
3871 * handle enumeration of printers at level 0
3872 ********************************************************************/
3874 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
3875 struct auth_serversupplied_info *server_info,
3876 uint32_t flags,
3877 const char *servername,
3878 union spoolss_PrinterInfo **info,
3879 uint32_t *count)
3881 DEBUG(4,("enum_all_printers_info_0\n"));
3883 return enum_all_printers_info_level(mem_ctx, server_info, 0, flags, info, count);
3887 /********************************************************************
3888 ********************************************************************/
3890 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
3891 struct auth_serversupplied_info *server_info,
3892 uint32_t flags,
3893 union spoolss_PrinterInfo **info,
3894 uint32_t *count)
3896 DEBUG(4,("enum_all_printers_info_1\n"));
3898 return enum_all_printers_info_level(mem_ctx, server_info, 1, flags, info, count);
3901 /********************************************************************
3902 enum_all_printers_info_1_local.
3903 *********************************************************************/
3905 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
3906 struct auth_serversupplied_info *server_info,
3907 union spoolss_PrinterInfo **info,
3908 uint32_t *count)
3910 DEBUG(4,("enum_all_printers_info_1_local\n"));
3912 return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_ICON8, info, count);
3915 /********************************************************************
3916 enum_all_printers_info_1_name.
3917 *********************************************************************/
3919 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
3920 struct auth_serversupplied_info *server_info,
3921 const char *name,
3922 union spoolss_PrinterInfo **info,
3923 uint32_t *count)
3925 const char *s = name;
3927 DEBUG(4,("enum_all_printers_info_1_name\n"));
3929 if ((name[0] == '\\') && (name[1] == '\\')) {
3930 s = name + 2;
3933 if (!is_myname_or_ipaddr(s)) {
3934 return WERR_INVALID_NAME;
3937 return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_ICON8, info, count);
3940 /********************************************************************
3941 enum_all_printers_info_1_network.
3942 *********************************************************************/
3944 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
3945 struct auth_serversupplied_info *server_info,
3946 const char *name,
3947 union spoolss_PrinterInfo **info,
3948 uint32_t *count)
3950 const char *s = name;
3952 DEBUG(4,("enum_all_printers_info_1_network\n"));
3954 /* If we respond to a enum_printers level 1 on our name with flags
3955 set to PRINTER_ENUM_REMOTE with a list of printers then these
3956 printers incorrectly appear in the APW browse list.
3957 Specifically the printers for the server appear at the workgroup
3958 level where all the other servers in the domain are
3959 listed. Windows responds to this call with a
3960 WERR_CAN_NOT_COMPLETE so we should do the same. */
3962 if (name[0] == '\\' && name[1] == '\\') {
3963 s = name + 2;
3966 if (is_myname_or_ipaddr(s)) {
3967 return WERR_CAN_NOT_COMPLETE;
3970 return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_NAME, info, count);
3973 /********************************************************************
3974 * api_spoolss_enumprinters
3976 * called from api_spoolss_enumprinters (see this to understand)
3977 ********************************************************************/
3979 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
3980 struct auth_serversupplied_info *server_info,
3981 union spoolss_PrinterInfo **info,
3982 uint32_t *count)
3984 DEBUG(4,("enum_all_printers_info_2\n"));
3986 return enum_all_printers_info_level(mem_ctx, server_info, 2, 0, info, count);
3989 /********************************************************************
3990 * handle enumeration of printers at level 1
3991 ********************************************************************/
3993 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
3994 struct auth_serversupplied_info *server_info,
3995 uint32_t flags,
3996 const char *name,
3997 union spoolss_PrinterInfo **info,
3998 uint32_t *count)
4000 /* Not all the flags are equals */
4002 if (flags & PRINTER_ENUM_LOCAL) {
4003 return enum_all_printers_info_1_local(mem_ctx, server_info, info, count);
4006 if (flags & PRINTER_ENUM_NAME) {
4007 return enum_all_printers_info_1_name(mem_ctx, server_info, name, info, count);
4010 if (flags & PRINTER_ENUM_NETWORK) {
4011 return enum_all_printers_info_1_network(mem_ctx, server_info, name, info, count);
4014 return WERR_OK; /* NT4sp5 does that */
4017 /********************************************************************
4018 * handle enumeration of printers at level 2
4019 ********************************************************************/
4021 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4022 struct auth_serversupplied_info *server_info,
4023 uint32_t flags,
4024 const char *servername,
4025 union spoolss_PrinterInfo **info,
4026 uint32_t *count)
4028 if (flags & PRINTER_ENUM_LOCAL) {
4029 return enum_all_printers_info_2(mem_ctx, server_info, info, count);
4032 if (flags & PRINTER_ENUM_NAME) {
4033 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4034 return WERR_INVALID_NAME;
4037 return enum_all_printers_info_2(mem_ctx, server_info, info, count);
4040 if (flags & PRINTER_ENUM_REMOTE) {
4041 return WERR_UNKNOWN_LEVEL;
4044 return WERR_OK;
4047 /********************************************************************
4048 * handle enumeration of printers at level 4
4049 ********************************************************************/
4051 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4052 struct auth_serversupplied_info *server_info,
4053 uint32_t flags,
4054 const char *servername,
4055 union spoolss_PrinterInfo **info,
4056 uint32_t *count)
4058 DEBUG(4,("enum_all_printers_info_4\n"));
4060 return enum_all_printers_info_level(mem_ctx, server_info, 4, flags, info, count);
4064 /********************************************************************
4065 * handle enumeration of printers at level 5
4066 ********************************************************************/
4068 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4069 struct auth_serversupplied_info *server_info,
4070 uint32_t flags,
4071 const char *servername,
4072 union spoolss_PrinterInfo **info,
4073 uint32_t *count)
4075 DEBUG(4,("enum_all_printers_info_5\n"));
4077 return enum_all_printers_info_level(mem_ctx, server_info, 5, flags, info, count);
4080 /****************************************************************
4081 _spoolss_EnumPrinters
4082 ****************************************************************/
4084 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4085 struct spoolss_EnumPrinters *r)
4087 const char *name = NULL;
4088 WERROR result;
4090 /* that's an [in out] buffer */
4092 if (!r->in.buffer && (r->in.offered != 0)) {
4093 return WERR_INVALID_PARAM;
4096 DEBUG(4,("_spoolss_EnumPrinters\n"));
4098 *r->out.needed = 0;
4099 *r->out.count = 0;
4100 *r->out.info = NULL;
4103 * Level 1:
4104 * flags==PRINTER_ENUM_NAME
4105 * if name=="" then enumerates all printers
4106 * if name!="" then enumerate the printer
4107 * flags==PRINTER_ENUM_REMOTE
4108 * name is NULL, enumerate printers
4109 * Level 2: name!="" enumerates printers, name can't be NULL
4110 * Level 3: doesn't exist
4111 * Level 4: does a local registry lookup
4112 * Level 5: same as Level 2
4115 if (r->in.server) {
4116 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4117 W_ERROR_HAVE_NO_MEMORY(name);
4120 switch (r->in.level) {
4121 case 0:
4122 result = enumprinters_level0(p->mem_ctx, p->server_info,
4123 r->in.flags, name,
4124 r->out.info, r->out.count);
4125 break;
4126 case 1:
4127 result = enumprinters_level1(p->mem_ctx, p->server_info,
4128 r->in.flags, name,
4129 r->out.info, r->out.count);
4130 break;
4131 case 2:
4132 result = enumprinters_level2(p->mem_ctx, p->server_info,
4133 r->in.flags, name,
4134 r->out.info, r->out.count);
4135 break;
4136 case 4:
4137 result = enumprinters_level4(p->mem_ctx, p->server_info,
4138 r->in.flags, name,
4139 r->out.info, r->out.count);
4140 break;
4141 case 5:
4142 result = enumprinters_level5(p->mem_ctx, p->server_info,
4143 r->in.flags, name,
4144 r->out.info, r->out.count);
4145 break;
4146 default:
4147 return WERR_UNKNOWN_LEVEL;
4150 if (!W_ERROR_IS_OK(result)) {
4151 return result;
4154 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4155 spoolss_EnumPrinters,
4156 *r->out.info, r->in.level,
4157 *r->out.count);
4158 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4159 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4161 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4164 /****************************************************************
4165 _spoolss_GetPrinter
4166 ****************************************************************/
4168 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4169 struct spoolss_GetPrinter *r)
4171 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4172 struct spoolss_PrinterInfo2 *info2 = NULL;
4173 WERROR result = WERR_OK;
4174 const char *servername = NULL;
4175 int snum;
4177 /* that's an [in out] buffer */
4179 if (!r->in.buffer && (r->in.offered != 0)) {
4180 return WERR_INVALID_PARAM;
4183 *r->out.needed = 0;
4185 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4186 return WERR_BADFID;
4189 if (Printer != NULL || Printer->servername != NULL) {
4190 servername = Printer->servername;
4193 result = winreg_get_printer(p->mem_ctx,
4194 p->server_info,
4195 servername,
4196 lp_const_servicename(snum),
4197 &info2);
4198 if (!W_ERROR_IS_OK(result)) {
4199 return result;
4202 switch (r->in.level) {
4203 case 0:
4204 result = construct_printer_info0(p->mem_ctx, p->server_info,
4205 info2,
4206 &r->out.info->info0, snum);
4207 break;
4208 case 1:
4209 result = construct_printer_info1(p->mem_ctx, info2,
4210 PRINTER_ENUM_ICON8,
4211 &r->out.info->info1, snum);
4212 break;
4213 case 2:
4214 result = construct_printer_info2(p->mem_ctx, info2,
4215 &r->out.info->info2, snum);
4216 break;
4217 case 3:
4218 result = construct_printer_info3(p->mem_ctx, info2,
4219 &r->out.info->info3, snum);
4220 break;
4221 case 4:
4222 result = construct_printer_info4(p->mem_ctx, info2,
4223 &r->out.info->info4, snum);
4224 break;
4225 case 5:
4226 result = construct_printer_info5(p->mem_ctx, info2,
4227 &r->out.info->info5, snum);
4228 break;
4229 case 6:
4230 result = construct_printer_info6(p->mem_ctx, info2,
4231 &r->out.info->info6, snum);
4232 break;
4233 case 7:
4234 result = construct_printer_info7(p->mem_ctx, Printer,
4235 &r->out.info->info7, snum);
4236 break;
4237 case 8:
4238 result = construct_printer_info8(p->mem_ctx, info2,
4239 &r->out.info->info8, snum);
4240 break;
4241 default:
4242 result = WERR_UNKNOWN_LEVEL;
4243 break;
4246 if (!W_ERROR_IS_OK(result)) {
4247 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4248 r->in.level, win_errstr(result)));
4249 TALLOC_FREE(r->out.info);
4250 return result;
4253 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4254 r->out.info, r->in.level);
4255 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4257 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4260 /********************************************************************
4261 ********************************************************************/
4263 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4264 do { \
4265 if (in && strlen(in)) { \
4266 out = talloc_strdup(mem_ctx, in); \
4267 } else { \
4268 out = talloc_strdup(mem_ctx, ""); \
4270 W_ERROR_HAVE_NO_MEMORY(out); \
4271 } while (0);
4273 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4274 do { \
4275 if (in && strlen(in)) { \
4276 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4277 } else { \
4278 out = talloc_strdup(mem_ctx, ""); \
4280 W_ERROR_HAVE_NO_MEMORY(out); \
4281 } while (0);
4283 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4284 const char **string_array,
4285 const char ***presult,
4286 const char *cservername,
4287 const char *arch,
4288 int version)
4290 int i, num_strings = 0;
4291 const char **array = NULL;
4293 if (string_array == NULL) {
4294 return WERR_INVALID_PARAMETER;;
4297 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4298 const char *str = NULL;
4300 if (cservername == NULL || arch == NULL) {
4301 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4302 } else {
4303 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4306 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4307 TALLOC_FREE(array);
4308 return WERR_NOMEM;
4312 if (i > 0) {
4313 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4314 &array, &num_strings);
4317 if (presult) {
4318 *presult = array;
4321 return WERR_OK;
4324 /********************************************************************
4325 * fill a spoolss_DriverInfo1 struct
4326 ********************************************************************/
4328 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4329 struct spoolss_DriverInfo1 *r,
4330 const struct spoolss_DriverInfo8 *driver,
4331 const char *servername)
4333 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4334 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4336 return WERR_OK;
4339 /********************************************************************
4340 * fill a spoolss_DriverInfo2 struct
4341 ********************************************************************/
4343 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4344 struct spoolss_DriverInfo2 *r,
4345 const struct spoolss_DriverInfo8 *driver,
4346 const char *servername)
4349 const char *cservername = canon_servername(servername);
4351 r->version = driver->version;
4353 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4354 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4355 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4356 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4358 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4359 driver->architecture,
4360 driver->version,
4361 driver->driver_path,
4362 r->driver_path);
4364 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4365 driver->architecture,
4366 driver->version,
4367 driver->data_file,
4368 r->data_file);
4370 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4371 driver->architecture,
4372 driver->version,
4373 driver->config_file,
4374 r->config_file);
4376 return WERR_OK;
4379 /********************************************************************
4380 * fill a spoolss_DriverInfo3 struct
4381 ********************************************************************/
4383 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4384 struct spoolss_DriverInfo3 *r,
4385 const struct spoolss_DriverInfo8 *driver,
4386 const char *servername)
4388 const char *cservername = canon_servername(servername);
4390 r->version = driver->version;
4392 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4393 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4394 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4395 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4397 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4398 driver->architecture,
4399 driver->version,
4400 driver->driver_path,
4401 r->driver_path);
4403 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4404 driver->architecture,
4405 driver->version,
4406 driver->data_file,
4407 r->data_file);
4409 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4410 driver->architecture,
4411 driver->version,
4412 driver->config_file,
4413 r->config_file);
4415 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4416 driver->architecture,
4417 driver->version,
4418 driver->help_file,
4419 r->help_file);
4421 FILL_DRIVER_STRING(mem_ctx,
4422 driver->monitor_name,
4423 r->monitor_name);
4425 FILL_DRIVER_STRING(mem_ctx,
4426 driver->default_datatype,
4427 r->default_datatype);
4429 return string_array_from_driver_info(mem_ctx,
4430 driver->dependent_files,
4431 &r->dependent_files,
4432 cservername,
4433 driver->architecture,
4434 driver->version);
4437 /********************************************************************
4438 * fill a spoolss_DriverInfo4 struct
4439 ********************************************************************/
4441 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4442 struct spoolss_DriverInfo4 *r,
4443 const struct spoolss_DriverInfo8 *driver,
4444 const char *servername)
4446 const char *cservername = canon_servername(servername);
4447 WERROR result;
4449 r->version = driver->version;
4451 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4452 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4453 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4454 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4456 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4457 driver->architecture,
4458 driver->version,
4459 driver->driver_path,
4460 r->driver_path);
4462 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4463 driver->architecture,
4464 driver->version,
4465 driver->data_file,
4466 r->data_file);
4468 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4469 driver->architecture,
4470 driver->version,
4471 driver->config_file,
4472 r->config_file);
4474 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4475 driver->architecture,
4476 driver->version,
4477 driver->help_file,
4478 r->help_file);
4480 result = string_array_from_driver_info(mem_ctx,
4481 driver->dependent_files,
4482 &r->dependent_files,
4483 cservername,
4484 driver->architecture,
4485 driver->version);
4486 if (!W_ERROR_IS_OK(result)) {
4487 return result;
4490 FILL_DRIVER_STRING(mem_ctx,
4491 driver->monitor_name,
4492 r->monitor_name);
4494 FILL_DRIVER_STRING(mem_ctx,
4495 driver->default_datatype,
4496 r->default_datatype);
4499 result = string_array_from_driver_info(mem_ctx,
4500 driver->previous_names,
4501 &r->previous_names,
4502 NULL, NULL, 0);
4504 return result;
4507 /********************************************************************
4508 * fill a spoolss_DriverInfo5 struct
4509 ********************************************************************/
4511 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4512 struct spoolss_DriverInfo5 *r,
4513 const struct spoolss_DriverInfo8 *driver,
4514 const char *servername)
4516 const char *cservername = canon_servername(servername);
4518 r->version = driver->version;
4520 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4521 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4522 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4523 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4525 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4526 driver->architecture,
4527 driver->version,
4528 driver->driver_path,
4529 r->driver_path);
4531 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4532 driver->architecture,
4533 driver->version,
4534 driver->data_file,
4535 r->data_file);
4537 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4538 driver->architecture,
4539 driver->version,
4540 driver->config_file,
4541 r->config_file);
4543 r->driver_attributes = 0;
4544 r->config_version = 0;
4545 r->driver_version = 0;
4547 return WERR_OK;
4549 /********************************************************************
4550 * fill a spoolss_DriverInfo6 struct
4551 ********************************************************************/
4553 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4554 struct spoolss_DriverInfo6 *r,
4555 const struct spoolss_DriverInfo8 *driver,
4556 const char *servername)
4558 const char *cservername = canon_servername(servername);
4559 WERROR result;
4561 r->version = driver->version;
4563 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4564 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4565 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4566 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4568 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4569 driver->architecture,
4570 driver->version,
4571 driver->driver_path,
4572 r->driver_path);
4574 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4575 driver->architecture,
4576 driver->version,
4577 driver->data_file,
4578 r->data_file);
4580 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4581 driver->architecture,
4582 driver->version,
4583 driver->config_file,
4584 r->config_file);
4586 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4587 driver->architecture,
4588 driver->version,
4589 driver->help_file,
4590 r->help_file);
4592 FILL_DRIVER_STRING(mem_ctx,
4593 driver->monitor_name,
4594 r->monitor_name);
4596 FILL_DRIVER_STRING(mem_ctx,
4597 driver->default_datatype,
4598 r->default_datatype);
4600 result = string_array_from_driver_info(mem_ctx,
4601 driver->dependent_files,
4602 &r->dependent_files,
4603 cservername,
4604 driver->architecture,
4605 driver->version);
4606 if (!W_ERROR_IS_OK(result)) {
4607 return result;
4610 result = string_array_from_driver_info(mem_ctx,
4611 driver->previous_names,
4612 &r->previous_names,
4613 NULL, NULL, 0);
4614 if (!W_ERROR_IS_OK(result)) {
4615 return result;
4618 r->driver_date = driver->driver_date;
4619 r->driver_version = driver->driver_version;
4621 FILL_DRIVER_STRING(mem_ctx,
4622 driver->manufacturer_name,
4623 r->manufacturer_name);
4624 FILL_DRIVER_STRING(mem_ctx,
4625 driver->manufacturer_url,
4626 r->manufacturer_url);
4627 FILL_DRIVER_STRING(mem_ctx,
4628 driver->hardware_id,
4629 r->hardware_id);
4630 FILL_DRIVER_STRING(mem_ctx,
4631 driver->provider,
4632 r->provider);
4634 return WERR_OK;
4637 /********************************************************************
4638 * fill a spoolss_DriverInfo8 struct
4639 ********************************************************************/
4641 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
4642 struct spoolss_DriverInfo8 *r,
4643 const struct spoolss_DriverInfo8 *driver,
4644 const char *servername)
4646 const char *cservername = canon_servername(servername);
4647 WERROR result;
4649 r->version = driver->version;
4651 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4652 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4653 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4654 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4656 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4657 driver->architecture,
4658 driver->version,
4659 driver->driver_path,
4660 r->driver_path);
4662 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4663 driver->architecture,
4664 driver->version,
4665 driver->data_file,
4666 r->data_file);
4668 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4669 driver->architecture,
4670 driver->version,
4671 driver->config_file,
4672 r->config_file);
4674 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4675 driver->architecture,
4676 driver->version,
4677 driver->help_file,
4678 r->help_file);
4680 FILL_DRIVER_STRING(mem_ctx,
4681 driver->monitor_name,
4682 r->monitor_name);
4684 FILL_DRIVER_STRING(mem_ctx,
4685 driver->default_datatype,
4686 r->default_datatype);
4688 result = string_array_from_driver_info(mem_ctx,
4689 driver->dependent_files,
4690 &r->dependent_files,
4691 cservername,
4692 driver->architecture,
4693 driver->version);
4694 if (!W_ERROR_IS_OK(result)) {
4695 return result;
4698 result = string_array_from_driver_info(mem_ctx,
4699 driver->previous_names,
4700 &r->previous_names,
4701 NULL, NULL, 0);
4702 if (!W_ERROR_IS_OK(result)) {
4703 return result;
4706 r->driver_date = driver->driver_date;
4707 r->driver_version = driver->driver_version;
4709 FILL_DRIVER_STRING(mem_ctx,
4710 driver->manufacturer_name,
4711 r->manufacturer_name);
4712 FILL_DRIVER_STRING(mem_ctx,
4713 driver->manufacturer_url,
4714 r->manufacturer_url);
4715 FILL_DRIVER_STRING(mem_ctx,
4716 driver->hardware_id,
4717 r->hardware_id);
4718 FILL_DRIVER_STRING(mem_ctx,
4719 driver->provider,
4720 r->provider);
4722 FILL_DRIVER_STRING(mem_ctx,
4723 driver->print_processor,
4724 r->print_processor);
4725 FILL_DRIVER_STRING(mem_ctx,
4726 driver->vendor_setup,
4727 r->vendor_setup);
4729 result = string_array_from_driver_info(mem_ctx,
4730 driver->color_profiles,
4731 &r->color_profiles,
4732 NULL, NULL, 0);
4733 if (!W_ERROR_IS_OK(result)) {
4734 return result;
4737 FILL_DRIVER_STRING(mem_ctx,
4738 driver->inf_path,
4739 r->inf_path);
4741 r->printer_driver_attributes = driver->printer_driver_attributes;
4743 result = string_array_from_driver_info(mem_ctx,
4744 driver->core_driver_dependencies,
4745 &r->core_driver_dependencies,
4746 NULL, NULL, 0);
4747 if (!W_ERROR_IS_OK(result)) {
4748 return result;
4751 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
4752 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
4754 return WERR_OK;
4757 #if 0 /* disabled until marshalling issues are resolved - gd */
4758 /********************************************************************
4759 ********************************************************************/
4761 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
4762 struct spoolss_DriverFileInfo *r,
4763 const char *cservername,
4764 const char *file_name,
4765 enum spoolss_DriverFileType file_type,
4766 uint32_t file_version)
4768 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
4769 cservername, file_name);
4770 W_ERROR_HAVE_NO_MEMORY(r->file_name);
4771 r->file_type = file_type;
4772 r->file_version = file_version;
4774 return WERR_OK;
4777 /********************************************************************
4778 ********************************************************************/
4780 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
4781 const struct spoolss_DriverInfo8 *driver,
4782 const char *cservername,
4783 struct spoolss_DriverFileInfo **info_p,
4784 uint32_t *count_p)
4786 struct spoolss_DriverFileInfo *info = NULL;
4787 uint32_t count = 0;
4788 WERROR result;
4789 uint32_t i;
4791 *info_p = NULL;
4792 *count_p = 0;
4794 if (strlen(driver->driver_path)) {
4795 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4796 struct spoolss_DriverFileInfo,
4797 count + 1);
4798 W_ERROR_HAVE_NO_MEMORY(info);
4799 result = fill_spoolss_DriverFileInfo(info,
4800 &info[count],
4801 cservername,
4802 driver->driver_path,
4803 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
4805 W_ERROR_NOT_OK_RETURN(result);
4806 count++;
4809 if (strlen(driver->config_file)) {
4810 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4811 struct spoolss_DriverFileInfo,
4812 count + 1);
4813 W_ERROR_HAVE_NO_MEMORY(info);
4814 result = fill_spoolss_DriverFileInfo(info,
4815 &info[count],
4816 cservername,
4817 driver->config_file,
4818 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
4820 W_ERROR_NOT_OK_RETURN(result);
4821 count++;
4824 if (strlen(driver->data_file)) {
4825 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4826 struct spoolss_DriverFileInfo,
4827 count + 1);
4828 W_ERROR_HAVE_NO_MEMORY(info);
4829 result = fill_spoolss_DriverFileInfo(info,
4830 &info[count],
4831 cservername,
4832 driver->data_file,
4833 SPOOLSS_DRIVER_FILE_TYPE_DATA,
4835 W_ERROR_NOT_OK_RETURN(result);
4836 count++;
4839 if (strlen(driver->help_file)) {
4840 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4841 struct spoolss_DriverFileInfo,
4842 count + 1);
4843 W_ERROR_HAVE_NO_MEMORY(info);
4844 result = fill_spoolss_DriverFileInfo(info,
4845 &info[count],
4846 cservername,
4847 driver->help_file,
4848 SPOOLSS_DRIVER_FILE_TYPE_HELP,
4850 W_ERROR_NOT_OK_RETURN(result);
4851 count++;
4854 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
4855 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4856 struct spoolss_DriverFileInfo,
4857 count + 1);
4858 W_ERROR_HAVE_NO_MEMORY(info);
4859 result = fill_spoolss_DriverFileInfo(info,
4860 &info[count],
4861 cservername,
4862 driver->dependent_files[i],
4863 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
4865 W_ERROR_NOT_OK_RETURN(result);
4866 count++;
4869 *info_p = info;
4870 *count_p = count;
4872 return WERR_OK;
4875 /********************************************************************
4876 * fill a spoolss_DriverInfo101 struct
4877 ********************************************************************/
4879 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
4880 struct spoolss_DriverInfo101 *r,
4881 const struct spoolss_DriverInfo8 *driver,
4882 const char *servername)
4884 const char *cservername = canon_servername(servername);
4885 WERROR result;
4887 r->version = driver->version;
4889 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4890 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4891 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4892 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4894 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
4895 cservername,
4896 &r->file_info,
4897 &r->file_count);
4898 if (!W_ERROR_IS_OK(result)) {
4899 return result;
4902 FILL_DRIVER_STRING(mem_ctx,
4903 driver->monitor_name,
4904 r->monitor_name);
4906 FILL_DRIVER_STRING(mem_ctx,
4907 driver->default_datatype,
4908 r->default_datatype);
4910 result = string_array_from_driver_info(mem_ctx,
4911 driver->previous_names,
4912 &r->previous_names,
4913 NULL, NULL, 0);
4914 if (!W_ERROR_IS_OK(result)) {
4915 return result;
4918 r->driver_date = driver->driver_date;
4919 r->driver_version = driver->driver_version;
4921 FILL_DRIVER_STRING(mem_ctx,
4922 driver->manufacturer_name,
4923 r->manufacturer_name);
4924 FILL_DRIVER_STRING(mem_ctx,
4925 driver->manufacturer_url,
4926 r->manufacturer_url);
4927 FILL_DRIVER_STRING(mem_ctx,
4928 driver->hardware_id,
4929 r->hardware_id);
4930 FILL_DRIVER_STRING(mem_ctx,
4931 driver->provider,
4932 r->provider);
4934 return WERR_OK;
4936 #endif
4937 /********************************************************************
4938 ********************************************************************/
4940 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
4941 struct auth_serversupplied_info *server_info,
4942 uint32_t level,
4943 union spoolss_DriverInfo *r,
4944 int snum,
4945 const char *servername,
4946 const char *architecture,
4947 uint32_t version)
4949 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
4950 struct spoolss_DriverInfo8 *driver;
4951 WERROR result;
4953 result = winreg_get_printer(mem_ctx,
4954 server_info,
4955 servername,
4956 lp_const_servicename(snum),
4957 &pinfo2);
4959 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
4960 win_errstr(result)));
4962 if (!W_ERROR_IS_OK(result)) {
4963 return WERR_INVALID_PRINTER_NAME;
4966 result = winreg_get_driver(mem_ctx, server_info, architecture,
4967 pinfo2->drivername, version, &driver);
4969 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
4970 win_errstr(result)));
4972 if (!W_ERROR_IS_OK(result)) {
4974 * Is this a W2k client ?
4977 if (version < 3) {
4978 talloc_free(pinfo2);
4979 return WERR_UNKNOWN_PRINTER_DRIVER;
4982 /* Yes - try again with a WinNT driver. */
4983 version = 2;
4984 result = winreg_get_driver(mem_ctx, server_info, architecture,
4985 pinfo2->drivername,
4986 version, &driver);
4987 DEBUG(8,("construct_printer_driver_level: status: %s\n",
4988 win_errstr(result)));
4989 if (!W_ERROR_IS_OK(result)) {
4990 talloc_free(pinfo2);
4991 return WERR_UNKNOWN_PRINTER_DRIVER;
4995 switch (level) {
4996 case 1:
4997 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
4998 break;
4999 case 2:
5000 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5001 break;
5002 case 3:
5003 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5004 break;
5005 case 4:
5006 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5007 break;
5008 case 5:
5009 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5010 break;
5011 case 6:
5012 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5013 break;
5014 case 8:
5015 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5016 break;
5017 #if 0 /* disabled until marshalling issues are resolved - gd */
5018 case 101:
5019 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5020 break;
5021 #endif
5022 default:
5023 result = WERR_UNKNOWN_LEVEL;
5024 break;
5027 talloc_free(pinfo2);
5028 talloc_free(driver);
5030 return result;
5033 /****************************************************************
5034 _spoolss_GetPrinterDriver2
5035 ****************************************************************/
5037 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5038 struct spoolss_GetPrinterDriver2 *r)
5040 Printer_entry *printer;
5041 WERROR result;
5043 int snum;
5045 /* that's an [in out] buffer */
5047 if (!r->in.buffer && (r->in.offered != 0)) {
5048 return WERR_INVALID_PARAM;
5051 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5053 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5054 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5055 return WERR_INVALID_PRINTER_NAME;
5058 *r->out.needed = 0;
5059 *r->out.server_major_version = 0;
5060 *r->out.server_minor_version = 0;
5062 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5063 return WERR_BADFID;
5066 result = construct_printer_driver_info_level(p->mem_ctx, p->server_info,
5067 r->in.level, r->out.info,
5068 snum, printer->servername,
5069 r->in.architecture,
5070 r->in.client_major_version);
5071 if (!W_ERROR_IS_OK(result)) {
5072 TALLOC_FREE(r->out.info);
5073 return result;
5076 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5077 r->out.info, r->in.level);
5078 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5080 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5084 /****************************************************************
5085 _spoolss_StartPagePrinter
5086 ****************************************************************/
5088 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5089 struct spoolss_StartPagePrinter *r)
5091 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5093 if (!Printer) {
5094 DEBUG(3,("_spoolss_StartPagePrinter: "
5095 "Error in startpageprinter printer handle\n"));
5096 return WERR_BADFID;
5099 Printer->page_started = true;
5100 return WERR_OK;
5103 /****************************************************************
5104 _spoolss_EndPagePrinter
5105 ****************************************************************/
5107 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5108 struct spoolss_EndPagePrinter *r)
5110 int snum;
5112 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5114 if (!Printer) {
5115 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5116 OUR_HANDLE(r->in.handle)));
5117 return WERR_BADFID;
5120 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5121 return WERR_BADFID;
5123 Printer->page_started = false;
5124 print_job_endpage(snum, Printer->jobid);
5126 return WERR_OK;
5129 /****************************************************************
5130 _spoolss_StartDocPrinter
5131 ****************************************************************/
5133 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5134 struct spoolss_StartDocPrinter *r)
5136 struct spoolss_DocumentInfo1 *info_1;
5137 int snum;
5138 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5139 WERROR werr;
5141 if (!Printer) {
5142 DEBUG(2,("_spoolss_StartDocPrinter: "
5143 "Invalid handle (%s:%u:%u)\n",
5144 OUR_HANDLE(r->in.handle)));
5145 return WERR_BADFID;
5148 if (Printer->jobid) {
5149 DEBUG(2, ("_spoolss_StartDocPrinter: "
5150 "StartDocPrinter called twice! "
5151 "(existing jobid = %d)\n", Printer->jobid));
5152 return WERR_INVALID_HANDLE;
5155 if (r->in.level != 1) {
5156 return WERR_UNKNOWN_LEVEL;
5159 info_1 = r->in.info.info1;
5162 * a nice thing with NT is it doesn't listen to what you tell it.
5163 * when asked to send _only_ RAW datas, it tries to send datas
5164 * in EMF format.
5166 * So I add checks like in NT Server ...
5169 if (info_1->datatype) {
5170 if (strcmp(info_1->datatype, "RAW") != 0) {
5171 *r->out.job_id = 0;
5172 return WERR_INVALID_DATATYPE;
5176 /* get the share number of the printer */
5177 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5178 return WERR_BADFID;
5181 werr = print_job_start(p->server_info, snum,
5182 info_1->document_name, info_1->output_file,
5183 Printer->devmode, &Printer->jobid);
5185 /* An error occured in print_job_start() so return an appropriate
5186 NT error code. */
5188 if (!W_ERROR_IS_OK(werr)) {
5189 return werr;
5192 Printer->document_started = true;
5193 *r->out.job_id = Printer->jobid;
5195 return WERR_OK;
5198 /****************************************************************
5199 _spoolss_EndDocPrinter
5200 ****************************************************************/
5202 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5203 struct spoolss_EndDocPrinter *r)
5205 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5206 NTSTATUS status;
5207 int snum;
5209 if (!Printer) {
5210 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5211 OUR_HANDLE(r->in.handle)));
5212 return WERR_BADFID;
5215 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5216 return WERR_BADFID;
5219 Printer->document_started = false;
5220 status = print_job_end(snum, Printer->jobid, NORMAL_CLOSE);
5221 if (!NT_STATUS_IS_OK(status)) {
5222 DEBUG(2, ("_spoolss_EndDocPrinter: "
5223 "print_job_end failed [%s]\n",
5224 nt_errstr(status)));
5227 Printer->jobid = 0;
5228 return ntstatus_to_werror(status);
5231 /****************************************************************
5232 _spoolss_WritePrinter
5233 ****************************************************************/
5235 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5236 struct spoolss_WritePrinter *r)
5238 ssize_t buffer_written;
5239 int snum;
5240 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5242 if (!Printer) {
5243 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5244 OUR_HANDLE(r->in.handle)));
5245 *r->out.num_written = r->in._data_size;
5246 return WERR_BADFID;
5249 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5250 return WERR_BADFID;
5252 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5253 buffer_written = print_job_write(snum, Printer->jobid,
5254 (const char *)r->in.data.data,
5255 (SMB_OFF_T)-1,
5256 (size_t)r->in._data_size);
5257 if (buffer_written == (ssize_t)-1) {
5258 *r->out.num_written = 0;
5259 if (errno == ENOSPC)
5260 return WERR_NO_SPOOL_SPACE;
5261 else
5262 return WERR_ACCESS_DENIED;
5265 *r->out.num_written = r->in._data_size;
5267 return WERR_OK;
5270 /********************************************************************
5271 * api_spoolss_getprinter
5272 * called from the spoolss dispatcher
5274 ********************************************************************/
5276 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5277 struct pipes_struct *p)
5279 int snum;
5280 WERROR errcode = WERR_BADFUNC;
5281 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5283 if (!Printer) {
5284 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5285 OUR_HANDLE(handle)));
5286 return WERR_BADFID;
5289 if (!get_printer_snum(p, handle, &snum, NULL))
5290 return WERR_BADFID;
5292 switch (command) {
5293 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5294 errcode = print_queue_pause(p->server_info, snum);
5295 break;
5296 case SPOOLSS_PRINTER_CONTROL_RESUME:
5297 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5298 errcode = print_queue_resume(p->server_info, snum);
5299 break;
5300 case SPOOLSS_PRINTER_CONTROL_PURGE:
5301 errcode = print_queue_purge(p->server_info, snum);
5302 break;
5303 default:
5304 return WERR_UNKNOWN_LEVEL;
5307 return errcode;
5311 /****************************************************************
5312 _spoolss_AbortPrinter
5313 * From MSDN: "Deletes printer's spool file if printer is configured
5314 * for spooling"
5315 ****************************************************************/
5317 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5318 struct spoolss_AbortPrinter *r)
5320 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5321 int snum;
5322 WERROR errcode = WERR_OK;
5324 if (!Printer) {
5325 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5326 OUR_HANDLE(r->in.handle)));
5327 return WERR_BADFID;
5330 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5331 return WERR_BADFID;
5333 if (!Printer->document_started) {
5334 return WERR_SPL_NO_STARTDOC;
5337 errcode = print_job_delete(p->server_info, snum, Printer->jobid);
5339 return errcode;
5342 /********************************************************************
5343 * called by spoolss_api_setprinter
5344 * when updating a printer description
5345 ********************************************************************/
5347 static WERROR update_printer_sec(struct policy_handle *handle,
5348 struct pipes_struct *p,
5349 struct sec_desc_buf *secdesc_ctr)
5351 struct spoolss_security_descriptor *new_secdesc = NULL;
5352 struct spoolss_security_descriptor *old_secdesc = NULL;
5353 const char *printer;
5354 WERROR result;
5355 int snum;
5357 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5359 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5360 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5361 OUR_HANDLE(handle)));
5363 result = WERR_BADFID;
5364 goto done;
5367 if (secdesc_ctr == NULL) {
5368 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5369 result = WERR_INVALID_PARAM;
5370 goto done;
5372 printer = lp_const_servicename(snum);
5374 /* Check the user has permissions to change the security
5375 descriptor. By experimentation with two NT machines, the user
5376 requires Full Access to the printer to change security
5377 information. */
5379 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5380 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5381 result = WERR_ACCESS_DENIED;
5382 goto done;
5385 /* NT seems to like setting the security descriptor even though
5386 nothing may have actually changed. */
5387 result = winreg_get_printer_secdesc(p->mem_ctx,
5388 p->server_info,
5389 printer,
5390 &old_secdesc);
5391 if (!W_ERROR_IS_OK(result)) {
5392 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5393 result = WERR_BADFID;
5394 goto done;
5397 if (DEBUGLEVEL >= 10) {
5398 struct security_acl *the_acl;
5399 int i;
5401 the_acl = old_secdesc->dacl;
5402 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5403 printer, the_acl->num_aces));
5405 for (i = 0; i < the_acl->num_aces; i++) {
5406 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5407 &the_acl->aces[i].trustee),
5408 the_acl->aces[i].access_mask));
5411 the_acl = secdesc_ctr->sd->dacl;
5413 if (the_acl) {
5414 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5415 printer, the_acl->num_aces));
5417 for (i = 0; i < the_acl->num_aces; i++) {
5418 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5419 &the_acl->aces[i].trustee),
5420 the_acl->aces[i].access_mask));
5422 } else {
5423 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5427 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
5428 if (new_secdesc == NULL) {
5429 result = WERR_NOMEM;
5430 goto done;
5433 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
5434 result = WERR_OK;
5435 goto done;
5438 result = winreg_set_printer_secdesc(p->mem_ctx,
5439 p->server_info,
5440 printer,
5441 new_secdesc);
5443 done:
5444 return result;
5447 /********************************************************************
5448 Canonicalize printer info from a client
5449 ********************************************************************/
5451 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
5452 struct spoolss_SetPrinterInfo2 *info2,
5453 int snum)
5455 fstring printername;
5456 const char *p;
5458 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5459 "portname=%s drivername=%s comment=%s location=%s\n",
5460 info2->servername, info2->printername, info2->sharename,
5461 info2->portname, info2->drivername, info2->comment,
5462 info2->location));
5464 /* we force some elements to "correct" values */
5465 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
5466 if (info2->servername == NULL) {
5467 return false;
5469 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
5470 if (info2->sharename == NULL) {
5471 return false;
5474 /* check to see if we allow printername != sharename */
5475 if (lp_force_printername(snum)) {
5476 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5477 global_myname(), info2->sharename);
5478 } else {
5479 /* make sure printername is in \\server\printername format */
5480 fstrcpy(printername, info2->printername);
5481 p = printername;
5482 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5483 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5484 p++;
5487 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5488 global_myname(), p);
5490 if (info2->printername == NULL) {
5491 return false;
5494 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5495 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5497 return true;
5500 /****************************************************************************
5501 ****************************************************************************/
5503 static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri)
5505 char *cmd = lp_addport_cmd();
5506 char *command = NULL;
5507 int ret;
5508 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5509 bool is_print_op = false;
5511 if ( !*cmd ) {
5512 return WERR_ACCESS_DENIED;
5515 command = talloc_asprintf(ctx,
5516 "%s \"%s\" \"%s\"", cmd, portname, uri );
5517 if (!command) {
5518 return WERR_NOMEM;
5521 if ( token )
5522 is_print_op = user_has_privileges( token, &se_printop );
5524 DEBUG(10,("Running [%s]\n", command));
5526 /********* BEGIN SePrintOperatorPrivilege **********/
5528 if ( is_print_op )
5529 become_root();
5531 ret = smbrun(command, NULL);
5533 if ( is_print_op )
5534 unbecome_root();
5536 /********* END SePrintOperatorPrivilege **********/
5538 DEBUGADD(10,("returned [%d]\n", ret));
5540 TALLOC_FREE(command);
5542 if ( ret != 0 ) {
5543 return WERR_ACCESS_DENIED;
5546 return WERR_OK;
5549 /****************************************************************************
5550 ****************************************************************************/
5552 bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
5553 struct spoolss_SetPrinterInfo2 *info2,
5554 const char *remote_machine)
5556 char *cmd = lp_addprinter_cmd();
5557 char **qlines;
5558 char *command = NULL;
5559 int numlines;
5560 int ret;
5561 int fd;
5562 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5563 bool is_print_op = false;
5565 if (!remote_machine) {
5566 return false;
5569 command = talloc_asprintf(ctx,
5570 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5571 cmd, info2->printername, info2->sharename,
5572 info2->portname, info2->drivername,
5573 info2->location, info2->comment, remote_machine);
5574 if (!command) {
5575 return false;
5578 if ( token )
5579 is_print_op = user_has_privileges( token, &se_printop );
5581 DEBUG(10,("Running [%s]\n", command));
5583 /********* BEGIN SePrintOperatorPrivilege **********/
5585 if ( is_print_op )
5586 become_root();
5588 if ( (ret = smbrun(command, &fd)) == 0 ) {
5589 /* Tell everyone we updated smb.conf. */
5590 message_send_all(smbd_messaging_context(),
5591 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5594 if ( is_print_op )
5595 unbecome_root();
5597 /********* END SePrintOperatorPrivilege **********/
5599 DEBUGADD(10,("returned [%d]\n", ret));
5601 TALLOC_FREE(command);
5603 if ( ret != 0 ) {
5604 if (fd != -1)
5605 close(fd);
5606 return false;
5609 /* reload our services immediately */
5610 become_root();
5611 reload_services(false);
5612 unbecome_root();
5614 numlines = 0;
5615 /* Get lines and convert them back to dos-codepage */
5616 qlines = fd_lines_load(fd, &numlines, 0, NULL);
5617 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
5618 close(fd);
5620 /* Set the portname to what the script says the portname should be. */
5621 /* but don't require anything to be return from the script exit a good error code */
5623 if (numlines) {
5624 /* Set the portname to what the script says the portname should be. */
5625 info2->portname = talloc_strdup(ctx, qlines[0]);
5626 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
5629 TALLOC_FREE(qlines);
5630 return true;
5633 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
5634 struct auth_serversupplied_info *server_info,
5635 int snum,
5636 struct spoolss_SetPrinterInfo2 *printer,
5637 struct spoolss_PrinterInfo2 *old_printer)
5639 bool force_update = (old_printer == NULL);
5640 const char *dnsdomname;
5641 const char *longname;
5642 const char *uncname;
5643 const char *spooling;
5644 DATA_BLOB buffer;
5645 WERROR result = WERR_OK;
5647 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
5648 push_reg_sz(mem_ctx, &buffer, printer->drivername);
5649 winreg_set_printer_dataex(mem_ctx,
5650 server_info,
5651 printer->sharename,
5652 SPOOL_DSSPOOLER_KEY,
5653 SPOOL_REG_DRIVERNAME,
5654 REG_SZ,
5655 buffer.data,
5656 buffer.length);
5658 if (!force_update) {
5659 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
5660 printer->drivername));
5662 notify_printer_driver(snum, printer->drivername);
5666 if (force_update || !strequal(printer->comment, old_printer->comment)) {
5667 push_reg_sz(mem_ctx, &buffer, printer->comment);
5668 winreg_set_printer_dataex(mem_ctx,
5669 server_info,
5670 printer->sharename,
5671 SPOOL_DSSPOOLER_KEY,
5672 SPOOL_REG_DESCRIPTION,
5673 REG_SZ,
5674 buffer.data,
5675 buffer.length);
5677 if (!force_update) {
5678 notify_printer_comment(snum, printer->comment);
5682 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
5683 push_reg_sz(mem_ctx, &buffer, printer->sharename);
5684 winreg_set_printer_dataex(mem_ctx,
5685 server_info,
5686 printer->sharename,
5687 SPOOL_DSSPOOLER_KEY,
5688 SPOOL_REG_PRINTSHARENAME,
5689 REG_SZ,
5690 buffer.data,
5691 buffer.length);
5693 if (!force_update) {
5694 notify_printer_sharename(snum, printer->sharename);
5698 if (force_update || !strequal(printer->printername, old_printer->printername)) {
5699 const char *p;
5701 p = strrchr(printer->printername, '\\' );
5702 if (p != NULL) {
5703 p++;
5704 } else {
5705 p = printer->printername;
5708 push_reg_sz(mem_ctx, &buffer, p);
5709 winreg_set_printer_dataex(mem_ctx,
5710 server_info,
5711 printer->sharename,
5712 SPOOL_DSSPOOLER_KEY,
5713 SPOOL_REG_PRINTERNAME,
5714 REG_SZ,
5715 buffer.data,
5716 buffer.length);
5718 if (!force_update) {
5719 notify_printer_printername(snum, p);
5723 if (force_update || !strequal(printer->portname, old_printer->portname)) {
5724 push_reg_sz(mem_ctx, &buffer, printer->portname);
5725 winreg_set_printer_dataex(mem_ctx,
5726 server_info,
5727 printer->sharename,
5728 SPOOL_DSSPOOLER_KEY,
5729 SPOOL_REG_PORTNAME,
5730 REG_SZ,
5731 buffer.data,
5732 buffer.length);
5734 if (!force_update) {
5735 notify_printer_port(snum, printer->portname);
5739 if (force_update || !strequal(printer->location, old_printer->location)) {
5740 push_reg_sz(mem_ctx, &buffer, printer->location);
5741 winreg_set_printer_dataex(mem_ctx,
5742 server_info,
5743 printer->sharename,
5744 SPOOL_DSSPOOLER_KEY,
5745 SPOOL_REG_LOCATION,
5746 REG_SZ,
5747 buffer.data,
5748 buffer.length);
5750 if (!force_update) {
5751 notify_printer_location(snum, printer->location);
5755 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
5756 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
5757 winreg_set_printer_dataex(mem_ctx,
5758 server_info,
5759 printer->sharename,
5760 SPOOL_DSSPOOLER_KEY,
5761 SPOOL_REG_PRINTSEPARATORFILE,
5762 REG_SZ,
5763 buffer.data,
5764 buffer.length);
5766 if (!force_update) {
5767 notify_printer_location(snum, printer->location);
5771 if (force_update || printer->starttime != old_printer->starttime) {
5772 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5773 SIVAL(buffer.data, 0, printer->starttime);
5774 winreg_set_printer_dataex(mem_ctx,
5775 server_info,
5776 printer->sharename,
5777 SPOOL_DSSPOOLER_KEY,
5778 SPOOL_REG_PRINTSTARTTIME,
5779 REG_DWORD,
5780 buffer.data,
5781 buffer.length);
5784 if (force_update || printer->untiltime != old_printer->untiltime) {
5785 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5786 SIVAL(buffer.data, 0, printer->untiltime);
5787 winreg_set_printer_dataex(mem_ctx,
5788 server_info,
5789 printer->sharename,
5790 SPOOL_DSSPOOLER_KEY,
5791 SPOOL_REG_PRINTENDTIME,
5792 REG_DWORD,
5793 buffer.data,
5794 buffer.length);
5797 if (force_update || printer->priority != old_printer->priority) {
5798 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5799 SIVAL(buffer.data, 0, printer->priority);
5800 winreg_set_printer_dataex(mem_ctx,
5801 server_info,
5802 printer->sharename,
5803 SPOOL_DSSPOOLER_KEY,
5804 SPOOL_REG_PRIORITY,
5805 REG_DWORD,
5806 buffer.data,
5807 buffer.length);
5810 if (force_update || printer->attributes != old_printer->attributes) {
5811 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5812 SIVAL(buffer.data, 0, (printer->attributes &
5813 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
5814 winreg_set_printer_dataex(mem_ctx,
5815 server_info,
5816 printer->sharename,
5817 SPOOL_DSSPOOLER_KEY,
5818 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
5819 REG_DWORD,
5820 buffer.data,
5821 buffer.length);
5823 switch (printer->attributes & 0x3) {
5824 case 0:
5825 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
5826 break;
5827 case 1:
5828 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
5829 break;
5830 case 2:
5831 spooling = SPOOL_REGVAL_PRINTDIRECT;
5832 break;
5833 default:
5834 spooling = "unknown";
5836 push_reg_sz(mem_ctx, &buffer, spooling);
5837 winreg_set_printer_dataex(mem_ctx,
5838 server_info,
5839 printer->sharename,
5840 SPOOL_DSSPOOLER_KEY,
5841 SPOOL_REG_PRINTSPOOLING,
5842 REG_SZ,
5843 buffer.data,
5844 buffer.length);
5847 push_reg_sz(mem_ctx, &buffer, global_myname());
5848 winreg_set_printer_dataex(mem_ctx,
5849 server_info,
5850 printer->sharename,
5851 SPOOL_DSSPOOLER_KEY,
5852 SPOOL_REG_SHORTSERVERNAME,
5853 REG_SZ,
5854 buffer.data,
5855 buffer.length);
5857 dnsdomname = get_mydnsfullname();
5858 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
5859 longname = talloc_strdup(mem_ctx, dnsdomname);
5860 } else {
5861 longname = talloc_strdup(mem_ctx, global_myname());
5863 if (longname == NULL) {
5864 result = WERR_NOMEM;
5865 goto done;
5868 push_reg_sz(mem_ctx, &buffer, longname);
5869 winreg_set_printer_dataex(mem_ctx,
5870 server_info,
5871 printer->sharename,
5872 SPOOL_DSSPOOLER_KEY,
5873 SPOOL_REG_SERVERNAME,
5874 REG_SZ,
5875 buffer.data,
5876 buffer.length);
5878 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5879 global_myname(), printer->sharename);
5880 push_reg_sz(mem_ctx, &buffer, uncname);
5881 winreg_set_printer_dataex(mem_ctx,
5882 server_info,
5883 printer->sharename,
5884 SPOOL_DSSPOOLER_KEY,
5885 SPOOL_REG_UNCNAME,
5886 REG_SZ,
5887 buffer.data,
5888 buffer.length);
5890 done:
5891 return result;
5894 /********************************************************************
5895 * Called by spoolss_api_setprinter
5896 * when updating a printer description.
5897 ********************************************************************/
5899 static WERROR update_printer(struct pipes_struct *p,
5900 struct policy_handle *handle,
5901 struct spoolss_SetPrinterInfoCtr *info_ctr,
5902 struct spoolss_DeviceMode *devmode)
5904 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
5905 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
5906 struct spoolss_PrinterInfo2 *old_printer;
5907 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5908 const char *servername = NULL;
5909 int snum;
5910 WERROR result = WERR_OK;
5911 TALLOC_CTX *tmp_ctx;
5913 DEBUG(8,("update_printer\n"));
5915 tmp_ctx = talloc_new(p->mem_ctx);
5916 if (tmp_ctx == NULL) {
5917 return WERR_NOMEM;
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 (Printer != NULL || Printer->servername != NULL) {
5931 servername = Printer->servername;
5934 result = winreg_get_printer(tmp_ctx,
5935 p->server_info,
5936 servername,
5937 lp_const_servicename(snum),
5938 &old_printer);
5939 if (!W_ERROR_IS_OK(result)) {
5940 result = WERR_BADFID;
5941 goto done;
5944 /* Do sanity check on the requested changes for Samba */
5945 if (!check_printer_ok(tmp_ctx, printer, snum)) {
5946 result = WERR_INVALID_PARAM;
5947 goto done;
5950 /* FIXME!!! If the driver has changed we really should verify that
5951 it is installed before doing much else --jerry */
5953 /* Check calling user has permission to update printer description */
5954 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
5955 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
5956 result = WERR_ACCESS_DENIED;
5957 goto done;
5960 /* Call addprinter hook */
5961 /* Check changes to see if this is really needed */
5963 if (*lp_addprinter_cmd() &&
5964 (!strequal(printer->drivername, old_printer->drivername) ||
5965 !strequal(printer->comment, old_printer->comment) ||
5966 !strequal(printer->portname, old_printer->portname) ||
5967 !strequal(printer->location, old_printer->location)) )
5969 /* add_printer_hook() will call reload_services() */
5970 if (!add_printer_hook(tmp_ctx, p->server_info->ptok,
5971 printer, p->client_address) ) {
5972 result = WERR_ACCESS_DENIED;
5973 goto done;
5977 update_dsspooler(tmp_ctx,
5978 p->server_info,
5979 snum,
5980 printer,
5981 old_printer);
5983 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
5985 if (devmode == NULL) {
5986 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
5988 result = winreg_update_printer(tmp_ctx,
5989 p->server_info,
5990 printer->sharename,
5991 printer_mask,
5992 printer,
5993 devmode,
5994 NULL);
5996 done:
5997 talloc_free(tmp_ctx);
5999 return result;
6002 /****************************************************************************
6003 ****************************************************************************/
6004 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6005 struct policy_handle *handle,
6006 struct spoolss_SetPrinterInfo7 *info7)
6008 #ifdef HAVE_ADS
6009 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6010 WERROR result;
6011 int snum;
6012 Printer_entry *Printer;
6014 if ( lp_security() != SEC_ADS ) {
6015 return WERR_UNKNOWN_LEVEL;
6018 Printer = find_printer_index_by_hnd(p, handle);
6020 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6022 if (!Printer)
6023 return WERR_BADFID;
6025 if (!get_printer_snum(p, handle, &snum, NULL))
6026 return WERR_BADFID;
6028 result = winreg_get_printer(p->mem_ctx, p->server_info,
6029 Printer->servername,
6030 lp_servicename(snum), &pinfo2);
6031 if (!W_ERROR_IS_OK(result)) {
6032 return WERR_BADFID;
6035 nt_printer_publish(pinfo2, p->server_info, pinfo2, info7->action);
6037 TALLOC_FREE(pinfo2);
6038 return WERR_OK;
6039 #else
6040 return WERR_UNKNOWN_LEVEL;
6041 #endif
6044 /********************************************************************
6045 ********************************************************************/
6047 static WERROR update_printer_devmode(struct pipes_struct *p,
6048 struct policy_handle *handle,
6049 struct spoolss_DeviceMode *devmode)
6051 int snum;
6052 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6053 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6055 DEBUG(8,("update_printer_devmode\n"));
6057 if (!Printer) {
6058 return WERR_BADFID;
6061 if (!get_printer_snum(p, handle, &snum, NULL)) {
6062 return WERR_BADFID;
6065 /* Check calling user has permission to update printer description */
6066 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6067 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6068 return WERR_ACCESS_DENIED;
6071 return winreg_update_printer(p->mem_ctx,
6072 p->server_info,
6073 lp_const_servicename(snum),
6074 info2_mask,
6075 NULL,
6076 devmode,
6077 NULL);
6081 /****************************************************************
6082 _spoolss_SetPrinter
6083 ****************************************************************/
6085 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6086 struct spoolss_SetPrinter *r)
6088 WERROR result;
6090 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6092 if (!Printer) {
6093 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6094 OUR_HANDLE(r->in.handle)));
6095 return WERR_BADFID;
6098 /* check the level */
6099 switch (r->in.info_ctr->level) {
6100 case 0:
6101 return control_printer(r->in.handle, r->in.command, p);
6102 case 2:
6103 result = update_printer(p, r->in.handle,
6104 r->in.info_ctr,
6105 r->in.devmode_ctr->devmode);
6106 if (!W_ERROR_IS_OK(result))
6107 return result;
6108 if (r->in.secdesc_ctr->sd)
6109 result = update_printer_sec(r->in.handle, p,
6110 r->in.secdesc_ctr);
6111 return result;
6112 case 3:
6113 return update_printer_sec(r->in.handle, p,
6114 r->in.secdesc_ctr);
6115 case 7:
6116 return publish_or_unpublish_printer(p, r->in.handle,
6117 r->in.info_ctr->info.info7);
6118 case 8:
6119 return update_printer_devmode(p, r->in.handle,
6120 r->in.devmode_ctr->devmode);
6121 default:
6122 return WERR_UNKNOWN_LEVEL;
6126 /****************************************************************
6127 _spoolss_FindClosePrinterNotify
6128 ****************************************************************/
6130 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6131 struct spoolss_FindClosePrinterNotify *r)
6133 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6135 if (!Printer) {
6136 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6137 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6138 return WERR_BADFID;
6141 if (Printer->notify.client_connected == true) {
6142 int snum = -1;
6144 if ( Printer->printer_type == SPLHND_SERVER)
6145 snum = -1;
6146 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6147 !get_printer_snum(p, r->in.handle, &snum, NULL) )
6148 return WERR_BADFID;
6150 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
6153 Printer->notify.flags=0;
6154 Printer->notify.options=0;
6155 Printer->notify.localmachine[0]='\0';
6156 Printer->notify.printerlocal=0;
6157 TALLOC_FREE(Printer->notify.option);
6158 Printer->notify.client_connected = false;
6160 return WERR_OK;
6163 /****************************************************************
6164 _spoolss_AddJob
6165 ****************************************************************/
6167 WERROR _spoolss_AddJob(struct pipes_struct *p,
6168 struct spoolss_AddJob *r)
6170 if (!r->in.buffer && (r->in.offered != 0)) {
6171 return WERR_INVALID_PARAM;
6174 /* this is what a NT server returns for AddJob. AddJob must fail on
6175 * non-local printers */
6177 if (r->in.level != 1) {
6178 return WERR_UNKNOWN_LEVEL;
6181 return WERR_INVALID_PARAM;
6184 /****************************************************************************
6185 fill_job_info1
6186 ****************************************************************************/
6188 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6189 struct spoolss_JobInfo1 *r,
6190 const print_queue_struct *queue,
6191 int position, int snum,
6192 struct spoolss_PrinterInfo2 *pinfo2)
6194 struct tm *t;
6196 t = gmtime(&queue->time);
6198 r->job_id = queue->job;
6200 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6201 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6202 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6203 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6204 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6205 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6206 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6207 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6208 r->data_type = talloc_strdup(mem_ctx, "RAW");
6209 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6210 r->text_status = talloc_strdup(mem_ctx, "");
6211 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6213 r->status = nt_printj_status(queue->status);
6214 r->priority = queue->priority;
6215 r->position = position;
6216 r->total_pages = queue->page_count;
6217 r->pages_printed = 0; /* ??? */
6219 init_systemtime(&r->submitted, t);
6221 return WERR_OK;
6224 /****************************************************************************
6225 fill_job_info2
6226 ****************************************************************************/
6228 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6229 struct spoolss_JobInfo2 *r,
6230 const print_queue_struct *queue,
6231 int position, int snum,
6232 struct spoolss_PrinterInfo2 *pinfo2,
6233 struct spoolss_DeviceMode *devmode)
6235 struct tm *t;
6237 t = gmtime(&queue->time);
6239 r->job_id = queue->job;
6241 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6242 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6243 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6244 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6245 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6246 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6247 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6248 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6249 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6250 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6251 r->data_type = talloc_strdup(mem_ctx, "RAW");
6252 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6253 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6254 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6255 r->parameters = talloc_strdup(mem_ctx, "");
6256 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6257 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6258 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6260 r->devmode = devmode;
6262 r->text_status = talloc_strdup(mem_ctx, "");
6263 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6265 r->secdesc = NULL;
6267 r->status = nt_printj_status(queue->status);
6268 r->priority = queue->priority;
6269 r->position = position;
6270 r->start_time = 0;
6271 r->until_time = 0;
6272 r->total_pages = queue->page_count;
6273 r->size = queue->size;
6274 init_systemtime(&r->submitted, t);
6275 r->time = 0;
6276 r->pages_printed = 0; /* ??? */
6278 return WERR_OK;
6281 /****************************************************************************
6282 fill_job_info3
6283 ****************************************************************************/
6285 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6286 struct spoolss_JobInfo3 *r,
6287 const print_queue_struct *queue,
6288 const print_queue_struct *next_queue,
6289 int position, int snum,
6290 struct spoolss_PrinterInfo2 *pinfo2)
6292 r->job_id = queue->job;
6293 r->next_job_id = 0;
6294 if (next_queue) {
6295 r->next_job_id = next_queue->job;
6297 r->reserved = 0;
6299 return WERR_OK;
6302 /****************************************************************************
6303 Enumjobs at level 1.
6304 ****************************************************************************/
6306 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6307 const print_queue_struct *queue,
6308 uint32_t num_queues, int snum,
6309 struct spoolss_PrinterInfo2 *pinfo2,
6310 union spoolss_JobInfo **info_p,
6311 uint32_t *count)
6313 union spoolss_JobInfo *info;
6314 int i;
6315 WERROR result = WERR_OK;
6317 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6318 W_ERROR_HAVE_NO_MEMORY(info);
6320 *count = num_queues;
6322 for (i=0; i<*count; i++) {
6323 result = fill_job_info1(info,
6324 &info[i].info1,
6325 &queue[i],
6327 snum,
6328 pinfo2);
6329 if (!W_ERROR_IS_OK(result)) {
6330 goto out;
6334 out:
6335 if (!W_ERROR_IS_OK(result)) {
6336 TALLOC_FREE(info);
6337 *count = 0;
6338 return result;
6341 *info_p = info;
6343 return WERR_OK;
6346 /****************************************************************************
6347 Enumjobs at level 2.
6348 ****************************************************************************/
6350 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6351 const print_queue_struct *queue,
6352 uint32_t num_queues, int snum,
6353 struct spoolss_PrinterInfo2 *pinfo2,
6354 union spoolss_JobInfo **info_p,
6355 uint32_t *count)
6357 union spoolss_JobInfo *info;
6358 int i;
6359 WERROR result = WERR_OK;
6361 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6362 W_ERROR_HAVE_NO_MEMORY(info);
6364 *count = num_queues;
6366 for (i=0; i<*count; i++) {
6367 struct spoolss_DeviceMode *devmode;
6369 result = spoolss_create_default_devmode(info,
6370 pinfo2->printername,
6371 &devmode);
6372 if (!W_ERROR_IS_OK(result)) {
6373 DEBUG(3, ("Can't proceed w/o a devmode!"));
6374 goto out;
6377 result = fill_job_info2(info,
6378 &info[i].info2,
6379 &queue[i],
6381 snum,
6382 pinfo2,
6383 devmode);
6384 if (!W_ERROR_IS_OK(result)) {
6385 goto out;
6389 out:
6390 if (!W_ERROR_IS_OK(result)) {
6391 TALLOC_FREE(info);
6392 *count = 0;
6393 return result;
6396 *info_p = info;
6398 return WERR_OK;
6401 /****************************************************************************
6402 Enumjobs at level 3.
6403 ****************************************************************************/
6405 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6406 const print_queue_struct *queue,
6407 uint32_t num_queues, int snum,
6408 struct spoolss_PrinterInfo2 *pinfo2,
6409 union spoolss_JobInfo **info_p,
6410 uint32_t *count)
6412 union spoolss_JobInfo *info;
6413 int i;
6414 WERROR result = WERR_OK;
6416 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6417 W_ERROR_HAVE_NO_MEMORY(info);
6419 *count = num_queues;
6421 for (i=0; i<*count; i++) {
6422 const print_queue_struct *next_queue = NULL;
6424 if (i+1 < *count) {
6425 next_queue = &queue[i+1];
6428 result = fill_job_info3(info,
6429 &info[i].info3,
6430 &queue[i],
6431 next_queue,
6433 snum,
6434 pinfo2);
6435 if (!W_ERROR_IS_OK(result)) {
6436 goto out;
6440 out:
6441 if (!W_ERROR_IS_OK(result)) {
6442 TALLOC_FREE(info);
6443 *count = 0;
6444 return result;
6447 *info_p = info;
6449 return WERR_OK;
6452 /****************************************************************
6453 _spoolss_EnumJobs
6454 ****************************************************************/
6456 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
6457 struct spoolss_EnumJobs *r)
6459 WERROR result;
6460 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6461 int snum;
6462 print_status_struct prt_status;
6463 print_queue_struct *queue = NULL;
6464 uint32_t count;
6466 /* that's an [in out] buffer */
6468 if (!r->in.buffer && (r->in.offered != 0)) {
6469 return WERR_INVALID_PARAM;
6472 DEBUG(4,("_spoolss_EnumJobs\n"));
6474 *r->out.needed = 0;
6475 *r->out.count = 0;
6476 *r->out.info = NULL;
6478 /* lookup the printer snum and tdb entry */
6480 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6481 return WERR_BADFID;
6484 result = winreg_get_printer(p->mem_ctx, p->server_info, NULL,
6485 lp_servicename(snum), &pinfo2);
6486 if (!W_ERROR_IS_OK(result)) {
6487 return result;
6490 count = print_queue_status(snum, &queue, &prt_status);
6491 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6492 count, prt_status.status, prt_status.message));
6494 if (count == 0) {
6495 SAFE_FREE(queue);
6496 TALLOC_FREE(pinfo2);
6497 return WERR_OK;
6500 switch (r->in.level) {
6501 case 1:
6502 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6503 pinfo2, r->out.info, r->out.count);
6504 break;
6505 case 2:
6506 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6507 pinfo2, r->out.info, r->out.count);
6508 break;
6509 case 3:
6510 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
6511 pinfo2, r->out.info, r->out.count);
6512 break;
6513 default:
6514 result = WERR_UNKNOWN_LEVEL;
6515 break;
6518 SAFE_FREE(queue);
6519 TALLOC_FREE(pinfo2);
6521 if (!W_ERROR_IS_OK(result)) {
6522 return result;
6525 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6526 spoolss_EnumJobs,
6527 *r->out.info, r->in.level,
6528 *r->out.count);
6529 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6530 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6532 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6535 /****************************************************************
6536 _spoolss_ScheduleJob
6537 ****************************************************************/
6539 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
6540 struct spoolss_ScheduleJob *r)
6542 return WERR_OK;
6545 /****************************************************************
6546 ****************************************************************/
6548 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
6549 const char *printer_name,
6550 uint32_t job_id,
6551 struct spoolss_SetJobInfo1 *r)
6553 char *old_doc_name;
6555 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
6556 return WERR_BADFID;
6559 if (strequal(old_doc_name, r->document_name)) {
6560 return WERR_OK;
6563 if (!print_job_set_name(printer_name, job_id, r->document_name)) {
6564 return WERR_BADFID;
6567 return WERR_OK;
6570 /****************************************************************
6571 _spoolss_SetJob
6572 ****************************************************************/
6574 WERROR _spoolss_SetJob(struct pipes_struct *p,
6575 struct spoolss_SetJob *r)
6577 int snum;
6578 WERROR errcode = WERR_BADFUNC;
6580 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6581 return WERR_BADFID;
6584 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6585 return WERR_INVALID_PRINTER_NAME;
6588 switch (r->in.command) {
6589 case SPOOLSS_JOB_CONTROL_CANCEL:
6590 case SPOOLSS_JOB_CONTROL_DELETE:
6591 errcode = print_job_delete(p->server_info,
6592 snum, r->in.job_id);
6593 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
6594 errcode = WERR_OK;
6596 break;
6597 case SPOOLSS_JOB_CONTROL_PAUSE:
6598 if (print_job_pause(p->server_info, snum, r->in.job_id, &errcode)) {
6599 errcode = WERR_OK;
6601 break;
6602 case SPOOLSS_JOB_CONTROL_RESTART:
6603 case SPOOLSS_JOB_CONTROL_RESUME:
6604 if (print_job_resume(p->server_info, snum, r->in.job_id, &errcode)) {
6605 errcode = WERR_OK;
6607 break;
6608 case 0:
6609 errcode = WERR_OK;
6610 break;
6611 default:
6612 return WERR_UNKNOWN_LEVEL;
6615 if (!W_ERROR_IS_OK(errcode)) {
6616 return errcode;
6619 if (r->in.ctr == NULL) {
6620 return errcode;
6623 switch (r->in.ctr->level) {
6624 case 1:
6625 errcode = spoolss_setjob_1(p->mem_ctx, lp_const_servicename(snum),
6626 r->in.job_id,
6627 r->in.ctr->info.info1);
6628 break;
6629 case 2:
6630 case 3:
6631 case 4:
6632 default:
6633 return WERR_UNKNOWN_LEVEL;
6636 return errcode;
6639 /****************************************************************************
6640 Enumerates all printer drivers by level and architecture.
6641 ****************************************************************************/
6643 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
6644 struct auth_serversupplied_info *server_info,
6645 const char *servername,
6646 const char *architecture,
6647 uint32_t level,
6648 union spoolss_DriverInfo **info_p,
6649 uint32_t *count_p)
6651 int i;
6652 uint32_t version;
6653 struct spoolss_DriverInfo8 *driver;
6654 union spoolss_DriverInfo *info = NULL;
6655 uint32_t count = 0;
6656 WERROR result = WERR_OK;
6657 uint32_t num_drivers;
6658 const char **drivers;
6660 *count_p = 0;
6661 *info_p = NULL;
6663 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6664 result = winreg_get_driver_list(mem_ctx, server_info,
6665 architecture, version,
6666 &num_drivers, &drivers);
6667 if (!W_ERROR_IS_OK(result)) {
6668 goto out;
6670 DEBUG(4, ("we have:[%d] drivers in environment"
6671 " [%s] and version [%d]\n",
6672 num_drivers, architecture, version));
6674 if (num_drivers != 0) {
6675 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6676 union spoolss_DriverInfo,
6677 count + num_drivers);
6678 if (!info) {
6679 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
6680 "failed to enlarge driver info buffer!\n"));
6681 result = WERR_NOMEM;
6682 goto out;
6686 for (i = 0; i < num_drivers; i++) {
6687 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
6689 result = winreg_get_driver(mem_ctx, server_info,
6690 architecture, drivers[i],
6691 version, &driver);
6692 if (!W_ERROR_IS_OK(result)) {
6693 goto out;
6696 switch (level) {
6697 case 1:
6698 result = fill_printer_driver_info1(info, &info[count+i].info1,
6699 driver, servername);
6700 break;
6701 case 2:
6702 result = fill_printer_driver_info2(info, &info[count+i].info2,
6703 driver, servername);
6704 break;
6705 case 3:
6706 result = fill_printer_driver_info3(info, &info[count+i].info3,
6707 driver, servername);
6708 break;
6709 case 4:
6710 result = fill_printer_driver_info4(info, &info[count+i].info4,
6711 driver, servername);
6712 break;
6713 case 5:
6714 result = fill_printer_driver_info5(info, &info[count+i].info5,
6715 driver, servername);
6716 break;
6717 case 6:
6718 result = fill_printer_driver_info6(info, &info[count+i].info6,
6719 driver, servername);
6720 break;
6721 case 8:
6722 result = fill_printer_driver_info8(info, &info[count+i].info8,
6723 driver, servername);
6724 break;
6725 default:
6726 result = WERR_UNKNOWN_LEVEL;
6727 break;
6730 TALLOC_FREE(driver);
6732 if (!W_ERROR_IS_OK(result)) {
6733 goto out;
6737 count += num_drivers;
6738 TALLOC_FREE(drivers);
6741 out:
6742 TALLOC_FREE(drivers);
6744 if (!W_ERROR_IS_OK(result)) {
6745 TALLOC_FREE(info);
6746 return result;
6749 *info_p = info;
6750 *count_p = count;
6752 return WERR_OK;
6755 /****************************************************************************
6756 Enumerates all printer drivers by level.
6757 ****************************************************************************/
6759 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
6760 struct auth_serversupplied_info *server_info,
6761 const char *servername,
6762 const char *architecture,
6763 uint32_t level,
6764 union spoolss_DriverInfo **info_p,
6765 uint32_t *count_p)
6767 uint32_t a,i;
6768 WERROR result = WERR_OK;
6770 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
6772 for (a=0; archi_table[a].long_archi != NULL; a++) {
6774 union spoolss_DriverInfo *info = NULL;
6775 uint32_t count = 0;
6777 result = enumprinterdrivers_level_by_architecture(mem_ctx,
6778 server_info,
6779 servername,
6780 archi_table[a].long_archi,
6781 level,
6782 &info,
6783 &count);
6784 if (!W_ERROR_IS_OK(result)) {
6785 continue;
6788 for (i=0; i < count; i++) {
6789 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
6790 info[i], info_p, count_p);
6794 return result;
6797 return enumprinterdrivers_level_by_architecture(mem_ctx,
6798 server_info,
6799 servername,
6800 architecture,
6801 level,
6802 info_p,
6803 count_p);
6806 /****************************************************************
6807 _spoolss_EnumPrinterDrivers
6808 ****************************************************************/
6810 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
6811 struct spoolss_EnumPrinterDrivers *r)
6813 const char *cservername;
6814 WERROR result;
6816 /* that's an [in out] buffer */
6818 if (!r->in.buffer && (r->in.offered != 0)) {
6819 return WERR_INVALID_PARAM;
6822 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
6824 *r->out.needed = 0;
6825 *r->out.count = 0;
6826 *r->out.info = NULL;
6828 cservername = canon_servername(r->in.server);
6830 if (!is_myname_or_ipaddr(cservername)) {
6831 return WERR_UNKNOWN_PRINTER_DRIVER;
6834 result = enumprinterdrivers_level(p->mem_ctx,
6835 p->server_info,
6836 cservername,
6837 r->in.environment,
6838 r->in.level,
6839 r->out.info,
6840 r->out.count);
6841 if (!W_ERROR_IS_OK(result)) {
6842 return result;
6845 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6846 spoolss_EnumPrinterDrivers,
6847 *r->out.info, r->in.level,
6848 *r->out.count);
6849 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6850 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6852 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6855 /****************************************************************
6856 _spoolss_EnumForms
6857 ****************************************************************/
6859 WERROR _spoolss_EnumForms(struct pipes_struct *p,
6860 struct spoolss_EnumForms *r)
6862 WERROR result;
6864 *r->out.count = 0;
6865 *r->out.needed = 0;
6866 *r->out.info = NULL;
6868 /* that's an [in out] buffer */
6870 if (!r->in.buffer && (r->in.offered != 0) ) {
6871 return WERR_INVALID_PARAM;
6874 DEBUG(4,("_spoolss_EnumForms\n"));
6875 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6876 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6878 switch (r->in.level) {
6879 case 1:
6880 result = winreg_printer_enumforms1(p->mem_ctx,
6881 p->server_info,
6882 r->out.count,
6883 r->out.info);
6884 break;
6885 default:
6886 result = WERR_UNKNOWN_LEVEL;
6887 break;
6890 if (!W_ERROR_IS_OK(result)) {
6891 return result;
6894 if (*r->out.count == 0) {
6895 return WERR_NO_MORE_ITEMS;
6898 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6899 spoolss_EnumForms,
6900 *r->out.info, r->in.level,
6901 *r->out.count);
6902 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6903 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6905 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6908 /****************************************************************
6909 _spoolss_GetForm
6910 ****************************************************************/
6912 WERROR _spoolss_GetForm(struct pipes_struct *p,
6913 struct spoolss_GetForm *r)
6915 WERROR result;
6917 /* that's an [in out] buffer */
6919 if (!r->in.buffer && (r->in.offered != 0)) {
6920 return WERR_INVALID_PARAM;
6923 DEBUG(4,("_spoolss_GetForm\n"));
6924 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6925 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6927 switch (r->in.level) {
6928 case 1:
6929 result = winreg_printer_getform1(p->mem_ctx,
6930 p->server_info,
6931 r->in.form_name,
6932 &r->out.info->info1);
6933 break;
6934 default:
6935 result = WERR_UNKNOWN_LEVEL;
6936 break;
6939 if (!W_ERROR_IS_OK(result)) {
6940 TALLOC_FREE(r->out.info);
6941 return result;
6944 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
6945 r->out.info, r->in.level);
6946 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
6948 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6951 /****************************************************************************
6952 ****************************************************************************/
6954 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
6955 struct spoolss_PortInfo1 *r,
6956 const char *name)
6958 r->port_name = talloc_strdup(mem_ctx, name);
6959 W_ERROR_HAVE_NO_MEMORY(r->port_name);
6961 return WERR_OK;
6964 /****************************************************************************
6965 TODO: This probably needs distinguish between TCP/IP and Local ports
6966 somehow.
6967 ****************************************************************************/
6969 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
6970 struct spoolss_PortInfo2 *r,
6971 const char *name)
6973 r->port_name = talloc_strdup(mem_ctx, name);
6974 W_ERROR_HAVE_NO_MEMORY(r->port_name);
6976 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
6977 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
6979 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
6980 W_ERROR_HAVE_NO_MEMORY(r->description);
6982 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
6983 r->reserved = 0;
6985 return WERR_OK;
6989 /****************************************************************************
6990 wrapper around the enumer ports command
6991 ****************************************************************************/
6993 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
6995 char *cmd = lp_enumports_cmd();
6996 char **qlines = NULL;
6997 char *command = NULL;
6998 int numlines;
6999 int ret;
7000 int fd;
7002 *count = 0;
7003 *lines = NULL;
7005 /* if no hook then just fill in the default port */
7007 if ( !*cmd ) {
7008 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7009 return WERR_NOMEM;
7011 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7012 TALLOC_FREE(qlines);
7013 return WERR_NOMEM;
7015 qlines[1] = NULL;
7016 numlines = 1;
7018 else {
7019 /* we have a valid enumport command */
7021 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7022 if (!command) {
7023 return WERR_NOMEM;
7026 DEBUG(10,("Running [%s]\n", command));
7027 ret = smbrun(command, &fd);
7028 DEBUG(10,("Returned [%d]\n", ret));
7029 TALLOC_FREE(command);
7030 if (ret != 0) {
7031 if (fd != -1) {
7032 close(fd);
7034 return WERR_ACCESS_DENIED;
7037 numlines = 0;
7038 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7039 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7040 close(fd);
7043 *count = numlines;
7044 *lines = qlines;
7046 return WERR_OK;
7049 /****************************************************************************
7050 enumports level 1.
7051 ****************************************************************************/
7053 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7054 union spoolss_PortInfo **info_p,
7055 uint32_t *count)
7057 union spoolss_PortInfo *info = NULL;
7058 int i=0;
7059 WERROR result = WERR_OK;
7060 char **qlines = NULL;
7061 int numlines = 0;
7063 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7064 if (!W_ERROR_IS_OK(result)) {
7065 goto out;
7068 if (numlines) {
7069 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7070 if (!info) {
7071 DEBUG(10,("Returning WERR_NOMEM\n"));
7072 result = WERR_NOMEM;
7073 goto out;
7076 for (i=0; i<numlines; i++) {
7077 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7078 result = fill_port_1(info, &info[i].info1, qlines[i]);
7079 if (!W_ERROR_IS_OK(result)) {
7080 goto out;
7084 TALLOC_FREE(qlines);
7086 out:
7087 if (!W_ERROR_IS_OK(result)) {
7088 TALLOC_FREE(info);
7089 TALLOC_FREE(qlines);
7090 *count = 0;
7091 *info_p = NULL;
7092 return result;
7095 *info_p = info;
7096 *count = numlines;
7098 return WERR_OK;
7101 /****************************************************************************
7102 enumports level 2.
7103 ****************************************************************************/
7105 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7106 union spoolss_PortInfo **info_p,
7107 uint32_t *count)
7109 union spoolss_PortInfo *info = NULL;
7110 int i=0;
7111 WERROR result = WERR_OK;
7112 char **qlines = NULL;
7113 int numlines = 0;
7115 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7116 if (!W_ERROR_IS_OK(result)) {
7117 goto out;
7120 if (numlines) {
7121 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7122 if (!info) {
7123 DEBUG(10,("Returning WERR_NOMEM\n"));
7124 result = WERR_NOMEM;
7125 goto out;
7128 for (i=0; i<numlines; i++) {
7129 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7130 result = fill_port_2(info, &info[i].info2, qlines[i]);
7131 if (!W_ERROR_IS_OK(result)) {
7132 goto out;
7136 TALLOC_FREE(qlines);
7138 out:
7139 if (!W_ERROR_IS_OK(result)) {
7140 TALLOC_FREE(info);
7141 TALLOC_FREE(qlines);
7142 *count = 0;
7143 *info_p = NULL;
7144 return result;
7147 *info_p = info;
7148 *count = numlines;
7150 return WERR_OK;
7153 /****************************************************************
7154 _spoolss_EnumPorts
7155 ****************************************************************/
7157 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
7158 struct spoolss_EnumPorts *r)
7160 WERROR result;
7162 /* that's an [in out] buffer */
7164 if (!r->in.buffer && (r->in.offered != 0)) {
7165 return WERR_INVALID_PARAM;
7168 DEBUG(4,("_spoolss_EnumPorts\n"));
7170 *r->out.count = 0;
7171 *r->out.needed = 0;
7172 *r->out.info = NULL;
7174 switch (r->in.level) {
7175 case 1:
7176 result = enumports_level_1(p->mem_ctx, r->out.info,
7177 r->out.count);
7178 break;
7179 case 2:
7180 result = enumports_level_2(p->mem_ctx, r->out.info,
7181 r->out.count);
7182 break;
7183 default:
7184 return WERR_UNKNOWN_LEVEL;
7187 if (!W_ERROR_IS_OK(result)) {
7188 return result;
7191 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7192 spoolss_EnumPorts,
7193 *r->out.info, r->in.level,
7194 *r->out.count);
7195 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7196 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7198 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7201 /****************************************************************************
7202 ****************************************************************************/
7204 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
7205 const char *server,
7206 struct spoolss_SetPrinterInfoCtr *info_ctr,
7207 struct spoolss_DeviceMode *devmode,
7208 struct security_descriptor *secdesc,
7209 struct spoolss_UserLevelCtr *user_ctr,
7210 struct policy_handle *handle)
7212 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7213 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7214 int snum;
7215 WERROR err = WERR_OK;
7217 /* samba does not have a concept of local, non-shared printers yet, so
7218 * make sure we always setup sharename - gd */
7219 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7220 (info2->printername != NULL && info2->printername[0] != '\0')) {
7221 DEBUG(5, ("spoolss_addprinterex_level_2: "
7222 "no sharename has been set, setting printername %s as sharename\n",
7223 info2->printername));
7224 info2->sharename = info2->printername;
7227 /* check to see if the printer already exists */
7228 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7229 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7230 info2->sharename));
7231 return WERR_PRINTER_ALREADY_EXISTS;
7234 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7235 if ((snum = print_queue_snum(info2->printername)) != -1) {
7236 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7237 info2->printername));
7238 return WERR_PRINTER_ALREADY_EXISTS;
7242 /* validate printer info struct */
7243 if (!info2->printername || strlen(info2->printername) == 0) {
7244 return WERR_INVALID_PRINTER_NAME;
7246 if (!info2->portname || strlen(info2->portname) == 0) {
7247 return WERR_UNKNOWN_PORT;
7249 if (!info2->drivername || strlen(info2->drivername) == 0) {
7250 return WERR_UNKNOWN_PRINTER_DRIVER;
7252 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7253 return WERR_UNKNOWN_PRINTPROCESSOR;
7256 /* FIXME!!! smbd should check to see if the driver is installed before
7257 trying to add a printer like this --jerry */
7259 if (*lp_addprinter_cmd() ) {
7260 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7261 info2, p->client_address) ) {
7262 return WERR_ACCESS_DENIED;
7264 } else {
7265 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7266 "smb.conf parameter \"addprinter command\" is defined. This"
7267 "parameter must exist for this call to succeed\n",
7268 info2->sharename ));
7271 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7272 return WERR_ACCESS_DENIED;
7275 /* you must be a printer admin to add a new printer */
7276 if (!print_access_check(p->server_info, snum, PRINTER_ACCESS_ADMINISTER)) {
7277 return WERR_ACCESS_DENIED;
7281 * Do sanity check on the requested changes for Samba.
7284 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7285 return WERR_INVALID_PARAM;
7288 if (devmode == NULL) {
7289 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7292 update_dsspooler(p->mem_ctx,
7293 p->server_info,
7295 info2,
7296 NULL);
7298 err = winreg_update_printer(p->mem_ctx,
7299 p->server_info,
7300 info2->sharename,
7301 info2_mask,
7302 info2,
7303 devmode,
7304 secdesc);
7305 if (!W_ERROR_IS_OK(err)) {
7306 return err;
7309 if (!open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER)) {
7310 /* Handle open failed - remove addition. */
7311 ZERO_STRUCTP(handle);
7312 return WERR_ACCESS_DENIED;
7315 return WERR_OK;
7318 /****************************************************************
7319 _spoolss_AddPrinterEx
7320 ****************************************************************/
7322 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
7323 struct spoolss_AddPrinterEx *r)
7325 switch (r->in.info_ctr->level) {
7326 case 1:
7327 /* we don't handle yet */
7328 /* but I know what to do ... */
7329 return WERR_UNKNOWN_LEVEL;
7330 case 2:
7331 return spoolss_addprinterex_level_2(p, r->in.server,
7332 r->in.info_ctr,
7333 r->in.devmode_ctr->devmode,
7334 r->in.secdesc_ctr->sd,
7335 r->in.userlevel_ctr,
7336 r->out.handle);
7337 default:
7338 return WERR_UNKNOWN_LEVEL;
7342 /****************************************************************
7343 _spoolss_AddPrinter
7344 ****************************************************************/
7346 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
7347 struct spoolss_AddPrinter *r)
7349 struct spoolss_AddPrinterEx a;
7350 struct spoolss_UserLevelCtr userlevel_ctr;
7352 ZERO_STRUCT(userlevel_ctr);
7354 userlevel_ctr.level = 1;
7356 a.in.server = r->in.server;
7357 a.in.info_ctr = r->in.info_ctr;
7358 a.in.devmode_ctr = r->in.devmode_ctr;
7359 a.in.secdesc_ctr = r->in.secdesc_ctr;
7360 a.in.userlevel_ctr = &userlevel_ctr;
7361 a.out.handle = r->out.handle;
7363 return _spoolss_AddPrinterEx(p, &a);
7366 /****************************************************************
7367 _spoolss_AddPrinterDriverEx
7368 ****************************************************************/
7370 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
7371 struct spoolss_AddPrinterDriverEx *r)
7373 WERROR err = WERR_OK;
7374 const char *driver_name = NULL;
7375 uint32_t version;
7376 const char *fn;
7378 switch (p->opnum) {
7379 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7380 fn = "_spoolss_AddPrinterDriver";
7381 break;
7382 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7383 fn = "_spoolss_AddPrinterDriverEx";
7384 break;
7385 default:
7386 return WERR_INVALID_PARAM;
7390 * we only support the semantics of AddPrinterDriver()
7391 * i.e. only copy files that are newer than existing ones
7394 if (r->in.flags == 0) {
7395 return WERR_INVALID_PARAM;
7398 if (r->in.flags != APD_COPY_NEW_FILES) {
7399 return WERR_ACCESS_DENIED;
7402 /* FIXME */
7403 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7404 /* Clever hack from Martin Zielinski <mz@seh.de>
7405 * to allow downgrade from level 8 (Vista).
7407 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7408 r->in.info_ctr->level));
7409 return WERR_UNKNOWN_LEVEL;
7412 DEBUG(5,("Cleaning driver's information\n"));
7413 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
7414 if (!W_ERROR_IS_OK(err))
7415 goto done;
7417 DEBUG(5,("Moving driver to final destination\n"));
7418 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7419 &err)) ) {
7420 goto done;
7423 err = winreg_add_driver(p->mem_ctx, p->server_info,
7424 r->in.info_ctr, &driver_name, &version);
7425 if (!W_ERROR_IS_OK(err)) {
7426 goto done;
7430 * I think this is where he DrvUpgradePrinter() hook would be
7431 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7432 * server. Right now, we just need to send ourselves a message
7433 * to update each printer bound to this driver. --jerry
7436 if (!srv_spoolss_drv_upgrade_printer(driver_name)) {
7437 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7438 fn, driver_name));
7441 done:
7442 return err;
7445 /****************************************************************
7446 _spoolss_AddPrinterDriver
7447 ****************************************************************/
7449 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
7450 struct spoolss_AddPrinterDriver *r)
7452 struct spoolss_AddPrinterDriverEx a;
7454 switch (r->in.info_ctr->level) {
7455 case 2:
7456 case 3:
7457 case 4:
7458 case 5:
7459 break;
7460 default:
7461 return WERR_UNKNOWN_LEVEL;
7464 a.in.servername = r->in.servername;
7465 a.in.info_ctr = r->in.info_ctr;
7466 a.in.flags = APD_COPY_NEW_FILES;
7468 return _spoolss_AddPrinterDriverEx(p, &a);
7471 /****************************************************************************
7472 ****************************************************************************/
7474 struct _spoolss_paths {
7475 int type;
7476 const char *share;
7477 const char *dir;
7480 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7482 static const struct _spoolss_paths spoolss_paths[]= {
7483 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7484 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7487 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7488 const char *servername,
7489 const char *environment,
7490 int component,
7491 char **path)
7493 const char *pservername = NULL;
7494 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7495 const char *short_archi;
7497 *path = NULL;
7499 /* environment may be empty */
7500 if (environment && strlen(environment)) {
7501 long_archi = environment;
7504 /* servername may be empty */
7505 if (servername && strlen(servername)) {
7506 pservername = canon_servername(servername);
7508 if (!is_myname_or_ipaddr(pservername)) {
7509 return WERR_INVALID_PARAM;
7513 if (!(short_archi = get_short_archi(long_archi))) {
7514 return WERR_INVALID_ENVIRONMENT;
7517 switch (component) {
7518 case SPOOLSS_PRTPROCS_PATH:
7519 case SPOOLSS_DRIVER_PATH:
7520 if (pservername) {
7521 *path = talloc_asprintf(mem_ctx,
7522 "\\\\%s\\%s\\%s",
7523 pservername,
7524 spoolss_paths[component].share,
7525 short_archi);
7526 } else {
7527 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7528 SPOOLSS_DEFAULT_SERVER_PATH,
7529 spoolss_paths[component].dir,
7530 short_archi);
7532 break;
7533 default:
7534 return WERR_INVALID_PARAM;
7537 if (!*path) {
7538 return WERR_NOMEM;
7541 return WERR_OK;
7544 /****************************************************************************
7545 ****************************************************************************/
7547 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7548 const char *servername,
7549 const char *environment,
7550 struct spoolss_DriverDirectoryInfo1 *r)
7552 WERROR werr;
7553 char *path = NULL;
7555 werr = compose_spoolss_server_path(mem_ctx,
7556 servername,
7557 environment,
7558 SPOOLSS_DRIVER_PATH,
7559 &path);
7560 if (!W_ERROR_IS_OK(werr)) {
7561 return werr;
7564 DEBUG(4,("printer driver directory: [%s]\n", path));
7566 r->directory_name = path;
7568 return WERR_OK;
7571 /****************************************************************
7572 _spoolss_GetPrinterDriverDirectory
7573 ****************************************************************/
7575 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
7576 struct spoolss_GetPrinterDriverDirectory *r)
7578 WERROR werror;
7580 /* that's an [in out] buffer */
7582 if (!r->in.buffer && (r->in.offered != 0)) {
7583 return WERR_INVALID_PARAM;
7586 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
7587 r->in.level));
7589 *r->out.needed = 0;
7591 /* r->in.level is ignored */
7593 werror = getprinterdriverdir_level_1(p->mem_ctx,
7594 r->in.server,
7595 r->in.environment,
7596 &r->out.info->info1);
7597 if (!W_ERROR_IS_OK(werror)) {
7598 TALLOC_FREE(r->out.info);
7599 return werror;
7602 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
7603 r->out.info, r->in.level);
7604 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7606 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7609 /****************************************************************
7610 _spoolss_EnumPrinterData
7611 ****************************************************************/
7613 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
7614 struct spoolss_EnumPrinterData *r)
7616 WERROR result;
7617 struct spoolss_EnumPrinterDataEx r2;
7618 uint32_t count;
7619 struct spoolss_PrinterEnumValues *info, *val = NULL;
7620 uint32_t needed;
7622 r2.in.handle = r->in.handle;
7623 r2.in.key_name = "PrinterDriverData";
7624 r2.in.offered = 0;
7625 r2.out.count = &count;
7626 r2.out.info = &info;
7627 r2.out.needed = &needed;
7629 result = _spoolss_EnumPrinterDataEx(p, &r2);
7630 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
7631 r2.in.offered = needed;
7632 result = _spoolss_EnumPrinterDataEx(p, &r2);
7634 if (!W_ERROR_IS_OK(result)) {
7635 return result;
7639 * The NT machine wants to know the biggest size of value and data
7641 * cf: MSDN EnumPrinterData remark section
7644 if (!r->in.value_offered && !r->in.data_offered) {
7645 uint32_t biggest_valuesize = 0;
7646 uint32_t biggest_datasize = 0;
7647 int i, name_length;
7649 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
7651 for (i=0; i<count; i++) {
7653 name_length = strlen(info[i].value_name);
7654 if (strlen(info[i].value_name) > biggest_valuesize) {
7655 biggest_valuesize = name_length;
7658 if (info[i].data_length > biggest_datasize) {
7659 biggest_datasize = info[i].data_length;
7662 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
7663 biggest_datasize));
7666 /* the value is an UNICODE string but real_value_size is the length
7667 in bytes including the trailing 0 */
7669 *r->out.value_needed = 2 * (1 + biggest_valuesize);
7670 *r->out.data_needed = biggest_datasize;
7672 DEBUG(6,("final values: [%d], [%d]\n",
7673 *r->out.value_needed, *r->out.data_needed));
7675 return WERR_OK;
7678 if (r->in.enum_index < count) {
7679 val = &info[r->in.enum_index];
7682 if (val == NULL) {
7683 /* out_value should default to "" or else NT4 has
7684 problems unmarshalling the response */
7686 if (r->in.value_offered) {
7687 *r->out.value_needed = 1;
7688 r->out.value_name = talloc_strdup(r, "");
7689 if (!r->out.value_name) {
7690 return WERR_NOMEM;
7692 } else {
7693 r->out.value_name = NULL;
7694 *r->out.value_needed = 0;
7697 /* the data is counted in bytes */
7699 *r->out.data_needed = r->in.data_offered;
7701 result = WERR_NO_MORE_ITEMS;
7702 } else {
7704 * the value is:
7705 * - counted in bytes in the request
7706 * - counted in UNICODE chars in the max reply
7707 * - counted in bytes in the real size
7709 * take a pause *before* coding not *during* coding
7712 /* name */
7713 if (r->in.value_offered) {
7714 r->out.value_name = talloc_strdup(r, val->value_name);
7715 if (!r->out.value_name) {
7716 return WERR_NOMEM;
7718 *r->out.value_needed = val->value_name_len;
7719 } else {
7720 r->out.value_name = NULL;
7721 *r->out.value_needed = 0;
7724 /* type */
7726 *r->out.type = val->type;
7728 /* data - counted in bytes */
7731 * See the section "Dynamically Typed Query Parameters"
7732 * in MS-RPRN.
7735 if (r->out.data && val->data && val->data->data &&
7736 val->data_length && r->in.data_offered) {
7737 memcpy(r->out.data, val->data->data,
7738 MIN(val->data_length,r->in.data_offered));
7741 *r->out.data_needed = val->data_length;
7743 result = WERR_OK;
7746 return result;
7749 /****************************************************************
7750 _spoolss_SetPrinterData
7751 ****************************************************************/
7753 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
7754 struct spoolss_SetPrinterData *r)
7756 struct spoolss_SetPrinterDataEx r2;
7758 r2.in.handle = r->in.handle;
7759 r2.in.key_name = "PrinterDriverData";
7760 r2.in.value_name = r->in.value_name;
7761 r2.in.type = r->in.type;
7762 r2.in.data = r->in.data;
7763 r2.in.offered = r->in.offered;
7765 return _spoolss_SetPrinterDataEx(p, &r2);
7768 /****************************************************************
7769 _spoolss_ResetPrinter
7770 ****************************************************************/
7772 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
7773 struct spoolss_ResetPrinter *r)
7775 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7776 int snum;
7778 DEBUG(5,("_spoolss_ResetPrinter\n"));
7781 * All we do is to check to see if the handle and queue is valid.
7782 * This call really doesn't mean anything to us because we only
7783 * support RAW printing. --jerry
7786 if (!Printer) {
7787 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
7788 OUR_HANDLE(r->in.handle)));
7789 return WERR_BADFID;
7792 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
7793 return WERR_BADFID;
7796 /* blindly return success */
7797 return WERR_OK;
7800 /****************************************************************
7801 _spoolss_DeletePrinterData
7802 ****************************************************************/
7804 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
7805 struct spoolss_DeletePrinterData *r)
7807 struct spoolss_DeletePrinterDataEx r2;
7809 r2.in.handle = r->in.handle;
7810 r2.in.key_name = "PrinterDriverData";
7811 r2.in.value_name = r->in.value_name;
7813 return _spoolss_DeletePrinterDataEx(p, &r2);
7816 /****************************************************************
7817 _spoolss_AddForm
7818 ****************************************************************/
7820 WERROR _spoolss_AddForm(struct pipes_struct *p,
7821 struct spoolss_AddForm *r)
7823 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
7824 int snum = -1;
7825 WERROR status = WERR_OK;
7826 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7828 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7830 DEBUG(5,("_spoolss_AddForm\n"));
7832 if (!Printer) {
7833 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
7834 OUR_HANDLE(r->in.handle)));
7835 return WERR_BADFID;
7838 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
7839 and not a printer admin, then fail */
7841 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7842 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7843 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7844 p->server_info->info3->base.domain.string,
7845 NULL,
7846 p->server_info->ptok,
7847 lp_printer_admin(snum))) {
7848 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
7849 return WERR_ACCESS_DENIED;
7852 switch (form->flags) {
7853 case SPOOLSS_FORM_USER:
7854 case SPOOLSS_FORM_BUILTIN:
7855 case SPOOLSS_FORM_PRINTER:
7856 break;
7857 default:
7858 return WERR_INVALID_PARAM;
7861 status = winreg_printer_addform1(p->mem_ctx, p->server_info, form);
7862 if (!W_ERROR_IS_OK(status)) {
7863 return status;
7867 * ChangeID must always be set if this is a printer
7869 if (Printer->printer_type == SPLHND_PRINTER) {
7870 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7871 return WERR_BADFID;
7874 status = winreg_printer_update_changeid(p->mem_ctx,
7875 p->server_info,
7876 lp_const_servicename(snum));
7877 if (!W_ERROR_IS_OK(status)) {
7878 return status;
7882 return status;
7885 /****************************************************************
7886 _spoolss_DeleteForm
7887 ****************************************************************/
7889 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
7890 struct spoolss_DeleteForm *r)
7892 const char *form_name = r->in.form_name;
7893 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7894 int snum = -1;
7895 WERROR status = WERR_OK;
7896 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7898 DEBUG(5,("_spoolss_DeleteForm\n"));
7900 if (!Printer) {
7901 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
7902 OUR_HANDLE(r->in.handle)));
7903 return WERR_BADFID;
7906 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7907 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7908 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7909 p->server_info->info3->base.domain.string,
7910 NULL,
7911 p->server_info->ptok,
7912 lp_printer_admin(snum))) {
7913 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
7914 return WERR_ACCESS_DENIED;
7917 status = winreg_printer_deleteform1(p->mem_ctx,
7918 p->server_info,
7919 form_name);
7920 if (!W_ERROR_IS_OK(status)) {
7921 return status;
7925 * ChangeID must always be set if this is a printer
7927 if (Printer->printer_type == SPLHND_PRINTER) {
7928 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7929 return WERR_BADFID;
7932 status = winreg_printer_update_changeid(p->mem_ctx,
7933 p->server_info,
7934 lp_const_servicename(snum));
7935 if (!W_ERROR_IS_OK(status)) {
7936 return status;
7940 return status;
7943 /****************************************************************
7944 _spoolss_SetForm
7945 ****************************************************************/
7947 WERROR _spoolss_SetForm(struct pipes_struct *p,
7948 struct spoolss_SetForm *r)
7950 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
7951 const char *form_name = r->in.form_name;
7952 int snum = -1;
7953 WERROR status = WERR_OK;
7954 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7956 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7958 DEBUG(5,("_spoolss_SetForm\n"));
7960 if (!Printer) {
7961 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
7962 OUR_HANDLE(r->in.handle)));
7963 return WERR_BADFID;
7966 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
7967 and not a printer admin, then fail */
7969 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7970 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7971 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7972 p->server_info->info3->base.domain.string,
7973 NULL,
7974 p->server_info->ptok,
7975 lp_printer_admin(snum))) {
7976 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
7977 return WERR_ACCESS_DENIED;
7980 status = winreg_printer_setform1(p->mem_ctx,
7981 p->server_info,
7982 form_name,
7983 form);
7984 if (!W_ERROR_IS_OK(status)) {
7985 return status;
7989 * ChangeID must always be set if this is a printer
7991 if (Printer->printer_type == SPLHND_PRINTER) {
7992 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7993 return WERR_BADFID;
7996 status = winreg_printer_update_changeid(p->mem_ctx,
7997 p->server_info,
7998 lp_const_servicename(snum));
7999 if (!W_ERROR_IS_OK(status)) {
8000 return status;
8004 return status;
8007 /****************************************************************************
8008 fill_print_processor1
8009 ****************************************************************************/
8011 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8012 struct spoolss_PrintProcessorInfo1 *r,
8013 const char *print_processor_name)
8015 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8016 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8018 return WERR_OK;
8021 /****************************************************************************
8022 enumprintprocessors level 1.
8023 ****************************************************************************/
8025 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8026 union spoolss_PrintProcessorInfo **info_p,
8027 uint32_t *count)
8029 union spoolss_PrintProcessorInfo *info;
8030 WERROR result;
8032 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8033 W_ERROR_HAVE_NO_MEMORY(info);
8035 *count = 1;
8037 result = fill_print_processor1(info, &info[0].info1, "winprint");
8038 if (!W_ERROR_IS_OK(result)) {
8039 goto out;
8042 out:
8043 if (!W_ERROR_IS_OK(result)) {
8044 TALLOC_FREE(info);
8045 *count = 0;
8046 return result;
8049 *info_p = info;
8051 return WERR_OK;
8054 /****************************************************************
8055 _spoolss_EnumPrintProcessors
8056 ****************************************************************/
8058 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8059 struct spoolss_EnumPrintProcessors *r)
8061 WERROR result;
8063 /* that's an [in out] buffer */
8065 if (!r->in.buffer && (r->in.offered != 0)) {
8066 return WERR_INVALID_PARAM;
8069 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8072 * Enumerate the print processors ...
8074 * Just reply with "winprint", to keep NT happy
8075 * and I can use my nice printer checker.
8078 *r->out.count = 0;
8079 *r->out.needed = 0;
8080 *r->out.info = NULL;
8082 switch (r->in.level) {
8083 case 1:
8084 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8085 r->out.count);
8086 break;
8087 default:
8088 return WERR_UNKNOWN_LEVEL;
8091 if (!W_ERROR_IS_OK(result)) {
8092 return result;
8095 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8096 spoolss_EnumPrintProcessors,
8097 *r->out.info, r->in.level,
8098 *r->out.count);
8099 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8100 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8102 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8105 /****************************************************************************
8106 fill_printprocdatatype1
8107 ****************************************************************************/
8109 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8110 struct spoolss_PrintProcDataTypesInfo1 *r,
8111 const char *name_array)
8113 r->name_array = talloc_strdup(mem_ctx, name_array);
8114 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8116 return WERR_OK;
8119 /****************************************************************************
8120 enumprintprocdatatypes level 1.
8121 ****************************************************************************/
8123 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8124 union spoolss_PrintProcDataTypesInfo **info_p,
8125 uint32_t *count)
8127 WERROR result;
8128 union spoolss_PrintProcDataTypesInfo *info;
8130 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8131 W_ERROR_HAVE_NO_MEMORY(info);
8133 *count = 1;
8135 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8136 if (!W_ERROR_IS_OK(result)) {
8137 goto out;
8140 out:
8141 if (!W_ERROR_IS_OK(result)) {
8142 TALLOC_FREE(info);
8143 *count = 0;
8144 return result;
8147 *info_p = info;
8149 return WERR_OK;
8152 /****************************************************************
8153 _spoolss_EnumPrintProcDataTypes
8154 ****************************************************************/
8156 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
8157 struct spoolss_EnumPrintProcDataTypes *r)
8159 WERROR result;
8161 /* that's an [in out] buffer */
8163 if (!r->in.buffer && (r->in.offered != 0)) {
8164 return WERR_INVALID_PARAM;
8167 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8169 *r->out.count = 0;
8170 *r->out.needed = 0;
8171 *r->out.info = NULL;
8173 switch (r->in.level) {
8174 case 1:
8175 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8176 r->out.count);
8177 break;
8178 default:
8179 return WERR_UNKNOWN_LEVEL;
8182 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8183 spoolss_EnumPrintProcDataTypes,
8184 *r->out.info, r->in.level,
8185 *r->out.count);
8186 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8187 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8189 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8192 /****************************************************************************
8193 fill_monitor_1
8194 ****************************************************************************/
8196 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8197 struct spoolss_MonitorInfo1 *r,
8198 const char *monitor_name)
8200 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8201 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8203 return WERR_OK;
8206 /****************************************************************************
8207 fill_monitor_2
8208 ****************************************************************************/
8210 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8211 struct spoolss_MonitorInfo2 *r,
8212 const char *monitor_name,
8213 const char *environment,
8214 const char *dll_name)
8216 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8217 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8218 r->environment = talloc_strdup(mem_ctx, environment);
8219 W_ERROR_HAVE_NO_MEMORY(r->environment);
8220 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8221 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8223 return WERR_OK;
8226 /****************************************************************************
8227 enumprintmonitors level 1.
8228 ****************************************************************************/
8230 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8231 union spoolss_MonitorInfo **info_p,
8232 uint32_t *count)
8234 union spoolss_MonitorInfo *info;
8235 WERROR result = WERR_OK;
8237 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8238 W_ERROR_HAVE_NO_MEMORY(info);
8240 *count = 2;
8242 result = fill_monitor_1(info, &info[0].info1,
8243 SPL_LOCAL_PORT);
8244 if (!W_ERROR_IS_OK(result)) {
8245 goto out;
8248 result = fill_monitor_1(info, &info[1].info1,
8249 SPL_TCPIP_PORT);
8250 if (!W_ERROR_IS_OK(result)) {
8251 goto out;
8254 out:
8255 if (!W_ERROR_IS_OK(result)) {
8256 TALLOC_FREE(info);
8257 *count = 0;
8258 return result;
8261 *info_p = info;
8263 return WERR_OK;
8266 /****************************************************************************
8267 enumprintmonitors level 2.
8268 ****************************************************************************/
8270 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8271 union spoolss_MonitorInfo **info_p,
8272 uint32_t *count)
8274 union spoolss_MonitorInfo *info;
8275 WERROR result = WERR_OK;
8277 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8278 W_ERROR_HAVE_NO_MEMORY(info);
8280 *count = 2;
8282 result = fill_monitor_2(info, &info[0].info2,
8283 SPL_LOCAL_PORT,
8284 "Windows NT X86", /* FIXME */
8285 "localmon.dll");
8286 if (!W_ERROR_IS_OK(result)) {
8287 goto out;
8290 result = fill_monitor_2(info, &info[1].info2,
8291 SPL_TCPIP_PORT,
8292 "Windows NT X86", /* FIXME */
8293 "tcpmon.dll");
8294 if (!W_ERROR_IS_OK(result)) {
8295 goto out;
8298 out:
8299 if (!W_ERROR_IS_OK(result)) {
8300 TALLOC_FREE(info);
8301 *count = 0;
8302 return result;
8305 *info_p = info;
8307 return WERR_OK;
8310 /****************************************************************
8311 _spoolss_EnumMonitors
8312 ****************************************************************/
8314 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
8315 struct spoolss_EnumMonitors *r)
8317 WERROR result;
8319 /* that's an [in out] buffer */
8321 if (!r->in.buffer && (r->in.offered != 0)) {
8322 return WERR_INVALID_PARAM;
8325 DEBUG(5,("_spoolss_EnumMonitors\n"));
8328 * Enumerate the print monitors ...
8330 * Just reply with "Local Port", to keep NT happy
8331 * and I can use my nice printer checker.
8334 *r->out.count = 0;
8335 *r->out.needed = 0;
8336 *r->out.info = NULL;
8338 switch (r->in.level) {
8339 case 1:
8340 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8341 r->out.count);
8342 break;
8343 case 2:
8344 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8345 r->out.count);
8346 break;
8347 default:
8348 return WERR_UNKNOWN_LEVEL;
8351 if (!W_ERROR_IS_OK(result)) {
8352 return result;
8355 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8356 spoolss_EnumMonitors,
8357 *r->out.info, r->in.level,
8358 *r->out.count);
8359 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8360 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8362 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8365 /****************************************************************************
8366 ****************************************************************************/
8368 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8369 const print_queue_struct *queue,
8370 int count, int snum,
8371 struct spoolss_PrinterInfo2 *pinfo2,
8372 uint32_t jobid,
8373 struct spoolss_JobInfo1 *r)
8375 int i = 0;
8376 bool found = false;
8378 for (i=0; i<count; i++) {
8379 if (queue[i].job == (int)jobid) {
8380 found = true;
8381 break;
8385 if (found == false) {
8386 /* NT treats not found as bad param... yet another bad choice */
8387 return WERR_INVALID_PARAM;
8390 return fill_job_info1(mem_ctx,
8392 &queue[i],
8394 snum,
8395 pinfo2);
8398 /****************************************************************************
8399 ****************************************************************************/
8401 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8402 const print_queue_struct *queue,
8403 int count, int snum,
8404 struct spoolss_PrinterInfo2 *pinfo2,
8405 uint32_t jobid,
8406 struct spoolss_JobInfo2 *r)
8408 int i = 0;
8409 bool found = false;
8410 struct spoolss_DeviceMode *devmode;
8411 WERROR result;
8413 for (i=0; i<count; i++) {
8414 if (queue[i].job == (int)jobid) {
8415 found = true;
8416 break;
8420 if (found == false) {
8421 /* NT treats not found as bad param... yet another bad
8422 choice */
8423 return WERR_INVALID_PARAM;
8427 * if the print job does not have a DEVMODE associated with it,
8428 * just use the one for the printer. A NULL devicemode is not
8429 * a failure condition
8432 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8433 if (!devmode) {
8434 result = spoolss_create_default_devmode(mem_ctx,
8435 pinfo2->printername,
8436 &devmode);
8437 if (!W_ERROR_IS_OK(result)) {
8438 DEBUG(3, ("Can't proceed w/o a devmode!"));
8439 return result;
8443 return fill_job_info2(mem_ctx,
8445 &queue[i],
8447 snum,
8448 pinfo2,
8449 devmode);
8452 /****************************************************************
8453 _spoolss_GetJob
8454 ****************************************************************/
8456 WERROR _spoolss_GetJob(struct pipes_struct *p,
8457 struct spoolss_GetJob *r)
8459 WERROR result = WERR_OK;
8460 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8461 int snum;
8462 int count;
8463 print_queue_struct *queue = NULL;
8464 print_status_struct prt_status;
8466 /* that's an [in out] buffer */
8468 if (!r->in.buffer && (r->in.offered != 0)) {
8469 return WERR_INVALID_PARAM;
8472 DEBUG(5,("_spoolss_GetJob\n"));
8474 *r->out.needed = 0;
8476 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8477 return WERR_BADFID;
8480 result = winreg_get_printer(p->mem_ctx, p->server_info, NULL,
8481 lp_servicename(snum), &pinfo2);
8482 if (!W_ERROR_IS_OK(result)) {
8483 return result;
8486 count = print_queue_status(snum, &queue, &prt_status);
8488 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8489 count, prt_status.status, prt_status.message));
8491 switch (r->in.level) {
8492 case 1:
8493 result = getjob_level_1(p->mem_ctx,
8494 queue, count, snum, pinfo2,
8495 r->in.job_id, &r->out.info->info1);
8496 break;
8497 case 2:
8498 result = getjob_level_2(p->mem_ctx,
8499 queue, count, snum, pinfo2,
8500 r->in.job_id, &r->out.info->info2);
8501 break;
8502 default:
8503 result = WERR_UNKNOWN_LEVEL;
8504 break;
8507 SAFE_FREE(queue);
8508 TALLOC_FREE(pinfo2);
8510 if (!W_ERROR_IS_OK(result)) {
8511 TALLOC_FREE(r->out.info);
8512 return result;
8515 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
8516 r->in.level);
8517 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8519 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8522 /****************************************************************
8523 _spoolss_GetPrinterDataEx
8524 ****************************************************************/
8526 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
8527 struct spoolss_GetPrinterDataEx *r)
8530 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8531 const char *printer;
8532 int snum = 0;
8533 WERROR result = WERR_OK;
8534 DATA_BLOB blob;
8535 enum winreg_Type val_type;
8536 uint8_t *val_data;
8537 uint32_t val_size;
8540 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8542 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8543 r->in.key_name, r->in.value_name));
8545 /* in case of problem, return some default values */
8547 *r->out.needed = 0;
8548 *r->out.type = REG_NONE;
8550 if (!Printer) {
8551 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8552 OUR_HANDLE(r->in.handle)));
8553 result = WERR_BADFID;
8554 goto done;
8557 /* Is the handle to a printer or to the server? */
8559 if (Printer->printer_type == SPLHND_SERVER) {
8561 union spoolss_PrinterData data;
8563 result = getprinterdata_printer_server(p->mem_ctx,
8564 r->in.value_name,
8565 r->out.type,
8566 &data);
8567 if (!W_ERROR_IS_OK(result)) {
8568 return result;
8571 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
8572 *r->out.type, &data);
8573 if (!W_ERROR_IS_OK(result)) {
8574 return result;
8577 *r->out.needed = blob.length;
8579 if (r->in.offered >= *r->out.needed) {
8580 memcpy(r->out.data, blob.data, blob.length);
8583 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8586 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8587 return WERR_BADFID;
8589 printer = lp_const_servicename(snum);
8591 /* check to see if the keyname is valid */
8592 if (!strlen(r->in.key_name)) {
8593 return WERR_INVALID_PARAM;
8596 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
8597 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
8598 strequal(r->in.value_name, "ChangeId")) {
8599 *r->out.type = REG_DWORD;
8600 *r->out.needed = 4;
8601 if (r->in.offered >= *r->out.needed) {
8602 uint32_t changeid = 0;
8604 result = winreg_printer_get_changeid(p->mem_ctx,
8605 p->server_info,
8606 printer,
8607 &changeid);
8608 if (!W_ERROR_IS_OK(result)) {
8609 return result;
8612 SIVAL(r->out.data, 0, changeid);
8613 result = WERR_OK;
8615 goto done;
8618 result = winreg_get_printer_dataex(p->mem_ctx,
8619 p->server_info,
8620 printer,
8621 r->in.key_name,
8622 r->in.value_name,
8623 &val_type,
8624 &val_data,
8625 &val_size);
8626 if (!W_ERROR_IS_OK(result)) {
8627 return result;
8630 *r->out.needed = val_size;
8631 *r->out.type = val_type;
8633 if (r->in.offered >= *r->out.needed) {
8634 memcpy(r->out.data, val_data, val_size);
8637 done:
8638 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
8639 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
8641 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8644 /****************************************************************
8645 _spoolss_SetPrinterDataEx
8646 ****************************************************************/
8648 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
8649 struct spoolss_SetPrinterDataEx *r)
8651 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8652 int snum = 0;
8653 WERROR result = WERR_OK;
8654 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8655 char *oid_string;
8657 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
8659 /* From MSDN documentation of SetPrinterDataEx: pass request to
8660 SetPrinterData if key is "PrinterDriverData" */
8662 if (!Printer) {
8663 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8664 OUR_HANDLE(r->in.handle)));
8665 return WERR_BADFID;
8668 if (Printer->printer_type == SPLHND_SERVER) {
8669 DEBUG(10,("_spoolss_SetPrinterDataEx: "
8670 "Not implemented for server handles yet\n"));
8671 return WERR_INVALID_PARAM;
8674 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8675 return WERR_BADFID;
8679 * Access check : NT returns "access denied" if you make a
8680 * SetPrinterData call without the necessary privildge.
8681 * we were originally returning OK if nothing changed
8682 * which made Win2k issue **a lot** of SetPrinterData
8683 * when connecting to a printer --jerry
8686 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8687 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
8688 "change denied by handle access permissions\n"));
8689 return WERR_ACCESS_DENIED;
8692 result = winreg_get_printer(Printer, p->server_info,
8693 Printer->servername,
8694 lp_servicename(snum),
8695 &pinfo2);
8696 if (!W_ERROR_IS_OK(result)) {
8697 return result;
8700 /* check for OID in valuename */
8702 oid_string = strchr(r->in.value_name, ',');
8703 if (oid_string) {
8704 *oid_string = '\0';
8705 oid_string++;
8708 /* save the registry data */
8710 result = winreg_set_printer_dataex(p->mem_ctx,
8711 p->server_info,
8712 pinfo2->sharename,
8713 r->in.key_name,
8714 r->in.value_name,
8715 r->in.type,
8716 r->in.data,
8717 r->in.offered);
8719 if (W_ERROR_IS_OK(result)) {
8720 /* save the OID if one was specified */
8721 if (oid_string) {
8722 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
8723 r->in.key_name, SPOOL_OID_KEY);
8724 if (!str) {
8725 result = WERR_NOMEM;
8726 goto done;
8730 * I'm not checking the status here on purpose. Don't know
8731 * if this is right, but I'm returning the status from the
8732 * previous set_printer_dataex() call. I have no idea if
8733 * this is right. --jerry
8735 winreg_set_printer_dataex(p->mem_ctx,
8736 p->server_info,
8737 pinfo2->sharename,
8738 str,
8739 r->in.value_name,
8740 REG_SZ,
8741 (uint8_t *) oid_string,
8742 strlen(oid_string) + 1);
8745 result = winreg_printer_update_changeid(p->mem_ctx,
8746 p->server_info,
8747 lp_const_servicename(snum));
8751 done:
8752 talloc_free(pinfo2);
8753 return result;
8756 /****************************************************************
8757 _spoolss_DeletePrinterDataEx
8758 ****************************************************************/
8760 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
8761 struct spoolss_DeletePrinterDataEx *r)
8763 const char *printer;
8764 int snum=0;
8765 WERROR status = WERR_OK;
8766 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8768 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
8770 if (!Printer) {
8771 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
8772 "Invalid handle (%s:%u:%u).\n",
8773 OUR_HANDLE(r->in.handle)));
8774 return WERR_BADFID;
8777 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8778 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
8779 "printer properties change denied by handle\n"));
8780 return WERR_ACCESS_DENIED;
8783 if (!r->in.value_name || !r->in.key_name) {
8784 return WERR_NOMEM;
8787 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8788 return WERR_BADFID;
8790 printer = lp_const_servicename(snum);
8792 status = winreg_delete_printer_dataex(p->mem_ctx,
8793 p->server_info,
8794 printer,
8795 r->in.key_name,
8796 r->in.value_name);
8797 if (W_ERROR_IS_OK(status)) {
8798 status = winreg_printer_update_changeid(p->mem_ctx,
8799 p->server_info,
8800 printer);
8803 return status;
8806 /****************************************************************
8807 _spoolss_EnumPrinterKey
8808 ****************************************************************/
8810 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
8811 struct spoolss_EnumPrinterKey *r)
8813 uint32_t num_keys;
8814 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8815 int snum = 0;
8816 WERROR result = WERR_BADFILE;
8817 const char **array = NULL;
8818 DATA_BLOB blob;
8820 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
8822 if (!Printer) {
8823 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
8824 OUR_HANDLE(r->in.handle)));
8825 return WERR_BADFID;
8828 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8829 return WERR_BADFID;
8832 result = winreg_enum_printer_key(p->mem_ctx,
8833 p->server_info,
8834 lp_const_servicename(snum),
8835 r->in.key_name,
8836 &num_keys,
8837 &array);
8838 if (!W_ERROR_IS_OK(result)) {
8839 goto done;
8842 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
8843 result = WERR_NOMEM;
8844 goto done;
8847 *r->out._ndr_size = r->in.offered / 2;
8848 *r->out.needed = blob.length;
8850 if (r->in.offered < *r->out.needed) {
8851 result = WERR_MORE_DATA;
8852 } else {
8853 result = WERR_OK;
8854 r->out.key_buffer->string_array = array;
8857 done:
8858 if (!W_ERROR_IS_OK(result)) {
8859 TALLOC_FREE(array);
8860 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8861 *r->out.needed = 0;
8865 return result;
8868 /****************************************************************
8869 _spoolss_DeletePrinterKey
8870 ****************************************************************/
8872 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
8873 struct spoolss_DeletePrinterKey *r)
8875 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8876 int snum=0;
8877 WERROR status;
8878 const char *printer;
8880 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
8882 if (!Printer) {
8883 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
8884 OUR_HANDLE(r->in.handle)));
8885 return WERR_BADFID;
8888 /* if keyname == NULL, return error */
8889 if ( !r->in.key_name )
8890 return WERR_INVALID_PARAM;
8892 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8893 return WERR_BADFID;
8896 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8897 DEBUG(3, ("_spoolss_DeletePrinterKey: "
8898 "printer properties change denied by handle\n"));
8899 return WERR_ACCESS_DENIED;
8902 printer = lp_const_servicename(snum);
8904 /* delete the key and all subkeys */
8905 status = winreg_delete_printer_key(p->mem_ctx,
8906 p->server_info,
8907 printer,
8908 r->in.key_name);
8909 if (W_ERROR_IS_OK(status)) {
8910 status = winreg_printer_update_changeid(p->mem_ctx,
8911 p->server_info,
8912 printer);
8915 return status;
8918 /****************************************************************
8919 _spoolss_EnumPrinterDataEx
8920 ****************************************************************/
8922 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
8923 struct spoolss_EnumPrinterDataEx *r)
8925 uint32_t count = 0;
8926 struct spoolss_PrinterEnumValues *info = NULL;
8927 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8928 int snum;
8929 WERROR result;
8931 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
8933 *r->out.count = 0;
8934 *r->out.needed = 0;
8935 *r->out.info = NULL;
8937 if (!Printer) {
8938 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
8939 OUR_HANDLE(r->in.handle)));
8940 return WERR_BADFID;
8944 * first check for a keyname of NULL or "". Win2k seems to send
8945 * this a lot and we should send back WERR_INVALID_PARAM
8946 * no need to spend time looking up the printer in this case.
8947 * --jerry
8950 if (!strlen(r->in.key_name)) {
8951 result = WERR_INVALID_PARAM;
8952 goto done;
8955 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8956 return WERR_BADFID;
8959 /* now look for a match on the key name */
8960 result = winreg_enum_printer_dataex(p->mem_ctx,
8961 p->server_info,
8962 lp_const_servicename(snum),
8963 r->in.key_name,
8964 &count,
8965 &info);
8966 if (!W_ERROR_IS_OK(result)) {
8967 goto done;
8970 #if 0 /* FIXME - gd */
8971 /* housekeeping information in the reply */
8973 /* Fix from Martin Zielinski <mz@seh.de> - ensure
8974 * the hand marshalled container size is a multiple
8975 * of 4 bytes for RPC alignment.
8978 if (needed % 4) {
8979 needed += 4-(needed % 4);
8981 #endif
8982 *r->out.count = count;
8983 *r->out.info = info;
8985 done:
8986 if (!W_ERROR_IS_OK(result)) {
8987 return result;
8990 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
8991 spoolss_EnumPrinterDataEx,
8992 *r->out.info,
8993 *r->out.count);
8994 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8995 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
8997 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9000 /****************************************************************************
9001 ****************************************************************************/
9003 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9004 const char *servername,
9005 const char *environment,
9006 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9008 WERROR werr;
9009 char *path = NULL;
9011 werr = compose_spoolss_server_path(mem_ctx,
9012 servername,
9013 environment,
9014 SPOOLSS_PRTPROCS_PATH,
9015 &path);
9016 if (!W_ERROR_IS_OK(werr)) {
9017 return werr;
9020 DEBUG(4,("print processor directory: [%s]\n", path));
9022 r->directory_name = path;
9024 return WERR_OK;
9027 /****************************************************************
9028 _spoolss_GetPrintProcessorDirectory
9029 ****************************************************************/
9031 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
9032 struct spoolss_GetPrintProcessorDirectory *r)
9034 WERROR result;
9036 /* that's an [in out] buffer */
9038 if (!r->in.buffer && (r->in.offered != 0)) {
9039 return WERR_INVALID_PARAM;
9042 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9043 r->in.level));
9045 *r->out.needed = 0;
9047 /* r->in.level is ignored */
9049 /* We always should reply with a local print processor directory so that
9050 * users are not forced to have a [prnproc$] share on the Samba spoolss
9051 * server - Guenther */
9053 result = getprintprocessordirectory_level_1(p->mem_ctx,
9054 NULL, /* r->in.server */
9055 r->in.environment,
9056 &r->out.info->info1);
9057 if (!W_ERROR_IS_OK(result)) {
9058 TALLOC_FREE(r->out.info);
9059 return result;
9062 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9063 r->out.info, r->in.level);
9064 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9066 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9069 /*******************************************************************
9070 ********************************************************************/
9072 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9073 const char *dllname)
9075 enum ndr_err_code ndr_err;
9076 struct spoolss_MonitorUi ui;
9078 ui.dll_name = dllname;
9080 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9081 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9082 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9083 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9085 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9088 /*******************************************************************
9089 Streams the monitor UI DLL name in UNICODE
9090 *******************************************************************/
9092 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9093 NT_USER_TOKEN *token, DATA_BLOB *in,
9094 DATA_BLOB *out, uint32_t *needed)
9096 const char *dllname = "tcpmonui.dll";
9098 *needed = (strlen(dllname)+1) * 2;
9100 if (out->length < *needed) {
9101 return WERR_INSUFFICIENT_BUFFER;
9104 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9105 return WERR_NOMEM;
9108 return WERR_OK;
9111 /*******************************************************************
9112 ********************************************************************/
9114 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9115 struct spoolss_PortData1 *port1,
9116 const DATA_BLOB *buf)
9118 enum ndr_err_code ndr_err;
9119 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9120 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9121 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9122 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9124 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9127 /*******************************************************************
9128 ********************************************************************/
9130 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9131 struct spoolss_PortData2 *port2,
9132 const DATA_BLOB *buf)
9134 enum ndr_err_code ndr_err;
9135 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9136 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9137 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9138 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9140 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9143 /*******************************************************************
9144 Create a new TCP/IP port
9145 *******************************************************************/
9147 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9148 NT_USER_TOKEN *token, DATA_BLOB *in,
9149 DATA_BLOB *out, uint32_t *needed)
9151 struct spoolss_PortData1 port1;
9152 struct spoolss_PortData2 port2;
9153 char *device_uri = NULL;
9154 uint32_t version;
9156 const char *portname;
9157 const char *hostaddress;
9158 const char *queue;
9159 uint32_t port_number;
9160 uint32_t protocol;
9162 /* peek for spoolss_PortData version */
9164 if (!in || (in->length < (128 + 4))) {
9165 return WERR_GENERAL_FAILURE;
9168 version = IVAL(in->data, 128);
9170 switch (version) {
9171 case 1:
9172 ZERO_STRUCT(port1);
9174 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9175 return WERR_NOMEM;
9178 portname = port1.portname;
9179 hostaddress = port1.hostaddress;
9180 queue = port1.queue;
9181 protocol = port1.protocol;
9182 port_number = port1.port_number;
9184 break;
9185 case 2:
9186 ZERO_STRUCT(port2);
9188 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9189 return WERR_NOMEM;
9192 portname = port2.portname;
9193 hostaddress = port2.hostaddress;
9194 queue = port2.queue;
9195 protocol = port2.protocol;
9196 port_number = port2.port_number;
9198 break;
9199 default:
9200 DEBUG(1,("xcvtcp_addport: "
9201 "unknown version of port_data: %d\n", version));
9202 return WERR_UNKNOWN_PORT;
9205 /* create the device URI and call the add_port_hook() */
9207 switch (protocol) {
9208 case PROTOCOL_RAWTCP_TYPE:
9209 device_uri = talloc_asprintf(mem_ctx,
9210 "socket://%s:%d/", hostaddress,
9211 port_number);
9212 break;
9214 case PROTOCOL_LPR_TYPE:
9215 device_uri = talloc_asprintf(mem_ctx,
9216 "lpr://%s/%s", hostaddress, queue );
9217 break;
9219 default:
9220 return WERR_UNKNOWN_PORT;
9223 if (!device_uri) {
9224 return WERR_NOMEM;
9227 return add_port_hook(mem_ctx, token, portname, device_uri);
9230 /*******************************************************************
9231 *******************************************************************/
9233 struct xcv_api_table xcvtcp_cmds[] = {
9234 { "MonitorUI", xcvtcp_monitorui },
9235 { "AddPort", xcvtcp_addport},
9236 { NULL, NULL }
9239 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9240 NT_USER_TOKEN *token, const char *command,
9241 DATA_BLOB *inbuf,
9242 DATA_BLOB *outbuf,
9243 uint32_t *needed )
9245 int i;
9247 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9249 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9250 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9251 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9254 return WERR_BADFUNC;
9257 /*******************************************************************
9258 *******************************************************************/
9259 #if 0 /* don't support management using the "Local Port" monitor */
9261 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9262 NT_USER_TOKEN *token, DATA_BLOB *in,
9263 DATA_BLOB *out, uint32_t *needed)
9265 const char *dllname = "localui.dll";
9267 *needed = (strlen(dllname)+1) * 2;
9269 if (out->length < *needed) {
9270 return WERR_INSUFFICIENT_BUFFER;
9273 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9274 return WERR_NOMEM;
9277 return WERR_OK;
9280 /*******************************************************************
9281 *******************************************************************/
9283 struct xcv_api_table xcvlocal_cmds[] = {
9284 { "MonitorUI", xcvlocal_monitorui },
9285 { NULL, NULL }
9287 #else
9288 struct xcv_api_table xcvlocal_cmds[] = {
9289 { NULL, NULL }
9291 #endif
9295 /*******************************************************************
9296 *******************************************************************/
9298 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9299 NT_USER_TOKEN *token, const char *command,
9300 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9301 uint32_t *needed)
9303 int i;
9305 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9307 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9308 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9309 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9311 return WERR_BADFUNC;
9314 /****************************************************************
9315 _spoolss_XcvData
9316 ****************************************************************/
9318 WERROR _spoolss_XcvData(struct pipes_struct *p,
9319 struct spoolss_XcvData *r)
9321 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9322 DATA_BLOB out_data = data_blob_null;
9323 WERROR werror;
9325 if (!Printer) {
9326 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9327 OUR_HANDLE(r->in.handle)));
9328 return WERR_BADFID;
9331 /* Has to be a handle to the TCP/IP port monitor */
9333 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9334 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9335 return WERR_BADFID;
9338 /* requires administrative access to the server */
9340 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9341 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9342 return WERR_ACCESS_DENIED;
9345 /* Allocate the outgoing buffer */
9347 if (r->in.out_data_size) {
9348 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9349 if (out_data.data == NULL) {
9350 return WERR_NOMEM;
9354 switch ( Printer->printer_type ) {
9355 case SPLHND_PORTMON_TCP:
9356 werror = process_xcvtcp_command(p->mem_ctx,
9357 p->server_info->ptok,
9358 r->in.function_name,
9359 &r->in.in_data, &out_data,
9360 r->out.needed);
9361 break;
9362 case SPLHND_PORTMON_LOCAL:
9363 werror = process_xcvlocal_command(p->mem_ctx,
9364 p->server_info->ptok,
9365 r->in.function_name,
9366 &r->in.in_data, &out_data,
9367 r->out.needed);
9368 break;
9369 default:
9370 werror = WERR_INVALID_PRINT_MONITOR;
9373 if (!W_ERROR_IS_OK(werror)) {
9374 return werror;
9377 *r->out.status_code = 0;
9379 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9380 memcpy(r->out.out_data, out_data.data,
9381 MIN(r->in.out_data_size, out_data.length));
9384 return WERR_OK;
9387 /****************************************************************
9388 _spoolss_AddPrintProcessor
9389 ****************************************************************/
9391 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
9392 struct spoolss_AddPrintProcessor *r)
9394 /* for now, just indicate success and ignore the add. We'll
9395 automatically set the winprint processor for printer
9396 entries later. Used to debug the LexMark Optra S 1855 PCL
9397 driver --jerry */
9399 return WERR_OK;
9402 /****************************************************************
9403 _spoolss_AddPort
9404 ****************************************************************/
9406 WERROR _spoolss_AddPort(struct pipes_struct *p,
9407 struct spoolss_AddPort *r)
9409 /* do what w2k3 does */
9411 return WERR_NOT_SUPPORTED;
9414 /****************************************************************
9415 _spoolss_GetPrinterDriver
9416 ****************************************************************/
9418 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
9419 struct spoolss_GetPrinterDriver *r)
9421 p->rng_fault_state = true;
9422 return WERR_NOT_SUPPORTED;
9425 /****************************************************************
9426 _spoolss_ReadPrinter
9427 ****************************************************************/
9429 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
9430 struct spoolss_ReadPrinter *r)
9432 p->rng_fault_state = true;
9433 return WERR_NOT_SUPPORTED;
9436 /****************************************************************
9437 _spoolss_WaitForPrinterChange
9438 ****************************************************************/
9440 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
9441 struct spoolss_WaitForPrinterChange *r)
9443 p->rng_fault_state = true;
9444 return WERR_NOT_SUPPORTED;
9447 /****************************************************************
9448 _spoolss_ConfigurePort
9449 ****************************************************************/
9451 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
9452 struct spoolss_ConfigurePort *r)
9454 p->rng_fault_state = true;
9455 return WERR_NOT_SUPPORTED;
9458 /****************************************************************
9459 _spoolss_DeletePort
9460 ****************************************************************/
9462 WERROR _spoolss_DeletePort(struct pipes_struct *p,
9463 struct spoolss_DeletePort *r)
9465 p->rng_fault_state = true;
9466 return WERR_NOT_SUPPORTED;
9469 /****************************************************************
9470 _spoolss_CreatePrinterIC
9471 ****************************************************************/
9473 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
9474 struct spoolss_CreatePrinterIC *r)
9476 p->rng_fault_state = true;
9477 return WERR_NOT_SUPPORTED;
9480 /****************************************************************
9481 _spoolss_PlayGDIScriptOnPrinterIC
9482 ****************************************************************/
9484 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
9485 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9487 p->rng_fault_state = true;
9488 return WERR_NOT_SUPPORTED;
9491 /****************************************************************
9492 _spoolss_DeletePrinterIC
9493 ****************************************************************/
9495 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
9496 struct spoolss_DeletePrinterIC *r)
9498 p->rng_fault_state = true;
9499 return WERR_NOT_SUPPORTED;
9502 /****************************************************************
9503 _spoolss_AddPrinterConnection
9504 ****************************************************************/
9506 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
9507 struct spoolss_AddPrinterConnection *r)
9509 p->rng_fault_state = true;
9510 return WERR_NOT_SUPPORTED;
9513 /****************************************************************
9514 _spoolss_DeletePrinterConnection
9515 ****************************************************************/
9517 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
9518 struct spoolss_DeletePrinterConnection *r)
9520 p->rng_fault_state = true;
9521 return WERR_NOT_SUPPORTED;
9524 /****************************************************************
9525 _spoolss_PrinterMessageBox
9526 ****************************************************************/
9528 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
9529 struct spoolss_PrinterMessageBox *r)
9531 p->rng_fault_state = true;
9532 return WERR_NOT_SUPPORTED;
9535 /****************************************************************
9536 _spoolss_AddMonitor
9537 ****************************************************************/
9539 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
9540 struct spoolss_AddMonitor *r)
9542 p->rng_fault_state = true;
9543 return WERR_NOT_SUPPORTED;
9546 /****************************************************************
9547 _spoolss_DeleteMonitor
9548 ****************************************************************/
9550 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
9551 struct spoolss_DeleteMonitor *r)
9553 p->rng_fault_state = true;
9554 return WERR_NOT_SUPPORTED;
9557 /****************************************************************
9558 _spoolss_DeletePrintProcessor
9559 ****************************************************************/
9561 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
9562 struct spoolss_DeletePrintProcessor *r)
9564 p->rng_fault_state = true;
9565 return WERR_NOT_SUPPORTED;
9568 /****************************************************************
9569 _spoolss_AddPrintProvidor
9570 ****************************************************************/
9572 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
9573 struct spoolss_AddPrintProvidor *r)
9575 p->rng_fault_state = true;
9576 return WERR_NOT_SUPPORTED;
9579 /****************************************************************
9580 _spoolss_DeletePrintProvidor
9581 ****************************************************************/
9583 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
9584 struct spoolss_DeletePrintProvidor *r)
9586 p->rng_fault_state = true;
9587 return WERR_NOT_SUPPORTED;
9590 /****************************************************************
9591 _spoolss_FindFirstPrinterChangeNotification
9592 ****************************************************************/
9594 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
9595 struct spoolss_FindFirstPrinterChangeNotification *r)
9597 p->rng_fault_state = true;
9598 return WERR_NOT_SUPPORTED;
9601 /****************************************************************
9602 _spoolss_FindNextPrinterChangeNotification
9603 ****************************************************************/
9605 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
9606 struct spoolss_FindNextPrinterChangeNotification *r)
9608 p->rng_fault_state = true;
9609 return WERR_NOT_SUPPORTED;
9612 /****************************************************************
9613 _spoolss_RouterFindFirstPrinterChangeNotificationOld
9614 ****************************************************************/
9616 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
9617 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
9619 p->rng_fault_state = true;
9620 return WERR_NOT_SUPPORTED;
9623 /****************************************************************
9624 _spoolss_ReplyOpenPrinter
9625 ****************************************************************/
9627 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
9628 struct spoolss_ReplyOpenPrinter *r)
9630 p->rng_fault_state = true;
9631 return WERR_NOT_SUPPORTED;
9634 /****************************************************************
9635 _spoolss_RouterReplyPrinter
9636 ****************************************************************/
9638 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
9639 struct spoolss_RouterReplyPrinter *r)
9641 p->rng_fault_state = true;
9642 return WERR_NOT_SUPPORTED;
9645 /****************************************************************
9646 _spoolss_ReplyClosePrinter
9647 ****************************************************************/
9649 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
9650 struct spoolss_ReplyClosePrinter *r)
9652 p->rng_fault_state = true;
9653 return WERR_NOT_SUPPORTED;
9656 /****************************************************************
9657 _spoolss_AddPortEx
9658 ****************************************************************/
9660 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
9661 struct spoolss_AddPortEx *r)
9663 p->rng_fault_state = true;
9664 return WERR_NOT_SUPPORTED;
9667 /****************************************************************
9668 _spoolss_RouterFindFirstPrinterChangeNotification
9669 ****************************************************************/
9671 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
9672 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
9674 p->rng_fault_state = true;
9675 return WERR_NOT_SUPPORTED;
9678 /****************************************************************
9679 _spoolss_SpoolerInit
9680 ****************************************************************/
9682 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
9683 struct spoolss_SpoolerInit *r)
9685 p->rng_fault_state = true;
9686 return WERR_NOT_SUPPORTED;
9689 /****************************************************************
9690 _spoolss_ResetPrinterEx
9691 ****************************************************************/
9693 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
9694 struct spoolss_ResetPrinterEx *r)
9696 p->rng_fault_state = true;
9697 return WERR_NOT_SUPPORTED;
9700 /****************************************************************
9701 _spoolss_RouterReplyPrinterEx
9702 ****************************************************************/
9704 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
9705 struct spoolss_RouterReplyPrinterEx *r)
9707 p->rng_fault_state = true;
9708 return WERR_NOT_SUPPORTED;
9711 /****************************************************************
9712 _spoolss_44
9713 ****************************************************************/
9715 WERROR _spoolss_44(struct pipes_struct *p,
9716 struct spoolss_44 *r)
9718 p->rng_fault_state = true;
9719 return WERR_NOT_SUPPORTED;
9722 /****************************************************************
9723 _spoolss_47
9724 ****************************************************************/
9726 WERROR _spoolss_47(struct pipes_struct *p,
9727 struct spoolss_47 *r)
9729 p->rng_fault_state = true;
9730 return WERR_NOT_SUPPORTED;
9733 /****************************************************************
9734 _spoolss_4a
9735 ****************************************************************/
9737 WERROR _spoolss_4a(struct pipes_struct *p,
9738 struct spoolss_4a *r)
9740 p->rng_fault_state = true;
9741 return WERR_NOT_SUPPORTED;
9744 /****************************************************************
9745 _spoolss_4b
9746 ****************************************************************/
9748 WERROR _spoolss_4b(struct pipes_struct *p,
9749 struct spoolss_4b *r)
9751 p->rng_fault_state = true;
9752 return WERR_NOT_SUPPORTED;
9755 /****************************************************************
9756 _spoolss_4c
9757 ****************************************************************/
9759 WERROR _spoolss_4c(struct pipes_struct *p,
9760 struct spoolss_4c *r)
9762 p->rng_fault_state = true;
9763 return WERR_NOT_SUPPORTED;
9766 /****************************************************************
9767 _spoolss_53
9768 ****************************************************************/
9770 WERROR _spoolss_53(struct pipes_struct *p,
9771 struct spoolss_53 *r)
9773 p->rng_fault_state = true;
9774 return WERR_NOT_SUPPORTED;
9777 /****************************************************************
9778 _spoolss_55
9779 ****************************************************************/
9781 WERROR _spoolss_55(struct pipes_struct *p,
9782 struct spoolss_55 *r)
9784 p->rng_fault_state = true;
9785 return WERR_NOT_SUPPORTED;
9788 /****************************************************************
9789 _spoolss_56
9790 ****************************************************************/
9792 WERROR _spoolss_56(struct pipes_struct *p,
9793 struct spoolss_56 *r)
9795 p->rng_fault_state = true;
9796 return WERR_NOT_SUPPORTED;
9799 /****************************************************************
9800 _spoolss_57
9801 ****************************************************************/
9803 WERROR _spoolss_57(struct pipes_struct *p,
9804 struct spoolss_57 *r)
9806 p->rng_fault_state = true;
9807 return WERR_NOT_SUPPORTED;
9810 /****************************************************************
9811 _spoolss_5a
9812 ****************************************************************/
9814 WERROR _spoolss_5a(struct pipes_struct *p,
9815 struct spoolss_5a *r)
9817 p->rng_fault_state = true;
9818 return WERR_NOT_SUPPORTED;
9821 /****************************************************************
9822 _spoolss_5b
9823 ****************************************************************/
9825 WERROR _spoolss_5b(struct pipes_struct *p,
9826 struct spoolss_5b *r)
9828 p->rng_fault_state = true;
9829 return WERR_NOT_SUPPORTED;
9832 /****************************************************************
9833 _spoolss_5c
9834 ****************************************************************/
9836 WERROR _spoolss_5c(struct pipes_struct *p,
9837 struct spoolss_5c *r)
9839 p->rng_fault_state = true;
9840 return WERR_NOT_SUPPORTED;
9843 /****************************************************************
9844 _spoolss_5d
9845 ****************************************************************/
9847 WERROR _spoolss_5d(struct pipes_struct *p,
9848 struct spoolss_5d *r)
9850 p->rng_fault_state = true;
9851 return WERR_NOT_SUPPORTED;
9854 /****************************************************************
9855 _spoolss_5e
9856 ****************************************************************/
9858 WERROR _spoolss_5e(struct pipes_struct *p,
9859 struct spoolss_5e *r)
9861 p->rng_fault_state = true;
9862 return WERR_NOT_SUPPORTED;
9865 /****************************************************************
9866 _spoolss_5f
9867 ****************************************************************/
9869 WERROR _spoolss_5f(struct pipes_struct *p,
9870 struct spoolss_5f *r)
9872 p->rng_fault_state = true;
9873 return WERR_NOT_SUPPORTED;
9876 /****************************************************************
9877 _spoolss_60
9878 ****************************************************************/
9880 WERROR _spoolss_60(struct pipes_struct *p,
9881 struct spoolss_60 *r)
9883 p->rng_fault_state = true;
9884 return WERR_NOT_SUPPORTED;
9887 /****************************************************************
9888 _spoolss_61
9889 ****************************************************************/
9891 WERROR _spoolss_61(struct pipes_struct *p,
9892 struct spoolss_61 *r)
9894 p->rng_fault_state = true;
9895 return WERR_NOT_SUPPORTED;
9898 /****************************************************************
9899 _spoolss_62
9900 ****************************************************************/
9902 WERROR _spoolss_62(struct pipes_struct *p,
9903 struct spoolss_62 *r)
9905 p->rng_fault_state = true;
9906 return WERR_NOT_SUPPORTED;
9909 /****************************************************************
9910 _spoolss_63
9911 ****************************************************************/
9913 WERROR _spoolss_63(struct pipes_struct *p,
9914 struct spoolss_63 *r)
9916 p->rng_fault_state = true;
9917 return WERR_NOT_SUPPORTED;
9920 /****************************************************************
9921 _spoolss_64
9922 ****************************************************************/
9924 WERROR _spoolss_64(struct pipes_struct *p,
9925 struct spoolss_64 *r)
9927 p->rng_fault_state = true;
9928 return WERR_NOT_SUPPORTED;
9931 /****************************************************************
9932 _spoolss_65
9933 ****************************************************************/
9935 WERROR _spoolss_65(struct pipes_struct *p,
9936 struct spoolss_65 *r)
9938 p->rng_fault_state = true;
9939 return WERR_NOT_SUPPORTED;
9942 /****************************************************************
9943 _spoolss_GetCorePrinterDrivers
9944 ****************************************************************/
9946 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
9947 struct spoolss_GetCorePrinterDrivers *r)
9949 p->rng_fault_state = true;
9950 return WERR_NOT_SUPPORTED;
9953 /****************************************************************
9954 _spoolss_67
9955 ****************************************************************/
9957 WERROR _spoolss_67(struct pipes_struct *p,
9958 struct spoolss_67 *r)
9960 p->rng_fault_state = true;
9961 return WERR_NOT_SUPPORTED;
9964 /****************************************************************
9965 _spoolss_GetPrinterDriverPackagePath
9966 ****************************************************************/
9968 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
9969 struct spoolss_GetPrinterDriverPackagePath *r)
9971 p->rng_fault_state = true;
9972 return WERR_NOT_SUPPORTED;
9975 /****************************************************************
9976 _spoolss_69
9977 ****************************************************************/
9979 WERROR _spoolss_69(struct pipes_struct *p,
9980 struct spoolss_69 *r)
9982 p->rng_fault_state = true;
9983 return WERR_NOT_SUPPORTED;
9986 /****************************************************************
9987 _spoolss_6a
9988 ****************************************************************/
9990 WERROR _spoolss_6a(struct pipes_struct *p,
9991 struct spoolss_6a *r)
9993 p->rng_fault_state = true;
9994 return WERR_NOT_SUPPORTED;
9997 /****************************************************************
9998 _spoolss_6b
9999 ****************************************************************/
10001 WERROR _spoolss_6b(struct pipes_struct *p,
10002 struct spoolss_6b *r)
10004 p->rng_fault_state = true;
10005 return WERR_NOT_SUPPORTED;
10008 /****************************************************************
10009 _spoolss_6c
10010 ****************************************************************/
10012 WERROR _spoolss_6c(struct pipes_struct *p,
10013 struct spoolss_6c *r)
10015 p->rng_fault_state = true;
10016 return WERR_NOT_SUPPORTED;
10019 /****************************************************************
10020 _spoolss_6d
10021 ****************************************************************/
10023 WERROR _spoolss_6d(struct pipes_struct *p,
10024 struct spoolss_6d *r)
10026 p->rng_fault_state = true;
10027 return WERR_NOT_SUPPORTED;