spoolss: return the spoolss job ID in notifications
[Samba.git] / source3 / rpc_server / spoolss / srv_spoolss_nt.c
bloba6201d4f55e7dcec9a88a53d6356ac4e63bd4b4c
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 "ntdomain.h"
32 #include "nt_printing.h"
33 #include "srv_spoolss_util.h"
34 #include "../librpc/gen_ndr/srv_spoolss.h"
35 #include "../librpc/gen_ndr/ndr_spoolss_c.h"
36 #include "rpc_client/init_spoolss.h"
37 #include "rpc_client/cli_pipe.h"
38 #include "../libcli/security/security.h"
39 #include "librpc/gen_ndr/ndr_security.h"
40 #include "registry.h"
41 #include "include/printing.h"
42 #include "secrets.h"
43 #include "../librpc/gen_ndr/netlogon.h"
44 #include "rpc_misc.h"
45 #include "printing/notify.h"
46 #include "serverid.h"
47 #include "../libcli/registry/util_reg.h"
48 #include "smbd/smbd.h"
49 #include "smbd/globals.h"
50 #include "auth.h"
51 #include "messages.h"
52 #include "rpc_server/spoolss/srv_spoolss_nt.h"
53 #include "util_tdb.h"
54 #include "libsmb/libsmb.h"
55 #include "printing/printer_list.h"
56 #include "../lib/tsocket/tsocket.h"
57 #include "rpc_client/cli_winreg_spoolss.h"
58 #include "../libcli/smb/smbXcli_base.h"
60 /* macros stolen from s4 spoolss server */
61 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
62 ((info)?ndr_size_##fn(info, level, 0):0)
64 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
65 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
67 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
68 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
70 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
72 #undef DBGC_CLASS
73 #define DBGC_CLASS DBGC_RPC_SRV
75 #ifndef MAX_OPEN_PRINTER_EXS
76 #define MAX_OPEN_PRINTER_EXS 50
77 #endif
79 struct notify_back_channel;
81 /* structure to store the printer handles */
82 /* and a reference to what it's pointing to */
83 /* and the notify info asked about */
84 /* that's the central struct */
85 struct printer_handle {
86 struct printer_handle *prev, *next;
87 bool document_started;
88 bool page_started;
89 uint32 jobid; /* jobid in printing backend */
90 int printer_type;
91 const char *servername;
92 fstring sharename;
93 uint32 type;
94 uint32 access_granted;
95 struct {
96 uint32 flags;
97 uint32 options;
98 fstring localmachine;
99 uint32 printerlocal;
100 struct spoolss_NotifyOption *option;
101 struct policy_handle cli_hnd;
102 struct notify_back_channel *cli_chan;
103 uint32 change;
104 /* are we in a FindNextPrinterChangeNotify() call? */
105 bool fnpcn;
106 struct messaging_context *msg_ctx;
107 } notify;
108 struct {
109 fstring machine;
110 fstring user;
111 } client;
113 /* devmode sent in the OpenPrinter() call */
114 struct spoolss_DeviceMode *devmode;
116 /* TODO cache the printer info2 structure */
117 struct spoolss_PrinterInfo2 *info2;
121 static struct printer_handle *printers_list;
123 struct printer_session_counter {
124 struct printer_session_counter *next;
125 struct printer_session_counter *prev;
127 int snum;
128 uint32_t counter;
131 static struct printer_session_counter *counter_list;
133 struct notify_back_channel {
134 struct notify_back_channel *prev, *next;
136 /* associated client */
137 struct sockaddr_storage client_address;
139 /* print notify back-channel pipe handle*/
140 struct rpc_pipe_client *cli_pipe;
141 struct cli_state *cli;
142 uint32_t active_connections;
145 static struct notify_back_channel *back_channels;
147 /* Map generic permissions to printer object specific permissions */
149 const struct standard_mapping printer_std_mapping = {
150 PRINTER_READ,
151 PRINTER_WRITE,
152 PRINTER_EXECUTE,
153 PRINTER_ALL_ACCESS
156 /* Map generic permissions to print server object specific permissions */
158 const struct standard_mapping printserver_std_mapping = {
159 SERVER_READ,
160 SERVER_WRITE,
161 SERVER_EXECUTE,
162 SERVER_ALL_ACCESS
165 /* API table for Xcv Monitor functions */
167 struct xcv_api_table {
168 const char *name;
169 WERROR(*fn) (TALLOC_CTX *mem_ctx, struct security_token *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
172 static void prune_printername_cache(void);
174 /********************************************************************
175 * Canonicalize servername.
176 ********************************************************************/
178 static const char *canon_servername(const char *servername)
180 const char *pservername = servername;
181 while (*pservername == '\\') {
182 pservername++;
184 return pservername;
187 /* translate between internal status numbers and NT status numbers */
188 static int nt_printj_status(int v)
190 switch (v) {
191 case LPQ_QUEUED:
192 return 0;
193 case LPQ_PAUSED:
194 return JOB_STATUS_PAUSED;
195 case LPQ_SPOOLING:
196 return JOB_STATUS_SPOOLING;
197 case LPQ_PRINTING:
198 return JOB_STATUS_PRINTING;
199 case LPQ_ERROR:
200 return JOB_STATUS_ERROR;
201 case LPQ_DELETING:
202 return JOB_STATUS_DELETING;
203 case LPQ_OFFLINE:
204 return JOB_STATUS_OFFLINE;
205 case LPQ_PAPEROUT:
206 return JOB_STATUS_PAPEROUT;
207 case LPQ_PRINTED:
208 return JOB_STATUS_PRINTED;
209 case LPQ_DELETED:
210 return JOB_STATUS_DELETED;
211 case LPQ_BLOCKED:
212 return JOB_STATUS_BLOCKED_DEVQ;
213 case LPQ_USER_INTERVENTION:
214 return JOB_STATUS_USER_INTERVENTION;
216 return 0;
219 static int nt_printq_status(int v)
221 switch (v) {
222 case LPQ_PAUSED:
223 return PRINTER_STATUS_PAUSED;
224 case LPQ_QUEUED:
225 case LPQ_SPOOLING:
226 case LPQ_PRINTING:
227 return 0;
229 return 0;
232 /***************************************************************************
233 Disconnect from the client
234 ****************************************************************************/
236 static void srv_spoolss_replycloseprinter(int snum,
237 struct printer_handle *prn_hnd)
239 WERROR result;
240 NTSTATUS status;
243 * Tell the specific printing tdb we no longer want messages for this printer
244 * by deregistering our PID.
247 if (!print_notify_deregister_pid(snum)) {
248 DEBUG(0, ("Failed to register our pid for printer %s\n",
249 lp_const_servicename(snum)));
252 /* weird if the test succeeds !!! */
253 if (prn_hnd->notify.cli_chan == NULL ||
254 prn_hnd->notify.cli_chan->cli_pipe == NULL ||
255 prn_hnd->notify.cli_chan->cli_pipe->binding_handle == NULL ||
256 prn_hnd->notify.cli_chan->active_connections == 0) {
257 DEBUG(0, ("Trying to close unexisting backchannel!\n"));
258 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
259 TALLOC_FREE(prn_hnd->notify.cli_chan);
260 return;
263 status = dcerpc_spoolss_ReplyClosePrinter(
264 prn_hnd->notify.cli_chan->cli_pipe->binding_handle,
265 talloc_tos(),
266 &prn_hnd->notify.cli_hnd,
267 &result);
268 if (!NT_STATUS_IS_OK(status)) {
269 DEBUG(0, ("dcerpc_spoolss_ReplyClosePrinter failed [%s].\n",
270 nt_errstr(status)));
271 result = ntstatus_to_werror(status);
272 } else if (!W_ERROR_IS_OK(result)) {
273 DEBUG(0, ("reply_close_printer failed [%s].\n",
274 win_errstr(result)));
277 /* if it's the last connection, deconnect the IPC$ share */
278 if (prn_hnd->notify.cli_chan->active_connections == 1) {
280 cli_shutdown(prn_hnd->notify.cli_chan->cli);
281 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
282 TALLOC_FREE(prn_hnd->notify.cli_chan);
284 if (prn_hnd->notify.msg_ctx != NULL) {
285 messaging_deregister(prn_hnd->notify.msg_ctx,
286 MSG_PRINTER_NOTIFY2, NULL);
290 if (prn_hnd->notify.cli_chan) {
291 prn_hnd->notify.cli_chan->active_connections--;
292 prn_hnd->notify.cli_chan = NULL;
296 /****************************************************************************
297 Functions to free a printer entry datastruct.
298 ****************************************************************************/
300 static int printer_entry_destructor(struct printer_handle *Printer)
302 if (Printer->notify.cli_chan != NULL &&
303 Printer->notify.cli_chan->active_connections > 0) {
304 int snum = -1;
306 switch(Printer->printer_type) {
307 case SPLHND_SERVER:
308 srv_spoolss_replycloseprinter(snum, Printer);
309 break;
311 case SPLHND_PRINTER:
312 snum = print_queue_snum(Printer->sharename);
313 if (snum != -1) {
314 srv_spoolss_replycloseprinter(snum, Printer);
316 break;
317 default:
318 break;
322 Printer->notify.flags=0;
323 Printer->notify.options=0;
324 Printer->notify.localmachine[0]='\0';
325 Printer->notify.printerlocal=0;
326 TALLOC_FREE(Printer->notify.option);
327 TALLOC_FREE(Printer->devmode);
329 /* Remove from the internal list. */
330 DLIST_REMOVE(printers_list, Printer);
331 return 0;
334 /****************************************************************************
335 find printer index by handle
336 ****************************************************************************/
338 static struct printer_handle *find_printer_index_by_hnd(struct pipes_struct *p,
339 struct policy_handle *hnd)
341 struct printer_handle *find_printer = NULL;
343 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
344 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
345 return NULL;
348 return find_printer;
351 /****************************************************************************
352 Close printer index by handle.
353 ****************************************************************************/
355 static bool close_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
357 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
359 if (!Printer) {
360 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
361 OUR_HANDLE(hnd)));
362 return false;
365 close_policy_hnd(p, hnd);
367 return true;
370 /****************************************************************************
371 Delete a printer given a handle.
372 ****************************************************************************/
374 static WERROR delete_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
375 const char *sharename,
376 struct messaging_context *msg_ctx)
378 char *cmd = lp_deleteprinter_cmd(talloc_tos());
379 char *command = NULL;
380 int ret;
381 bool is_print_op = false;
383 /* can't fail if we don't try */
385 if ( !*cmd )
386 return WERR_OK;
388 command = talloc_asprintf(ctx,
389 "%s \"%s\"",
390 cmd, sharename);
391 if (!command) {
392 return WERR_NOMEM;
394 if ( token )
395 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
397 DEBUG(10,("Running [%s]\n", command));
399 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
401 if ( is_print_op )
402 become_root();
404 if ( (ret = smbrun(command, NULL)) == 0 ) {
405 /* Tell everyone we updated smb.conf. */
406 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
409 if ( is_print_op )
410 unbecome_root();
412 /********** END SePrintOperatorPrivlege BLOCK **********/
414 DEBUGADD(10,("returned [%d]\n", ret));
416 TALLOC_FREE(command);
418 if (ret != 0)
419 return WERR_BADFID; /* What to return here? */
421 return WERR_OK;
424 /****************************************************************************
425 Delete a printer given a handle.
426 ****************************************************************************/
428 static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
430 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
431 WERROR result;
433 if (!Printer) {
434 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
435 OUR_HANDLE(hnd)));
436 return WERR_BADFID;
440 * It turns out that Windows allows delete printer on a handle
441 * opened by an admin user, then used on a pipe handle created
442 * by an anonymous user..... but they're working on security.... riiight !
443 * JRA.
446 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
447 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
448 return WERR_ACCESS_DENIED;
451 /* this does not need a become root since the access check has been
452 done on the handle already */
454 result = winreg_delete_printer_key_internal(p->mem_ctx,
455 get_session_info_system(),
456 p->msg_ctx,
457 Printer->sharename,
458 "");
459 if (!W_ERROR_IS_OK(result)) {
460 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
461 return WERR_BADFID;
464 result = delete_printer_hook(p->mem_ctx, p->session_info->security_token,
465 Printer->sharename, p->msg_ctx);
466 if (!W_ERROR_IS_OK(result)) {
467 return result;
469 prune_printername_cache();
470 return WERR_OK;
473 /****************************************************************************
474 Return the snum of a printer corresponding to an handle.
475 ****************************************************************************/
477 static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
478 int *number, struct share_params **params)
480 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
482 if (!Printer) {
483 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
484 OUR_HANDLE(hnd)));
485 return false;
488 switch (Printer->printer_type) {
489 case SPLHND_PRINTER:
490 DEBUG(4,("short name:%s\n", Printer->sharename));
491 *number = print_queue_snum(Printer->sharename);
492 return (*number != -1);
493 case SPLHND_SERVER:
494 return false;
495 default:
496 return false;
500 /****************************************************************************
501 Set printer handle type.
502 Check if it's \\server or \\server\printer
503 ****************************************************************************/
505 static bool set_printer_hnd_printertype(struct printer_handle *Printer, const char *handlename)
507 DEBUG(3,("Setting printer type=%s\n", handlename));
509 /* it's a print server */
510 if (handlename && *handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
511 DEBUGADD(4,("Printer is a print server\n"));
512 Printer->printer_type = SPLHND_SERVER;
514 /* it's a printer (set_printer_hnd_name() will handle port monitors */
515 else {
516 DEBUGADD(4,("Printer is a printer\n"));
517 Printer->printer_type = SPLHND_PRINTER;
520 return true;
523 static void prune_printername_cache_fn(const char *key, const char *value,
524 time_t timeout, void *private_data)
526 gencache_del(key);
529 static void prune_printername_cache(void)
531 gencache_iterate(prune_printername_cache_fn, NULL, "PRINTERNAME/*");
534 /****************************************************************************
535 Set printer handle name.. Accept names like \\server, \\server\printer,
536 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
537 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
538 XcvDataPort() interface.
539 ****************************************************************************/
541 static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
542 const struct auth_session_info *session_info,
543 struct messaging_context *msg_ctx,
544 struct printer_handle *Printer,
545 const char *handlename)
547 int snum;
548 int n_services=lp_numservices();
549 char *aprinter;
550 const char *printername;
551 const char *servername = NULL;
552 fstring sname;
553 bool found = false;
554 struct spoolss_PrinterInfo2 *info2 = NULL;
555 WERROR result;
556 char *p;
559 * Hopefully nobody names his printers like this. Maybe \ or ,
560 * are illegal in printer names even?
562 const char printer_not_found[] = "Printer \\, !@#$%^&*( not found";
563 char *cache_key;
564 char *tmp;
566 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
567 (unsigned long)strlen(handlename)));
569 aprinter = discard_const_p(char, handlename);
570 if ( *handlename == '\\' ) {
571 servername = canon_servername(handlename);
572 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
573 *aprinter = '\0';
574 aprinter++;
576 if (!is_myname_or_ipaddr(servername)) {
577 return WERR_INVALID_PRINTER_NAME;
579 Printer->servername = talloc_asprintf(Printer, "\\\\%s", servername);
580 if (Printer->servername == NULL) {
581 return WERR_NOMEM;
585 if (Printer->printer_type == SPLHND_SERVER) {
586 return WERR_OK;
589 if (Printer->printer_type != SPLHND_PRINTER) {
590 return WERR_INVALID_HANDLE;
593 DEBUGADD(5, ("searching for [%s]\n", aprinter));
595 p = strchr(aprinter, ',');
596 if (p != NULL) {
597 char *p2 = p;
598 p++;
599 if (*p == ' ') {
600 p++;
602 if (strncmp(p, "DrvConvert", strlen("DrvConvert")) == 0) {
603 *p2 = '\0';
604 } else if (strncmp(p, "LocalOnly", strlen("LocalOnly")) == 0) {
605 *p2 = '\0';
609 if (p) {
610 DEBUGADD(5, ("stripped handlename: [%s]\n", aprinter));
613 /* check for the Port Monitor Interface */
614 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
615 Printer->printer_type = SPLHND_PORTMON_TCP;
616 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
617 found = true;
619 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
620 Printer->printer_type = SPLHND_PORTMON_LOCAL;
621 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
622 found = true;
626 * With hundreds of printers, the "for" loop iterating all
627 * shares can be quite expensive, as it is done on every
628 * OpenPrinter. The loop maps "aprinter" to "sname", the
629 * result of which we cache in gencache.
632 cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
633 aprinter);
634 if ((cache_key != NULL) &&
635 gencache_get(cache_key, talloc_tos(), &tmp, NULL)) {
637 found = (strcmp(tmp, printer_not_found) != 0);
638 if (!found) {
639 DEBUG(4, ("Printer %s not found\n", aprinter));
640 TALLOC_FREE(tmp);
641 return WERR_INVALID_PRINTER_NAME;
643 fstrcpy(sname, tmp);
644 TALLOC_FREE(tmp);
647 /* Search all sharenames first as this is easier than pulling
648 the printer_info_2 off of disk. Don't use find_service() since
649 that calls out to map_username() */
651 /* do another loop to look for printernames */
652 for (snum = 0; !found && snum < n_services; snum++) {
653 const char *printer = lp_const_servicename(snum);
655 /* no point going on if this is not a printer */
656 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
657 continue;
660 /* ignore [printers] share */
661 if (strequal(printer, "printers")) {
662 continue;
665 fstrcpy(sname, printer);
666 if (strequal(aprinter, printer)) {
667 found = true;
668 break;
671 /* no point looking up the printer object if
672 we aren't allowing printername != sharename */
673 if (lp_force_printername(snum)) {
674 continue;
677 result = winreg_get_printer_internal(mem_ctx,
678 session_info,
679 msg_ctx,
680 sname,
681 &info2);
682 if ( !W_ERROR_IS_OK(result) ) {
683 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
684 sname, win_errstr(result)));
685 continue;
688 printername = strrchr(info2->printername, '\\');
689 if (printername == NULL) {
690 printername = info2->printername;
691 } else {
692 printername++;
695 if (strequal(printername, aprinter)) {
696 found = true;
697 break;
700 DEBUGADD(10, ("printername: %s\n", printername));
702 TALLOC_FREE(info2);
705 if ( !found ) {
706 if (cache_key != NULL) {
707 gencache_set(cache_key, printer_not_found,
708 time(NULL)+300);
709 TALLOC_FREE(cache_key);
711 DEBUGADD(4,("Printer not found\n"));
712 return WERR_INVALID_PRINTER_NAME;
715 if (cache_key != NULL) {
716 gencache_set(cache_key, sname, time(NULL)+300);
717 TALLOC_FREE(cache_key);
720 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
722 strlcpy(Printer->sharename, sname, sizeof(Printer->sharename));
724 return WERR_OK;
727 /****************************************************************************
728 Find first available printer slot. creates a printer handle for you.
729 ****************************************************************************/
731 static WERROR open_printer_hnd(struct pipes_struct *p,
732 struct policy_handle *hnd,
733 const char *name,
734 uint32_t access_granted)
736 struct printer_handle *new_printer;
737 WERROR result;
739 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
741 new_printer = talloc_zero(p->mem_ctx, struct printer_handle);
742 if (new_printer == NULL) {
743 return WERR_NOMEM;
745 talloc_set_destructor(new_printer, printer_entry_destructor);
747 /* This also steals the printer_handle on the policy_handle */
748 if (!create_policy_hnd(p, hnd, new_printer)) {
749 TALLOC_FREE(new_printer);
750 return WERR_INVALID_HANDLE;
753 /* Add to the internal list. */
754 DLIST_ADD(printers_list, new_printer);
756 new_printer->notify.option=NULL;
758 if (!set_printer_hnd_printertype(new_printer, name)) {
759 close_printer_handle(p, hnd);
760 return WERR_INVALID_HANDLE;
763 result = set_printer_hnd_name(p->mem_ctx,
764 get_session_info_system(),
765 p->msg_ctx,
766 new_printer, name);
767 if (!W_ERROR_IS_OK(result)) {
768 close_printer_handle(p, hnd);
769 return result;
772 new_printer->access_granted = access_granted;
774 DEBUG(5, ("%d printer handles active\n",
775 (int)num_pipe_handles(p)));
777 return WERR_OK;
780 /***************************************************************************
781 check to see if the client motify handle is monitoring the notification
782 given by (notify_type, notify_field).
783 **************************************************************************/
785 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
786 uint16_t notify_field)
788 return true;
791 static bool is_monitoring_event(struct printer_handle *p, uint16_t notify_type,
792 uint16_t notify_field)
794 struct spoolss_NotifyOption *option = p->notify.option;
795 uint32_t i, j;
798 * Flags should always be zero when the change notify
799 * is registered by the client's spooler. A user Win32 app
800 * might use the flags though instead of the NOTIFY_OPTION_INFO
801 * --jerry
804 if (!option) {
805 return false;
808 if (p->notify.flags)
809 return is_monitoring_event_flags(
810 p->notify.flags, notify_type, notify_field);
812 for (i = 0; i < option->count; i++) {
814 /* Check match for notify_type */
816 if (option->types[i].type != notify_type)
817 continue;
819 /* Check match for field */
821 for (j = 0; j < option->types[i].count; j++) {
822 if (option->types[i].fields[j].field == notify_field) {
823 return true;
828 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
829 p->servername, p->sharename, notify_type, notify_field));
831 return false;
834 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
835 _data->data.integer[0] = _integer; \
836 _data->data.integer[1] = 0;
839 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
840 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
841 if (!_data->data.string.string) {\
842 _data->data.string.size = 0; \
844 _data->data.string.size = strlen_m_term(_p) * 2;
846 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
847 _data->data.devmode.devmode = _devmode;
849 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
850 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
851 if (!_data->data.sd.sd) { \
852 _data->data.sd.sd_size = 0; \
854 _data->data.sd.sd_size = \
855 ndr_size_security_descriptor(_data->data.sd.sd, 0);
857 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
858 struct tm *t,
859 const char **pp,
860 uint32_t *plen)
862 struct spoolss_Time st;
863 uint32_t len = 16;
864 char *p;
866 if (!init_systemtime(&st, t)) {
867 return;
870 p = talloc_array(mem_ctx, char, len);
871 if (!p) {
872 return;
876 * Systemtime must be linearized as a set of UINT16's.
877 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
880 SSVAL(p, 0, st.year);
881 SSVAL(p, 2, st.month);
882 SSVAL(p, 4, st.day_of_week);
883 SSVAL(p, 6, st.day);
884 SSVAL(p, 8, st.hour);
885 SSVAL(p, 10, st.minute);
886 SSVAL(p, 12, st.second);
887 SSVAL(p, 14, st.millisecond);
889 *pp = p;
890 *plen = len;
893 /* Convert a notification message to a struct spoolss_Notify */
895 static void notify_one_value(struct spoolss_notify_msg *msg,
896 struct spoolss_Notify *data,
897 TALLOC_CTX *mem_ctx)
899 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
902 static void notify_string(struct spoolss_notify_msg *msg,
903 struct spoolss_Notify *data,
904 TALLOC_CTX *mem_ctx)
906 /* The length of the message includes the trailing \0 */
908 data->data.string.size = msg->len * 2;
909 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
910 if (!data->data.string.string) {
911 data->data.string.size = 0;
912 return;
916 static void notify_system_time(struct spoolss_notify_msg *msg,
917 struct spoolss_Notify *data,
918 TALLOC_CTX *mem_ctx)
920 data->data.string.string = NULL;
921 data->data.string.size = 0;
923 if (msg->len != sizeof(time_t)) {
924 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
925 msg->len));
926 return;
929 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
930 &data->data.string.string,
931 &data->data.string.size);
934 struct notify2_message_table {
935 const char *name;
936 void (*fn)(struct spoolss_notify_msg *msg,
937 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
940 static struct notify2_message_table printer_notify_table[] = {
941 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
942 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
943 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
944 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
945 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
946 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
947 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
948 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
949 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
950 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
951 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
952 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
953 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
954 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
955 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
956 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
957 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
958 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
959 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
962 static struct notify2_message_table job_notify_table[] = {
963 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
964 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
965 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
966 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
967 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
968 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
969 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
970 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
971 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
972 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
973 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
974 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
975 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
976 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
977 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
978 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
979 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
980 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
981 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
982 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
983 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
984 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
985 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
986 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
990 /***********************************************************************
991 Allocate talloc context for container object
992 **********************************************************************/
994 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
996 if ( !ctr )
997 return;
999 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
1001 return;
1004 /***********************************************************************
1005 release all allocated memory and zero out structure
1006 **********************************************************************/
1008 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1010 if ( !ctr )
1011 return;
1013 if ( ctr->ctx )
1014 talloc_destroy(ctr->ctx);
1016 ZERO_STRUCTP(ctr);
1018 return;
1021 /***********************************************************************
1022 **********************************************************************/
1024 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1026 if ( !ctr )
1027 return NULL;
1029 return ctr->ctx;
1032 /***********************************************************************
1033 **********************************************************************/
1035 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1037 if ( !ctr || !ctr->msg_groups )
1038 return NULL;
1040 if ( idx >= ctr->num_groups )
1041 return NULL;
1043 return &ctr->msg_groups[idx];
1047 /***********************************************************************
1048 How many groups of change messages do we have ?
1049 **********************************************************************/
1051 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1053 if ( !ctr )
1054 return 0;
1056 return ctr->num_groups;
1059 /***********************************************************************
1060 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1061 **********************************************************************/
1063 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
1065 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
1066 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
1067 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
1068 int i, new_slot;
1070 if ( !ctr || !msg )
1071 return 0;
1073 /* loop over all groups looking for a matching printer name */
1075 for ( i=0; i<ctr->num_groups; i++ ) {
1076 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
1077 break;
1080 /* add a new group? */
1082 if ( i == ctr->num_groups ) {
1083 ctr->num_groups++;
1085 if ( !(groups = talloc_realloc( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
1086 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1087 return 0;
1089 ctr->msg_groups = groups;
1091 /* clear the new entry and set the printer name */
1093 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
1094 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
1097 /* add the change messages; 'i' is the correct index now regardless */
1099 msg_grp = &ctr->msg_groups[i];
1101 msg_grp->num_msgs++;
1103 if ( !(msg_list = talloc_realloc( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
1104 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
1105 return 0;
1107 msg_grp->msgs = msg_list;
1109 new_slot = msg_grp->num_msgs-1;
1110 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
1112 /* need to allocate own copy of data */
1114 if ( msg->len != 0 )
1115 msg_grp->msgs[new_slot].notify.data = (char *)
1116 talloc_memdup( ctr->ctx, msg->notify.data, msg->len );
1118 return ctr->num_groups;
1121 static void construct_info_data(struct spoolss_Notify *info_data,
1122 enum spoolss_NotifyType type,
1123 uint16_t field, int id);
1125 /***********************************************************************
1126 Send a change notication message on all handles which have a call
1127 back registered
1128 **********************************************************************/
1130 static int build_notify2_messages(TALLOC_CTX *mem_ctx,
1131 struct printer_handle *prn_hnd,
1132 SPOOLSS_NOTIFY_MSG *messages,
1133 uint32_t num_msgs,
1134 struct spoolss_Notify **_notifies,
1135 int *_count)
1137 struct spoolss_Notify *notifies;
1138 SPOOLSS_NOTIFY_MSG *msg;
1139 int count = 0;
1140 uint32_t id;
1141 int i;
1143 notifies = talloc_zero_array(mem_ctx,
1144 struct spoolss_Notify, num_msgs);
1145 if (!notifies) {
1146 return ENOMEM;
1149 for (i = 0; i < num_msgs; i++) {
1151 msg = &messages[i];
1153 /* Are we monitoring this event? */
1155 if (!is_monitoring_event(prn_hnd, msg->type, msg->field)) {
1156 continue;
1159 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1160 "for printer [%s]\n",
1161 msg->type, msg->field, prn_hnd->sharename));
1164 * if the is a printer notification handle and not a job
1165 * notification type, then set the id to 0.
1166 * Otherwise just use what was specified in the message.
1168 * When registering change notification on a print server
1169 * handle we always need to send back the id (snum) matching
1170 * the printer for which the change took place.
1171 * For change notify registered on a printer handle,
1172 * this does not matter and the id should be 0.
1174 * --jerry
1177 if ((msg->type == PRINTER_NOTIFY_TYPE) &&
1178 (prn_hnd->printer_type == SPLHND_PRINTER)) {
1179 id = 0;
1180 } else {
1181 id = msg->id;
1184 /* Convert unix jobid to smb jobid */
1186 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1187 id = sysjob_to_jobid(msg->id);
1189 if (id == -1) {
1190 DEBUG(3, ("no such unix jobid %d\n",
1191 msg->id));
1192 continue;
1196 construct_info_data(&notifies[count],
1197 msg->type, msg->field, id);
1199 switch(msg->type) {
1200 case PRINTER_NOTIFY_TYPE:
1201 if (printer_notify_table[msg->field].fn) {
1202 printer_notify_table[msg->field].fn(msg,
1203 &notifies[count], mem_ctx);
1205 break;
1207 case JOB_NOTIFY_TYPE:
1208 if (job_notify_table[msg->field].fn) {
1209 job_notify_table[msg->field].fn(msg,
1210 &notifies[count], mem_ctx);
1212 break;
1214 default:
1215 DEBUG(5, ("Unknown notification type %d\n",
1216 msg->type));
1217 continue;
1220 count++;
1223 *_notifies = notifies;
1224 *_count = count;
1226 return 0;
1229 static int send_notify2_printer(TALLOC_CTX *mem_ctx,
1230 struct printer_handle *prn_hnd,
1231 SPOOLSS_NOTIFY_MSG_GROUP *msg_group)
1233 struct spoolss_Notify *notifies;
1234 int count = 0;
1235 union spoolss_ReplyPrinterInfo info;
1236 struct spoolss_NotifyInfo info0;
1237 uint32_t reply_result;
1238 NTSTATUS status;
1239 WERROR werr;
1240 int ret;
1242 /* Is there notification on this handle? */
1243 if (prn_hnd->notify.cli_chan == NULL ||
1244 prn_hnd->notify.cli_chan->cli_pipe == NULL ||
1245 prn_hnd->notify.cli_chan->cli_pipe->binding_handle == NULL ||
1246 prn_hnd->notify.cli_chan->active_connections == 0) {
1247 return 0;
1250 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1251 prn_hnd->servername, prn_hnd->sharename));
1253 /* For this printer? Print servers always receive notifications. */
1254 if ((prn_hnd->printer_type == SPLHND_PRINTER) &&
1255 (!strequal(msg_group->printername, prn_hnd->sharename))) {
1256 return 0;
1259 DEBUG(10,("Our printer\n"));
1261 /* build the array of change notifications */
1262 ret = build_notify2_messages(mem_ctx, prn_hnd,
1263 msg_group->msgs,
1264 msg_group->num_msgs,
1265 &notifies, &count);
1266 if (ret) {
1267 return ret;
1270 info0.version = 0x2;
1271 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1272 info0.count = count;
1273 info0.notifies = notifies;
1275 info.info0 = &info0;
1277 status = dcerpc_spoolss_RouterReplyPrinterEx(
1278 prn_hnd->notify.cli_chan->cli_pipe->binding_handle,
1279 mem_ctx,
1280 &prn_hnd->notify.cli_hnd,
1281 prn_hnd->notify.change, /* color */
1282 prn_hnd->notify.flags,
1283 &reply_result,
1284 0, /* reply_type, must be 0 */
1285 info, &werr);
1286 if (!NT_STATUS_IS_OK(status)) {
1287 DEBUG(1, ("dcerpc_spoolss_RouterReplyPrinterEx to client: %s "
1288 "failed: %s\n",
1289 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1290 nt_errstr(status)));
1291 werr = ntstatus_to_werror(status);
1292 } else if (!W_ERROR_IS_OK(werr)) {
1293 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1294 "failed: %s\n",
1295 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1296 win_errstr(werr)));
1298 switch (reply_result) {
1299 case 0:
1300 break;
1301 case PRINTER_NOTIFY_INFO_DISCARDED:
1302 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1303 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1304 break;
1305 default:
1306 break;
1309 return 0;
1312 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1314 struct printer_handle *p;
1315 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
1316 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
1317 int ret;
1319 if ( !msg_group ) {
1320 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1321 return;
1324 if (!msg_group->msgs) {
1325 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1326 return;
1329 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
1331 /* loop over all printers */
1333 for (p = printers_list; p; p = p->next) {
1334 ret = send_notify2_printer(mem_ctx, p, msg_group);
1335 if (ret) {
1336 goto done;
1340 done:
1341 DEBUG(8,("send_notify2_changes: Exit...\n"));
1342 return;
1345 /***********************************************************************
1346 **********************************************************************/
1348 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1351 uint32_t tv_sec, tv_usec;
1352 size_t offset = 0;
1354 /* Unpack message */
1356 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1357 msg->printer);
1359 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1360 &tv_sec, &tv_usec,
1361 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1363 if (msg->len == 0)
1364 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1365 &msg->notify.value[0], &msg->notify.value[1]);
1366 else
1367 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1368 &msg->len, &msg->notify.data);
1370 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1371 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1373 tv->tv_sec = tv_sec;
1374 tv->tv_usec = tv_usec;
1376 if (msg->len == 0)
1377 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1378 msg->notify.value[1]));
1379 else
1380 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1382 return true;
1385 /********************************************************************
1386 Receive a notify2 message list
1387 ********************************************************************/
1389 static void receive_notify2_message_list(struct messaging_context *msg,
1390 void *private_data,
1391 uint32_t msg_type,
1392 struct server_id server_id,
1393 DATA_BLOB *data)
1395 size_t msg_count, i;
1396 char *buf = (char *)data->data;
1397 char *msg_ptr;
1398 size_t msg_len;
1399 SPOOLSS_NOTIFY_MSG notify;
1400 SPOOLSS_NOTIFY_MSG_CTR messages;
1401 int num_groups;
1403 if (data->length < 4) {
1404 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1405 return;
1408 msg_count = IVAL(buf, 0);
1409 msg_ptr = buf + 4;
1411 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1413 if (msg_count == 0) {
1414 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1415 return;
1418 /* initialize the container */
1420 ZERO_STRUCT( messages );
1421 notify_msg_ctr_init( &messages );
1424 * build message groups for each printer identified
1425 * in a change_notify msg. Remember that a PCN message
1426 * includes the handle returned for the srv_spoolss_replyopenprinter()
1427 * call. Therefore messages are grouped according to printer handle.
1430 for ( i=0; i<msg_count; i++ ) {
1431 struct timeval msg_tv;
1433 if (msg_ptr + 4 - buf > data->length) {
1434 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1435 return;
1438 msg_len = IVAL(msg_ptr,0);
1439 msg_ptr += 4;
1441 if (msg_ptr + msg_len - buf > data->length) {
1442 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1443 return;
1446 /* unpack messages */
1448 ZERO_STRUCT( notify );
1449 notify2_unpack_msg( &notify, &msg_tv, msg_ptr, msg_len );
1450 msg_ptr += msg_len;
1452 /* add to correct list in container */
1454 notify_msg_ctr_addmsg( &messages, &notify );
1456 /* free memory that might have been allocated by notify2_unpack_msg() */
1458 if ( notify.len != 0 )
1459 SAFE_FREE( notify.notify.data );
1462 /* process each group of messages */
1464 num_groups = notify_msg_ctr_numgroups( &messages );
1465 for ( i=0; i<num_groups; i++ )
1466 send_notify2_changes( &messages, i );
1469 /* cleanup */
1471 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1472 (uint32_t)msg_count ));
1474 notify_msg_ctr_destroy( &messages );
1476 return;
1479 /********************************************************************
1480 Send a message to ourself about new driver being installed
1481 so we can upgrade the information for each printer bound to this
1482 driver
1483 ********************************************************************/
1485 static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
1486 struct messaging_context *msg_ctx)
1488 int len = strlen(drivername);
1490 if (!len)
1491 return false;
1493 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1494 drivername));
1496 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
1497 MSG_PRINTER_DRVUPGRADE,
1498 (const uint8_t *)drivername, len+1);
1500 return true;
1503 void srv_spoolss_cleanup(void)
1505 struct printer_session_counter *session_counter;
1507 for (session_counter = counter_list;
1508 session_counter != NULL;
1509 session_counter = counter_list) {
1510 DLIST_REMOVE(counter_list, session_counter);
1511 TALLOC_FREE(session_counter);
1515 /**********************************************************************
1516 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1517 over all printers, upgrading ones as necessary
1518 **********************************************************************/
1520 void do_drv_upgrade_printer(struct messaging_context *msg,
1521 void *private_data,
1522 uint32_t msg_type,
1523 struct server_id server_id,
1524 DATA_BLOB *data)
1526 TALLOC_CTX *tmp_ctx;
1527 const struct auth_session_info *session_info = get_session_info_system();
1528 struct spoolss_PrinterInfo2 *pinfo2;
1529 WERROR result;
1530 const char *drivername;
1531 int snum;
1532 int n_services = lp_numservices();
1533 struct dcerpc_binding_handle *b = NULL;
1535 tmp_ctx = talloc_new(NULL);
1536 if (!tmp_ctx) return;
1538 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, data->length);
1539 if (!drivername) {
1540 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1541 goto done;
1544 DEBUG(10, ("do_drv_upgrade_printer: "
1545 "Got message for new driver [%s]\n", drivername));
1547 /* Iterate the printer list */
1549 for (snum = 0; snum < n_services; snum++) {
1550 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1551 continue;
1554 /* ignore [printers] share */
1555 if (strequal(lp_const_servicename(snum), "printers")) {
1556 continue;
1559 if (b == NULL) {
1560 result = winreg_printer_binding_handle(tmp_ctx,
1561 session_info,
1562 msg,
1563 &b);
1564 if (!W_ERROR_IS_OK(result)) {
1565 break;
1569 result = winreg_get_printer(tmp_ctx, b,
1570 lp_const_servicename(snum),
1571 &pinfo2);
1573 if (!W_ERROR_IS_OK(result)) {
1574 continue;
1577 if (!pinfo2->drivername) {
1578 continue;
1581 if (strcmp(drivername, pinfo2->drivername) != 0) {
1582 continue;
1585 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1587 /* all we care about currently is the change_id */
1588 result = winreg_printer_update_changeid(tmp_ctx, b,
1589 pinfo2->printername);
1591 if (!W_ERROR_IS_OK(result)) {
1592 DEBUG(3, ("do_drv_upgrade_printer: "
1593 "Failed to update changeid [%s]\n",
1594 win_errstr(result)));
1598 /* all done */
1599 done:
1600 talloc_free(tmp_ctx);
1603 /********************************************************************
1604 Update the cache for all printq's with a registered client
1605 connection
1606 ********************************************************************/
1608 void update_monitored_printq_cache(struct messaging_context *msg_ctx)
1610 struct printer_handle *printer = printers_list;
1611 int snum;
1613 /* loop through all printers and update the cache where
1614 a client is connected */
1615 while (printer) {
1616 if ((printer->printer_type == SPLHND_PRINTER) &&
1617 ((printer->notify.cli_chan != NULL) &&
1618 (printer->notify.cli_chan->active_connections > 0))) {
1619 snum = print_queue_snum(printer->sharename);
1620 print_queue_status(msg_ctx, snum, NULL, NULL);
1623 printer = printer->next;
1626 return;
1629 /****************************************************************
1630 _spoolss_OpenPrinter
1631 ****************************************************************/
1633 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1634 struct spoolss_OpenPrinter *r)
1636 struct spoolss_OpenPrinterEx e;
1637 struct spoolss_UserLevel1 level1;
1638 WERROR werr;
1640 ZERO_STRUCT(level1);
1642 e.in.printername = r->in.printername;
1643 e.in.datatype = r->in.datatype;
1644 e.in.devmode_ctr = r->in.devmode_ctr;
1645 e.in.access_mask = r->in.access_mask;
1646 e.in.userlevel_ctr.level = 1;
1647 e.in.userlevel_ctr.user_info.level1 = &level1;
1649 e.out.handle = r->out.handle;
1651 werr = _spoolss_OpenPrinterEx(p, &e);
1653 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1654 /* OpenPrinterEx returns this for a bad
1655 * printer name. We must return WERR_INVALID_PRINTER_NAME
1656 * instead.
1658 werr = WERR_INVALID_PRINTER_NAME;
1661 return werr;
1664 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1665 struct spoolss_DeviceMode *orig,
1666 struct spoolss_DeviceMode **dest)
1668 struct spoolss_DeviceMode *dm;
1670 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1671 if (!dm) {
1672 return WERR_NOMEM;
1675 /* copy all values, then duplicate strings and structs */
1676 *dm = *orig;
1678 dm->devicename = talloc_strdup(dm, orig->devicename);
1679 if (!dm->devicename) {
1680 return WERR_NOMEM;
1682 dm->formname = talloc_strdup(dm, orig->formname);
1683 if (!dm->formname) {
1684 return WERR_NOMEM;
1686 if (orig->driverextra_data.data) {
1687 dm->driverextra_data.data =
1688 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1689 orig->driverextra_data.length);
1690 if (!dm->driverextra_data.data) {
1691 return WERR_NOMEM;
1695 *dest = dm;
1696 return WERR_OK;
1699 /****************************************************************
1700 _spoolss_OpenPrinterEx
1701 ****************************************************************/
1703 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1704 struct spoolss_OpenPrinterEx *r)
1706 int snum;
1707 char *raddr;
1708 char *rhost;
1709 struct printer_handle *Printer=NULL;
1710 WERROR result;
1711 int rc;
1713 if (!r->in.printername) {
1714 return WERR_INVALID_PARAM;
1717 if (!*r->in.printername) {
1718 return WERR_INVALID_PARAM;
1721 if (r->in.userlevel_ctr.level > 3) {
1722 return WERR_INVALID_PARAM;
1724 if ((r->in.userlevel_ctr.level == 1 && !r->in.userlevel_ctr.user_info.level1) ||
1725 (r->in.userlevel_ctr.level == 2 && !r->in.userlevel_ctr.user_info.level2) ||
1726 (r->in.userlevel_ctr.level == 3 && !r->in.userlevel_ctr.user_info.level3)) {
1727 return WERR_INVALID_PARAM;
1730 /* some sanity check because you can open a printer or a print server */
1731 /* aka: \\server\printer or \\server */
1733 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1735 result = open_printer_hnd(p, r->out.handle, r->in.printername, 0);
1736 if (!W_ERROR_IS_OK(result)) {
1737 DEBUG(3,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1738 "for printer %s\n", r->in.printername));
1739 ZERO_STRUCTP(r->out.handle);
1740 return result;
1743 Printer = find_printer_index_by_hnd(p, r->out.handle);
1744 if ( !Printer ) {
1745 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1746 "handle we created for printer %s\n", r->in.printername));
1747 close_printer_handle(p, r->out.handle);
1748 ZERO_STRUCTP(r->out.handle);
1749 return WERR_INVALID_PARAM;
1753 * First case: the user is opening the print server:
1755 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1756 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1758 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1759 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1760 * or if the user is listed in the smb.conf printer admin parameter.
1762 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1763 * client view printer folder, but does not show the MSAPW.
1765 * Note: this test needs code to check access rights here too. Jeremy
1766 * could you look at this?
1768 * Second case: the user is opening a printer:
1769 * NT doesn't let us connect to a printer if the connecting user
1770 * doesn't have print permission.
1772 * Third case: user is opening a Port Monitor
1773 * access checks same as opening a handle to the print server.
1776 switch (Printer->printer_type )
1778 case SPLHND_SERVER:
1779 case SPLHND_PORTMON_TCP:
1780 case SPLHND_PORTMON_LOCAL:
1781 /* Printserver handles use global struct... */
1783 snum = -1;
1785 /* Map standard access rights to object specific access rights */
1787 se_map_standard(&r->in.access_mask,
1788 &printserver_std_mapping);
1790 /* Deny any object specific bits that don't apply to print
1791 servers (i.e printer and job specific bits) */
1793 r->in.access_mask &= SEC_MASK_SPECIFIC;
1795 if (r->in.access_mask &
1796 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1797 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1798 close_printer_handle(p, r->out.handle);
1799 ZERO_STRUCTP(r->out.handle);
1800 return WERR_ACCESS_DENIED;
1803 /* Allow admin access */
1805 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1807 if (!lp_ms_add_printer_wizard()) {
1808 close_printer_handle(p, r->out.handle);
1809 ZERO_STRUCTP(r->out.handle);
1810 return WERR_ACCESS_DENIED;
1813 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1814 and not a printer admin, then fail */
1816 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
1817 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
1818 !nt_token_check_sid(&global_sid_Builtin_Print_Operators,
1819 p->session_info->security_token)) {
1820 close_printer_handle(p, r->out.handle);
1821 ZERO_STRUCTP(r->out.handle);
1822 DEBUG(3,("access DENIED as user is not root, "
1823 "has no printoperator privilege, "
1824 "not a member of the printoperator builtin group and "
1825 "is not in printer admin list"));
1826 return WERR_ACCESS_DENIED;
1829 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1831 else
1833 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1836 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1837 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1839 /* We fall through to return WERR_OK */
1840 break;
1842 case SPLHND_PRINTER:
1843 /* NT doesn't let us connect to a printer if the connecting user
1844 doesn't have print permission. */
1846 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1847 close_printer_handle(p, r->out.handle);
1848 ZERO_STRUCTP(r->out.handle);
1849 return WERR_BADFID;
1852 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1853 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1856 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1858 /* map an empty access mask to the minimum access mask */
1859 if (r->in.access_mask == 0x0)
1860 r->in.access_mask = PRINTER_ACCESS_USE;
1863 * If we are not serving the printer driver for this printer,
1864 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1865 * will keep NT clients happy --jerry
1868 if (lp_use_client_driver(snum)
1869 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1871 r->in.access_mask = PRINTER_ACCESS_USE;
1874 /* check smb.conf parameters and the the sec_desc */
1875 raddr = tsocket_address_inet_addr_string(p->remote_address,
1876 p->mem_ctx);
1877 if (raddr == NULL) {
1878 return WERR_NOMEM;
1881 rc = get_remote_hostname(p->remote_address,
1882 &rhost,
1883 p->mem_ctx);
1884 if (rc < 0) {
1885 return WERR_NOMEM;
1887 if (strequal(rhost, "UNKNOWN")) {
1888 rhost = raddr;
1891 if (!allow_access(lp_hostsdeny(snum), lp_hostsallow(snum),
1892 rhost, raddr)) {
1893 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1894 ZERO_STRUCTP(r->out.handle);
1895 return WERR_ACCESS_DENIED;
1898 if (!user_ok_token(uidtoname(p->session_info->unix_token->uid), NULL,
1899 p->session_info->security_token, snum) ||
1900 !print_access_check(p->session_info,
1901 p->msg_ctx,
1902 snum,
1903 r->in.access_mask)) {
1904 DEBUG(3, ("access DENIED for printer open\n"));
1905 close_printer_handle(p, r->out.handle);
1906 ZERO_STRUCTP(r->out.handle);
1907 return WERR_ACCESS_DENIED;
1910 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1911 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1912 close_printer_handle(p, r->out.handle);
1913 ZERO_STRUCTP(r->out.handle);
1914 return WERR_ACCESS_DENIED;
1917 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1918 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1919 else
1920 r->in.access_mask = PRINTER_ACCESS_USE;
1922 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1923 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1925 winreg_create_printer_internal(p->mem_ctx,
1926 get_session_info_system(),
1927 p->msg_ctx,
1928 lp_const_servicename(snum));
1930 break;
1932 default:
1933 /* sanity check to prevent programmer error */
1934 ZERO_STRUCTP(r->out.handle);
1935 return WERR_BADFID;
1938 Printer->access_granted = r->in.access_mask;
1941 * If the client sent a devmode in the OpenPrinter() call, then
1942 * save it here in case we get a job submission on this handle
1945 if ((Printer->printer_type != SPLHND_SERVER)
1946 && (r->in.devmode_ctr.devmode != NULL)) {
1947 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1948 &Printer->devmode);
1951 return WERR_OK;
1954 /****************************************************************
1955 _spoolss_ClosePrinter
1956 ****************************************************************/
1958 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1959 struct spoolss_ClosePrinter *r)
1961 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1963 if (Printer && Printer->document_started) {
1964 struct spoolss_EndDocPrinter e;
1966 e.in.handle = r->in.handle;
1968 _spoolss_EndDocPrinter(p, &e);
1971 if (!close_printer_handle(p, r->in.handle))
1972 return WERR_BADFID;
1974 /* clear the returned printer handle. Observed behavior
1975 from Win2k server. Don't think this really matters.
1976 Previous code just copied the value of the closed
1977 handle. --jerry */
1979 ZERO_STRUCTP(r->out.handle);
1981 return WERR_OK;
1984 /****************************************************************
1985 _spoolss_DeletePrinter
1986 ****************************************************************/
1988 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1989 struct spoolss_DeletePrinter *r)
1991 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1992 WERROR result;
1993 int snum;
1995 if (Printer && Printer->document_started) {
1996 struct spoolss_EndDocPrinter e;
1998 e.in.handle = r->in.handle;
2000 _spoolss_EndDocPrinter(p, &e);
2003 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
2004 winreg_delete_printer_key_internal(p->mem_ctx,
2005 get_session_info_system(),
2006 p->msg_ctx,
2007 lp_const_servicename(snum),
2008 "");
2011 result = delete_printer_handle(p, r->in.handle);
2013 return result;
2016 /*******************************************************************
2017 * static function to lookup the version id corresponding to an
2018 * long architecture string
2019 ******************************************************************/
2021 static const struct print_architecture_table_node archi_table[]= {
2023 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
2024 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
2025 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
2026 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
2027 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
2028 {"Windows IA64", SPL_ARCH_IA64, 3 },
2029 {"Windows x64", SPL_ARCH_X64, 3 },
2030 {NULL, "", -1 }
2033 static const int drv_cversion[] = {SPOOLSS_DRIVER_VERSION_9X,
2034 SPOOLSS_DRIVER_VERSION_NT35,
2035 SPOOLSS_DRIVER_VERSION_NT4,
2036 SPOOLSS_DRIVER_VERSION_200X,
2037 -1};
2039 static int get_version_id(const char *arch)
2041 int i;
2043 for (i=0; archi_table[i].long_archi != NULL; i++)
2045 if (strcmp(arch, archi_table[i].long_archi) == 0)
2046 return (archi_table[i].version);
2049 return -1;
2052 /****************************************************************
2053 _spoolss_DeletePrinterDriver
2054 ****************************************************************/
2056 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
2057 struct spoolss_DeletePrinterDriver *r)
2060 struct spoolss_DriverInfo8 *info = NULL;
2061 int version;
2062 WERROR status;
2063 struct dcerpc_binding_handle *b;
2064 TALLOC_CTX *tmp_ctx = NULL;
2065 int i;
2066 bool found;
2068 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2069 and not a printer admin, then fail */
2071 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
2072 !security_token_has_privilege(p->session_info->security_token,
2073 SEC_PRIV_PRINT_OPERATOR)) {
2074 return WERR_ACCESS_DENIED;
2077 /* check that we have a valid driver name first */
2079 if ((version = get_version_id(r->in.architecture)) == -1) {
2080 return WERR_INVALID_ENVIRONMENT;
2083 tmp_ctx = talloc_new(p->mem_ctx);
2084 if (!tmp_ctx) {
2085 return WERR_NOMEM;
2088 status = winreg_printer_binding_handle(tmp_ctx,
2089 get_session_info_system(),
2090 p->msg_ctx,
2091 &b);
2092 if (!W_ERROR_IS_OK(status)) {
2093 goto done;
2096 for (found = false, i = 0; drv_cversion[i] >= 0; i++) {
2097 status = winreg_get_driver(tmp_ctx, b,
2098 r->in.architecture, r->in.driver,
2099 drv_cversion[i], &info);
2100 if (!W_ERROR_IS_OK(status)) {
2101 DEBUG(5, ("skipping del of driver with version %d\n",
2102 drv_cversion[i]));
2103 continue;
2105 found = true;
2107 if (printer_driver_in_use(tmp_ctx, b, info)) {
2108 status = WERR_PRINTER_DRIVER_IN_USE;
2109 goto done;
2112 status = winreg_del_driver(tmp_ctx, b, info, drv_cversion[i]);
2113 if (!W_ERROR_IS_OK(status)) {
2114 DEBUG(0, ("failed del of driver with version %d\n",
2115 drv_cversion[i]));
2116 goto done;
2119 if (found == false) {
2120 DEBUG(0, ("driver %s not found for deletion\n", r->in.driver));
2121 status = WERR_UNKNOWN_PRINTER_DRIVER;
2122 } else {
2123 status = WERR_OK;
2126 done:
2127 talloc_free(tmp_ctx);
2129 return status;
2132 static WERROR spoolss_dpd_version(TALLOC_CTX *mem_ctx,
2133 struct pipes_struct *p,
2134 struct spoolss_DeletePrinterDriverEx *r,
2135 struct dcerpc_binding_handle *b,
2136 struct spoolss_DriverInfo8 *info)
2138 WERROR status;
2139 bool delete_files;
2141 if (printer_driver_in_use(mem_ctx, b, info)) {
2142 status = WERR_PRINTER_DRIVER_IN_USE;
2143 goto done;
2147 * we have a couple of cases to consider.
2148 * (1) Are any files in use? If so and DPD_DELETE_ALL_FILES is set,
2149 * then the delete should fail if **any** files overlap with
2150 * other drivers
2151 * (2) If DPD_DELETE_UNUSED_FILES is set, then delete all
2152 * non-overlapping files
2153 * (3) If neither DPD_DELETE_ALL_FILES nor DPD_DELETE_UNUSED_FILES
2154 * are set, then do not delete any files
2155 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2158 delete_files = r->in.delete_flags
2159 & (DPD_DELETE_ALL_FILES | DPD_DELETE_UNUSED_FILES);
2162 if (delete_files) {
2163 bool in_use = printer_driver_files_in_use(mem_ctx, b, info);
2164 if (in_use && (r->in.delete_flags & DPD_DELETE_ALL_FILES)) {
2165 status = WERR_PRINTER_DRIVER_IN_USE;
2166 goto done;
2169 * printer_driver_files_in_use() has trimmed overlapping files
2170 * from info so they are not removed on DPD_DELETE_UNUSED_FILES
2175 status = winreg_del_driver(mem_ctx, b, info, info->version);
2176 if (!W_ERROR_IS_OK(status)) {
2177 goto done;
2181 * now delete any associated files if delete_files is
2182 * true. Even if this part failes, we return succes
2183 * because the driver doesn not exist any more
2185 if (delete_files) {
2186 delete_driver_files(p->session_info, info);
2189 done:
2190 return status;
2193 /****************************************************************
2194 _spoolss_DeletePrinterDriverEx
2195 ****************************************************************/
2197 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
2198 struct spoolss_DeletePrinterDriverEx *r)
2200 struct spoolss_DriverInfo8 *info = NULL;
2201 WERROR status;
2202 struct dcerpc_binding_handle *b;
2203 TALLOC_CTX *tmp_ctx = NULL;
2204 int i;
2205 bool found;
2207 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2208 and not a printer admin, then fail */
2210 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
2211 !security_token_has_privilege(p->session_info->security_token,
2212 SEC_PRIV_PRINT_OPERATOR)) {
2213 return WERR_ACCESS_DENIED;
2216 /* check that we have a valid driver name first */
2217 if (get_version_id(r->in.architecture) == -1) {
2218 /* this is what NT returns */
2219 return WERR_INVALID_ENVIRONMENT;
2222 tmp_ctx = talloc_new(p->mem_ctx);
2223 if (!tmp_ctx) {
2224 return WERR_NOMEM;
2227 status = winreg_printer_binding_handle(tmp_ctx,
2228 get_session_info_system(),
2229 p->msg_ctx,
2230 &b);
2231 if (!W_ERROR_IS_OK(status)) {
2232 goto done;
2235 for (found = false, i = 0; drv_cversion[i] >= 0; i++) {
2236 if ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2237 && (drv_cversion[i] != r->in.version)) {
2238 continue;
2241 /* check if a driver with this version exists before delete */
2242 status = winreg_get_driver(tmp_ctx, b,
2243 r->in.architecture, r->in.driver,
2244 drv_cversion[i], &info);
2245 if (!W_ERROR_IS_OK(status)) {
2246 DEBUG(5, ("skipping del of driver with version %d\n",
2247 drv_cversion[i]));
2248 continue;
2250 found = true;
2252 status = spoolss_dpd_version(tmp_ctx, p, r, b, info);
2253 if (!W_ERROR_IS_OK(status)) {
2254 DEBUG(0, ("failed to delete driver with version %d\n",
2255 drv_cversion[i]));
2256 goto done;
2259 if (found == false) {
2260 DEBUG(0, ("driver %s not found for deletion\n", r->in.driver));
2261 status = WERR_UNKNOWN_PRINTER_DRIVER;
2262 } else {
2263 status = WERR_OK;
2266 done:
2267 talloc_free(tmp_ctx);
2268 return status;
2272 /********************************************************************
2273 GetPrinterData on a printer server Handle.
2274 ********************************************************************/
2276 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2277 const char *value,
2278 enum winreg_Type *type,
2279 union spoolss_PrinterData *data)
2281 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2283 if (!strcasecmp_m(value, "W3SvcInstalled")) {
2284 *type = REG_DWORD;
2285 SIVAL(&data->value, 0, 0x00);
2286 return WERR_OK;
2289 if (!strcasecmp_m(value, "BeepEnabled")) {
2290 *type = REG_DWORD;
2291 SIVAL(&data->value, 0, 0x00);
2292 return WERR_OK;
2295 if (!strcasecmp_m(value, "EventLog")) {
2296 *type = REG_DWORD;
2297 /* formally was 0x1b */
2298 SIVAL(&data->value, 0, 0x00);
2299 return WERR_OK;
2302 if (!strcasecmp_m(value, "NetPopup")) {
2303 *type = REG_DWORD;
2304 SIVAL(&data->value, 0, 0x00);
2305 return WERR_OK;
2308 if (!strcasecmp_m(value, "MajorVersion")) {
2309 *type = REG_DWORD;
2311 /* Windows NT 4.0 seems to not allow uploading of drivers
2312 to a server that reports 0x3 as the MajorVersion.
2313 need to investigate more how Win2k gets around this .
2314 -- jerry */
2316 if (RA_WINNT == get_remote_arch()) {
2317 SIVAL(&data->value, 0, 0x02);
2318 } else {
2319 SIVAL(&data->value, 0, 0x03);
2322 return WERR_OK;
2325 if (!strcasecmp_m(value, "MinorVersion")) {
2326 *type = REG_DWORD;
2327 SIVAL(&data->value, 0, 0x00);
2328 return WERR_OK;
2331 /* REG_BINARY
2332 * uint32_t size = 0x114
2333 * uint32_t major = 5
2334 * uint32_t minor = [0|1]
2335 * uint32_t build = [2195|2600]
2336 * extra unicode string = e.g. "Service Pack 3"
2338 if (!strcasecmp_m(value, "OSVersion")) {
2339 DATA_BLOB blob;
2340 enum ndr_err_code ndr_err;
2341 struct spoolss_OSVersion os;
2343 os.major = lp_parm_int(GLOBAL_SECTION_SNUM,
2344 "spoolss", "os_major", 5);
2345 /* Windows 2000 == 5.0 */
2346 os.minor = lp_parm_int(GLOBAL_SECTION_SNUM,
2347 "spoolss", "os_minor", 0);
2348 os.build = lp_parm_int(GLOBAL_SECTION_SNUM,
2349 "spoolss", "os_build", 2195);
2350 os.extra_string = ""; /* leave extra string empty */
2352 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2353 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2354 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2355 return WERR_GENERAL_FAILURE;
2358 if (DEBUGLEVEL >= 10) {
2359 NDR_PRINT_DEBUG(spoolss_OSVersion, &os);
2362 *type = REG_BINARY;
2363 data->binary = blob;
2365 return WERR_OK;
2369 if (!strcasecmp_m(value, "DefaultSpoolDirectory")) {
2370 *type = REG_SZ;
2372 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2373 W_ERROR_HAVE_NO_MEMORY(data->string);
2375 return WERR_OK;
2378 if (!strcasecmp_m(value, "Architecture")) {
2379 *type = REG_SZ;
2380 data->string = talloc_strdup(mem_ctx,
2381 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2382 W_ERROR_HAVE_NO_MEMORY(data->string);
2384 return WERR_OK;
2387 if (!strcasecmp_m(value, "DsPresent")) {
2388 *type = REG_DWORD;
2390 /* only show the publish check box if we are a
2391 member of a AD domain */
2393 if (lp_security() == SEC_ADS) {
2394 SIVAL(&data->value, 0, 0x01);
2395 } else {
2396 SIVAL(&data->value, 0, 0x00);
2398 return WERR_OK;
2401 if (!strcasecmp_m(value, "DNSMachineName")) {
2402 const char *hostname = get_mydnsfullname();
2404 if (!hostname) {
2405 return WERR_BADFILE;
2408 *type = REG_SZ;
2409 data->string = talloc_strdup(mem_ctx, hostname);
2410 W_ERROR_HAVE_NO_MEMORY(data->string);
2412 return WERR_OK;
2415 *type = REG_NONE;
2417 return WERR_INVALID_PARAM;
2420 /****************************************************************
2421 _spoolss_GetPrinterData
2422 ****************************************************************/
2424 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2425 struct spoolss_GetPrinterData *r)
2427 struct spoolss_GetPrinterDataEx r2;
2429 r2.in.handle = r->in.handle;
2430 r2.in.key_name = "PrinterDriverData";
2431 r2.in.value_name = r->in.value_name;
2432 r2.in.offered = r->in.offered;
2433 r2.out.type = r->out.type;
2434 r2.out.data = r->out.data;
2435 r2.out.needed = r->out.needed;
2437 return _spoolss_GetPrinterDataEx(p, &r2);
2440 /*********************************************************
2441 Connect to the client machine.
2442 **********************************************************/
2444 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, struct cli_state **pp_cli,
2445 struct sockaddr_storage *client_ss, const char *remote_machine)
2447 NTSTATUS ret;
2448 struct sockaddr_storage rm_addr;
2449 char addr[INET6_ADDRSTRLEN];
2451 if ( is_zero_addr(client_ss) ) {
2452 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2453 remote_machine));
2454 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2455 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2456 return false;
2458 print_sockaddr(addr, sizeof(addr), &rm_addr);
2459 } else {
2460 rm_addr = *client_ss;
2461 print_sockaddr(addr, sizeof(addr), &rm_addr);
2462 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2463 addr));
2466 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2467 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2468 addr));
2469 return false;
2472 /* setup the connection */
2473 ret = cli_full_connection( pp_cli, lp_netbios_name(), remote_machine,
2474 &rm_addr, 0, "IPC$", "IPC",
2475 "", /* username */
2476 "", /* domain */
2477 "", /* password */
2478 0, lp_client_signing());
2480 if ( !NT_STATUS_IS_OK( ret ) ) {
2481 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2482 remote_machine ));
2483 return false;
2486 if ( smbXcli_conn_protocol((*pp_cli)->conn) != PROTOCOL_NT1 ) {
2487 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2488 cli_shutdown(*pp_cli);
2489 return false;
2493 * Ok - we have an anonymous connection to the IPC$ share.
2494 * Now start the NT Domain stuff :-).
2497 ret = cli_rpc_pipe_open_noauth(*pp_cli, &ndr_table_spoolss, pp_pipe);
2498 if (!NT_STATUS_IS_OK(ret)) {
2499 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2500 remote_machine, nt_errstr(ret)));
2501 cli_shutdown(*pp_cli);
2502 return false;
2505 return true;
2508 /***************************************************************************
2509 Connect to the client.
2510 ****************************************************************************/
2512 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2513 uint32_t localprinter,
2514 enum winreg_Type type,
2515 struct policy_handle *handle,
2516 struct notify_back_channel **_chan,
2517 struct sockaddr_storage *client_ss,
2518 struct messaging_context *msg_ctx)
2520 WERROR result;
2521 NTSTATUS status;
2522 struct notify_back_channel *chan;
2524 for (chan = back_channels; chan; chan = chan->next) {
2525 if (memcmp(&chan->client_address, client_ss,
2526 sizeof(struct sockaddr_storage)) == 0) {
2527 break;
2532 * If it's the first connection, contact the client
2533 * and connect to the IPC$ share anonymously
2535 if (!chan) {
2536 fstring unix_printer;
2538 /* the +2 is to strip the leading 2 backslashs */
2539 fstrcpy(unix_printer, printer + 2);
2541 chan = talloc_zero(NULL, struct notify_back_channel);
2542 if (!chan) {
2543 return false;
2545 chan->client_address = *client_ss;
2547 if (!spoolss_connect_to_client(&chan->cli_pipe, &chan->cli, client_ss, unix_printer)) {
2548 TALLOC_FREE(chan);
2549 return false;
2552 DLIST_ADD(back_channels, chan);
2554 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2555 receive_notify2_message_list);
2558 if (chan->cli_pipe == NULL ||
2559 chan->cli_pipe->binding_handle == NULL) {
2560 DEBUG(0, ("srv_spoolss_replyopenprinter: error - "
2561 "NULL %s for printer %s\n",
2562 chan->cli_pipe == NULL ?
2563 "chan->cli_pipe" : "chan->cli_pipe->binding_handle",
2564 printer));
2565 return false;
2569 * Tell the specific printing tdb we want messages for this printer
2570 * by registering our PID.
2573 if (!print_notify_register_pid(snum)) {
2574 DEBUG(0, ("Failed to register our pid for printer %s\n",
2575 printer));
2578 status = dcerpc_spoolss_ReplyOpenPrinter(chan->cli_pipe->binding_handle,
2579 talloc_tos(),
2580 printer,
2581 localprinter,
2582 type,
2584 NULL,
2585 handle,
2586 &result);
2587 if (!NT_STATUS_IS_OK(status)) {
2588 DEBUG(5, ("dcerpc_spoolss_ReplyOpenPrinter returned [%s]\n", nt_errstr(status)));
2589 result = ntstatus_to_werror(status);
2590 } else if (!W_ERROR_IS_OK(result)) {
2591 DEBUG(5, ("ReplyOpenPrinter returned [%s]\n", win_errstr(result)));
2594 chan->active_connections++;
2595 *_chan = chan;
2597 return (W_ERROR_IS_OK(result));
2600 /****************************************************************
2601 ****************************************************************/
2603 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2604 const struct spoolss_NotifyOption *r)
2606 struct spoolss_NotifyOption *option;
2607 uint32_t i,k;
2609 if (!r) {
2610 return NULL;
2613 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2614 if (!option) {
2615 return NULL;
2618 *option = *r;
2620 if (!option->count) {
2621 return option;
2624 option->types = talloc_zero_array(option,
2625 struct spoolss_NotifyOptionType, option->count);
2626 if (!option->types) {
2627 talloc_free(option);
2628 return NULL;
2631 for (i=0; i < option->count; i++) {
2632 option->types[i] = r->types[i];
2634 if (option->types[i].count) {
2635 option->types[i].fields = talloc_zero_array(option,
2636 union spoolss_Field, option->types[i].count);
2637 if (!option->types[i].fields) {
2638 talloc_free(option);
2639 return NULL;
2641 for (k=0; k<option->types[i].count; k++) {
2642 option->types[i].fields[k] =
2643 r->types[i].fields[k];
2648 return option;
2651 /****************************************************************
2652 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2654 * before replying OK: status=0 a rpc call is made to the workstation
2655 * asking ReplyOpenPrinter
2657 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2658 * called from api_spoolss_rffpcnex
2659 ****************************************************************/
2661 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2662 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2664 int snum = -1;
2665 struct spoolss_NotifyOption *option = r->in.notify_options;
2666 struct sockaddr_storage client_ss;
2667 ssize_t client_len;
2669 /* store the notify value in the printer struct */
2671 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2673 if (!Printer) {
2674 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2675 "Invalid handle (%s:%u:%u).\n",
2676 OUR_HANDLE(r->in.handle)));
2677 return WERR_BADFID;
2680 Printer->notify.flags = r->in.flags;
2681 Printer->notify.options = r->in.options;
2682 Printer->notify.printerlocal = r->in.printer_local;
2683 Printer->notify.msg_ctx = p->msg_ctx;
2685 TALLOC_FREE(Printer->notify.option);
2686 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2688 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2690 /* Connect to the client machine and send a ReplyOpenPrinter */
2692 if ( Printer->printer_type == SPLHND_SERVER)
2693 snum = -1;
2694 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2695 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2696 return WERR_BADFID;
2698 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2699 "remote_address is %s\n",
2700 tsocket_address_string(p->remote_address, p->mem_ctx)));
2702 if (!lp_print_notify_backchannel(snum)) {
2703 DEBUG(10, ("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2704 "backchannel disabled\n"));
2705 return WERR_SERVER_UNAVAILABLE;
2708 client_len = tsocket_address_bsd_sockaddr(p->remote_address,
2709 (struct sockaddr *) &client_ss,
2710 sizeof(struct sockaddr_storage));
2711 if (client_len < 0) {
2712 return WERR_NOMEM;
2715 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2716 Printer->notify.printerlocal, REG_SZ,
2717 &Printer->notify.cli_hnd,
2718 &Printer->notify.cli_chan,
2719 &client_ss, p->msg_ctx)) {
2720 return WERR_SERVER_UNAVAILABLE;
2723 return WERR_OK;
2726 /*******************************************************************
2727 * fill a notify_info_data with the servername
2728 ********************************************************************/
2730 static void spoolss_notify_server_name(struct messaging_context *msg_ctx,
2731 int snum,
2732 struct spoolss_Notify *data,
2733 print_queue_struct *queue,
2734 struct spoolss_PrinterInfo2 *pinfo2,
2735 TALLOC_CTX *mem_ctx)
2737 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2740 /*******************************************************************
2741 * fill a notify_info_data with the printername (not including the servername).
2742 ********************************************************************/
2744 static void spoolss_notify_printer_name(struct messaging_context *msg_ctx,
2745 int snum,
2746 struct spoolss_Notify *data,
2747 print_queue_struct *queue,
2748 struct spoolss_PrinterInfo2 *pinfo2,
2749 TALLOC_CTX *mem_ctx)
2751 /* the notify name should not contain the \\server\ part */
2752 const char *p = strrchr(pinfo2->printername, '\\');
2754 if (!p) {
2755 p = pinfo2->printername;
2756 } else {
2757 p++;
2760 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2763 /*******************************************************************
2764 * fill a notify_info_data with the servicename
2765 ********************************************************************/
2767 static void spoolss_notify_share_name(struct messaging_context *msg_ctx,
2768 int snum,
2769 struct spoolss_Notify *data,
2770 print_queue_struct *queue,
2771 struct spoolss_PrinterInfo2 *pinfo2,
2772 TALLOC_CTX *mem_ctx)
2774 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(talloc_tos(), snum));
2777 /*******************************************************************
2778 * fill a notify_info_data with the port name
2779 ********************************************************************/
2781 static void spoolss_notify_port_name(struct messaging_context *msg_ctx,
2782 int snum,
2783 struct spoolss_Notify *data,
2784 print_queue_struct *queue,
2785 struct spoolss_PrinterInfo2 *pinfo2,
2786 TALLOC_CTX *mem_ctx)
2788 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2791 /*******************************************************************
2792 * fill a notify_info_data with the printername
2793 * but it doesn't exist, have to see what to do
2794 ********************************************************************/
2796 static void spoolss_notify_driver_name(struct messaging_context *msg_ctx,
2797 int snum,
2798 struct spoolss_Notify *data,
2799 print_queue_struct *queue,
2800 struct spoolss_PrinterInfo2 *pinfo2,
2801 TALLOC_CTX *mem_ctx)
2803 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2806 /*******************************************************************
2807 * fill a notify_info_data with the comment
2808 ********************************************************************/
2810 static void spoolss_notify_comment(struct messaging_context *msg_ctx,
2811 int snum,
2812 struct spoolss_Notify *data,
2813 print_queue_struct *queue,
2814 struct spoolss_PrinterInfo2 *pinfo2,
2815 TALLOC_CTX *mem_ctx)
2817 const char *p;
2819 if (*pinfo2->comment == '\0') {
2820 p = lp_comment(talloc_tos(), snum);
2821 } else {
2822 p = pinfo2->comment;
2825 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2828 /*******************************************************************
2829 * fill a notify_info_data with the comment
2830 * location = "Room 1, floor 2, building 3"
2831 ********************************************************************/
2833 static void spoolss_notify_location(struct messaging_context *msg_ctx,
2834 int snum,
2835 struct spoolss_Notify *data,
2836 print_queue_struct *queue,
2837 struct spoolss_PrinterInfo2 *pinfo2,
2838 TALLOC_CTX *mem_ctx)
2840 const char *loc = pinfo2->location;
2841 NTSTATUS status;
2843 status = printer_list_get_printer(mem_ctx,
2844 pinfo2->sharename,
2845 NULL,
2846 &loc,
2847 NULL);
2848 if (NT_STATUS_IS_OK(status)) {
2849 if (loc == NULL) {
2850 loc = pinfo2->location;
2854 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, loc);
2857 /*******************************************************************
2858 * fill a notify_info_data with the device mode
2859 * jfm:xxxx don't to it for know but that's a real problem !!!
2860 ********************************************************************/
2862 static void spoolss_notify_devmode(struct messaging_context *msg_ctx,
2863 int snum,
2864 struct spoolss_Notify *data,
2865 print_queue_struct *queue,
2866 struct spoolss_PrinterInfo2 *pinfo2,
2867 TALLOC_CTX *mem_ctx)
2869 /* for a dummy implementation we have to zero the fields */
2870 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2873 /*******************************************************************
2874 * fill a notify_info_data with the separator file name
2875 ********************************************************************/
2877 static void spoolss_notify_sepfile(struct messaging_context *msg_ctx,
2878 int snum,
2879 struct spoolss_Notify *data,
2880 print_queue_struct *queue,
2881 struct spoolss_PrinterInfo2 *pinfo2,
2882 TALLOC_CTX *mem_ctx)
2884 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2887 /*******************************************************************
2888 * fill a notify_info_data with the print processor
2889 * jfm:xxxx return always winprint to indicate we don't do anything to it
2890 ********************************************************************/
2892 static void spoolss_notify_print_processor(struct messaging_context *msg_ctx,
2893 int snum,
2894 struct spoolss_Notify *data,
2895 print_queue_struct *queue,
2896 struct spoolss_PrinterInfo2 *pinfo2,
2897 TALLOC_CTX *mem_ctx)
2899 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2902 /*******************************************************************
2903 * fill a notify_info_data with the print processor options
2904 * jfm:xxxx send an empty string
2905 ********************************************************************/
2907 static void spoolss_notify_parameters(struct messaging_context *msg_ctx,
2908 int snum,
2909 struct spoolss_Notify *data,
2910 print_queue_struct *queue,
2911 struct spoolss_PrinterInfo2 *pinfo2,
2912 TALLOC_CTX *mem_ctx)
2914 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2917 /*******************************************************************
2918 * fill a notify_info_data with the data type
2919 * jfm:xxxx always send RAW as data type
2920 ********************************************************************/
2922 static void spoolss_notify_datatype(struct messaging_context *msg_ctx,
2923 int snum,
2924 struct spoolss_Notify *data,
2925 print_queue_struct *queue,
2926 struct spoolss_PrinterInfo2 *pinfo2,
2927 TALLOC_CTX *mem_ctx)
2929 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2932 /*******************************************************************
2933 * fill a notify_info_data with the security descriptor
2934 * jfm:xxxx send an null pointer to say no security desc
2935 * have to implement security before !
2936 ********************************************************************/
2938 static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
2939 int snum,
2940 struct spoolss_Notify *data,
2941 print_queue_struct *queue,
2942 struct spoolss_PrinterInfo2 *pinfo2,
2943 TALLOC_CTX *mem_ctx)
2945 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2948 /*******************************************************************
2949 * fill a notify_info_data with the attributes
2950 * jfm:xxxx a samba printer is always shared
2951 ********************************************************************/
2953 static void spoolss_notify_attributes(struct messaging_context *msg_ctx,
2954 int snum,
2955 struct spoolss_Notify *data,
2956 print_queue_struct *queue,
2957 struct spoolss_PrinterInfo2 *pinfo2,
2958 TALLOC_CTX *mem_ctx)
2960 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2963 /*******************************************************************
2964 * fill a notify_info_data with the priority
2965 ********************************************************************/
2967 static void spoolss_notify_priority(struct messaging_context *msg_ctx,
2968 int snum,
2969 struct spoolss_Notify *data,
2970 print_queue_struct *queue,
2971 struct spoolss_PrinterInfo2 *pinfo2,
2972 TALLOC_CTX *mem_ctx)
2974 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2977 /*******************************************************************
2978 * fill a notify_info_data with the default priority
2979 ********************************************************************/
2981 static void spoolss_notify_default_priority(struct messaging_context *msg_ctx,
2982 int snum,
2983 struct spoolss_Notify *data,
2984 print_queue_struct *queue,
2985 struct spoolss_PrinterInfo2 *pinfo2,
2986 TALLOC_CTX *mem_ctx)
2988 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
2991 /*******************************************************************
2992 * fill a notify_info_data with the start time
2993 ********************************************************************/
2995 static void spoolss_notify_start_time(struct messaging_context *msg_ctx,
2996 int snum,
2997 struct spoolss_Notify *data,
2998 print_queue_struct *queue,
2999 struct spoolss_PrinterInfo2 *pinfo2,
3000 TALLOC_CTX *mem_ctx)
3002 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
3005 /*******************************************************************
3006 * fill a notify_info_data with the until time
3007 ********************************************************************/
3009 static void spoolss_notify_until_time(struct messaging_context *msg_ctx,
3010 int snum,
3011 struct spoolss_Notify *data,
3012 print_queue_struct *queue,
3013 struct spoolss_PrinterInfo2 *pinfo2,
3014 TALLOC_CTX *mem_ctx)
3016 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
3019 /*******************************************************************
3020 * fill a notify_info_data with the status
3021 ********************************************************************/
3023 static void spoolss_notify_status(struct messaging_context *msg_ctx,
3024 int snum,
3025 struct spoolss_Notify *data,
3026 print_queue_struct *queue,
3027 struct spoolss_PrinterInfo2 *pinfo2,
3028 TALLOC_CTX *mem_ctx)
3030 print_status_struct status;
3032 print_queue_length(msg_ctx, snum, &status);
3033 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3036 /*******************************************************************
3037 * fill a notify_info_data with the number of jobs queued
3038 ********************************************************************/
3040 static void spoolss_notify_cjobs(struct messaging_context *msg_ctx,
3041 int snum,
3042 struct spoolss_Notify *data,
3043 print_queue_struct *queue,
3044 struct spoolss_PrinterInfo2 *pinfo2,
3045 TALLOC_CTX *mem_ctx)
3047 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3048 data, print_queue_length(msg_ctx, snum, NULL));
3051 /*******************************************************************
3052 * fill a notify_info_data with the average ppm
3053 ********************************************************************/
3055 static void spoolss_notify_average_ppm(struct messaging_context *msg_ctx,
3056 int snum,
3057 struct spoolss_Notify *data,
3058 print_queue_struct *queue,
3059 struct spoolss_PrinterInfo2 *pinfo2,
3060 TALLOC_CTX *mem_ctx)
3062 /* always respond 8 pages per minutes */
3063 /* a little hard ! */
3064 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
3067 /*******************************************************************
3068 * fill a notify_info_data with username
3069 ********************************************************************/
3071 static void spoolss_notify_username(struct messaging_context *msg_ctx,
3072 int snum,
3073 struct spoolss_Notify *data,
3074 print_queue_struct *queue,
3075 struct spoolss_PrinterInfo2 *pinfo2,
3076 TALLOC_CTX *mem_ctx)
3078 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3081 /*******************************************************************
3082 * fill a notify_info_data with job status
3083 ********************************************************************/
3085 static void spoolss_notify_job_status(struct messaging_context *msg_ctx,
3086 int snum,
3087 struct spoolss_Notify *data,
3088 print_queue_struct *queue,
3089 struct spoolss_PrinterInfo2 *pinfo2,
3090 TALLOC_CTX *mem_ctx)
3092 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3095 /*******************************************************************
3096 * fill a notify_info_data with job name
3097 ********************************************************************/
3099 static void spoolss_notify_job_name(struct messaging_context *msg_ctx,
3100 int snum,
3101 struct spoolss_Notify *data,
3102 print_queue_struct *queue,
3103 struct spoolss_PrinterInfo2 *pinfo2,
3104 TALLOC_CTX *mem_ctx)
3106 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3109 /*******************************************************************
3110 * fill a notify_info_data with job status
3111 ********************************************************************/
3113 static void spoolss_notify_job_status_string(struct messaging_context *msg_ctx,
3114 int snum,
3115 struct spoolss_Notify *data,
3116 print_queue_struct *queue,
3117 struct spoolss_PrinterInfo2 *pinfo2,
3118 TALLOC_CTX *mem_ctx)
3121 * Now we're returning job status codes we just return a "" here. JRA.
3124 const char *p = "";
3126 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3127 p = "unknown";
3129 switch (queue->status) {
3130 case LPQ_QUEUED:
3131 p = "Queued";
3132 break;
3133 case LPQ_PAUSED:
3134 p = ""; /* NT provides the paused string */
3135 break;
3136 case LPQ_SPOOLING:
3137 p = "Spooling";
3138 break;
3139 case LPQ_PRINTING:
3140 p = "Printing";
3141 break;
3143 #endif /* NO LONGER NEEDED. */
3145 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3148 /*******************************************************************
3149 * fill a notify_info_data with job time
3150 ********************************************************************/
3152 static void spoolss_notify_job_time(struct messaging_context *msg_ctx,
3153 int snum,
3154 struct spoolss_Notify *data,
3155 print_queue_struct *queue,
3156 struct spoolss_PrinterInfo2 *pinfo2,
3157 TALLOC_CTX *mem_ctx)
3159 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3162 /*******************************************************************
3163 * fill a notify_info_data with job size
3164 ********************************************************************/
3166 static void spoolss_notify_job_size(struct messaging_context *msg_ctx,
3167 int snum,
3168 struct spoolss_Notify *data,
3169 print_queue_struct *queue,
3170 struct spoolss_PrinterInfo2 *pinfo2,
3171 TALLOC_CTX *mem_ctx)
3173 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3176 /*******************************************************************
3177 * fill a notify_info_data with page info
3178 ********************************************************************/
3179 static void spoolss_notify_total_pages(struct messaging_context *msg_ctx,
3180 int snum,
3181 struct spoolss_Notify *data,
3182 print_queue_struct *queue,
3183 struct spoolss_PrinterInfo2 *pinfo2,
3184 TALLOC_CTX *mem_ctx)
3186 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3189 /*******************************************************************
3190 * fill a notify_info_data with pages printed info.
3191 ********************************************************************/
3192 static void spoolss_notify_pages_printed(struct messaging_context *msg_ctx,
3193 int snum,
3194 struct spoolss_Notify *data,
3195 print_queue_struct *queue,
3196 struct spoolss_PrinterInfo2 *pinfo2,
3197 TALLOC_CTX *mem_ctx)
3199 /* Add code when back-end tracks this */
3200 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3203 /*******************************************************************
3204 Fill a notify_info_data with job position.
3205 ********************************************************************/
3207 static void spoolss_notify_job_position(struct messaging_context *msg_ctx,
3208 int snum,
3209 struct spoolss_Notify *data,
3210 print_queue_struct *queue,
3211 struct spoolss_PrinterInfo2 *pinfo2,
3212 TALLOC_CTX *mem_ctx)
3214 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->sysjob);
3217 /*******************************************************************
3218 Fill a notify_info_data with submitted time.
3219 ********************************************************************/
3221 static void spoolss_notify_submitted_time(struct messaging_context *msg_ctx,
3222 int snum,
3223 struct spoolss_Notify *data,
3224 print_queue_struct *queue,
3225 struct spoolss_PrinterInfo2 *pinfo2,
3226 TALLOC_CTX *mem_ctx)
3228 data->data.string.string = NULL;
3229 data->data.string.size = 0;
3231 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3232 &data->data.string.string,
3233 &data->data.string.size);
3237 struct s_notify_info_data_table
3239 enum spoolss_NotifyType type;
3240 uint16_t field;
3241 const char *name;
3242 enum spoolss_NotifyTable variable_type;
3243 void (*fn) (struct messaging_context *msg_ctx,
3244 int snum, struct spoolss_Notify *data,
3245 print_queue_struct *queue,
3246 struct spoolss_PrinterInfo2 *pinfo2,
3247 TALLOC_CTX *mem_ctx);
3250 /* A table describing the various print notification constants and
3251 whether the notification data is a pointer to a variable sized
3252 buffer, a one value uint32_t or a two value uint32_t. */
3254 static const struct s_notify_info_data_table notify_info_data_table[] =
3256 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3257 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3258 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3259 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3260 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3261 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3262 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3263 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3264 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3265 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3266 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3267 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3268 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3269 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3270 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3271 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3272 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3273 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3274 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3275 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3276 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3277 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3278 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3279 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3280 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3281 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3282 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3283 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3284 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3285 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3286 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3287 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3288 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3289 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3290 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3291 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3292 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3293 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3294 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3295 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3296 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3297 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3298 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3299 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3300 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3301 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3302 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3303 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3304 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3307 /*******************************************************************
3308 Return the variable_type of info_data structure.
3309 ********************************************************************/
3311 static enum spoolss_NotifyTable variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3312 uint16_t field)
3314 int i=0;
3316 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3317 if ( (notify_info_data_table[i].type == type) &&
3318 (notify_info_data_table[i].field == field) ) {
3319 return notify_info_data_table[i].variable_type;
3323 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3325 return (enum spoolss_NotifyTable) 0;
3328 /****************************************************************************
3329 ****************************************************************************/
3331 static bool search_notify(enum spoolss_NotifyType type,
3332 uint16_t field,
3333 int *value)
3335 int i;
3337 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3338 if (notify_info_data_table[i].type == type &&
3339 notify_info_data_table[i].field == field &&
3340 notify_info_data_table[i].fn != NULL) {
3341 *value = i;
3342 return true;
3346 return false;
3349 /****************************************************************************
3350 ****************************************************************************/
3352 static void construct_info_data(struct spoolss_Notify *info_data,
3353 enum spoolss_NotifyType type,
3354 uint16_t field, int id)
3356 info_data->type = type;
3357 info_data->field.field = field;
3358 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3359 info_data->job_id = id;
3362 /*******************************************************************
3364 * fill a notify_info struct with info asked
3366 ********************************************************************/
3368 static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
3369 struct printer_handle *print_hnd,
3370 struct spoolss_NotifyInfo *info,
3371 struct spoolss_PrinterInfo2 *pinfo2,
3372 int snum,
3373 const struct spoolss_NotifyOptionType *option_type,
3374 uint32_t id,
3375 TALLOC_CTX *mem_ctx)
3377 int field_num,j;
3378 enum spoolss_NotifyType type;
3379 uint16_t field;
3381 struct spoolss_Notify *current_data;
3383 type = option_type->type;
3385 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3386 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3387 option_type->count, lp_servicename(talloc_tos(), snum)));
3389 for(field_num=0; field_num < option_type->count; field_num++) {
3390 field = option_type->fields[field_num].field;
3392 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3394 if (!search_notify(type, field, &j) )
3395 continue;
3397 info->notifies = talloc_realloc(info, info->notifies,
3398 struct spoolss_Notify,
3399 info->count + 1);
3400 if (info->notifies == NULL) {
3401 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3402 return false;
3405 current_data = &info->notifies[info->count];
3407 construct_info_data(current_data, type, field, id);
3409 DEBUG(10, ("construct_notify_printer_info: "
3410 "calling [%s] snum=%d printername=[%s])\n",
3411 notify_info_data_table[j].name, snum,
3412 pinfo2->printername));
3414 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3415 NULL, pinfo2, mem_ctx);
3417 info->count++;
3420 return true;
3423 /*******************************************************************
3425 * fill a notify_info struct with info asked
3427 ********************************************************************/
3429 static bool construct_notify_jobs_info(struct messaging_context *msg_ctx,
3430 print_queue_struct *queue,
3431 struct spoolss_NotifyInfo *info,
3432 struct spoolss_PrinterInfo2 *pinfo2,
3433 int snum,
3434 const struct spoolss_NotifyOptionType *option_type,
3435 uint32_t id,
3436 TALLOC_CTX *mem_ctx)
3438 int field_num,j;
3439 enum spoolss_NotifyType type;
3440 uint16_t field;
3441 struct spoolss_Notify *current_data;
3443 DEBUG(4,("construct_notify_jobs_info\n"));
3445 type = option_type->type;
3447 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3448 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3449 option_type->count));
3451 for(field_num=0; field_num<option_type->count; field_num++) {
3452 field = option_type->fields[field_num].field;
3454 if (!search_notify(type, field, &j) )
3455 continue;
3457 info->notifies = talloc_realloc(info, info->notifies,
3458 struct spoolss_Notify,
3459 info->count + 1);
3460 if (info->notifies == NULL) {
3461 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3462 return false;
3465 current_data=&(info->notifies[info->count]);
3467 construct_info_data(current_data, type, field, id);
3468 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3469 queue, pinfo2, mem_ctx);
3470 info->count++;
3473 return true;
3477 * JFM: The enumeration is not that simple, it's even non obvious.
3479 * let's take an example: I want to monitor the PRINTER SERVER for
3480 * the printer's name and the number of jobs currently queued.
3481 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3482 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3484 * I have 3 printers on the back of my server.
3486 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3487 * structures.
3488 * Number Data Id
3489 * 1 printer 1 name 1
3490 * 2 printer 1 cjob 1
3491 * 3 printer 2 name 2
3492 * 4 printer 2 cjob 2
3493 * 5 printer 3 name 3
3494 * 6 printer 3 name 3
3496 * that's the print server case, the printer case is even worse.
3499 /*******************************************************************
3501 * enumerate all printers on the printserver
3502 * fill a notify_info struct with info asked
3504 ********************************************************************/
3506 static WERROR printserver_notify_info(struct pipes_struct *p,
3507 struct policy_handle *hnd,
3508 struct spoolss_NotifyInfo *info,
3509 TALLOC_CTX *mem_ctx)
3511 int snum;
3512 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3513 int n_services=lp_numservices();
3514 int i;
3515 struct spoolss_NotifyOption *option;
3516 struct spoolss_NotifyOptionType option_type;
3517 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3518 WERROR result;
3520 DEBUG(4,("printserver_notify_info\n"));
3522 if (!Printer)
3523 return WERR_BADFID;
3525 option = Printer->notify.option;
3527 info->version = 2;
3528 info->notifies = NULL;
3529 info->count = 0;
3531 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3532 sending a ffpcn() request first */
3534 if ( !option )
3535 return WERR_BADFID;
3537 for (i=0; i<option->count; i++) {
3538 option_type = option->types[i];
3540 if (option_type.type != PRINTER_NOTIFY_TYPE)
3541 continue;
3543 for (snum = 0; snum < n_services; snum++) {
3544 if (!lp_browseable(snum) ||
3545 !lp_snum_ok(snum) ||
3546 !lp_print_ok(snum)) {
3547 continue; /* skip */
3550 /* Maybe we should use the SYSTEM session_info here... */
3551 result = winreg_get_printer_internal(mem_ctx,
3552 get_session_info_system(),
3553 p->msg_ctx,
3554 lp_servicename(talloc_tos(), snum),
3555 &pinfo2);
3556 if (!W_ERROR_IS_OK(result)) {
3557 DEBUG(4, ("printserver_notify_info: "
3558 "Failed to get printer [%s]\n",
3559 lp_servicename(talloc_tos(), snum)));
3560 continue;
3564 construct_notify_printer_info(p->msg_ctx,
3565 Printer, info,
3566 pinfo2, snum,
3567 &option_type, snum,
3568 mem_ctx);
3570 TALLOC_FREE(pinfo2);
3574 #if 0
3576 * Debugging information, don't delete.
3579 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3580 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3581 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3583 for (i=0; i<info->count; i++) {
3584 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3585 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3586 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3588 #endif
3590 return WERR_OK;
3593 /*******************************************************************
3595 * fill a notify_info struct with info asked
3597 ********************************************************************/
3599 static WERROR printer_notify_info(struct pipes_struct *p,
3600 struct policy_handle *hnd,
3601 struct spoolss_NotifyInfo *info,
3602 TALLOC_CTX *mem_ctx)
3604 int snum;
3605 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3606 int i;
3607 uint32_t id;
3608 struct spoolss_NotifyOption *option;
3609 struct spoolss_NotifyOptionType option_type;
3610 int count,j;
3611 print_queue_struct *queue=NULL;
3612 print_status_struct status;
3613 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3614 WERROR result;
3615 struct tdb_print_db *pdb;
3617 DEBUG(4,("printer_notify_info\n"));
3619 if (!Printer)
3620 return WERR_BADFID;
3622 option = Printer->notify.option;
3623 id = 0x0;
3625 info->version = 2;
3626 info->notifies = NULL;
3627 info->count = 0;
3629 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3630 sending a ffpcn() request first */
3632 if ( !option )
3633 return WERR_BADFID;
3635 if (!get_printer_snum(p, hnd, &snum, NULL)) {
3636 return WERR_BADFID;
3639 pdb = get_print_db_byname(Printer->sharename);
3640 if (pdb == NULL) {
3641 return WERR_BADFID;
3644 /* Maybe we should use the SYSTEM session_info here... */
3645 result = winreg_get_printer_internal(mem_ctx,
3646 get_session_info_system(),
3647 p->msg_ctx,
3648 lp_servicename(talloc_tos(), snum), &pinfo2);
3649 if (!W_ERROR_IS_OK(result)) {
3650 result = WERR_BADFID;
3651 goto err_pdb_drop;
3655 * When sending a PRINTER_NOTIFY_FIELD_SERVER_NAME we should send the
3656 * correct servername.
3658 pinfo2->servername = talloc_strdup(pinfo2, Printer->servername);
3659 if (pinfo2->servername == NULL) {
3660 result = WERR_NOMEM;
3661 goto err_pdb_drop;
3664 for (i = 0; i < option->count; i++) {
3665 option_type = option->types[i];
3667 switch (option_type.type) {
3668 case PRINTER_NOTIFY_TYPE:
3669 if (construct_notify_printer_info(p->msg_ctx,
3670 Printer, info,
3671 pinfo2, snum,
3672 &option_type, id,
3673 mem_ctx)) {
3674 id--;
3676 break;
3678 case JOB_NOTIFY_TYPE:
3680 count = print_queue_status(p->msg_ctx, snum, &queue,
3681 &status);
3683 for (j = 0; j < count; j++) {
3684 uint32_t jobid;
3685 jobid = sysjob_to_jobid_pdb(pdb,
3686 queue[j].sysjob);
3687 if (jobid == (uint32_t)-1) {
3688 DEBUG(2, ("ignoring untracked job %d\n",
3689 queue[j].sysjob));
3690 continue;
3692 /* FIXME check return value */
3693 construct_notify_jobs_info(p->msg_ctx,
3694 &queue[j], info,
3695 pinfo2, snum,
3696 &option_type,
3697 jobid,
3698 mem_ctx);
3701 SAFE_FREE(queue);
3702 break;
3707 * Debugging information, don't delete.
3710 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3711 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3712 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3714 for (i=0; i<info->count; i++) {
3715 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3716 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3717 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3721 talloc_free(pinfo2);
3722 result = WERR_OK;
3723 err_pdb_drop:
3724 release_print_db(pdb);
3725 return result;
3728 /****************************************************************
3729 _spoolss_RouterRefreshPrinterChangeNotify
3730 ****************************************************************/
3732 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3733 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3735 struct spoolss_NotifyInfo *info;
3737 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
3738 WERROR result = WERR_BADFID;
3740 /* we always have a spoolss_NotifyInfo struct */
3741 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3742 if (!info) {
3743 result = WERR_NOMEM;
3744 goto done;
3747 *r->out.info = info;
3749 if (!Printer) {
3750 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3751 "Invalid handle (%s:%u:%u).\n",
3752 OUR_HANDLE(r->in.handle)));
3753 goto done;
3756 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3759 * We are now using the change value, and
3760 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3761 * I don't have a global notification system, I'm sending back all the
3762 * information even when _NOTHING_ has changed.
3765 /* We need to keep track of the change value to send back in
3766 RRPCN replies otherwise our updates are ignored. */
3768 Printer->notify.fnpcn = true;
3770 if (Printer->notify.cli_chan != NULL &&
3771 Printer->notify.cli_chan->active_connections > 0) {
3772 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3773 "Saving change value in request [%x]\n",
3774 r->in.change_low));
3775 Printer->notify.change = r->in.change_low;
3778 /* just ignore the spoolss_NotifyOption */
3780 switch (Printer->printer_type) {
3781 case SPLHND_SERVER:
3782 result = printserver_notify_info(p, r->in.handle,
3783 info, p->mem_ctx);
3784 break;
3786 case SPLHND_PRINTER:
3787 result = printer_notify_info(p, r->in.handle,
3788 info, p->mem_ctx);
3789 break;
3792 Printer->notify.fnpcn = false;
3794 done:
3795 return result;
3798 /********************************************************************
3799 ********************************************************************/
3801 static WERROR create_printername(TALLOC_CTX *mem_ctx,
3802 const char *servername,
3803 const char *printername,
3804 const char **printername_p)
3806 /* FIXME: add lp_force_printername() */
3808 if (servername == NULL) {
3809 *printername_p = talloc_strdup(mem_ctx, printername);
3810 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3811 return WERR_OK;
3814 if (servername[0] == '\\' && servername[1] == '\\') {
3815 servername += 2;
3818 *printername_p = talloc_asprintf(mem_ctx, "\\\\%s\\%s", servername, printername);
3819 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3821 return WERR_OK;
3824 /********************************************************************
3825 ********************************************************************/
3827 static void compose_devicemode_devicename(struct spoolss_DeviceMode *dm,
3828 const char *printername)
3830 if (dm == NULL) {
3831 return;
3834 dm->devicename = talloc_strndup(dm, printername,
3835 MIN(strlen(printername), 31));
3838 /********************************************************************
3839 * construct_printer_info_0
3840 * fill a printer_info_0 struct
3841 ********************************************************************/
3843 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3844 const struct auth_session_info *session_info,
3845 struct messaging_context *msg_ctx,
3846 struct spoolss_PrinterInfo2 *info2,
3847 const char *servername,
3848 struct spoolss_PrinterInfo0 *r,
3849 int snum)
3851 int count;
3852 struct printer_session_counter *session_counter;
3853 struct timeval setuptime;
3854 print_status_struct status;
3855 WERROR result;
3857 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3858 if (!W_ERROR_IS_OK(result)) {
3859 return result;
3862 if (servername) {
3863 r->servername = talloc_strdup(mem_ctx, servername);
3864 W_ERROR_HAVE_NO_MEMORY(r->servername);
3865 } else {
3866 r->servername = NULL;
3869 count = print_queue_length(msg_ctx, snum, &status);
3871 /* check if we already have a counter for this printer */
3872 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3873 if (session_counter->snum == snum)
3874 break;
3877 /* it's the first time, add it to the list */
3878 if (session_counter == NULL) {
3879 session_counter = talloc_zero(counter_list, struct printer_session_counter);
3880 W_ERROR_HAVE_NO_MEMORY(session_counter);
3881 session_counter->snum = snum;
3882 session_counter->counter = 0;
3883 DLIST_ADD(counter_list, session_counter);
3886 /* increment it */
3887 session_counter->counter++;
3889 r->cjobs = count;
3890 r->total_jobs = 0;
3891 r->total_bytes = 0;
3893 get_startup_time(&setuptime);
3894 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3896 /* JFM:
3897 * the global_counter should be stored in a TDB as it's common to all the clients
3898 * and should be zeroed on samba startup
3900 r->global_counter = session_counter->counter;
3901 r->total_pages = 0;
3902 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3903 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3904 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3905 r->free_build = SPOOLSS_RELEASE_BUILD;
3906 r->spooling = 0;
3907 r->max_spooling = 0;
3908 r->session_counter = session_counter->counter;
3909 r->num_error_out_of_paper = 0x0;
3910 r->num_error_not_ready = 0x0; /* number of print failure */
3911 r->job_error = 0x0;
3912 r->number_of_processors = 0x1;
3913 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3914 r->high_part_total_bytes = 0x0;
3916 /* ChangeID in milliseconds*/
3917 winreg_printer_get_changeid_internal(mem_ctx, session_info, msg_ctx,
3918 info2->sharename, &r->change_id);
3920 r->last_error = WERR_OK;
3921 r->status = nt_printq_status(status.status);
3922 r->enumerate_network_printers = 0x0;
3923 r->c_setprinter = 0x0;
3924 r->processor_architecture = PROCESSOR_ARCHITECTURE_INTEL;
3925 r->processor_level = 0x6; /* 6 ???*/
3926 r->ref_ic = 0;
3927 r->reserved2 = 0;
3928 r->reserved3 = 0;
3930 return WERR_OK;
3934 /********************************************************************
3935 * construct_printer_info1
3936 * fill a spoolss_PrinterInfo1 struct
3937 ********************************************************************/
3939 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3940 const struct spoolss_PrinterInfo2 *info2,
3941 uint32_t flags,
3942 const char *servername,
3943 struct spoolss_PrinterInfo1 *r,
3944 int snum)
3946 WERROR result;
3948 r->flags = flags;
3950 if (info2->comment == NULL || info2->comment[0] == '\0') {
3951 r->comment = lp_comment(mem_ctx, snum);
3952 } else {
3953 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3955 W_ERROR_HAVE_NO_MEMORY(r->comment);
3957 result = create_printername(mem_ctx, servername, info2->printername, &r->name);
3958 if (!W_ERROR_IS_OK(result)) {
3959 return result;
3962 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3963 r->name,
3964 info2->drivername,
3965 r->comment);
3966 W_ERROR_HAVE_NO_MEMORY(r->description);
3968 return WERR_OK;
3971 /********************************************************************
3972 * construct_printer_info2
3973 * fill a spoolss_PrinterInfo2 struct
3974 ********************************************************************/
3976 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3977 struct messaging_context *msg_ctx,
3978 const struct spoolss_PrinterInfo2 *info2,
3979 const char *servername,
3980 struct spoolss_PrinterInfo2 *r,
3981 int snum)
3983 int count;
3984 print_status_struct status;
3985 WERROR result;
3987 count = print_queue_length(msg_ctx, snum, &status);
3989 if (servername) {
3990 r->servername = talloc_strdup(mem_ctx, servername);
3991 W_ERROR_HAVE_NO_MEMORY(r->servername);
3992 } else {
3993 r->servername = NULL;
3996 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3997 if (!W_ERROR_IS_OK(result)) {
3998 return result;
4001 r->sharename = lp_servicename(mem_ctx, snum);
4002 W_ERROR_HAVE_NO_MEMORY(r->sharename);
4003 r->portname = talloc_strdup(mem_ctx, info2->portname);
4004 W_ERROR_HAVE_NO_MEMORY(r->portname);
4005 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
4006 W_ERROR_HAVE_NO_MEMORY(r->drivername);
4008 if (info2->comment[0] == '\0') {
4009 r->comment = lp_comment(mem_ctx, snum);
4010 } else {
4011 r->comment = talloc_strdup(mem_ctx, info2->comment);
4013 W_ERROR_HAVE_NO_MEMORY(r->comment);
4015 r->location = talloc_strdup(mem_ctx, info2->location);
4016 if (info2->location[0] == '\0') {
4017 const char *loc = NULL;
4018 NTSTATUS nt_status;
4020 nt_status = printer_list_get_printer(mem_ctx,
4021 info2->sharename,
4022 NULL,
4023 &loc,
4024 NULL);
4025 if (NT_STATUS_IS_OK(nt_status)) {
4026 if (loc != NULL) {
4027 r->location = talloc_strdup(mem_ctx, loc);
4031 W_ERROR_HAVE_NO_MEMORY(r->location);
4033 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
4034 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
4035 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
4036 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
4037 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
4038 W_ERROR_HAVE_NO_MEMORY(r->datatype);
4039 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
4040 W_ERROR_HAVE_NO_MEMORY(r->parameters);
4042 r->attributes = info2->attributes;
4044 r->priority = info2->priority;
4045 r->defaultpriority = info2->defaultpriority;
4046 r->starttime = info2->starttime;
4047 r->untiltime = info2->untiltime;
4048 r->status = nt_printq_status(status.status);
4049 r->cjobs = count;
4050 r->averageppm = info2->averageppm;
4052 if (info2->devmode != NULL) {
4053 result = copy_devicemode(mem_ctx,
4054 info2->devmode,
4055 &r->devmode);
4056 if (!W_ERROR_IS_OK(result)) {
4057 return result;
4059 } else if (lp_default_devmode(snum)) {
4060 result = spoolss_create_default_devmode(mem_ctx,
4061 info2->printername,
4062 &r->devmode);
4063 if (!W_ERROR_IS_OK(result)) {
4064 return result;
4066 } else {
4067 r->devmode = NULL;
4068 DEBUG(8,("Returning NULL Devicemode!\n"));
4071 compose_devicemode_devicename(r->devmode, r->printername);
4073 r->secdesc = NULL;
4075 if (info2->secdesc != NULL) {
4076 /* don't use talloc_steal() here unless you do a deep steal of all
4077 the SEC_DESC members */
4079 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4082 return WERR_OK;
4085 /********************************************************************
4086 * construct_printer_info3
4087 * fill a spoolss_PrinterInfo3 struct
4088 ********************************************************************/
4090 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
4091 const struct spoolss_PrinterInfo2 *info2,
4092 const char *servername,
4093 struct spoolss_PrinterInfo3 *r,
4094 int snum)
4096 /* These are the components of the SD we are returning. */
4098 if (info2->secdesc != NULL) {
4099 /* don't use talloc_steal() here unless you do a deep steal of all
4100 the SEC_DESC members */
4102 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4103 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
4106 return WERR_OK;
4109 /********************************************************************
4110 * construct_printer_info4
4111 * fill a spoolss_PrinterInfo4 struct
4112 ********************************************************************/
4114 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4115 const struct spoolss_PrinterInfo2 *info2,
4116 const char *servername,
4117 struct spoolss_PrinterInfo4 *r,
4118 int snum)
4120 WERROR result;
4122 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4123 if (!W_ERROR_IS_OK(result)) {
4124 return result;
4127 if (servername) {
4128 r->servername = talloc_strdup(mem_ctx, servername);
4129 W_ERROR_HAVE_NO_MEMORY(r->servername);
4130 } else {
4131 r->servername = NULL;
4134 r->attributes = info2->attributes;
4136 return WERR_OK;
4139 /********************************************************************
4140 * construct_printer_info5
4141 * fill a spoolss_PrinterInfo5 struct
4142 ********************************************************************/
4144 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4145 const struct spoolss_PrinterInfo2 *info2,
4146 const char *servername,
4147 struct spoolss_PrinterInfo5 *r,
4148 int snum)
4150 WERROR result;
4152 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4153 if (!W_ERROR_IS_OK(result)) {
4154 return result;
4157 r->portname = talloc_strdup(mem_ctx, info2->portname);
4158 W_ERROR_HAVE_NO_MEMORY(r->portname);
4160 r->attributes = info2->attributes;
4162 /* these two are not used by NT+ according to MSDN */
4163 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4164 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4166 return WERR_OK;
4169 /********************************************************************
4170 * construct_printer_info_6
4171 * fill a spoolss_PrinterInfo6 struct
4172 ********************************************************************/
4174 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4175 struct messaging_context *msg_ctx,
4176 const struct spoolss_PrinterInfo2 *info2,
4177 const char *servername,
4178 struct spoolss_PrinterInfo6 *r,
4179 int snum)
4181 print_status_struct status;
4183 print_queue_length(msg_ctx, snum, &status);
4185 r->status = nt_printq_status(status.status);
4187 return WERR_OK;
4190 /********************************************************************
4191 * construct_printer_info7
4192 * fill a spoolss_PrinterInfo7 struct
4193 ********************************************************************/
4195 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4196 struct messaging_context *msg_ctx,
4197 const char *servername,
4198 struct spoolss_PrinterInfo7 *r,
4199 int snum)
4201 const struct auth_session_info *session_info;
4202 char *printer;
4203 WERROR werr;
4204 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
4205 if (tmp_ctx == NULL) {
4206 return WERR_NOMEM;
4209 session_info = get_session_info_system();
4210 SMB_ASSERT(session_info != NULL);
4212 printer = lp_servicename(tmp_ctx, snum);
4213 if (printer == NULL) {
4214 DEBUG(0, ("invalid printer snum %d\n", snum));
4215 werr = WERR_INVALID_PARAM;
4216 goto out_tmp_free;
4219 if (is_printer_published(tmp_ctx, session_info, msg_ctx,
4220 servername, printer, NULL)) {
4221 struct GUID guid;
4222 werr = nt_printer_guid_get(tmp_ctx, session_info, msg_ctx,
4223 printer, &guid);
4224 if (!W_ERROR_IS_OK(werr)) {
4225 goto out_tmp_free;
4227 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4228 r->action = DSPRINT_PUBLISH;
4229 } else {
4230 r->guid = talloc_strdup(mem_ctx, "");
4231 r->action = DSPRINT_UNPUBLISH;
4233 if (r->guid == NULL) {
4234 werr = WERR_NOMEM;
4235 goto out_tmp_free;
4238 werr = WERR_OK;
4239 out_tmp_free:
4240 talloc_free(tmp_ctx);
4241 return werr;
4244 /********************************************************************
4245 * construct_printer_info8
4246 * fill a spoolss_PrinterInfo8 struct
4247 ********************************************************************/
4249 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4250 const struct spoolss_PrinterInfo2 *info2,
4251 const char *servername,
4252 struct spoolss_DeviceModeInfo *r,
4253 int snum)
4255 WERROR result;
4256 const char *printername;
4258 result = create_printername(mem_ctx, servername, info2->printername, &printername);
4259 if (!W_ERROR_IS_OK(result)) {
4260 return result;
4263 if (info2->devmode != NULL) {
4264 result = copy_devicemode(mem_ctx,
4265 info2->devmode,
4266 &r->devmode);
4267 if (!W_ERROR_IS_OK(result)) {
4268 return result;
4270 } else if (lp_default_devmode(snum)) {
4271 result = spoolss_create_default_devmode(mem_ctx,
4272 info2->printername,
4273 &r->devmode);
4274 if (!W_ERROR_IS_OK(result)) {
4275 return result;
4277 } else {
4278 r->devmode = NULL;
4279 DEBUG(8,("Returning NULL Devicemode!\n"));
4282 compose_devicemode_devicename(r->devmode, printername);
4284 return WERR_OK;
4288 /********************************************************************
4289 ********************************************************************/
4291 static bool snum_is_shared_printer(int snum)
4293 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4296 /********************************************************************
4297 Spoolss_enumprinters.
4298 ********************************************************************/
4300 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4301 const struct auth_session_info *session_info,
4302 struct messaging_context *msg_ctx,
4303 const char *servername,
4304 uint32_t level,
4305 uint32_t flags,
4306 union spoolss_PrinterInfo **info_p,
4307 uint32_t *count_p)
4309 int snum;
4310 int n_services = lp_numservices();
4311 union spoolss_PrinterInfo *info = NULL;
4312 uint32_t count = 0;
4313 WERROR result = WERR_OK;
4314 struct dcerpc_binding_handle *b = NULL;
4315 TALLOC_CTX *tmp_ctx = NULL;
4317 tmp_ctx = talloc_new(mem_ctx);
4318 if (!tmp_ctx) {
4319 return WERR_NOMEM;
4322 *count_p = 0;
4323 *info_p = NULL;
4325 for (snum = 0; snum < n_services; snum++) {
4327 const char *printer;
4328 struct spoolss_PrinterInfo2 *info2;
4330 if (!snum_is_shared_printer(snum)) {
4331 continue;
4334 printer = lp_const_servicename(snum);
4336 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4337 printer, snum));
4339 if (b == NULL) {
4340 result = winreg_printer_binding_handle(tmp_ctx,
4341 session_info,
4342 msg_ctx,
4343 &b);
4344 if (!W_ERROR_IS_OK(result)) {
4345 goto out;
4349 result = winreg_create_printer(tmp_ctx, b,
4350 printer);
4351 if (!W_ERROR_IS_OK(result)) {
4352 goto out;
4355 info = talloc_realloc(tmp_ctx, info,
4356 union spoolss_PrinterInfo,
4357 count + 1);
4358 if (!info) {
4359 result = WERR_NOMEM;
4360 goto out;
4363 result = winreg_get_printer(tmp_ctx, b,
4364 printer, &info2);
4365 if (!W_ERROR_IS_OK(result)) {
4366 goto out;
4369 switch (level) {
4370 case 0:
4371 result = construct_printer_info0(info, session_info,
4372 msg_ctx, info2,
4373 servername,
4374 &info[count].info0, snum);
4375 break;
4376 case 1:
4377 result = construct_printer_info1(info, info2, flags,
4378 servername,
4379 &info[count].info1, snum);
4380 break;
4381 case 2:
4382 result = construct_printer_info2(info, msg_ctx, info2,
4383 servername,
4384 &info[count].info2, snum);
4385 break;
4386 case 4:
4387 result = construct_printer_info4(info, info2,
4388 servername,
4389 &info[count].info4, snum);
4390 break;
4391 case 5:
4392 result = construct_printer_info5(info, info2,
4393 servername,
4394 &info[count].info5, snum);
4395 break;
4397 default:
4398 result = WERR_UNKNOWN_LEVEL;
4399 goto out;
4402 if (!W_ERROR_IS_OK(result)) {
4403 goto out;
4406 count++;
4409 out:
4410 if (W_ERROR_IS_OK(result)) {
4411 *info_p = talloc_move(mem_ctx, &info);
4412 *count_p = count;
4415 talloc_free(tmp_ctx);
4417 return result;
4420 /********************************************************************
4421 * handle enumeration of printers at level 0
4422 ********************************************************************/
4424 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4425 const struct auth_session_info *session_info,
4426 struct messaging_context *msg_ctx,
4427 uint32_t flags,
4428 const char *servername,
4429 union spoolss_PrinterInfo **info,
4430 uint32_t *count)
4432 DEBUG(4,("enum_all_printers_info_0\n"));
4434 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4435 servername, 0, flags, info, count);
4439 /********************************************************************
4440 ********************************************************************/
4442 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4443 const struct auth_session_info *session_info,
4444 struct messaging_context *msg_ctx,
4445 const char *servername,
4446 uint32_t flags,
4447 union spoolss_PrinterInfo **info,
4448 uint32_t *count)
4450 DEBUG(4,("enum_all_printers_info_1\n"));
4452 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4453 servername, 1, flags, info, count);
4456 /********************************************************************
4457 enum_all_printers_info_1_local.
4458 *********************************************************************/
4460 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4461 const struct auth_session_info *session_info,
4462 struct messaging_context *msg_ctx,
4463 const char *servername,
4464 union spoolss_PrinterInfo **info,
4465 uint32_t *count)
4467 DEBUG(4,("enum_all_printers_info_1_local\n"));
4469 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4470 servername, PRINTER_ENUM_ICON8, info, count);
4473 /********************************************************************
4474 enum_all_printers_info_1_name.
4475 *********************************************************************/
4477 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4478 const struct auth_session_info *session_info,
4479 struct messaging_context *msg_ctx,
4480 const char *servername,
4481 union spoolss_PrinterInfo **info,
4482 uint32_t *count)
4484 const char *s = servername;
4486 DEBUG(4,("enum_all_printers_info_1_name\n"));
4488 if (servername != NULL &&
4489 (servername[0] == '\\') && (servername[1] == '\\')) {
4490 s = servername + 2;
4493 if (!is_myname_or_ipaddr(s)) {
4494 return WERR_INVALID_NAME;
4497 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4498 servername, PRINTER_ENUM_ICON8, info, count);
4501 /********************************************************************
4502 enum_all_printers_info_1_network.
4503 *********************************************************************/
4505 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4506 const struct auth_session_info *session_info,
4507 struct messaging_context *msg_ctx,
4508 const char *servername,
4509 union spoolss_PrinterInfo **info,
4510 uint32_t *count)
4512 const char *s = servername;
4514 DEBUG(4,("enum_all_printers_info_1_network\n"));
4516 /* If we respond to a enum_printers level 1 on our name with flags
4517 set to PRINTER_ENUM_REMOTE with a list of printers then these
4518 printers incorrectly appear in the APW browse list.
4519 Specifically the printers for the server appear at the workgroup
4520 level where all the other servers in the domain are
4521 listed. Windows responds to this call with a
4522 WERR_CAN_NOT_COMPLETE so we should do the same. */
4524 if (servername != NULL &&
4525 (servername[0] == '\\') && (servername[1] == '\\')) {
4526 s = servername + 2;
4529 if (is_myname_or_ipaddr(s)) {
4530 return WERR_CAN_NOT_COMPLETE;
4533 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4534 servername, PRINTER_ENUM_NAME, info, count);
4537 /********************************************************************
4538 * api_spoolss_enumprinters
4540 * called from api_spoolss_enumprinters (see this to understand)
4541 ********************************************************************/
4543 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4544 const struct auth_session_info *session_info,
4545 struct messaging_context *msg_ctx,
4546 const char *servername,
4547 union spoolss_PrinterInfo **info,
4548 uint32_t *count)
4550 DEBUG(4,("enum_all_printers_info_2\n"));
4552 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4553 servername, 2, 0, info, count);
4556 /********************************************************************
4557 * handle enumeration of printers at level 1
4558 ********************************************************************/
4560 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4561 const struct auth_session_info *session_info,
4562 struct messaging_context *msg_ctx,
4563 uint32_t flags,
4564 const char *servername,
4565 union spoolss_PrinterInfo **info,
4566 uint32_t *count)
4568 /* Not all the flags are equals */
4570 if (flags & PRINTER_ENUM_LOCAL) {
4571 return enum_all_printers_info_1_local(mem_ctx, session_info,
4572 msg_ctx, servername, info, count);
4575 if (flags & PRINTER_ENUM_NAME) {
4576 return enum_all_printers_info_1_name(mem_ctx, session_info,
4577 msg_ctx, servername, info,
4578 count);
4581 if (flags & PRINTER_ENUM_NETWORK) {
4582 return enum_all_printers_info_1_network(mem_ctx, session_info,
4583 msg_ctx, servername, info,
4584 count);
4587 return WERR_OK; /* NT4sp5 does that */
4590 /********************************************************************
4591 * handle enumeration of printers at level 2
4592 ********************************************************************/
4594 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4595 const struct auth_session_info *session_info,
4596 struct messaging_context *msg_ctx,
4597 uint32_t flags,
4598 const char *servername,
4599 union spoolss_PrinterInfo **info,
4600 uint32_t *count)
4602 if (flags & PRINTER_ENUM_LOCAL) {
4604 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4605 servername,
4606 info, count);
4609 if (flags & PRINTER_ENUM_NAME) {
4610 if (servername && !is_myname_or_ipaddr(canon_servername(servername))) {
4611 return WERR_INVALID_NAME;
4614 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4615 servername,
4616 info, count);
4619 if (flags & PRINTER_ENUM_REMOTE) {
4620 return WERR_UNKNOWN_LEVEL;
4623 return WERR_OK;
4626 /********************************************************************
4627 * handle enumeration of printers at level 4
4628 ********************************************************************/
4630 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4631 const struct auth_session_info *session_info,
4632 struct messaging_context *msg_ctx,
4633 uint32_t flags,
4634 const char *servername,
4635 union spoolss_PrinterInfo **info,
4636 uint32_t *count)
4638 DEBUG(4,("enum_all_printers_info_4\n"));
4640 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4641 servername, 4, flags, info, count);
4645 /********************************************************************
4646 * handle enumeration of printers at level 5
4647 ********************************************************************/
4649 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4650 const struct auth_session_info *session_info,
4651 struct messaging_context *msg_ctx,
4652 uint32_t flags,
4653 const char *servername,
4654 union spoolss_PrinterInfo **info,
4655 uint32_t *count)
4657 DEBUG(4,("enum_all_printers_info_5\n"));
4659 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4660 servername, 5, flags, info, count);
4663 /****************************************************************
4664 _spoolss_EnumPrinters
4665 ****************************************************************/
4667 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4668 struct spoolss_EnumPrinters *r)
4670 const struct auth_session_info *session_info = get_session_info_system();
4671 WERROR result;
4673 /* that's an [in out] buffer */
4675 if (!r->in.buffer && (r->in.offered != 0)) {
4676 return WERR_INVALID_PARAM;
4679 DEBUG(4,("_spoolss_EnumPrinters\n"));
4681 *r->out.needed = 0;
4682 *r->out.count = 0;
4683 *r->out.info = NULL;
4686 * Level 1:
4687 * flags==PRINTER_ENUM_NAME
4688 * if name=="" then enumerates all printers
4689 * if name!="" then enumerate the printer
4690 * flags==PRINTER_ENUM_REMOTE
4691 * name is NULL, enumerate printers
4692 * Level 2: name!="" enumerates printers, name can't be NULL
4693 * Level 3: doesn't exist
4694 * Level 4: does a local registry lookup
4695 * Level 5: same as Level 2
4698 if (r->in.server && r->in.server[0] == '\0') {
4699 r->in.server = NULL;
4702 switch (r->in.level) {
4703 case 0:
4704 result = enumprinters_level0(p->mem_ctx, session_info,
4705 p->msg_ctx, r->in.flags,
4706 r->in.server,
4707 r->out.info, r->out.count);
4708 break;
4709 case 1:
4710 result = enumprinters_level1(p->mem_ctx, session_info,
4711 p->msg_ctx, r->in.flags,
4712 r->in.server,
4713 r->out.info, r->out.count);
4714 break;
4715 case 2:
4716 result = enumprinters_level2(p->mem_ctx, session_info,
4717 p->msg_ctx, r->in.flags,
4718 r->in.server,
4719 r->out.info, r->out.count);
4720 break;
4721 case 4:
4722 result = enumprinters_level4(p->mem_ctx, session_info,
4723 p->msg_ctx, r->in.flags,
4724 r->in.server,
4725 r->out.info, r->out.count);
4726 break;
4727 case 5:
4728 result = enumprinters_level5(p->mem_ctx, session_info,
4729 p->msg_ctx, r->in.flags,
4730 r->in.server,
4731 r->out.info, r->out.count);
4732 break;
4733 default:
4734 return WERR_UNKNOWN_LEVEL;
4737 if (!W_ERROR_IS_OK(result)) {
4738 return result;
4741 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4742 spoolss_EnumPrinters,
4743 *r->out.info, r->in.level,
4744 *r->out.count);
4745 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4746 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4748 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4751 /****************************************************************
4752 _spoolss_GetPrinter
4753 ****************************************************************/
4755 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4756 struct spoolss_GetPrinter *r)
4758 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
4759 struct spoolss_PrinterInfo2 *info2 = NULL;
4760 WERROR result = WERR_OK;
4761 int snum;
4763 /* that's an [in out] buffer */
4765 if (!r->in.buffer && (r->in.offered != 0)) {
4766 return WERR_INVALID_PARAM;
4769 *r->out.needed = 0;
4771 if (Printer == NULL) {
4772 return WERR_BADFID;
4775 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4776 return WERR_BADFID;
4779 result = winreg_get_printer_internal(p->mem_ctx,
4780 get_session_info_system(),
4781 p->msg_ctx,
4782 lp_const_servicename(snum),
4783 &info2);
4784 if (!W_ERROR_IS_OK(result)) {
4785 goto out;
4788 switch (r->in.level) {
4789 case 0:
4790 result = construct_printer_info0(p->mem_ctx,
4791 get_session_info_system(),
4792 p->msg_ctx,
4793 info2,
4794 Printer->servername,
4795 &r->out.info->info0,
4796 snum);
4797 break;
4798 case 1:
4799 result = construct_printer_info1(p->mem_ctx, info2,
4800 PRINTER_ENUM_ICON8,
4801 Printer->servername,
4802 &r->out.info->info1, snum);
4803 break;
4804 case 2:
4805 result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
4806 Printer->servername,
4807 &r->out.info->info2, snum);
4808 break;
4809 case 3:
4810 result = construct_printer_info3(p->mem_ctx, info2,
4811 Printer->servername,
4812 &r->out.info->info3, snum);
4813 break;
4814 case 4:
4815 result = construct_printer_info4(p->mem_ctx, info2,
4816 Printer->servername,
4817 &r->out.info->info4, snum);
4818 break;
4819 case 5:
4820 result = construct_printer_info5(p->mem_ctx, info2,
4821 Printer->servername,
4822 &r->out.info->info5, snum);
4823 break;
4824 case 6:
4825 result = construct_printer_info6(p->mem_ctx, p->msg_ctx, info2,
4826 Printer->servername,
4827 &r->out.info->info6, snum);
4828 break;
4829 case 7:
4830 result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
4831 Printer->servername,
4832 &r->out.info->info7, snum);
4833 break;
4834 case 8:
4835 result = construct_printer_info8(p->mem_ctx, info2,
4836 Printer->servername,
4837 &r->out.info->info8, snum);
4838 break;
4839 default:
4840 result = WERR_UNKNOWN_LEVEL;
4841 break;
4843 TALLOC_FREE(info2);
4845 out:
4846 if (!W_ERROR_IS_OK(result)) {
4847 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4848 r->in.level, win_errstr(result)));
4849 TALLOC_FREE(r->out.info);
4850 return result;
4853 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4854 r->out.info, r->in.level);
4855 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4857 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4860 /********************************************************************
4861 ********************************************************************/
4863 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4864 do { \
4865 if (in && strlen(in)) { \
4866 out = talloc_strdup(mem_ctx, in); \
4867 } else { \
4868 out = talloc_strdup(mem_ctx, ""); \
4870 W_ERROR_HAVE_NO_MEMORY(out); \
4871 } while (0);
4873 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4874 do { \
4875 if (in && strlen(in)) { \
4876 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4877 } else { \
4878 out = talloc_strdup(mem_ctx, ""); \
4880 W_ERROR_HAVE_NO_MEMORY(out); \
4881 } while (0);
4883 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4884 const char **string_array,
4885 const char ***presult,
4886 const char *cservername,
4887 const char *arch,
4888 int version)
4890 int i, num_strings = 0;
4891 const char **array = NULL;
4893 if (string_array == NULL) {
4894 return WERR_INVALID_PARAMETER;
4897 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4898 const char *str = NULL;
4900 if (cservername == NULL || arch == NULL) {
4901 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4902 } else {
4903 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4906 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4907 TALLOC_FREE(array);
4908 return WERR_NOMEM;
4912 if (i > 0) {
4913 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4914 &array, &num_strings);
4917 if (presult != NULL) {
4918 *presult = array;
4919 } else {
4920 talloc_free(array);
4923 return WERR_OK;
4926 /********************************************************************
4927 * fill a spoolss_DriverInfo1 struct
4928 ********************************************************************/
4930 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4931 struct spoolss_DriverInfo1 *r,
4932 const struct spoolss_DriverInfo8 *driver,
4933 const char *servername)
4935 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4936 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4938 return WERR_OK;
4941 /********************************************************************
4942 * fill a spoolss_DriverInfo2 struct
4943 ********************************************************************/
4945 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4946 struct spoolss_DriverInfo2 *r,
4947 const struct spoolss_DriverInfo8 *driver,
4948 const char *servername)
4951 const char *cservername = canon_servername(servername);
4953 r->version = driver->version;
4955 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4956 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4957 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4958 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4960 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4961 driver->architecture,
4962 driver->version,
4963 driver->driver_path,
4964 r->driver_path);
4966 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4967 driver->architecture,
4968 driver->version,
4969 driver->data_file,
4970 r->data_file);
4972 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4973 driver->architecture,
4974 driver->version,
4975 driver->config_file,
4976 r->config_file);
4978 return WERR_OK;
4981 /********************************************************************
4982 * fill a spoolss_DriverInfo3 struct
4983 ********************************************************************/
4985 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4986 struct spoolss_DriverInfo3 *r,
4987 const struct spoolss_DriverInfo8 *driver,
4988 const char *servername)
4990 const char *cservername = canon_servername(servername);
4992 r->version = driver->version;
4994 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4995 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4996 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4997 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4999 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5000 driver->architecture,
5001 driver->version,
5002 driver->driver_path,
5003 r->driver_path);
5005 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5006 driver->architecture,
5007 driver->version,
5008 driver->data_file,
5009 r->data_file);
5011 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5012 driver->architecture,
5013 driver->version,
5014 driver->config_file,
5015 r->config_file);
5017 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5018 driver->architecture,
5019 driver->version,
5020 driver->help_file,
5021 r->help_file);
5023 FILL_DRIVER_STRING(mem_ctx,
5024 driver->monitor_name,
5025 r->monitor_name);
5027 FILL_DRIVER_STRING(mem_ctx,
5028 driver->default_datatype,
5029 r->default_datatype);
5031 return string_array_from_driver_info(mem_ctx,
5032 driver->dependent_files,
5033 &r->dependent_files,
5034 cservername,
5035 driver->architecture,
5036 driver->version);
5039 /********************************************************************
5040 * fill a spoolss_DriverInfo4 struct
5041 ********************************************************************/
5043 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
5044 struct spoolss_DriverInfo4 *r,
5045 const struct spoolss_DriverInfo8 *driver,
5046 const char *servername)
5048 const char *cservername = canon_servername(servername);
5049 WERROR result;
5051 r->version = driver->version;
5053 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5054 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5055 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5056 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5058 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5059 driver->architecture,
5060 driver->version,
5061 driver->driver_path,
5062 r->driver_path);
5064 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5065 driver->architecture,
5066 driver->version,
5067 driver->data_file,
5068 r->data_file);
5070 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5071 driver->architecture,
5072 driver->version,
5073 driver->config_file,
5074 r->config_file);
5076 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5077 driver->architecture,
5078 driver->version,
5079 driver->help_file,
5080 r->help_file);
5082 result = string_array_from_driver_info(mem_ctx,
5083 driver->dependent_files,
5084 &r->dependent_files,
5085 cservername,
5086 driver->architecture,
5087 driver->version);
5088 if (!W_ERROR_IS_OK(result)) {
5089 return result;
5092 FILL_DRIVER_STRING(mem_ctx,
5093 driver->monitor_name,
5094 r->monitor_name);
5096 FILL_DRIVER_STRING(mem_ctx,
5097 driver->default_datatype,
5098 r->default_datatype);
5101 result = string_array_from_driver_info(mem_ctx,
5102 driver->previous_names,
5103 &r->previous_names,
5104 NULL, NULL, 0);
5106 return result;
5109 /********************************************************************
5110 * fill a spoolss_DriverInfo5 struct
5111 ********************************************************************/
5113 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
5114 struct spoolss_DriverInfo5 *r,
5115 const struct spoolss_DriverInfo8 *driver,
5116 const char *servername)
5118 const char *cservername = canon_servername(servername);
5120 r->version = driver->version;
5122 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5123 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5124 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5125 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5127 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5128 driver->architecture,
5129 driver->version,
5130 driver->driver_path,
5131 r->driver_path);
5133 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5134 driver->architecture,
5135 driver->version,
5136 driver->data_file,
5137 r->data_file);
5139 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5140 driver->architecture,
5141 driver->version,
5142 driver->config_file,
5143 r->config_file);
5145 r->driver_attributes = 0;
5146 r->config_version = 0;
5147 r->driver_version = 0;
5149 return WERR_OK;
5151 /********************************************************************
5152 * fill a spoolss_DriverInfo6 struct
5153 ********************************************************************/
5155 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
5156 struct spoolss_DriverInfo6 *r,
5157 const struct spoolss_DriverInfo8 *driver,
5158 const char *servername)
5160 const char *cservername = canon_servername(servername);
5161 WERROR result;
5163 r->version = driver->version;
5165 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5166 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5167 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5168 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5170 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5171 driver->architecture,
5172 driver->version,
5173 driver->driver_path,
5174 r->driver_path);
5176 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5177 driver->architecture,
5178 driver->version,
5179 driver->data_file,
5180 r->data_file);
5182 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5183 driver->architecture,
5184 driver->version,
5185 driver->config_file,
5186 r->config_file);
5188 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5189 driver->architecture,
5190 driver->version,
5191 driver->help_file,
5192 r->help_file);
5194 FILL_DRIVER_STRING(mem_ctx,
5195 driver->monitor_name,
5196 r->monitor_name);
5198 FILL_DRIVER_STRING(mem_ctx,
5199 driver->default_datatype,
5200 r->default_datatype);
5202 result = string_array_from_driver_info(mem_ctx,
5203 driver->dependent_files,
5204 &r->dependent_files,
5205 cservername,
5206 driver->architecture,
5207 driver->version);
5208 if (!W_ERROR_IS_OK(result)) {
5209 return result;
5212 result = string_array_from_driver_info(mem_ctx,
5213 driver->previous_names,
5214 &r->previous_names,
5215 NULL, NULL, 0);
5216 if (!W_ERROR_IS_OK(result)) {
5217 return result;
5220 r->driver_date = driver->driver_date;
5221 r->driver_version = driver->driver_version;
5223 FILL_DRIVER_STRING(mem_ctx,
5224 driver->manufacturer_name,
5225 r->manufacturer_name);
5226 FILL_DRIVER_STRING(mem_ctx,
5227 driver->manufacturer_url,
5228 r->manufacturer_url);
5229 FILL_DRIVER_STRING(mem_ctx,
5230 driver->hardware_id,
5231 r->hardware_id);
5232 FILL_DRIVER_STRING(mem_ctx,
5233 driver->provider,
5234 r->provider);
5236 return WERR_OK;
5239 /********************************************************************
5240 * fill a spoolss_DriverInfo8 struct
5241 ********************************************************************/
5243 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
5244 struct spoolss_DriverInfo8 *r,
5245 const struct spoolss_DriverInfo8 *driver,
5246 const char *servername)
5248 const char *cservername = canon_servername(servername);
5249 WERROR result;
5251 r->version = driver->version;
5253 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5254 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5255 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5256 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5258 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5259 driver->architecture,
5260 driver->version,
5261 driver->driver_path,
5262 r->driver_path);
5264 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5265 driver->architecture,
5266 driver->version,
5267 driver->data_file,
5268 r->data_file);
5270 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5271 driver->architecture,
5272 driver->version,
5273 driver->config_file,
5274 r->config_file);
5276 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5277 driver->architecture,
5278 driver->version,
5279 driver->help_file,
5280 r->help_file);
5282 FILL_DRIVER_STRING(mem_ctx,
5283 driver->monitor_name,
5284 r->monitor_name);
5286 FILL_DRIVER_STRING(mem_ctx,
5287 driver->default_datatype,
5288 r->default_datatype);
5290 result = string_array_from_driver_info(mem_ctx,
5291 driver->dependent_files,
5292 &r->dependent_files,
5293 cservername,
5294 driver->architecture,
5295 driver->version);
5296 if (!W_ERROR_IS_OK(result)) {
5297 return result;
5300 result = string_array_from_driver_info(mem_ctx,
5301 driver->previous_names,
5302 &r->previous_names,
5303 NULL, NULL, 0);
5304 if (!W_ERROR_IS_OK(result)) {
5305 return result;
5308 r->driver_date = driver->driver_date;
5309 r->driver_version = driver->driver_version;
5311 FILL_DRIVER_STRING(mem_ctx,
5312 driver->manufacturer_name,
5313 r->manufacturer_name);
5314 FILL_DRIVER_STRING(mem_ctx,
5315 driver->manufacturer_url,
5316 r->manufacturer_url);
5317 FILL_DRIVER_STRING(mem_ctx,
5318 driver->hardware_id,
5319 r->hardware_id);
5320 FILL_DRIVER_STRING(mem_ctx,
5321 driver->provider,
5322 r->provider);
5324 FILL_DRIVER_STRING(mem_ctx,
5325 driver->print_processor,
5326 r->print_processor);
5327 FILL_DRIVER_STRING(mem_ctx,
5328 driver->vendor_setup,
5329 r->vendor_setup);
5331 result = string_array_from_driver_info(mem_ctx,
5332 driver->color_profiles,
5333 &r->color_profiles,
5334 NULL, NULL, 0);
5335 if (!W_ERROR_IS_OK(result)) {
5336 return result;
5339 FILL_DRIVER_STRING(mem_ctx,
5340 driver->inf_path,
5341 r->inf_path);
5343 r->printer_driver_attributes = driver->printer_driver_attributes;
5345 result = string_array_from_driver_info(mem_ctx,
5346 driver->core_driver_dependencies,
5347 &r->core_driver_dependencies,
5348 NULL, NULL, 0);
5349 if (!W_ERROR_IS_OK(result)) {
5350 return result;
5353 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
5354 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
5356 return WERR_OK;
5359 #if 0 /* disabled until marshalling issues are resolved - gd */
5360 /********************************************************************
5361 ********************************************************************/
5363 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5364 struct spoolss_DriverFileInfo *r,
5365 const char *cservername,
5366 const char *file_name,
5367 enum spoolss_DriverFileType file_type,
5368 uint32_t file_version)
5370 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5371 cservername, file_name);
5372 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5373 r->file_type = file_type;
5374 r->file_version = file_version;
5376 return WERR_OK;
5379 /********************************************************************
5380 ********************************************************************/
5382 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5383 const struct spoolss_DriverInfo8 *driver,
5384 const char *cservername,
5385 struct spoolss_DriverFileInfo **info_p,
5386 uint32_t *count_p)
5388 struct spoolss_DriverFileInfo *info = NULL;
5389 uint32_t count = 0;
5390 WERROR result;
5391 uint32_t i;
5393 *info_p = NULL;
5394 *count_p = 0;
5396 if (strlen(driver->driver_path)) {
5397 info = talloc_realloc(mem_ctx, info,
5398 struct spoolss_DriverFileInfo,
5399 count + 1);
5400 W_ERROR_HAVE_NO_MEMORY(info);
5401 result = fill_spoolss_DriverFileInfo(info,
5402 &info[count],
5403 cservername,
5404 driver->driver_path,
5405 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5407 W_ERROR_NOT_OK_RETURN(result);
5408 count++;
5411 if (strlen(driver->config_file)) {
5412 info = talloc_realloc(mem_ctx, info,
5413 struct spoolss_DriverFileInfo,
5414 count + 1);
5415 W_ERROR_HAVE_NO_MEMORY(info);
5416 result = fill_spoolss_DriverFileInfo(info,
5417 &info[count],
5418 cservername,
5419 driver->config_file,
5420 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5422 W_ERROR_NOT_OK_RETURN(result);
5423 count++;
5426 if (strlen(driver->data_file)) {
5427 info = talloc_realloc(mem_ctx, info,
5428 struct spoolss_DriverFileInfo,
5429 count + 1);
5430 W_ERROR_HAVE_NO_MEMORY(info);
5431 result = fill_spoolss_DriverFileInfo(info,
5432 &info[count],
5433 cservername,
5434 driver->data_file,
5435 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5437 W_ERROR_NOT_OK_RETURN(result);
5438 count++;
5441 if (strlen(driver->help_file)) {
5442 info = talloc_realloc(mem_ctx, info,
5443 struct spoolss_DriverFileInfo,
5444 count + 1);
5445 W_ERROR_HAVE_NO_MEMORY(info);
5446 result = fill_spoolss_DriverFileInfo(info,
5447 &info[count],
5448 cservername,
5449 driver->help_file,
5450 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5452 W_ERROR_NOT_OK_RETURN(result);
5453 count++;
5456 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
5457 info = talloc_realloc(mem_ctx, info,
5458 struct spoolss_DriverFileInfo,
5459 count + 1);
5460 W_ERROR_HAVE_NO_MEMORY(info);
5461 result = fill_spoolss_DriverFileInfo(info,
5462 &info[count],
5463 cservername,
5464 driver->dependent_files[i],
5465 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5467 W_ERROR_NOT_OK_RETURN(result);
5468 count++;
5471 *info_p = info;
5472 *count_p = count;
5474 return WERR_OK;
5477 /********************************************************************
5478 * fill a spoolss_DriverInfo101 struct
5479 ********************************************************************/
5481 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5482 struct spoolss_DriverInfo101 *r,
5483 const struct spoolss_DriverInfo8 *driver,
5484 const char *servername)
5486 const char *cservername = canon_servername(servername);
5487 WERROR result;
5489 r->version = driver->version;
5491 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5492 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5493 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5494 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5496 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5497 cservername,
5498 &r->file_info,
5499 &r->file_count);
5500 if (!W_ERROR_IS_OK(result)) {
5501 return result;
5504 FILL_DRIVER_STRING(mem_ctx,
5505 driver->monitor_name,
5506 r->monitor_name);
5508 FILL_DRIVER_STRING(mem_ctx,
5509 driver->default_datatype,
5510 r->default_datatype);
5512 result = string_array_from_driver_info(mem_ctx,
5513 driver->previous_names,
5514 &r->previous_names,
5515 NULL, NULL, 0);
5516 if (!W_ERROR_IS_OK(result)) {
5517 return result;
5520 r->driver_date = driver->driver_date;
5521 r->driver_version = driver->driver_version;
5523 FILL_DRIVER_STRING(mem_ctx,
5524 driver->manufacturer_name,
5525 r->manufacturer_name);
5526 FILL_DRIVER_STRING(mem_ctx,
5527 driver->manufacturer_url,
5528 r->manufacturer_url);
5529 FILL_DRIVER_STRING(mem_ctx,
5530 driver->hardware_id,
5531 r->hardware_id);
5532 FILL_DRIVER_STRING(mem_ctx,
5533 driver->provider,
5534 r->provider);
5536 return WERR_OK;
5538 #endif
5539 /********************************************************************
5540 ********************************************************************/
5542 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5543 const struct auth_session_info *session_info,
5544 struct messaging_context *msg_ctx,
5545 uint32_t level,
5546 union spoolss_DriverInfo *r,
5547 int snum,
5548 const char *servername,
5549 const char *architecture,
5550 uint32_t version)
5552 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5553 struct spoolss_DriverInfo8 *driver;
5554 WERROR result;
5555 struct dcerpc_binding_handle *b;
5556 TALLOC_CTX *tmp_ctx = NULL;
5558 if (level == 101) {
5559 return WERR_UNKNOWN_LEVEL;
5562 tmp_ctx = talloc_new(mem_ctx);
5563 if (!tmp_ctx) {
5564 return WERR_NOMEM;
5567 result = winreg_printer_binding_handle(tmp_ctx,
5568 session_info,
5569 msg_ctx,
5570 &b);
5571 if (!W_ERROR_IS_OK(result)) {
5572 goto done;
5575 result = winreg_get_printer(tmp_ctx, b,
5576 lp_const_servicename(snum),
5577 &pinfo2);
5579 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5580 win_errstr(result)));
5582 if (!W_ERROR_IS_OK(result)) {
5583 result = WERR_INVALID_PRINTER_NAME;
5584 goto done;
5587 result = winreg_get_driver(tmp_ctx, b,
5588 architecture,
5589 pinfo2->drivername, version, &driver);
5591 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5592 win_errstr(result)));
5594 if (!W_ERROR_IS_OK(result)) {
5596 * Is this a W2k client ?
5599 if (version < 3) {
5600 result = WERR_UNKNOWN_PRINTER_DRIVER;
5601 goto done;
5604 /* Yes - try again with a WinNT driver. */
5605 version = 2;
5606 result = winreg_get_driver(tmp_ctx, b,
5607 architecture,
5608 pinfo2->drivername,
5609 version, &driver);
5610 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5611 win_errstr(result)));
5612 if (!W_ERROR_IS_OK(result)) {
5613 result = WERR_UNKNOWN_PRINTER_DRIVER;
5614 goto done;
5618 /* these are allocated on mem_ctx and not tmp_ctx because they are
5619 * the 'return value' and need to utlive this call */
5620 switch (level) {
5621 case 1:
5622 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5623 break;
5624 case 2:
5625 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5626 break;
5627 case 3:
5628 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5629 break;
5630 case 4:
5631 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5632 break;
5633 case 5:
5634 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5635 break;
5636 case 6:
5637 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5638 break;
5639 case 8:
5640 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5641 break;
5642 #if 0 /* disabled until marshalling issues are resolved - gd */
5643 case 101:
5644 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5645 break;
5646 #endif
5647 default:
5648 result = WERR_UNKNOWN_LEVEL;
5649 break;
5652 done:
5653 talloc_free(tmp_ctx);
5654 return result;
5657 /****************************************************************
5658 _spoolss_GetPrinterDriver2
5659 ****************************************************************/
5661 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5662 struct spoolss_GetPrinterDriver2 *r)
5664 struct printer_handle *printer;
5665 WERROR result;
5666 uint32_t version = r->in.client_major_version;
5668 int snum;
5670 /* that's an [in out] buffer */
5672 if (!r->in.buffer && (r->in.offered != 0)) {
5673 return WERR_INVALID_PARAM;
5676 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5678 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5679 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5680 return WERR_INVALID_PRINTER_NAME;
5683 *r->out.needed = 0;
5684 *r->out.server_major_version = 0;
5685 *r->out.server_minor_version = 0;
5687 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5688 return WERR_BADFID;
5691 if (r->in.client_major_version == SPOOLSS_DRIVER_VERSION_2012) {
5692 DEBUG(3,("_spoolss_GetPrinterDriver2: v4 driver requested, "
5693 "downgrading to v3\n"));
5694 version = SPOOLSS_DRIVER_VERSION_200X;
5697 result = construct_printer_driver_info_level(p->mem_ctx,
5698 get_session_info_system(),
5699 p->msg_ctx,
5700 r->in.level, r->out.info,
5701 snum, printer->servername,
5702 r->in.architecture,
5703 version);
5704 if (!W_ERROR_IS_OK(result)) {
5705 TALLOC_FREE(r->out.info);
5706 return result;
5709 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5710 r->out.info, r->in.level);
5711 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5713 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5717 /****************************************************************
5718 _spoolss_StartPagePrinter
5719 ****************************************************************/
5721 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5722 struct spoolss_StartPagePrinter *r)
5724 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5726 if (!Printer) {
5727 DEBUG(3,("_spoolss_StartPagePrinter: "
5728 "Error in startpageprinter printer handle\n"));
5729 return WERR_BADFID;
5732 Printer->page_started = true;
5733 return WERR_OK;
5736 /****************************************************************
5737 _spoolss_EndPagePrinter
5738 ****************************************************************/
5740 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5741 struct spoolss_EndPagePrinter *r)
5743 int snum;
5745 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5747 if (!Printer) {
5748 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5749 OUR_HANDLE(r->in.handle)));
5750 return WERR_BADFID;
5753 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5754 return WERR_BADFID;
5756 Printer->page_started = false;
5757 print_job_endpage(p->msg_ctx, snum, Printer->jobid);
5759 return WERR_OK;
5762 /****************************************************************
5763 _spoolss_StartDocPrinter
5764 ****************************************************************/
5766 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5767 struct spoolss_StartDocPrinter *r)
5769 struct spoolss_DocumentInfo1 *info_1;
5770 int snum;
5771 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5772 WERROR werr;
5773 char *rhost;
5774 int rc;
5776 if (!Printer) {
5777 DEBUG(2,("_spoolss_StartDocPrinter: "
5778 "Invalid handle (%s:%u:%u)\n",
5779 OUR_HANDLE(r->in.handle)));
5780 return WERR_BADFID;
5783 if (Printer->jobid) {
5784 DEBUG(2, ("_spoolss_StartDocPrinter: "
5785 "StartDocPrinter called twice! "
5786 "(existing jobid = %d)\n", Printer->jobid));
5787 return WERR_INVALID_HANDLE;
5790 if (r->in.info_ctr->level != 1) {
5791 return WERR_UNKNOWN_LEVEL;
5794 info_1 = r->in.info_ctr->info.info1;
5797 * a nice thing with NT is it doesn't listen to what you tell it.
5798 * when asked to send _only_ RAW datas, it tries to send datas
5799 * in EMF format.
5801 * So I add checks like in NT Server ...
5804 if (info_1->datatype) {
5805 if (strcmp(info_1->datatype, "RAW") != 0) {
5806 *r->out.job_id = 0;
5807 return WERR_INVALID_DATATYPE;
5811 /* get the share number of the printer */
5812 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5813 return WERR_BADFID;
5816 rc = get_remote_hostname(p->remote_address,
5817 &rhost,
5818 p->mem_ctx);
5819 if (rc < 0) {
5820 return WERR_NOMEM;
5822 if (strequal(rhost,"UNKNOWN")) {
5823 rhost = tsocket_address_inet_addr_string(p->remote_address,
5824 p->mem_ctx);
5825 if (rhost == NULL) {
5826 return WERR_NOMEM;
5830 werr = print_job_start(p->session_info,
5831 p->msg_ctx,
5832 rhost,
5833 snum,
5834 info_1->document_name,
5835 info_1->output_file,
5836 Printer->devmode,
5837 &Printer->jobid);
5839 /* An error occured in print_job_start() so return an appropriate
5840 NT error code. */
5842 if (!W_ERROR_IS_OK(werr)) {
5843 return werr;
5846 Printer->document_started = true;
5847 *r->out.job_id = Printer->jobid;
5849 return WERR_OK;
5852 /****************************************************************
5853 _spoolss_EndDocPrinter
5854 ****************************************************************/
5856 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5857 struct spoolss_EndDocPrinter *r)
5859 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5860 NTSTATUS status;
5861 int snum;
5863 if (!Printer) {
5864 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5865 OUR_HANDLE(r->in.handle)));
5866 return WERR_BADFID;
5869 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5870 return WERR_BADFID;
5873 Printer->document_started = false;
5874 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5875 if (!NT_STATUS_IS_OK(status)) {
5876 DEBUG(2, ("_spoolss_EndDocPrinter: "
5877 "print_job_end failed [%s]\n",
5878 nt_errstr(status)));
5881 Printer->jobid = 0;
5882 return ntstatus_to_werror(status);
5885 /****************************************************************
5886 _spoolss_WritePrinter
5887 ****************************************************************/
5889 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5890 struct spoolss_WritePrinter *r)
5892 ssize_t buffer_written;
5893 int snum;
5894 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5896 if (!Printer) {
5897 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5898 OUR_HANDLE(r->in.handle)));
5899 *r->out.num_written = r->in._data_size;
5900 return WERR_BADFID;
5903 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5904 return WERR_BADFID;
5906 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5907 buffer_written = print_job_write(server_event_context(),p->msg_ctx,
5908 snum, Printer->jobid,
5909 (const char *)r->in.data.data,
5910 (size_t)r->in._data_size);
5911 if (buffer_written == (ssize_t)-1) {
5912 *r->out.num_written = 0;
5913 if (errno == ENOSPC)
5914 return WERR_NO_SPOOL_SPACE;
5915 else
5916 return WERR_ACCESS_DENIED;
5919 *r->out.num_written = r->in._data_size;
5921 return WERR_OK;
5924 /********************************************************************
5925 * api_spoolss_getprinter
5926 * called from the spoolss dispatcher
5928 ********************************************************************/
5930 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5931 struct pipes_struct *p)
5933 const struct auth_session_info *session_info = p->session_info;
5934 int snum;
5935 WERROR errcode = WERR_BADFUNC;
5936 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5938 if (!Printer) {
5939 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5940 OUR_HANDLE(handle)));
5941 return WERR_BADFID;
5944 if (!get_printer_snum(p, handle, &snum, NULL))
5945 return WERR_BADFID;
5947 switch (command) {
5948 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5949 errcode = print_queue_pause(session_info, p->msg_ctx, snum);
5950 break;
5951 case SPOOLSS_PRINTER_CONTROL_RESUME:
5952 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5953 errcode = print_queue_resume(session_info, p->msg_ctx, snum);
5954 break;
5955 case SPOOLSS_PRINTER_CONTROL_PURGE:
5956 errcode = print_queue_purge(session_info, p->msg_ctx, snum);
5957 break;
5958 default:
5959 return WERR_UNKNOWN_LEVEL;
5962 return errcode;
5966 /****************************************************************
5967 _spoolss_AbortPrinter
5968 * From MSDN: "Deletes printer's spool file if printer is configured
5969 * for spooling"
5970 ****************************************************************/
5972 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5973 struct spoolss_AbortPrinter *r)
5975 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5976 int snum;
5977 WERROR errcode = WERR_OK;
5979 if (!Printer) {
5980 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5981 OUR_HANDLE(r->in.handle)));
5982 return WERR_BADFID;
5985 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5986 return WERR_BADFID;
5988 if (!Printer->document_started) {
5989 return WERR_SPL_NO_STARTDOC;
5992 errcode = print_job_delete(p->session_info,
5993 p->msg_ctx,
5994 snum,
5995 Printer->jobid);
5997 return errcode;
6000 /********************************************************************
6001 * called by spoolss_api_setprinter
6002 * when updating a printer description
6003 ********************************************************************/
6005 static WERROR update_printer_sec(struct policy_handle *handle,
6006 struct pipes_struct *p,
6007 struct sec_desc_buf *secdesc_ctr)
6009 struct spoolss_security_descriptor *new_secdesc = NULL;
6010 struct spoolss_security_descriptor *old_secdesc = NULL;
6011 const char *printer;
6012 WERROR result;
6013 int snum;
6014 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6015 struct dcerpc_binding_handle *b;
6016 TALLOC_CTX *tmp_ctx = NULL;
6018 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
6019 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
6020 OUR_HANDLE(handle)));
6022 result = WERR_BADFID;
6023 goto done;
6026 if (secdesc_ctr == NULL) {
6027 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
6028 result = WERR_INVALID_PARAM;
6029 goto done;
6031 printer = lp_const_servicename(snum);
6033 /* Check the user has permissions to change the security
6034 descriptor. By experimentation with two NT machines, the user
6035 requires Full Access to the printer to change security
6036 information. */
6038 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
6039 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
6040 result = WERR_ACCESS_DENIED;
6041 goto done;
6044 tmp_ctx = talloc_new(p->mem_ctx);
6045 if (!tmp_ctx) {
6046 return WERR_NOMEM;
6049 result = winreg_printer_binding_handle(tmp_ctx,
6050 get_session_info_system(),
6051 p->msg_ctx,
6052 &b);
6053 if (!W_ERROR_IS_OK(result)) {
6054 goto done;
6057 /* NT seems to like setting the security descriptor even though
6058 nothing may have actually changed. */
6059 result = winreg_get_printer_secdesc(tmp_ctx, b,
6060 printer,
6061 &old_secdesc);
6062 if (!W_ERROR_IS_OK(result)) {
6063 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc_internal() failed\n"));
6064 result = WERR_BADFID;
6065 goto done;
6068 if (DEBUGLEVEL >= 10) {
6069 struct security_acl *the_acl;
6070 int i;
6072 the_acl = old_secdesc->dacl;
6073 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
6074 printer, the_acl->num_aces));
6076 for (i = 0; i < the_acl->num_aces; i++) {
6077 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6078 &the_acl->aces[i].trustee),
6079 the_acl->aces[i].access_mask));
6082 the_acl = secdesc_ctr->sd->dacl;
6084 if (the_acl) {
6085 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
6086 printer, the_acl->num_aces));
6088 for (i = 0; i < the_acl->num_aces; i++) {
6089 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6090 &the_acl->aces[i].trustee),
6091 the_acl->aces[i].access_mask));
6093 } else {
6094 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
6098 new_secdesc = sec_desc_merge(tmp_ctx, secdesc_ctr->sd, old_secdesc);
6099 if (new_secdesc == NULL) {
6100 result = WERR_NOMEM;
6101 goto done;
6104 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
6105 result = WERR_OK;
6106 goto done;
6109 result = winreg_set_printer_secdesc(tmp_ctx, b,
6110 printer,
6111 new_secdesc);
6113 done:
6114 talloc_free(tmp_ctx);
6115 return result;
6118 /********************************************************************
6119 Canonicalize printer info from a client
6120 ********************************************************************/
6122 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
6123 struct spoolss_SetPrinterInfo2 *info2,
6124 int snum)
6126 fstring printername;
6127 const char *p;
6129 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
6130 "portname=%s drivername=%s comment=%s location=%s\n",
6131 info2->servername, info2->printername, info2->sharename,
6132 info2->portname, info2->drivername, info2->comment,
6133 info2->location));
6135 /* we force some elements to "correct" values */
6136 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", lp_netbios_name());
6137 if (info2->servername == NULL) {
6138 return false;
6140 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
6141 if (info2->sharename == NULL) {
6142 return false;
6145 /* check to see if we allow printername != sharename */
6146 if (lp_force_printername(snum)) {
6147 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6148 lp_netbios_name(), info2->sharename);
6149 } else {
6150 /* make sure printername is in \\server\printername format */
6151 fstrcpy(printername, info2->printername);
6152 p = printername;
6153 if ( printername[0] == '\\' && printername[1] == '\\' ) {
6154 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
6155 p++;
6158 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6159 lp_netbios_name(), p);
6161 if (info2->printername == NULL) {
6162 return false;
6165 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
6166 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
6168 return true;
6171 /****************************************************************************
6172 ****************************************************************************/
6174 static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const char *portname, const char *uri)
6176 char *cmd = lp_addport_cmd(talloc_tos());
6177 char *command = NULL;
6178 int ret;
6179 bool is_print_op = false;
6181 if ( !*cmd ) {
6182 return WERR_ACCESS_DENIED;
6185 command = talloc_asprintf(ctx,
6186 "%s \"%s\" \"%s\"", cmd, portname, uri );
6187 if (!command) {
6188 return WERR_NOMEM;
6191 if ( token )
6192 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6194 DEBUG(10,("Running [%s]\n", command));
6196 /********* BEGIN SePrintOperatorPrivilege **********/
6198 if ( is_print_op )
6199 become_root();
6201 ret = smbrun(command, NULL);
6203 if ( is_print_op )
6204 unbecome_root();
6206 /********* END SePrintOperatorPrivilege **********/
6208 DEBUGADD(10,("returned [%d]\n", ret));
6210 TALLOC_FREE(command);
6212 if ( ret != 0 ) {
6213 return WERR_ACCESS_DENIED;
6216 return WERR_OK;
6219 /****************************************************************************
6220 ****************************************************************************/
6222 static bool spoolss_conn_snum_used(struct smbd_server_connection *sconn,
6223 int snum)
6226 * As we do not know if we are embedded in the file server process
6227 * or not, we have to pretend that all shares are in use.
6229 return true;
6232 static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
6233 struct spoolss_SetPrinterInfo2 *info2,
6234 const char *remote_machine,
6235 struct messaging_context *msg_ctx)
6237 char *cmd = lp_addprinter_cmd(talloc_tos());
6238 char **qlines;
6239 char *command = NULL;
6240 int numlines;
6241 int ret;
6242 int fd;
6243 bool is_print_op = false;
6245 if (!remote_machine) {
6246 return false;
6249 command = talloc_asprintf(ctx,
6250 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6251 cmd, info2->printername, info2->sharename,
6252 info2->portname, info2->drivername,
6253 info2->location, info2->comment, remote_machine);
6254 if (!command) {
6255 return false;
6258 if ( token )
6259 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6261 DEBUG(10,("Running [%s]\n", command));
6263 /********* BEGIN SePrintOperatorPrivilege **********/
6265 if ( is_print_op )
6266 become_root();
6268 if ( (ret = smbrun(command, &fd)) == 0 ) {
6269 /* Tell everyone we updated smb.conf. */
6270 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6273 if ( is_print_op )
6274 unbecome_root();
6276 /********* END SePrintOperatorPrivilege **********/
6278 DEBUGADD(10,("returned [%d]\n", ret));
6280 TALLOC_FREE(command);
6282 if ( ret != 0 ) {
6283 if (fd != -1)
6284 close(fd);
6285 return false;
6288 /* reload our services immediately */
6289 become_root();
6290 reload_services(NULL, spoolss_conn_snum_used, false);
6291 unbecome_root();
6293 numlines = 0;
6294 /* Get lines and convert them back to dos-codepage */
6295 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6296 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6297 close(fd);
6299 /* Set the portname to what the script says the portname should be. */
6300 /* but don't require anything to be return from the script exit a good error code */
6302 if (numlines) {
6303 /* Set the portname to what the script says the portname should be. */
6304 info2->portname = talloc_strdup(ctx, qlines[0]);
6305 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6308 TALLOC_FREE(qlines);
6309 return true;
6312 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
6313 const struct auth_session_info *session_info,
6314 struct messaging_context *msg_ctx,
6315 int snum,
6316 struct spoolss_SetPrinterInfo2 *printer,
6317 struct spoolss_PrinterInfo2 *old_printer)
6319 bool force_update = (old_printer == NULL);
6320 const char *dnsdomname;
6321 const char *longname;
6322 const char *uncname;
6323 const char *spooling;
6324 DATA_BLOB buffer;
6325 WERROR result = WERR_OK;
6326 struct dcerpc_binding_handle *b;
6327 TALLOC_CTX *tmp_ctx;
6328 bool ok;
6330 tmp_ctx = talloc_new(mem_ctx);
6331 if (!tmp_ctx) {
6332 return WERR_NOMEM;
6335 result = winreg_printer_binding_handle(tmp_ctx,
6336 session_info,
6337 msg_ctx,
6338 &b);
6339 if (!W_ERROR_IS_OK(result)) {
6340 goto done;
6343 if (printer->drivername != NULL &&
6344 (force_update ||
6345 !strequal(printer->drivername, old_printer->drivername))) {
6346 ok = push_reg_sz(tmp_ctx, &buffer, printer->drivername);
6347 if (!ok) {
6348 DEBUG(0, ("%s data corrupted\n", SPOOL_REG_DRIVERNAME));
6349 result = WERR_INVALID_DATA;
6350 goto done;
6352 result = winreg_set_printer_dataex(tmp_ctx, b,
6353 printer->sharename,
6354 SPOOL_DSSPOOLER_KEY,
6355 SPOOL_REG_DRIVERNAME,
6356 REG_SZ,
6357 buffer.data,
6358 buffer.length);
6359 if (!W_ERROR_IS_OK(result)) {
6360 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DRIVERNAME));
6361 goto done;
6364 if (!force_update) {
6365 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6366 printer->drivername));
6368 notify_printer_driver(server_event_context(), msg_ctx,
6369 snum, printer->drivername ?
6370 printer->drivername : "");
6374 if (printer->comment != NULL &&
6375 (force_update ||
6376 !strequal(printer->comment, old_printer->comment))) {
6377 ok = push_reg_sz(tmp_ctx, &buffer, printer->comment);
6378 if (!ok) {
6379 DEBUG(0, ("comment data corrupted\n"));
6380 result = WERR_INVALID_DATA;
6381 goto done;
6383 result = winreg_set_printer_dataex(tmp_ctx, b,
6384 printer->sharename,
6385 SPOOL_DSSPOOLER_KEY,
6386 SPOOL_REG_DESCRIPTION,
6387 REG_SZ,
6388 buffer.data,
6389 buffer.length);
6390 if (!W_ERROR_IS_OK(result)) {
6391 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DESCRIPTION));
6392 goto done;
6395 if (!force_update) {
6396 notify_printer_comment(server_event_context(), msg_ctx,
6397 snum, printer->comment ?
6398 printer->comment : "");
6402 if (printer->sharename != NULL &&
6403 (force_update ||
6404 !strequal(printer->sharename, old_printer->sharename))) {
6405 ok = push_reg_sz(tmp_ctx, &buffer, printer->sharename);
6406 if (!ok) {
6407 DEBUG(0, ("sharename data corrupted\n"));
6408 result = WERR_INVALID_DATA;
6409 goto done;
6411 result = winreg_set_printer_dataex(tmp_ctx, b,
6412 printer->sharename,
6413 SPOOL_DSSPOOLER_KEY,
6414 SPOOL_REG_PRINTSHARENAME,
6415 REG_SZ,
6416 buffer.data,
6417 buffer.length);
6418 if (!W_ERROR_IS_OK(result)) {
6419 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME));
6420 goto done;
6423 if (!force_update) {
6424 notify_printer_sharename(server_event_context(),
6425 msg_ctx,
6426 snum, printer->sharename ?
6427 printer->sharename : "");
6431 if (printer->printername != NULL &&
6432 (force_update ||
6433 !strequal(printer->printername, old_printer->printername))) {
6434 const char *p;
6436 p = strrchr(printer->printername, '\\' );
6437 if (p != NULL) {
6438 p++;
6439 } else {
6440 p = printer->printername;
6443 ok = push_reg_sz(tmp_ctx, &buffer, p);
6444 if (!ok) {
6445 DEBUG(0, ("printername data corrupted\n"));
6446 result = WERR_INVALID_DATA;
6447 goto done;
6449 result = winreg_set_printer_dataex(tmp_ctx, b,
6450 printer->sharename,
6451 SPOOL_DSSPOOLER_KEY,
6452 SPOOL_REG_PRINTERNAME,
6453 REG_SZ,
6454 buffer.data,
6455 buffer.length);
6456 if (!W_ERROR_IS_OK(result)) {
6457 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME));
6458 goto done;
6461 if (!force_update) {
6462 notify_printer_printername(server_event_context(),
6463 msg_ctx, snum, p ? p : "");
6467 if (printer->portname != NULL &&
6468 (force_update ||
6469 !strequal(printer->portname, old_printer->portname))) {
6470 ok = push_reg_sz(tmp_ctx, &buffer, printer->portname);
6471 if (!ok) {
6472 DEBUG(0, ("portname data corrupted\n"));
6473 result = WERR_INVALID_DATA;
6474 goto done;
6476 result = winreg_set_printer_dataex(tmp_ctx, b,
6477 printer->sharename,
6478 SPOOL_DSSPOOLER_KEY,
6479 SPOOL_REG_PORTNAME,
6480 REG_SZ,
6481 buffer.data,
6482 buffer.length);
6483 if (!W_ERROR_IS_OK(result)) {
6484 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PORTNAME));
6485 goto done;
6488 if (!force_update) {
6489 notify_printer_port(server_event_context(),
6490 msg_ctx, snum, printer->portname ?
6491 printer->portname : "");
6495 if (printer->location != NULL &&
6496 (force_update ||
6497 !strequal(printer->location, old_printer->location))) {
6498 ok = push_reg_sz(tmp_ctx, &buffer, printer->location);
6499 if (!ok) {
6500 DEBUG(0, ("location data corrupted\n"));
6501 result = WERR_INVALID_DATA;
6502 goto done;
6504 result = winreg_set_printer_dataex(tmp_ctx, b,
6505 printer->sharename,
6506 SPOOL_DSSPOOLER_KEY,
6507 SPOOL_REG_LOCATION,
6508 REG_SZ,
6509 buffer.data,
6510 buffer.length);
6511 if (!W_ERROR_IS_OK(result)) {
6512 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_LOCATION));
6513 goto done;
6516 if (!force_update) {
6517 notify_printer_location(server_event_context(),
6518 msg_ctx, snum,
6519 printer->location ?
6520 printer->location : "");
6524 if (printer->sepfile != NULL &&
6525 (force_update ||
6526 !strequal(printer->sepfile, old_printer->sepfile))) {
6527 ok = push_reg_sz(tmp_ctx, &buffer, printer->sepfile);
6528 if (!ok) {
6529 DEBUG(0, ("sepfile data corrupted\n"));
6530 result = WERR_INVALID_DATA;
6531 goto done;
6533 result = winreg_set_printer_dataex(tmp_ctx, b,
6534 printer->sharename,
6535 SPOOL_DSSPOOLER_KEY,
6536 SPOOL_REG_PRINTSEPARATORFILE,
6537 REG_SZ,
6538 buffer.data,
6539 buffer.length);
6540 if (!W_ERROR_IS_OK(result)) {
6541 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSEPARATORFILE));
6542 goto done;
6545 if (!force_update) {
6546 notify_printer_sepfile(server_event_context(),
6547 msg_ctx, snum,
6548 printer->sepfile ?
6549 printer->sepfile : "");
6553 if (printer->starttime != 0 &&
6554 (force_update ||
6555 printer->starttime != old_printer->starttime)) {
6556 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6557 SIVAL(buffer.data, 0, printer->starttime);
6558 result = winreg_set_printer_dataex(tmp_ctx, b,
6559 printer->sharename,
6560 SPOOL_DSSPOOLER_KEY,
6561 SPOOL_REG_PRINTSTARTTIME,
6562 REG_DWORD,
6563 buffer.data,
6564 buffer.length);
6565 if (!W_ERROR_IS_OK(result)) {
6566 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSTARTTIME));
6567 goto done;
6571 if (printer->untiltime != 0 &&
6572 (force_update ||
6573 printer->untiltime != old_printer->untiltime)) {
6574 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6575 SIVAL(buffer.data, 0, printer->untiltime);
6576 result = winreg_set_printer_dataex(tmp_ctx, b,
6577 printer->sharename,
6578 SPOOL_DSSPOOLER_KEY,
6579 SPOOL_REG_PRINTENDTIME,
6580 REG_DWORD,
6581 buffer.data,
6582 buffer.length);
6583 if (!W_ERROR_IS_OK(result)) {
6584 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME));
6585 goto done;
6589 if (force_update || printer->priority != old_printer->priority) {
6590 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6591 SIVAL(buffer.data, 0, printer->priority);
6592 result = winreg_set_printer_dataex(tmp_ctx, b,
6593 printer->sharename,
6594 SPOOL_DSSPOOLER_KEY,
6595 SPOOL_REG_PRIORITY,
6596 REG_DWORD,
6597 buffer.data,
6598 buffer.length);
6599 if (!W_ERROR_IS_OK(result)) {
6600 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME));
6601 goto done;
6605 if (force_update || printer->attributes != old_printer->attributes) {
6606 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6607 SIVAL(buffer.data, 0, (printer->attributes &
6608 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
6609 result = winreg_set_printer_dataex(tmp_ctx, b,
6610 printer->sharename,
6611 SPOOL_DSSPOOLER_KEY,
6612 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
6613 REG_DWORD,
6614 buffer.data,
6615 buffer.length);
6616 if (!W_ERROR_IS_OK(result)) {
6617 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME));
6618 goto done;
6621 switch (printer->attributes & 0x3) {
6622 case 0:
6623 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
6624 break;
6625 case 1:
6626 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
6627 break;
6628 case 2:
6629 spooling = SPOOL_REGVAL_PRINTDIRECT;
6630 break;
6631 default:
6632 spooling = "unknown";
6634 ok = push_reg_sz(tmp_ctx, &buffer, spooling);
6635 if (!ok) {
6636 DEBUG(0, ("printSpooling data corrupted\n"));
6637 result = WERR_INVALID_DATA;
6638 goto done;
6640 winreg_set_printer_dataex(tmp_ctx, b,
6641 printer->sharename,
6642 SPOOL_DSSPOOLER_KEY,
6643 SPOOL_REG_PRINTSPOOLING,
6644 REG_SZ,
6645 buffer.data,
6646 buffer.length);
6649 ok = push_reg_sz(tmp_ctx, &buffer, lp_netbios_name());
6650 if (!ok) {
6651 DEBUG(0, ("shortServerName data corrupted\n"));
6652 result = WERR_INVALID_DATA;
6653 goto done;
6655 result = winreg_set_printer_dataex(tmp_ctx, b,
6656 printer->sharename,
6657 SPOOL_DSSPOOLER_KEY,
6658 SPOOL_REG_SHORTSERVERNAME,
6659 REG_SZ,
6660 buffer.data,
6661 buffer.length);
6662 if (!W_ERROR_IS_OK(result)) {
6663 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SHORTSERVERNAME));
6664 goto done;
6667 dnsdomname = get_mydnsfullname();
6668 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
6669 longname = talloc_strdup(tmp_ctx, dnsdomname);
6670 } else {
6671 longname = talloc_strdup(tmp_ctx, lp_netbios_name());
6673 if (longname == NULL) {
6674 result = WERR_NOMEM;
6675 goto done;
6678 ok = push_reg_sz(tmp_ctx, &buffer, longname);
6679 if (!ok) {
6680 DEBUG(0, ("longname data corrupted\n"));
6681 result = WERR_INVALID_DATA;
6682 goto done;
6684 result = winreg_set_printer_dataex(tmp_ctx, b,
6685 printer->sharename,
6686 SPOOL_DSSPOOLER_KEY,
6687 SPOOL_REG_SERVERNAME,
6688 REG_SZ,
6689 buffer.data,
6690 buffer.length);
6691 if (!W_ERROR_IS_OK(result)) {
6692 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SERVERNAME));
6693 goto done;
6696 uncname = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
6697 lp_netbios_name(), printer->sharename);
6698 ok = push_reg_sz(tmp_ctx, &buffer, uncname);
6699 if (!ok) {
6700 DEBUG(0, ("uncName data corrupted\n"));
6701 result = WERR_INVALID_DATA;
6702 goto done;
6704 result = winreg_set_printer_dataex(tmp_ctx, b,
6705 printer->sharename,
6706 SPOOL_DSSPOOLER_KEY,
6707 SPOOL_REG_UNCNAME,
6708 REG_SZ,
6709 buffer.data,
6710 buffer.length);
6711 if (!W_ERROR_IS_OK(result)) {
6712 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_UNCNAME));
6713 goto done;
6716 done:
6717 talloc_free(tmp_ctx);
6718 return result;
6721 /********************************************************************
6722 * Called by spoolss_api_setprinter
6723 * when updating a printer description.
6724 ********************************************************************/
6726 static WERROR update_printer(struct pipes_struct *p,
6727 struct policy_handle *handle,
6728 struct spoolss_SetPrinterInfoCtr *info_ctr,
6729 struct spoolss_DeviceMode *devmode)
6731 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6732 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6733 struct spoolss_PrinterInfo2 *old_printer;
6734 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6735 int snum;
6736 WERROR result = WERR_OK;
6737 TALLOC_CTX *tmp_ctx;
6738 struct dcerpc_binding_handle *b;
6740 DEBUG(8,("update_printer\n"));
6742 tmp_ctx = talloc_new(p->mem_ctx);
6743 if (tmp_ctx == NULL) {
6744 return WERR_NOMEM;
6747 if (!Printer) {
6748 result = WERR_BADFID;
6749 goto done;
6752 if (!get_printer_snum(p, handle, &snum, NULL)) {
6753 result = WERR_BADFID;
6754 goto done;
6757 result = winreg_printer_binding_handle(tmp_ctx,
6758 get_session_info_system(),
6759 p->msg_ctx,
6760 &b);
6761 if (!W_ERROR_IS_OK(result)) {
6762 goto done;
6765 result = winreg_get_printer(tmp_ctx, b,
6766 lp_const_servicename(snum),
6767 &old_printer);
6768 if (!W_ERROR_IS_OK(result)) {
6769 result = WERR_BADFID;
6770 goto done;
6773 /* Do sanity check on the requested changes for Samba */
6774 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6775 result = WERR_INVALID_PARAM;
6776 goto done;
6779 /* FIXME!!! If the driver has changed we really should verify that
6780 it is installed before doing much else --jerry */
6782 /* Check calling user has permission to update printer description */
6783 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6784 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6785 result = WERR_ACCESS_DENIED;
6786 goto done;
6789 /* Call addprinter hook */
6790 /* Check changes to see if this is really needed */
6792 if (*lp_addprinter_cmd(talloc_tos()) &&
6793 (!strequal(printer->drivername, old_printer->drivername) ||
6794 !strequal(printer->comment, old_printer->comment) ||
6795 !strequal(printer->portname, old_printer->portname) ||
6796 !strequal(printer->location, old_printer->location)) )
6798 char *raddr;
6800 raddr = tsocket_address_inet_addr_string(p->remote_address,
6801 p->mem_ctx);
6802 if (raddr == NULL) {
6803 return WERR_NOMEM;
6806 /* add_printer_hook() will call reload_services() */
6807 if (!add_printer_hook(tmp_ctx, p->session_info->security_token,
6808 printer, raddr,
6809 p->msg_ctx)) {
6810 result = WERR_ACCESS_DENIED;
6811 goto done;
6815 result = update_dsspooler(tmp_ctx,
6816 get_session_info_system(),
6817 p->msg_ctx,
6818 snum,
6819 printer,
6820 old_printer);
6821 if (!W_ERROR_IS_OK(result)) {
6822 goto done;
6825 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6827 if (devmode == NULL) {
6828 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6830 result = winreg_update_printer(tmp_ctx, b,
6831 printer->sharename,
6832 printer_mask,
6833 printer,
6834 devmode,
6835 NULL);
6837 done:
6838 talloc_free(tmp_ctx);
6840 return result;
6843 /****************************************************************************
6844 ****************************************************************************/
6845 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6846 struct policy_handle *handle,
6847 struct spoolss_SetPrinterInfo7 *info7)
6849 #ifdef HAVE_ADS
6850 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6851 WERROR result;
6852 int snum;
6853 struct printer_handle *Printer;
6855 if ( lp_security() != SEC_ADS ) {
6856 return WERR_UNKNOWN_LEVEL;
6859 Printer = find_printer_index_by_hnd(p, handle);
6861 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6863 if (!Printer)
6864 return WERR_BADFID;
6866 if (!get_printer_snum(p, handle, &snum, NULL))
6867 return WERR_BADFID;
6869 result = winreg_get_printer_internal(p->mem_ctx,
6870 get_session_info_system(),
6871 p->msg_ctx,
6872 lp_servicename(talloc_tos(), snum),
6873 &pinfo2);
6874 if (!W_ERROR_IS_OK(result)) {
6875 return WERR_BADFID;
6878 nt_printer_publish(pinfo2,
6879 get_session_info_system(),
6880 p->msg_ctx,
6881 pinfo2,
6882 info7->action);
6884 TALLOC_FREE(pinfo2);
6885 return WERR_OK;
6886 #else
6887 return WERR_UNKNOWN_LEVEL;
6888 #endif
6891 /********************************************************************
6892 ********************************************************************/
6894 static WERROR update_printer_devmode(struct pipes_struct *p,
6895 struct policy_handle *handle,
6896 struct spoolss_DeviceMode *devmode)
6898 int snum;
6899 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6900 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6902 DEBUG(8,("update_printer_devmode\n"));
6904 if (!Printer) {
6905 return WERR_BADFID;
6908 if (!get_printer_snum(p, handle, &snum, NULL)) {
6909 return WERR_BADFID;
6912 /* Check calling user has permission to update printer description */
6913 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6914 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6915 return WERR_ACCESS_DENIED;
6918 return winreg_update_printer_internal(p->mem_ctx,
6919 get_session_info_system(),
6920 p->msg_ctx,
6921 lp_const_servicename(snum),
6922 info2_mask,
6923 NULL,
6924 devmode,
6925 NULL);
6929 /****************************************************************
6930 _spoolss_SetPrinter
6931 ****************************************************************/
6933 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6934 struct spoolss_SetPrinter *r)
6936 WERROR result;
6938 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6940 if (!Printer) {
6941 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6942 OUR_HANDLE(r->in.handle)));
6943 return WERR_BADFID;
6946 /* check the level */
6947 switch (r->in.info_ctr->level) {
6948 case 0:
6949 return control_printer(r->in.handle, r->in.command, p);
6950 case 2:
6951 result = update_printer(p, r->in.handle,
6952 r->in.info_ctr,
6953 r->in.devmode_ctr->devmode);
6954 if (!W_ERROR_IS_OK(result))
6955 return result;
6956 if (r->in.secdesc_ctr->sd)
6957 result = update_printer_sec(r->in.handle, p,
6958 r->in.secdesc_ctr);
6959 return result;
6960 case 3:
6961 return update_printer_sec(r->in.handle, p,
6962 r->in.secdesc_ctr);
6963 case 7:
6964 return publish_or_unpublish_printer(p, r->in.handle,
6965 r->in.info_ctr->info.info7);
6966 case 8:
6967 return update_printer_devmode(p, r->in.handle,
6968 r->in.devmode_ctr->devmode);
6969 default:
6970 return WERR_UNKNOWN_LEVEL;
6974 /****************************************************************
6975 _spoolss_FindClosePrinterNotify
6976 ****************************************************************/
6978 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6979 struct spoolss_FindClosePrinterNotify *r)
6981 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6983 if (!Printer) {
6984 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6985 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6986 return WERR_BADFID;
6989 if (Printer->notify.cli_chan != NULL &&
6990 Printer->notify.cli_chan->active_connections > 0) {
6991 int snum = -1;
6993 if (Printer->printer_type == SPLHND_PRINTER) {
6994 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6995 return WERR_BADFID;
6999 srv_spoolss_replycloseprinter(snum, Printer);
7002 Printer->notify.flags=0;
7003 Printer->notify.options=0;
7004 Printer->notify.localmachine[0]='\0';
7005 Printer->notify.printerlocal=0;
7006 TALLOC_FREE(Printer->notify.option);
7008 return WERR_OK;
7011 /****************************************************************
7012 _spoolss_AddJob
7013 ****************************************************************/
7015 WERROR _spoolss_AddJob(struct pipes_struct *p,
7016 struct spoolss_AddJob *r)
7018 if (!r->in.buffer && (r->in.offered != 0)) {
7019 return WERR_INVALID_PARAM;
7022 /* this is what a NT server returns for AddJob. AddJob must fail on
7023 * non-local printers */
7025 if (r->in.level != 1) {
7026 return WERR_UNKNOWN_LEVEL;
7029 return WERR_INVALID_PARAM;
7032 /****************************************************************************
7033 fill_job_info1
7034 ****************************************************************************/
7036 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
7037 struct spoolss_JobInfo1 *r,
7038 const print_queue_struct *queue,
7039 int position, int snum,
7040 struct spoolss_PrinterInfo2 *pinfo2)
7042 struct tm *t;
7044 t = gmtime(&queue->time);
7046 r->job_id = queue->sysjob;
7048 r->printer_name = lp_servicename(mem_ctx, snum);
7049 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
7050 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
7051 W_ERROR_HAVE_NO_MEMORY(r->server_name);
7052 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
7053 W_ERROR_HAVE_NO_MEMORY(r->user_name);
7054 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
7055 W_ERROR_HAVE_NO_MEMORY(r->document_name);
7056 r->data_type = talloc_strdup(mem_ctx, "RAW");
7057 W_ERROR_HAVE_NO_MEMORY(r->data_type);
7058 r->text_status = talloc_strdup(mem_ctx, "");
7059 W_ERROR_HAVE_NO_MEMORY(r->text_status);
7061 r->status = nt_printj_status(queue->status);
7062 r->priority = queue->priority;
7063 r->position = position;
7064 r->total_pages = queue->page_count;
7065 r->pages_printed = 0; /* ??? */
7067 init_systemtime(&r->submitted, t);
7069 return WERR_OK;
7072 /****************************************************************************
7073 fill_job_info2
7074 ****************************************************************************/
7076 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
7077 struct spoolss_JobInfo2 *r,
7078 const print_queue_struct *queue,
7079 int position, int snum,
7080 struct spoolss_PrinterInfo2 *pinfo2,
7081 struct spoolss_DeviceMode *devmode)
7083 struct tm *t;
7085 t = gmtime(&queue->time);
7087 r->job_id = queue->sysjob;
7089 r->printer_name = lp_servicename(mem_ctx, snum);
7090 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
7091 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
7092 W_ERROR_HAVE_NO_MEMORY(r->server_name);
7093 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
7094 W_ERROR_HAVE_NO_MEMORY(r->user_name);
7095 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
7096 W_ERROR_HAVE_NO_MEMORY(r->document_name);
7097 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
7098 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
7099 r->data_type = talloc_strdup(mem_ctx, "RAW");
7100 W_ERROR_HAVE_NO_MEMORY(r->data_type);
7101 r->print_processor = talloc_strdup(mem_ctx, "winprint");
7102 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
7103 r->parameters = talloc_strdup(mem_ctx, "");
7104 W_ERROR_HAVE_NO_MEMORY(r->parameters);
7105 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
7106 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
7108 r->devmode = devmode;
7110 r->text_status = talloc_strdup(mem_ctx, "");
7111 W_ERROR_HAVE_NO_MEMORY(r->text_status);
7113 r->secdesc = NULL;
7115 r->status = nt_printj_status(queue->status);
7116 r->priority = queue->priority;
7117 r->position = position;
7118 r->start_time = 0;
7119 r->until_time = 0;
7120 r->total_pages = queue->page_count;
7121 r->size = queue->size;
7122 init_systemtime(&r->submitted, t);
7123 r->time = 0;
7124 r->pages_printed = 0; /* ??? */
7126 return WERR_OK;
7129 /****************************************************************************
7130 fill_job_info3
7131 ****************************************************************************/
7133 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
7134 struct spoolss_JobInfo3 *r,
7135 const print_queue_struct *queue,
7136 const print_queue_struct *next_queue,
7137 int position, int snum,
7138 struct spoolss_PrinterInfo2 *pinfo2)
7140 r->job_id = queue->sysjob;
7141 r->next_job_id = 0;
7142 if (next_queue) {
7143 r->next_job_id = next_queue->sysjob;
7145 r->reserved = 0;
7147 return WERR_OK;
7150 /****************************************************************************
7151 Enumjobs at level 1.
7152 ****************************************************************************/
7154 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
7155 const print_queue_struct *queue,
7156 uint32_t num_queues, int snum,
7157 struct spoolss_PrinterInfo2 *pinfo2,
7158 union spoolss_JobInfo **info_p,
7159 uint32_t *count)
7161 union spoolss_JobInfo *info;
7162 int i;
7163 WERROR result = WERR_OK;
7165 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7166 W_ERROR_HAVE_NO_MEMORY(info);
7168 *count = num_queues;
7170 for (i=0; i<*count; i++) {
7171 result = fill_job_info1(info,
7172 &info[i].info1,
7173 &queue[i],
7175 snum,
7176 pinfo2);
7177 if (!W_ERROR_IS_OK(result)) {
7178 goto out;
7182 out:
7183 if (!W_ERROR_IS_OK(result)) {
7184 TALLOC_FREE(info);
7185 *count = 0;
7186 return result;
7189 *info_p = info;
7191 return WERR_OK;
7194 /****************************************************************************
7195 Enumjobs at level 2.
7196 ****************************************************************************/
7198 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
7199 const print_queue_struct *queue,
7200 uint32_t num_queues, int snum,
7201 struct spoolss_PrinterInfo2 *pinfo2,
7202 union spoolss_JobInfo **info_p,
7203 uint32_t *count)
7205 union spoolss_JobInfo *info;
7206 int i;
7207 WERROR result = WERR_OK;
7209 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7210 W_ERROR_HAVE_NO_MEMORY(info);
7212 *count = num_queues;
7214 for (i=0; i<*count; i++) {
7215 struct spoolss_DeviceMode *devmode;
7217 result = spoolss_create_default_devmode(info,
7218 pinfo2->printername,
7219 &devmode);
7220 if (!W_ERROR_IS_OK(result)) {
7221 DEBUG(3, ("Can't proceed w/o a devmode!"));
7222 goto out;
7225 result = fill_job_info2(info,
7226 &info[i].info2,
7227 &queue[i],
7229 snum,
7230 pinfo2,
7231 devmode);
7232 if (!W_ERROR_IS_OK(result)) {
7233 goto out;
7237 out:
7238 if (!W_ERROR_IS_OK(result)) {
7239 TALLOC_FREE(info);
7240 *count = 0;
7241 return result;
7244 *info_p = info;
7246 return WERR_OK;
7249 /****************************************************************************
7250 Enumjobs at level 3.
7251 ****************************************************************************/
7253 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
7254 const print_queue_struct *queue,
7255 uint32_t num_queues, int snum,
7256 struct spoolss_PrinterInfo2 *pinfo2,
7257 union spoolss_JobInfo **info_p,
7258 uint32_t *count)
7260 union spoolss_JobInfo *info;
7261 int i;
7262 WERROR result = WERR_OK;
7264 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7265 W_ERROR_HAVE_NO_MEMORY(info);
7267 *count = num_queues;
7269 for (i=0; i<*count; i++) {
7270 const print_queue_struct *next_queue = NULL;
7272 if (i+1 < *count) {
7273 next_queue = &queue[i+1];
7276 result = fill_job_info3(info,
7277 &info[i].info3,
7278 &queue[i],
7279 next_queue,
7281 snum,
7282 pinfo2);
7283 if (!W_ERROR_IS_OK(result)) {
7284 goto out;
7288 out:
7289 if (!W_ERROR_IS_OK(result)) {
7290 TALLOC_FREE(info);
7291 *count = 0;
7292 return result;
7295 *info_p = info;
7297 return WERR_OK;
7300 /****************************************************************
7301 _spoolss_EnumJobs
7302 ****************************************************************/
7304 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
7305 struct spoolss_EnumJobs *r)
7307 WERROR result;
7308 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
7309 int snum;
7310 print_status_struct prt_status;
7311 print_queue_struct *queue = NULL;
7312 uint32_t count;
7314 /* that's an [in out] buffer */
7316 if (!r->in.buffer && (r->in.offered != 0)) {
7317 return WERR_INVALID_PARAM;
7320 DEBUG(4,("_spoolss_EnumJobs\n"));
7322 *r->out.needed = 0;
7323 *r->out.count = 0;
7324 *r->out.info = NULL;
7326 /* lookup the printer snum and tdb entry */
7328 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7329 return WERR_BADFID;
7332 result = winreg_get_printer_internal(p->mem_ctx,
7333 get_session_info_system(),
7334 p->msg_ctx,
7335 lp_const_servicename(snum),
7336 &pinfo2);
7337 if (!W_ERROR_IS_OK(result)) {
7338 return result;
7341 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
7342 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7343 count, prt_status.status, prt_status.message));
7345 if (count == 0) {
7346 SAFE_FREE(queue);
7347 TALLOC_FREE(pinfo2);
7348 return WERR_OK;
7351 switch (r->in.level) {
7352 case 1:
7353 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
7354 pinfo2, r->out.info, r->out.count);
7355 break;
7356 case 2:
7357 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
7358 pinfo2, r->out.info, r->out.count);
7359 break;
7360 case 3:
7361 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
7362 pinfo2, r->out.info, r->out.count);
7363 break;
7364 default:
7365 result = WERR_UNKNOWN_LEVEL;
7366 break;
7369 SAFE_FREE(queue);
7370 TALLOC_FREE(pinfo2);
7372 if (!W_ERROR_IS_OK(result)) {
7373 return result;
7376 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7377 spoolss_EnumJobs,
7378 *r->out.info, r->in.level,
7379 *r->out.count);
7380 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7381 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7383 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7386 /****************************************************************
7387 _spoolss_ScheduleJob
7388 ****************************************************************/
7390 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
7391 struct spoolss_ScheduleJob *r)
7393 return WERR_OK;
7396 /****************************************************************
7397 ****************************************************************/
7399 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
7400 struct messaging_context *msg_ctx,
7401 const char *printer_name,
7402 uint32_t job_id,
7403 struct spoolss_SetJobInfo1 *r)
7405 char *old_doc_name;
7407 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
7408 return WERR_BADFID;
7411 if (strequal(old_doc_name, r->document_name)) {
7412 return WERR_OK;
7415 if (!print_job_set_name(server_event_context(), msg_ctx,
7416 printer_name, job_id, r->document_name)) {
7417 return WERR_BADFID;
7420 return WERR_OK;
7423 /****************************************************************
7424 _spoolss_SetJob
7425 ****************************************************************/
7427 WERROR _spoolss_SetJob(struct pipes_struct *p,
7428 struct spoolss_SetJob *r)
7430 const struct auth_session_info *session_info = p->session_info;
7431 int snum;
7432 WERROR errcode = WERR_BADFUNC;
7434 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7435 return WERR_BADFID;
7438 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
7439 return WERR_INVALID_PRINTER_NAME;
7442 switch (r->in.command) {
7443 case SPOOLSS_JOB_CONTROL_CANCEL:
7444 case SPOOLSS_JOB_CONTROL_DELETE:
7445 errcode = print_job_delete(session_info, p->msg_ctx,
7446 snum, r->in.job_id);
7447 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
7448 errcode = WERR_OK;
7450 break;
7451 case SPOOLSS_JOB_CONTROL_PAUSE:
7452 errcode = print_job_pause(session_info, p->msg_ctx,
7453 snum, r->in.job_id);
7454 break;
7455 case SPOOLSS_JOB_CONTROL_RESTART:
7456 case SPOOLSS_JOB_CONTROL_RESUME:
7457 errcode = print_job_resume(session_info, p->msg_ctx,
7458 snum, r->in.job_id);
7459 break;
7460 case 0:
7461 errcode = WERR_OK;
7462 break;
7463 default:
7464 return WERR_UNKNOWN_LEVEL;
7467 if (!W_ERROR_IS_OK(errcode)) {
7468 return errcode;
7471 if (r->in.ctr == NULL) {
7472 return errcode;
7475 switch (r->in.ctr->level) {
7476 case 1:
7477 errcode = spoolss_setjob_1(p->mem_ctx, p->msg_ctx,
7478 lp_const_servicename(snum),
7479 r->in.job_id,
7480 r->in.ctr->info.info1);
7481 break;
7482 case 2:
7483 case 3:
7484 case 4:
7485 default:
7486 return WERR_UNKNOWN_LEVEL;
7489 return errcode;
7492 /****************************************************************************
7493 Enumerates all printer drivers by level and architecture.
7494 ****************************************************************************/
7496 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
7497 const struct auth_session_info *session_info,
7498 struct messaging_context *msg_ctx,
7499 const char *servername,
7500 const char *architecture,
7501 uint32_t level,
7502 union spoolss_DriverInfo **info_p,
7503 uint32_t *count_p)
7505 int i;
7506 uint32_t version;
7507 struct spoolss_DriverInfo8 *driver;
7508 union spoolss_DriverInfo *info = NULL;
7509 uint32_t count = 0;
7510 WERROR result = WERR_OK;
7511 uint32_t num_drivers;
7512 const char **drivers;
7513 struct dcerpc_binding_handle *b;
7514 TALLOC_CTX *tmp_ctx = NULL;
7516 *count_p = 0;
7517 *info_p = NULL;
7519 tmp_ctx = talloc_new(mem_ctx);
7520 if (!tmp_ctx) {
7521 return WERR_NOMEM;
7524 result = winreg_printer_binding_handle(tmp_ctx,
7525 session_info,
7526 msg_ctx,
7527 &b);
7528 if (!W_ERROR_IS_OK(result)) {
7529 goto out;
7532 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7533 result = winreg_get_driver_list(tmp_ctx, b,
7534 architecture, version,
7535 &num_drivers, &drivers);
7536 if (!W_ERROR_IS_OK(result)) {
7537 goto out;
7539 DEBUG(4, ("we have:[%d] drivers in environment"
7540 " [%s] and version [%d]\n",
7541 num_drivers, architecture, version));
7543 if (num_drivers != 0) {
7544 info = talloc_realloc(tmp_ctx, info,
7545 union spoolss_DriverInfo,
7546 count + num_drivers);
7547 if (!info) {
7548 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7549 "failed to enlarge driver info buffer!\n"));
7550 result = WERR_NOMEM;
7551 goto out;
7555 for (i = 0; i < num_drivers; i++) {
7556 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
7558 result = winreg_get_driver(tmp_ctx, b,
7559 architecture, drivers[i],
7560 version, &driver);
7561 if (!W_ERROR_IS_OK(result)) {
7562 goto out;
7565 switch (level) {
7566 case 1:
7567 result = fill_printer_driver_info1(info, &info[count+i].info1,
7568 driver, servername);
7569 break;
7570 case 2:
7571 result = fill_printer_driver_info2(info, &info[count+i].info2,
7572 driver, servername);
7573 break;
7574 case 3:
7575 result = fill_printer_driver_info3(info, &info[count+i].info3,
7576 driver, servername);
7577 break;
7578 case 4:
7579 result = fill_printer_driver_info4(info, &info[count+i].info4,
7580 driver, servername);
7581 break;
7582 case 5:
7583 result = fill_printer_driver_info5(info, &info[count+i].info5,
7584 driver, servername);
7585 break;
7586 case 6:
7587 result = fill_printer_driver_info6(info, &info[count+i].info6,
7588 driver, servername);
7589 break;
7590 case 8:
7591 result = fill_printer_driver_info8(info, &info[count+i].info8,
7592 driver, servername);
7593 break;
7594 default:
7595 result = WERR_UNKNOWN_LEVEL;
7596 break;
7599 TALLOC_FREE(driver);
7601 if (!W_ERROR_IS_OK(result)) {
7602 goto out;
7606 count += num_drivers;
7607 TALLOC_FREE(drivers);
7610 out:
7611 if (W_ERROR_IS_OK(result)) {
7612 *info_p = talloc_move(mem_ctx, &info);
7613 *count_p = count;
7616 talloc_free(tmp_ctx);
7617 return result;
7620 /****************************************************************************
7621 Enumerates all printer drivers by level.
7622 ****************************************************************************/
7624 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
7625 const struct auth_session_info *session_info,
7626 struct messaging_context *msg_ctx,
7627 const char *servername,
7628 const char *architecture,
7629 uint32_t level,
7630 union spoolss_DriverInfo **info_p,
7631 uint32_t *count_p)
7633 uint32_t a,i;
7634 WERROR result = WERR_OK;
7636 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
7638 for (a=0; archi_table[a].long_archi != NULL; a++) {
7640 union spoolss_DriverInfo *info = NULL;
7641 uint32_t count = 0;
7643 result = enumprinterdrivers_level_by_architecture(mem_ctx,
7644 session_info,
7645 msg_ctx,
7646 servername,
7647 archi_table[a].long_archi,
7648 level,
7649 &info,
7650 &count);
7651 if (!W_ERROR_IS_OK(result)) {
7652 continue;
7655 for (i=0; i < count; i++) {
7656 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
7657 info[i], info_p, count_p);
7661 return result;
7664 return enumprinterdrivers_level_by_architecture(mem_ctx,
7665 session_info,
7666 msg_ctx,
7667 servername,
7668 architecture,
7669 level,
7670 info_p,
7671 count_p);
7674 /****************************************************************
7675 _spoolss_EnumPrinterDrivers
7676 ****************************************************************/
7678 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
7679 struct spoolss_EnumPrinterDrivers *r)
7681 const char *cservername;
7682 WERROR result;
7684 /* that's an [in out] buffer */
7686 if (!r->in.buffer && (r->in.offered != 0)) {
7687 return WERR_INVALID_PARAM;
7690 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7692 *r->out.needed = 0;
7693 *r->out.count = 0;
7694 *r->out.info = NULL;
7696 cservername = canon_servername(r->in.server);
7698 if (!is_myname_or_ipaddr(cservername)) {
7699 return WERR_UNKNOWN_PRINTER_DRIVER;
7702 result = enumprinterdrivers_level(p->mem_ctx,
7703 get_session_info_system(),
7704 p->msg_ctx,
7705 cservername,
7706 r->in.environment,
7707 r->in.level,
7708 r->out.info,
7709 r->out.count);
7710 if (!W_ERROR_IS_OK(result)) {
7711 return result;
7714 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7715 spoolss_EnumPrinterDrivers,
7716 *r->out.info, r->in.level,
7717 *r->out.count);
7718 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7719 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7721 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7724 /****************************************************************
7725 _spoolss_EnumForms
7726 ****************************************************************/
7728 WERROR _spoolss_EnumForms(struct pipes_struct *p,
7729 struct spoolss_EnumForms *r)
7731 WERROR result;
7733 *r->out.count = 0;
7734 *r->out.needed = 0;
7735 *r->out.info = NULL;
7737 /* that's an [in out] buffer */
7739 if (!r->in.buffer && (r->in.offered != 0) ) {
7740 return WERR_INVALID_PARAM;
7743 DEBUG(4,("_spoolss_EnumForms\n"));
7744 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7745 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7747 switch (r->in.level) {
7748 case 1:
7749 result = winreg_printer_enumforms1_internal(p->mem_ctx,
7750 get_session_info_system(),
7751 p->msg_ctx,
7752 r->out.count,
7753 r->out.info);
7754 break;
7755 default:
7756 result = WERR_UNKNOWN_LEVEL;
7757 break;
7760 if (!W_ERROR_IS_OK(result)) {
7761 return result;
7764 if (*r->out.count == 0) {
7765 return WERR_NO_MORE_ITEMS;
7768 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7769 spoolss_EnumForms,
7770 *r->out.info, r->in.level,
7771 *r->out.count);
7772 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7773 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7775 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7778 /****************************************************************
7779 _spoolss_GetForm
7780 ****************************************************************/
7782 WERROR _spoolss_GetForm(struct pipes_struct *p,
7783 struct spoolss_GetForm *r)
7785 WERROR result;
7787 /* that's an [in out] buffer */
7789 if (!r->in.buffer && (r->in.offered != 0)) {
7790 return WERR_INVALID_PARAM;
7793 DEBUG(4,("_spoolss_GetForm\n"));
7794 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7795 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7797 switch (r->in.level) {
7798 case 1:
7799 result = winreg_printer_getform1_internal(p->mem_ctx,
7800 get_session_info_system(),
7801 p->msg_ctx,
7802 r->in.form_name,
7803 &r->out.info->info1);
7804 break;
7805 default:
7806 result = WERR_UNKNOWN_LEVEL;
7807 break;
7810 if (!W_ERROR_IS_OK(result)) {
7811 TALLOC_FREE(r->out.info);
7812 return result;
7815 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7816 r->out.info, r->in.level);
7817 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7819 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7822 /****************************************************************************
7823 ****************************************************************************/
7825 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7826 struct spoolss_PortInfo1 *r,
7827 const char *name)
7829 r->port_name = talloc_strdup(mem_ctx, name);
7830 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7832 return WERR_OK;
7835 /****************************************************************************
7836 TODO: This probably needs distinguish between TCP/IP and Local ports
7837 somehow.
7838 ****************************************************************************/
7840 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7841 struct spoolss_PortInfo2 *r,
7842 const char *name)
7844 r->port_name = talloc_strdup(mem_ctx, name);
7845 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7847 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7848 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7850 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7851 W_ERROR_HAVE_NO_MEMORY(r->description);
7853 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7854 r->reserved = 0;
7856 return WERR_OK;
7860 /****************************************************************************
7861 wrapper around the enumer ports command
7862 ****************************************************************************/
7864 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7866 char *cmd = lp_enumports_cmd(talloc_tos());
7867 char **qlines = NULL;
7868 char *command = NULL;
7869 int numlines;
7870 int ret;
7871 int fd;
7873 *count = 0;
7874 *lines = NULL;
7876 /* if no hook then just fill in the default port */
7878 if ( !*cmd ) {
7879 if (!(qlines = talloc_array( NULL, char*, 2 ))) {
7880 return WERR_NOMEM;
7882 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7883 TALLOC_FREE(qlines);
7884 return WERR_NOMEM;
7886 qlines[1] = NULL;
7887 numlines = 1;
7889 else {
7890 /* we have a valid enumport command */
7892 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7893 if (!command) {
7894 return WERR_NOMEM;
7897 DEBUG(10,("Running [%s]\n", command));
7898 ret = smbrun(command, &fd);
7899 DEBUG(10,("Returned [%d]\n", ret));
7900 TALLOC_FREE(command);
7901 if (ret != 0) {
7902 if (fd != -1) {
7903 close(fd);
7905 return WERR_ACCESS_DENIED;
7908 numlines = 0;
7909 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7910 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7911 close(fd);
7914 *count = numlines;
7915 *lines = qlines;
7917 return WERR_OK;
7920 /****************************************************************************
7921 enumports level 1.
7922 ****************************************************************************/
7924 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7925 union spoolss_PortInfo **info_p,
7926 uint32_t *count)
7928 union spoolss_PortInfo *info = NULL;
7929 int i=0;
7930 WERROR result = WERR_OK;
7931 char **qlines = NULL;
7932 int numlines = 0;
7934 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7935 if (!W_ERROR_IS_OK(result)) {
7936 goto out;
7939 if (numlines) {
7940 info = talloc_array(mem_ctx, union spoolss_PortInfo, numlines);
7941 if (!info) {
7942 DEBUG(10,("Returning WERR_NOMEM\n"));
7943 result = WERR_NOMEM;
7944 goto out;
7947 for (i=0; i<numlines; i++) {
7948 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7949 result = fill_port_1(info, &info[i].info1, qlines[i]);
7950 if (!W_ERROR_IS_OK(result)) {
7951 goto out;
7955 TALLOC_FREE(qlines);
7957 out:
7958 if (!W_ERROR_IS_OK(result)) {
7959 TALLOC_FREE(info);
7960 TALLOC_FREE(qlines);
7961 *count = 0;
7962 *info_p = NULL;
7963 return result;
7966 *info_p = info;
7967 *count = numlines;
7969 return WERR_OK;
7972 /****************************************************************************
7973 enumports level 2.
7974 ****************************************************************************/
7976 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7977 union spoolss_PortInfo **info_p,
7978 uint32_t *count)
7980 union spoolss_PortInfo *info = NULL;
7981 int i=0;
7982 WERROR result = WERR_OK;
7983 char **qlines = NULL;
7984 int numlines = 0;
7986 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7987 if (!W_ERROR_IS_OK(result)) {
7988 goto out;
7991 if (numlines) {
7992 info = talloc_array(mem_ctx, union spoolss_PortInfo, numlines);
7993 if (!info) {
7994 DEBUG(10,("Returning WERR_NOMEM\n"));
7995 result = WERR_NOMEM;
7996 goto out;
7999 for (i=0; i<numlines; i++) {
8000 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
8001 result = fill_port_2(info, &info[i].info2, qlines[i]);
8002 if (!W_ERROR_IS_OK(result)) {
8003 goto out;
8007 TALLOC_FREE(qlines);
8009 out:
8010 if (!W_ERROR_IS_OK(result)) {
8011 TALLOC_FREE(info);
8012 TALLOC_FREE(qlines);
8013 *count = 0;
8014 *info_p = NULL;
8015 return result;
8018 *info_p = info;
8019 *count = numlines;
8021 return WERR_OK;
8024 /****************************************************************
8025 _spoolss_EnumPorts
8026 ****************************************************************/
8028 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
8029 struct spoolss_EnumPorts *r)
8031 WERROR result;
8033 /* that's an [in out] buffer */
8035 if (!r->in.buffer && (r->in.offered != 0)) {
8036 return WERR_INVALID_PARAM;
8039 DEBUG(4,("_spoolss_EnumPorts\n"));
8041 *r->out.count = 0;
8042 *r->out.needed = 0;
8043 *r->out.info = NULL;
8045 switch (r->in.level) {
8046 case 1:
8047 result = enumports_level_1(p->mem_ctx, r->out.info,
8048 r->out.count);
8049 break;
8050 case 2:
8051 result = enumports_level_2(p->mem_ctx, r->out.info,
8052 r->out.count);
8053 break;
8054 default:
8055 return WERR_UNKNOWN_LEVEL;
8058 if (!W_ERROR_IS_OK(result)) {
8059 return result;
8062 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8063 spoolss_EnumPorts,
8064 *r->out.info, r->in.level,
8065 *r->out.count);
8066 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8067 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8069 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8072 /****************************************************************************
8073 ****************************************************************************/
8075 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
8076 const char *server,
8077 struct spoolss_SetPrinterInfoCtr *info_ctr,
8078 struct spoolss_DeviceMode *devmode,
8079 struct security_descriptor *secdesc,
8080 struct spoolss_UserLevelCtr *user_ctr,
8081 struct policy_handle *handle)
8083 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
8084 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
8085 int snum;
8086 WERROR err = WERR_OK;
8088 /* samba does not have a concept of local, non-shared printers yet, so
8089 * make sure we always setup sharename - gd */
8090 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
8091 (info2->printername != NULL && info2->printername[0] != '\0')) {
8092 DEBUG(5, ("spoolss_addprinterex_level_2: "
8093 "no sharename has been set, setting printername %s as sharename\n",
8094 info2->printername));
8095 info2->sharename = info2->printername;
8098 /* check to see if the printer already exists */
8099 if ((snum = print_queue_snum(info2->sharename)) != -1) {
8100 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8101 info2->sharename));
8102 return WERR_PRINTER_ALREADY_EXISTS;
8105 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
8106 if ((snum = print_queue_snum(info2->printername)) != -1) {
8107 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8108 info2->printername));
8109 return WERR_PRINTER_ALREADY_EXISTS;
8113 /* validate printer info struct */
8114 if (!info2->printername || strlen(info2->printername) == 0) {
8115 return WERR_INVALID_PRINTER_NAME;
8117 if (!info2->portname || strlen(info2->portname) == 0) {
8118 return WERR_UNKNOWN_PORT;
8120 if (!info2->drivername || strlen(info2->drivername) == 0) {
8121 return WERR_UNKNOWN_PRINTER_DRIVER;
8123 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
8124 return WERR_UNKNOWN_PRINTPROCESSOR;
8127 /* FIXME!!! smbd should check to see if the driver is installed before
8128 trying to add a printer like this --jerry */
8130 if (*lp_addprinter_cmd(talloc_tos()) ) {
8131 char *raddr;
8133 raddr = tsocket_address_inet_addr_string(p->remote_address,
8134 p->mem_ctx);
8135 if (raddr == NULL) {
8136 return WERR_NOMEM;
8139 if ( !add_printer_hook(p->mem_ctx, p->session_info->security_token,
8140 info2, raddr,
8141 p->msg_ctx) ) {
8142 return WERR_ACCESS_DENIED;
8144 } else {
8145 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no "
8146 "smb.conf parameter \"addprinter command\" is defined. This "
8147 "parameter must exist for this call to succeed\n",
8148 info2->sharename ));
8151 if ((snum = print_queue_snum(info2->sharename)) == -1) {
8152 return WERR_ACCESS_DENIED;
8155 /* you must be a printer admin to add a new printer */
8156 if (!print_access_check(p->session_info,
8157 p->msg_ctx,
8158 snum,
8159 PRINTER_ACCESS_ADMINISTER)) {
8160 return WERR_ACCESS_DENIED;
8164 * Do sanity check on the requested changes for Samba.
8167 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
8168 return WERR_INVALID_PARAM;
8171 if (devmode == NULL) {
8172 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
8175 err = update_dsspooler(p->mem_ctx,
8176 get_session_info_system(),
8177 p->msg_ctx,
8179 info2,
8180 NULL);
8181 if (!W_ERROR_IS_OK(err)) {
8182 return err;
8185 err = winreg_update_printer_internal(p->mem_ctx,
8186 get_session_info_system(),
8187 p->msg_ctx,
8188 info2->sharename,
8189 info2_mask,
8190 info2,
8191 devmode,
8192 secdesc);
8193 if (!W_ERROR_IS_OK(err)) {
8194 return err;
8197 err = open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER);
8198 if (!W_ERROR_IS_OK(err)) {
8199 /* Handle open failed - remove addition. */
8200 ZERO_STRUCTP(handle);
8201 return err;
8204 return WERR_OK;
8207 /****************************************************************
8208 _spoolss_AddPrinterEx
8209 ****************************************************************/
8211 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
8212 struct spoolss_AddPrinterEx *r)
8214 switch (r->in.info_ctr->level) {
8215 case 1:
8216 /* we don't handle yet */
8217 /* but I know what to do ... */
8218 return WERR_UNKNOWN_LEVEL;
8219 case 2:
8220 return spoolss_addprinterex_level_2(p, r->in.server,
8221 r->in.info_ctr,
8222 r->in.devmode_ctr->devmode,
8223 r->in.secdesc_ctr->sd,
8224 r->in.userlevel_ctr,
8225 r->out.handle);
8226 default:
8227 return WERR_UNKNOWN_LEVEL;
8231 /****************************************************************
8232 _spoolss_AddPrinter
8233 ****************************************************************/
8235 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
8236 struct spoolss_AddPrinter *r)
8238 struct spoolss_AddPrinterEx a;
8239 struct spoolss_UserLevelCtr userlevel_ctr;
8241 ZERO_STRUCT(userlevel_ctr);
8243 userlevel_ctr.level = 1;
8245 a.in.server = r->in.server;
8246 a.in.info_ctr = r->in.info_ctr;
8247 a.in.devmode_ctr = r->in.devmode_ctr;
8248 a.in.secdesc_ctr = r->in.secdesc_ctr;
8249 a.in.userlevel_ctr = &userlevel_ctr;
8250 a.out.handle = r->out.handle;
8252 return _spoolss_AddPrinterEx(p, &a);
8255 /****************************************************************
8256 _spoolss_AddPrinterDriverEx
8257 ****************************************************************/
8259 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
8260 struct spoolss_AddPrinterDriverEx *r)
8262 WERROR err = WERR_OK;
8263 const char *driver_name = NULL;
8264 uint32_t version;
8265 const char *fn;
8267 switch (p->opnum) {
8268 case NDR_SPOOLSS_ADDPRINTERDRIVER:
8269 fn = "_spoolss_AddPrinterDriver";
8270 break;
8271 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
8272 fn = "_spoolss_AddPrinterDriverEx";
8273 break;
8274 default:
8275 return WERR_INVALID_PARAM;
8279 * we only support the semantics of AddPrinterDriver()
8280 * i.e. only copy files that are newer than existing ones
8283 if (r->in.flags == 0) {
8284 return WERR_INVALID_PARAM;
8287 if (r->in.flags != APD_COPY_NEW_FILES) {
8288 return WERR_ACCESS_DENIED;
8291 /* FIXME */
8292 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
8293 /* Clever hack from Martin Zielinski <mz@seh.de>
8294 * to allow downgrade from level 8 (Vista).
8296 DEBUG(0,("%s: level %d not yet implemented\n", fn,
8297 r->in.info_ctr->level));
8298 return WERR_UNKNOWN_LEVEL;
8301 DEBUG(5,("Cleaning driver's information\n"));
8302 err = clean_up_driver_struct(p->mem_ctx, p->session_info, r->in.info_ctr);
8303 if (!W_ERROR_IS_OK(err))
8304 goto done;
8306 DEBUG(5,("Moving driver to final destination\n"));
8307 err = move_driver_to_download_area(p->session_info, r->in.info_ctr);
8308 if (!W_ERROR_IS_OK(err)) {
8309 goto done;
8312 err = winreg_add_driver_internal(p->mem_ctx,
8313 get_session_info_system(),
8314 p->msg_ctx,
8315 r->in.info_ctr,
8316 &driver_name,
8317 &version);
8318 if (!W_ERROR_IS_OK(err)) {
8319 goto done;
8323 * I think this is where he DrvUpgradePrinter() hook would be
8324 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8325 * server. Right now, we just need to send ourselves a message
8326 * to update each printer bound to this driver. --jerry
8329 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
8330 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8331 fn, driver_name));
8334 done:
8335 return err;
8338 /****************************************************************
8339 _spoolss_AddPrinterDriver
8340 ****************************************************************/
8342 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
8343 struct spoolss_AddPrinterDriver *r)
8345 struct spoolss_AddPrinterDriverEx a;
8347 switch (r->in.info_ctr->level) {
8348 case 2:
8349 case 3:
8350 case 4:
8351 case 5:
8352 break;
8353 default:
8354 return WERR_UNKNOWN_LEVEL;
8357 a.in.servername = r->in.servername;
8358 a.in.info_ctr = r->in.info_ctr;
8359 a.in.flags = APD_COPY_NEW_FILES;
8361 return _spoolss_AddPrinterDriverEx(p, &a);
8364 /****************************************************************************
8365 ****************************************************************************/
8367 struct _spoolss_paths {
8368 int type;
8369 const char *share;
8370 const char *dir;
8373 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
8375 static const struct _spoolss_paths spoolss_paths[]= {
8376 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
8377 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
8380 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
8381 const char *servername,
8382 const char *environment,
8383 int component,
8384 char **path)
8386 const char *pservername = NULL;
8387 const char *long_archi;
8388 const char *short_archi;
8390 *path = NULL;
8392 /* environment may be empty */
8393 if (environment && strlen(environment)) {
8394 long_archi = environment;
8395 } else {
8396 long_archi = lp_parm_const_string(GLOBAL_SECTION_SNUM,
8397 "spoolss", "architecture",
8398 SPOOLSS_ARCHITECTURE_NT_X86);
8401 /* servername may be empty */
8402 if (servername && strlen(servername)) {
8403 pservername = canon_servername(servername);
8405 if (!is_myname_or_ipaddr(pservername)) {
8406 return WERR_INVALID_PARAM;
8410 if (!(short_archi = get_short_archi(long_archi))) {
8411 return WERR_INVALID_ENVIRONMENT;
8414 switch (component) {
8415 case SPOOLSS_PRTPROCS_PATH:
8416 case SPOOLSS_DRIVER_PATH:
8417 if (pservername) {
8418 *path = talloc_asprintf(mem_ctx,
8419 "\\\\%s\\%s\\%s",
8420 pservername,
8421 spoolss_paths[component].share,
8422 short_archi);
8423 } else {
8424 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
8425 SPOOLSS_DEFAULT_SERVER_PATH,
8426 spoolss_paths[component].dir,
8427 short_archi);
8429 break;
8430 default:
8431 return WERR_INVALID_PARAM;
8434 if (!*path) {
8435 return WERR_NOMEM;
8438 return WERR_OK;
8441 /****************************************************************************
8442 ****************************************************************************/
8444 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
8445 const char *servername,
8446 const char *environment,
8447 struct spoolss_DriverDirectoryInfo1 *r)
8449 WERROR werr;
8450 char *path = NULL;
8452 werr = compose_spoolss_server_path(mem_ctx,
8453 servername,
8454 environment,
8455 SPOOLSS_DRIVER_PATH,
8456 &path);
8457 if (!W_ERROR_IS_OK(werr)) {
8458 return werr;
8461 DEBUG(4,("printer driver directory: [%s]\n", path));
8463 r->directory_name = path;
8465 return WERR_OK;
8468 /****************************************************************
8469 _spoolss_GetPrinterDriverDirectory
8470 ****************************************************************/
8472 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
8473 struct spoolss_GetPrinterDriverDirectory *r)
8475 WERROR werror;
8477 /* that's an [in out] buffer */
8479 if (!r->in.buffer && (r->in.offered != 0)) {
8480 return WERR_INVALID_PARAM;
8483 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8484 r->in.level));
8486 *r->out.needed = 0;
8488 /* r->in.level is ignored */
8490 werror = getprinterdriverdir_level_1(p->mem_ctx,
8491 r->in.server,
8492 r->in.environment,
8493 &r->out.info->info1);
8494 if (!W_ERROR_IS_OK(werror)) {
8495 TALLOC_FREE(r->out.info);
8496 return werror;
8499 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
8500 r->out.info, r->in.level);
8501 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8503 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8506 /****************************************************************
8507 _spoolss_EnumPrinterData
8508 ****************************************************************/
8510 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
8511 struct spoolss_EnumPrinterData *r)
8513 WERROR result;
8514 struct spoolss_EnumPrinterDataEx r2;
8515 uint32_t count;
8516 struct spoolss_PrinterEnumValues *info, *val = NULL;
8517 uint32_t needed;
8519 r2.in.handle = r->in.handle;
8520 r2.in.key_name = "PrinterDriverData";
8521 r2.in.offered = 0;
8522 r2.out.count = &count;
8523 r2.out.info = &info;
8524 r2.out.needed = &needed;
8526 result = _spoolss_EnumPrinterDataEx(p, &r2);
8527 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8528 r2.in.offered = needed;
8529 result = _spoolss_EnumPrinterDataEx(p, &r2);
8531 if (!W_ERROR_IS_OK(result)) {
8532 return result;
8536 * The NT machine wants to know the biggest size of value and data
8538 * cf: MSDN EnumPrinterData remark section
8541 if (!r->in.value_offered && !r->in.data_offered) {
8542 uint32_t biggest_valuesize = 0;
8543 uint32_t biggest_datasize = 0;
8544 int i, name_length;
8546 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8548 for (i=0; i<count; i++) {
8550 name_length = strlen(info[i].value_name);
8551 if (strlen(info[i].value_name) > biggest_valuesize) {
8552 biggest_valuesize = name_length;
8555 if (info[i].data_length > biggest_datasize) {
8556 biggest_datasize = info[i].data_length;
8559 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8560 biggest_datasize));
8563 /* the value is an UNICODE string but real_value_size is the length
8564 in bytes including the trailing 0 */
8566 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8567 *r->out.data_needed = biggest_datasize;
8569 DEBUG(6,("final values: [%d], [%d]\n",
8570 *r->out.value_needed, *r->out.data_needed));
8572 return WERR_OK;
8575 if (r->in.enum_index < count) {
8576 val = &info[r->in.enum_index];
8579 if (val == NULL) {
8580 /* out_value should default to "" or else NT4 has
8581 problems unmarshalling the response */
8583 if (r->in.value_offered) {
8584 *r->out.value_needed = 1;
8585 r->out.value_name = talloc_strdup(r, "");
8586 if (!r->out.value_name) {
8587 return WERR_NOMEM;
8589 } else {
8590 r->out.value_name = NULL;
8591 *r->out.value_needed = 0;
8594 /* the data is counted in bytes */
8596 *r->out.data_needed = r->in.data_offered;
8598 result = WERR_NO_MORE_ITEMS;
8599 } else {
8601 * the value is:
8602 * - counted in bytes in the request
8603 * - counted in UNICODE chars in the max reply
8604 * - counted in bytes in the real size
8606 * take a pause *before* coding not *during* coding
8609 /* name */
8610 if (r->in.value_offered) {
8611 r->out.value_name = talloc_strdup(r, val->value_name);
8612 if (!r->out.value_name) {
8613 return WERR_NOMEM;
8615 *r->out.value_needed = val->value_name_len;
8616 } else {
8617 r->out.value_name = NULL;
8618 *r->out.value_needed = 0;
8621 /* type */
8623 *r->out.type = val->type;
8625 /* data - counted in bytes */
8628 * See the section "Dynamically Typed Query Parameters"
8629 * in MS-RPRN.
8632 if (r->out.data && val->data && val->data->data &&
8633 val->data_length && r->in.data_offered) {
8634 memcpy(r->out.data, val->data->data,
8635 MIN(val->data_length,r->in.data_offered));
8638 *r->out.data_needed = val->data_length;
8640 result = WERR_OK;
8643 return result;
8646 /****************************************************************
8647 _spoolss_SetPrinterData
8648 ****************************************************************/
8650 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
8651 struct spoolss_SetPrinterData *r)
8653 struct spoolss_SetPrinterDataEx r2;
8655 r2.in.handle = r->in.handle;
8656 r2.in.key_name = "PrinterDriverData";
8657 r2.in.value_name = r->in.value_name;
8658 r2.in.type = r->in.type;
8659 r2.in.data = r->in.data;
8660 r2.in.offered = r->in.offered;
8662 return _spoolss_SetPrinterDataEx(p, &r2);
8665 /****************************************************************
8666 _spoolss_ResetPrinter
8667 ****************************************************************/
8669 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
8670 struct spoolss_ResetPrinter *r)
8672 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8673 int snum;
8675 DEBUG(5,("_spoolss_ResetPrinter\n"));
8678 * All we do is to check to see if the handle and queue is valid.
8679 * This call really doesn't mean anything to us because we only
8680 * support RAW printing. --jerry
8683 if (!Printer) {
8684 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8685 OUR_HANDLE(r->in.handle)));
8686 return WERR_BADFID;
8689 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8690 return WERR_BADFID;
8693 /* blindly return success */
8694 return WERR_OK;
8697 /****************************************************************
8698 _spoolss_DeletePrinterData
8699 ****************************************************************/
8701 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
8702 struct spoolss_DeletePrinterData *r)
8704 struct spoolss_DeletePrinterDataEx r2;
8706 r2.in.handle = r->in.handle;
8707 r2.in.key_name = "PrinterDriverData";
8708 r2.in.value_name = r->in.value_name;
8710 return _spoolss_DeletePrinterDataEx(p, &r2);
8713 /****************************************************************
8714 _spoolss_AddForm
8715 ****************************************************************/
8717 WERROR _spoolss_AddForm(struct pipes_struct *p,
8718 struct spoolss_AddForm *r)
8720 struct spoolss_AddFormInfo1 *form;
8721 int snum = -1;
8722 WERROR status = WERR_OK;
8723 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8724 struct dcerpc_binding_handle *b;
8725 TALLOC_CTX *tmp_ctx = NULL;
8727 DEBUG(5,("_spoolss_AddForm\n"));
8729 if (!Printer) {
8730 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8731 OUR_HANDLE(r->in.handle)));
8732 return WERR_BADFID;
8735 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8736 and not a printer admin, then fail */
8738 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
8739 !security_token_has_privilege(p->session_info->security_token,
8740 SEC_PRIV_PRINT_OPERATOR)) {
8741 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8742 return WERR_ACCESS_DENIED;
8745 if (r->in.info_ctr->level != 1) {
8746 return WERR_INVALID_LEVEL;
8749 form = r->in.info_ctr->info.info1;
8750 if (!form) {
8751 return WERR_INVALID_PARAM;
8754 switch (form->flags) {
8755 case SPOOLSS_FORM_USER:
8756 case SPOOLSS_FORM_BUILTIN:
8757 case SPOOLSS_FORM_PRINTER:
8758 break;
8759 default:
8760 return WERR_INVALID_PARAM;
8763 tmp_ctx = talloc_new(p->mem_ctx);
8764 if (!tmp_ctx) {
8765 return WERR_NOMEM;
8768 status = winreg_printer_binding_handle(tmp_ctx,
8769 get_session_info_system(),
8770 p->msg_ctx,
8771 &b);
8772 if (!W_ERROR_IS_OK(status)) {
8773 goto done;
8776 status = winreg_printer_addform1(tmp_ctx, b, form);
8777 if (!W_ERROR_IS_OK(status)) {
8778 goto done;
8782 * ChangeID must always be set if this is a printer
8784 if (Printer->printer_type == SPLHND_PRINTER) {
8785 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8786 status = WERR_BADFID;
8787 goto done;
8790 status = winreg_printer_update_changeid(tmp_ctx, b,
8791 lp_const_servicename(snum));
8794 done:
8795 talloc_free(tmp_ctx);
8796 return status;
8799 /****************************************************************
8800 _spoolss_DeleteForm
8801 ****************************************************************/
8803 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8804 struct spoolss_DeleteForm *r)
8806 const char *form_name = r->in.form_name;
8807 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8808 int snum = -1;
8809 WERROR status = WERR_OK;
8810 struct dcerpc_binding_handle *b;
8811 TALLOC_CTX *tmp_ctx = NULL;
8813 DEBUG(5,("_spoolss_DeleteForm\n"));
8815 if (!Printer) {
8816 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8817 OUR_HANDLE(r->in.handle)));
8818 return WERR_BADFID;
8821 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
8822 !security_token_has_privilege(p->session_info->security_token,
8823 SEC_PRIV_PRINT_OPERATOR)) {
8824 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8825 return WERR_ACCESS_DENIED;
8828 tmp_ctx = talloc_new(p->mem_ctx);
8829 if (!tmp_ctx) {
8830 return WERR_NOMEM;
8833 status = winreg_printer_binding_handle(tmp_ctx,
8834 get_session_info_system(),
8835 p->msg_ctx,
8836 &b);
8837 if (!W_ERROR_IS_OK(status)) {
8838 goto done;
8841 status = winreg_printer_deleteform1(tmp_ctx, b, form_name);
8842 if (!W_ERROR_IS_OK(status)) {
8843 goto done;
8847 * ChangeID must always be set if this is a printer
8849 if (Printer->printer_type == SPLHND_PRINTER) {
8850 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8851 status = WERR_BADFID;
8852 goto done;
8855 status = winreg_printer_update_changeid(tmp_ctx, b,
8856 lp_const_servicename(snum));
8859 done:
8860 talloc_free(tmp_ctx);
8861 return status;
8864 /****************************************************************
8865 _spoolss_SetForm
8866 ****************************************************************/
8868 WERROR _spoolss_SetForm(struct pipes_struct *p,
8869 struct spoolss_SetForm *r)
8871 struct spoolss_AddFormInfo1 *form;
8872 const char *form_name = r->in.form_name;
8873 int snum = -1;
8874 WERROR status = WERR_OK;
8875 struct dcerpc_binding_handle *b;
8876 TALLOC_CTX *tmp_ctx = NULL;
8878 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8880 DEBUG(5,("_spoolss_SetForm\n"));
8882 if (!Printer) {
8883 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8884 OUR_HANDLE(r->in.handle)));
8885 return WERR_BADFID;
8888 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8889 and not a printer admin, then fail */
8891 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
8892 !security_token_has_privilege(p->session_info->security_token,
8893 SEC_PRIV_PRINT_OPERATOR)) {
8894 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8895 return WERR_ACCESS_DENIED;
8898 if (r->in.info_ctr->level != 1) {
8899 return WERR_INVALID_LEVEL;
8902 form = r->in.info_ctr->info.info1;
8903 if (!form) {
8904 return WERR_INVALID_PARAM;
8907 tmp_ctx = talloc_new(p->mem_ctx);
8908 if (!tmp_ctx) {
8909 return WERR_NOMEM;
8912 status = winreg_printer_binding_handle(tmp_ctx,
8913 get_session_info_system(),
8914 p->msg_ctx,
8915 &b);
8916 if (!W_ERROR_IS_OK(status)) {
8917 goto done;
8920 status = winreg_printer_setform1(tmp_ctx, b,
8921 form_name,
8922 form);
8923 if (!W_ERROR_IS_OK(status)) {
8924 goto done;
8928 * ChangeID must always be set if this is a printer
8930 if (Printer->printer_type == SPLHND_PRINTER) {
8931 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8932 status = WERR_BADFID;
8933 goto done;
8936 status = winreg_printer_update_changeid(tmp_ctx, b,
8937 lp_const_servicename(snum));
8940 done:
8941 talloc_free(tmp_ctx);
8942 return status;
8945 /****************************************************************************
8946 fill_print_processor1
8947 ****************************************************************************/
8949 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8950 struct spoolss_PrintProcessorInfo1 *r,
8951 const char *print_processor_name)
8953 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8954 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8956 return WERR_OK;
8959 /****************************************************************************
8960 enumprintprocessors level 1.
8961 ****************************************************************************/
8963 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8964 union spoolss_PrintProcessorInfo **info_p,
8965 uint32_t *count)
8967 union spoolss_PrintProcessorInfo *info;
8968 WERROR result;
8970 info = talloc_array(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8971 W_ERROR_HAVE_NO_MEMORY(info);
8973 *count = 1;
8975 result = fill_print_processor1(info, &info[0].info1, "winprint");
8976 if (!W_ERROR_IS_OK(result)) {
8977 goto out;
8980 out:
8981 if (!W_ERROR_IS_OK(result)) {
8982 TALLOC_FREE(info);
8983 *count = 0;
8984 return result;
8987 *info_p = info;
8989 return WERR_OK;
8992 /****************************************************************
8993 _spoolss_EnumPrintProcessors
8994 ****************************************************************/
8996 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8997 struct spoolss_EnumPrintProcessors *r)
8999 WERROR result;
9001 /* that's an [in out] buffer */
9003 if (!r->in.buffer && (r->in.offered != 0)) {
9004 return WERR_INVALID_PARAM;
9007 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
9010 * Enumerate the print processors ...
9012 * Just reply with "winprint", to keep NT happy
9013 * and I can use my nice printer checker.
9016 *r->out.count = 0;
9017 *r->out.needed = 0;
9018 *r->out.info = NULL;
9020 if (!get_short_archi(r->in.environment)) {
9021 return WERR_INVALID_ENVIRONMENT;
9024 switch (r->in.level) {
9025 case 1:
9026 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
9027 r->out.count);
9028 break;
9029 default:
9030 return WERR_UNKNOWN_LEVEL;
9033 if (!W_ERROR_IS_OK(result)) {
9034 return result;
9037 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9038 spoolss_EnumPrintProcessors,
9039 *r->out.info, r->in.level,
9040 *r->out.count);
9041 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9042 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9044 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9047 /****************************************************************************
9048 fill_printprocdatatype1
9049 ****************************************************************************/
9051 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
9052 struct spoolss_PrintProcDataTypesInfo1 *r,
9053 const char *name_array)
9055 r->name_array = talloc_strdup(mem_ctx, name_array);
9056 W_ERROR_HAVE_NO_MEMORY(r->name_array);
9058 return WERR_OK;
9061 /****************************************************************************
9062 enumprintprocdatatypes level 1.
9063 ****************************************************************************/
9065 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
9066 union spoolss_PrintProcDataTypesInfo **info_p,
9067 uint32_t *count)
9069 WERROR result;
9070 union spoolss_PrintProcDataTypesInfo *info;
9072 info = talloc_array(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
9073 W_ERROR_HAVE_NO_MEMORY(info);
9075 *count = 1;
9077 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
9078 if (!W_ERROR_IS_OK(result)) {
9079 goto out;
9082 out:
9083 if (!W_ERROR_IS_OK(result)) {
9084 TALLOC_FREE(info);
9085 *count = 0;
9086 return result;
9089 *info_p = info;
9091 return WERR_OK;
9094 /****************************************************************
9095 _spoolss_EnumPrintProcDataTypes
9096 ****************************************************************/
9098 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
9099 struct spoolss_EnumPrintProcDataTypes *r)
9101 WERROR result;
9103 /* that's an [in out] buffer */
9105 if (!r->in.buffer && (r->in.offered != 0)) {
9106 return WERR_INVALID_PARAM;
9109 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
9111 *r->out.count = 0;
9112 *r->out.needed = 0;
9113 *r->out.info = NULL;
9115 if (r->in.print_processor_name == NULL ||
9116 !strequal(r->in.print_processor_name, "winprint")) {
9117 return WERR_UNKNOWN_PRINTPROCESSOR;
9120 switch (r->in.level) {
9121 case 1:
9122 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
9123 r->out.count);
9124 break;
9125 default:
9126 return WERR_UNKNOWN_LEVEL;
9129 if (!W_ERROR_IS_OK(result)) {
9130 return result;
9133 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9134 spoolss_EnumPrintProcDataTypes,
9135 *r->out.info, r->in.level,
9136 *r->out.count);
9137 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9138 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9140 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9143 /****************************************************************************
9144 fill_monitor_1
9145 ****************************************************************************/
9147 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
9148 struct spoolss_MonitorInfo1 *r,
9149 const char *monitor_name)
9151 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
9152 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
9154 return WERR_OK;
9157 /****************************************************************************
9158 fill_monitor_2
9159 ****************************************************************************/
9161 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
9162 struct spoolss_MonitorInfo2 *r,
9163 const char *monitor_name,
9164 const char *environment,
9165 const char *dll_name)
9167 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
9168 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
9169 r->environment = talloc_strdup(mem_ctx, environment);
9170 W_ERROR_HAVE_NO_MEMORY(r->environment);
9171 r->dll_name = talloc_strdup(mem_ctx, dll_name);
9172 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
9174 return WERR_OK;
9177 /****************************************************************************
9178 enumprintmonitors level 1.
9179 ****************************************************************************/
9181 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
9182 union spoolss_MonitorInfo **info_p,
9183 uint32_t *count)
9185 union spoolss_MonitorInfo *info;
9186 WERROR result = WERR_OK;
9188 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, 2);
9189 W_ERROR_HAVE_NO_MEMORY(info);
9191 *count = 2;
9193 result = fill_monitor_1(info, &info[0].info1,
9194 SPL_LOCAL_PORT);
9195 if (!W_ERROR_IS_OK(result)) {
9196 goto out;
9199 result = fill_monitor_1(info, &info[1].info1,
9200 SPL_TCPIP_PORT);
9201 if (!W_ERROR_IS_OK(result)) {
9202 goto out;
9205 out:
9206 if (!W_ERROR_IS_OK(result)) {
9207 TALLOC_FREE(info);
9208 *count = 0;
9209 return result;
9212 *info_p = info;
9214 return WERR_OK;
9217 /****************************************************************************
9218 enumprintmonitors level 2.
9219 ****************************************************************************/
9221 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
9222 union spoolss_MonitorInfo **info_p,
9223 uint32_t *count)
9225 union spoolss_MonitorInfo *info;
9226 WERROR result = WERR_OK;
9228 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, 2);
9229 W_ERROR_HAVE_NO_MEMORY(info);
9231 *count = 2;
9233 result = fill_monitor_2(info, &info[0].info2,
9234 SPL_LOCAL_PORT,
9235 "Windows NT X86", /* FIXME */
9236 "localmon.dll");
9237 if (!W_ERROR_IS_OK(result)) {
9238 goto out;
9241 result = fill_monitor_2(info, &info[1].info2,
9242 SPL_TCPIP_PORT,
9243 "Windows NT X86", /* FIXME */
9244 "tcpmon.dll");
9245 if (!W_ERROR_IS_OK(result)) {
9246 goto out;
9249 out:
9250 if (!W_ERROR_IS_OK(result)) {
9251 TALLOC_FREE(info);
9252 *count = 0;
9253 return result;
9256 *info_p = info;
9258 return WERR_OK;
9261 /****************************************************************
9262 _spoolss_EnumMonitors
9263 ****************************************************************/
9265 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
9266 struct spoolss_EnumMonitors *r)
9268 WERROR result;
9270 /* that's an [in out] buffer */
9272 if (!r->in.buffer && (r->in.offered != 0)) {
9273 return WERR_INVALID_PARAM;
9276 DEBUG(5,("_spoolss_EnumMonitors\n"));
9279 * Enumerate the print monitors ...
9281 * Just reply with "Local Port", to keep NT happy
9282 * and I can use my nice printer checker.
9285 *r->out.count = 0;
9286 *r->out.needed = 0;
9287 *r->out.info = NULL;
9289 switch (r->in.level) {
9290 case 1:
9291 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
9292 r->out.count);
9293 break;
9294 case 2:
9295 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
9296 r->out.count);
9297 break;
9298 default:
9299 return WERR_UNKNOWN_LEVEL;
9302 if (!W_ERROR_IS_OK(result)) {
9303 return result;
9306 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9307 spoolss_EnumMonitors,
9308 *r->out.info, r->in.level,
9309 *r->out.count);
9310 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9311 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9313 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9316 /****************************************************************************
9317 ****************************************************************************/
9319 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
9320 const print_queue_struct *queue,
9321 int count, int snum,
9322 struct spoolss_PrinterInfo2 *pinfo2,
9323 uint32_t jobid,
9324 struct spoolss_JobInfo1 *r)
9326 int i = 0;
9327 bool found = false;
9329 for (i=0; i<count; i++) {
9330 if (queue[i].sysjob == (int)jobid) {
9331 found = true;
9332 break;
9336 if (found == false) {
9337 /* NT treats not found as bad param... yet another bad choice */
9338 return WERR_INVALID_PARAM;
9341 return fill_job_info1(mem_ctx,
9343 &queue[i],
9345 snum,
9346 pinfo2);
9349 /****************************************************************************
9350 ****************************************************************************/
9352 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
9353 const print_queue_struct *queue,
9354 int count, int snum,
9355 struct spoolss_PrinterInfo2 *pinfo2,
9356 uint32_t jobid,
9357 struct spoolss_JobInfo2 *r)
9359 int i = 0;
9360 bool found = false;
9361 struct spoolss_DeviceMode *devmode;
9362 WERROR result;
9364 for (i=0; i<count; i++) {
9365 if (queue[i].sysjob == (int)jobid) {
9366 found = true;
9367 break;
9371 if (found == false) {
9372 /* NT treats not found as bad param... yet another bad
9373 choice */
9374 return WERR_INVALID_PARAM;
9378 * if the print job does not have a DEVMODE associated with it,
9379 * just use the one for the printer. A NULL devicemode is not
9380 * a failure condition
9383 devmode = print_job_devmode(mem_ctx, lp_const_servicename(snum), jobid);
9384 if (!devmode) {
9385 result = spoolss_create_default_devmode(mem_ctx,
9386 pinfo2->printername,
9387 &devmode);
9388 if (!W_ERROR_IS_OK(result)) {
9389 DEBUG(3, ("Can't proceed w/o a devmode!"));
9390 return result;
9394 return fill_job_info2(mem_ctx,
9396 &queue[i],
9398 snum,
9399 pinfo2,
9400 devmode);
9403 /****************************************************************
9404 _spoolss_GetJob
9405 ****************************************************************/
9407 WERROR _spoolss_GetJob(struct pipes_struct *p,
9408 struct spoolss_GetJob *r)
9410 WERROR result = WERR_OK;
9411 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9412 int snum;
9413 int count;
9414 print_queue_struct *queue = NULL;
9415 print_status_struct prt_status;
9417 /* that's an [in out] buffer */
9419 if (!r->in.buffer && (r->in.offered != 0)) {
9420 return WERR_INVALID_PARAM;
9423 DEBUG(5,("_spoolss_GetJob\n"));
9425 *r->out.needed = 0;
9427 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9428 return WERR_BADFID;
9431 result = winreg_get_printer_internal(p->mem_ctx,
9432 get_session_info_system(),
9433 p->msg_ctx,
9434 lp_const_servicename(snum),
9435 &pinfo2);
9436 if (!W_ERROR_IS_OK(result)) {
9437 return result;
9440 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
9442 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9443 count, prt_status.status, prt_status.message));
9445 switch (r->in.level) {
9446 case 1:
9447 result = getjob_level_1(p->mem_ctx,
9448 queue, count, snum, pinfo2,
9449 r->in.job_id, &r->out.info->info1);
9450 break;
9451 case 2:
9452 result = getjob_level_2(p->mem_ctx,
9453 queue, count, snum, pinfo2,
9454 r->in.job_id, &r->out.info->info2);
9455 break;
9456 default:
9457 result = WERR_UNKNOWN_LEVEL;
9458 break;
9461 SAFE_FREE(queue);
9462 TALLOC_FREE(pinfo2);
9464 if (!W_ERROR_IS_OK(result)) {
9465 TALLOC_FREE(r->out.info);
9466 return result;
9469 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
9470 r->in.level);
9471 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9473 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9476 /****************************************************************
9477 _spoolss_GetPrinterDataEx
9478 ****************************************************************/
9480 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
9481 struct spoolss_GetPrinterDataEx *r)
9484 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9485 const char *printer;
9486 int snum = 0;
9487 WERROR result = WERR_OK;
9488 DATA_BLOB blob;
9489 enum winreg_Type val_type = REG_NONE;
9490 uint8_t *val_data = NULL;
9491 uint32_t val_size = 0;
9492 struct dcerpc_binding_handle *b;
9493 TALLOC_CTX *tmp_ctx;
9495 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9497 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9498 r->in.key_name, r->in.value_name));
9500 /* in case of problem, return some default values */
9502 *r->out.needed = 0;
9503 *r->out.type = REG_NONE;
9505 tmp_ctx = talloc_new(p->mem_ctx);
9506 if (!tmp_ctx) {
9507 return WERR_NOMEM;
9510 if (!Printer) {
9511 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9512 OUR_HANDLE(r->in.handle)));
9513 result = WERR_BADFID;
9514 goto done;
9517 /* check to see if the keyname is valid */
9518 if (!strlen(r->in.key_name)) {
9519 result = WERR_INVALID_PARAM;
9520 goto done;
9523 /* Is the handle to a printer or to the server? */
9525 if (Printer->printer_type == SPLHND_SERVER) {
9527 union spoolss_PrinterData data;
9529 result = getprinterdata_printer_server(tmp_ctx,
9530 r->in.value_name,
9531 r->out.type,
9532 &data);
9533 if (!W_ERROR_IS_OK(result)) {
9534 goto done;
9537 result = push_spoolss_PrinterData(tmp_ctx, &blob,
9538 *r->out.type, &data);
9539 if (!W_ERROR_IS_OK(result)) {
9540 goto done;
9543 *r->out.needed = blob.length;
9545 if (r->in.offered >= *r->out.needed) {
9546 memcpy(r->out.data, blob.data, blob.length);
9549 result = WERR_OK;
9550 goto done;
9553 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9554 result = WERR_BADFID;
9555 goto done;
9557 printer = lp_const_servicename(snum);
9559 result = winreg_printer_binding_handle(tmp_ctx,
9560 get_session_info_system(),
9561 p->msg_ctx,
9562 &b);
9563 if (!W_ERROR_IS_OK(result)) {
9564 goto done;
9567 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9568 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
9569 strequal(r->in.value_name, "ChangeId")) {
9570 *r->out.type = REG_DWORD;
9571 *r->out.needed = 4;
9572 if (r->in.offered >= *r->out.needed) {
9573 uint32_t changeid = 0;
9575 result = winreg_printer_get_changeid(tmp_ctx, b,
9576 printer,
9577 &changeid);
9578 if (!W_ERROR_IS_OK(result)) {
9579 goto done;
9582 SIVAL(r->out.data, 0, changeid);
9583 result = WERR_OK;
9585 goto done;
9588 result = winreg_get_printer_dataex(tmp_ctx, b,
9589 printer,
9590 r->in.key_name,
9591 r->in.value_name,
9592 &val_type,
9593 &val_data,
9594 &val_size);
9595 if (!W_ERROR_IS_OK(result)) {
9596 goto done;
9599 *r->out.needed = val_size;
9600 *r->out.type = val_type;
9602 if (r->in.offered >= *r->out.needed) {
9603 memcpy(r->out.data, val_data, val_size);
9606 done:
9607 /* NOTE: do not replace type when returning WERR_MORE_DATA */
9609 if (W_ERROR_IS_OK(result)) {
9610 result = SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9613 talloc_free(tmp_ctx);
9614 return result;
9617 /****************************************************************
9618 _spoolss_SetPrinterDataEx
9619 ****************************************************************/
9621 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
9622 struct spoolss_SetPrinterDataEx *r)
9624 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9625 int snum = 0;
9626 WERROR result = WERR_OK;
9627 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9628 char *oid_string;
9629 struct dcerpc_binding_handle *b;
9630 TALLOC_CTX *tmp_ctx;
9632 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9634 /* From MSDN documentation of SetPrinterDataEx: pass request to
9635 SetPrinterData if key is "PrinterDriverData" */
9637 if (!Printer) {
9638 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9639 OUR_HANDLE(r->in.handle)));
9640 return WERR_BADFID;
9643 if (Printer->printer_type == SPLHND_SERVER) {
9644 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9645 "Not implemented for server handles yet\n"));
9646 return WERR_INVALID_PARAM;
9649 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9650 return WERR_BADFID;
9654 * Access check : NT returns "access denied" if you make a
9655 * SetPrinterData call without the necessary privildge.
9656 * we were originally returning OK if nothing changed
9657 * which made Win2k issue **a lot** of SetPrinterData
9658 * when connecting to a printer --jerry
9661 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9662 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9663 "change denied by handle access permissions\n"));
9664 return WERR_ACCESS_DENIED;
9667 tmp_ctx = talloc_new(p->mem_ctx);
9668 if (!tmp_ctx) {
9669 return WERR_NOMEM;
9672 result = winreg_printer_binding_handle(tmp_ctx,
9673 get_session_info_system(),
9674 p->msg_ctx,
9675 &b);
9676 if (!W_ERROR_IS_OK(result)) {
9677 goto done;
9680 result = winreg_get_printer(tmp_ctx, b,
9681 lp_servicename(talloc_tos(), snum),
9682 &pinfo2);
9683 if (!W_ERROR_IS_OK(result)) {
9684 goto done;
9687 /* check for OID in valuename */
9689 oid_string = strchr(r->in.value_name, ',');
9690 if (oid_string) {
9691 *oid_string = '\0';
9692 oid_string++;
9695 /* save the registry data */
9697 result = winreg_set_printer_dataex(tmp_ctx, b,
9698 pinfo2->sharename,
9699 r->in.key_name,
9700 r->in.value_name,
9701 r->in.type,
9702 r->in.data,
9703 r->in.offered);
9705 if (W_ERROR_IS_OK(result)) {
9706 /* save the OID if one was specified */
9707 if (oid_string) {
9708 char *str = talloc_asprintf(tmp_ctx, "%s\\%s",
9709 r->in.key_name, SPOOL_OID_KEY);
9710 if (!str) {
9711 result = WERR_NOMEM;
9712 goto done;
9716 * I'm not checking the status here on purpose. Don't know
9717 * if this is right, but I'm returning the status from the
9718 * previous set_printer_dataex() call. I have no idea if
9719 * this is right. --jerry
9721 winreg_set_printer_dataex(tmp_ctx, b,
9722 pinfo2->sharename,
9723 str,
9724 r->in.value_name,
9725 REG_SZ,
9726 (uint8_t *) oid_string,
9727 strlen(oid_string) + 1);
9730 result = winreg_printer_update_changeid(tmp_ctx, b,
9731 lp_const_servicename(snum));
9735 done:
9736 talloc_free(tmp_ctx);
9737 return result;
9740 /****************************************************************
9741 _spoolss_DeletePrinterDataEx
9742 ****************************************************************/
9744 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
9745 struct spoolss_DeletePrinterDataEx *r)
9747 const char *printer;
9748 int snum=0;
9749 WERROR status = WERR_OK;
9750 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9752 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9754 if (!Printer) {
9755 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9756 "Invalid handle (%s:%u:%u).\n",
9757 OUR_HANDLE(r->in.handle)));
9758 return WERR_BADFID;
9761 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9762 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9763 "printer properties change denied by handle\n"));
9764 return WERR_ACCESS_DENIED;
9767 if (!r->in.value_name || !r->in.key_name) {
9768 return WERR_NOMEM;
9771 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9772 return WERR_BADFID;
9774 printer = lp_const_servicename(snum);
9776 status = winreg_delete_printer_dataex_internal(p->mem_ctx,
9777 get_session_info_system(),
9778 p->msg_ctx,
9779 printer,
9780 r->in.key_name,
9781 r->in.value_name);
9782 if (W_ERROR_IS_OK(status)) {
9783 status = winreg_printer_update_changeid_internal(p->mem_ctx,
9784 get_session_info_system(),
9785 p->msg_ctx,
9786 printer);
9789 return status;
9792 /****************************************************************
9793 _spoolss_EnumPrinterKey
9794 ****************************************************************/
9796 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
9797 struct spoolss_EnumPrinterKey *r)
9799 uint32_t num_keys;
9800 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9801 int snum = 0;
9802 WERROR result = WERR_BADFILE;
9803 const char **array = NULL;
9804 DATA_BLOB blob;
9806 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9808 if (!Printer) {
9809 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9810 OUR_HANDLE(r->in.handle)));
9811 return WERR_BADFID;
9814 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9815 return WERR_BADFID;
9818 result = winreg_enum_printer_key_internal(p->mem_ctx,
9819 get_session_info_system(),
9820 p->msg_ctx,
9821 lp_const_servicename(snum),
9822 r->in.key_name,
9823 &num_keys,
9824 &array);
9825 if (!W_ERROR_IS_OK(result)) {
9826 goto done;
9829 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9830 result = WERR_NOMEM;
9831 goto done;
9834 *r->out._ndr_size = r->in.offered / 2;
9835 *r->out.needed = blob.length;
9837 if (r->in.offered < *r->out.needed) {
9838 result = WERR_MORE_DATA;
9839 } else {
9840 result = WERR_OK;
9841 r->out.key_buffer->string_array = array;
9844 done:
9845 if (!W_ERROR_IS_OK(result)) {
9846 TALLOC_FREE(array);
9847 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9848 *r->out.needed = 0;
9852 return result;
9855 /****************************************************************
9856 _spoolss_DeletePrinterKey
9857 ****************************************************************/
9859 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9860 struct spoolss_DeletePrinterKey *r)
9862 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9863 int snum=0;
9864 WERROR status;
9865 const char *printer;
9866 struct dcerpc_binding_handle *b;
9867 TALLOC_CTX *tmp_ctx;
9869 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9871 if (!Printer) {
9872 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9873 OUR_HANDLE(r->in.handle)));
9874 return WERR_BADFID;
9877 /* if keyname == NULL, return error */
9878 if ( !r->in.key_name )
9879 return WERR_INVALID_PARAM;
9881 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9882 return WERR_BADFID;
9885 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9886 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9887 "printer properties change denied by handle\n"));
9888 return WERR_ACCESS_DENIED;
9891 printer = lp_const_servicename(snum);
9893 tmp_ctx = talloc_new(p->mem_ctx);
9894 if (!tmp_ctx) {
9895 return WERR_NOMEM;
9898 status = winreg_printer_binding_handle(tmp_ctx,
9899 get_session_info_system(),
9900 p->msg_ctx,
9901 &b);
9902 if (!W_ERROR_IS_OK(status)) {
9903 goto done;
9906 /* delete the key and all subkeys */
9907 status = winreg_delete_printer_key(tmp_ctx, b,
9908 printer,
9909 r->in.key_name);
9910 if (W_ERROR_IS_OK(status)) {
9911 status = winreg_printer_update_changeid(tmp_ctx, b,
9912 printer);
9915 done:
9916 talloc_free(tmp_ctx);
9917 return status;
9920 /****************************************************************
9921 _spoolss_EnumPrinterDataEx
9922 ****************************************************************/
9924 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9925 struct spoolss_EnumPrinterDataEx *r)
9927 uint32_t count = 0;
9928 struct spoolss_PrinterEnumValues *info = NULL;
9929 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9930 int snum;
9931 WERROR result;
9933 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9935 *r->out.count = 0;
9936 *r->out.needed = 0;
9937 *r->out.info = NULL;
9939 if (!Printer) {
9940 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9941 OUR_HANDLE(r->in.handle)));
9942 return WERR_BADFID;
9946 * first check for a keyname of NULL or "". Win2k seems to send
9947 * this a lot and we should send back WERR_INVALID_PARAM
9948 * no need to spend time looking up the printer in this case.
9949 * --jerry
9952 if (!strlen(r->in.key_name)) {
9953 result = WERR_INVALID_PARAM;
9954 goto done;
9957 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9958 return WERR_BADFID;
9961 /* now look for a match on the key name */
9962 result = winreg_enum_printer_dataex_internal(p->mem_ctx,
9963 get_session_info_system(),
9964 p->msg_ctx,
9965 lp_const_servicename(snum),
9966 r->in.key_name,
9967 &count,
9968 &info);
9969 if (!W_ERROR_IS_OK(result)) {
9970 goto done;
9973 #if 0 /* FIXME - gd */
9974 /* housekeeping information in the reply */
9976 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9977 * the hand marshalled container size is a multiple
9978 * of 4 bytes for RPC alignment.
9981 if (needed % 4) {
9982 needed += 4-(needed % 4);
9984 #endif
9985 *r->out.count = count;
9986 *r->out.info = info;
9988 done:
9989 if (!W_ERROR_IS_OK(result)) {
9990 return result;
9993 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9994 spoolss_EnumPrinterDataEx,
9995 *r->out.info,
9996 *r->out.count);
9997 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9998 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
10000 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
10003 /****************************************************************************
10004 ****************************************************************************/
10006 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
10007 const char *servername,
10008 const char *environment,
10009 struct spoolss_PrintProcessorDirectoryInfo1 *r)
10011 WERROR werr;
10012 char *path = NULL;
10014 werr = compose_spoolss_server_path(mem_ctx,
10015 servername,
10016 environment,
10017 SPOOLSS_PRTPROCS_PATH,
10018 &path);
10019 if (!W_ERROR_IS_OK(werr)) {
10020 return werr;
10023 DEBUG(4,("print processor directory: [%s]\n", path));
10025 r->directory_name = path;
10027 return WERR_OK;
10030 /****************************************************************
10031 _spoolss_GetPrintProcessorDirectory
10032 ****************************************************************/
10034 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
10035 struct spoolss_GetPrintProcessorDirectory *r)
10037 WERROR result;
10038 char *prnproc_share = NULL;
10039 bool prnproc_share_exists = false;
10040 int snum;
10042 /* that's an [in out] buffer */
10044 if (!r->in.buffer && (r->in.offered != 0)) {
10045 return WERR_INVALID_PARAM;
10048 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
10049 r->in.level));
10051 *r->out.needed = 0;
10053 /* r->in.level is ignored */
10055 /* We always should reply with a local print processor directory so that
10056 * users are not forced to have a [prnproc$] share on the Samba spoolss
10057 * server, if users decide to do so, lets announce it though - Guenther */
10059 snum = find_service(talloc_tos(), "prnproc$", &prnproc_share);
10060 if (!prnproc_share) {
10061 return WERR_NOMEM;
10063 if (snum != -1) {
10064 prnproc_share_exists = true;
10067 result = getprintprocessordirectory_level_1(p->mem_ctx,
10068 prnproc_share_exists ? r->in.server : NULL,
10069 r->in.environment,
10070 &r->out.info->info1);
10071 if (!W_ERROR_IS_OK(result)) {
10072 TALLOC_FREE(r->out.info);
10073 return result;
10076 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
10077 r->out.info, r->in.level);
10078 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
10080 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
10083 /*******************************************************************
10084 ********************************************************************/
10086 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
10087 const char *dllname)
10089 enum ndr_err_code ndr_err;
10090 struct spoolss_MonitorUi ui;
10092 ui.dll_name = dllname;
10094 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
10095 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
10096 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10097 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
10099 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10102 /*******************************************************************
10103 Streams the monitor UI DLL name in UNICODE
10104 *******************************************************************/
10106 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
10107 struct security_token *token, DATA_BLOB *in,
10108 DATA_BLOB *out, uint32_t *needed)
10110 const char *dllname = "tcpmonui.dll";
10112 *needed = (strlen(dllname)+1) * 2;
10114 if (out->length < *needed) {
10115 return WERR_INSUFFICIENT_BUFFER;
10118 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
10119 return WERR_NOMEM;
10122 return WERR_OK;
10125 /*******************************************************************
10126 ********************************************************************/
10128 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
10129 struct spoolss_PortData1 *port1,
10130 const DATA_BLOB *buf)
10132 enum ndr_err_code ndr_err;
10133 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
10134 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
10135 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10136 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
10138 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10141 /*******************************************************************
10142 ********************************************************************/
10144 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
10145 struct spoolss_PortData2 *port2,
10146 const DATA_BLOB *buf)
10148 enum ndr_err_code ndr_err;
10149 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
10150 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
10151 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10152 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
10154 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10157 /*******************************************************************
10158 Create a new TCP/IP port
10159 *******************************************************************/
10161 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
10162 struct security_token *token, DATA_BLOB *in,
10163 DATA_BLOB *out, uint32_t *needed)
10165 struct spoolss_PortData1 port1;
10166 struct spoolss_PortData2 port2;
10167 char *device_uri = NULL;
10168 uint32_t version;
10170 const char *portname;
10171 const char *hostaddress;
10172 const char *queue;
10173 uint32_t port_number;
10174 uint32_t protocol;
10176 /* peek for spoolss_PortData version */
10178 if (!in || (in->length < (128 + 4))) {
10179 return WERR_GENERAL_FAILURE;
10182 version = IVAL(in->data, 128);
10184 switch (version) {
10185 case 1:
10186 ZERO_STRUCT(port1);
10188 if (!pull_port_data_1(mem_ctx, &port1, in)) {
10189 return WERR_NOMEM;
10192 portname = port1.portname;
10193 hostaddress = port1.hostaddress;
10194 queue = port1.queue;
10195 protocol = port1.protocol;
10196 port_number = port1.port_number;
10198 break;
10199 case 2:
10200 ZERO_STRUCT(port2);
10202 if (!pull_port_data_2(mem_ctx, &port2, in)) {
10203 return WERR_NOMEM;
10206 portname = port2.portname;
10207 hostaddress = port2.hostaddress;
10208 queue = port2.queue;
10209 protocol = port2.protocol;
10210 port_number = port2.port_number;
10212 break;
10213 default:
10214 DEBUG(1,("xcvtcp_addport: "
10215 "unknown version of port_data: %d\n", version));
10216 return WERR_UNKNOWN_PORT;
10219 /* create the device URI and call the add_port_hook() */
10221 switch (protocol) {
10222 case PROTOCOL_RAWTCP_TYPE:
10223 device_uri = talloc_asprintf(mem_ctx,
10224 "socket://%s:%d/", hostaddress,
10225 port_number);
10226 break;
10228 case PROTOCOL_LPR_TYPE:
10229 device_uri = talloc_asprintf(mem_ctx,
10230 "lpr://%s/%s", hostaddress, queue );
10231 break;
10233 default:
10234 return WERR_UNKNOWN_PORT;
10237 if (!device_uri) {
10238 return WERR_NOMEM;
10241 return add_port_hook(mem_ctx, token, portname, device_uri);
10244 /*******************************************************************
10245 *******************************************************************/
10247 struct xcv_api_table xcvtcp_cmds[] = {
10248 { "MonitorUI", xcvtcp_monitorui },
10249 { "AddPort", xcvtcp_addport},
10250 { NULL, NULL }
10253 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
10254 struct security_token *token, const char *command,
10255 DATA_BLOB *inbuf,
10256 DATA_BLOB *outbuf,
10257 uint32_t *needed )
10259 int i;
10261 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
10263 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
10264 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
10265 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
10268 return WERR_BADFUNC;
10271 /*******************************************************************
10272 *******************************************************************/
10273 #if 0 /* don't support management using the "Local Port" monitor */
10275 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
10276 struct security_token *token, DATA_BLOB *in,
10277 DATA_BLOB *out, uint32_t *needed)
10279 const char *dllname = "localui.dll";
10281 *needed = (strlen(dllname)+1) * 2;
10283 if (out->length < *needed) {
10284 return WERR_INSUFFICIENT_BUFFER;
10287 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
10288 return WERR_NOMEM;
10291 return WERR_OK;
10294 /*******************************************************************
10295 *******************************************************************/
10297 struct xcv_api_table xcvlocal_cmds[] = {
10298 { "MonitorUI", xcvlocal_monitorui },
10299 { NULL, NULL }
10301 #else
10302 struct xcv_api_table xcvlocal_cmds[] = {
10303 { NULL, NULL }
10305 #endif
10309 /*******************************************************************
10310 *******************************************************************/
10312 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
10313 struct security_token *token, const char *command,
10314 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
10315 uint32_t *needed)
10317 int i;
10319 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
10321 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
10322 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
10323 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
10325 return WERR_BADFUNC;
10328 /****************************************************************
10329 _spoolss_XcvData
10330 ****************************************************************/
10332 WERROR _spoolss_XcvData(struct pipes_struct *p,
10333 struct spoolss_XcvData *r)
10335 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
10336 DATA_BLOB out_data = data_blob_null;
10337 WERROR werror;
10339 if (!Printer) {
10340 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
10341 OUR_HANDLE(r->in.handle)));
10342 return WERR_BADFID;
10345 /* Has to be a handle to the TCP/IP port monitor */
10347 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
10348 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
10349 return WERR_BADFID;
10352 /* requires administrative access to the server */
10354 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
10355 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
10356 return WERR_ACCESS_DENIED;
10359 /* Allocate the outgoing buffer */
10361 if (r->in.out_data_size) {
10362 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
10363 if (out_data.data == NULL) {
10364 return WERR_NOMEM;
10368 switch ( Printer->printer_type ) {
10369 case SPLHND_PORTMON_TCP:
10370 werror = process_xcvtcp_command(p->mem_ctx,
10371 p->session_info->security_token,
10372 r->in.function_name,
10373 &r->in.in_data, &out_data,
10374 r->out.needed);
10375 break;
10376 case SPLHND_PORTMON_LOCAL:
10377 werror = process_xcvlocal_command(p->mem_ctx,
10378 p->session_info->security_token,
10379 r->in.function_name,
10380 &r->in.in_data, &out_data,
10381 r->out.needed);
10382 break;
10383 default:
10384 werror = WERR_INVALID_PRINT_MONITOR;
10387 if (!W_ERROR_IS_OK(werror)) {
10388 return werror;
10391 *r->out.status_code = 0;
10393 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
10394 memcpy(r->out.out_data, out_data.data,
10395 MIN(r->in.out_data_size, out_data.length));
10398 return WERR_OK;
10401 /****************************************************************
10402 _spoolss_AddPrintProcessor
10403 ****************************************************************/
10405 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
10406 struct spoolss_AddPrintProcessor *r)
10408 /* for now, just indicate success and ignore the add. We'll
10409 automatically set the winprint processor for printer
10410 entries later. Used to debug the LexMark Optra S 1855 PCL
10411 driver --jerry */
10413 return WERR_OK;
10416 /****************************************************************
10417 _spoolss_AddPort
10418 ****************************************************************/
10420 WERROR _spoolss_AddPort(struct pipes_struct *p,
10421 struct spoolss_AddPort *r)
10423 /* do what w2k3 does */
10425 return WERR_NOT_SUPPORTED;
10428 /****************************************************************
10429 _spoolss_GetPrinterDriver
10430 ****************************************************************/
10432 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
10433 struct spoolss_GetPrinterDriver *r)
10435 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10436 return WERR_NOT_SUPPORTED;
10439 /****************************************************************
10440 _spoolss_ReadPrinter
10441 ****************************************************************/
10443 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
10444 struct spoolss_ReadPrinter *r)
10446 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10447 return WERR_NOT_SUPPORTED;
10450 /****************************************************************
10451 _spoolss_WaitForPrinterChange
10452 ****************************************************************/
10454 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
10455 struct spoolss_WaitForPrinterChange *r)
10457 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10458 return WERR_NOT_SUPPORTED;
10461 /****************************************************************
10462 _spoolss_ConfigurePort
10463 ****************************************************************/
10465 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
10466 struct spoolss_ConfigurePort *r)
10468 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10469 return WERR_NOT_SUPPORTED;
10472 /****************************************************************
10473 _spoolss_DeletePort
10474 ****************************************************************/
10476 WERROR _spoolss_DeletePort(struct pipes_struct *p,
10477 struct spoolss_DeletePort *r)
10479 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10480 return WERR_NOT_SUPPORTED;
10483 /****************************************************************
10484 _spoolss_CreatePrinterIC
10485 ****************************************************************/
10487 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
10488 struct spoolss_CreatePrinterIC *r)
10490 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10491 return WERR_NOT_SUPPORTED;
10494 /****************************************************************
10495 _spoolss_PlayGDIScriptOnPrinterIC
10496 ****************************************************************/
10498 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
10499 struct spoolss_PlayGDIScriptOnPrinterIC *r)
10501 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10502 return WERR_NOT_SUPPORTED;
10505 /****************************************************************
10506 _spoolss_DeletePrinterIC
10507 ****************************************************************/
10509 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
10510 struct spoolss_DeletePrinterIC *r)
10512 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10513 return WERR_NOT_SUPPORTED;
10516 /****************************************************************
10517 _spoolss_AddPrinterConnection
10518 ****************************************************************/
10520 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
10521 struct spoolss_AddPrinterConnection *r)
10523 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10524 return WERR_NOT_SUPPORTED;
10527 /****************************************************************
10528 _spoolss_DeletePrinterConnection
10529 ****************************************************************/
10531 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
10532 struct spoolss_DeletePrinterConnection *r)
10534 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10535 return WERR_NOT_SUPPORTED;
10538 /****************************************************************
10539 _spoolss_PrinterMessageBox
10540 ****************************************************************/
10542 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
10543 struct spoolss_PrinterMessageBox *r)
10545 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10546 return WERR_NOT_SUPPORTED;
10549 /****************************************************************
10550 _spoolss_AddMonitor
10551 ****************************************************************/
10553 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
10554 struct spoolss_AddMonitor *r)
10556 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10557 return WERR_NOT_SUPPORTED;
10560 /****************************************************************
10561 _spoolss_DeleteMonitor
10562 ****************************************************************/
10564 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
10565 struct spoolss_DeleteMonitor *r)
10567 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10568 return WERR_NOT_SUPPORTED;
10571 /****************************************************************
10572 _spoolss_DeletePrintProcessor
10573 ****************************************************************/
10575 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
10576 struct spoolss_DeletePrintProcessor *r)
10578 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10579 return WERR_NOT_SUPPORTED;
10582 /****************************************************************
10583 _spoolss_AddPrintProvidor
10584 ****************************************************************/
10586 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
10587 struct spoolss_AddPrintProvidor *r)
10589 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10590 return WERR_NOT_SUPPORTED;
10593 /****************************************************************
10594 _spoolss_DeletePrintProvidor
10595 ****************************************************************/
10597 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
10598 struct spoolss_DeletePrintProvidor *r)
10600 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10601 return WERR_NOT_SUPPORTED;
10604 /****************************************************************
10605 _spoolss_FindFirstPrinterChangeNotification
10606 ****************************************************************/
10608 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
10609 struct spoolss_FindFirstPrinterChangeNotification *r)
10611 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10612 return WERR_NOT_SUPPORTED;
10615 /****************************************************************
10616 _spoolss_FindNextPrinterChangeNotification
10617 ****************************************************************/
10619 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
10620 struct spoolss_FindNextPrinterChangeNotification *r)
10622 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10623 return WERR_NOT_SUPPORTED;
10626 /****************************************************************
10627 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10628 ****************************************************************/
10630 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
10631 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10633 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10634 return WERR_NOT_SUPPORTED;
10637 /****************************************************************
10638 _spoolss_ReplyOpenPrinter
10639 ****************************************************************/
10641 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
10642 struct spoolss_ReplyOpenPrinter *r)
10644 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10645 return WERR_NOT_SUPPORTED;
10648 /****************************************************************
10649 _spoolss_RouterReplyPrinter
10650 ****************************************************************/
10652 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
10653 struct spoolss_RouterReplyPrinter *r)
10655 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10656 return WERR_NOT_SUPPORTED;
10659 /****************************************************************
10660 _spoolss_ReplyClosePrinter
10661 ****************************************************************/
10663 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
10664 struct spoolss_ReplyClosePrinter *r)
10666 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10667 return WERR_NOT_SUPPORTED;
10670 /****************************************************************
10671 _spoolss_AddPortEx
10672 ****************************************************************/
10674 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
10675 struct spoolss_AddPortEx *r)
10677 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10678 return WERR_NOT_SUPPORTED;
10681 /****************************************************************
10682 _spoolss_RouterFindFirstPrinterChangeNotification
10683 ****************************************************************/
10685 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
10686 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10688 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10689 return WERR_NOT_SUPPORTED;
10692 /****************************************************************
10693 _spoolss_SpoolerInit
10694 ****************************************************************/
10696 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
10697 struct spoolss_SpoolerInit *r)
10699 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10700 return WERR_NOT_SUPPORTED;
10703 /****************************************************************
10704 _spoolss_ResetPrinterEx
10705 ****************************************************************/
10707 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
10708 struct spoolss_ResetPrinterEx *r)
10710 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10711 return WERR_NOT_SUPPORTED;
10714 /****************************************************************
10715 _spoolss_RouterReplyPrinterEx
10716 ****************************************************************/
10718 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
10719 struct spoolss_RouterReplyPrinterEx *r)
10721 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10722 return WERR_NOT_SUPPORTED;
10725 /****************************************************************
10726 _spoolss_44
10727 ****************************************************************/
10729 WERROR _spoolss_44(struct pipes_struct *p,
10730 struct spoolss_44 *r)
10732 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10733 return WERR_NOT_SUPPORTED;
10736 /****************************************************************
10737 _spoolss_SetPort
10738 ****************************************************************/
10740 WERROR _spoolss_SetPort(struct pipes_struct *p,
10741 struct spoolss_SetPort *r)
10743 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10744 return WERR_NOT_SUPPORTED;
10747 /****************************************************************
10748 _spoolss_4a
10749 ****************************************************************/
10751 WERROR _spoolss_4a(struct pipes_struct *p,
10752 struct spoolss_4a *r)
10754 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10755 return WERR_NOT_SUPPORTED;
10758 /****************************************************************
10759 _spoolss_4b
10760 ****************************************************************/
10762 WERROR _spoolss_4b(struct pipes_struct *p,
10763 struct spoolss_4b *r)
10765 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10766 return WERR_NOT_SUPPORTED;
10769 /****************************************************************
10770 _spoolss_4c
10771 ****************************************************************/
10773 WERROR _spoolss_4c(struct pipes_struct *p,
10774 struct spoolss_4c *r)
10776 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10777 return WERR_NOT_SUPPORTED;
10780 /****************************************************************
10781 _spoolss_53
10782 ****************************************************************/
10784 WERROR _spoolss_53(struct pipes_struct *p,
10785 struct spoolss_53 *r)
10787 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10788 return WERR_NOT_SUPPORTED;
10791 /****************************************************************
10792 _spoolss_AddPerMachineConnection
10793 ****************************************************************/
10795 WERROR _spoolss_AddPerMachineConnection(struct pipes_struct *p,
10796 struct spoolss_AddPerMachineConnection *r)
10798 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10799 return WERR_NOT_SUPPORTED;
10802 /****************************************************************
10803 _spoolss_DeletePerMachineConnection
10804 ****************************************************************/
10806 WERROR _spoolss_DeletePerMachineConnection(struct pipes_struct *p,
10807 struct spoolss_DeletePerMachineConnection *r)
10809 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10810 return WERR_NOT_SUPPORTED;
10813 /****************************************************************
10814 _spoolss_EnumPerMachineConnections
10815 ****************************************************************/
10817 WERROR _spoolss_EnumPerMachineConnections(struct pipes_struct *p,
10818 struct spoolss_EnumPerMachineConnections *r)
10820 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10821 return WERR_NOT_SUPPORTED;
10824 /****************************************************************
10825 _spoolss_5a
10826 ****************************************************************/
10828 WERROR _spoolss_5a(struct pipes_struct *p,
10829 struct spoolss_5a *r)
10831 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10832 return WERR_NOT_SUPPORTED;
10835 /****************************************************************
10836 _spoolss_5b
10837 ****************************************************************/
10839 WERROR _spoolss_5b(struct pipes_struct *p,
10840 struct spoolss_5b *r)
10842 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10843 return WERR_NOT_SUPPORTED;
10846 /****************************************************************
10847 _spoolss_5c
10848 ****************************************************************/
10850 WERROR _spoolss_5c(struct pipes_struct *p,
10851 struct spoolss_5c *r)
10853 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10854 return WERR_NOT_SUPPORTED;
10857 /****************************************************************
10858 _spoolss_5d
10859 ****************************************************************/
10861 WERROR _spoolss_5d(struct pipes_struct *p,
10862 struct spoolss_5d *r)
10864 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10865 return WERR_NOT_SUPPORTED;
10868 /****************************************************************
10869 _spoolss_5e
10870 ****************************************************************/
10872 WERROR _spoolss_5e(struct pipes_struct *p,
10873 struct spoolss_5e *r)
10875 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10876 return WERR_NOT_SUPPORTED;
10879 /****************************************************************
10880 _spoolss_5f
10881 ****************************************************************/
10883 WERROR _spoolss_5f(struct pipes_struct *p,
10884 struct spoolss_5f *r)
10886 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10887 return WERR_NOT_SUPPORTED;
10890 /****************************************************************
10891 _spoolss_60
10892 ****************************************************************/
10894 WERROR _spoolss_60(struct pipes_struct *p,
10895 struct spoolss_60 *r)
10897 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10898 return WERR_NOT_SUPPORTED;
10901 /****************************************************************
10902 _spoolss_RpcSendRecvBidiData
10903 ****************************************************************/
10905 WERROR _spoolss_RpcSendRecvBidiData(struct pipes_struct *p,
10906 struct spoolss_RpcSendRecvBidiData *r)
10908 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10909 return WERR_NOT_SUPPORTED;
10912 /****************************************************************
10913 _spoolss_62
10914 ****************************************************************/
10916 WERROR _spoolss_62(struct pipes_struct *p,
10917 struct spoolss_62 *r)
10919 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10920 return WERR_NOT_SUPPORTED;
10923 /****************************************************************
10924 _spoolss_63
10925 ****************************************************************/
10927 WERROR _spoolss_63(struct pipes_struct *p,
10928 struct spoolss_63 *r)
10930 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10931 return WERR_NOT_SUPPORTED;
10934 /****************************************************************
10935 _spoolss_64
10936 ****************************************************************/
10938 WERROR _spoolss_64(struct pipes_struct *p,
10939 struct spoolss_64 *r)
10941 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10942 return WERR_NOT_SUPPORTED;
10945 /****************************************************************
10946 _spoolss_65
10947 ****************************************************************/
10949 WERROR _spoolss_65(struct pipes_struct *p,
10950 struct spoolss_65 *r)
10952 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10953 return WERR_NOT_SUPPORTED;
10956 /****************************************************************
10957 _spoolss_GetCorePrinterDrivers
10958 ****************************************************************/
10960 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10961 struct spoolss_GetCorePrinterDrivers *r)
10963 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10964 return WERR_NOT_SUPPORTED;
10967 /****************************************************************
10968 _spoolss_67
10969 ****************************************************************/
10971 WERROR _spoolss_67(struct pipes_struct *p,
10972 struct spoolss_67 *r)
10974 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10975 return WERR_NOT_SUPPORTED;
10978 /****************************************************************
10979 _spoolss_GetPrinterDriverPackagePath
10980 ****************************************************************/
10982 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10983 struct spoolss_GetPrinterDriverPackagePath *r)
10985 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10986 return WERR_NOT_SUPPORTED;
10989 /****************************************************************
10990 _spoolss_69
10991 ****************************************************************/
10993 WERROR _spoolss_69(struct pipes_struct *p,
10994 struct spoolss_69 *r)
10996 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10997 return WERR_NOT_SUPPORTED;
11000 /****************************************************************
11001 _spoolss_6a
11002 ****************************************************************/
11004 WERROR _spoolss_6a(struct pipes_struct *p,
11005 struct spoolss_6a *r)
11007 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11008 return WERR_NOT_SUPPORTED;
11011 /****************************************************************
11012 _spoolss_6b
11013 ****************************************************************/
11015 WERROR _spoolss_6b(struct pipes_struct *p,
11016 struct spoolss_6b *r)
11018 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11019 return WERR_NOT_SUPPORTED;
11022 /****************************************************************
11023 _spoolss_6c
11024 ****************************************************************/
11026 WERROR _spoolss_6c(struct pipes_struct *p,
11027 struct spoolss_6c *r)
11029 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11030 return WERR_NOT_SUPPORTED;
11033 /****************************************************************
11034 _spoolss_6d
11035 ****************************************************************/
11037 WERROR _spoolss_6d(struct pipes_struct *p,
11038 struct spoolss_6d *r)
11040 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11041 return WERR_NOT_SUPPORTED;
11044 /****************************************************************
11045 _spoolss_RpcGetJobNamedPropertyValue
11046 ****************************************************************/
11048 WERROR _spoolss_RpcGetJobNamedPropertyValue(struct pipes_struct *p,
11049 struct spoolss_RpcGetJobNamedPropertyValue *r)
11051 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11052 return WERR_NOT_SUPPORTED;
11055 /****************************************************************
11056 _spoolss_RpcSetJobNamedProperty
11057 ****************************************************************/
11059 WERROR _spoolss_RpcSetJobNamedProperty(struct pipes_struct *p,
11060 struct spoolss_RpcSetJobNamedProperty *r)
11062 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11063 return WERR_NOT_SUPPORTED;
11066 /****************************************************************
11067 _spoolss_RpcDeleteJobNamedProperty
11068 ****************************************************************/
11070 WERROR _spoolss_RpcDeleteJobNamedProperty(struct pipes_struct *p,
11071 struct spoolss_RpcDeleteJobNamedProperty *r)
11073 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11074 return WERR_NOT_SUPPORTED;
11077 /****************************************************************
11078 _spoolss_RpcEnumJobNamedProperties
11079 ****************************************************************/
11081 WERROR _spoolss_RpcEnumJobNamedProperties(struct pipes_struct *p,
11082 struct spoolss_RpcEnumJobNamedProperties *r)
11084 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11085 return WERR_NOT_SUPPORTED;