s3:rpc_server/spoolss: make use of SPOOLSS_JOB_CONTROL_NOOP
[Samba.git] / source3 / rpc_server / spoolss / srv_spoolss_nt.c
blobd61b072c0482e16d85cad8a2b8d7e6d0281e3a9a
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_command(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_printable(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 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
850 struct tm *t,
851 const char **pp,
852 uint32_t *plen)
854 struct spoolss_Time st;
855 uint32_t len = 16;
856 char *p;
858 if (!init_systemtime(&st, t)) {
859 return;
862 p = talloc_array(mem_ctx, char, len);
863 if (!p) {
864 return;
868 * Systemtime must be linearized as a set of UINT16's.
869 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
872 SSVAL(p, 0, st.year);
873 SSVAL(p, 2, st.month);
874 SSVAL(p, 4, st.day_of_week);
875 SSVAL(p, 6, st.day);
876 SSVAL(p, 8, st.hour);
877 SSVAL(p, 10, st.minute);
878 SSVAL(p, 12, st.second);
879 SSVAL(p, 14, st.millisecond);
881 *pp = p;
882 *plen = len;
885 /* Convert a notification message to a struct spoolss_Notify */
887 static void notify_one_value(struct spoolss_notify_msg *msg,
888 struct spoolss_Notify *data,
889 TALLOC_CTX *mem_ctx)
891 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
894 static void notify_string(struct spoolss_notify_msg *msg,
895 struct spoolss_Notify *data,
896 TALLOC_CTX *mem_ctx)
898 /* The length of the message includes the trailing \0 */
900 data->data.string.size = msg->len * 2;
901 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
902 if (!data->data.string.string) {
903 data->data.string.size = 0;
904 return;
908 static void notify_system_time(struct spoolss_notify_msg *msg,
909 struct spoolss_Notify *data,
910 TALLOC_CTX *mem_ctx)
912 data->data.string.string = NULL;
913 data->data.string.size = 0;
915 if (msg->len != sizeof(time_t)) {
916 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
917 msg->len));
918 return;
921 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
922 &data->data.string.string,
923 &data->data.string.size);
926 struct notify2_message_table {
927 const char *name;
928 void (*fn)(struct spoolss_notify_msg *msg,
929 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
932 static struct notify2_message_table printer_notify_table[] = {
933 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
934 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
935 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
936 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
937 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
938 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
939 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
940 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
941 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
942 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
943 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
944 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
945 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
946 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
947 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
948 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
949 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
950 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
951 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
954 static struct notify2_message_table job_notify_table[] = {
955 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
956 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
957 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
958 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
959 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
960 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
961 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
962 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
963 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
964 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
965 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
966 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
967 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
968 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
969 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
970 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
971 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
972 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
973 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
974 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
975 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
976 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
977 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
978 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
982 /***********************************************************************
983 Allocate talloc context for container object
984 **********************************************************************/
986 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
988 if ( !ctr )
989 return;
991 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
993 return;
996 /***********************************************************************
997 release all allocated memory and zero out structure
998 **********************************************************************/
1000 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1002 if ( !ctr )
1003 return;
1005 if ( ctr->ctx )
1006 talloc_destroy(ctr->ctx);
1008 ZERO_STRUCTP(ctr);
1010 return;
1013 /***********************************************************************
1014 **********************************************************************/
1016 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1018 if ( !ctr )
1019 return NULL;
1021 return ctr->ctx;
1024 /***********************************************************************
1025 **********************************************************************/
1027 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1029 if ( !ctr || !ctr->msg_groups )
1030 return NULL;
1032 if ( idx >= ctr->num_groups )
1033 return NULL;
1035 return &ctr->msg_groups[idx];
1039 /***********************************************************************
1040 How many groups of change messages do we have ?
1041 **********************************************************************/
1043 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1045 if ( !ctr )
1046 return 0;
1048 return ctr->num_groups;
1051 /***********************************************************************
1052 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1053 **********************************************************************/
1055 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
1057 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
1058 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
1059 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
1060 int i, new_slot;
1062 if ( !ctr || !msg )
1063 return 0;
1065 /* loop over all groups looking for a matching printer name */
1067 for ( i=0; i<ctr->num_groups; i++ ) {
1068 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
1069 break;
1072 /* add a new group? */
1074 if ( i == ctr->num_groups ) {
1075 ctr->num_groups++;
1077 if ( !(groups = talloc_realloc( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
1078 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1079 return 0;
1081 ctr->msg_groups = groups;
1083 /* clear the new entry and set the printer name */
1085 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
1086 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
1089 /* add the change messages; 'i' is the correct index now regardless */
1091 msg_grp = &ctr->msg_groups[i];
1093 msg_grp->num_msgs++;
1095 if ( !(msg_list = talloc_realloc( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
1096 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
1097 return 0;
1099 msg_grp->msgs = msg_list;
1101 new_slot = msg_grp->num_msgs-1;
1102 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
1104 /* need to allocate own copy of data */
1106 if ( msg->len != 0 )
1107 msg_grp->msgs[new_slot].notify.data = (char *)
1108 talloc_memdup( ctr->ctx, msg->notify.data, msg->len );
1110 return ctr->num_groups;
1113 static void construct_info_data(struct spoolss_Notify *info_data,
1114 enum spoolss_NotifyType type,
1115 uint16_t field, int id);
1117 /***********************************************************************
1118 Send a change notication message on all handles which have a call
1119 back registered
1120 **********************************************************************/
1122 static int build_notify2_messages(TALLOC_CTX *mem_ctx,
1123 struct printer_handle *prn_hnd,
1124 SPOOLSS_NOTIFY_MSG *messages,
1125 uint32_t num_msgs,
1126 struct spoolss_Notify **_notifies,
1127 int *_count)
1129 struct spoolss_Notify *notifies;
1130 SPOOLSS_NOTIFY_MSG *msg;
1131 int count = 0;
1132 uint32_t id;
1133 int i;
1135 notifies = talloc_zero_array(mem_ctx,
1136 struct spoolss_Notify, num_msgs);
1137 if (!notifies) {
1138 return ENOMEM;
1141 for (i = 0; i < num_msgs; i++) {
1143 msg = &messages[i];
1145 /* Are we monitoring this event? */
1147 if (!is_monitoring_event(prn_hnd, msg->type, msg->field)) {
1148 continue;
1151 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1152 "for printer [%s]\n",
1153 msg->type, msg->field, prn_hnd->sharename));
1156 * if the is a printer notification handle and not a job
1157 * notification type, then set the id to 0.
1158 * Otherwise just use what was specified in the message.
1160 * When registering change notification on a print server
1161 * handle we always need to send back the id (snum) matching
1162 * the printer for which the change took place.
1163 * For change notify registered on a printer handle,
1164 * this does not matter and the id should be 0.
1166 * --jerry
1169 if ((msg->type == PRINTER_NOTIFY_TYPE) &&
1170 (prn_hnd->printer_type == SPLHND_PRINTER)) {
1171 id = 0;
1172 } else {
1173 id = msg->id;
1176 /* Convert unix jobid to smb jobid */
1178 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1179 id = sysjob_to_jobid(msg->id);
1181 if (id == -1) {
1182 DEBUG(3, ("no such unix jobid %d\n",
1183 msg->id));
1184 continue;
1188 construct_info_data(&notifies[count],
1189 msg->type, msg->field, id);
1191 switch(msg->type) {
1192 case PRINTER_NOTIFY_TYPE:
1193 if (printer_notify_table[msg->field].fn) {
1194 printer_notify_table[msg->field].fn(msg,
1195 &notifies[count], mem_ctx);
1197 break;
1199 case JOB_NOTIFY_TYPE:
1200 if (job_notify_table[msg->field].fn) {
1201 job_notify_table[msg->field].fn(msg,
1202 &notifies[count], mem_ctx);
1204 break;
1206 default:
1207 DEBUG(5, ("Unknown notification type %d\n",
1208 msg->type));
1209 continue;
1212 count++;
1215 *_notifies = notifies;
1216 *_count = count;
1218 return 0;
1221 static int send_notify2_printer(TALLOC_CTX *mem_ctx,
1222 struct printer_handle *prn_hnd,
1223 SPOOLSS_NOTIFY_MSG_GROUP *msg_group)
1225 struct spoolss_Notify *notifies;
1226 int count = 0;
1227 union spoolss_ReplyPrinterInfo info;
1228 struct spoolss_NotifyInfo info0;
1229 uint32_t reply_result;
1230 NTSTATUS status;
1231 WERROR werr;
1232 int ret;
1234 /* Is there notification on this handle? */
1235 if (prn_hnd->notify.cli_chan == NULL ||
1236 prn_hnd->notify.cli_chan->cli_pipe == NULL ||
1237 prn_hnd->notify.cli_chan->cli_pipe->binding_handle == NULL ||
1238 prn_hnd->notify.cli_chan->active_connections == 0) {
1239 return 0;
1242 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1243 prn_hnd->servername, prn_hnd->sharename));
1245 /* For this printer? Print servers always receive notifications. */
1246 if ((prn_hnd->printer_type == SPLHND_PRINTER) &&
1247 (!strequal(msg_group->printername, prn_hnd->sharename))) {
1248 return 0;
1251 DEBUG(10,("Our printer\n"));
1253 /* build the array of change notifications */
1254 ret = build_notify2_messages(mem_ctx, prn_hnd,
1255 msg_group->msgs,
1256 msg_group->num_msgs,
1257 &notifies, &count);
1258 if (ret) {
1259 return ret;
1262 info0.version = 0x2;
1263 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1264 info0.count = count;
1265 info0.notifies = notifies;
1267 info.info0 = &info0;
1269 status = dcerpc_spoolss_RouterReplyPrinterEx(
1270 prn_hnd->notify.cli_chan->cli_pipe->binding_handle,
1271 mem_ctx,
1272 &prn_hnd->notify.cli_hnd,
1273 prn_hnd->notify.change, /* color */
1274 prn_hnd->notify.flags,
1275 &reply_result,
1276 0, /* reply_type, must be 0 */
1277 info, &werr);
1278 if (!NT_STATUS_IS_OK(status)) {
1279 DEBUG(1, ("dcerpc_spoolss_RouterReplyPrinterEx to client: %s "
1280 "failed: %s\n",
1281 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1282 nt_errstr(status)));
1283 werr = ntstatus_to_werror(status);
1284 } else if (!W_ERROR_IS_OK(werr)) {
1285 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1286 "failed: %s\n",
1287 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1288 win_errstr(werr)));
1290 switch (reply_result) {
1291 case 0:
1292 break;
1293 case PRINTER_NOTIFY_INFO_DISCARDED:
1294 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1295 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1296 break;
1297 default:
1298 break;
1301 return 0;
1304 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1306 struct printer_handle *p;
1307 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
1308 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
1309 int ret;
1311 if ( !msg_group ) {
1312 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1313 return;
1316 if (!msg_group->msgs) {
1317 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1318 return;
1321 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
1323 /* loop over all printers */
1325 for (p = printers_list; p; p = p->next) {
1326 ret = send_notify2_printer(mem_ctx, p, msg_group);
1327 if (ret) {
1328 goto done;
1332 done:
1333 DEBUG(8,("send_notify2_changes: Exit...\n"));
1334 return;
1337 /***********************************************************************
1338 **********************************************************************/
1340 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1343 uint32_t tv_sec, tv_usec;
1344 size_t offset = 0;
1346 /* Unpack message */
1348 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1349 msg->printer);
1351 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1352 &tv_sec, &tv_usec,
1353 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1355 if (msg->len == 0)
1356 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1357 &msg->notify.value[0], &msg->notify.value[1]);
1358 else
1359 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1360 &msg->len, &msg->notify.data);
1362 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1363 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1365 tv->tv_sec = tv_sec;
1366 tv->tv_usec = tv_usec;
1368 if (msg->len == 0)
1369 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1370 msg->notify.value[1]));
1371 else
1372 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1374 return true;
1377 /********************************************************************
1378 Receive a notify2 message list
1379 ********************************************************************/
1381 static void receive_notify2_message_list(struct messaging_context *msg,
1382 void *private_data,
1383 uint32_t msg_type,
1384 struct server_id server_id,
1385 DATA_BLOB *data)
1387 size_t msg_count, i;
1388 char *buf = (char *)data->data;
1389 char *msg_ptr;
1390 size_t msg_len;
1391 SPOOLSS_NOTIFY_MSG notify;
1392 SPOOLSS_NOTIFY_MSG_CTR messages;
1393 int num_groups;
1395 if (data->length < 4) {
1396 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1397 return;
1400 msg_count = IVAL(buf, 0);
1401 msg_ptr = buf + 4;
1403 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1405 if (msg_count == 0) {
1406 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1407 return;
1410 /* initialize the container */
1412 ZERO_STRUCT( messages );
1413 notify_msg_ctr_init( &messages );
1416 * build message groups for each printer identified
1417 * in a change_notify msg. Remember that a PCN message
1418 * includes the handle returned for the srv_spoolss_replyopenprinter()
1419 * call. Therefore messages are grouped according to printer handle.
1422 for ( i=0; i<msg_count; i++ ) {
1423 struct timeval msg_tv;
1425 if (msg_ptr + 4 - buf > data->length) {
1426 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1427 return;
1430 msg_len = IVAL(msg_ptr,0);
1431 msg_ptr += 4;
1433 if (msg_ptr + msg_len - buf > data->length) {
1434 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1435 return;
1438 /* unpack messages */
1440 ZERO_STRUCT( notify );
1441 notify2_unpack_msg( &notify, &msg_tv, msg_ptr, msg_len );
1442 msg_ptr += msg_len;
1444 /* add to correct list in container */
1446 notify_msg_ctr_addmsg( &messages, &notify );
1448 /* free memory that might have been allocated by notify2_unpack_msg() */
1450 if ( notify.len != 0 )
1451 SAFE_FREE( notify.notify.data );
1454 /* process each group of messages */
1456 num_groups = notify_msg_ctr_numgroups( &messages );
1457 for ( i=0; i<num_groups; i++ )
1458 send_notify2_changes( &messages, i );
1461 /* cleanup */
1463 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1464 (uint32_t)msg_count ));
1466 notify_msg_ctr_destroy( &messages );
1468 return;
1471 /********************************************************************
1472 Send a message to ourself about new driver being installed
1473 so we can upgrade the information for each printer bound to this
1474 driver
1475 ********************************************************************/
1477 static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
1478 struct messaging_context *msg_ctx)
1480 int len = strlen(drivername);
1482 if (!len)
1483 return false;
1485 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1486 drivername));
1488 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
1489 MSG_PRINTER_DRVUPGRADE,
1490 (const uint8_t *)drivername, len+1);
1492 return true;
1495 void srv_spoolss_cleanup(void)
1497 struct printer_session_counter *session_counter;
1499 for (session_counter = counter_list;
1500 session_counter != NULL;
1501 session_counter = counter_list) {
1502 DLIST_REMOVE(counter_list, session_counter);
1503 TALLOC_FREE(session_counter);
1507 /**********************************************************************
1508 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1509 over all printers, upgrading ones as necessary
1510 This is now *ONLY* called inside the background lpq updater. JRA.
1511 **********************************************************************/
1513 void do_drv_upgrade_printer(struct messaging_context *msg,
1514 void *private_data,
1515 uint32_t msg_type,
1516 struct server_id server_id,
1517 DATA_BLOB *data)
1519 TALLOC_CTX *tmp_ctx;
1520 const struct auth_session_info *session_info = get_session_info_system();
1521 struct spoolss_PrinterInfo2 *pinfo2;
1522 WERROR result;
1523 const char *drivername;
1524 int snum;
1525 int n_services = lp_numservices();
1526 struct dcerpc_binding_handle *b = NULL;
1528 tmp_ctx = talloc_new(NULL);
1529 if (!tmp_ctx) return;
1531 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, data->length);
1532 if (!drivername) {
1533 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1534 goto done;
1537 DEBUG(10, ("do_drv_upgrade_printer: "
1538 "Got message for new driver [%s]\n", drivername));
1540 /* Iterate the printer list */
1542 for (snum = 0; snum < n_services; snum++) {
1543 if (!lp_snum_ok(snum) || !lp_printable(snum)) {
1544 continue;
1547 /* ignore [printers] share */
1548 if (strequal(lp_const_servicename(snum), "printers")) {
1549 continue;
1552 if (b == NULL) {
1553 result = winreg_printer_binding_handle(tmp_ctx,
1554 session_info,
1555 msg,
1556 &b);
1557 if (!W_ERROR_IS_OK(result)) {
1558 break;
1562 result = winreg_get_printer(tmp_ctx, b,
1563 lp_const_servicename(snum),
1564 &pinfo2);
1566 if (!W_ERROR_IS_OK(result)) {
1567 continue;
1570 if (!pinfo2->drivername) {
1571 continue;
1574 if (strcmp(drivername, pinfo2->drivername) != 0) {
1575 continue;
1578 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1580 /* all we care about currently is the change_id */
1581 result = winreg_printer_update_changeid(tmp_ctx, b,
1582 pinfo2->printername);
1584 if (!W_ERROR_IS_OK(result)) {
1585 DEBUG(3, ("do_drv_upgrade_printer: "
1586 "Failed to update changeid [%s]\n",
1587 win_errstr(result)));
1591 /* all done */
1592 done:
1593 talloc_free(tmp_ctx);
1596 /********************************************************************
1597 Update the cache for all printq's with a registered client
1598 connection
1599 ********************************************************************/
1601 void update_monitored_printq_cache(struct messaging_context *msg_ctx)
1603 struct printer_handle *printer = printers_list;
1604 int snum;
1606 /* loop through all printers and update the cache where
1607 a client is connected */
1608 while (printer) {
1609 if ((printer->printer_type == SPLHND_PRINTER) &&
1610 ((printer->notify.cli_chan != NULL) &&
1611 (printer->notify.cli_chan->active_connections > 0))) {
1612 snum = print_queue_snum(printer->sharename);
1613 print_queue_status(msg_ctx, snum, NULL, NULL);
1616 printer = printer->next;
1619 return;
1622 /****************************************************************
1623 _spoolss_OpenPrinter
1624 ****************************************************************/
1626 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1627 struct spoolss_OpenPrinter *r)
1629 struct spoolss_OpenPrinterEx e;
1630 struct spoolss_UserLevel1 level1;
1631 WERROR werr;
1633 ZERO_STRUCT(level1);
1635 e.in.printername = r->in.printername;
1636 e.in.datatype = r->in.datatype;
1637 e.in.devmode_ctr = r->in.devmode_ctr;
1638 e.in.access_mask = r->in.access_mask;
1639 e.in.userlevel_ctr.level = 1;
1640 e.in.userlevel_ctr.user_info.level1 = &level1;
1642 e.out.handle = r->out.handle;
1644 werr = _spoolss_OpenPrinterEx(p, &e);
1646 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1647 /* OpenPrinterEx returns this for a bad
1648 * printer name. We must return WERR_INVALID_PRINTER_NAME
1649 * instead.
1651 werr = WERR_INVALID_PRINTER_NAME;
1654 return werr;
1657 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1658 struct spoolss_DeviceMode *orig,
1659 struct spoolss_DeviceMode **dest)
1661 struct spoolss_DeviceMode *dm;
1663 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1664 if (!dm) {
1665 return WERR_NOMEM;
1668 /* copy all values, then duplicate strings and structs */
1669 *dm = *orig;
1671 dm->devicename = talloc_strdup(dm, orig->devicename);
1672 if (!dm->devicename) {
1673 return WERR_NOMEM;
1675 dm->formname = talloc_strdup(dm, orig->formname);
1676 if (!dm->formname) {
1677 return WERR_NOMEM;
1679 if (orig->driverextra_data.data) {
1680 dm->driverextra_data.data =
1681 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1682 orig->driverextra_data.length);
1683 if (!dm->driverextra_data.data) {
1684 return WERR_NOMEM;
1688 *dest = dm;
1689 return WERR_OK;
1692 /****************************************************************
1693 _spoolss_OpenPrinterEx
1694 ****************************************************************/
1696 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1697 struct spoolss_OpenPrinterEx *r)
1699 int snum;
1700 char *raddr;
1701 char *rhost;
1702 struct printer_handle *Printer=NULL;
1703 WERROR result;
1704 int rc;
1706 if (!r->in.printername) {
1707 return WERR_INVALID_PARAM;
1710 if (!*r->in.printername) {
1711 return WERR_INVALID_PARAM;
1714 if (r->in.userlevel_ctr.level > 3) {
1715 return WERR_INVALID_PARAM;
1717 if ((r->in.userlevel_ctr.level == 1 && !r->in.userlevel_ctr.user_info.level1) ||
1718 (r->in.userlevel_ctr.level == 2 && !r->in.userlevel_ctr.user_info.level2) ||
1719 (r->in.userlevel_ctr.level == 3 && !r->in.userlevel_ctr.user_info.level3)) {
1720 return WERR_INVALID_PARAM;
1724 * The printcap printer share inventory is updated on client
1725 * enumeration. For clients that do not perform enumeration prior to
1726 * access, such as cupssmbadd, we reinitialise the printer share
1727 * inventory on open as well.
1729 become_root();
1730 delete_and_reload_printers(server_event_context(), p->msg_ctx);
1731 unbecome_root();
1733 /* some sanity check because you can open a printer or a print server */
1734 /* aka: \\server\printer or \\server */
1736 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1738 result = open_printer_hnd(p, r->out.handle, r->in.printername, 0);
1739 if (!W_ERROR_IS_OK(result)) {
1740 DEBUG(3,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1741 "for printer %s\n", r->in.printername));
1742 ZERO_STRUCTP(r->out.handle);
1743 return result;
1746 Printer = find_printer_index_by_hnd(p, r->out.handle);
1747 if ( !Printer ) {
1748 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1749 "handle we created for printer %s\n", r->in.printername));
1750 close_printer_handle(p, r->out.handle);
1751 ZERO_STRUCTP(r->out.handle);
1752 return WERR_INVALID_PARAM;
1756 * First case: the user is opening the print server:
1758 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1759 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1761 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1762 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1763 * or if the user is listed in the smb.conf printer admin parameter.
1765 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1766 * client view printer folder, but does not show the MSAPW.
1768 * Note: this test needs code to check access rights here too. Jeremy
1769 * could you look at this?
1771 * Second case: the user is opening a printer:
1772 * NT doesn't let us connect to a printer if the connecting user
1773 * doesn't have print permission.
1775 * Third case: user is opening a Port Monitor
1776 * access checks same as opening a handle to the print server.
1779 switch (Printer->printer_type )
1781 case SPLHND_SERVER:
1782 case SPLHND_PORTMON_TCP:
1783 case SPLHND_PORTMON_LOCAL:
1784 /* Printserver handles use global struct... */
1786 snum = -1;
1788 /* Map standard access rights to object specific access rights */
1790 se_map_standard(&r->in.access_mask,
1791 &printserver_std_mapping);
1793 /* Deny any object specific bits that don't apply to print
1794 servers (i.e printer and job specific bits) */
1796 r->in.access_mask &= SEC_MASK_SPECIFIC;
1798 if (r->in.access_mask &
1799 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1800 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1801 close_printer_handle(p, r->out.handle);
1802 ZERO_STRUCTP(r->out.handle);
1803 return WERR_ACCESS_DENIED;
1806 /* Allow admin access */
1808 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1810 if (!lp_show_add_printer_wizard()) {
1811 close_printer_handle(p, r->out.handle);
1812 ZERO_STRUCTP(r->out.handle);
1813 return WERR_ACCESS_DENIED;
1816 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1817 and not a printer admin, then fail */
1819 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
1820 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
1821 !nt_token_check_sid(&global_sid_Builtin_Print_Operators,
1822 p->session_info->security_token)) {
1823 close_printer_handle(p, r->out.handle);
1824 ZERO_STRUCTP(r->out.handle);
1825 DEBUG(3,("access DENIED as user is not root, "
1826 "has no printoperator privilege, "
1827 "not a member of the printoperator builtin group and "
1828 "is not in printer admin list"));
1829 return WERR_ACCESS_DENIED;
1832 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1834 else
1836 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1839 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1840 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1842 /* We fall through to return WERR_OK */
1843 break;
1845 case SPLHND_PRINTER:
1846 /* NT doesn't let us connect to a printer if the connecting user
1847 doesn't have print permission. */
1849 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1850 close_printer_handle(p, r->out.handle);
1851 ZERO_STRUCTP(r->out.handle);
1852 return WERR_BADFID;
1855 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1856 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1859 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1861 /* map an empty access mask to the minimum access mask */
1862 if (r->in.access_mask == 0x0)
1863 r->in.access_mask = PRINTER_ACCESS_USE;
1866 * If we are not serving the printer driver for this printer,
1867 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1868 * will keep NT clients happy --jerry
1871 if (lp_use_client_driver(snum)
1872 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1874 r->in.access_mask = PRINTER_ACCESS_USE;
1877 /* check smb.conf parameters and the the sec_desc */
1878 raddr = tsocket_address_inet_addr_string(p->remote_address,
1879 p->mem_ctx);
1880 if (raddr == NULL) {
1881 return WERR_NOMEM;
1884 rc = get_remote_hostname(p->remote_address,
1885 &rhost,
1886 p->mem_ctx);
1887 if (rc < 0) {
1888 return WERR_NOMEM;
1890 if (strequal(rhost, "UNKNOWN")) {
1891 rhost = raddr;
1894 if (!allow_access(lp_hosts_deny(snum), lp_hosts_allow(snum),
1895 rhost, raddr)) {
1896 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1897 ZERO_STRUCTP(r->out.handle);
1898 return WERR_ACCESS_DENIED;
1901 if (!user_ok_token(uidtoname(p->session_info->unix_token->uid), NULL,
1902 p->session_info->security_token, snum) ||
1903 !W_ERROR_IS_OK(print_access_check(p->session_info,
1904 p->msg_ctx,
1905 snum,
1906 r->in.access_mask))) {
1907 DEBUG(3, ("access DENIED for printer open\n"));
1908 close_printer_handle(p, r->out.handle);
1909 ZERO_STRUCTP(r->out.handle);
1910 return WERR_ACCESS_DENIED;
1913 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1914 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1915 close_printer_handle(p, r->out.handle);
1916 ZERO_STRUCTP(r->out.handle);
1917 return WERR_ACCESS_DENIED;
1920 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1921 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1922 else
1923 r->in.access_mask = PRINTER_ACCESS_USE;
1925 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1926 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1928 winreg_create_printer_internal(p->mem_ctx,
1929 get_session_info_system(),
1930 p->msg_ctx,
1931 lp_const_servicename(snum));
1933 break;
1935 default:
1936 /* sanity check to prevent programmer error */
1937 ZERO_STRUCTP(r->out.handle);
1938 return WERR_BADFID;
1941 Printer->access_granted = r->in.access_mask;
1944 * If the client sent a devmode in the OpenPrinter() call, then
1945 * save it here in case we get a job submission on this handle
1948 if ((Printer->printer_type != SPLHND_SERVER)
1949 && (r->in.devmode_ctr.devmode != NULL)) {
1950 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1951 &Printer->devmode);
1954 return WERR_OK;
1957 /****************************************************************
1958 _spoolss_ClosePrinter
1959 ****************************************************************/
1961 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1962 struct spoolss_ClosePrinter *r)
1964 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1966 if (Printer && Printer->document_started) {
1967 struct spoolss_EndDocPrinter e;
1969 e.in.handle = r->in.handle;
1971 _spoolss_EndDocPrinter(p, &e);
1974 if (!close_printer_handle(p, r->in.handle))
1975 return WERR_BADFID;
1977 /* clear the returned printer handle. Observed behavior
1978 from Win2k server. Don't think this really matters.
1979 Previous code just copied the value of the closed
1980 handle. --jerry */
1982 ZERO_STRUCTP(r->out.handle);
1984 return WERR_OK;
1987 /****************************************************************
1988 _spoolss_DeletePrinter
1989 ****************************************************************/
1991 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1992 struct spoolss_DeletePrinter *r)
1994 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1995 WERROR result;
1996 int snum;
1998 if (Printer && Printer->document_started) {
1999 struct spoolss_EndDocPrinter e;
2001 e.in.handle = r->in.handle;
2003 _spoolss_EndDocPrinter(p, &e);
2006 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
2007 winreg_delete_printer_key_internal(p->mem_ctx,
2008 get_session_info_system(),
2009 p->msg_ctx,
2010 lp_const_servicename(snum),
2011 "");
2014 result = delete_printer_handle(p, r->in.handle);
2016 return result;
2019 /*******************************************************************
2020 * static function to lookup the version id corresponding to an
2021 * long architecture string
2022 ******************************************************************/
2024 static const struct print_architecture_table_node archi_table[]= {
2026 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
2027 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
2028 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
2029 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
2030 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
2031 {"Windows IA64", SPL_ARCH_IA64, 3 },
2032 {"Windows x64", SPL_ARCH_X64, 3 },
2033 {NULL, "", -1 }
2036 static const int drv_cversion[] = {SPOOLSS_DRIVER_VERSION_9X,
2037 SPOOLSS_DRIVER_VERSION_NT35,
2038 SPOOLSS_DRIVER_VERSION_NT4,
2039 SPOOLSS_DRIVER_VERSION_200X,
2040 -1};
2042 static int get_version_id(const char *arch)
2044 int i;
2046 for (i=0; archi_table[i].long_archi != NULL; i++)
2048 if (strcmp(arch, archi_table[i].long_archi) == 0)
2049 return (archi_table[i].version);
2052 return -1;
2055 /****************************************************************
2056 _spoolss_DeletePrinterDriver
2057 ****************************************************************/
2059 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
2060 struct spoolss_DeletePrinterDriver *r)
2063 struct spoolss_DriverInfo8 *info = NULL;
2064 int version;
2065 WERROR status;
2066 struct dcerpc_binding_handle *b;
2067 TALLOC_CTX *tmp_ctx = NULL;
2068 int i;
2069 bool found;
2071 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2072 and not a printer admin, then fail */
2074 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
2075 !security_token_has_privilege(p->session_info->security_token,
2076 SEC_PRIV_PRINT_OPERATOR)) {
2077 return WERR_ACCESS_DENIED;
2080 /* check that we have a valid driver name first */
2082 if ((version = get_version_id(r->in.architecture)) == -1) {
2083 return WERR_INVALID_ENVIRONMENT;
2086 tmp_ctx = talloc_new(p->mem_ctx);
2087 if (!tmp_ctx) {
2088 return WERR_NOMEM;
2091 status = winreg_printer_binding_handle(tmp_ctx,
2092 get_session_info_system(),
2093 p->msg_ctx,
2094 &b);
2095 if (!W_ERROR_IS_OK(status)) {
2096 goto done;
2099 for (found = false, i = 0; drv_cversion[i] >= 0; i++) {
2100 status = winreg_get_driver(tmp_ctx, b,
2101 r->in.architecture, r->in.driver,
2102 drv_cversion[i], &info);
2103 if (!W_ERROR_IS_OK(status)) {
2104 DEBUG(5, ("skipping del of driver with version %d\n",
2105 drv_cversion[i]));
2106 continue;
2108 found = true;
2110 if (printer_driver_in_use(tmp_ctx, b, info)) {
2111 status = WERR_PRINTER_DRIVER_IN_USE;
2112 goto done;
2115 status = winreg_del_driver(tmp_ctx, b, info, drv_cversion[i]);
2116 if (!W_ERROR_IS_OK(status)) {
2117 DEBUG(0, ("failed del of driver with version %d\n",
2118 drv_cversion[i]));
2119 goto done;
2122 if (found == false) {
2123 DEBUG(0, ("driver %s not found for deletion\n", r->in.driver));
2124 status = WERR_UNKNOWN_PRINTER_DRIVER;
2125 } else {
2126 status = WERR_OK;
2129 done:
2130 talloc_free(tmp_ctx);
2132 return status;
2135 static WERROR spoolss_dpd_version(TALLOC_CTX *mem_ctx,
2136 struct pipes_struct *p,
2137 struct spoolss_DeletePrinterDriverEx *r,
2138 struct dcerpc_binding_handle *b,
2139 struct spoolss_DriverInfo8 *info)
2141 WERROR status;
2142 bool delete_files;
2144 if (printer_driver_in_use(mem_ctx, b, info)) {
2145 status = WERR_PRINTER_DRIVER_IN_USE;
2146 goto done;
2150 * we have a couple of cases to consider.
2151 * (1) Are any files in use? If so and DPD_DELETE_ALL_FILES is set,
2152 * then the delete should fail if **any** files overlap with
2153 * other drivers
2154 * (2) If DPD_DELETE_UNUSED_FILES is set, then delete all
2155 * non-overlapping files
2156 * (3) If neither DPD_DELETE_ALL_FILES nor DPD_DELETE_UNUSED_FILES
2157 * are set, then do not delete any files
2158 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2161 delete_files = r->in.delete_flags
2162 & (DPD_DELETE_ALL_FILES | DPD_DELETE_UNUSED_FILES);
2165 if (delete_files) {
2166 bool in_use = printer_driver_files_in_use(mem_ctx, b, info);
2167 if (in_use && (r->in.delete_flags & DPD_DELETE_ALL_FILES)) {
2168 status = WERR_PRINTER_DRIVER_IN_USE;
2169 goto done;
2172 * printer_driver_files_in_use() has trimmed overlapping files
2173 * from info so they are not removed on DPD_DELETE_UNUSED_FILES
2178 status = winreg_del_driver(mem_ctx, b, info, info->version);
2179 if (!W_ERROR_IS_OK(status)) {
2180 goto done;
2184 * now delete any associated files if delete_files is
2185 * true. Even if this part failes, we return succes
2186 * because the driver doesn not exist any more
2188 if (delete_files) {
2189 delete_driver_files(p->session_info, info);
2192 done:
2193 return status;
2196 /****************************************************************
2197 _spoolss_DeletePrinterDriverEx
2198 ****************************************************************/
2200 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
2201 struct spoolss_DeletePrinterDriverEx *r)
2203 struct spoolss_DriverInfo8 *info = NULL;
2204 WERROR status;
2205 struct dcerpc_binding_handle *b;
2206 TALLOC_CTX *tmp_ctx = NULL;
2207 int i;
2208 bool found;
2210 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2211 and not a printer admin, then fail */
2213 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
2214 !security_token_has_privilege(p->session_info->security_token,
2215 SEC_PRIV_PRINT_OPERATOR)) {
2216 return WERR_ACCESS_DENIED;
2219 /* check that we have a valid driver name first */
2220 if (get_version_id(r->in.architecture) == -1) {
2221 /* this is what NT returns */
2222 return WERR_INVALID_ENVIRONMENT;
2225 tmp_ctx = talloc_new(p->mem_ctx);
2226 if (!tmp_ctx) {
2227 return WERR_NOMEM;
2230 status = winreg_printer_binding_handle(tmp_ctx,
2231 get_session_info_system(),
2232 p->msg_ctx,
2233 &b);
2234 if (!W_ERROR_IS_OK(status)) {
2235 goto done;
2238 for (found = false, i = 0; drv_cversion[i] >= 0; i++) {
2239 if ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2240 && (drv_cversion[i] != r->in.version)) {
2241 continue;
2244 /* check if a driver with this version exists before delete */
2245 status = winreg_get_driver(tmp_ctx, b,
2246 r->in.architecture, r->in.driver,
2247 drv_cversion[i], &info);
2248 if (!W_ERROR_IS_OK(status)) {
2249 DEBUG(5, ("skipping del of driver with version %d\n",
2250 drv_cversion[i]));
2251 continue;
2253 found = true;
2255 status = spoolss_dpd_version(tmp_ctx, p, r, b, info);
2256 if (!W_ERROR_IS_OK(status)) {
2257 DEBUG(0, ("failed to delete driver with version %d\n",
2258 drv_cversion[i]));
2259 goto done;
2262 if (found == false) {
2263 DEBUG(0, ("driver %s not found for deletion\n", r->in.driver));
2264 status = WERR_UNKNOWN_PRINTER_DRIVER;
2265 } else {
2266 status = WERR_OK;
2269 done:
2270 talloc_free(tmp_ctx);
2271 return status;
2275 /********************************************************************
2276 GetPrinterData on a printer server Handle.
2277 ********************************************************************/
2279 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2280 const char *value,
2281 enum winreg_Type *type,
2282 union spoolss_PrinterData *data)
2284 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2286 if (!strcasecmp_m(value, "W3SvcInstalled")) {
2287 *type = REG_DWORD;
2288 SIVAL(&data->value, 0, 0x00);
2289 return WERR_OK;
2292 if (!strcasecmp_m(value, "BeepEnabled")) {
2293 *type = REG_DWORD;
2294 SIVAL(&data->value, 0, 0x00);
2295 return WERR_OK;
2298 if (!strcasecmp_m(value, "EventLog")) {
2299 *type = REG_DWORD;
2300 /* formally was 0x1b */
2301 SIVAL(&data->value, 0, 0x00);
2302 return WERR_OK;
2305 if (!strcasecmp_m(value, "NetPopup")) {
2306 *type = REG_DWORD;
2307 SIVAL(&data->value, 0, 0x00);
2308 return WERR_OK;
2311 if (!strcasecmp_m(value, "MajorVersion")) {
2312 *type = REG_DWORD;
2314 /* Windows NT 4.0 seems to not allow uploading of drivers
2315 to a server that reports 0x3 as the MajorVersion.
2316 need to investigate more how Win2k gets around this .
2317 -- jerry */
2319 if (RA_WINNT == get_remote_arch()) {
2320 SIVAL(&data->value, 0, 0x02);
2321 } else {
2322 SIVAL(&data->value, 0, 0x03);
2325 return WERR_OK;
2328 if (!strcasecmp_m(value, "MinorVersion")) {
2329 *type = REG_DWORD;
2330 SIVAL(&data->value, 0, 0x00);
2331 return WERR_OK;
2334 /* REG_BINARY
2335 * uint32_t size = 0x114
2336 * uint32_t major = 5
2337 * uint32_t minor = [0|1]
2338 * uint32_t build = [2195|2600]
2339 * extra unicode string = e.g. "Service Pack 3"
2341 if (!strcasecmp_m(value, "OSVersion")) {
2342 DATA_BLOB blob;
2343 enum ndr_err_code ndr_err;
2344 struct spoolss_OSVersion os;
2346 os.major = lp_parm_int(GLOBAL_SECTION_SNUM,
2347 "spoolss", "os_major", 5);
2348 /* Windows 2000 == 5.0 */
2349 os.minor = lp_parm_int(GLOBAL_SECTION_SNUM,
2350 "spoolss", "os_minor", 0);
2351 os.build = lp_parm_int(GLOBAL_SECTION_SNUM,
2352 "spoolss", "os_build", 2195);
2353 os.extra_string = ""; /* leave extra string empty */
2355 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2356 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2357 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2358 return WERR_GENERAL_FAILURE;
2361 if (DEBUGLEVEL >= 10) {
2362 NDR_PRINT_DEBUG(spoolss_OSVersion, &os);
2365 *type = REG_BINARY;
2366 data->binary = blob;
2368 return WERR_OK;
2372 if (!strcasecmp_m(value, "DefaultSpoolDirectory")) {
2373 *type = REG_SZ;
2375 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2376 W_ERROR_HAVE_NO_MEMORY(data->string);
2378 return WERR_OK;
2381 if (!strcasecmp_m(value, "Architecture")) {
2382 *type = REG_SZ;
2383 data->string = talloc_strdup(mem_ctx,
2384 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2385 W_ERROR_HAVE_NO_MEMORY(data->string);
2387 return WERR_OK;
2390 if (!strcasecmp_m(value, "DsPresent")) {
2391 *type = REG_DWORD;
2393 /* only show the publish check box if we are a
2394 member of a AD domain */
2396 if (lp_security() == SEC_ADS) {
2397 SIVAL(&data->value, 0, 0x01);
2398 } else {
2399 SIVAL(&data->value, 0, 0x00);
2401 return WERR_OK;
2404 if (!strcasecmp_m(value, "DNSMachineName")) {
2405 const char *hostname = get_mydnsfullname();
2407 if (!hostname) {
2408 return WERR_BADFILE;
2411 *type = REG_SZ;
2412 data->string = talloc_strdup(mem_ctx, hostname);
2413 W_ERROR_HAVE_NO_MEMORY(data->string);
2415 return WERR_OK;
2418 *type = REG_NONE;
2420 return WERR_INVALID_PARAM;
2423 /****************************************************************
2424 _spoolss_GetPrinterData
2425 ****************************************************************/
2427 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2428 struct spoolss_GetPrinterData *r)
2430 struct spoolss_GetPrinterDataEx r2;
2432 r2.in.handle = r->in.handle;
2433 r2.in.key_name = "PrinterDriverData";
2434 r2.in.value_name = r->in.value_name;
2435 r2.in.offered = r->in.offered;
2436 r2.out.type = r->out.type;
2437 r2.out.data = r->out.data;
2438 r2.out.needed = r->out.needed;
2440 return _spoolss_GetPrinterDataEx(p, &r2);
2443 /*********************************************************
2444 Connect to the client machine.
2445 **********************************************************/
2447 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, struct cli_state **pp_cli,
2448 struct sockaddr_storage *client_ss, const char *remote_machine)
2450 NTSTATUS ret;
2451 struct sockaddr_storage rm_addr;
2452 char addr[INET6_ADDRSTRLEN];
2454 if ( is_zero_addr(client_ss) ) {
2455 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2456 remote_machine));
2457 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2458 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2459 return false;
2461 print_sockaddr(addr, sizeof(addr), &rm_addr);
2462 } else {
2463 rm_addr = *client_ss;
2464 print_sockaddr(addr, sizeof(addr), &rm_addr);
2465 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2466 addr));
2469 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2470 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2471 addr));
2472 return false;
2475 /* setup the connection */
2476 ret = cli_full_connection( pp_cli, lp_netbios_name(), remote_machine,
2477 &rm_addr, 0, "IPC$", "IPC",
2478 "", /* username */
2479 "", /* domain */
2480 "", /* password */
2481 0, lp_client_signing());
2483 if ( !NT_STATUS_IS_OK( ret ) ) {
2484 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2485 remote_machine ));
2486 return false;
2489 if ( smbXcli_conn_protocol((*pp_cli)->conn) != PROTOCOL_NT1 ) {
2490 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2491 cli_shutdown(*pp_cli);
2492 return false;
2496 * Ok - we have an anonymous connection to the IPC$ share.
2497 * Now start the NT Domain stuff :-).
2500 ret = cli_rpc_pipe_open_noauth(*pp_cli, &ndr_table_spoolss, pp_pipe);
2501 if (!NT_STATUS_IS_OK(ret)) {
2502 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2503 remote_machine, nt_errstr(ret)));
2504 cli_shutdown(*pp_cli);
2505 return false;
2508 return true;
2511 /***************************************************************************
2512 Connect to the client.
2513 ****************************************************************************/
2515 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2516 uint32_t localprinter,
2517 enum winreg_Type type,
2518 struct policy_handle *handle,
2519 struct notify_back_channel **_chan,
2520 struct sockaddr_storage *client_ss,
2521 struct messaging_context *msg_ctx)
2523 WERROR result;
2524 NTSTATUS status;
2525 struct notify_back_channel *chan;
2527 for (chan = back_channels; chan; chan = chan->next) {
2528 if (memcmp(&chan->client_address, client_ss,
2529 sizeof(struct sockaddr_storage)) == 0) {
2530 break;
2535 * If it's the first connection, contact the client
2536 * and connect to the IPC$ share anonymously
2538 if (!chan) {
2539 fstring unix_printer;
2541 /* the +2 is to strip the leading 2 backslashs */
2542 fstrcpy(unix_printer, printer + 2);
2544 chan = talloc_zero(NULL, struct notify_back_channel);
2545 if (!chan) {
2546 return false;
2548 chan->client_address = *client_ss;
2550 if (!spoolss_connect_to_client(&chan->cli_pipe, &chan->cli, client_ss, unix_printer)) {
2551 TALLOC_FREE(chan);
2552 return false;
2555 DLIST_ADD(back_channels, chan);
2557 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2558 receive_notify2_message_list);
2561 if (chan->cli_pipe == NULL ||
2562 chan->cli_pipe->binding_handle == NULL) {
2563 DEBUG(0, ("srv_spoolss_replyopenprinter: error - "
2564 "NULL %s for printer %s\n",
2565 chan->cli_pipe == NULL ?
2566 "chan->cli_pipe" : "chan->cli_pipe->binding_handle",
2567 printer));
2568 return false;
2572 * Tell the specific printing tdb we want messages for this printer
2573 * by registering our PID.
2576 if (!print_notify_register_pid(snum)) {
2577 DEBUG(0, ("Failed to register our pid for printer %s\n",
2578 printer));
2581 status = dcerpc_spoolss_ReplyOpenPrinter(chan->cli_pipe->binding_handle,
2582 talloc_tos(),
2583 printer,
2584 localprinter,
2585 type,
2587 NULL,
2588 handle,
2589 &result);
2590 if (!NT_STATUS_IS_OK(status)) {
2591 DEBUG(5, ("dcerpc_spoolss_ReplyOpenPrinter returned [%s]\n", nt_errstr(status)));
2592 result = ntstatus_to_werror(status);
2593 } else if (!W_ERROR_IS_OK(result)) {
2594 DEBUG(5, ("ReplyOpenPrinter returned [%s]\n", win_errstr(result)));
2597 chan->active_connections++;
2598 *_chan = chan;
2600 return (W_ERROR_IS_OK(result));
2603 /****************************************************************
2604 ****************************************************************/
2606 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2607 const struct spoolss_NotifyOption *r)
2609 struct spoolss_NotifyOption *option;
2610 uint32_t i,k;
2612 if (!r) {
2613 return NULL;
2616 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2617 if (!option) {
2618 return NULL;
2621 *option = *r;
2623 if (!option->count) {
2624 return option;
2627 option->types = talloc_zero_array(option,
2628 struct spoolss_NotifyOptionType, option->count);
2629 if (!option->types) {
2630 talloc_free(option);
2631 return NULL;
2634 for (i=0; i < option->count; i++) {
2635 option->types[i] = r->types[i];
2637 if (option->types[i].count) {
2638 option->types[i].fields = talloc_zero_array(option,
2639 union spoolss_Field, option->types[i].count);
2640 if (!option->types[i].fields) {
2641 talloc_free(option);
2642 return NULL;
2644 for (k=0; k<option->types[i].count; k++) {
2645 option->types[i].fields[k] =
2646 r->types[i].fields[k];
2651 return option;
2654 /****************************************************************
2655 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2657 * before replying OK: status=0 a rpc call is made to the workstation
2658 * asking ReplyOpenPrinter
2660 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2661 * called from api_spoolss_rffpcnex
2662 ****************************************************************/
2664 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2665 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2667 int snum = -1;
2668 struct spoolss_NotifyOption *option = r->in.notify_options;
2669 struct sockaddr_storage client_ss;
2670 ssize_t client_len;
2672 /* store the notify value in the printer struct */
2674 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2676 if (!Printer) {
2677 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2678 "Invalid handle (%s:%u:%u).\n",
2679 OUR_HANDLE(r->in.handle)));
2680 return WERR_BADFID;
2683 Printer->notify.flags = r->in.flags;
2684 Printer->notify.options = r->in.options;
2685 Printer->notify.printerlocal = r->in.printer_local;
2686 Printer->notify.msg_ctx = p->msg_ctx;
2688 TALLOC_FREE(Printer->notify.option);
2689 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2691 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2693 /* Connect to the client machine and send a ReplyOpenPrinter */
2695 if ( Printer->printer_type == SPLHND_SERVER)
2696 snum = -1;
2697 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2698 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2699 return WERR_BADFID;
2701 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2702 "remote_address is %s\n",
2703 tsocket_address_string(p->remote_address, p->mem_ctx)));
2705 if (!lp_print_notify_backchannel(snum)) {
2706 DEBUG(10, ("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2707 "backchannel disabled\n"));
2708 return WERR_SERVER_UNAVAILABLE;
2711 client_len = tsocket_address_bsd_sockaddr(p->remote_address,
2712 (struct sockaddr *) &client_ss,
2713 sizeof(struct sockaddr_storage));
2714 if (client_len < 0) {
2715 return WERR_NOMEM;
2718 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2719 Printer->notify.printerlocal, REG_SZ,
2720 &Printer->notify.cli_hnd,
2721 &Printer->notify.cli_chan,
2722 &client_ss, p->msg_ctx)) {
2723 return WERR_SERVER_UNAVAILABLE;
2726 return WERR_OK;
2729 /*******************************************************************
2730 * fill a notify_info_data with the servername
2731 ********************************************************************/
2733 static void spoolss_notify_server_name(struct messaging_context *msg_ctx,
2734 int snum,
2735 struct spoolss_Notify *data,
2736 print_queue_struct *queue,
2737 struct spoolss_PrinterInfo2 *pinfo2,
2738 TALLOC_CTX *mem_ctx)
2740 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2743 /*******************************************************************
2744 * fill a notify_info_data with the printername (not including the servername).
2745 ********************************************************************/
2747 static void spoolss_notify_printer_name(struct messaging_context *msg_ctx,
2748 int snum,
2749 struct spoolss_Notify *data,
2750 print_queue_struct *queue,
2751 struct spoolss_PrinterInfo2 *pinfo2,
2752 TALLOC_CTX *mem_ctx)
2754 /* the notify name should not contain the \\server\ part */
2755 const char *p = strrchr(pinfo2->printername, '\\');
2757 if (!p) {
2758 p = pinfo2->printername;
2759 } else {
2760 p++;
2763 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2766 /*******************************************************************
2767 * fill a notify_info_data with the servicename
2768 ********************************************************************/
2770 static void spoolss_notify_share_name(struct messaging_context *msg_ctx,
2771 int snum,
2772 struct spoolss_Notify *data,
2773 print_queue_struct *queue,
2774 struct spoolss_PrinterInfo2 *pinfo2,
2775 TALLOC_CTX *mem_ctx)
2777 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(talloc_tos(), snum));
2780 /*******************************************************************
2781 * fill a notify_info_data with the port name
2782 ********************************************************************/
2784 static void spoolss_notify_port_name(struct messaging_context *msg_ctx,
2785 int snum,
2786 struct spoolss_Notify *data,
2787 print_queue_struct *queue,
2788 struct spoolss_PrinterInfo2 *pinfo2,
2789 TALLOC_CTX *mem_ctx)
2791 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2794 /*******************************************************************
2795 * fill a notify_info_data with the printername
2796 * but it doesn't exist, have to see what to do
2797 ********************************************************************/
2799 static void spoolss_notify_driver_name(struct messaging_context *msg_ctx,
2800 int snum,
2801 struct spoolss_Notify *data,
2802 print_queue_struct *queue,
2803 struct spoolss_PrinterInfo2 *pinfo2,
2804 TALLOC_CTX *mem_ctx)
2806 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2809 /*******************************************************************
2810 * fill a notify_info_data with the comment
2811 ********************************************************************/
2813 static void spoolss_notify_comment(struct messaging_context *msg_ctx,
2814 int snum,
2815 struct spoolss_Notify *data,
2816 print_queue_struct *queue,
2817 struct spoolss_PrinterInfo2 *pinfo2,
2818 TALLOC_CTX *mem_ctx)
2820 const char *p;
2822 if (*pinfo2->comment == '\0') {
2823 p = lp_comment(talloc_tos(), snum);
2824 } else {
2825 p = pinfo2->comment;
2828 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2831 /*******************************************************************
2832 * fill a notify_info_data with the comment
2833 * location = "Room 1, floor 2, building 3"
2834 ********************************************************************/
2836 static void spoolss_notify_location(struct messaging_context *msg_ctx,
2837 int snum,
2838 struct spoolss_Notify *data,
2839 print_queue_struct *queue,
2840 struct spoolss_PrinterInfo2 *pinfo2,
2841 TALLOC_CTX *mem_ctx)
2843 const char *loc = pinfo2->location;
2844 NTSTATUS status;
2846 status = printer_list_get_printer(mem_ctx,
2847 pinfo2->sharename,
2848 NULL,
2849 &loc,
2850 NULL);
2851 if (NT_STATUS_IS_OK(status)) {
2852 if (loc == NULL) {
2853 loc = pinfo2->location;
2857 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, loc);
2860 /*******************************************************************
2861 * fill a notify_info_data with the device mode
2862 * jfm:xxxx don't to it for know but that's a real problem !!!
2863 ********************************************************************/
2865 static void spoolss_notify_devmode(struct messaging_context *msg_ctx,
2866 int snum,
2867 struct spoolss_Notify *data,
2868 print_queue_struct *queue,
2869 struct spoolss_PrinterInfo2 *pinfo2,
2870 TALLOC_CTX *mem_ctx)
2872 /* for a dummy implementation we have to zero the fields */
2873 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2876 /*******************************************************************
2877 * fill a notify_info_data with the separator file name
2878 ********************************************************************/
2880 static void spoolss_notify_sepfile(struct messaging_context *msg_ctx,
2881 int snum,
2882 struct spoolss_Notify *data,
2883 print_queue_struct *queue,
2884 struct spoolss_PrinterInfo2 *pinfo2,
2885 TALLOC_CTX *mem_ctx)
2887 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2890 /*******************************************************************
2891 * fill a notify_info_data with the print processor
2892 * jfm:xxxx return always winprint to indicate we don't do anything to it
2893 ********************************************************************/
2895 static void spoolss_notify_print_processor(struct messaging_context *msg_ctx,
2896 int snum,
2897 struct spoolss_Notify *data,
2898 print_queue_struct *queue,
2899 struct spoolss_PrinterInfo2 *pinfo2,
2900 TALLOC_CTX *mem_ctx)
2902 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2905 /*******************************************************************
2906 * fill a notify_info_data with the print processor options
2907 * jfm:xxxx send an empty string
2908 ********************************************************************/
2910 static void spoolss_notify_parameters(struct messaging_context *msg_ctx,
2911 int snum,
2912 struct spoolss_Notify *data,
2913 print_queue_struct *queue,
2914 struct spoolss_PrinterInfo2 *pinfo2,
2915 TALLOC_CTX *mem_ctx)
2917 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2920 /*******************************************************************
2921 * fill a notify_info_data with the data type
2922 * jfm:xxxx always send RAW as data type
2923 ********************************************************************/
2925 static void spoolss_notify_datatype(struct messaging_context *msg_ctx,
2926 int snum,
2927 struct spoolss_Notify *data,
2928 print_queue_struct *queue,
2929 struct spoolss_PrinterInfo2 *pinfo2,
2930 TALLOC_CTX *mem_ctx)
2932 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2935 /*******************************************************************
2936 * fill a notify_info_data with the security descriptor
2937 * jfm:xxxx send an null pointer to say no security desc
2938 * have to implement security before !
2939 ********************************************************************/
2941 static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
2942 int snum,
2943 struct spoolss_Notify *data,
2944 print_queue_struct *queue,
2945 struct spoolss_PrinterInfo2 *pinfo2,
2946 TALLOC_CTX *mem_ctx)
2948 if (pinfo2->secdesc == NULL) {
2949 data->data.sd.sd = NULL;
2950 } else {
2951 data->data.sd.sd = security_descriptor_copy(mem_ctx,
2952 pinfo2->secdesc);
2954 data->data.sd.sd_size = ndr_size_security_descriptor(data->data.sd.sd,
2958 /*******************************************************************
2959 * fill a notify_info_data with the attributes
2960 * jfm:xxxx a samba printer is always shared
2961 ********************************************************************/
2963 static void spoolss_notify_attributes(struct messaging_context *msg_ctx,
2964 int snum,
2965 struct spoolss_Notify *data,
2966 print_queue_struct *queue,
2967 struct spoolss_PrinterInfo2 *pinfo2,
2968 TALLOC_CTX *mem_ctx)
2970 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2973 /*******************************************************************
2974 * fill a notify_info_data with the priority
2975 ********************************************************************/
2977 static void spoolss_notify_priority(struct messaging_context *msg_ctx,
2978 int snum,
2979 struct spoolss_Notify *data,
2980 print_queue_struct *queue,
2981 struct spoolss_PrinterInfo2 *pinfo2,
2982 TALLOC_CTX *mem_ctx)
2984 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2987 /*******************************************************************
2988 * fill a notify_info_data with the default priority
2989 ********************************************************************/
2991 static void spoolss_notify_default_priority(struct messaging_context *msg_ctx,
2992 int snum,
2993 struct spoolss_Notify *data,
2994 print_queue_struct *queue,
2995 struct spoolss_PrinterInfo2 *pinfo2,
2996 TALLOC_CTX *mem_ctx)
2998 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
3001 /*******************************************************************
3002 * fill a notify_info_data with the start time
3003 ********************************************************************/
3005 static void spoolss_notify_start_time(struct messaging_context *msg_ctx,
3006 int snum,
3007 struct spoolss_Notify *data,
3008 print_queue_struct *queue,
3009 struct spoolss_PrinterInfo2 *pinfo2,
3010 TALLOC_CTX *mem_ctx)
3012 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
3015 /*******************************************************************
3016 * fill a notify_info_data with the until time
3017 ********************************************************************/
3019 static void spoolss_notify_until_time(struct messaging_context *msg_ctx,
3020 int snum,
3021 struct spoolss_Notify *data,
3022 print_queue_struct *queue,
3023 struct spoolss_PrinterInfo2 *pinfo2,
3024 TALLOC_CTX *mem_ctx)
3026 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
3029 /*******************************************************************
3030 * fill a notify_info_data with the status
3031 ********************************************************************/
3033 static void spoolss_notify_status(struct messaging_context *msg_ctx,
3034 int snum,
3035 struct spoolss_Notify *data,
3036 print_queue_struct *queue,
3037 struct spoolss_PrinterInfo2 *pinfo2,
3038 TALLOC_CTX *mem_ctx)
3040 print_status_struct status;
3042 print_queue_length(msg_ctx, snum, &status);
3043 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3046 /*******************************************************************
3047 * fill a notify_info_data with the number of jobs queued
3048 ********************************************************************/
3050 static void spoolss_notify_cjobs(struct messaging_context *msg_ctx,
3051 int snum,
3052 struct spoolss_Notify *data,
3053 print_queue_struct *queue,
3054 struct spoolss_PrinterInfo2 *pinfo2,
3055 TALLOC_CTX *mem_ctx)
3057 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3058 data, print_queue_length(msg_ctx, snum, NULL));
3061 /*******************************************************************
3062 * fill a notify_info_data with the average ppm
3063 ********************************************************************/
3065 static void spoolss_notify_average_ppm(struct messaging_context *msg_ctx,
3066 int snum,
3067 struct spoolss_Notify *data,
3068 print_queue_struct *queue,
3069 struct spoolss_PrinterInfo2 *pinfo2,
3070 TALLOC_CTX *mem_ctx)
3072 /* always respond 8 pages per minutes */
3073 /* a little hard ! */
3074 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
3077 /*******************************************************************
3078 * fill a notify_info_data with username
3079 ********************************************************************/
3081 static void spoolss_notify_username(struct messaging_context *msg_ctx,
3082 int snum,
3083 struct spoolss_Notify *data,
3084 print_queue_struct *queue,
3085 struct spoolss_PrinterInfo2 *pinfo2,
3086 TALLOC_CTX *mem_ctx)
3088 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3091 /*******************************************************************
3092 * fill a notify_info_data with job status
3093 ********************************************************************/
3095 static void spoolss_notify_job_status(struct messaging_context *msg_ctx,
3096 int snum,
3097 struct spoolss_Notify *data,
3098 print_queue_struct *queue,
3099 struct spoolss_PrinterInfo2 *pinfo2,
3100 TALLOC_CTX *mem_ctx)
3102 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3105 /*******************************************************************
3106 * fill a notify_info_data with job name
3107 ********************************************************************/
3109 static void spoolss_notify_job_name(struct messaging_context *msg_ctx,
3110 int snum,
3111 struct spoolss_Notify *data,
3112 print_queue_struct *queue,
3113 struct spoolss_PrinterInfo2 *pinfo2,
3114 TALLOC_CTX *mem_ctx)
3116 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3119 /*******************************************************************
3120 * fill a notify_info_data with job status
3121 ********************************************************************/
3123 static void spoolss_notify_job_status_string(struct messaging_context *msg_ctx,
3124 int snum,
3125 struct spoolss_Notify *data,
3126 print_queue_struct *queue,
3127 struct spoolss_PrinterInfo2 *pinfo2,
3128 TALLOC_CTX *mem_ctx)
3131 * Now we're returning job status codes we just return a "" here. JRA.
3134 const char *p = "";
3136 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3137 p = "unknown";
3139 switch (queue->status) {
3140 case LPQ_QUEUED:
3141 p = "Queued";
3142 break;
3143 case LPQ_PAUSED:
3144 p = ""; /* NT provides the paused string */
3145 break;
3146 case LPQ_SPOOLING:
3147 p = "Spooling";
3148 break;
3149 case LPQ_PRINTING:
3150 p = "Printing";
3151 break;
3153 #endif /* NO LONGER NEEDED. */
3155 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3158 /*******************************************************************
3159 * fill a notify_info_data with job time
3160 ********************************************************************/
3162 static void spoolss_notify_job_time(struct messaging_context *msg_ctx,
3163 int snum,
3164 struct spoolss_Notify *data,
3165 print_queue_struct *queue,
3166 struct spoolss_PrinterInfo2 *pinfo2,
3167 TALLOC_CTX *mem_ctx)
3169 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3172 /*******************************************************************
3173 * fill a notify_info_data with job size
3174 ********************************************************************/
3176 static void spoolss_notify_job_size(struct messaging_context *msg_ctx,
3177 int snum,
3178 struct spoolss_Notify *data,
3179 print_queue_struct *queue,
3180 struct spoolss_PrinterInfo2 *pinfo2,
3181 TALLOC_CTX *mem_ctx)
3183 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3186 /*******************************************************************
3187 * fill a notify_info_data with page info
3188 ********************************************************************/
3189 static void spoolss_notify_total_pages(struct messaging_context *msg_ctx,
3190 int snum,
3191 struct spoolss_Notify *data,
3192 print_queue_struct *queue,
3193 struct spoolss_PrinterInfo2 *pinfo2,
3194 TALLOC_CTX *mem_ctx)
3196 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3199 /*******************************************************************
3200 * fill a notify_info_data with pages printed info.
3201 ********************************************************************/
3202 static void spoolss_notify_pages_printed(struct messaging_context *msg_ctx,
3203 int snum,
3204 struct spoolss_Notify *data,
3205 print_queue_struct *queue,
3206 struct spoolss_PrinterInfo2 *pinfo2,
3207 TALLOC_CTX *mem_ctx)
3209 /* Add code when back-end tracks this */
3210 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3213 /*******************************************************************
3214 Fill a notify_info_data with job position.
3215 ********************************************************************/
3217 static void spoolss_notify_job_position(struct messaging_context *msg_ctx,
3218 int snum,
3219 struct spoolss_Notify *data,
3220 print_queue_struct *queue,
3221 struct spoolss_PrinterInfo2 *pinfo2,
3222 TALLOC_CTX *mem_ctx)
3224 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->sysjob);
3227 /*******************************************************************
3228 Fill a notify_info_data with submitted time.
3229 ********************************************************************/
3231 static void spoolss_notify_submitted_time(struct messaging_context *msg_ctx,
3232 int snum,
3233 struct spoolss_Notify *data,
3234 print_queue_struct *queue,
3235 struct spoolss_PrinterInfo2 *pinfo2,
3236 TALLOC_CTX *mem_ctx)
3238 data->data.string.string = NULL;
3239 data->data.string.size = 0;
3241 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3242 &data->data.string.string,
3243 &data->data.string.size);
3247 struct s_notify_info_data_table
3249 enum spoolss_NotifyType type;
3250 uint16_t field;
3251 const char *name;
3252 enum spoolss_NotifyTable variable_type;
3253 void (*fn) (struct messaging_context *msg_ctx,
3254 int snum, struct spoolss_Notify *data,
3255 print_queue_struct *queue,
3256 struct spoolss_PrinterInfo2 *pinfo2,
3257 TALLOC_CTX *mem_ctx);
3260 /* A table describing the various print notification constants and
3261 whether the notification data is a pointer to a variable sized
3262 buffer, a one value uint32_t or a two value uint32_t. */
3264 static const struct s_notify_info_data_table notify_info_data_table[] =
3266 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3267 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3268 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3269 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3270 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3271 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3272 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3273 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3274 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3275 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3276 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3277 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3278 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3279 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3280 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3281 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3282 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3283 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3284 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3285 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3286 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3287 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3288 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3289 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3290 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3291 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3292 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3293 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3294 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3295 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3296 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3297 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3298 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3299 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3300 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3301 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3302 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3303 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3304 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3305 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3306 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3307 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3308 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3309 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3310 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3311 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3312 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3313 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3314 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3317 /*******************************************************************
3318 Return the variable_type of info_data structure.
3319 ********************************************************************/
3321 static enum spoolss_NotifyTable variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3322 uint16_t field)
3324 int i=0;
3326 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3327 if ( (notify_info_data_table[i].type == type) &&
3328 (notify_info_data_table[i].field == field) ) {
3329 return notify_info_data_table[i].variable_type;
3333 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3335 return (enum spoolss_NotifyTable) 0;
3338 /****************************************************************************
3339 ****************************************************************************/
3341 static bool search_notify(enum spoolss_NotifyType type,
3342 uint16_t field,
3343 int *value)
3345 int i;
3347 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3348 if (notify_info_data_table[i].type == type &&
3349 notify_info_data_table[i].field == field &&
3350 notify_info_data_table[i].fn != NULL) {
3351 *value = i;
3352 return true;
3356 return false;
3359 /****************************************************************************
3360 ****************************************************************************/
3362 static void construct_info_data(struct spoolss_Notify *info_data,
3363 enum spoolss_NotifyType type,
3364 uint16_t field, int id)
3366 info_data->type = type;
3367 info_data->field.field = field;
3368 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3369 info_data->job_id = id;
3372 /*******************************************************************
3374 * fill a notify_info struct with info asked
3376 ********************************************************************/
3378 static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
3379 struct printer_handle *print_hnd,
3380 struct spoolss_NotifyInfo *info,
3381 struct spoolss_PrinterInfo2 *pinfo2,
3382 int snum,
3383 const struct spoolss_NotifyOptionType *option_type,
3384 uint32_t id,
3385 TALLOC_CTX *mem_ctx)
3387 int field_num,j;
3388 enum spoolss_NotifyType type;
3389 uint16_t field;
3391 struct spoolss_Notify *current_data;
3393 type = option_type->type;
3395 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3396 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3397 option_type->count, lp_servicename(talloc_tos(), snum)));
3399 for(field_num=0; field_num < option_type->count; field_num++) {
3400 field = option_type->fields[field_num].field;
3402 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3404 if (!search_notify(type, field, &j) )
3405 continue;
3407 info->notifies = talloc_realloc(info, info->notifies,
3408 struct spoolss_Notify,
3409 info->count + 1);
3410 if (info->notifies == NULL) {
3411 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3412 return false;
3415 current_data = &info->notifies[info->count];
3417 construct_info_data(current_data, type, field, id);
3419 DEBUG(10, ("construct_notify_printer_info: "
3420 "calling [%s] snum=%d printername=[%s])\n",
3421 notify_info_data_table[j].name, snum,
3422 pinfo2->printername));
3424 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3425 NULL, pinfo2, mem_ctx);
3427 info->count++;
3430 return true;
3433 /*******************************************************************
3435 * fill a notify_info struct with info asked
3437 ********************************************************************/
3439 static bool construct_notify_jobs_info(struct messaging_context *msg_ctx,
3440 print_queue_struct *queue,
3441 struct spoolss_NotifyInfo *info,
3442 struct spoolss_PrinterInfo2 *pinfo2,
3443 int snum,
3444 const struct spoolss_NotifyOptionType *option_type,
3445 uint32_t id,
3446 TALLOC_CTX *mem_ctx)
3448 int field_num,j;
3449 enum spoolss_NotifyType type;
3450 uint16_t field;
3451 struct spoolss_Notify *current_data;
3453 DEBUG(4,("construct_notify_jobs_info\n"));
3455 type = option_type->type;
3457 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3458 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3459 option_type->count));
3461 for(field_num=0; field_num<option_type->count; field_num++) {
3462 field = option_type->fields[field_num].field;
3464 if (!search_notify(type, field, &j) )
3465 continue;
3467 info->notifies = talloc_realloc(info, info->notifies,
3468 struct spoolss_Notify,
3469 info->count + 1);
3470 if (info->notifies == NULL) {
3471 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3472 return false;
3475 current_data=&(info->notifies[info->count]);
3477 construct_info_data(current_data, type, field, id);
3478 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3479 queue, pinfo2, mem_ctx);
3480 info->count++;
3483 return true;
3487 * JFM: The enumeration is not that simple, it's even non obvious.
3489 * let's take an example: I want to monitor the PRINTER SERVER for
3490 * the printer's name and the number of jobs currently queued.
3491 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3492 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3494 * I have 3 printers on the back of my server.
3496 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3497 * structures.
3498 * Number Data Id
3499 * 1 printer 1 name 1
3500 * 2 printer 1 cjob 1
3501 * 3 printer 2 name 2
3502 * 4 printer 2 cjob 2
3503 * 5 printer 3 name 3
3504 * 6 printer 3 name 3
3506 * that's the print server case, the printer case is even worse.
3509 /*******************************************************************
3511 * enumerate all printers on the printserver
3512 * fill a notify_info struct with info asked
3514 ********************************************************************/
3516 static WERROR printserver_notify_info(struct pipes_struct *p,
3517 struct policy_handle *hnd,
3518 struct spoolss_NotifyInfo *info,
3519 TALLOC_CTX *mem_ctx)
3521 int snum;
3522 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3523 int n_services=lp_numservices();
3524 int i;
3525 struct spoolss_NotifyOption *option;
3526 struct spoolss_NotifyOptionType option_type;
3527 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3528 WERROR result;
3530 DEBUG(4,("printserver_notify_info\n"));
3532 if (!Printer)
3533 return WERR_BADFID;
3535 option = Printer->notify.option;
3537 info->version = 2;
3538 info->notifies = NULL;
3539 info->count = 0;
3541 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3542 sending a ffpcn() request first */
3544 if ( !option )
3545 return WERR_BADFID;
3547 for (i=0; i<option->count; i++) {
3548 option_type = option->types[i];
3550 if (option_type.type != PRINTER_NOTIFY_TYPE)
3551 continue;
3553 for (snum = 0; snum < n_services; snum++) {
3554 if (!lp_browseable(snum) ||
3555 !lp_snum_ok(snum) ||
3556 !lp_printable(snum)) {
3557 continue; /* skip */
3560 /* Maybe we should use the SYSTEM session_info here... */
3561 result = winreg_get_printer_internal(mem_ctx,
3562 get_session_info_system(),
3563 p->msg_ctx,
3564 lp_servicename(talloc_tos(), snum),
3565 &pinfo2);
3566 if (!W_ERROR_IS_OK(result)) {
3567 DEBUG(4, ("printserver_notify_info: "
3568 "Failed to get printer [%s]\n",
3569 lp_servicename(talloc_tos(), snum)));
3570 continue;
3574 construct_notify_printer_info(p->msg_ctx,
3575 Printer, info,
3576 pinfo2, snum,
3577 &option_type, snum,
3578 mem_ctx);
3580 TALLOC_FREE(pinfo2);
3584 #if 0
3586 * Debugging information, don't delete.
3589 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3590 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3591 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3593 for (i=0; i<info->count; i++) {
3594 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3595 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3596 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3598 #endif
3600 return WERR_OK;
3603 /*******************************************************************
3605 * fill a notify_info struct with info asked
3607 ********************************************************************/
3609 static WERROR printer_notify_info(struct pipes_struct *p,
3610 struct policy_handle *hnd,
3611 struct spoolss_NotifyInfo *info,
3612 TALLOC_CTX *mem_ctx)
3614 int snum;
3615 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3616 int i;
3617 uint32_t id;
3618 struct spoolss_NotifyOption *option;
3619 struct spoolss_NotifyOptionType option_type;
3620 int count,j;
3621 print_queue_struct *queue=NULL;
3622 print_status_struct status;
3623 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3624 WERROR result;
3625 struct tdb_print_db *pdb;
3627 DEBUG(4,("printer_notify_info\n"));
3629 if (!Printer)
3630 return WERR_BADFID;
3632 option = Printer->notify.option;
3633 id = 0x0;
3635 info->version = 2;
3636 info->notifies = NULL;
3637 info->count = 0;
3639 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3640 sending a ffpcn() request first */
3642 if ( !option )
3643 return WERR_BADFID;
3645 if (!get_printer_snum(p, hnd, &snum, NULL)) {
3646 return WERR_BADFID;
3649 pdb = get_print_db_byname(Printer->sharename);
3650 if (pdb == NULL) {
3651 return WERR_BADFID;
3654 /* Maybe we should use the SYSTEM session_info here... */
3655 result = winreg_get_printer_internal(mem_ctx,
3656 get_session_info_system(),
3657 p->msg_ctx,
3658 lp_servicename(talloc_tos(), snum), &pinfo2);
3659 if (!W_ERROR_IS_OK(result)) {
3660 result = WERR_BADFID;
3661 goto err_pdb_drop;
3665 * When sending a PRINTER_NOTIFY_FIELD_SERVER_NAME we should send the
3666 * correct servername.
3668 pinfo2->servername = talloc_strdup(pinfo2, Printer->servername);
3669 if (pinfo2->servername == NULL) {
3670 result = WERR_NOMEM;
3671 goto err_pdb_drop;
3674 for (i = 0; i < option->count; i++) {
3675 option_type = option->types[i];
3677 switch (option_type.type) {
3678 case PRINTER_NOTIFY_TYPE:
3679 if (construct_notify_printer_info(p->msg_ctx,
3680 Printer, info,
3681 pinfo2, snum,
3682 &option_type, id,
3683 mem_ctx)) {
3684 id--;
3686 break;
3688 case JOB_NOTIFY_TYPE:
3690 count = print_queue_status(p->msg_ctx, snum, &queue,
3691 &status);
3693 for (j = 0; j < count; j++) {
3694 uint32_t jobid;
3695 jobid = sysjob_to_jobid_pdb(pdb,
3696 queue[j].sysjob);
3697 if (jobid == (uint32_t)-1) {
3698 DEBUG(2, ("ignoring untracked job %d\n",
3699 queue[j].sysjob));
3700 continue;
3702 /* FIXME check return value */
3703 construct_notify_jobs_info(p->msg_ctx,
3704 &queue[j], info,
3705 pinfo2, snum,
3706 &option_type,
3707 jobid,
3708 mem_ctx);
3711 SAFE_FREE(queue);
3712 break;
3717 * Debugging information, don't delete.
3720 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3721 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3722 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3724 for (i=0; i<info->count; i++) {
3725 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3726 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3727 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3731 talloc_free(pinfo2);
3732 result = WERR_OK;
3733 err_pdb_drop:
3734 release_print_db(pdb);
3735 return result;
3738 /****************************************************************
3739 _spoolss_RouterRefreshPrinterChangeNotify
3740 ****************************************************************/
3742 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3743 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3745 struct spoolss_NotifyInfo *info;
3747 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
3748 WERROR result = WERR_BADFID;
3750 /* we always have a spoolss_NotifyInfo struct */
3751 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3752 if (!info) {
3753 result = WERR_NOMEM;
3754 goto done;
3757 *r->out.info = info;
3759 if (!Printer) {
3760 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3761 "Invalid handle (%s:%u:%u).\n",
3762 OUR_HANDLE(r->in.handle)));
3763 goto done;
3766 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3769 * We are now using the change value, and
3770 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3771 * I don't have a global notification system, I'm sending back all the
3772 * information even when _NOTHING_ has changed.
3775 /* We need to keep track of the change value to send back in
3776 RRPCN replies otherwise our updates are ignored. */
3778 Printer->notify.fnpcn = true;
3780 if (Printer->notify.cli_chan != NULL &&
3781 Printer->notify.cli_chan->active_connections > 0) {
3782 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3783 "Saving change value in request [%x]\n",
3784 r->in.change_low));
3785 Printer->notify.change = r->in.change_low;
3788 /* just ignore the spoolss_NotifyOption */
3790 switch (Printer->printer_type) {
3791 case SPLHND_SERVER:
3792 result = printserver_notify_info(p, r->in.handle,
3793 info, p->mem_ctx);
3794 break;
3796 case SPLHND_PRINTER:
3797 result = printer_notify_info(p, r->in.handle,
3798 info, p->mem_ctx);
3799 break;
3802 Printer->notify.fnpcn = false;
3804 done:
3805 return result;
3808 /********************************************************************
3809 ********************************************************************/
3811 static WERROR create_printername(TALLOC_CTX *mem_ctx,
3812 const char *servername,
3813 const char *printername,
3814 const char **printername_p)
3816 /* FIXME: add lp_force_printername() */
3818 if (servername == NULL) {
3819 *printername_p = talloc_strdup(mem_ctx, printername);
3820 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3821 return WERR_OK;
3824 if (servername[0] == '\\' && servername[1] == '\\') {
3825 servername += 2;
3828 *printername_p = talloc_asprintf(mem_ctx, "\\\\%s\\%s", servername, printername);
3829 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3831 return WERR_OK;
3834 /********************************************************************
3835 ********************************************************************/
3837 static void compose_devicemode_devicename(struct spoolss_DeviceMode *dm,
3838 const char *printername)
3840 if (dm == NULL) {
3841 return;
3844 dm->devicename = talloc_strndup(dm, printername,
3845 MIN(strlen(printername), 31));
3848 /********************************************************************
3849 * construct_printer_info_0
3850 * fill a printer_info_0 struct
3851 ********************************************************************/
3853 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3854 const struct auth_session_info *session_info,
3855 struct messaging_context *msg_ctx,
3856 struct spoolss_PrinterInfo2 *info2,
3857 const char *servername,
3858 struct spoolss_PrinterInfo0 *r,
3859 int snum)
3861 int count;
3862 struct printer_session_counter *session_counter;
3863 struct timeval setuptime;
3864 print_status_struct status;
3865 WERROR result;
3867 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3868 if (!W_ERROR_IS_OK(result)) {
3869 return result;
3872 if (servername) {
3873 r->servername = talloc_strdup(mem_ctx, servername);
3874 W_ERROR_HAVE_NO_MEMORY(r->servername);
3875 } else {
3876 r->servername = NULL;
3879 count = print_queue_length(msg_ctx, snum, &status);
3881 /* check if we already have a counter for this printer */
3882 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3883 if (session_counter->snum == snum)
3884 break;
3887 /* it's the first time, add it to the list */
3888 if (session_counter == NULL) {
3889 session_counter = talloc_zero(counter_list, struct printer_session_counter);
3890 W_ERROR_HAVE_NO_MEMORY(session_counter);
3891 session_counter->snum = snum;
3892 session_counter->counter = 0;
3893 DLIST_ADD(counter_list, session_counter);
3896 /* increment it */
3897 session_counter->counter++;
3899 r->cjobs = count;
3900 r->total_jobs = 0;
3901 r->total_bytes = 0;
3903 get_startup_time(&setuptime);
3904 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3906 /* JFM:
3907 * the global_counter should be stored in a TDB as it's common to all the clients
3908 * and should be zeroed on samba startup
3910 r->global_counter = session_counter->counter;
3911 r->total_pages = 0;
3912 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3913 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3914 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3915 r->free_build = SPOOLSS_RELEASE_BUILD;
3916 r->spooling = 0;
3917 r->max_spooling = 0;
3918 r->session_counter = session_counter->counter;
3919 r->num_error_out_of_paper = 0x0;
3920 r->num_error_not_ready = 0x0; /* number of print failure */
3921 r->job_error = 0x0;
3922 r->number_of_processors = 0x1;
3923 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3924 r->high_part_total_bytes = 0x0;
3926 /* ChangeID in milliseconds*/
3927 winreg_printer_get_changeid_internal(mem_ctx, session_info, msg_ctx,
3928 info2->sharename, &r->change_id);
3930 r->last_error = WERR_OK;
3931 r->status = nt_printq_status(status.status);
3932 r->enumerate_network_printers = 0x0;
3933 r->c_setprinter = 0x0;
3934 r->processor_architecture = PROCESSOR_ARCHITECTURE_INTEL;
3935 r->processor_level = 0x6; /* 6 ???*/
3936 r->ref_ic = 0;
3937 r->reserved2 = 0;
3938 r->reserved3 = 0;
3940 return WERR_OK;
3944 /********************************************************************
3945 * construct_printer_info1
3946 * fill a spoolss_PrinterInfo1 struct
3947 ********************************************************************/
3949 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3950 const struct spoolss_PrinterInfo2 *info2,
3951 uint32_t flags,
3952 const char *servername,
3953 struct spoolss_PrinterInfo1 *r,
3954 int snum)
3956 WERROR result;
3958 r->flags = flags;
3960 if (info2->comment == NULL || info2->comment[0] == '\0') {
3961 r->comment = lp_comment(mem_ctx, snum);
3962 } else {
3963 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3965 W_ERROR_HAVE_NO_MEMORY(r->comment);
3967 result = create_printername(mem_ctx, servername, info2->printername, &r->name);
3968 if (!W_ERROR_IS_OK(result)) {
3969 return result;
3972 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3973 r->name,
3974 info2->drivername,
3975 r->comment);
3976 W_ERROR_HAVE_NO_MEMORY(r->description);
3978 return WERR_OK;
3981 /********************************************************************
3982 * construct_printer_info2
3983 * fill a spoolss_PrinterInfo2 struct
3984 ********************************************************************/
3986 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3987 struct messaging_context *msg_ctx,
3988 const struct spoolss_PrinterInfo2 *info2,
3989 const char *servername,
3990 struct spoolss_PrinterInfo2 *r,
3991 int snum)
3993 int count;
3994 print_status_struct status;
3995 WERROR result;
3997 count = print_queue_length(msg_ctx, snum, &status);
3999 if (servername) {
4000 r->servername = talloc_strdup(mem_ctx, servername);
4001 W_ERROR_HAVE_NO_MEMORY(r->servername);
4002 } else {
4003 r->servername = NULL;
4006 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4007 if (!W_ERROR_IS_OK(result)) {
4008 return result;
4011 r->sharename = lp_servicename(mem_ctx, snum);
4012 W_ERROR_HAVE_NO_MEMORY(r->sharename);
4013 r->portname = talloc_strdup(mem_ctx, info2->portname);
4014 W_ERROR_HAVE_NO_MEMORY(r->portname);
4015 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
4016 W_ERROR_HAVE_NO_MEMORY(r->drivername);
4018 if (info2->comment[0] == '\0') {
4019 r->comment = lp_comment(mem_ctx, snum);
4020 } else {
4021 r->comment = talloc_strdup(mem_ctx, info2->comment);
4023 W_ERROR_HAVE_NO_MEMORY(r->comment);
4025 r->location = talloc_strdup(mem_ctx, info2->location);
4026 if (info2->location[0] == '\0') {
4027 const char *loc = NULL;
4028 NTSTATUS nt_status;
4030 nt_status = printer_list_get_printer(mem_ctx,
4031 info2->sharename,
4032 NULL,
4033 &loc,
4034 NULL);
4035 if (NT_STATUS_IS_OK(nt_status)) {
4036 if (loc != NULL) {
4037 r->location = talloc_strdup(mem_ctx, loc);
4041 W_ERROR_HAVE_NO_MEMORY(r->location);
4043 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
4044 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
4045 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
4046 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
4047 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
4048 W_ERROR_HAVE_NO_MEMORY(r->datatype);
4049 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
4050 W_ERROR_HAVE_NO_MEMORY(r->parameters);
4052 r->attributes = info2->attributes;
4054 r->priority = info2->priority;
4055 r->defaultpriority = info2->defaultpriority;
4056 r->starttime = info2->starttime;
4057 r->untiltime = info2->untiltime;
4058 r->status = nt_printq_status(status.status);
4059 r->cjobs = count;
4060 r->averageppm = info2->averageppm;
4062 if (info2->devmode != NULL) {
4063 result = copy_devicemode(mem_ctx,
4064 info2->devmode,
4065 &r->devmode);
4066 if (!W_ERROR_IS_OK(result)) {
4067 return result;
4069 } else if (lp_default_devmode(snum)) {
4070 result = spoolss_create_default_devmode(mem_ctx,
4071 info2->printername,
4072 &r->devmode);
4073 if (!W_ERROR_IS_OK(result)) {
4074 return result;
4076 } else {
4077 r->devmode = NULL;
4078 DEBUG(8,("Returning NULL Devicemode!\n"));
4081 compose_devicemode_devicename(r->devmode, r->printername);
4083 r->secdesc = NULL;
4085 if (info2->secdesc != NULL) {
4086 /* don't use talloc_steal() here unless you do a deep steal of all
4087 the SEC_DESC members */
4089 r->secdesc = security_descriptor_copy(mem_ctx, info2->secdesc);
4090 if (r->secdesc == NULL) {
4091 return WERR_NOMEM;
4095 return WERR_OK;
4098 /********************************************************************
4099 * construct_printer_info3
4100 * fill a spoolss_PrinterInfo3 struct
4101 ********************************************************************/
4103 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
4104 const struct spoolss_PrinterInfo2 *info2,
4105 const char *servername,
4106 struct spoolss_PrinterInfo3 *r,
4107 int snum)
4109 /* These are the components of the SD we are returning. */
4111 if (info2->secdesc != NULL) {
4112 /* don't use talloc_steal() here unless you do a deep steal of all
4113 the SEC_DESC members */
4115 r->secdesc = security_descriptor_copy(mem_ctx, info2->secdesc);
4116 if (r->secdesc == NULL) {
4117 return WERR_NOMEM;
4121 return WERR_OK;
4124 /********************************************************************
4125 * construct_printer_info4
4126 * fill a spoolss_PrinterInfo4 struct
4127 ********************************************************************/
4129 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4130 const struct spoolss_PrinterInfo2 *info2,
4131 const char *servername,
4132 struct spoolss_PrinterInfo4 *r,
4133 int snum)
4135 WERROR result;
4137 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4138 if (!W_ERROR_IS_OK(result)) {
4139 return result;
4142 if (servername) {
4143 r->servername = talloc_strdup(mem_ctx, servername);
4144 W_ERROR_HAVE_NO_MEMORY(r->servername);
4145 } else {
4146 r->servername = NULL;
4149 r->attributes = info2->attributes;
4151 return WERR_OK;
4154 /********************************************************************
4155 * construct_printer_info5
4156 * fill a spoolss_PrinterInfo5 struct
4157 ********************************************************************/
4159 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4160 const struct spoolss_PrinterInfo2 *info2,
4161 const char *servername,
4162 struct spoolss_PrinterInfo5 *r,
4163 int snum)
4165 WERROR result;
4167 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4168 if (!W_ERROR_IS_OK(result)) {
4169 return result;
4172 r->portname = talloc_strdup(mem_ctx, info2->portname);
4173 W_ERROR_HAVE_NO_MEMORY(r->portname);
4175 r->attributes = info2->attributes;
4177 /* these two are not used by NT+ according to MSDN */
4178 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4179 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4181 return WERR_OK;
4184 /********************************************************************
4185 * construct_printer_info_6
4186 * fill a spoolss_PrinterInfo6 struct
4187 ********************************************************************/
4189 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4190 struct messaging_context *msg_ctx,
4191 const struct spoolss_PrinterInfo2 *info2,
4192 const char *servername,
4193 struct spoolss_PrinterInfo6 *r,
4194 int snum)
4196 print_status_struct status;
4198 print_queue_length(msg_ctx, snum, &status);
4200 r->status = nt_printq_status(status.status);
4202 return WERR_OK;
4205 /********************************************************************
4206 * construct_printer_info7
4207 * fill a spoolss_PrinterInfo7 struct
4208 ********************************************************************/
4210 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4211 struct messaging_context *msg_ctx,
4212 const char *servername,
4213 struct spoolss_PrinterInfo7 *r,
4214 int snum)
4216 const struct auth_session_info *session_info;
4217 char *printer;
4218 WERROR werr;
4219 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
4220 if (tmp_ctx == NULL) {
4221 return WERR_NOMEM;
4224 session_info = get_session_info_system();
4225 SMB_ASSERT(session_info != NULL);
4227 printer = lp_servicename(tmp_ctx, snum);
4228 if (printer == NULL) {
4229 DEBUG(0, ("invalid printer snum %d\n", snum));
4230 werr = WERR_INVALID_PARAM;
4231 goto out_tmp_free;
4234 if (is_printer_published(tmp_ctx, session_info, msg_ctx,
4235 servername, printer, NULL)) {
4236 struct GUID guid;
4237 struct GUID_txt_buf guid_txt;
4238 werr = nt_printer_guid_get(tmp_ctx, session_info, msg_ctx,
4239 printer, &guid);
4240 if (!W_ERROR_IS_OK(werr)) {
4242 * If we do not have a GUID entry in the registry, then
4243 * try to retrieve it from AD and store it now.
4245 werr = nt_printer_guid_retrieve(tmp_ctx, printer,
4246 &guid);
4247 if (!W_ERROR_IS_OK(werr)) {
4248 DEBUG(1, ("Failed to retrieve GUID for "
4249 "printer [%s] from AD - "
4250 "Is the the printer still "
4251 "published ?\n", printer));
4252 goto out_tmp_free;
4255 werr = nt_printer_guid_store(msg_ctx, printer, guid);
4256 if (!W_ERROR_IS_OK(werr)) {
4257 DEBUG(3, ("failed to store printer %s guid\n",
4258 printer));
4261 r->guid = talloc_strdup_upper(mem_ctx,
4262 GUID_buf_string(&guid, &guid_txt));
4263 r->action = DSPRINT_PUBLISH;
4264 } else {
4265 r->guid = talloc_strdup(mem_ctx, "");
4266 r->action = DSPRINT_UNPUBLISH;
4268 if (r->guid == NULL) {
4269 werr = WERR_NOMEM;
4270 goto out_tmp_free;
4273 werr = WERR_OK;
4274 out_tmp_free:
4275 talloc_free(tmp_ctx);
4276 return werr;
4279 /********************************************************************
4280 * construct_printer_info8
4281 * fill a spoolss_PrinterInfo8 struct
4282 ********************************************************************/
4284 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4285 const struct spoolss_PrinterInfo2 *info2,
4286 const char *servername,
4287 struct spoolss_DeviceModeInfo *r,
4288 int snum)
4290 WERROR result;
4291 const char *printername;
4293 result = create_printername(mem_ctx, servername, info2->printername, &printername);
4294 if (!W_ERROR_IS_OK(result)) {
4295 return result;
4298 if (info2->devmode != NULL) {
4299 result = copy_devicemode(mem_ctx,
4300 info2->devmode,
4301 &r->devmode);
4302 if (!W_ERROR_IS_OK(result)) {
4303 return result;
4305 } else if (lp_default_devmode(snum)) {
4306 result = spoolss_create_default_devmode(mem_ctx,
4307 info2->printername,
4308 &r->devmode);
4309 if (!W_ERROR_IS_OK(result)) {
4310 return result;
4312 } else {
4313 r->devmode = NULL;
4314 DEBUG(8,("Returning NULL Devicemode!\n"));
4317 compose_devicemode_devicename(r->devmode, printername);
4319 return WERR_OK;
4322 /********************************************************************
4323 Spoolss_enumprinters.
4324 ********************************************************************/
4326 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4327 const struct auth_session_info *session_info,
4328 struct messaging_context *msg_ctx,
4329 const char *servername,
4330 uint32_t level,
4331 uint32_t flags,
4332 union spoolss_PrinterInfo **info_p,
4333 uint32_t *count_p)
4335 int snum;
4336 int n_services;
4337 union spoolss_PrinterInfo *info = NULL;
4338 uint32_t count = 0;
4339 WERROR result = WERR_OK;
4340 struct dcerpc_binding_handle *b = NULL;
4341 TALLOC_CTX *tmp_ctx = NULL;
4343 tmp_ctx = talloc_new(mem_ctx);
4344 if (!tmp_ctx) {
4345 return WERR_NOMEM;
4349 * printer shares are updated on client enumeration. The background
4350 * printer process updates printer_list.tdb at regular intervals.
4352 become_root();
4353 delete_and_reload_printers(server_event_context(), msg_ctx);
4354 unbecome_root();
4356 n_services = lp_numservices();
4357 *count_p = 0;
4358 *info_p = NULL;
4360 for (snum = 0; snum < n_services; snum++) {
4362 const char *printer;
4363 struct spoolss_PrinterInfo2 *info2;
4365 if (!snum_is_shared_printer(snum)) {
4366 continue;
4369 printer = lp_const_servicename(snum);
4371 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4372 printer, snum));
4374 if (b == NULL) {
4375 result = winreg_printer_binding_handle(tmp_ctx,
4376 session_info,
4377 msg_ctx,
4378 &b);
4379 if (!W_ERROR_IS_OK(result)) {
4380 goto out;
4384 result = winreg_create_printer(tmp_ctx, b,
4385 printer);
4386 if (!W_ERROR_IS_OK(result)) {
4387 goto out;
4390 info = talloc_realloc(tmp_ctx, info,
4391 union spoolss_PrinterInfo,
4392 count + 1);
4393 if (!info) {
4394 result = WERR_NOMEM;
4395 goto out;
4398 result = winreg_get_printer(tmp_ctx, b,
4399 printer, &info2);
4400 if (!W_ERROR_IS_OK(result)) {
4401 goto out;
4404 switch (level) {
4405 case 0:
4406 result = construct_printer_info0(info, session_info,
4407 msg_ctx, info2,
4408 servername,
4409 &info[count].info0, snum);
4410 break;
4411 case 1:
4412 result = construct_printer_info1(info, info2, flags,
4413 servername,
4414 &info[count].info1, snum);
4415 break;
4416 case 2:
4417 result = construct_printer_info2(info, msg_ctx, info2,
4418 servername,
4419 &info[count].info2, snum);
4420 break;
4421 case 4:
4422 result = construct_printer_info4(info, info2,
4423 servername,
4424 &info[count].info4, snum);
4425 break;
4426 case 5:
4427 result = construct_printer_info5(info, info2,
4428 servername,
4429 &info[count].info5, snum);
4430 break;
4432 default:
4433 result = WERR_UNKNOWN_LEVEL;
4434 goto out;
4437 if (!W_ERROR_IS_OK(result)) {
4438 goto out;
4441 count++;
4444 out:
4445 if (W_ERROR_IS_OK(result)) {
4446 *info_p = talloc_move(mem_ctx, &info);
4447 *count_p = count;
4450 talloc_free(tmp_ctx);
4452 return result;
4455 /********************************************************************
4456 * handle enumeration of printers at level 0
4457 ********************************************************************/
4459 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4460 const struct auth_session_info *session_info,
4461 struct messaging_context *msg_ctx,
4462 uint32_t flags,
4463 const char *servername,
4464 union spoolss_PrinterInfo **info,
4465 uint32_t *count)
4467 DEBUG(4,("enum_all_printers_info_0\n"));
4469 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4470 servername, 0, flags, info, count);
4474 /********************************************************************
4475 ********************************************************************/
4477 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4478 const struct auth_session_info *session_info,
4479 struct messaging_context *msg_ctx,
4480 const char *servername,
4481 uint32_t flags,
4482 union spoolss_PrinterInfo **info,
4483 uint32_t *count)
4485 DEBUG(4,("enum_all_printers_info_1\n"));
4487 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4488 servername, 1, flags, info, count);
4491 /********************************************************************
4492 enum_all_printers_info_1_local.
4493 *********************************************************************/
4495 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4496 const struct auth_session_info *session_info,
4497 struct messaging_context *msg_ctx,
4498 const char *servername,
4499 union spoolss_PrinterInfo **info,
4500 uint32_t *count)
4502 DEBUG(4,("enum_all_printers_info_1_local\n"));
4504 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4505 servername, PRINTER_ENUM_ICON8, info, count);
4508 /********************************************************************
4509 enum_all_printers_info_1_name.
4510 *********************************************************************/
4512 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4513 const struct auth_session_info *session_info,
4514 struct messaging_context *msg_ctx,
4515 const char *servername,
4516 union spoolss_PrinterInfo **info,
4517 uint32_t *count)
4519 const char *s = servername;
4521 DEBUG(4,("enum_all_printers_info_1_name\n"));
4523 if (servername != NULL &&
4524 (servername[0] == '\\') && (servername[1] == '\\')) {
4525 s = servername + 2;
4528 if (!is_myname_or_ipaddr(s)) {
4529 return WERR_INVALID_NAME;
4532 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4533 servername, PRINTER_ENUM_ICON8, info, count);
4536 /********************************************************************
4537 enum_all_printers_info_1_network.
4538 *********************************************************************/
4540 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4541 const struct auth_session_info *session_info,
4542 struct messaging_context *msg_ctx,
4543 const char *servername,
4544 union spoolss_PrinterInfo **info,
4545 uint32_t *count)
4547 const char *s = servername;
4549 DEBUG(4,("enum_all_printers_info_1_network\n"));
4551 /* If we respond to a enum_printers level 1 on our name with flags
4552 set to PRINTER_ENUM_REMOTE with a list of printers then these
4553 printers incorrectly appear in the APW browse list.
4554 Specifically the printers for the server appear at the workgroup
4555 level where all the other servers in the domain are
4556 listed. Windows responds to this call with a
4557 WERR_CAN_NOT_COMPLETE so we should do the same. */
4559 if (servername != NULL &&
4560 (servername[0] == '\\') && (servername[1] == '\\')) {
4561 s = servername + 2;
4564 if (is_myname_or_ipaddr(s)) {
4565 return WERR_CAN_NOT_COMPLETE;
4568 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4569 servername, PRINTER_ENUM_NAME, info, count);
4572 /********************************************************************
4573 * api_spoolss_enumprinters
4575 * called from api_spoolss_enumprinters (see this to understand)
4576 ********************************************************************/
4578 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4579 const struct auth_session_info *session_info,
4580 struct messaging_context *msg_ctx,
4581 const char *servername,
4582 union spoolss_PrinterInfo **info,
4583 uint32_t *count)
4585 DEBUG(4,("enum_all_printers_info_2\n"));
4587 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4588 servername, 2, 0, info, count);
4591 /********************************************************************
4592 * handle enumeration of printers at level 1
4593 ********************************************************************/
4595 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4596 const struct auth_session_info *session_info,
4597 struct messaging_context *msg_ctx,
4598 uint32_t flags,
4599 const char *servername,
4600 union spoolss_PrinterInfo **info,
4601 uint32_t *count)
4603 /* Not all the flags are equals */
4605 if (flags & PRINTER_ENUM_LOCAL) {
4606 return enum_all_printers_info_1_local(mem_ctx, session_info,
4607 msg_ctx, servername, info, count);
4610 if (flags & PRINTER_ENUM_NAME) {
4611 return enum_all_printers_info_1_name(mem_ctx, session_info,
4612 msg_ctx, servername, info,
4613 count);
4616 if (flags & PRINTER_ENUM_NETWORK) {
4617 return enum_all_printers_info_1_network(mem_ctx, session_info,
4618 msg_ctx, servername, info,
4619 count);
4622 return WERR_OK; /* NT4sp5 does that */
4625 /********************************************************************
4626 * handle enumeration of printers at level 2
4627 ********************************************************************/
4629 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4630 const struct auth_session_info *session_info,
4631 struct messaging_context *msg_ctx,
4632 uint32_t flags,
4633 const char *servername,
4634 union spoolss_PrinterInfo **info,
4635 uint32_t *count)
4637 if (flags & PRINTER_ENUM_LOCAL) {
4639 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4640 servername,
4641 info, count);
4644 if (flags & PRINTER_ENUM_NAME) {
4645 if (servername && !is_myname_or_ipaddr(canon_servername(servername))) {
4646 return WERR_INVALID_NAME;
4649 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4650 servername,
4651 info, count);
4654 if (flags & PRINTER_ENUM_REMOTE) {
4655 return WERR_UNKNOWN_LEVEL;
4658 return WERR_OK;
4661 /********************************************************************
4662 * handle enumeration of printers at level 4
4663 ********************************************************************/
4665 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4666 const struct auth_session_info *session_info,
4667 struct messaging_context *msg_ctx,
4668 uint32_t flags,
4669 const char *servername,
4670 union spoolss_PrinterInfo **info,
4671 uint32_t *count)
4673 DEBUG(4,("enum_all_printers_info_4\n"));
4675 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4676 servername, 4, flags, info, count);
4680 /********************************************************************
4681 * handle enumeration of printers at level 5
4682 ********************************************************************/
4684 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4685 const struct auth_session_info *session_info,
4686 struct messaging_context *msg_ctx,
4687 uint32_t flags,
4688 const char *servername,
4689 union spoolss_PrinterInfo **info,
4690 uint32_t *count)
4692 DEBUG(4,("enum_all_printers_info_5\n"));
4694 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4695 servername, 5, flags, info, count);
4698 /****************************************************************
4699 _spoolss_EnumPrinters
4700 ****************************************************************/
4702 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4703 struct spoolss_EnumPrinters *r)
4705 const struct auth_session_info *session_info = get_session_info_system();
4706 WERROR result;
4708 /* that's an [in out] buffer */
4710 if (!r->in.buffer && (r->in.offered != 0)) {
4711 return WERR_INVALID_PARAM;
4714 DEBUG(4,("_spoolss_EnumPrinters\n"));
4716 *r->out.needed = 0;
4717 *r->out.count = 0;
4718 *r->out.info = NULL;
4721 * Level 1:
4722 * flags==PRINTER_ENUM_NAME
4723 * if name=="" then enumerates all printers
4724 * if name!="" then enumerate the printer
4725 * flags==PRINTER_ENUM_REMOTE
4726 * name is NULL, enumerate printers
4727 * Level 2: name!="" enumerates printers, name can't be NULL
4728 * Level 3: doesn't exist
4729 * Level 4: does a local registry lookup
4730 * Level 5: same as Level 2
4733 if (r->in.server && r->in.server[0] == '\0') {
4734 r->in.server = NULL;
4737 switch (r->in.level) {
4738 case 0:
4739 result = enumprinters_level0(p->mem_ctx, session_info,
4740 p->msg_ctx, r->in.flags,
4741 r->in.server,
4742 r->out.info, r->out.count);
4743 break;
4744 case 1:
4745 result = enumprinters_level1(p->mem_ctx, session_info,
4746 p->msg_ctx, r->in.flags,
4747 r->in.server,
4748 r->out.info, r->out.count);
4749 break;
4750 case 2:
4751 result = enumprinters_level2(p->mem_ctx, session_info,
4752 p->msg_ctx, r->in.flags,
4753 r->in.server,
4754 r->out.info, r->out.count);
4755 break;
4756 case 4:
4757 result = enumprinters_level4(p->mem_ctx, session_info,
4758 p->msg_ctx, r->in.flags,
4759 r->in.server,
4760 r->out.info, r->out.count);
4761 break;
4762 case 5:
4763 result = enumprinters_level5(p->mem_ctx, session_info,
4764 p->msg_ctx, r->in.flags,
4765 r->in.server,
4766 r->out.info, r->out.count);
4767 break;
4768 default:
4769 return WERR_UNKNOWN_LEVEL;
4772 if (!W_ERROR_IS_OK(result)) {
4773 return result;
4776 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4777 spoolss_EnumPrinters,
4778 *r->out.info, r->in.level,
4779 *r->out.count);
4780 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4781 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4783 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4786 /****************************************************************
4787 _spoolss_GetPrinter
4788 ****************************************************************/
4790 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4791 struct spoolss_GetPrinter *r)
4793 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
4794 struct spoolss_PrinterInfo2 *info2 = NULL;
4795 WERROR result = WERR_OK;
4796 int snum;
4798 /* that's an [in out] buffer */
4800 if (!r->in.buffer && (r->in.offered != 0)) {
4801 result = WERR_INVALID_PARAM;
4802 goto err_info_free;
4805 *r->out.needed = 0;
4807 if (Printer == NULL) {
4808 result = WERR_BADFID;
4809 goto err_info_free;
4812 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4813 result = WERR_BADFID;
4814 goto err_info_free;
4817 result = winreg_get_printer_internal(p->mem_ctx,
4818 get_session_info_system(),
4819 p->msg_ctx,
4820 lp_const_servicename(snum),
4821 &info2);
4822 if (!W_ERROR_IS_OK(result)) {
4823 goto err_info_free;
4826 switch (r->in.level) {
4827 case 0:
4828 result = construct_printer_info0(p->mem_ctx,
4829 get_session_info_system(),
4830 p->msg_ctx,
4831 info2,
4832 Printer->servername,
4833 &r->out.info->info0,
4834 snum);
4835 break;
4836 case 1:
4837 result = construct_printer_info1(p->mem_ctx, info2,
4838 PRINTER_ENUM_ICON8,
4839 Printer->servername,
4840 &r->out.info->info1, snum);
4841 break;
4842 case 2:
4843 result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
4844 Printer->servername,
4845 &r->out.info->info2, snum);
4846 break;
4847 case 3:
4848 result = construct_printer_info3(p->mem_ctx, info2,
4849 Printer->servername,
4850 &r->out.info->info3, snum);
4851 break;
4852 case 4:
4853 result = construct_printer_info4(p->mem_ctx, info2,
4854 Printer->servername,
4855 &r->out.info->info4, snum);
4856 break;
4857 case 5:
4858 result = construct_printer_info5(p->mem_ctx, info2,
4859 Printer->servername,
4860 &r->out.info->info5, snum);
4861 break;
4862 case 6:
4863 result = construct_printer_info6(p->mem_ctx, p->msg_ctx, info2,
4864 Printer->servername,
4865 &r->out.info->info6, snum);
4866 break;
4867 case 7:
4868 result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
4869 Printer->servername,
4870 &r->out.info->info7, snum);
4871 break;
4872 case 8:
4873 result = construct_printer_info8(p->mem_ctx, info2,
4874 Printer->servername,
4875 &r->out.info->info8, snum);
4876 break;
4877 default:
4878 result = WERR_UNKNOWN_LEVEL;
4879 break;
4881 TALLOC_FREE(info2);
4883 if (!W_ERROR_IS_OK(result)) {
4884 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4885 r->in.level, win_errstr(result)));
4886 goto err_info_free;
4889 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4890 r->out.info, r->in.level);
4891 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4893 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4895 err_info_free:
4896 TALLOC_FREE(r->out.info);
4897 return result;
4900 /********************************************************************
4901 ********************************************************************/
4903 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4904 do { \
4905 if (in && strlen(in)) { \
4906 out = talloc_strdup(mem_ctx, in); \
4907 } else { \
4908 out = talloc_strdup(mem_ctx, ""); \
4910 W_ERROR_HAVE_NO_MEMORY(out); \
4911 } while (0);
4913 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4914 do { \
4915 if (in && strlen(in)) { \
4916 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4917 } else { \
4918 out = talloc_strdup(mem_ctx, ""); \
4920 W_ERROR_HAVE_NO_MEMORY(out); \
4921 } while (0);
4923 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4924 const char **string_array,
4925 const char ***presult,
4926 const char *cservername,
4927 const char *arch,
4928 int version)
4930 int i;
4931 size_t num_strings = 0;
4932 const char **array = NULL;
4934 if (string_array == NULL) {
4935 return WERR_INVALID_PARAMETER;
4938 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4939 const char *str = NULL;
4941 if (cservername == NULL || arch == NULL) {
4942 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4943 } else {
4944 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4947 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4948 TALLOC_FREE(array);
4949 return WERR_NOMEM;
4953 if (i > 0) {
4954 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4955 &array, &num_strings);
4958 if (presult != NULL) {
4959 *presult = array;
4960 } else {
4961 talloc_free(array);
4964 return WERR_OK;
4967 /********************************************************************
4968 * fill a spoolss_DriverInfo1 struct
4969 ********************************************************************/
4971 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4972 struct spoolss_DriverInfo1 *r,
4973 const struct spoolss_DriverInfo8 *driver,
4974 const char *servername)
4976 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4977 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4979 return WERR_OK;
4982 /********************************************************************
4983 * fill a spoolss_DriverInfo2 struct
4984 ********************************************************************/
4986 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4987 struct spoolss_DriverInfo2 *r,
4988 const struct spoolss_DriverInfo8 *driver,
4989 const char *servername)
4992 const char *cservername = canon_servername(servername);
4994 r->version = driver->version;
4996 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4997 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4998 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4999 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5001 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5002 driver->architecture,
5003 driver->version,
5004 driver->driver_path,
5005 r->driver_path);
5007 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5008 driver->architecture,
5009 driver->version,
5010 driver->data_file,
5011 r->data_file);
5013 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5014 driver->architecture,
5015 driver->version,
5016 driver->config_file,
5017 r->config_file);
5019 return WERR_OK;
5022 /********************************************************************
5023 * fill a spoolss_DriverInfo3 struct
5024 ********************************************************************/
5026 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
5027 struct spoolss_DriverInfo3 *r,
5028 const struct spoolss_DriverInfo8 *driver,
5029 const char *servername)
5031 const char *cservername = canon_servername(servername);
5033 r->version = driver->version;
5035 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5036 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5037 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5038 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5040 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5041 driver->architecture,
5042 driver->version,
5043 driver->driver_path,
5044 r->driver_path);
5046 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5047 driver->architecture,
5048 driver->version,
5049 driver->data_file,
5050 r->data_file);
5052 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5053 driver->architecture,
5054 driver->version,
5055 driver->config_file,
5056 r->config_file);
5058 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5059 driver->architecture,
5060 driver->version,
5061 driver->help_file,
5062 r->help_file);
5064 FILL_DRIVER_STRING(mem_ctx,
5065 driver->monitor_name,
5066 r->monitor_name);
5068 FILL_DRIVER_STRING(mem_ctx,
5069 driver->default_datatype,
5070 r->default_datatype);
5072 return string_array_from_driver_info(mem_ctx,
5073 driver->dependent_files,
5074 &r->dependent_files,
5075 cservername,
5076 driver->architecture,
5077 driver->version);
5080 /********************************************************************
5081 * fill a spoolss_DriverInfo4 struct
5082 ********************************************************************/
5084 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
5085 struct spoolss_DriverInfo4 *r,
5086 const struct spoolss_DriverInfo8 *driver,
5087 const char *servername)
5089 const char *cservername = canon_servername(servername);
5090 WERROR result;
5092 r->version = driver->version;
5094 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5095 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5096 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5097 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5099 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5100 driver->architecture,
5101 driver->version,
5102 driver->driver_path,
5103 r->driver_path);
5105 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5106 driver->architecture,
5107 driver->version,
5108 driver->data_file,
5109 r->data_file);
5111 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5112 driver->architecture,
5113 driver->version,
5114 driver->config_file,
5115 r->config_file);
5117 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5118 driver->architecture,
5119 driver->version,
5120 driver->help_file,
5121 r->help_file);
5123 result = string_array_from_driver_info(mem_ctx,
5124 driver->dependent_files,
5125 &r->dependent_files,
5126 cservername,
5127 driver->architecture,
5128 driver->version);
5129 if (!W_ERROR_IS_OK(result)) {
5130 return result;
5133 FILL_DRIVER_STRING(mem_ctx,
5134 driver->monitor_name,
5135 r->monitor_name);
5137 FILL_DRIVER_STRING(mem_ctx,
5138 driver->default_datatype,
5139 r->default_datatype);
5142 result = string_array_from_driver_info(mem_ctx,
5143 driver->previous_names,
5144 &r->previous_names,
5145 NULL, NULL, 0);
5147 return result;
5150 /********************************************************************
5151 * fill a spoolss_DriverInfo5 struct
5152 ********************************************************************/
5154 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
5155 struct spoolss_DriverInfo5 *r,
5156 const struct spoolss_DriverInfo8 *driver,
5157 const char *servername)
5159 const char *cservername = canon_servername(servername);
5161 r->version = driver->version;
5163 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5164 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5165 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5166 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5168 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5169 driver->architecture,
5170 driver->version,
5171 driver->driver_path,
5172 r->driver_path);
5174 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5175 driver->architecture,
5176 driver->version,
5177 driver->data_file,
5178 r->data_file);
5180 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5181 driver->architecture,
5182 driver->version,
5183 driver->config_file,
5184 r->config_file);
5186 r->driver_attributes = 0;
5187 r->config_version = 0;
5188 r->driver_version = 0;
5190 return WERR_OK;
5192 /********************************************************************
5193 * fill a spoolss_DriverInfo6 struct
5194 ********************************************************************/
5196 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
5197 struct spoolss_DriverInfo6 *r,
5198 const struct spoolss_DriverInfo8 *driver,
5199 const char *servername)
5201 const char *cservername = canon_servername(servername);
5202 WERROR result;
5204 r->version = driver->version;
5206 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5207 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5208 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5209 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5211 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5212 driver->architecture,
5213 driver->version,
5214 driver->driver_path,
5215 r->driver_path);
5217 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5218 driver->architecture,
5219 driver->version,
5220 driver->data_file,
5221 r->data_file);
5223 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5224 driver->architecture,
5225 driver->version,
5226 driver->config_file,
5227 r->config_file);
5229 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5230 driver->architecture,
5231 driver->version,
5232 driver->help_file,
5233 r->help_file);
5235 FILL_DRIVER_STRING(mem_ctx,
5236 driver->monitor_name,
5237 r->monitor_name);
5239 FILL_DRIVER_STRING(mem_ctx,
5240 driver->default_datatype,
5241 r->default_datatype);
5243 result = string_array_from_driver_info(mem_ctx,
5244 driver->dependent_files,
5245 &r->dependent_files,
5246 cservername,
5247 driver->architecture,
5248 driver->version);
5249 if (!W_ERROR_IS_OK(result)) {
5250 return result;
5253 result = string_array_from_driver_info(mem_ctx,
5254 driver->previous_names,
5255 &r->previous_names,
5256 NULL, NULL, 0);
5257 if (!W_ERROR_IS_OK(result)) {
5258 return result;
5261 r->driver_date = driver->driver_date;
5262 r->driver_version = driver->driver_version;
5264 FILL_DRIVER_STRING(mem_ctx,
5265 driver->manufacturer_name,
5266 r->manufacturer_name);
5267 FILL_DRIVER_STRING(mem_ctx,
5268 driver->manufacturer_url,
5269 r->manufacturer_url);
5270 FILL_DRIVER_STRING(mem_ctx,
5271 driver->hardware_id,
5272 r->hardware_id);
5273 FILL_DRIVER_STRING(mem_ctx,
5274 driver->provider,
5275 r->provider);
5277 return WERR_OK;
5280 /********************************************************************
5281 * fill a spoolss_DriverInfo8 struct
5282 ********************************************************************/
5284 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
5285 struct spoolss_DriverInfo8 *r,
5286 const struct spoolss_DriverInfo8 *driver,
5287 const char *servername)
5289 const char *cservername = canon_servername(servername);
5290 WERROR result;
5292 r->version = driver->version;
5294 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5295 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5296 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5297 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5299 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5300 driver->architecture,
5301 driver->version,
5302 driver->driver_path,
5303 r->driver_path);
5305 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5306 driver->architecture,
5307 driver->version,
5308 driver->data_file,
5309 r->data_file);
5311 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5312 driver->architecture,
5313 driver->version,
5314 driver->config_file,
5315 r->config_file);
5317 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5318 driver->architecture,
5319 driver->version,
5320 driver->help_file,
5321 r->help_file);
5323 FILL_DRIVER_STRING(mem_ctx,
5324 driver->monitor_name,
5325 r->monitor_name);
5327 FILL_DRIVER_STRING(mem_ctx,
5328 driver->default_datatype,
5329 r->default_datatype);
5331 result = string_array_from_driver_info(mem_ctx,
5332 driver->dependent_files,
5333 &r->dependent_files,
5334 cservername,
5335 driver->architecture,
5336 driver->version);
5337 if (!W_ERROR_IS_OK(result)) {
5338 return result;
5341 result = string_array_from_driver_info(mem_ctx,
5342 driver->previous_names,
5343 &r->previous_names,
5344 NULL, NULL, 0);
5345 if (!W_ERROR_IS_OK(result)) {
5346 return result;
5349 r->driver_date = driver->driver_date;
5350 r->driver_version = driver->driver_version;
5352 FILL_DRIVER_STRING(mem_ctx,
5353 driver->manufacturer_name,
5354 r->manufacturer_name);
5355 FILL_DRIVER_STRING(mem_ctx,
5356 driver->manufacturer_url,
5357 r->manufacturer_url);
5358 FILL_DRIVER_STRING(mem_ctx,
5359 driver->hardware_id,
5360 r->hardware_id);
5361 FILL_DRIVER_STRING(mem_ctx,
5362 driver->provider,
5363 r->provider);
5365 FILL_DRIVER_STRING(mem_ctx,
5366 driver->print_processor,
5367 r->print_processor);
5368 FILL_DRIVER_STRING(mem_ctx,
5369 driver->vendor_setup,
5370 r->vendor_setup);
5372 result = string_array_from_driver_info(mem_ctx,
5373 driver->color_profiles,
5374 &r->color_profiles,
5375 NULL, NULL, 0);
5376 if (!W_ERROR_IS_OK(result)) {
5377 return result;
5380 FILL_DRIVER_STRING(mem_ctx,
5381 driver->inf_path,
5382 r->inf_path);
5384 r->printer_driver_attributes = driver->printer_driver_attributes;
5386 result = string_array_from_driver_info(mem_ctx,
5387 driver->core_driver_dependencies,
5388 &r->core_driver_dependencies,
5389 NULL, NULL, 0);
5390 if (!W_ERROR_IS_OK(result)) {
5391 return result;
5394 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
5395 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
5397 return WERR_OK;
5400 #if 0 /* disabled until marshalling issues are resolved - gd */
5401 /********************************************************************
5402 ********************************************************************/
5404 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5405 struct spoolss_DriverFileInfo *r,
5406 const char *cservername,
5407 const char *file_name,
5408 enum spoolss_DriverFileType file_type,
5409 uint32_t file_version)
5411 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5412 cservername, file_name);
5413 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5414 r->file_type = file_type;
5415 r->file_version = file_version;
5417 return WERR_OK;
5420 /********************************************************************
5421 ********************************************************************/
5423 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5424 const struct spoolss_DriverInfo8 *driver,
5425 const char *cservername,
5426 struct spoolss_DriverFileInfo **info_p,
5427 uint32_t *count_p)
5429 struct spoolss_DriverFileInfo *info = NULL;
5430 uint32_t count = 0;
5431 WERROR result;
5432 uint32_t i;
5434 *info_p = NULL;
5435 *count_p = 0;
5437 if (strlen(driver->driver_path)) {
5438 info = talloc_realloc(mem_ctx, info,
5439 struct spoolss_DriverFileInfo,
5440 count + 1);
5441 W_ERROR_HAVE_NO_MEMORY(info);
5442 result = fill_spoolss_DriverFileInfo(info,
5443 &info[count],
5444 cservername,
5445 driver->driver_path,
5446 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5448 W_ERROR_NOT_OK_RETURN(result);
5449 count++;
5452 if (strlen(driver->config_file)) {
5453 info = talloc_realloc(mem_ctx, info,
5454 struct spoolss_DriverFileInfo,
5455 count + 1);
5456 W_ERROR_HAVE_NO_MEMORY(info);
5457 result = fill_spoolss_DriverFileInfo(info,
5458 &info[count],
5459 cservername,
5460 driver->config_file,
5461 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5463 W_ERROR_NOT_OK_RETURN(result);
5464 count++;
5467 if (strlen(driver->data_file)) {
5468 info = talloc_realloc(mem_ctx, info,
5469 struct spoolss_DriverFileInfo,
5470 count + 1);
5471 W_ERROR_HAVE_NO_MEMORY(info);
5472 result = fill_spoolss_DriverFileInfo(info,
5473 &info[count],
5474 cservername,
5475 driver->data_file,
5476 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5478 W_ERROR_NOT_OK_RETURN(result);
5479 count++;
5482 if (strlen(driver->help_file)) {
5483 info = talloc_realloc(mem_ctx, info,
5484 struct spoolss_DriverFileInfo,
5485 count + 1);
5486 W_ERROR_HAVE_NO_MEMORY(info);
5487 result = fill_spoolss_DriverFileInfo(info,
5488 &info[count],
5489 cservername,
5490 driver->help_file,
5491 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5493 W_ERROR_NOT_OK_RETURN(result);
5494 count++;
5497 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
5498 info = talloc_realloc(mem_ctx, info,
5499 struct spoolss_DriverFileInfo,
5500 count + 1);
5501 W_ERROR_HAVE_NO_MEMORY(info);
5502 result = fill_spoolss_DriverFileInfo(info,
5503 &info[count],
5504 cservername,
5505 driver->dependent_files[i],
5506 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5508 W_ERROR_NOT_OK_RETURN(result);
5509 count++;
5512 *info_p = info;
5513 *count_p = count;
5515 return WERR_OK;
5518 /********************************************************************
5519 * fill a spoolss_DriverInfo101 struct
5520 ********************************************************************/
5522 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5523 struct spoolss_DriverInfo101 *r,
5524 const struct spoolss_DriverInfo8 *driver,
5525 const char *servername)
5527 const char *cservername = canon_servername(servername);
5528 WERROR result;
5530 r->version = driver->version;
5532 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5533 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5534 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5535 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5537 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5538 cservername,
5539 &r->file_info,
5540 &r->file_count);
5541 if (!W_ERROR_IS_OK(result)) {
5542 return result;
5545 FILL_DRIVER_STRING(mem_ctx,
5546 driver->monitor_name,
5547 r->monitor_name);
5549 FILL_DRIVER_STRING(mem_ctx,
5550 driver->default_datatype,
5551 r->default_datatype);
5553 result = string_array_from_driver_info(mem_ctx,
5554 driver->previous_names,
5555 &r->previous_names,
5556 NULL, NULL, 0);
5557 if (!W_ERROR_IS_OK(result)) {
5558 return result;
5561 r->driver_date = driver->driver_date;
5562 r->driver_version = driver->driver_version;
5564 FILL_DRIVER_STRING(mem_ctx,
5565 driver->manufacturer_name,
5566 r->manufacturer_name);
5567 FILL_DRIVER_STRING(mem_ctx,
5568 driver->manufacturer_url,
5569 r->manufacturer_url);
5570 FILL_DRIVER_STRING(mem_ctx,
5571 driver->hardware_id,
5572 r->hardware_id);
5573 FILL_DRIVER_STRING(mem_ctx,
5574 driver->provider,
5575 r->provider);
5577 return WERR_OK;
5579 #endif
5580 /********************************************************************
5581 ********************************************************************/
5583 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5584 const struct auth_session_info *session_info,
5585 struct messaging_context *msg_ctx,
5586 uint32_t level,
5587 union spoolss_DriverInfo *r,
5588 int snum,
5589 const char *servername,
5590 const char *architecture,
5591 uint32_t version)
5593 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5594 struct spoolss_DriverInfo8 *driver;
5595 WERROR result;
5596 struct dcerpc_binding_handle *b;
5597 TALLOC_CTX *tmp_ctx = NULL;
5599 if (level == 101) {
5600 return WERR_UNKNOWN_LEVEL;
5603 tmp_ctx = talloc_new(mem_ctx);
5604 if (!tmp_ctx) {
5605 return WERR_NOMEM;
5608 result = winreg_printer_binding_handle(tmp_ctx,
5609 session_info,
5610 msg_ctx,
5611 &b);
5612 if (!W_ERROR_IS_OK(result)) {
5613 goto done;
5616 result = winreg_get_printer(tmp_ctx, b,
5617 lp_const_servicename(snum),
5618 &pinfo2);
5620 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5621 win_errstr(result)));
5623 if (!W_ERROR_IS_OK(result)) {
5624 result = WERR_INVALID_PRINTER_NAME;
5625 goto done;
5628 result = winreg_get_driver(tmp_ctx, b,
5629 architecture,
5630 pinfo2->drivername, version, &driver);
5632 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5633 win_errstr(result)));
5635 if (!W_ERROR_IS_OK(result)) {
5637 * Is this a W2k client ?
5640 if (version < 3) {
5641 result = WERR_UNKNOWN_PRINTER_DRIVER;
5642 goto done;
5645 /* Yes - try again with a WinNT driver. */
5646 version = 2;
5647 result = winreg_get_driver(tmp_ctx, b,
5648 architecture,
5649 pinfo2->drivername,
5650 version, &driver);
5651 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5652 win_errstr(result)));
5653 if (!W_ERROR_IS_OK(result)) {
5654 result = WERR_UNKNOWN_PRINTER_DRIVER;
5655 goto done;
5659 /* these are allocated on mem_ctx and not tmp_ctx because they are
5660 * the 'return value' and need to utlive this call */
5661 switch (level) {
5662 case 1:
5663 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5664 break;
5665 case 2:
5666 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5667 break;
5668 case 3:
5669 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5670 break;
5671 case 4:
5672 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5673 break;
5674 case 5:
5675 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5676 break;
5677 case 6:
5678 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5679 break;
5680 case 8:
5681 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5682 break;
5683 #if 0 /* disabled until marshalling issues are resolved - gd */
5684 case 101:
5685 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5686 break;
5687 #endif
5688 default:
5689 result = WERR_UNKNOWN_LEVEL;
5690 break;
5693 done:
5694 talloc_free(tmp_ctx);
5695 return result;
5698 /****************************************************************
5699 _spoolss_GetPrinterDriver2
5700 ****************************************************************/
5702 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5703 struct spoolss_GetPrinterDriver2 *r)
5705 struct printer_handle *printer;
5706 WERROR result;
5707 uint32_t version = r->in.client_major_version;
5709 int snum;
5711 /* that's an [in out] buffer */
5713 if (!r->in.buffer && (r->in.offered != 0)) {
5714 result = WERR_INVALID_PARAM;
5715 goto err_info_free;
5718 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5720 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5721 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5722 result = WERR_INVALID_PRINTER_NAME;
5723 goto err_info_free;
5726 *r->out.needed = 0;
5727 *r->out.server_major_version = 0;
5728 *r->out.server_minor_version = 0;
5730 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5731 result = WERR_BADFID;
5732 goto err_info_free;
5735 if (r->in.client_major_version == SPOOLSS_DRIVER_VERSION_2012) {
5736 DEBUG(3,("_spoolss_GetPrinterDriver2: v4 driver requested, "
5737 "downgrading to v3\n"));
5738 version = SPOOLSS_DRIVER_VERSION_200X;
5741 result = construct_printer_driver_info_level(p->mem_ctx,
5742 get_session_info_system(),
5743 p->msg_ctx,
5744 r->in.level, r->out.info,
5745 snum, printer->servername,
5746 r->in.architecture,
5747 version);
5748 if (!W_ERROR_IS_OK(result)) {
5749 goto err_info_free;
5752 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5753 r->out.info, r->in.level);
5754 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5756 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5758 err_info_free:
5759 TALLOC_FREE(r->out.info);
5760 return result;
5764 /****************************************************************
5765 _spoolss_StartPagePrinter
5766 ****************************************************************/
5768 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5769 struct spoolss_StartPagePrinter *r)
5771 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5773 if (!Printer) {
5774 DEBUG(3,("_spoolss_StartPagePrinter: "
5775 "Error in startpageprinter printer handle\n"));
5776 return WERR_BADFID;
5779 Printer->page_started = true;
5780 return WERR_OK;
5783 /****************************************************************
5784 _spoolss_EndPagePrinter
5785 ****************************************************************/
5787 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5788 struct spoolss_EndPagePrinter *r)
5790 int snum;
5792 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5794 if (!Printer) {
5795 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5796 OUR_HANDLE(r->in.handle)));
5797 return WERR_BADFID;
5800 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5801 return WERR_BADFID;
5803 Printer->page_started = false;
5804 print_job_endpage(p->msg_ctx, snum, Printer->jobid);
5806 return WERR_OK;
5809 /****************************************************************
5810 _spoolss_StartDocPrinter
5811 ****************************************************************/
5813 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5814 struct spoolss_StartDocPrinter *r)
5816 struct spoolss_DocumentInfo1 *info_1;
5817 int snum;
5818 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5819 WERROR werr;
5820 char *rhost;
5821 int rc;
5823 if (!Printer) {
5824 DEBUG(2,("_spoolss_StartDocPrinter: "
5825 "Invalid handle (%s:%u:%u)\n",
5826 OUR_HANDLE(r->in.handle)));
5827 return WERR_BADFID;
5830 if (Printer->jobid) {
5831 DEBUG(2, ("_spoolss_StartDocPrinter: "
5832 "StartDocPrinter called twice! "
5833 "(existing jobid = %d)\n", Printer->jobid));
5834 return WERR_INVALID_HANDLE;
5837 if (r->in.info_ctr->level != 1) {
5838 return WERR_UNKNOWN_LEVEL;
5841 info_1 = r->in.info_ctr->info.info1;
5844 * a nice thing with NT is it doesn't listen to what you tell it.
5845 * when asked to send _only_ RAW datas, it tries to send datas
5846 * in EMF format.
5848 * So I add checks like in NT Server ...
5851 if (info_1->datatype) {
5853 * The v4 driver model used in Windows 8 declares print jobs
5854 * intended to bypass the XPS processing layer by setting
5855 * datatype to "XPS_PASS" instead of "RAW".
5857 if ((strcmp(info_1->datatype, "RAW") != 0)
5858 && (strcmp(info_1->datatype, "XPS_PASS") != 0)) {
5859 *r->out.job_id = 0;
5860 return WERR_INVALID_DATATYPE;
5864 /* get the share number of the printer */
5865 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5866 return WERR_BADFID;
5869 rc = get_remote_hostname(p->remote_address,
5870 &rhost,
5871 p->mem_ctx);
5872 if (rc < 0) {
5873 return WERR_NOMEM;
5875 if (strequal(rhost,"UNKNOWN")) {
5876 rhost = tsocket_address_inet_addr_string(p->remote_address,
5877 p->mem_ctx);
5878 if (rhost == NULL) {
5879 return WERR_NOMEM;
5883 werr = print_job_start(p->session_info,
5884 p->msg_ctx,
5885 rhost,
5886 snum,
5887 info_1->document_name,
5888 info_1->output_file,
5889 Printer->devmode,
5890 &Printer->jobid);
5892 /* An error occured in print_job_start() so return an appropriate
5893 NT error code. */
5895 if (!W_ERROR_IS_OK(werr)) {
5896 return werr;
5899 Printer->document_started = true;
5900 *r->out.job_id = Printer->jobid;
5902 return WERR_OK;
5905 /****************************************************************
5906 _spoolss_EndDocPrinter
5907 ****************************************************************/
5909 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5910 struct spoolss_EndDocPrinter *r)
5912 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5913 NTSTATUS status;
5914 int snum;
5916 if (!Printer) {
5917 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5918 OUR_HANDLE(r->in.handle)));
5919 return WERR_BADFID;
5922 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5923 return WERR_BADFID;
5926 Printer->document_started = false;
5927 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5928 if (!NT_STATUS_IS_OK(status)) {
5929 DEBUG(2, ("_spoolss_EndDocPrinter: "
5930 "print_job_end failed [%s]\n",
5931 nt_errstr(status)));
5934 Printer->jobid = 0;
5935 return ntstatus_to_werror(status);
5938 /****************************************************************
5939 _spoolss_WritePrinter
5940 ****************************************************************/
5942 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5943 struct spoolss_WritePrinter *r)
5945 ssize_t buffer_written;
5946 int snum;
5947 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5949 if (!Printer) {
5950 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5951 OUR_HANDLE(r->in.handle)));
5952 *r->out.num_written = r->in._data_size;
5953 return WERR_BADFID;
5956 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5957 return WERR_BADFID;
5959 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5960 buffer_written = print_job_write(server_event_context(),p->msg_ctx,
5961 snum, Printer->jobid,
5962 (const char *)r->in.data.data,
5963 (size_t)r->in._data_size);
5964 if (buffer_written == (ssize_t)-1) {
5965 *r->out.num_written = 0;
5966 if (errno == ENOSPC)
5967 return WERR_NO_SPOOL_SPACE;
5968 else
5969 return WERR_ACCESS_DENIED;
5972 *r->out.num_written = r->in._data_size;
5974 return WERR_OK;
5977 /********************************************************************
5978 * api_spoolss_getprinter
5979 * called from the spoolss dispatcher
5981 ********************************************************************/
5983 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5984 struct pipes_struct *p)
5986 const struct auth_session_info *session_info = p->session_info;
5987 int snum;
5988 WERROR errcode = WERR_BADFUNC;
5989 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5991 if (!Printer) {
5992 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5993 OUR_HANDLE(handle)));
5994 return WERR_BADFID;
5997 if (!get_printer_snum(p, handle, &snum, NULL))
5998 return WERR_BADFID;
6000 switch (command) {
6001 case SPOOLSS_PRINTER_CONTROL_PAUSE:
6002 errcode = print_queue_pause(session_info, p->msg_ctx, snum);
6003 break;
6004 case SPOOLSS_PRINTER_CONTROL_RESUME:
6005 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
6006 errcode = print_queue_resume(session_info, p->msg_ctx, snum);
6007 break;
6008 case SPOOLSS_PRINTER_CONTROL_PURGE:
6009 errcode = print_queue_purge(session_info, p->msg_ctx, snum);
6010 break;
6011 default:
6012 return WERR_UNKNOWN_LEVEL;
6015 return errcode;
6019 /****************************************************************
6020 _spoolss_AbortPrinter
6021 * From MSDN: "Deletes printer's spool file if printer is configured
6022 * for spooling"
6023 ****************************************************************/
6025 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
6026 struct spoolss_AbortPrinter *r)
6028 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6029 int snum;
6030 WERROR errcode = WERR_OK;
6032 if (!Printer) {
6033 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
6034 OUR_HANDLE(r->in.handle)));
6035 return WERR_BADFID;
6038 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
6039 return WERR_BADFID;
6041 if (!Printer->document_started) {
6042 return WERR_SPL_NO_STARTDOC;
6045 errcode = print_job_delete(p->session_info,
6046 p->msg_ctx,
6047 snum,
6048 Printer->jobid);
6050 return errcode;
6053 /********************************************************************
6054 * called by spoolss_api_setprinter
6055 * when updating a printer description
6056 ********************************************************************/
6058 static WERROR update_printer_sec(struct policy_handle *handle,
6059 struct pipes_struct *p,
6060 struct sec_desc_buf *secdesc_ctr)
6062 struct spoolss_security_descriptor *new_secdesc = NULL;
6063 struct spoolss_security_descriptor *old_secdesc = NULL;
6064 const char *printer;
6065 WERROR result;
6066 int snum;
6067 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6068 struct dcerpc_binding_handle *b;
6069 TALLOC_CTX *tmp_ctx = NULL;
6071 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
6072 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
6073 OUR_HANDLE(handle)));
6075 result = WERR_BADFID;
6076 goto done;
6079 if (secdesc_ctr == NULL) {
6080 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
6081 result = WERR_INVALID_PARAM;
6082 goto done;
6084 printer = lp_const_servicename(snum);
6086 /* Check the user has permissions to change the security
6087 descriptor. By experimentation with two NT machines, the user
6088 requires Full Access to the printer to change security
6089 information. */
6091 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
6092 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
6093 result = WERR_ACCESS_DENIED;
6094 goto done;
6097 tmp_ctx = talloc_new(p->mem_ctx);
6098 if (!tmp_ctx) {
6099 return WERR_NOMEM;
6102 result = winreg_printer_binding_handle(tmp_ctx,
6103 get_session_info_system(),
6104 p->msg_ctx,
6105 &b);
6106 if (!W_ERROR_IS_OK(result)) {
6107 goto done;
6110 /* NT seems to like setting the security descriptor even though
6111 nothing may have actually changed. */
6112 result = winreg_get_printer_secdesc(tmp_ctx, b,
6113 printer,
6114 &old_secdesc);
6115 if (!W_ERROR_IS_OK(result)) {
6116 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc_internal() failed\n"));
6117 result = WERR_BADFID;
6118 goto done;
6121 if (DEBUGLEVEL >= 10) {
6122 struct security_acl *the_acl;
6123 int i;
6125 the_acl = old_secdesc->dacl;
6126 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
6127 printer, the_acl->num_aces));
6129 for (i = 0; i < the_acl->num_aces; i++) {
6130 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6131 &the_acl->aces[i].trustee),
6132 the_acl->aces[i].access_mask));
6135 the_acl = secdesc_ctr->sd->dacl;
6137 if (the_acl) {
6138 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
6139 printer, the_acl->num_aces));
6141 for (i = 0; i < the_acl->num_aces; i++) {
6142 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6143 &the_acl->aces[i].trustee),
6144 the_acl->aces[i].access_mask));
6146 } else {
6147 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
6151 new_secdesc = sec_desc_merge(tmp_ctx, secdesc_ctr->sd, old_secdesc);
6152 if (new_secdesc == NULL) {
6153 result = WERR_NOMEM;
6154 goto done;
6157 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
6158 result = WERR_OK;
6159 goto done;
6162 result = winreg_set_printer_secdesc(tmp_ctx, b,
6163 printer,
6164 new_secdesc);
6166 done:
6167 talloc_free(tmp_ctx);
6168 return result;
6171 /********************************************************************
6172 Canonicalize printer info from a client
6173 ********************************************************************/
6175 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
6176 struct spoolss_SetPrinterInfo2 *info2,
6177 int snum)
6179 fstring printername;
6180 const char *p;
6182 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
6183 "portname=%s drivername=%s comment=%s location=%s\n",
6184 info2->servername, info2->printername, info2->sharename,
6185 info2->portname, info2->drivername, info2->comment,
6186 info2->location));
6188 /* we force some elements to "correct" values */
6189 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", lp_netbios_name());
6190 if (info2->servername == NULL) {
6191 return false;
6193 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
6194 if (info2->sharename == NULL) {
6195 return false;
6198 /* check to see if we allow printername != sharename */
6199 if (lp_force_printername(snum)) {
6200 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6201 lp_netbios_name(), info2->sharename);
6202 } else {
6203 /* make sure printername is in \\server\printername format */
6204 fstrcpy(printername, info2->printername);
6205 p = printername;
6206 if ( printername[0] == '\\' && printername[1] == '\\' ) {
6207 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
6208 p++;
6211 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6212 lp_netbios_name(), p);
6214 if (info2->printername == NULL) {
6215 return false;
6218 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
6219 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
6221 return true;
6224 /****************************************************************************
6225 ****************************************************************************/
6227 static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const char *portname, const char *uri)
6229 char *cmd = lp_addport_command(talloc_tos());
6230 char *command = NULL;
6231 int ret;
6232 bool is_print_op = false;
6234 if ( !*cmd ) {
6235 return WERR_ACCESS_DENIED;
6238 command = talloc_asprintf(ctx,
6239 "%s \"%s\" \"%s\"", cmd, portname, uri );
6240 if (!command) {
6241 return WERR_NOMEM;
6244 if ( token )
6245 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6247 DEBUG(10,("Running [%s]\n", command));
6249 /********* BEGIN SePrintOperatorPrivilege **********/
6251 if ( is_print_op )
6252 become_root();
6254 ret = smbrun(command, NULL);
6256 if ( is_print_op )
6257 unbecome_root();
6259 /********* END SePrintOperatorPrivilege **********/
6261 DEBUGADD(10,("returned [%d]\n", ret));
6263 TALLOC_FREE(command);
6265 if ( ret != 0 ) {
6266 return WERR_ACCESS_DENIED;
6269 return WERR_OK;
6272 /****************************************************************************
6273 ****************************************************************************/
6275 static bool spoolss_conn_snum_used(struct smbd_server_connection *sconn,
6276 int snum)
6279 * As we do not know if we are embedded in the file server process
6280 * or not, we have to pretend that all shares are in use.
6282 return true;
6285 static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
6286 struct spoolss_SetPrinterInfo2 *info2,
6287 const char *remote_machine,
6288 struct messaging_context *msg_ctx)
6290 char *cmd = lp_addprinter_command(talloc_tos());
6291 char **qlines;
6292 char *command = NULL;
6293 int numlines;
6294 int ret;
6295 int fd;
6296 bool is_print_op = false;
6298 if (!remote_machine) {
6299 return false;
6302 command = talloc_asprintf(ctx,
6303 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6304 cmd, info2->printername, info2->sharename,
6305 info2->portname, info2->drivername,
6306 info2->location, info2->comment, remote_machine);
6307 if (!command) {
6308 return false;
6311 if ( token )
6312 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6314 DEBUG(10,("Running [%s]\n", command));
6316 /********* BEGIN SePrintOperatorPrivilege **********/
6318 if ( is_print_op )
6319 become_root();
6321 if ( (ret = smbrun(command, &fd)) == 0 ) {
6322 /* Tell everyone we updated smb.conf. */
6323 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6326 if ( is_print_op )
6327 unbecome_root();
6329 /********* END SePrintOperatorPrivilege **********/
6331 DEBUGADD(10,("returned [%d]\n", ret));
6333 TALLOC_FREE(command);
6335 if ( ret != 0 ) {
6336 if (fd != -1)
6337 close(fd);
6338 return false;
6341 /* reload our services immediately */
6342 become_root();
6343 reload_services(NULL, spoolss_conn_snum_used, false);
6344 unbecome_root();
6346 numlines = 0;
6347 /* Get lines and convert them back to dos-codepage */
6348 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6349 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6350 close(fd);
6352 /* Set the portname to what the script says the portname should be. */
6353 /* but don't require anything to be return from the script exit a good error code */
6355 if (numlines) {
6356 /* Set the portname to what the script says the portname should be. */
6357 info2->portname = talloc_strdup(ctx, qlines[0]);
6358 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6361 TALLOC_FREE(qlines);
6362 return true;
6365 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
6366 const struct auth_session_info *session_info,
6367 struct messaging_context *msg_ctx,
6368 int snum,
6369 struct spoolss_SetPrinterInfo2 *printer,
6370 struct spoolss_PrinterInfo2 *old_printer)
6372 bool force_update = (old_printer == NULL);
6373 const char *dnsdomname;
6374 const char *longname;
6375 const char *uncname;
6376 const char *spooling;
6377 DATA_BLOB buffer;
6378 WERROR result = WERR_OK;
6379 struct dcerpc_binding_handle *b;
6380 TALLOC_CTX *tmp_ctx;
6381 bool ok;
6383 tmp_ctx = talloc_new(mem_ctx);
6384 if (!tmp_ctx) {
6385 return WERR_NOMEM;
6388 result = winreg_printer_binding_handle(tmp_ctx,
6389 session_info,
6390 msg_ctx,
6391 &b);
6392 if (!W_ERROR_IS_OK(result)) {
6393 goto done;
6396 if (printer->drivername != NULL &&
6397 (force_update ||
6398 !strequal(printer->drivername, old_printer->drivername))) {
6399 ok = push_reg_sz(tmp_ctx, &buffer, printer->drivername);
6400 if (!ok) {
6401 DEBUG(0, ("%s data corrupted\n", SPOOL_REG_DRIVERNAME));
6402 result = WERR_INVALID_DATA;
6403 goto done;
6405 result = winreg_set_printer_dataex(tmp_ctx, b,
6406 printer->sharename,
6407 SPOOL_DSSPOOLER_KEY,
6408 SPOOL_REG_DRIVERNAME,
6409 REG_SZ,
6410 buffer.data,
6411 buffer.length);
6412 if (!W_ERROR_IS_OK(result)) {
6413 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DRIVERNAME));
6414 goto done;
6417 if (!force_update) {
6418 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6419 printer->drivername));
6421 notify_printer_driver(server_event_context(), msg_ctx,
6422 snum, printer->drivername ?
6423 printer->drivername : "");
6427 if (printer->comment != NULL &&
6428 (force_update ||
6429 !strequal(printer->comment, old_printer->comment))) {
6430 ok = push_reg_sz(tmp_ctx, &buffer, printer->comment);
6431 if (!ok) {
6432 DEBUG(0, ("comment data corrupted\n"));
6433 result = WERR_INVALID_DATA;
6434 goto done;
6436 result = winreg_set_printer_dataex(tmp_ctx, b,
6437 printer->sharename,
6438 SPOOL_DSSPOOLER_KEY,
6439 SPOOL_REG_DESCRIPTION,
6440 REG_SZ,
6441 buffer.data,
6442 buffer.length);
6443 if (!W_ERROR_IS_OK(result)) {
6444 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DESCRIPTION));
6445 goto done;
6448 if (!force_update) {
6449 notify_printer_comment(server_event_context(), msg_ctx,
6450 snum, printer->comment ?
6451 printer->comment : "");
6455 if (printer->sharename != NULL &&
6456 (force_update ||
6457 !strequal(printer->sharename, old_printer->sharename))) {
6458 ok = push_reg_sz(tmp_ctx, &buffer, printer->sharename);
6459 if (!ok) {
6460 DEBUG(0, ("sharename data corrupted\n"));
6461 result = WERR_INVALID_DATA;
6462 goto done;
6464 result = winreg_set_printer_dataex(tmp_ctx, b,
6465 printer->sharename,
6466 SPOOL_DSSPOOLER_KEY,
6467 SPOOL_REG_PRINTSHARENAME,
6468 REG_SZ,
6469 buffer.data,
6470 buffer.length);
6471 if (!W_ERROR_IS_OK(result)) {
6472 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME));
6473 goto done;
6476 if (!force_update) {
6477 notify_printer_sharename(server_event_context(),
6478 msg_ctx,
6479 snum, printer->sharename ?
6480 printer->sharename : "");
6484 if (printer->printername != NULL &&
6485 (force_update ||
6486 !strequal(printer->printername, old_printer->printername))) {
6487 const char *p;
6489 p = strrchr(printer->printername, '\\' );
6490 if (p != NULL) {
6491 p++;
6492 } else {
6493 p = printer->printername;
6496 ok = push_reg_sz(tmp_ctx, &buffer, p);
6497 if (!ok) {
6498 DEBUG(0, ("printername data corrupted\n"));
6499 result = WERR_INVALID_DATA;
6500 goto done;
6502 result = winreg_set_printer_dataex(tmp_ctx, b,
6503 printer->sharename,
6504 SPOOL_DSSPOOLER_KEY,
6505 SPOOL_REG_PRINTERNAME,
6506 REG_SZ,
6507 buffer.data,
6508 buffer.length);
6509 if (!W_ERROR_IS_OK(result)) {
6510 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME));
6511 goto done;
6514 if (!force_update) {
6515 notify_printer_printername(server_event_context(),
6516 msg_ctx, snum, p ? p : "");
6520 if (printer->portname != NULL &&
6521 (force_update ||
6522 !strequal(printer->portname, old_printer->portname))) {
6523 ok = push_reg_sz(tmp_ctx, &buffer, printer->portname);
6524 if (!ok) {
6525 DEBUG(0, ("portname data corrupted\n"));
6526 result = WERR_INVALID_DATA;
6527 goto done;
6529 result = winreg_set_printer_dataex(tmp_ctx, b,
6530 printer->sharename,
6531 SPOOL_DSSPOOLER_KEY,
6532 SPOOL_REG_PORTNAME,
6533 REG_SZ,
6534 buffer.data,
6535 buffer.length);
6536 if (!W_ERROR_IS_OK(result)) {
6537 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PORTNAME));
6538 goto done;
6541 if (!force_update) {
6542 notify_printer_port(server_event_context(),
6543 msg_ctx, snum, printer->portname ?
6544 printer->portname : "");
6548 if (printer->location != NULL &&
6549 (force_update ||
6550 !strequal(printer->location, old_printer->location))) {
6551 ok = push_reg_sz(tmp_ctx, &buffer, printer->location);
6552 if (!ok) {
6553 DEBUG(0, ("location data corrupted\n"));
6554 result = WERR_INVALID_DATA;
6555 goto done;
6557 result = winreg_set_printer_dataex(tmp_ctx, b,
6558 printer->sharename,
6559 SPOOL_DSSPOOLER_KEY,
6560 SPOOL_REG_LOCATION,
6561 REG_SZ,
6562 buffer.data,
6563 buffer.length);
6564 if (!W_ERROR_IS_OK(result)) {
6565 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_LOCATION));
6566 goto done;
6569 if (!force_update) {
6570 notify_printer_location(server_event_context(),
6571 msg_ctx, snum,
6572 printer->location ?
6573 printer->location : "");
6577 if (printer->sepfile != NULL &&
6578 (force_update ||
6579 !strequal(printer->sepfile, old_printer->sepfile))) {
6580 ok = push_reg_sz(tmp_ctx, &buffer, printer->sepfile);
6581 if (!ok) {
6582 DEBUG(0, ("sepfile data corrupted\n"));
6583 result = WERR_INVALID_DATA;
6584 goto done;
6586 result = winreg_set_printer_dataex(tmp_ctx, b,
6587 printer->sharename,
6588 SPOOL_DSSPOOLER_KEY,
6589 SPOOL_REG_PRINTSEPARATORFILE,
6590 REG_SZ,
6591 buffer.data,
6592 buffer.length);
6593 if (!W_ERROR_IS_OK(result)) {
6594 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSEPARATORFILE));
6595 goto done;
6598 if (!force_update) {
6599 notify_printer_sepfile(server_event_context(),
6600 msg_ctx, snum,
6601 printer->sepfile ?
6602 printer->sepfile : "");
6606 if (printer->starttime != 0 &&
6607 (force_update ||
6608 printer->starttime != old_printer->starttime)) {
6609 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6610 SIVAL(buffer.data, 0, printer->starttime);
6611 result = winreg_set_printer_dataex(tmp_ctx, b,
6612 printer->sharename,
6613 SPOOL_DSSPOOLER_KEY,
6614 SPOOL_REG_PRINTSTARTTIME,
6615 REG_DWORD,
6616 buffer.data,
6617 buffer.length);
6618 if (!W_ERROR_IS_OK(result)) {
6619 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSTARTTIME));
6620 goto done;
6624 if (printer->untiltime != 0 &&
6625 (force_update ||
6626 printer->untiltime != old_printer->untiltime)) {
6627 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6628 SIVAL(buffer.data, 0, printer->untiltime);
6629 result = winreg_set_printer_dataex(tmp_ctx, b,
6630 printer->sharename,
6631 SPOOL_DSSPOOLER_KEY,
6632 SPOOL_REG_PRINTENDTIME,
6633 REG_DWORD,
6634 buffer.data,
6635 buffer.length);
6636 if (!W_ERROR_IS_OK(result)) {
6637 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME));
6638 goto done;
6642 if (force_update || printer->priority != old_printer->priority) {
6643 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6644 SIVAL(buffer.data, 0, printer->priority);
6645 result = winreg_set_printer_dataex(tmp_ctx, b,
6646 printer->sharename,
6647 SPOOL_DSSPOOLER_KEY,
6648 SPOOL_REG_PRIORITY,
6649 REG_DWORD,
6650 buffer.data,
6651 buffer.length);
6652 if (!W_ERROR_IS_OK(result)) {
6653 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME));
6654 goto done;
6658 if (force_update || printer->attributes != old_printer->attributes) {
6659 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6660 SIVAL(buffer.data, 0, (printer->attributes &
6661 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
6662 result = winreg_set_printer_dataex(tmp_ctx, b,
6663 printer->sharename,
6664 SPOOL_DSSPOOLER_KEY,
6665 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
6666 REG_DWORD,
6667 buffer.data,
6668 buffer.length);
6669 if (!W_ERROR_IS_OK(result)) {
6670 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME));
6671 goto done;
6674 switch (printer->attributes & 0x3) {
6675 case 0:
6676 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
6677 break;
6678 case 1:
6679 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
6680 break;
6681 case 2:
6682 spooling = SPOOL_REGVAL_PRINTDIRECT;
6683 break;
6684 default:
6685 spooling = "unknown";
6687 ok = push_reg_sz(tmp_ctx, &buffer, spooling);
6688 if (!ok) {
6689 DEBUG(0, ("printSpooling data corrupted\n"));
6690 result = WERR_INVALID_DATA;
6691 goto done;
6693 winreg_set_printer_dataex(tmp_ctx, b,
6694 printer->sharename,
6695 SPOOL_DSSPOOLER_KEY,
6696 SPOOL_REG_PRINTSPOOLING,
6697 REG_SZ,
6698 buffer.data,
6699 buffer.length);
6702 ok = push_reg_sz(tmp_ctx, &buffer, lp_netbios_name());
6703 if (!ok) {
6704 DEBUG(0, ("shortServerName data corrupted\n"));
6705 result = WERR_INVALID_DATA;
6706 goto done;
6708 result = winreg_set_printer_dataex(tmp_ctx, b,
6709 printer->sharename,
6710 SPOOL_DSSPOOLER_KEY,
6711 SPOOL_REG_SHORTSERVERNAME,
6712 REG_SZ,
6713 buffer.data,
6714 buffer.length);
6715 if (!W_ERROR_IS_OK(result)) {
6716 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SHORTSERVERNAME));
6717 goto done;
6720 dnsdomname = get_mydnsfullname();
6721 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
6722 longname = talloc_strdup(tmp_ctx, dnsdomname);
6723 } else {
6724 longname = talloc_strdup(tmp_ctx, lp_netbios_name());
6726 if (longname == NULL) {
6727 result = WERR_NOMEM;
6728 goto done;
6731 ok = push_reg_sz(tmp_ctx, &buffer, longname);
6732 if (!ok) {
6733 DEBUG(0, ("longname data corrupted\n"));
6734 result = WERR_INVALID_DATA;
6735 goto done;
6737 result = winreg_set_printer_dataex(tmp_ctx, b,
6738 printer->sharename,
6739 SPOOL_DSSPOOLER_KEY,
6740 SPOOL_REG_SERVERNAME,
6741 REG_SZ,
6742 buffer.data,
6743 buffer.length);
6744 if (!W_ERROR_IS_OK(result)) {
6745 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SERVERNAME));
6746 goto done;
6749 uncname = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
6750 lp_netbios_name(), printer->sharename);
6751 ok = push_reg_sz(tmp_ctx, &buffer, uncname);
6752 if (!ok) {
6753 DEBUG(0, ("uncName data corrupted\n"));
6754 result = WERR_INVALID_DATA;
6755 goto done;
6757 result = winreg_set_printer_dataex(tmp_ctx, b,
6758 printer->sharename,
6759 SPOOL_DSSPOOLER_KEY,
6760 SPOOL_REG_UNCNAME,
6761 REG_SZ,
6762 buffer.data,
6763 buffer.length);
6764 if (!W_ERROR_IS_OK(result)) {
6765 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_UNCNAME));
6766 goto done;
6769 done:
6770 talloc_free(tmp_ctx);
6771 return result;
6774 /********************************************************************
6775 * Called by spoolss_api_setprinter
6776 * when updating a printer description.
6777 ********************************************************************/
6779 static WERROR update_printer(struct pipes_struct *p,
6780 struct policy_handle *handle,
6781 struct spoolss_SetPrinterInfoCtr *info_ctr,
6782 struct spoolss_DeviceMode *devmode)
6784 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6785 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6786 struct spoolss_PrinterInfo2 *old_printer;
6787 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6788 int snum;
6789 WERROR result = WERR_OK;
6790 TALLOC_CTX *tmp_ctx;
6791 struct dcerpc_binding_handle *b;
6793 DEBUG(8,("update_printer\n"));
6795 tmp_ctx = talloc_new(p->mem_ctx);
6796 if (tmp_ctx == NULL) {
6797 return WERR_NOMEM;
6800 if (!Printer) {
6801 result = WERR_BADFID;
6802 goto done;
6805 if (!get_printer_snum(p, handle, &snum, NULL)) {
6806 result = WERR_BADFID;
6807 goto done;
6810 result = winreg_printer_binding_handle(tmp_ctx,
6811 get_session_info_system(),
6812 p->msg_ctx,
6813 &b);
6814 if (!W_ERROR_IS_OK(result)) {
6815 goto done;
6818 result = winreg_get_printer(tmp_ctx, b,
6819 lp_const_servicename(snum),
6820 &old_printer);
6821 if (!W_ERROR_IS_OK(result)) {
6822 result = WERR_BADFID;
6823 goto done;
6826 /* Do sanity check on the requested changes for Samba */
6827 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6828 result = WERR_INVALID_PARAM;
6829 goto done;
6832 /* FIXME!!! If the driver has changed we really should verify that
6833 it is installed before doing much else --jerry */
6835 /* Check calling user has permission to update printer description */
6836 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6837 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6838 result = WERR_ACCESS_DENIED;
6839 goto done;
6842 /* Call addprinter hook */
6843 /* Check changes to see if this is really needed */
6845 if (*lp_addprinter_command(talloc_tos()) &&
6846 (!strequal(printer->drivername, old_printer->drivername) ||
6847 !strequal(printer->comment, old_printer->comment) ||
6848 !strequal(printer->portname, old_printer->portname) ||
6849 !strequal(printer->location, old_printer->location)) )
6851 char *raddr;
6853 raddr = tsocket_address_inet_addr_string(p->remote_address,
6854 p->mem_ctx);
6855 if (raddr == NULL) {
6856 return WERR_NOMEM;
6859 /* add_printer_hook() will call reload_services() */
6860 if (!add_printer_hook(tmp_ctx, p->session_info->security_token,
6861 printer, raddr,
6862 p->msg_ctx)) {
6863 result = WERR_ACCESS_DENIED;
6864 goto done;
6868 result = update_dsspooler(tmp_ctx,
6869 get_session_info_system(),
6870 p->msg_ctx,
6871 snum,
6872 printer,
6873 old_printer);
6874 if (!W_ERROR_IS_OK(result)) {
6875 goto done;
6878 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6880 if (devmode == NULL) {
6881 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6883 result = winreg_update_printer(tmp_ctx, b,
6884 printer->sharename,
6885 printer_mask,
6886 printer,
6887 devmode,
6888 NULL);
6890 done:
6891 talloc_free(tmp_ctx);
6893 return result;
6896 /****************************************************************************
6897 ****************************************************************************/
6898 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6899 struct policy_handle *handle,
6900 struct spoolss_SetPrinterInfo7 *info7)
6902 #ifdef HAVE_ADS
6903 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6904 WERROR result;
6905 int snum;
6906 struct printer_handle *Printer;
6908 if ( lp_security() != SEC_ADS ) {
6909 return WERR_UNKNOWN_LEVEL;
6912 Printer = find_printer_index_by_hnd(p, handle);
6914 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6916 if (!Printer)
6917 return WERR_BADFID;
6919 if (!get_printer_snum(p, handle, &snum, NULL))
6920 return WERR_BADFID;
6922 result = winreg_get_printer_internal(p->mem_ctx,
6923 get_session_info_system(),
6924 p->msg_ctx,
6925 lp_servicename(talloc_tos(), snum),
6926 &pinfo2);
6927 if (!W_ERROR_IS_OK(result)) {
6928 return WERR_BADFID;
6931 nt_printer_publish(pinfo2,
6932 get_session_info_system(),
6933 p->msg_ctx,
6934 pinfo2,
6935 info7->action);
6937 TALLOC_FREE(pinfo2);
6938 return WERR_OK;
6939 #else
6940 return WERR_UNKNOWN_LEVEL;
6941 #endif
6944 /********************************************************************
6945 ********************************************************************/
6947 static WERROR update_printer_devmode(struct pipes_struct *p,
6948 struct policy_handle *handle,
6949 struct spoolss_DeviceMode *devmode)
6951 int snum;
6952 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6953 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6955 DEBUG(8,("update_printer_devmode\n"));
6957 if (!Printer) {
6958 return WERR_BADFID;
6961 if (!get_printer_snum(p, handle, &snum, NULL)) {
6962 return WERR_BADFID;
6965 /* Check calling user has permission to update printer description */
6966 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6967 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6968 return WERR_ACCESS_DENIED;
6971 return winreg_update_printer_internal(p->mem_ctx,
6972 get_session_info_system(),
6973 p->msg_ctx,
6974 lp_const_servicename(snum),
6975 info2_mask,
6976 NULL,
6977 devmode,
6978 NULL);
6982 /****************************************************************
6983 _spoolss_SetPrinter
6984 ****************************************************************/
6986 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6987 struct spoolss_SetPrinter *r)
6989 WERROR result;
6991 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6993 if (!Printer) {
6994 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6995 OUR_HANDLE(r->in.handle)));
6996 return WERR_BADFID;
6999 /* check the level */
7000 switch (r->in.info_ctr->level) {
7001 case 0:
7002 return control_printer(r->in.handle, r->in.command, p);
7003 case 2:
7004 result = update_printer(p, r->in.handle,
7005 r->in.info_ctr,
7006 r->in.devmode_ctr->devmode);
7007 if (!W_ERROR_IS_OK(result))
7008 return result;
7009 if (r->in.secdesc_ctr->sd)
7010 result = update_printer_sec(r->in.handle, p,
7011 r->in.secdesc_ctr);
7012 return result;
7013 case 3:
7014 return update_printer_sec(r->in.handle, p,
7015 r->in.secdesc_ctr);
7016 case 7:
7017 return publish_or_unpublish_printer(p, r->in.handle,
7018 r->in.info_ctr->info.info7);
7019 case 8:
7020 return update_printer_devmode(p, r->in.handle,
7021 r->in.devmode_ctr->devmode);
7022 default:
7023 return WERR_UNKNOWN_LEVEL;
7027 /****************************************************************
7028 _spoolss_FindClosePrinterNotify
7029 ****************************************************************/
7031 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
7032 struct spoolss_FindClosePrinterNotify *r)
7034 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
7036 if (!Printer) {
7037 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
7038 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
7039 return WERR_BADFID;
7042 if (Printer->notify.cli_chan != NULL &&
7043 Printer->notify.cli_chan->active_connections > 0) {
7044 int snum = -1;
7046 if (Printer->printer_type == SPLHND_PRINTER) {
7047 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7048 return WERR_BADFID;
7052 srv_spoolss_replycloseprinter(snum, Printer);
7055 Printer->notify.flags=0;
7056 Printer->notify.options=0;
7057 Printer->notify.localmachine[0]='\0';
7058 Printer->notify.printerlocal=0;
7059 TALLOC_FREE(Printer->notify.option);
7061 return WERR_OK;
7064 /****************************************************************
7065 _spoolss_AddJob
7066 ****************************************************************/
7068 WERROR _spoolss_AddJob(struct pipes_struct *p,
7069 struct spoolss_AddJob *r)
7071 if (!r->in.buffer && (r->in.offered != 0)) {
7072 return WERR_INVALID_PARAM;
7075 /* this is what a NT server returns for AddJob. AddJob must fail on
7076 * non-local printers */
7078 if (r->in.level != 1) {
7079 return WERR_UNKNOWN_LEVEL;
7082 return WERR_INVALID_PARAM;
7085 /****************************************************************************
7086 fill_job_info1
7087 ****************************************************************************/
7089 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
7090 struct spoolss_JobInfo1 *r,
7091 const print_queue_struct *queue,
7092 uint32_t jobid,
7093 int position, int snum,
7094 struct spoolss_PrinterInfo2 *pinfo2)
7096 struct tm *t;
7098 t = gmtime(&queue->time);
7100 r->job_id = jobid;
7102 r->printer_name = lp_servicename(mem_ctx, snum);
7103 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
7104 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
7105 W_ERROR_HAVE_NO_MEMORY(r->server_name);
7106 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
7107 W_ERROR_HAVE_NO_MEMORY(r->user_name);
7108 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
7109 W_ERROR_HAVE_NO_MEMORY(r->document_name);
7110 r->data_type = talloc_strdup(mem_ctx, "RAW");
7111 W_ERROR_HAVE_NO_MEMORY(r->data_type);
7112 r->text_status = talloc_strdup(mem_ctx, "");
7113 W_ERROR_HAVE_NO_MEMORY(r->text_status);
7115 r->status = nt_printj_status(queue->status);
7116 r->priority = queue->priority;
7117 r->position = position;
7118 r->total_pages = queue->page_count;
7119 r->pages_printed = 0; /* ??? */
7121 init_systemtime(&r->submitted, t);
7123 return WERR_OK;
7126 /****************************************************************************
7127 fill_job_info2
7128 ****************************************************************************/
7130 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
7131 struct spoolss_JobInfo2 *r,
7132 const print_queue_struct *queue,
7133 uint32_t jobid,
7134 int position, int snum,
7135 struct spoolss_PrinterInfo2 *pinfo2,
7136 struct spoolss_DeviceMode *devmode)
7138 struct tm *t;
7140 t = gmtime(&queue->time);
7142 r->job_id = jobid;
7144 r->printer_name = lp_servicename(mem_ctx, snum);
7145 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
7146 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
7147 W_ERROR_HAVE_NO_MEMORY(r->server_name);
7148 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
7149 W_ERROR_HAVE_NO_MEMORY(r->user_name);
7150 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
7151 W_ERROR_HAVE_NO_MEMORY(r->document_name);
7152 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
7153 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
7154 r->data_type = talloc_strdup(mem_ctx, "RAW");
7155 W_ERROR_HAVE_NO_MEMORY(r->data_type);
7156 r->print_processor = talloc_strdup(mem_ctx, "winprint");
7157 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
7158 r->parameters = talloc_strdup(mem_ctx, "");
7159 W_ERROR_HAVE_NO_MEMORY(r->parameters);
7160 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
7161 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
7163 r->devmode = devmode;
7165 r->text_status = talloc_strdup(mem_ctx, "");
7166 W_ERROR_HAVE_NO_MEMORY(r->text_status);
7168 r->secdesc = NULL;
7170 r->status = nt_printj_status(queue->status);
7171 r->priority = queue->priority;
7172 r->position = position;
7173 r->start_time = 0;
7174 r->until_time = 0;
7175 r->total_pages = queue->page_count;
7176 r->size = queue->size;
7177 init_systemtime(&r->submitted, t);
7178 r->time = 0;
7179 r->pages_printed = 0; /* ??? */
7181 return WERR_OK;
7184 /****************************************************************************
7185 Enumjobs at level 1.
7186 ****************************************************************************/
7188 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
7189 const print_queue_struct *queue,
7190 uint32_t num_queues, int snum,
7191 struct spoolss_PrinterInfo2 *pinfo2,
7192 union spoolss_JobInfo **info_p,
7193 uint32_t *count)
7195 union spoolss_JobInfo *info;
7196 int i;
7197 WERROR result = WERR_OK;
7198 uint32_t num_filled;
7199 struct tdb_print_db *pdb;
7201 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7202 if (info == NULL) {
7203 result = WERR_NOMEM;
7204 goto err_out;
7207 pdb = get_print_db_byname(pinfo2->sharename);
7208 if (pdb == NULL) {
7209 result = WERR_INVALID_PARAM;
7210 goto err_info_free;
7213 num_filled = 0;
7214 for (i = 0; i < num_queues; i++) {
7215 uint32_t jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
7216 if (jobid == (uint32_t)-1) {
7217 DEBUG(4, ("skipping sysjob %d\n", queue[i].sysjob));
7218 continue;
7221 result = fill_job_info1(info,
7222 &info[num_filled].info1,
7223 &queue[i],
7224 jobid,
7226 snum,
7227 pinfo2);
7228 if (!W_ERROR_IS_OK(result)) {
7229 goto err_pdb_drop;
7232 num_filled++;
7235 release_print_db(pdb);
7236 *info_p = info;
7237 *count = num_filled;
7239 return WERR_OK;
7241 err_pdb_drop:
7242 release_print_db(pdb);
7243 err_info_free:
7244 TALLOC_FREE(info);
7245 err_out:
7246 *count = 0;
7247 return result;
7250 /****************************************************************************
7251 Enumjobs at level 2.
7252 ****************************************************************************/
7254 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
7255 const print_queue_struct *queue,
7256 uint32_t num_queues, int snum,
7257 struct spoolss_PrinterInfo2 *pinfo2,
7258 union spoolss_JobInfo **info_p,
7259 uint32_t *count)
7261 union spoolss_JobInfo *info;
7262 int i;
7263 WERROR result = WERR_OK;
7264 uint32_t num_filled;
7265 struct tdb_print_db *pdb;
7267 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7268 if (info == NULL) {
7269 result = WERR_NOMEM;
7270 goto err_out;
7273 pdb = get_print_db_byname(pinfo2->sharename);
7274 if (pdb == NULL) {
7275 result = WERR_INVALID_PARAM;
7276 goto err_info_free;
7279 num_filled = 0;
7280 for (i = 0; i< num_queues; i++) {
7281 struct spoolss_DeviceMode *devmode;
7282 uint32_t jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
7283 if (jobid == (uint32_t)-1) {
7284 DEBUG(4, ("skipping sysjob %d\n", queue[i].sysjob));
7285 continue;
7288 result = spoolss_create_default_devmode(info,
7289 pinfo2->printername,
7290 &devmode);
7291 if (!W_ERROR_IS_OK(result)) {
7292 DEBUG(3, ("Can't proceed w/o a devmode!"));
7293 goto err_pdb_drop;
7296 result = fill_job_info2(info,
7297 &info[num_filled].info2,
7298 &queue[i],
7299 jobid,
7301 snum,
7302 pinfo2,
7303 devmode);
7304 if (!W_ERROR_IS_OK(result)) {
7305 goto err_pdb_drop;
7307 num_filled++;
7310 release_print_db(pdb);
7311 *info_p = info;
7312 *count = num_filled;
7314 return WERR_OK;
7316 err_pdb_drop:
7317 release_print_db(pdb);
7318 err_info_free:
7319 TALLOC_FREE(info);
7320 err_out:
7321 *count = 0;
7322 return result;
7325 /****************************************************************************
7326 Enumjobs at level 3.
7327 ****************************************************************************/
7329 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
7330 const print_queue_struct *queue,
7331 uint32_t num_queues, int snum,
7332 struct spoolss_PrinterInfo2 *pinfo2,
7333 union spoolss_JobInfo **info_p,
7334 uint32_t *count)
7336 union spoolss_JobInfo *info;
7337 int i;
7338 WERROR result = WERR_OK;
7339 uint32_t num_filled;
7340 struct tdb_print_db *pdb;
7342 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7343 if (info == NULL) {
7344 result = WERR_NOMEM;
7345 goto err_out;
7348 pdb = get_print_db_byname(pinfo2->sharename);
7349 if (pdb == NULL) {
7350 result = WERR_INVALID_PARAM;
7351 goto err_info_free;
7354 num_filled = 0;
7355 for (i = 0; i < num_queues; i++) {
7356 uint32_t jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
7357 if (jobid == (uint32_t)-1) {
7358 DEBUG(4, ("skipping sysjob %d\n", queue[i].sysjob));
7359 continue;
7362 info[num_filled].info3.job_id = jobid;
7363 /* next_job_id is overwritten on next iteration */
7364 info[num_filled].info3.next_job_id = 0;
7365 info[num_filled].info3.reserved = 0;
7367 if (num_filled > 0) {
7368 info[num_filled - 1].info3.next_job_id = jobid;
7370 num_filled++;
7373 release_print_db(pdb);
7374 *info_p = info;
7375 *count = num_filled;
7377 return WERR_OK;
7379 err_info_free:
7380 TALLOC_FREE(info);
7381 err_out:
7382 *count = 0;
7383 return result;
7386 /****************************************************************
7387 _spoolss_EnumJobs
7388 ****************************************************************/
7390 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
7391 struct spoolss_EnumJobs *r)
7393 WERROR result;
7394 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
7395 int snum;
7396 print_status_struct prt_status;
7397 print_queue_struct *queue = NULL;
7398 uint32_t count;
7400 /* that's an [in out] buffer */
7402 if (!r->in.buffer && (r->in.offered != 0)) {
7403 return WERR_INVALID_PARAM;
7406 if ((r->in.level != 1) && (r->in.level != 2) && (r->in.level != 3)) {
7407 DEBUG(4, ("EnumJobs level %d not supported\n", r->in.level));
7408 return WERR_UNKNOWN_LEVEL;
7411 DEBUG(4,("_spoolss_EnumJobs\n"));
7413 *r->out.needed = 0;
7414 *r->out.count = 0;
7415 *r->out.info = NULL;
7417 /* lookup the printer snum and tdb entry */
7419 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7420 return WERR_BADFID;
7423 result = winreg_get_printer_internal(p->mem_ctx,
7424 get_session_info_system(),
7425 p->msg_ctx,
7426 lp_const_servicename(snum),
7427 &pinfo2);
7428 if (!W_ERROR_IS_OK(result)) {
7429 return result;
7432 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
7433 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7434 count, prt_status.status, prt_status.message));
7436 if (count == 0) {
7437 SAFE_FREE(queue);
7438 TALLOC_FREE(pinfo2);
7439 return WERR_OK;
7442 switch (r->in.level) {
7443 case 1:
7444 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
7445 pinfo2, r->out.info, r->out.count);
7446 break;
7447 case 2:
7448 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
7449 pinfo2, r->out.info, r->out.count);
7450 break;
7451 case 3:
7452 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
7453 pinfo2, r->out.info, r->out.count);
7454 break;
7455 default:
7456 SMB_ASSERT(false); /* level checked on entry */
7457 break;
7460 SAFE_FREE(queue);
7461 TALLOC_FREE(pinfo2);
7463 if (!W_ERROR_IS_OK(result)) {
7464 return result;
7467 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7468 spoolss_EnumJobs,
7469 *r->out.info, r->in.level,
7470 *r->out.count);
7471 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7472 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7474 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7477 /****************************************************************
7478 _spoolss_ScheduleJob
7479 ****************************************************************/
7481 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
7482 struct spoolss_ScheduleJob *r)
7484 return WERR_OK;
7487 /****************************************************************
7488 ****************************************************************/
7490 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
7491 struct messaging_context *msg_ctx,
7492 const char *printer_name,
7493 uint32_t job_id,
7494 struct spoolss_SetJobInfo1 *r)
7496 char *old_doc_name;
7498 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
7499 return WERR_BADFID;
7502 if (strequal(old_doc_name, r->document_name)) {
7503 return WERR_OK;
7506 if (!print_job_set_name(server_event_context(), msg_ctx,
7507 printer_name, job_id, r->document_name)) {
7508 return WERR_BADFID;
7511 return WERR_OK;
7514 /****************************************************************
7515 _spoolss_SetJob
7516 ****************************************************************/
7518 WERROR _spoolss_SetJob(struct pipes_struct *p,
7519 struct spoolss_SetJob *r)
7521 const struct auth_session_info *session_info = p->session_info;
7522 int snum;
7523 WERROR errcode = WERR_BADFUNC;
7525 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7526 return WERR_BADFID;
7529 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
7530 return WERR_INVALID_PRINTER_NAME;
7533 switch (r->in.command) {
7534 case SPOOLSS_JOB_CONTROL_CANCEL:
7535 case SPOOLSS_JOB_CONTROL_DELETE:
7536 errcode = print_job_delete(session_info, p->msg_ctx,
7537 snum, r->in.job_id);
7538 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
7539 errcode = WERR_OK;
7541 break;
7542 case SPOOLSS_JOB_CONTROL_PAUSE:
7543 errcode = print_job_pause(session_info, p->msg_ctx,
7544 snum, r->in.job_id);
7545 break;
7546 case SPOOLSS_JOB_CONTROL_RESTART:
7547 case SPOOLSS_JOB_CONTROL_RESUME:
7548 errcode = print_job_resume(session_info, p->msg_ctx,
7549 snum, r->in.job_id);
7550 break;
7551 case SPOOLSS_JOB_CONTROL_NOOP:
7552 errcode = WERR_OK;
7553 break;
7554 default:
7555 return WERR_UNKNOWN_LEVEL;
7558 if (!W_ERROR_IS_OK(errcode)) {
7559 return errcode;
7562 if (r->in.ctr == NULL) {
7563 return errcode;
7566 switch (r->in.ctr->level) {
7567 case 1:
7568 errcode = spoolss_setjob_1(p->mem_ctx, p->msg_ctx,
7569 lp_const_servicename(snum),
7570 r->in.job_id,
7571 r->in.ctr->info.info1);
7572 break;
7573 case 2:
7574 case 3:
7575 case 4:
7576 default:
7577 return WERR_UNKNOWN_LEVEL;
7580 return errcode;
7583 /****************************************************************************
7584 Enumerates all printer drivers by level and architecture.
7585 ****************************************************************************/
7587 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
7588 const struct auth_session_info *session_info,
7589 struct messaging_context *msg_ctx,
7590 const char *servername,
7591 const char *architecture,
7592 uint32_t level,
7593 union spoolss_DriverInfo **info_p,
7594 uint32_t *count_p)
7596 int i;
7597 uint32_t version;
7598 struct spoolss_DriverInfo8 *driver;
7599 union spoolss_DriverInfo *info = NULL;
7600 uint32_t count = 0;
7601 WERROR result = WERR_OK;
7602 uint32_t num_drivers;
7603 const char **drivers;
7604 struct dcerpc_binding_handle *b;
7605 TALLOC_CTX *tmp_ctx = NULL;
7607 *count_p = 0;
7608 *info_p = NULL;
7610 tmp_ctx = talloc_new(mem_ctx);
7611 if (!tmp_ctx) {
7612 return WERR_NOMEM;
7615 result = winreg_printer_binding_handle(tmp_ctx,
7616 session_info,
7617 msg_ctx,
7618 &b);
7619 if (!W_ERROR_IS_OK(result)) {
7620 goto out;
7623 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7624 result = winreg_get_driver_list(tmp_ctx, b,
7625 architecture, version,
7626 &num_drivers, &drivers);
7627 if (!W_ERROR_IS_OK(result)) {
7628 goto out;
7630 DEBUG(4, ("we have:[%d] drivers in environment"
7631 " [%s] and version [%d]\n",
7632 num_drivers, architecture, version));
7634 if (num_drivers != 0) {
7635 info = talloc_realloc(tmp_ctx, info,
7636 union spoolss_DriverInfo,
7637 count + num_drivers);
7638 if (!info) {
7639 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7640 "failed to enlarge driver info buffer!\n"));
7641 result = WERR_NOMEM;
7642 goto out;
7646 for (i = 0; i < num_drivers; i++) {
7647 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
7649 result = winreg_get_driver(tmp_ctx, b,
7650 architecture, drivers[i],
7651 version, &driver);
7652 if (!W_ERROR_IS_OK(result)) {
7653 goto out;
7656 switch (level) {
7657 case 1:
7658 result = fill_printer_driver_info1(info, &info[count+i].info1,
7659 driver, servername);
7660 break;
7661 case 2:
7662 result = fill_printer_driver_info2(info, &info[count+i].info2,
7663 driver, servername);
7664 break;
7665 case 3:
7666 result = fill_printer_driver_info3(info, &info[count+i].info3,
7667 driver, servername);
7668 break;
7669 case 4:
7670 result = fill_printer_driver_info4(info, &info[count+i].info4,
7671 driver, servername);
7672 break;
7673 case 5:
7674 result = fill_printer_driver_info5(info, &info[count+i].info5,
7675 driver, servername);
7676 break;
7677 case 6:
7678 result = fill_printer_driver_info6(info, &info[count+i].info6,
7679 driver, servername);
7680 break;
7681 case 8:
7682 result = fill_printer_driver_info8(info, &info[count+i].info8,
7683 driver, servername);
7684 break;
7685 default:
7686 result = WERR_UNKNOWN_LEVEL;
7687 break;
7690 TALLOC_FREE(driver);
7692 if (!W_ERROR_IS_OK(result)) {
7693 goto out;
7697 count += num_drivers;
7698 TALLOC_FREE(drivers);
7701 out:
7702 if (W_ERROR_IS_OK(result)) {
7703 *info_p = talloc_move(mem_ctx, &info);
7704 *count_p = count;
7707 talloc_free(tmp_ctx);
7708 return result;
7711 /****************************************************************************
7712 Enumerates all printer drivers by level.
7713 ****************************************************************************/
7715 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
7716 const struct auth_session_info *session_info,
7717 struct messaging_context *msg_ctx,
7718 const char *servername,
7719 const char *architecture,
7720 uint32_t level,
7721 union spoolss_DriverInfo **info_p,
7722 uint32_t *count_p)
7724 uint32_t a,i;
7725 WERROR result = WERR_OK;
7727 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
7729 for (a=0; archi_table[a].long_archi != NULL; a++) {
7731 union spoolss_DriverInfo *info = NULL;
7732 uint32_t count = 0;
7734 result = enumprinterdrivers_level_by_architecture(mem_ctx,
7735 session_info,
7736 msg_ctx,
7737 servername,
7738 archi_table[a].long_archi,
7739 level,
7740 &info,
7741 &count);
7742 if (!W_ERROR_IS_OK(result)) {
7743 continue;
7746 for (i=0; i < count; i++) {
7747 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
7748 info[i], info_p, count_p);
7752 return result;
7755 return enumprinterdrivers_level_by_architecture(mem_ctx,
7756 session_info,
7757 msg_ctx,
7758 servername,
7759 architecture,
7760 level,
7761 info_p,
7762 count_p);
7765 /****************************************************************
7766 _spoolss_EnumPrinterDrivers
7767 ****************************************************************/
7769 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
7770 struct spoolss_EnumPrinterDrivers *r)
7772 const char *cservername;
7773 WERROR result;
7775 /* that's an [in out] buffer */
7777 if (!r->in.buffer && (r->in.offered != 0)) {
7778 return WERR_INVALID_PARAM;
7781 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7783 *r->out.needed = 0;
7784 *r->out.count = 0;
7785 *r->out.info = NULL;
7787 cservername = canon_servername(r->in.server);
7789 if (!is_myname_or_ipaddr(cservername)) {
7790 return WERR_UNKNOWN_PRINTER_DRIVER;
7793 result = enumprinterdrivers_level(p->mem_ctx,
7794 get_session_info_system(),
7795 p->msg_ctx,
7796 cservername,
7797 r->in.environment,
7798 r->in.level,
7799 r->out.info,
7800 r->out.count);
7801 if (!W_ERROR_IS_OK(result)) {
7802 return result;
7805 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7806 spoolss_EnumPrinterDrivers,
7807 *r->out.info, r->in.level,
7808 *r->out.count);
7809 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7810 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7812 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7815 /****************************************************************
7816 _spoolss_EnumForms
7817 ****************************************************************/
7819 WERROR _spoolss_EnumForms(struct pipes_struct *p,
7820 struct spoolss_EnumForms *r)
7822 WERROR result;
7824 *r->out.count = 0;
7825 *r->out.needed = 0;
7826 *r->out.info = NULL;
7828 /* that's an [in out] buffer */
7830 if (!r->in.buffer && (r->in.offered != 0) ) {
7831 return WERR_INVALID_PARAM;
7834 DEBUG(4,("_spoolss_EnumForms\n"));
7835 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7836 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7838 switch (r->in.level) {
7839 case 1:
7840 result = winreg_printer_enumforms1_internal(p->mem_ctx,
7841 get_session_info_system(),
7842 p->msg_ctx,
7843 r->out.count,
7844 r->out.info);
7845 break;
7846 default:
7847 result = WERR_UNKNOWN_LEVEL;
7848 break;
7851 if (!W_ERROR_IS_OK(result)) {
7852 return result;
7855 if (*r->out.count == 0) {
7856 return WERR_NO_MORE_ITEMS;
7859 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7860 spoolss_EnumForms,
7861 *r->out.info, r->in.level,
7862 *r->out.count);
7863 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7864 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7866 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7869 /****************************************************************
7870 _spoolss_GetForm
7871 ****************************************************************/
7873 WERROR _spoolss_GetForm(struct pipes_struct *p,
7874 struct spoolss_GetForm *r)
7876 WERROR result;
7878 /* that's an [in out] buffer */
7880 if (!r->in.buffer && (r->in.offered != 0)) {
7881 TALLOC_FREE(r->out.info);
7882 return WERR_INVALID_PARAM;
7885 DEBUG(4,("_spoolss_GetForm\n"));
7886 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7887 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7889 switch (r->in.level) {
7890 case 1:
7891 result = winreg_printer_getform1_internal(p->mem_ctx,
7892 get_session_info_system(),
7893 p->msg_ctx,
7894 r->in.form_name,
7895 &r->out.info->info1);
7896 break;
7897 default:
7898 result = WERR_UNKNOWN_LEVEL;
7899 break;
7902 if (!W_ERROR_IS_OK(result)) {
7903 TALLOC_FREE(r->out.info);
7904 return result;
7907 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7908 r->out.info, r->in.level);
7909 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7911 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7914 /****************************************************************************
7915 ****************************************************************************/
7917 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7918 struct spoolss_PortInfo1 *r,
7919 const char *name)
7921 r->port_name = talloc_strdup(mem_ctx, name);
7922 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7924 return WERR_OK;
7927 /****************************************************************************
7928 TODO: This probably needs distinguish between TCP/IP and Local ports
7929 somehow.
7930 ****************************************************************************/
7932 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7933 struct spoolss_PortInfo2 *r,
7934 const char *name)
7936 r->port_name = talloc_strdup(mem_ctx, name);
7937 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7939 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7940 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7942 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7943 W_ERROR_HAVE_NO_MEMORY(r->description);
7945 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7946 r->reserved = 0;
7948 return WERR_OK;
7952 /****************************************************************************
7953 wrapper around the enumer ports command
7954 ****************************************************************************/
7956 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7958 char *cmd = lp_enumports_command(talloc_tos());
7959 char **qlines = NULL;
7960 char *command = NULL;
7961 int numlines;
7962 int ret;
7963 int fd;
7965 *count = 0;
7966 *lines = NULL;
7968 /* if no hook then just fill in the default port */
7970 if ( !*cmd ) {
7971 if (!(qlines = talloc_array( NULL, char*, 2 ))) {
7972 return WERR_NOMEM;
7974 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7975 TALLOC_FREE(qlines);
7976 return WERR_NOMEM;
7978 qlines[1] = NULL;
7979 numlines = 1;
7981 else {
7982 /* we have a valid enumport command */
7984 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7985 if (!command) {
7986 return WERR_NOMEM;
7989 DEBUG(10,("Running [%s]\n", command));
7990 ret = smbrun(command, &fd);
7991 DEBUG(10,("Returned [%d]\n", ret));
7992 TALLOC_FREE(command);
7993 if (ret != 0) {
7994 if (fd != -1) {
7995 close(fd);
7997 return WERR_ACCESS_DENIED;
8000 numlines = 0;
8001 qlines = fd_lines_load(fd, &numlines, 0, NULL);
8002 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
8003 close(fd);
8006 *count = numlines;
8007 *lines = qlines;
8009 return WERR_OK;
8012 /****************************************************************************
8013 enumports level 1.
8014 ****************************************************************************/
8016 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
8017 union spoolss_PortInfo **info_p,
8018 uint32_t *count)
8020 union spoolss_PortInfo *info = NULL;
8021 int i=0;
8022 WERROR result = WERR_OK;
8023 char **qlines = NULL;
8024 int numlines = 0;
8026 result = enumports_hook(talloc_tos(), &numlines, &qlines );
8027 if (!W_ERROR_IS_OK(result)) {
8028 goto out;
8031 if (numlines) {
8032 info = talloc_array(mem_ctx, union spoolss_PortInfo, numlines);
8033 if (!info) {
8034 DEBUG(10,("Returning WERR_NOMEM\n"));
8035 result = WERR_NOMEM;
8036 goto out;
8039 for (i=0; i<numlines; i++) {
8040 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
8041 result = fill_port_1(info, &info[i].info1, qlines[i]);
8042 if (!W_ERROR_IS_OK(result)) {
8043 goto out;
8047 TALLOC_FREE(qlines);
8049 out:
8050 if (!W_ERROR_IS_OK(result)) {
8051 TALLOC_FREE(info);
8052 TALLOC_FREE(qlines);
8053 *count = 0;
8054 *info_p = NULL;
8055 return result;
8058 *info_p = info;
8059 *count = numlines;
8061 return WERR_OK;
8064 /****************************************************************************
8065 enumports level 2.
8066 ****************************************************************************/
8068 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
8069 union spoolss_PortInfo **info_p,
8070 uint32_t *count)
8072 union spoolss_PortInfo *info = NULL;
8073 int i=0;
8074 WERROR result = WERR_OK;
8075 char **qlines = NULL;
8076 int numlines = 0;
8078 result = enumports_hook(talloc_tos(), &numlines, &qlines );
8079 if (!W_ERROR_IS_OK(result)) {
8080 goto out;
8083 if (numlines) {
8084 info = talloc_array(mem_ctx, union spoolss_PortInfo, numlines);
8085 if (!info) {
8086 DEBUG(10,("Returning WERR_NOMEM\n"));
8087 result = WERR_NOMEM;
8088 goto out;
8091 for (i=0; i<numlines; i++) {
8092 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
8093 result = fill_port_2(info, &info[i].info2, qlines[i]);
8094 if (!W_ERROR_IS_OK(result)) {
8095 goto out;
8099 TALLOC_FREE(qlines);
8101 out:
8102 if (!W_ERROR_IS_OK(result)) {
8103 TALLOC_FREE(info);
8104 TALLOC_FREE(qlines);
8105 *count = 0;
8106 *info_p = NULL;
8107 return result;
8110 *info_p = info;
8111 *count = numlines;
8113 return WERR_OK;
8116 /****************************************************************
8117 _spoolss_EnumPorts
8118 ****************************************************************/
8120 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
8121 struct spoolss_EnumPorts *r)
8123 WERROR result;
8125 /* that's an [in out] buffer */
8127 if (!r->in.buffer && (r->in.offered != 0)) {
8128 return WERR_INVALID_PARAM;
8131 DEBUG(4,("_spoolss_EnumPorts\n"));
8133 *r->out.count = 0;
8134 *r->out.needed = 0;
8135 *r->out.info = NULL;
8137 switch (r->in.level) {
8138 case 1:
8139 result = enumports_level_1(p->mem_ctx, r->out.info,
8140 r->out.count);
8141 break;
8142 case 2:
8143 result = enumports_level_2(p->mem_ctx, r->out.info,
8144 r->out.count);
8145 break;
8146 default:
8147 return WERR_UNKNOWN_LEVEL;
8150 if (!W_ERROR_IS_OK(result)) {
8151 return result;
8154 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8155 spoolss_EnumPorts,
8156 *r->out.info, r->in.level,
8157 *r->out.count);
8158 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8159 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8161 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8164 /****************************************************************************
8165 ****************************************************************************/
8167 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
8168 const char *server,
8169 struct spoolss_SetPrinterInfoCtr *info_ctr,
8170 struct spoolss_DeviceMode *devmode,
8171 struct security_descriptor *secdesc,
8172 struct spoolss_UserLevelCtr *user_ctr,
8173 struct policy_handle *handle)
8175 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
8176 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
8177 int snum;
8178 WERROR err = WERR_OK;
8180 /* samba does not have a concept of local, non-shared printers yet, so
8181 * make sure we always setup sharename - gd */
8182 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
8183 (info2->printername != NULL && info2->printername[0] != '\0')) {
8184 DEBUG(5, ("spoolss_addprinterex_level_2: "
8185 "no sharename has been set, setting printername %s as sharename\n",
8186 info2->printername));
8187 info2->sharename = info2->printername;
8190 /* check to see if the printer already exists */
8191 if ((snum = print_queue_snum(info2->sharename)) != -1) {
8192 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8193 info2->sharename));
8194 return WERR_PRINTER_ALREADY_EXISTS;
8197 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
8198 if ((snum = print_queue_snum(info2->printername)) != -1) {
8199 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8200 info2->printername));
8201 return WERR_PRINTER_ALREADY_EXISTS;
8205 /* validate printer info struct */
8206 if (!info2->printername || strlen(info2->printername) == 0) {
8207 return WERR_INVALID_PRINTER_NAME;
8209 if (!info2->portname || strlen(info2->portname) == 0) {
8210 return WERR_UNKNOWN_PORT;
8212 if (!info2->drivername || strlen(info2->drivername) == 0) {
8213 return WERR_UNKNOWN_PRINTER_DRIVER;
8215 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
8216 return WERR_UNKNOWN_PRINTPROCESSOR;
8219 /* FIXME!!! smbd should check to see if the driver is installed before
8220 trying to add a printer like this --jerry */
8222 if (*lp_addprinter_command(talloc_tos()) ) {
8223 char *raddr;
8225 raddr = tsocket_address_inet_addr_string(p->remote_address,
8226 p->mem_ctx);
8227 if (raddr == NULL) {
8228 return WERR_NOMEM;
8231 if ( !add_printer_hook(p->mem_ctx, p->session_info->security_token,
8232 info2, raddr,
8233 p->msg_ctx) ) {
8234 return WERR_ACCESS_DENIED;
8236 } else {
8237 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no "
8238 "smb.conf parameter \"addprinter command\" is defined. This "
8239 "parameter must exist for this call to succeed\n",
8240 info2->sharename ));
8243 if ((snum = print_queue_snum(info2->sharename)) == -1) {
8244 return WERR_ACCESS_DENIED;
8247 /* you must be a printer admin to add a new printer */
8248 if (!W_ERROR_IS_OK(print_access_check(p->session_info,
8249 p->msg_ctx,
8250 snum,
8251 PRINTER_ACCESS_ADMINISTER))) {
8252 return WERR_ACCESS_DENIED;
8256 * Do sanity check on the requested changes for Samba.
8259 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
8260 return WERR_INVALID_PARAM;
8263 if (devmode == NULL) {
8264 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
8267 err = update_dsspooler(p->mem_ctx,
8268 get_session_info_system(),
8269 p->msg_ctx,
8271 info2,
8272 NULL);
8273 if (!W_ERROR_IS_OK(err)) {
8274 return err;
8277 err = winreg_update_printer_internal(p->mem_ctx,
8278 get_session_info_system(),
8279 p->msg_ctx,
8280 info2->sharename,
8281 info2_mask,
8282 info2,
8283 devmode,
8284 secdesc);
8285 if (!W_ERROR_IS_OK(err)) {
8286 return err;
8289 err = open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER);
8290 if (!W_ERROR_IS_OK(err)) {
8291 /* Handle open failed - remove addition. */
8292 ZERO_STRUCTP(handle);
8293 return err;
8296 return WERR_OK;
8299 /****************************************************************
8300 _spoolss_AddPrinterEx
8301 ****************************************************************/
8303 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
8304 struct spoolss_AddPrinterEx *r)
8306 switch (r->in.info_ctr->level) {
8307 case 1:
8308 /* we don't handle yet */
8309 /* but I know what to do ... */
8310 return WERR_UNKNOWN_LEVEL;
8311 case 2:
8312 return spoolss_addprinterex_level_2(p, r->in.server,
8313 r->in.info_ctr,
8314 r->in.devmode_ctr->devmode,
8315 r->in.secdesc_ctr->sd,
8316 r->in.userlevel_ctr,
8317 r->out.handle);
8318 default:
8319 return WERR_UNKNOWN_LEVEL;
8323 /****************************************************************
8324 _spoolss_AddPrinter
8325 ****************************************************************/
8327 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
8328 struct spoolss_AddPrinter *r)
8330 struct spoolss_AddPrinterEx a;
8331 struct spoolss_UserLevelCtr userlevel_ctr;
8333 ZERO_STRUCT(userlevel_ctr);
8335 userlevel_ctr.level = 1;
8337 a.in.server = r->in.server;
8338 a.in.info_ctr = r->in.info_ctr;
8339 a.in.devmode_ctr = r->in.devmode_ctr;
8340 a.in.secdesc_ctr = r->in.secdesc_ctr;
8341 a.in.userlevel_ctr = &userlevel_ctr;
8342 a.out.handle = r->out.handle;
8344 return _spoolss_AddPrinterEx(p, &a);
8347 /****************************************************************
8348 _spoolss_AddPrinterDriverEx
8349 ****************************************************************/
8351 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
8352 struct spoolss_AddPrinterDriverEx *r)
8354 WERROR err = WERR_OK;
8355 const char *driver_name = NULL;
8356 uint32_t version;
8357 const char *fn;
8359 switch (p->opnum) {
8360 case NDR_SPOOLSS_ADDPRINTERDRIVER:
8361 fn = "_spoolss_AddPrinterDriver";
8362 break;
8363 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
8364 fn = "_spoolss_AddPrinterDriverEx";
8365 break;
8366 default:
8367 return WERR_INVALID_PARAM;
8371 * we only support the semantics of AddPrinterDriver()
8372 * i.e. only copy files that are newer than existing ones
8375 if (r->in.flags == 0) {
8376 return WERR_INVALID_PARAM;
8379 if (r->in.flags != APD_COPY_NEW_FILES) {
8380 return WERR_ACCESS_DENIED;
8383 /* FIXME */
8384 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
8385 /* Clever hack from Martin Zielinski <mz@seh.de>
8386 * to allow downgrade from level 8 (Vista).
8388 DEBUG(0,("%s: level %d not yet implemented\n", fn,
8389 r->in.info_ctr->level));
8390 return WERR_UNKNOWN_LEVEL;
8393 DEBUG(5,("Cleaning driver's information\n"));
8394 err = clean_up_driver_struct(p->mem_ctx, p->session_info, r->in.info_ctr);
8395 if (!W_ERROR_IS_OK(err))
8396 goto done;
8398 DEBUG(5,("Moving driver to final destination\n"));
8399 err = move_driver_to_download_area(p->session_info, r->in.info_ctr);
8400 if (!W_ERROR_IS_OK(err)) {
8401 goto done;
8404 err = winreg_add_driver_internal(p->mem_ctx,
8405 get_session_info_system(),
8406 p->msg_ctx,
8407 r->in.info_ctr,
8408 &driver_name,
8409 &version);
8410 if (!W_ERROR_IS_OK(err)) {
8411 goto done;
8415 * I think this is where he DrvUpgradePrinter() hook would be
8416 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8417 * server. Right now, we just need to send ourselves a message
8418 * to update each printer bound to this driver. --jerry
8421 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
8422 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8423 fn, driver_name));
8426 done:
8427 return err;
8430 /****************************************************************
8431 _spoolss_AddPrinterDriver
8432 ****************************************************************/
8434 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
8435 struct spoolss_AddPrinterDriver *r)
8437 struct spoolss_AddPrinterDriverEx a;
8439 switch (r->in.info_ctr->level) {
8440 case 2:
8441 case 3:
8442 case 4:
8443 case 5:
8444 break;
8445 default:
8446 return WERR_UNKNOWN_LEVEL;
8449 a.in.servername = r->in.servername;
8450 a.in.info_ctr = r->in.info_ctr;
8451 a.in.flags = APD_COPY_NEW_FILES;
8453 return _spoolss_AddPrinterDriverEx(p, &a);
8456 /****************************************************************************
8457 ****************************************************************************/
8459 struct _spoolss_paths {
8460 int type;
8461 const char *share;
8462 const char *dir;
8465 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
8467 static const struct _spoolss_paths spoolss_paths[]= {
8468 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
8469 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
8472 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
8473 const char *servername,
8474 const char *environment,
8475 int component,
8476 char **path)
8478 const char *pservername = NULL;
8479 const char *long_archi;
8480 const char *short_archi;
8482 *path = NULL;
8484 /* environment may be empty */
8485 if (environment && strlen(environment)) {
8486 long_archi = environment;
8487 } else {
8488 long_archi = lp_parm_const_string(GLOBAL_SECTION_SNUM,
8489 "spoolss", "architecture",
8490 SPOOLSS_ARCHITECTURE_NT_X86);
8493 /* servername may be empty */
8494 if (servername && strlen(servername)) {
8495 pservername = canon_servername(servername);
8497 if (!is_myname_or_ipaddr(pservername)) {
8498 return WERR_INVALID_PARAM;
8502 if (!(short_archi = get_short_archi(long_archi))) {
8503 return WERR_INVALID_ENVIRONMENT;
8506 switch (component) {
8507 case SPOOLSS_PRTPROCS_PATH:
8508 case SPOOLSS_DRIVER_PATH:
8509 if (pservername) {
8510 *path = talloc_asprintf(mem_ctx,
8511 "\\\\%s\\%s\\%s",
8512 pservername,
8513 spoolss_paths[component].share,
8514 short_archi);
8515 } else {
8516 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
8517 SPOOLSS_DEFAULT_SERVER_PATH,
8518 spoolss_paths[component].dir,
8519 short_archi);
8521 break;
8522 default:
8523 return WERR_INVALID_PARAM;
8526 if (!*path) {
8527 return WERR_NOMEM;
8530 return WERR_OK;
8533 /****************************************************************************
8534 ****************************************************************************/
8536 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
8537 const char *servername,
8538 const char *environment,
8539 struct spoolss_DriverDirectoryInfo1 *r)
8541 WERROR werr;
8542 char *path = NULL;
8544 werr = compose_spoolss_server_path(mem_ctx,
8545 servername,
8546 environment,
8547 SPOOLSS_DRIVER_PATH,
8548 &path);
8549 if (!W_ERROR_IS_OK(werr)) {
8550 return werr;
8553 DEBUG(4,("printer driver directory: [%s]\n", path));
8555 r->directory_name = path;
8557 return WERR_OK;
8560 /****************************************************************
8561 _spoolss_GetPrinterDriverDirectory
8562 ****************************************************************/
8564 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
8565 struct spoolss_GetPrinterDriverDirectory *r)
8567 WERROR werror;
8569 /* that's an [in out] buffer */
8571 if (!r->in.buffer && (r->in.offered != 0)) {
8572 TALLOC_FREE(r->out.info);
8573 return WERR_INVALID_PARAM;
8576 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8577 r->in.level));
8579 *r->out.needed = 0;
8581 /* r->in.level is ignored */
8583 werror = getprinterdriverdir_level_1(p->mem_ctx,
8584 r->in.server,
8585 r->in.environment,
8586 &r->out.info->info1);
8587 if (!W_ERROR_IS_OK(werror)) {
8588 TALLOC_FREE(r->out.info);
8589 return werror;
8592 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
8593 r->out.info, r->in.level);
8594 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8596 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8599 /****************************************************************
8600 _spoolss_EnumPrinterData
8601 ****************************************************************/
8603 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
8604 struct spoolss_EnumPrinterData *r)
8606 WERROR result;
8607 struct spoolss_EnumPrinterDataEx r2;
8608 uint32_t count;
8609 struct spoolss_PrinterEnumValues *info, *val = NULL;
8610 uint32_t needed;
8612 r2.in.handle = r->in.handle;
8613 r2.in.key_name = "PrinterDriverData";
8614 r2.in.offered = 0;
8615 r2.out.count = &count;
8616 r2.out.info = &info;
8617 r2.out.needed = &needed;
8619 result = _spoolss_EnumPrinterDataEx(p, &r2);
8620 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8621 r2.in.offered = needed;
8622 result = _spoolss_EnumPrinterDataEx(p, &r2);
8624 if (!W_ERROR_IS_OK(result)) {
8625 return result;
8629 * The NT machine wants to know the biggest size of value and data
8631 * cf: MSDN EnumPrinterData remark section
8634 if (!r->in.value_offered && !r->in.data_offered) {
8635 uint32_t biggest_valuesize = 0;
8636 uint32_t biggest_datasize = 0;
8637 int i, name_length;
8639 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8641 for (i=0; i<count; i++) {
8643 name_length = strlen(info[i].value_name);
8644 if (strlen(info[i].value_name) > biggest_valuesize) {
8645 biggest_valuesize = name_length;
8648 if (info[i].data_length > biggest_datasize) {
8649 biggest_datasize = info[i].data_length;
8652 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8653 biggest_datasize));
8656 /* the value is an UNICODE string but real_value_size is the length
8657 in bytes including the trailing 0 */
8659 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8660 *r->out.data_needed = biggest_datasize;
8662 DEBUG(6,("final values: [%d], [%d]\n",
8663 *r->out.value_needed, *r->out.data_needed));
8665 return WERR_OK;
8668 if (r->in.enum_index < count) {
8669 val = &info[r->in.enum_index];
8672 if (val == NULL) {
8673 /* out_value should default to "" or else NT4 has
8674 problems unmarshalling the response */
8676 if (r->in.value_offered) {
8677 *r->out.value_needed = 1;
8678 r->out.value_name = talloc_strdup(r, "");
8679 if (!r->out.value_name) {
8680 return WERR_NOMEM;
8682 } else {
8683 r->out.value_name = NULL;
8684 *r->out.value_needed = 0;
8687 /* the data is counted in bytes */
8689 *r->out.data_needed = r->in.data_offered;
8691 result = WERR_NO_MORE_ITEMS;
8692 } else {
8694 * the value is:
8695 * - counted in bytes in the request
8696 * - counted in UNICODE chars in the max reply
8697 * - counted in bytes in the real size
8699 * take a pause *before* coding not *during* coding
8702 /* name */
8703 if (r->in.value_offered) {
8704 r->out.value_name = talloc_strdup(r, val->value_name);
8705 if (!r->out.value_name) {
8706 return WERR_NOMEM;
8708 *r->out.value_needed = val->value_name_len;
8709 } else {
8710 r->out.value_name = NULL;
8711 *r->out.value_needed = 0;
8714 /* type */
8716 *r->out.type = val->type;
8718 /* data - counted in bytes */
8721 * See the section "Dynamically Typed Query Parameters"
8722 * in MS-RPRN.
8725 if (r->out.data && val->data && val->data->data &&
8726 val->data_length && r->in.data_offered) {
8727 memcpy(r->out.data, val->data->data,
8728 MIN(val->data_length,r->in.data_offered));
8731 *r->out.data_needed = val->data_length;
8733 result = WERR_OK;
8736 return result;
8739 /****************************************************************
8740 _spoolss_SetPrinterData
8741 ****************************************************************/
8743 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
8744 struct spoolss_SetPrinterData *r)
8746 struct spoolss_SetPrinterDataEx r2;
8748 r2.in.handle = r->in.handle;
8749 r2.in.key_name = "PrinterDriverData";
8750 r2.in.value_name = r->in.value_name;
8751 r2.in.type = r->in.type;
8752 r2.in.data = r->in.data;
8753 r2.in.offered = r->in.offered;
8755 return _spoolss_SetPrinterDataEx(p, &r2);
8758 /****************************************************************
8759 _spoolss_ResetPrinter
8760 ****************************************************************/
8762 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
8763 struct spoolss_ResetPrinter *r)
8765 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8766 int snum;
8768 DEBUG(5,("_spoolss_ResetPrinter\n"));
8771 * All we do is to check to see if the handle and queue is valid.
8772 * This call really doesn't mean anything to us because we only
8773 * support RAW printing. --jerry
8776 if (!Printer) {
8777 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8778 OUR_HANDLE(r->in.handle)));
8779 return WERR_BADFID;
8782 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8783 return WERR_BADFID;
8786 /* blindly return success */
8787 return WERR_OK;
8790 /****************************************************************
8791 _spoolss_DeletePrinterData
8792 ****************************************************************/
8794 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
8795 struct spoolss_DeletePrinterData *r)
8797 struct spoolss_DeletePrinterDataEx r2;
8799 r2.in.handle = r->in.handle;
8800 r2.in.key_name = "PrinterDriverData";
8801 r2.in.value_name = r->in.value_name;
8803 return _spoolss_DeletePrinterDataEx(p, &r2);
8806 /****************************************************************
8807 _spoolss_AddForm
8808 ****************************************************************/
8810 WERROR _spoolss_AddForm(struct pipes_struct *p,
8811 struct spoolss_AddForm *r)
8813 struct spoolss_AddFormInfo1 *form;
8814 int snum = -1;
8815 WERROR status = WERR_OK;
8816 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8817 struct dcerpc_binding_handle *b;
8818 TALLOC_CTX *tmp_ctx = NULL;
8820 DEBUG(5,("_spoolss_AddForm\n"));
8822 if (!Printer) {
8823 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8824 OUR_HANDLE(r->in.handle)));
8825 return WERR_BADFID;
8828 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8829 and not a printer admin, then fail */
8831 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
8832 !security_token_has_privilege(p->session_info->security_token,
8833 SEC_PRIV_PRINT_OPERATOR)) {
8834 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8835 return WERR_ACCESS_DENIED;
8838 if (r->in.info_ctr->level != 1) {
8839 return WERR_INVALID_LEVEL;
8842 form = r->in.info_ctr->info.info1;
8843 if (!form) {
8844 return WERR_INVALID_PARAM;
8847 switch (form->flags) {
8848 case SPOOLSS_FORM_USER:
8849 case SPOOLSS_FORM_BUILTIN:
8850 case SPOOLSS_FORM_PRINTER:
8851 break;
8852 default:
8853 return WERR_INVALID_PARAM;
8856 tmp_ctx = talloc_new(p->mem_ctx);
8857 if (!tmp_ctx) {
8858 return WERR_NOMEM;
8861 status = winreg_printer_binding_handle(tmp_ctx,
8862 get_session_info_system(),
8863 p->msg_ctx,
8864 &b);
8865 if (!W_ERROR_IS_OK(status)) {
8866 goto done;
8869 status = winreg_printer_addform1(tmp_ctx, b, form);
8870 if (!W_ERROR_IS_OK(status)) {
8871 goto done;
8875 * ChangeID must always be set if this is a printer
8877 if (Printer->printer_type == SPLHND_PRINTER) {
8878 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8879 status = WERR_BADFID;
8880 goto done;
8883 status = winreg_printer_update_changeid(tmp_ctx, b,
8884 lp_const_servicename(snum));
8887 done:
8888 talloc_free(tmp_ctx);
8889 return status;
8892 /****************************************************************
8893 _spoolss_DeleteForm
8894 ****************************************************************/
8896 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8897 struct spoolss_DeleteForm *r)
8899 const char *form_name = r->in.form_name;
8900 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8901 int snum = -1;
8902 WERROR status = WERR_OK;
8903 struct dcerpc_binding_handle *b;
8904 TALLOC_CTX *tmp_ctx = NULL;
8906 DEBUG(5,("_spoolss_DeleteForm\n"));
8908 if (!Printer) {
8909 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8910 OUR_HANDLE(r->in.handle)));
8911 return WERR_BADFID;
8914 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
8915 !security_token_has_privilege(p->session_info->security_token,
8916 SEC_PRIV_PRINT_OPERATOR)) {
8917 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8918 return WERR_ACCESS_DENIED;
8921 tmp_ctx = talloc_new(p->mem_ctx);
8922 if (!tmp_ctx) {
8923 return WERR_NOMEM;
8926 status = winreg_printer_binding_handle(tmp_ctx,
8927 get_session_info_system(),
8928 p->msg_ctx,
8929 &b);
8930 if (!W_ERROR_IS_OK(status)) {
8931 goto done;
8934 status = winreg_printer_deleteform1(tmp_ctx, b, form_name);
8935 if (!W_ERROR_IS_OK(status)) {
8936 goto done;
8940 * ChangeID must always be set if this is a printer
8942 if (Printer->printer_type == SPLHND_PRINTER) {
8943 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8944 status = WERR_BADFID;
8945 goto done;
8948 status = winreg_printer_update_changeid(tmp_ctx, b,
8949 lp_const_servicename(snum));
8952 done:
8953 talloc_free(tmp_ctx);
8954 return status;
8957 /****************************************************************
8958 _spoolss_SetForm
8959 ****************************************************************/
8961 WERROR _spoolss_SetForm(struct pipes_struct *p,
8962 struct spoolss_SetForm *r)
8964 struct spoolss_AddFormInfo1 *form;
8965 const char *form_name = r->in.form_name;
8966 int snum = -1;
8967 WERROR status = WERR_OK;
8968 struct dcerpc_binding_handle *b;
8969 TALLOC_CTX *tmp_ctx = NULL;
8971 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8973 DEBUG(5,("_spoolss_SetForm\n"));
8975 if (!Printer) {
8976 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8977 OUR_HANDLE(r->in.handle)));
8978 return WERR_BADFID;
8981 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8982 and not a printer admin, then fail */
8984 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
8985 !security_token_has_privilege(p->session_info->security_token,
8986 SEC_PRIV_PRINT_OPERATOR)) {
8987 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8988 return WERR_ACCESS_DENIED;
8991 if (r->in.info_ctr->level != 1) {
8992 return WERR_INVALID_LEVEL;
8995 form = r->in.info_ctr->info.info1;
8996 if (!form) {
8997 return WERR_INVALID_PARAM;
9000 tmp_ctx = talloc_new(p->mem_ctx);
9001 if (!tmp_ctx) {
9002 return WERR_NOMEM;
9005 status = winreg_printer_binding_handle(tmp_ctx,
9006 get_session_info_system(),
9007 p->msg_ctx,
9008 &b);
9009 if (!W_ERROR_IS_OK(status)) {
9010 goto done;
9013 status = winreg_printer_setform1(tmp_ctx, b,
9014 form_name,
9015 form);
9016 if (!W_ERROR_IS_OK(status)) {
9017 goto done;
9021 * ChangeID must always be set if this is a printer
9023 if (Printer->printer_type == SPLHND_PRINTER) {
9024 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9025 status = WERR_BADFID;
9026 goto done;
9029 status = winreg_printer_update_changeid(tmp_ctx, b,
9030 lp_const_servicename(snum));
9033 done:
9034 talloc_free(tmp_ctx);
9035 return status;
9038 /****************************************************************************
9039 fill_print_processor1
9040 ****************************************************************************/
9042 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
9043 struct spoolss_PrintProcessorInfo1 *r,
9044 const char *print_processor_name)
9046 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
9047 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
9049 return WERR_OK;
9052 /****************************************************************************
9053 enumprintprocessors level 1.
9054 ****************************************************************************/
9056 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
9057 union spoolss_PrintProcessorInfo **info_p,
9058 uint32_t *count)
9060 union spoolss_PrintProcessorInfo *info;
9061 WERROR result;
9063 info = talloc_array(mem_ctx, union spoolss_PrintProcessorInfo, 1);
9064 W_ERROR_HAVE_NO_MEMORY(info);
9066 *count = 1;
9068 result = fill_print_processor1(info, &info[0].info1, "winprint");
9069 if (!W_ERROR_IS_OK(result)) {
9070 goto out;
9073 out:
9074 if (!W_ERROR_IS_OK(result)) {
9075 TALLOC_FREE(info);
9076 *count = 0;
9077 return result;
9080 *info_p = info;
9082 return WERR_OK;
9085 /****************************************************************
9086 _spoolss_EnumPrintProcessors
9087 ****************************************************************/
9089 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
9090 struct spoolss_EnumPrintProcessors *r)
9092 WERROR result;
9094 /* that's an [in out] buffer */
9096 if (!r->in.buffer && (r->in.offered != 0)) {
9097 return WERR_INVALID_PARAM;
9100 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
9103 * Enumerate the print processors ...
9105 * Just reply with "winprint", to keep NT happy
9106 * and I can use my nice printer checker.
9109 *r->out.count = 0;
9110 *r->out.needed = 0;
9111 *r->out.info = NULL;
9113 if (!get_short_archi(r->in.environment)) {
9114 return WERR_INVALID_ENVIRONMENT;
9117 switch (r->in.level) {
9118 case 1:
9119 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
9120 r->out.count);
9121 break;
9122 default:
9123 return WERR_UNKNOWN_LEVEL;
9126 if (!W_ERROR_IS_OK(result)) {
9127 return result;
9130 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9131 spoolss_EnumPrintProcessors,
9132 *r->out.info, r->in.level,
9133 *r->out.count);
9134 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9135 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9137 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9140 /****************************************************************************
9141 fill_printprocdatatype1
9142 ****************************************************************************/
9144 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
9145 struct spoolss_PrintProcDataTypesInfo1 *r,
9146 const char *name_array)
9148 r->name_array = talloc_strdup(mem_ctx, name_array);
9149 W_ERROR_HAVE_NO_MEMORY(r->name_array);
9151 return WERR_OK;
9154 /****************************************************************************
9155 enumprintprocdatatypes level 1.
9156 ****************************************************************************/
9158 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
9159 union spoolss_PrintProcDataTypesInfo **info_p,
9160 uint32_t *count)
9162 WERROR result;
9163 union spoolss_PrintProcDataTypesInfo *info;
9165 info = talloc_array(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
9166 W_ERROR_HAVE_NO_MEMORY(info);
9168 *count = 1;
9170 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
9171 if (!W_ERROR_IS_OK(result)) {
9172 goto out;
9175 out:
9176 if (!W_ERROR_IS_OK(result)) {
9177 TALLOC_FREE(info);
9178 *count = 0;
9179 return result;
9182 *info_p = info;
9184 return WERR_OK;
9187 /****************************************************************
9188 _spoolss_EnumPrintProcDataTypes
9189 ****************************************************************/
9191 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
9192 struct spoolss_EnumPrintProcDataTypes *r)
9194 WERROR result;
9196 /* that's an [in out] buffer */
9198 if (!r->in.buffer && (r->in.offered != 0)) {
9199 return WERR_INVALID_PARAM;
9202 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
9204 *r->out.count = 0;
9205 *r->out.needed = 0;
9206 *r->out.info = NULL;
9208 if (r->in.print_processor_name == NULL ||
9209 !strequal(r->in.print_processor_name, "winprint")) {
9210 return WERR_UNKNOWN_PRINTPROCESSOR;
9213 switch (r->in.level) {
9214 case 1:
9215 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
9216 r->out.count);
9217 break;
9218 default:
9219 return WERR_UNKNOWN_LEVEL;
9222 if (!W_ERROR_IS_OK(result)) {
9223 return result;
9226 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9227 spoolss_EnumPrintProcDataTypes,
9228 *r->out.info, r->in.level,
9229 *r->out.count);
9230 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9231 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9233 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9236 /****************************************************************************
9237 fill_monitor_1
9238 ****************************************************************************/
9240 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
9241 struct spoolss_MonitorInfo1 *r,
9242 const char *monitor_name)
9244 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
9245 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
9247 return WERR_OK;
9250 /****************************************************************************
9251 fill_monitor_2
9252 ****************************************************************************/
9254 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
9255 struct spoolss_MonitorInfo2 *r,
9256 const char *monitor_name,
9257 const char *environment,
9258 const char *dll_name)
9260 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
9261 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
9262 r->environment = talloc_strdup(mem_ctx, environment);
9263 W_ERROR_HAVE_NO_MEMORY(r->environment);
9264 r->dll_name = talloc_strdup(mem_ctx, dll_name);
9265 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
9267 return WERR_OK;
9270 /****************************************************************************
9271 enumprintmonitors level 1.
9272 ****************************************************************************/
9274 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
9275 union spoolss_MonitorInfo **info_p,
9276 uint32_t *count)
9278 union spoolss_MonitorInfo *info;
9279 WERROR result = WERR_OK;
9281 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, 2);
9282 W_ERROR_HAVE_NO_MEMORY(info);
9284 *count = 2;
9286 result = fill_monitor_1(info, &info[0].info1,
9287 SPL_LOCAL_PORT);
9288 if (!W_ERROR_IS_OK(result)) {
9289 goto out;
9292 result = fill_monitor_1(info, &info[1].info1,
9293 SPL_TCPIP_PORT);
9294 if (!W_ERROR_IS_OK(result)) {
9295 goto out;
9298 out:
9299 if (!W_ERROR_IS_OK(result)) {
9300 TALLOC_FREE(info);
9301 *count = 0;
9302 return result;
9305 *info_p = info;
9307 return WERR_OK;
9310 /****************************************************************************
9311 enumprintmonitors level 2.
9312 ****************************************************************************/
9314 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
9315 union spoolss_MonitorInfo **info_p,
9316 uint32_t *count)
9318 union spoolss_MonitorInfo *info;
9319 WERROR result = WERR_OK;
9321 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, 2);
9322 W_ERROR_HAVE_NO_MEMORY(info);
9324 *count = 2;
9326 result = fill_monitor_2(info, &info[0].info2,
9327 SPL_LOCAL_PORT,
9328 "Windows NT X86", /* FIXME */
9329 "localmon.dll");
9330 if (!W_ERROR_IS_OK(result)) {
9331 goto out;
9334 result = fill_monitor_2(info, &info[1].info2,
9335 SPL_TCPIP_PORT,
9336 "Windows NT X86", /* FIXME */
9337 "tcpmon.dll");
9338 if (!W_ERROR_IS_OK(result)) {
9339 goto out;
9342 out:
9343 if (!W_ERROR_IS_OK(result)) {
9344 TALLOC_FREE(info);
9345 *count = 0;
9346 return result;
9349 *info_p = info;
9351 return WERR_OK;
9354 /****************************************************************
9355 _spoolss_EnumMonitors
9356 ****************************************************************/
9358 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
9359 struct spoolss_EnumMonitors *r)
9361 WERROR result;
9363 /* that's an [in out] buffer */
9365 if (!r->in.buffer && (r->in.offered != 0)) {
9366 return WERR_INVALID_PARAM;
9369 DEBUG(5,("_spoolss_EnumMonitors\n"));
9372 * Enumerate the print monitors ...
9374 * Just reply with "Local Port", to keep NT happy
9375 * and I can use my nice printer checker.
9378 *r->out.count = 0;
9379 *r->out.needed = 0;
9380 *r->out.info = NULL;
9382 switch (r->in.level) {
9383 case 1:
9384 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
9385 r->out.count);
9386 break;
9387 case 2:
9388 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
9389 r->out.count);
9390 break;
9391 default:
9392 return WERR_UNKNOWN_LEVEL;
9395 if (!W_ERROR_IS_OK(result)) {
9396 return result;
9399 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9400 spoolss_EnumMonitors,
9401 *r->out.info, r->in.level,
9402 *r->out.count);
9403 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9404 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9406 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9409 /****************************************************************************
9410 ****************************************************************************/
9412 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
9413 const print_queue_struct *queue,
9414 int count, int snum,
9415 struct spoolss_PrinterInfo2 *pinfo2,
9416 uint32_t jobid,
9417 int sysjob,
9418 struct spoolss_JobInfo1 *r)
9420 int i = 0;
9421 bool found = false;
9423 for (i=0; i<count; i++) {
9424 if (queue[i].sysjob == sysjob) {
9425 found = true;
9426 break;
9430 if (found == false) {
9431 /* NT treats not found as bad param... yet another bad choice */
9432 return WERR_INVALID_PARAM;
9435 return fill_job_info1(mem_ctx,
9437 &queue[i],
9438 jobid,
9440 snum,
9441 pinfo2);
9444 /****************************************************************************
9445 ****************************************************************************/
9447 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
9448 const print_queue_struct *queue,
9449 int count, int snum,
9450 struct spoolss_PrinterInfo2 *pinfo2,
9451 uint32_t jobid,
9452 int sysjob,
9453 struct spoolss_JobInfo2 *r)
9455 int i = 0;
9456 bool found = false;
9457 struct spoolss_DeviceMode *devmode;
9458 WERROR result;
9460 for (i=0; i<count; i++) {
9461 if (queue[i].sysjob == sysjob) {
9462 found = true;
9463 break;
9467 if (found == false) {
9468 /* NT treats not found as bad param... yet another bad
9469 choice */
9470 return WERR_INVALID_PARAM;
9474 * if the print job does not have a DEVMODE associated with it,
9475 * just use the one for the printer. A NULL devicemode is not
9476 * a failure condition
9479 devmode = print_job_devmode(mem_ctx, lp_const_servicename(snum), jobid);
9480 if (!devmode) {
9481 result = spoolss_create_default_devmode(mem_ctx,
9482 pinfo2->printername,
9483 &devmode);
9484 if (!W_ERROR_IS_OK(result)) {
9485 DEBUG(3, ("Can't proceed w/o a devmode!"));
9486 return result;
9490 return fill_job_info2(mem_ctx,
9492 &queue[i],
9493 jobid,
9495 snum,
9496 pinfo2,
9497 devmode);
9500 /****************************************************************
9501 _spoolss_GetJob
9502 ****************************************************************/
9504 WERROR _spoolss_GetJob(struct pipes_struct *p,
9505 struct spoolss_GetJob *r)
9507 WERROR result = WERR_OK;
9508 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9509 const char *svc_name;
9510 int sysjob;
9511 int snum;
9512 int count;
9513 struct tdb_print_db *pdb;
9514 print_queue_struct *queue = NULL;
9515 print_status_struct prt_status;
9517 /* that's an [in out] buffer */
9519 if (!r->in.buffer && (r->in.offered != 0)) {
9520 result = WERR_INVALID_PARAM;
9521 goto err_jinfo_free;
9524 DEBUG(5,("_spoolss_GetJob\n"));
9526 *r->out.needed = 0;
9528 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9529 result = WERR_BADFID;
9530 goto err_jinfo_free;
9533 svc_name = lp_const_servicename(snum);
9534 if (svc_name == NULL) {
9535 result = WERR_INVALID_PARAM;
9536 goto err_jinfo_free;
9539 result = winreg_get_printer_internal(p->mem_ctx,
9540 get_session_info_system(),
9541 p->msg_ctx,
9542 svc_name,
9543 &pinfo2);
9544 if (!W_ERROR_IS_OK(result)) {
9545 goto err_jinfo_free;
9548 pdb = get_print_db_byname(svc_name);
9549 if (pdb == NULL) {
9550 DEBUG(3, ("failed to get print db for svc %s\n", svc_name));
9551 result = WERR_INVALID_PARAM;
9552 goto err_pinfo_free;
9555 sysjob = jobid_to_sysjob_pdb(pdb, r->in.job_id);
9556 release_print_db(pdb);
9557 if (sysjob == -1) {
9558 DEBUG(3, ("no sysjob for spoolss jobid %u\n", r->in.job_id));
9559 result = WERR_INVALID_PARAM;
9560 goto err_pinfo_free;
9563 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
9565 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9566 count, prt_status.status, prt_status.message));
9568 switch (r->in.level) {
9569 case 1:
9570 result = getjob_level_1(p->mem_ctx,
9571 queue, count, snum, pinfo2,
9572 r->in.job_id, sysjob,
9573 &r->out.info->info1);
9574 break;
9575 case 2:
9576 result = getjob_level_2(p->mem_ctx,
9577 queue, count, snum, pinfo2,
9578 r->in.job_id, sysjob,
9579 &r->out.info->info2);
9580 break;
9581 default:
9582 result = WERR_UNKNOWN_LEVEL;
9583 break;
9586 SAFE_FREE(queue);
9587 TALLOC_FREE(pinfo2);
9589 if (!W_ERROR_IS_OK(result)) {
9590 goto err_jinfo_free;
9593 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
9594 r->in.level);
9595 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9597 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9599 err_pinfo_free:
9600 TALLOC_FREE(pinfo2);
9601 err_jinfo_free:
9602 TALLOC_FREE(r->out.info);
9603 return result;
9606 /****************************************************************
9607 _spoolss_GetPrinterDataEx
9608 ****************************************************************/
9610 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
9611 struct spoolss_GetPrinterDataEx *r)
9614 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9615 const char *printer;
9616 int snum = 0;
9617 WERROR result = WERR_OK;
9618 DATA_BLOB blob;
9619 enum winreg_Type val_type = REG_NONE;
9620 uint8_t *val_data = NULL;
9621 uint32_t val_size = 0;
9622 struct dcerpc_binding_handle *b;
9623 TALLOC_CTX *tmp_ctx;
9625 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9627 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9628 r->in.key_name, r->in.value_name));
9630 /* in case of problem, return some default values */
9632 *r->out.needed = 0;
9633 *r->out.type = REG_NONE;
9635 tmp_ctx = talloc_new(p->mem_ctx);
9636 if (!tmp_ctx) {
9637 return WERR_NOMEM;
9640 if (!Printer) {
9641 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9642 OUR_HANDLE(r->in.handle)));
9643 result = WERR_BADFID;
9644 goto done;
9647 /* check to see if the keyname is valid */
9648 if (!strlen(r->in.key_name)) {
9649 result = WERR_INVALID_PARAM;
9650 goto done;
9653 /* Is the handle to a printer or to the server? */
9655 if (Printer->printer_type == SPLHND_SERVER) {
9657 union spoolss_PrinterData data;
9659 result = getprinterdata_printer_server(tmp_ctx,
9660 r->in.value_name,
9661 r->out.type,
9662 &data);
9663 if (!W_ERROR_IS_OK(result)) {
9664 goto done;
9667 result = push_spoolss_PrinterData(tmp_ctx, &blob,
9668 *r->out.type, &data);
9669 if (!W_ERROR_IS_OK(result)) {
9670 goto done;
9673 *r->out.needed = blob.length;
9675 if (r->in.offered >= *r->out.needed) {
9676 memcpy(r->out.data, blob.data, blob.length);
9679 result = WERR_OK;
9680 goto done;
9683 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9684 result = WERR_BADFID;
9685 goto done;
9687 printer = lp_const_servicename(snum);
9689 result = winreg_printer_binding_handle(tmp_ctx,
9690 get_session_info_system(),
9691 p->msg_ctx,
9692 &b);
9693 if (!W_ERROR_IS_OK(result)) {
9694 goto done;
9697 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9698 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
9699 strequal(r->in.value_name, "ChangeId")) {
9700 *r->out.type = REG_DWORD;
9701 *r->out.needed = 4;
9702 if (r->in.offered >= *r->out.needed) {
9703 uint32_t changeid = 0;
9705 result = winreg_printer_get_changeid(tmp_ctx, b,
9706 printer,
9707 &changeid);
9708 if (!W_ERROR_IS_OK(result)) {
9709 goto done;
9712 SIVAL(r->out.data, 0, changeid);
9713 result = WERR_OK;
9715 goto done;
9718 result = winreg_get_printer_dataex(tmp_ctx, b,
9719 printer,
9720 r->in.key_name,
9721 r->in.value_name,
9722 &val_type,
9723 &val_data,
9724 &val_size);
9725 if (!W_ERROR_IS_OK(result)) {
9726 goto done;
9729 *r->out.needed = val_size;
9730 *r->out.type = val_type;
9732 if (r->in.offered >= *r->out.needed) {
9733 memcpy(r->out.data, val_data, val_size);
9736 done:
9737 /* NOTE: do not replace type when returning WERR_MORE_DATA */
9739 if (W_ERROR_IS_OK(result)) {
9740 result = SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9743 talloc_free(tmp_ctx);
9744 return result;
9747 /****************************************************************
9748 _spoolss_SetPrinterDataEx
9749 ****************************************************************/
9751 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
9752 struct spoolss_SetPrinterDataEx *r)
9754 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9755 int snum = 0;
9756 WERROR result = WERR_OK;
9757 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9758 char *oid_string;
9759 struct dcerpc_binding_handle *b;
9760 TALLOC_CTX *tmp_ctx;
9762 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9764 /* From MSDN documentation of SetPrinterDataEx: pass request to
9765 SetPrinterData if key is "PrinterDriverData" */
9767 if (!Printer) {
9768 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9769 OUR_HANDLE(r->in.handle)));
9770 return WERR_BADFID;
9773 if (Printer->printer_type == SPLHND_SERVER) {
9774 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9775 "Not implemented for server handles yet\n"));
9776 return WERR_INVALID_PARAM;
9779 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9780 return WERR_BADFID;
9784 * Access check : NT returns "access denied" if you make a
9785 * SetPrinterData call without the necessary privildge.
9786 * we were originally returning OK if nothing changed
9787 * which made Win2k issue **a lot** of SetPrinterData
9788 * when connecting to a printer --jerry
9791 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9792 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9793 "change denied by handle access permissions\n"));
9794 return WERR_ACCESS_DENIED;
9797 tmp_ctx = talloc_new(p->mem_ctx);
9798 if (!tmp_ctx) {
9799 return WERR_NOMEM;
9802 result = winreg_printer_binding_handle(tmp_ctx,
9803 get_session_info_system(),
9804 p->msg_ctx,
9805 &b);
9806 if (!W_ERROR_IS_OK(result)) {
9807 goto done;
9810 result = winreg_get_printer(tmp_ctx, b,
9811 lp_servicename(talloc_tos(), snum),
9812 &pinfo2);
9813 if (!W_ERROR_IS_OK(result)) {
9814 goto done;
9817 /* check for OID in valuename */
9819 oid_string = strchr(r->in.value_name, ',');
9820 if (oid_string) {
9821 *oid_string = '\0';
9822 oid_string++;
9825 /* save the registry data */
9827 result = winreg_set_printer_dataex(tmp_ctx, b,
9828 pinfo2->sharename,
9829 r->in.key_name,
9830 r->in.value_name,
9831 r->in.type,
9832 r->in.data,
9833 r->in.offered);
9835 if (W_ERROR_IS_OK(result)) {
9836 /* save the OID if one was specified */
9837 if (oid_string) {
9838 char *str = talloc_asprintf(tmp_ctx, "%s\\%s",
9839 r->in.key_name, SPOOL_OID_KEY);
9840 if (!str) {
9841 result = WERR_NOMEM;
9842 goto done;
9846 * I'm not checking the status here on purpose. Don't know
9847 * if this is right, but I'm returning the status from the
9848 * previous set_printer_dataex() call. I have no idea if
9849 * this is right. --jerry
9851 winreg_set_printer_dataex(tmp_ctx, b,
9852 pinfo2->sharename,
9853 str,
9854 r->in.value_name,
9855 REG_SZ,
9856 (uint8_t *) oid_string,
9857 strlen(oid_string) + 1);
9860 result = winreg_printer_update_changeid(tmp_ctx, b,
9861 lp_const_servicename(snum));
9865 done:
9866 talloc_free(tmp_ctx);
9867 return result;
9870 /****************************************************************
9871 _spoolss_DeletePrinterDataEx
9872 ****************************************************************/
9874 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
9875 struct spoolss_DeletePrinterDataEx *r)
9877 const char *printer;
9878 int snum=0;
9879 WERROR status = WERR_OK;
9880 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9882 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9884 if (!Printer) {
9885 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9886 "Invalid handle (%s:%u:%u).\n",
9887 OUR_HANDLE(r->in.handle)));
9888 return WERR_BADFID;
9891 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9892 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9893 "printer properties change denied by handle\n"));
9894 return WERR_ACCESS_DENIED;
9897 if (!r->in.value_name || !r->in.key_name) {
9898 return WERR_NOMEM;
9901 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9902 return WERR_BADFID;
9904 printer = lp_const_servicename(snum);
9906 status = winreg_delete_printer_dataex_internal(p->mem_ctx,
9907 get_session_info_system(),
9908 p->msg_ctx,
9909 printer,
9910 r->in.key_name,
9911 r->in.value_name);
9912 if (W_ERROR_IS_OK(status)) {
9913 status = winreg_printer_update_changeid_internal(p->mem_ctx,
9914 get_session_info_system(),
9915 p->msg_ctx,
9916 printer);
9919 return status;
9922 /****************************************************************
9923 _spoolss_EnumPrinterKey
9924 ****************************************************************/
9926 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
9927 struct spoolss_EnumPrinterKey *r)
9929 uint32_t num_keys;
9930 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9931 int snum = 0;
9932 WERROR result = WERR_BADFILE;
9933 const char **array = NULL;
9934 DATA_BLOB blob;
9936 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9938 if (!Printer) {
9939 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9940 OUR_HANDLE(r->in.handle)));
9941 return WERR_BADFID;
9944 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9945 return WERR_BADFID;
9948 result = winreg_enum_printer_key_internal(p->mem_ctx,
9949 get_session_info_system(),
9950 p->msg_ctx,
9951 lp_const_servicename(snum),
9952 r->in.key_name,
9953 &num_keys,
9954 &array);
9955 if (!W_ERROR_IS_OK(result)) {
9956 goto done;
9959 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9960 result = WERR_NOMEM;
9961 goto done;
9964 *r->out._ndr_size = r->in.offered / 2;
9965 *r->out.needed = blob.length;
9967 if (r->in.offered < *r->out.needed) {
9968 result = WERR_MORE_DATA;
9969 } else {
9970 result = WERR_OK;
9971 r->out.key_buffer->string_array = array;
9974 done:
9975 if (!W_ERROR_IS_OK(result)) {
9976 TALLOC_FREE(array);
9977 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9978 *r->out.needed = 0;
9982 return result;
9985 /****************************************************************
9986 _spoolss_DeletePrinterKey
9987 ****************************************************************/
9989 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9990 struct spoolss_DeletePrinterKey *r)
9992 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9993 int snum=0;
9994 WERROR status;
9995 const char *printer;
9996 struct dcerpc_binding_handle *b;
9997 TALLOC_CTX *tmp_ctx;
9999 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
10001 if (!Printer) {
10002 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
10003 OUR_HANDLE(r->in.handle)));
10004 return WERR_BADFID;
10007 /* if keyname == NULL, return error */
10008 if ( !r->in.key_name )
10009 return WERR_INVALID_PARAM;
10011 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
10012 return WERR_BADFID;
10015 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
10016 DEBUG(3, ("_spoolss_DeletePrinterKey: "
10017 "printer properties change denied by handle\n"));
10018 return WERR_ACCESS_DENIED;
10021 printer = lp_const_servicename(snum);
10023 tmp_ctx = talloc_new(p->mem_ctx);
10024 if (!tmp_ctx) {
10025 return WERR_NOMEM;
10028 status = winreg_printer_binding_handle(tmp_ctx,
10029 get_session_info_system(),
10030 p->msg_ctx,
10031 &b);
10032 if (!W_ERROR_IS_OK(status)) {
10033 goto done;
10036 /* delete the key and all subkeys */
10037 status = winreg_delete_printer_key(tmp_ctx, b,
10038 printer,
10039 r->in.key_name);
10040 if (W_ERROR_IS_OK(status)) {
10041 status = winreg_printer_update_changeid(tmp_ctx, b,
10042 printer);
10045 done:
10046 talloc_free(tmp_ctx);
10047 return status;
10050 /****************************************************************
10051 _spoolss_EnumPrinterDataEx
10052 ****************************************************************/
10054 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
10055 struct spoolss_EnumPrinterDataEx *r)
10057 uint32_t count = 0;
10058 struct spoolss_PrinterEnumValues *info = NULL;
10059 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
10060 int snum;
10061 WERROR result;
10063 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
10065 *r->out.count = 0;
10066 *r->out.needed = 0;
10067 *r->out.info = NULL;
10069 if (!Printer) {
10070 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
10071 OUR_HANDLE(r->in.handle)));
10072 return WERR_BADFID;
10076 * first check for a keyname of NULL or "". Win2k seems to send
10077 * this a lot and we should send back WERR_INVALID_PARAM
10078 * no need to spend time looking up the printer in this case.
10079 * --jerry
10082 if (!strlen(r->in.key_name)) {
10083 result = WERR_INVALID_PARAM;
10084 goto done;
10087 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
10088 return WERR_BADFID;
10091 /* now look for a match on the key name */
10092 result = winreg_enum_printer_dataex_internal(p->mem_ctx,
10093 get_session_info_system(),
10094 p->msg_ctx,
10095 lp_const_servicename(snum),
10096 r->in.key_name,
10097 &count,
10098 &info);
10099 if (!W_ERROR_IS_OK(result)) {
10100 goto done;
10103 #if 0 /* FIXME - gd */
10104 /* housekeeping information in the reply */
10106 /* Fix from Martin Zielinski <mz@seh.de> - ensure
10107 * the hand marshalled container size is a multiple
10108 * of 4 bytes for RPC alignment.
10111 if (needed % 4) {
10112 needed += 4-(needed % 4);
10114 #endif
10115 *r->out.count = count;
10116 *r->out.info = info;
10118 done:
10119 if (!W_ERROR_IS_OK(result)) {
10120 return result;
10123 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
10124 spoolss_EnumPrinterDataEx,
10125 *r->out.info,
10126 *r->out.count);
10127 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
10128 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
10130 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
10133 /****************************************************************************
10134 ****************************************************************************/
10136 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
10137 const char *servername,
10138 const char *environment,
10139 struct spoolss_PrintProcessorDirectoryInfo1 *r)
10141 WERROR werr;
10142 char *path = NULL;
10144 werr = compose_spoolss_server_path(mem_ctx,
10145 servername,
10146 environment,
10147 SPOOLSS_PRTPROCS_PATH,
10148 &path);
10149 if (!W_ERROR_IS_OK(werr)) {
10150 return werr;
10153 DEBUG(4,("print processor directory: [%s]\n", path));
10155 r->directory_name = path;
10157 return WERR_OK;
10160 /****************************************************************
10161 _spoolss_GetPrintProcessorDirectory
10162 ****************************************************************/
10164 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
10165 struct spoolss_GetPrintProcessorDirectory *r)
10167 WERROR result;
10168 char *prnproc_share = NULL;
10169 bool prnproc_share_exists = false;
10170 int snum;
10172 /* that's an [in out] buffer */
10174 if (!r->in.buffer && (r->in.offered != 0)) {
10175 result = WERR_INVALID_PARAM;
10176 goto err_info_free;
10179 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
10180 r->in.level));
10182 *r->out.needed = 0;
10184 /* r->in.level is ignored */
10186 /* We always should reply with a local print processor directory so that
10187 * users are not forced to have a [prnproc$] share on the Samba spoolss
10188 * server, if users decide to do so, lets announce it though - Guenther */
10190 snum = find_service(talloc_tos(), "prnproc$", &prnproc_share);
10191 if (!prnproc_share) {
10192 result = WERR_NOMEM;
10193 goto err_info_free;
10195 if (snum != -1) {
10196 prnproc_share_exists = true;
10199 result = getprintprocessordirectory_level_1(p->mem_ctx,
10200 prnproc_share_exists ? r->in.server : NULL,
10201 r->in.environment,
10202 &r->out.info->info1);
10203 if (!W_ERROR_IS_OK(result)) {
10204 goto err_info_free;
10207 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
10208 r->out.info, r->in.level);
10209 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
10211 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
10213 err_info_free:
10214 TALLOC_FREE(r->out.info);
10215 return result;
10218 /*******************************************************************
10219 ********************************************************************/
10221 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
10222 const char *dllname)
10224 enum ndr_err_code ndr_err;
10225 struct spoolss_MonitorUi ui;
10227 ui.dll_name = dllname;
10229 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
10230 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
10231 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10232 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
10234 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10237 /*******************************************************************
10238 Streams the monitor UI DLL name in UNICODE
10239 *******************************************************************/
10241 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
10242 struct security_token *token, DATA_BLOB *in,
10243 DATA_BLOB *out, uint32_t *needed)
10245 const char *dllname = "tcpmonui.dll";
10247 *needed = (strlen(dllname)+1) * 2;
10249 if (out->length < *needed) {
10250 return WERR_INSUFFICIENT_BUFFER;
10253 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
10254 return WERR_NOMEM;
10257 return WERR_OK;
10260 /*******************************************************************
10261 ********************************************************************/
10263 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
10264 struct spoolss_PortData1 *port1,
10265 const DATA_BLOB *buf)
10267 enum ndr_err_code ndr_err;
10268 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
10269 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
10270 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10271 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
10273 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10276 /*******************************************************************
10277 ********************************************************************/
10279 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
10280 struct spoolss_PortData2 *port2,
10281 const DATA_BLOB *buf)
10283 enum ndr_err_code ndr_err;
10284 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
10285 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
10286 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10287 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
10289 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10292 /*******************************************************************
10293 Create a new TCP/IP port
10294 *******************************************************************/
10296 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
10297 struct security_token *token, DATA_BLOB *in,
10298 DATA_BLOB *out, uint32_t *needed)
10300 struct spoolss_PortData1 port1;
10301 struct spoolss_PortData2 port2;
10302 char *device_uri = NULL;
10303 uint32_t version;
10305 const char *portname;
10306 const char *hostaddress;
10307 const char *queue;
10308 uint32_t port_number;
10309 uint32_t protocol;
10311 /* peek for spoolss_PortData version */
10313 if (!in || (in->length < (128 + 4))) {
10314 return WERR_GENERAL_FAILURE;
10317 version = IVAL(in->data, 128);
10319 switch (version) {
10320 case 1:
10321 ZERO_STRUCT(port1);
10323 if (!pull_port_data_1(mem_ctx, &port1, in)) {
10324 return WERR_NOMEM;
10327 portname = port1.portname;
10328 hostaddress = port1.hostaddress;
10329 queue = port1.queue;
10330 protocol = port1.protocol;
10331 port_number = port1.port_number;
10333 break;
10334 case 2:
10335 ZERO_STRUCT(port2);
10337 if (!pull_port_data_2(mem_ctx, &port2, in)) {
10338 return WERR_NOMEM;
10341 portname = port2.portname;
10342 hostaddress = port2.hostaddress;
10343 queue = port2.queue;
10344 protocol = port2.protocol;
10345 port_number = port2.port_number;
10347 break;
10348 default:
10349 DEBUG(1,("xcvtcp_addport: "
10350 "unknown version of port_data: %d\n", version));
10351 return WERR_UNKNOWN_PORT;
10354 /* create the device URI and call the add_port_hook() */
10356 switch (protocol) {
10357 case PROTOCOL_RAWTCP_TYPE:
10358 device_uri = talloc_asprintf(mem_ctx,
10359 "socket://%s:%d/", hostaddress,
10360 port_number);
10361 break;
10363 case PROTOCOL_LPR_TYPE:
10364 device_uri = talloc_asprintf(mem_ctx,
10365 "lpr://%s/%s", hostaddress, queue );
10366 break;
10368 default:
10369 return WERR_UNKNOWN_PORT;
10372 if (!device_uri) {
10373 return WERR_NOMEM;
10376 return add_port_hook(mem_ctx, token, portname, device_uri);
10379 /*******************************************************************
10380 *******************************************************************/
10382 struct xcv_api_table xcvtcp_cmds[] = {
10383 { "MonitorUI", xcvtcp_monitorui },
10384 { "AddPort", xcvtcp_addport},
10385 { NULL, NULL }
10388 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
10389 struct security_token *token, const char *command,
10390 DATA_BLOB *inbuf,
10391 DATA_BLOB *outbuf,
10392 uint32_t *needed )
10394 int i;
10396 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
10398 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
10399 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
10400 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
10403 return WERR_BADFUNC;
10406 /*******************************************************************
10407 *******************************************************************/
10408 #if 0 /* don't support management using the "Local Port" monitor */
10410 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
10411 struct security_token *token, DATA_BLOB *in,
10412 DATA_BLOB *out, uint32_t *needed)
10414 const char *dllname = "localui.dll";
10416 *needed = (strlen(dllname)+1) * 2;
10418 if (out->length < *needed) {
10419 return WERR_INSUFFICIENT_BUFFER;
10422 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
10423 return WERR_NOMEM;
10426 return WERR_OK;
10429 /*******************************************************************
10430 *******************************************************************/
10432 struct xcv_api_table xcvlocal_cmds[] = {
10433 { "MonitorUI", xcvlocal_monitorui },
10434 { NULL, NULL }
10436 #else
10437 struct xcv_api_table xcvlocal_cmds[] = {
10438 { NULL, NULL }
10440 #endif
10444 /*******************************************************************
10445 *******************************************************************/
10447 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
10448 struct security_token *token, const char *command,
10449 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
10450 uint32_t *needed)
10452 int i;
10454 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
10456 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
10457 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
10458 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
10460 return WERR_BADFUNC;
10463 /****************************************************************
10464 _spoolss_XcvData
10465 ****************************************************************/
10467 WERROR _spoolss_XcvData(struct pipes_struct *p,
10468 struct spoolss_XcvData *r)
10470 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
10471 DATA_BLOB out_data = data_blob_null;
10472 WERROR werror;
10474 if (!Printer) {
10475 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
10476 OUR_HANDLE(r->in.handle)));
10477 return WERR_BADFID;
10480 /* Has to be a handle to the TCP/IP port monitor */
10482 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
10483 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
10484 return WERR_BADFID;
10487 /* requires administrative access to the server */
10489 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
10490 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
10491 return WERR_ACCESS_DENIED;
10494 /* Allocate the outgoing buffer */
10496 if (r->in.out_data_size) {
10497 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
10498 if (out_data.data == NULL) {
10499 return WERR_NOMEM;
10503 switch ( Printer->printer_type ) {
10504 case SPLHND_PORTMON_TCP:
10505 werror = process_xcvtcp_command(p->mem_ctx,
10506 p->session_info->security_token,
10507 r->in.function_name,
10508 &r->in.in_data, &out_data,
10509 r->out.needed);
10510 break;
10511 case SPLHND_PORTMON_LOCAL:
10512 werror = process_xcvlocal_command(p->mem_ctx,
10513 p->session_info->security_token,
10514 r->in.function_name,
10515 &r->in.in_data, &out_data,
10516 r->out.needed);
10517 break;
10518 default:
10519 werror = WERR_INVALID_PRINT_MONITOR;
10522 if (!W_ERROR_IS_OK(werror)) {
10523 return werror;
10526 *r->out.status_code = 0;
10528 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
10529 memcpy(r->out.out_data, out_data.data,
10530 MIN(r->in.out_data_size, out_data.length));
10533 return WERR_OK;
10536 /****************************************************************
10537 _spoolss_AddPrintProcessor
10538 ****************************************************************/
10540 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
10541 struct spoolss_AddPrintProcessor *r)
10543 /* for now, just indicate success and ignore the add. We'll
10544 automatically set the winprint processor for printer
10545 entries later. Used to debug the LexMark Optra S 1855 PCL
10546 driver --jerry */
10548 return WERR_OK;
10551 /****************************************************************
10552 _spoolss_AddPort
10553 ****************************************************************/
10555 WERROR _spoolss_AddPort(struct pipes_struct *p,
10556 struct spoolss_AddPort *r)
10558 /* do what w2k3 does */
10560 return WERR_NOT_SUPPORTED;
10563 /****************************************************************
10564 _spoolss_GetPrinterDriver
10565 ****************************************************************/
10567 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
10568 struct spoolss_GetPrinterDriver *r)
10570 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10571 return WERR_NOT_SUPPORTED;
10574 /****************************************************************
10575 _spoolss_ReadPrinter
10576 ****************************************************************/
10578 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
10579 struct spoolss_ReadPrinter *r)
10581 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10582 return WERR_NOT_SUPPORTED;
10585 /****************************************************************
10586 _spoolss_WaitForPrinterChange
10587 ****************************************************************/
10589 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
10590 struct spoolss_WaitForPrinterChange *r)
10592 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10593 return WERR_NOT_SUPPORTED;
10596 /****************************************************************
10597 _spoolss_ConfigurePort
10598 ****************************************************************/
10600 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
10601 struct spoolss_ConfigurePort *r)
10603 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10604 return WERR_NOT_SUPPORTED;
10607 /****************************************************************
10608 _spoolss_DeletePort
10609 ****************************************************************/
10611 WERROR _spoolss_DeletePort(struct pipes_struct *p,
10612 struct spoolss_DeletePort *r)
10614 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10615 return WERR_NOT_SUPPORTED;
10618 /****************************************************************
10619 _spoolss_CreatePrinterIC
10620 ****************************************************************/
10622 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
10623 struct spoolss_CreatePrinterIC *r)
10625 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10626 return WERR_NOT_SUPPORTED;
10629 /****************************************************************
10630 _spoolss_PlayGDIScriptOnPrinterIC
10631 ****************************************************************/
10633 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
10634 struct spoolss_PlayGDIScriptOnPrinterIC *r)
10636 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10637 return WERR_NOT_SUPPORTED;
10640 /****************************************************************
10641 _spoolss_DeletePrinterIC
10642 ****************************************************************/
10644 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
10645 struct spoolss_DeletePrinterIC *r)
10647 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10648 return WERR_NOT_SUPPORTED;
10651 /****************************************************************
10652 _spoolss_AddPrinterConnection
10653 ****************************************************************/
10655 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
10656 struct spoolss_AddPrinterConnection *r)
10658 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10659 return WERR_NOT_SUPPORTED;
10662 /****************************************************************
10663 _spoolss_DeletePrinterConnection
10664 ****************************************************************/
10666 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
10667 struct spoolss_DeletePrinterConnection *r)
10669 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10670 return WERR_NOT_SUPPORTED;
10673 /****************************************************************
10674 _spoolss_PrinterMessageBox
10675 ****************************************************************/
10677 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
10678 struct spoolss_PrinterMessageBox *r)
10680 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10681 return WERR_NOT_SUPPORTED;
10684 /****************************************************************
10685 _spoolss_AddMonitor
10686 ****************************************************************/
10688 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
10689 struct spoolss_AddMonitor *r)
10691 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10692 return WERR_NOT_SUPPORTED;
10695 /****************************************************************
10696 _spoolss_DeleteMonitor
10697 ****************************************************************/
10699 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
10700 struct spoolss_DeleteMonitor *r)
10702 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10703 return WERR_NOT_SUPPORTED;
10706 /****************************************************************
10707 _spoolss_DeletePrintProcessor
10708 ****************************************************************/
10710 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
10711 struct spoolss_DeletePrintProcessor *r)
10713 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10714 return WERR_NOT_SUPPORTED;
10717 /****************************************************************
10718 _spoolss_AddPrintProvidor
10719 ****************************************************************/
10721 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
10722 struct spoolss_AddPrintProvidor *r)
10724 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10725 return WERR_NOT_SUPPORTED;
10728 /****************************************************************
10729 _spoolss_DeletePrintProvidor
10730 ****************************************************************/
10732 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
10733 struct spoolss_DeletePrintProvidor *r)
10735 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10736 return WERR_NOT_SUPPORTED;
10739 /****************************************************************
10740 _spoolss_FindFirstPrinterChangeNotification
10741 ****************************************************************/
10743 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
10744 struct spoolss_FindFirstPrinterChangeNotification *r)
10746 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10747 return WERR_NOT_SUPPORTED;
10750 /****************************************************************
10751 _spoolss_FindNextPrinterChangeNotification
10752 ****************************************************************/
10754 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
10755 struct spoolss_FindNextPrinterChangeNotification *r)
10757 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10758 return WERR_NOT_SUPPORTED;
10761 /****************************************************************
10762 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10763 ****************************************************************/
10765 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
10766 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10768 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10769 return WERR_NOT_SUPPORTED;
10772 /****************************************************************
10773 _spoolss_ReplyOpenPrinter
10774 ****************************************************************/
10776 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
10777 struct spoolss_ReplyOpenPrinter *r)
10779 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10780 return WERR_NOT_SUPPORTED;
10783 /****************************************************************
10784 _spoolss_RouterReplyPrinter
10785 ****************************************************************/
10787 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
10788 struct spoolss_RouterReplyPrinter *r)
10790 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10791 return WERR_NOT_SUPPORTED;
10794 /****************************************************************
10795 _spoolss_ReplyClosePrinter
10796 ****************************************************************/
10798 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
10799 struct spoolss_ReplyClosePrinter *r)
10801 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10802 return WERR_NOT_SUPPORTED;
10805 /****************************************************************
10806 _spoolss_AddPortEx
10807 ****************************************************************/
10809 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
10810 struct spoolss_AddPortEx *r)
10812 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10813 return WERR_NOT_SUPPORTED;
10816 /****************************************************************
10817 _spoolss_RouterFindFirstPrinterChangeNotification
10818 ****************************************************************/
10820 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
10821 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10823 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10824 return WERR_NOT_SUPPORTED;
10827 /****************************************************************
10828 _spoolss_SpoolerInit
10829 ****************************************************************/
10831 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
10832 struct spoolss_SpoolerInit *r)
10834 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10835 return WERR_NOT_SUPPORTED;
10838 /****************************************************************
10839 _spoolss_ResetPrinterEx
10840 ****************************************************************/
10842 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
10843 struct spoolss_ResetPrinterEx *r)
10845 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10846 return WERR_NOT_SUPPORTED;
10849 /****************************************************************
10850 _spoolss_RouterReplyPrinterEx
10851 ****************************************************************/
10853 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
10854 struct spoolss_RouterReplyPrinterEx *r)
10856 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10857 return WERR_NOT_SUPPORTED;
10860 /****************************************************************
10861 _spoolss_44
10862 ****************************************************************/
10864 WERROR _spoolss_44(struct pipes_struct *p,
10865 struct spoolss_44 *r)
10867 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10868 return WERR_NOT_SUPPORTED;
10871 /****************************************************************
10872 _spoolss_SetPort
10873 ****************************************************************/
10875 WERROR _spoolss_SetPort(struct pipes_struct *p,
10876 struct spoolss_SetPort *r)
10878 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10879 return WERR_NOT_SUPPORTED;
10882 /****************************************************************
10883 _spoolss_4a
10884 ****************************************************************/
10886 WERROR _spoolss_4a(struct pipes_struct *p,
10887 struct spoolss_4a *r)
10889 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10890 return WERR_NOT_SUPPORTED;
10893 /****************************************************************
10894 _spoolss_4b
10895 ****************************************************************/
10897 WERROR _spoolss_4b(struct pipes_struct *p,
10898 struct spoolss_4b *r)
10900 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10901 return WERR_NOT_SUPPORTED;
10904 /****************************************************************
10905 _spoolss_4c
10906 ****************************************************************/
10908 WERROR _spoolss_4c(struct pipes_struct *p,
10909 struct spoolss_4c *r)
10911 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10912 return WERR_NOT_SUPPORTED;
10915 /****************************************************************
10916 _spoolss_53
10917 ****************************************************************/
10919 WERROR _spoolss_53(struct pipes_struct *p,
10920 struct spoolss_53 *r)
10922 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10923 return WERR_NOT_SUPPORTED;
10926 /****************************************************************
10927 _spoolss_AddPerMachineConnection
10928 ****************************************************************/
10930 WERROR _spoolss_AddPerMachineConnection(struct pipes_struct *p,
10931 struct spoolss_AddPerMachineConnection *r)
10933 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10934 return WERR_NOT_SUPPORTED;
10937 /****************************************************************
10938 _spoolss_DeletePerMachineConnection
10939 ****************************************************************/
10941 WERROR _spoolss_DeletePerMachineConnection(struct pipes_struct *p,
10942 struct spoolss_DeletePerMachineConnection *r)
10944 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10945 return WERR_NOT_SUPPORTED;
10948 /****************************************************************
10949 _spoolss_EnumPerMachineConnections
10950 ****************************************************************/
10952 WERROR _spoolss_EnumPerMachineConnections(struct pipes_struct *p,
10953 struct spoolss_EnumPerMachineConnections *r)
10955 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10956 return WERR_NOT_SUPPORTED;
10959 /****************************************************************
10960 _spoolss_5a
10961 ****************************************************************/
10963 WERROR _spoolss_5a(struct pipes_struct *p,
10964 struct spoolss_5a *r)
10966 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10967 return WERR_NOT_SUPPORTED;
10970 /****************************************************************
10971 _spoolss_5b
10972 ****************************************************************/
10974 WERROR _spoolss_5b(struct pipes_struct *p,
10975 struct spoolss_5b *r)
10977 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10978 return WERR_NOT_SUPPORTED;
10981 /****************************************************************
10982 _spoolss_5c
10983 ****************************************************************/
10985 WERROR _spoolss_5c(struct pipes_struct *p,
10986 struct spoolss_5c *r)
10988 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10989 return WERR_NOT_SUPPORTED;
10992 /****************************************************************
10993 _spoolss_5d
10994 ****************************************************************/
10996 WERROR _spoolss_5d(struct pipes_struct *p,
10997 struct spoolss_5d *r)
10999 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11000 return WERR_NOT_SUPPORTED;
11003 /****************************************************************
11004 _spoolss_5e
11005 ****************************************************************/
11007 WERROR _spoolss_5e(struct pipes_struct *p,
11008 struct spoolss_5e *r)
11010 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11011 return WERR_NOT_SUPPORTED;
11014 /****************************************************************
11015 _spoolss_5f
11016 ****************************************************************/
11018 WERROR _spoolss_5f(struct pipes_struct *p,
11019 struct spoolss_5f *r)
11021 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11022 return WERR_NOT_SUPPORTED;
11025 /****************************************************************
11026 _spoolss_60
11027 ****************************************************************/
11029 WERROR _spoolss_60(struct pipes_struct *p,
11030 struct spoolss_60 *r)
11032 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11033 return WERR_NOT_SUPPORTED;
11036 /****************************************************************
11037 _spoolss_RpcSendRecvBidiData
11038 ****************************************************************/
11040 WERROR _spoolss_RpcSendRecvBidiData(struct pipes_struct *p,
11041 struct spoolss_RpcSendRecvBidiData *r)
11043 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11044 return WERR_NOT_SUPPORTED;
11047 /****************************************************************
11048 _spoolss_62
11049 ****************************************************************/
11051 WERROR _spoolss_62(struct pipes_struct *p,
11052 struct spoolss_62 *r)
11054 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11055 return WERR_NOT_SUPPORTED;
11058 /****************************************************************
11059 _spoolss_63
11060 ****************************************************************/
11062 WERROR _spoolss_63(struct pipes_struct *p,
11063 struct spoolss_63 *r)
11065 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11066 return WERR_NOT_SUPPORTED;
11069 /****************************************************************
11070 _spoolss_64
11071 ****************************************************************/
11073 WERROR _spoolss_64(struct pipes_struct *p,
11074 struct spoolss_64 *r)
11076 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11077 return WERR_NOT_SUPPORTED;
11080 /****************************************************************
11081 _spoolss_65
11082 ****************************************************************/
11084 WERROR _spoolss_65(struct pipes_struct *p,
11085 struct spoolss_65 *r)
11087 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11088 return WERR_NOT_SUPPORTED;
11091 /****************************************************************
11092 _spoolss_GetCorePrinterDrivers
11093 ****************************************************************/
11095 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
11096 struct spoolss_GetCorePrinterDrivers *r)
11098 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11099 return WERR_NOT_SUPPORTED;
11102 /****************************************************************
11103 _spoolss_67
11104 ****************************************************************/
11106 WERROR _spoolss_67(struct pipes_struct *p,
11107 struct spoolss_67 *r)
11109 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11110 return WERR_NOT_SUPPORTED;
11113 /****************************************************************
11114 _spoolss_GetPrinterDriverPackagePath
11115 ****************************************************************/
11117 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
11118 struct spoolss_GetPrinterDriverPackagePath *r)
11120 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11121 return WERR_NOT_SUPPORTED;
11124 /****************************************************************
11125 _spoolss_69
11126 ****************************************************************/
11128 WERROR _spoolss_69(struct pipes_struct *p,
11129 struct spoolss_69 *r)
11131 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11132 return WERR_NOT_SUPPORTED;
11135 /****************************************************************
11136 _spoolss_6a
11137 ****************************************************************/
11139 WERROR _spoolss_6a(struct pipes_struct *p,
11140 struct spoolss_6a *r)
11142 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11143 return WERR_NOT_SUPPORTED;
11146 /****************************************************************
11147 _spoolss_6b
11148 ****************************************************************/
11150 WERROR _spoolss_6b(struct pipes_struct *p,
11151 struct spoolss_6b *r)
11153 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11154 return WERR_NOT_SUPPORTED;
11157 /****************************************************************
11158 _spoolss_6c
11159 ****************************************************************/
11161 WERROR _spoolss_6c(struct pipes_struct *p,
11162 struct spoolss_6c *r)
11164 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11165 return WERR_NOT_SUPPORTED;
11168 /****************************************************************
11169 _spoolss_6d
11170 ****************************************************************/
11172 WERROR _spoolss_6d(struct pipes_struct *p,
11173 struct spoolss_6d *r)
11175 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11176 return WERR_NOT_SUPPORTED;
11179 /****************************************************************
11180 _spoolss_RpcGetJobNamedPropertyValue
11181 ****************************************************************/
11183 WERROR _spoolss_RpcGetJobNamedPropertyValue(struct pipes_struct *p,
11184 struct spoolss_RpcGetJobNamedPropertyValue *r)
11186 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11187 return WERR_NOT_SUPPORTED;
11190 /****************************************************************
11191 _spoolss_RpcSetJobNamedProperty
11192 ****************************************************************/
11194 WERROR _spoolss_RpcSetJobNamedProperty(struct pipes_struct *p,
11195 struct spoolss_RpcSetJobNamedProperty *r)
11197 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11198 return WERR_NOT_SUPPORTED;
11201 /****************************************************************
11202 _spoolss_RpcDeleteJobNamedProperty
11203 ****************************************************************/
11205 WERROR _spoolss_RpcDeleteJobNamedProperty(struct pipes_struct *p,
11206 struct spoolss_RpcDeleteJobNamedProperty *r)
11208 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11209 return WERR_NOT_SUPPORTED;
11212 /****************************************************************
11213 _spoolss_RpcEnumJobNamedProperties
11214 ****************************************************************/
11216 WERROR _spoolss_RpcEnumJobNamedProperties(struct pipes_struct *p,
11217 struct spoolss_RpcEnumJobNamedProperties *r)
11219 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11220 return WERR_NOT_SUPPORTED;