Raise the level of a debug.
[Samba.git] / source3 / rpc_server / spoolss / srv_spoolss_nt.c
blob4814e04b79bde37f3db34dd0832169911db6b31b
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 uint32_t active_connections;
144 static struct notify_back_channel *back_channels;
146 /* Map generic permissions to printer object specific permissions */
148 const struct standard_mapping printer_std_mapping = {
149 PRINTER_READ,
150 PRINTER_WRITE,
151 PRINTER_EXECUTE,
152 PRINTER_ALL_ACCESS
155 /* Map generic permissions to print server object specific permissions */
157 const struct standard_mapping printserver_std_mapping = {
158 SERVER_READ,
159 SERVER_WRITE,
160 SERVER_EXECUTE,
161 SERVER_ALL_ACCESS
164 /* API table for Xcv Monitor functions */
166 struct xcv_api_table {
167 const char *name;
168 WERROR(*fn) (TALLOC_CTX *mem_ctx, struct security_token *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
171 static void prune_printername_cache(void);
173 /********************************************************************
174 * Canonicalize servername.
175 ********************************************************************/
177 static const char *canon_servername(const char *servername)
179 const char *pservername = servername;
180 while (*pservername == '\\') {
181 pservername++;
183 return pservername;
186 /* translate between internal status numbers and NT status numbers */
187 static int nt_printj_status(int v)
189 switch (v) {
190 case LPQ_QUEUED:
191 return 0;
192 case LPQ_PAUSED:
193 return JOB_STATUS_PAUSED;
194 case LPQ_SPOOLING:
195 return JOB_STATUS_SPOOLING;
196 case LPQ_PRINTING:
197 return JOB_STATUS_PRINTING;
198 case LPQ_ERROR:
199 return JOB_STATUS_ERROR;
200 case LPQ_DELETING:
201 return JOB_STATUS_DELETING;
202 case LPQ_OFFLINE:
203 return JOB_STATUS_OFFLINE;
204 case LPQ_PAPEROUT:
205 return JOB_STATUS_PAPEROUT;
206 case LPQ_PRINTED:
207 return JOB_STATUS_PRINTED;
208 case LPQ_DELETED:
209 return JOB_STATUS_DELETED;
210 case LPQ_BLOCKED:
211 return JOB_STATUS_BLOCKED_DEVQ;
212 case LPQ_USER_INTERVENTION:
213 return JOB_STATUS_USER_INTERVENTION;
215 return 0;
218 static int nt_printq_status(int v)
220 switch (v) {
221 case LPQ_PAUSED:
222 return PRINTER_STATUS_PAUSED;
223 case LPQ_QUEUED:
224 case LPQ_SPOOLING:
225 case LPQ_PRINTING:
226 return 0;
228 return 0;
231 /***************************************************************************
232 Disconnect from the client
233 ****************************************************************************/
235 static void srv_spoolss_replycloseprinter(int snum,
236 struct printer_handle *prn_hnd)
238 WERROR result;
239 NTSTATUS status;
242 * Tell the specific printing tdb we no longer want messages for this printer
243 * by deregistering our PID.
246 if (!print_notify_deregister_pid(snum)) {
247 DEBUG(0, ("Failed to register our pid for printer %s\n",
248 lp_const_servicename(snum)));
251 /* weird if the test succeeds !!! */
252 if (prn_hnd->notify.cli_chan == NULL ||
253 prn_hnd->notify.cli_chan->cli_pipe == NULL ||
254 prn_hnd->notify.cli_chan->cli_pipe->binding_handle == NULL ||
255 prn_hnd->notify.cli_chan->active_connections == 0) {
256 DEBUG(0, ("Trying to close unexisting backchannel!\n"));
257 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
258 TALLOC_FREE(prn_hnd->notify.cli_chan);
259 return;
262 status = dcerpc_spoolss_ReplyClosePrinter(
263 prn_hnd->notify.cli_chan->cli_pipe->binding_handle,
264 talloc_tos(),
265 &prn_hnd->notify.cli_hnd,
266 &result);
267 if (!NT_STATUS_IS_OK(status)) {
268 DEBUG(0, ("dcerpc_spoolss_ReplyClosePrinter failed [%s].\n",
269 nt_errstr(status)));
270 result = ntstatus_to_werror(status);
271 } else if (!W_ERROR_IS_OK(result)) {
272 DEBUG(0, ("reply_close_printer failed [%s].\n",
273 win_errstr(result)));
276 /* if it's the last connection, deconnect the IPC$ share */
277 if (prn_hnd->notify.cli_chan->active_connections == 1) {
279 cli_shutdown(rpc_pipe_np_smb_conn(prn_hnd->notify.cli_chan->cli_pipe));
280 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
281 TALLOC_FREE(prn_hnd->notify.cli_chan);
283 if (prn_hnd->notify.msg_ctx != NULL) {
284 messaging_deregister(prn_hnd->notify.msg_ctx,
285 MSG_PRINTER_NOTIFY2, NULL);
289 if (prn_hnd->notify.cli_chan) {
290 prn_hnd->notify.cli_chan->active_connections--;
291 prn_hnd->notify.cli_chan = NULL;
295 /****************************************************************************
296 Functions to free a printer entry datastruct.
297 ****************************************************************************/
299 static int printer_entry_destructor(struct printer_handle *Printer)
301 if (Printer->notify.cli_chan != NULL &&
302 Printer->notify.cli_chan->active_connections > 0) {
303 int snum = -1;
305 switch(Printer->printer_type) {
306 case SPLHND_SERVER:
307 srv_spoolss_replycloseprinter(snum, Printer);
308 break;
310 case SPLHND_PRINTER:
311 snum = print_queue_snum(Printer->sharename);
312 if (snum != -1) {
313 srv_spoolss_replycloseprinter(snum, Printer);
315 break;
316 default:
317 break;
321 Printer->notify.flags=0;
322 Printer->notify.options=0;
323 Printer->notify.localmachine[0]='\0';
324 Printer->notify.printerlocal=0;
325 TALLOC_FREE(Printer->notify.option);
326 TALLOC_FREE(Printer->devmode);
328 /* Remove from the internal list. */
329 DLIST_REMOVE(printers_list, Printer);
330 return 0;
333 /****************************************************************************
334 find printer index by handle
335 ****************************************************************************/
337 static struct printer_handle *find_printer_index_by_hnd(struct pipes_struct *p,
338 struct policy_handle *hnd)
340 struct printer_handle *find_printer = NULL;
342 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
343 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
344 return NULL;
347 return find_printer;
350 /****************************************************************************
351 Close printer index by handle.
352 ****************************************************************************/
354 static bool close_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
356 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
358 if (!Printer) {
359 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
360 OUR_HANDLE(hnd)));
361 return false;
364 close_policy_hnd(p, hnd);
366 return true;
369 /****************************************************************************
370 Delete a printer given a handle.
371 ****************************************************************************/
373 static WERROR delete_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
374 const char *sharename,
375 struct messaging_context *msg_ctx)
377 char *cmd = lp_deleteprinter_cmd(talloc_tos());
378 char *command = NULL;
379 int ret;
380 bool is_print_op = false;
382 /* can't fail if we don't try */
384 if ( !*cmd )
385 return WERR_OK;
387 command = talloc_asprintf(ctx,
388 "%s \"%s\"",
389 cmd, sharename);
390 if (!command) {
391 return WERR_NOMEM;
393 if ( token )
394 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
396 DEBUG(10,("Running [%s]\n", command));
398 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
400 if ( is_print_op )
401 become_root();
403 if ( (ret = smbrun(command, NULL)) == 0 ) {
404 /* Tell everyone we updated smb.conf. */
405 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
408 if ( is_print_op )
409 unbecome_root();
411 /********** END SePrintOperatorPrivlege BLOCK **********/
413 DEBUGADD(10,("returned [%d]\n", ret));
415 TALLOC_FREE(command);
417 if (ret != 0)
418 return WERR_BADFID; /* What to return here? */
420 return WERR_OK;
423 /****************************************************************************
424 Delete a printer given a handle.
425 ****************************************************************************/
427 static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
429 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
430 WERROR result;
432 if (!Printer) {
433 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
434 OUR_HANDLE(hnd)));
435 return WERR_BADFID;
439 * It turns out that Windows allows delete printer on a handle
440 * opened by an admin user, then used on a pipe handle created
441 * by an anonymous user..... but they're working on security.... riiight !
442 * JRA.
445 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
446 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
447 return WERR_ACCESS_DENIED;
450 /* this does not need a become root since the access check has been
451 done on the handle already */
453 result = winreg_delete_printer_key_internal(p->mem_ctx,
454 get_session_info_system(),
455 p->msg_ctx,
456 Printer->sharename,
457 "");
458 if (!W_ERROR_IS_OK(result)) {
459 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
460 return WERR_BADFID;
463 result = delete_printer_hook(p->mem_ctx, p->session_info->security_token,
464 Printer->sharename, p->msg_ctx);
465 if (!W_ERROR_IS_OK(result)) {
466 return result;
468 prune_printername_cache();
469 return WERR_OK;
472 /****************************************************************************
473 Return the snum of a printer corresponding to an handle.
474 ****************************************************************************/
476 static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
477 int *number, struct share_params **params)
479 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
481 if (!Printer) {
482 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
483 OUR_HANDLE(hnd)));
484 return false;
487 switch (Printer->printer_type) {
488 case SPLHND_PRINTER:
489 DEBUG(4,("short name:%s\n", Printer->sharename));
490 *number = print_queue_snum(Printer->sharename);
491 return (*number != -1);
492 case SPLHND_SERVER:
493 return false;
494 default:
495 return false;
499 /****************************************************************************
500 Set printer handle type.
501 Check if it's \\server or \\server\printer
502 ****************************************************************************/
504 static bool set_printer_hnd_printertype(struct printer_handle *Printer, const char *handlename)
506 DEBUG(3,("Setting printer type=%s\n", handlename));
508 /* it's a print server */
509 if (handlename && *handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
510 DEBUGADD(4,("Printer is a print server\n"));
511 Printer->printer_type = SPLHND_SERVER;
513 /* it's a printer (set_printer_hnd_name() will handle port monitors */
514 else {
515 DEBUGADD(4,("Printer is a printer\n"));
516 Printer->printer_type = SPLHND_PRINTER;
519 return true;
522 static void prune_printername_cache_fn(const char *key, const char *value,
523 time_t timeout, void *private_data)
525 gencache_del(key);
528 static void prune_printername_cache(void)
530 gencache_iterate(prune_printername_cache_fn, NULL, "PRINTERNAME/*");
533 /****************************************************************************
534 Set printer handle name.. Accept names like \\server, \\server\printer,
535 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
536 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
537 XcvDataPort() interface.
538 ****************************************************************************/
540 static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
541 const struct auth_session_info *session_info,
542 struct messaging_context *msg_ctx,
543 struct printer_handle *Printer,
544 const char *handlename)
546 int snum;
547 int n_services=lp_numservices();
548 char *aprinter;
549 const char *printername;
550 const char *servername = NULL;
551 fstring sname;
552 bool found = false;
553 struct spoolss_PrinterInfo2 *info2 = NULL;
554 WERROR result;
555 char *p;
558 * Hopefully nobody names his printers like this. Maybe \ or ,
559 * are illegal in printer names even?
561 const char printer_not_found[] = "Printer \\, !@#$%^&*( not found";
562 char *cache_key;
563 char *tmp;
565 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
566 (unsigned long)strlen(handlename)));
568 aprinter = discard_const_p(char, handlename);
569 if ( *handlename == '\\' ) {
570 servername = canon_servername(handlename);
571 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
572 *aprinter = '\0';
573 aprinter++;
575 if (!is_myname_or_ipaddr(servername)) {
576 return WERR_INVALID_PRINTER_NAME;
578 Printer->servername = talloc_asprintf(Printer, "\\\\%s", servername);
579 if (Printer->servername == NULL) {
580 return WERR_NOMEM;
584 if (Printer->printer_type == SPLHND_SERVER) {
585 return WERR_OK;
588 if (Printer->printer_type != SPLHND_PRINTER) {
589 return WERR_INVALID_HANDLE;
592 DEBUGADD(5, ("searching for [%s]\n", aprinter));
594 p = strchr(aprinter, ',');
595 if (p != NULL) {
596 char *p2 = p;
597 p++;
598 if (*p == ' ') {
599 p++;
601 if (strncmp(p, "DrvConvert", strlen("DrvConvert")) == 0) {
602 *p2 = '\0';
603 } else if (strncmp(p, "LocalOnly", strlen("LocalOnly")) == 0) {
604 *p2 = '\0';
608 if (p) {
609 DEBUGADD(5, ("stripped handlename: [%s]\n", aprinter));
612 /* check for the Port Monitor Interface */
613 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
614 Printer->printer_type = SPLHND_PORTMON_TCP;
615 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
616 found = true;
618 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
619 Printer->printer_type = SPLHND_PORTMON_LOCAL;
620 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
621 found = true;
625 * With hundreds of printers, the "for" loop iterating all
626 * shares can be quite expensive, as it is done on every
627 * OpenPrinter. The loop maps "aprinter" to "sname", the
628 * result of which we cache in gencache.
631 cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
632 aprinter);
633 if ((cache_key != NULL) && gencache_get(cache_key, &tmp, NULL)) {
635 found = (strcmp(tmp, printer_not_found) != 0);
636 if (!found) {
637 DEBUG(4, ("Printer %s not found\n", aprinter));
638 SAFE_FREE(tmp);
639 return WERR_INVALID_PRINTER_NAME;
641 fstrcpy(sname, tmp);
642 SAFE_FREE(tmp);
645 /* Search all sharenames first as this is easier than pulling
646 the printer_info_2 off of disk. Don't use find_service() since
647 that calls out to map_username() */
649 /* do another loop to look for printernames */
650 for (snum = 0; !found && snum < n_services; snum++) {
651 const char *printer = lp_const_servicename(snum);
653 /* no point going on if this is not a printer */
654 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
655 continue;
658 /* ignore [printers] share */
659 if (strequal(printer, "printers")) {
660 continue;
663 fstrcpy(sname, printer);
664 if (strequal(aprinter, printer)) {
665 found = true;
666 break;
669 /* no point looking up the printer object if
670 we aren't allowing printername != sharename */
671 if (lp_force_printername(snum)) {
672 continue;
675 result = winreg_get_printer_internal(mem_ctx,
676 session_info,
677 msg_ctx,
678 sname,
679 &info2);
680 if ( !W_ERROR_IS_OK(result) ) {
681 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
682 sname, win_errstr(result)));
683 continue;
686 printername = strrchr(info2->printername, '\\');
687 if (printername == NULL) {
688 printername = info2->printername;
689 } else {
690 printername++;
693 if (strequal(printername, aprinter)) {
694 found = true;
695 break;
698 DEBUGADD(10, ("printername: %s\n", printername));
700 TALLOC_FREE(info2);
703 if ( !found ) {
704 if (cache_key != NULL) {
705 gencache_set(cache_key, printer_not_found,
706 time(NULL)+300);
707 TALLOC_FREE(cache_key);
709 DEBUGADD(4,("Printer not found\n"));
710 return WERR_INVALID_PRINTER_NAME;
713 if (cache_key != NULL) {
714 gencache_set(cache_key, sname, time(NULL)+300);
715 TALLOC_FREE(cache_key);
718 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
720 strlcpy(Printer->sharename, sname, sizeof(Printer->sharename));
722 return WERR_OK;
725 /****************************************************************************
726 Find first available printer slot. creates a printer handle for you.
727 ****************************************************************************/
729 static WERROR open_printer_hnd(struct pipes_struct *p,
730 struct policy_handle *hnd,
731 const char *name,
732 uint32_t access_granted)
734 struct printer_handle *new_printer;
735 WERROR result;
737 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
739 new_printer = talloc_zero(p->mem_ctx, struct printer_handle);
740 if (new_printer == NULL) {
741 return WERR_NOMEM;
743 talloc_set_destructor(new_printer, printer_entry_destructor);
745 /* This also steals the printer_handle on the policy_handle */
746 if (!create_policy_hnd(p, hnd, new_printer)) {
747 TALLOC_FREE(new_printer);
748 return WERR_INVALID_HANDLE;
751 /* Add to the internal list. */
752 DLIST_ADD(printers_list, new_printer);
754 new_printer->notify.option=NULL;
756 if (!set_printer_hnd_printertype(new_printer, name)) {
757 close_printer_handle(p, hnd);
758 return WERR_INVALID_HANDLE;
761 result = set_printer_hnd_name(p->mem_ctx,
762 get_session_info_system(),
763 p->msg_ctx,
764 new_printer, name);
765 if (!W_ERROR_IS_OK(result)) {
766 close_printer_handle(p, hnd);
767 return result;
770 new_printer->access_granted = access_granted;
772 DEBUG(5, ("%d printer handles active\n",
773 (int)num_pipe_handles(p)));
775 return WERR_OK;
778 /***************************************************************************
779 check to see if the client motify handle is monitoring the notification
780 given by (notify_type, notify_field).
781 **************************************************************************/
783 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
784 uint16_t notify_field)
786 return true;
789 static bool is_monitoring_event(struct printer_handle *p, uint16_t notify_type,
790 uint16_t notify_field)
792 struct spoolss_NotifyOption *option = p->notify.option;
793 uint32_t i, j;
796 * Flags should always be zero when the change notify
797 * is registered by the client's spooler. A user Win32 app
798 * might use the flags though instead of the NOTIFY_OPTION_INFO
799 * --jerry
802 if (!option) {
803 return false;
806 if (p->notify.flags)
807 return is_monitoring_event_flags(
808 p->notify.flags, notify_type, notify_field);
810 for (i = 0; i < option->count; i++) {
812 /* Check match for notify_type */
814 if (option->types[i].type != notify_type)
815 continue;
817 /* Check match for field */
819 for (j = 0; j < option->types[i].count; j++) {
820 if (option->types[i].fields[j].field == notify_field) {
821 return true;
826 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
827 p->servername, p->sharename, notify_type, notify_field));
829 return false;
832 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
833 _data->data.integer[0] = _integer; \
834 _data->data.integer[1] = 0;
837 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
838 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
839 if (!_data->data.string.string) {\
840 _data->data.string.size = 0; \
842 _data->data.string.size = strlen_m_term(_p) * 2;
844 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
845 _data->data.devmode.devmode = _devmode;
847 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
848 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
849 if (!_data->data.sd.sd) { \
850 _data->data.sd.sd_size = 0; \
852 _data->data.sd.sd_size = \
853 ndr_size_security_descriptor(_data->data.sd.sd, 0);
855 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
856 struct tm *t,
857 const char **pp,
858 uint32_t *plen)
860 struct spoolss_Time st;
861 uint32_t len = 16;
862 char *p;
864 if (!init_systemtime(&st, t)) {
865 return;
868 p = talloc_array(mem_ctx, char, len);
869 if (!p) {
870 return;
874 * Systemtime must be linearized as a set of UINT16's.
875 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
878 SSVAL(p, 0, st.year);
879 SSVAL(p, 2, st.month);
880 SSVAL(p, 4, st.day_of_week);
881 SSVAL(p, 6, st.day);
882 SSVAL(p, 8, st.hour);
883 SSVAL(p, 10, st.minute);
884 SSVAL(p, 12, st.second);
885 SSVAL(p, 14, st.millisecond);
887 *pp = p;
888 *plen = len;
891 /* Convert a notification message to a struct spoolss_Notify */
893 static void notify_one_value(struct spoolss_notify_msg *msg,
894 struct spoolss_Notify *data,
895 TALLOC_CTX *mem_ctx)
897 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
900 static void notify_string(struct spoolss_notify_msg *msg,
901 struct spoolss_Notify *data,
902 TALLOC_CTX *mem_ctx)
904 /* The length of the message includes the trailing \0 */
906 data->data.string.size = msg->len * 2;
907 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
908 if (!data->data.string.string) {
909 data->data.string.size = 0;
910 return;
914 static void notify_system_time(struct spoolss_notify_msg *msg,
915 struct spoolss_Notify *data,
916 TALLOC_CTX *mem_ctx)
918 data->data.string.string = NULL;
919 data->data.string.size = 0;
921 if (msg->len != sizeof(time_t)) {
922 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
923 msg->len));
924 return;
927 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
928 &data->data.string.string,
929 &data->data.string.size);
932 struct notify2_message_table {
933 const char *name;
934 void (*fn)(struct spoolss_notify_msg *msg,
935 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
938 static struct notify2_message_table printer_notify_table[] = {
939 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
940 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
941 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
942 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
943 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
944 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
945 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
946 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
947 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
948 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
949 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
950 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
951 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
952 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
953 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
954 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
955 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
956 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
957 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
960 static struct notify2_message_table job_notify_table[] = {
961 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
962 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
963 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
964 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
965 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
966 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
967 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
968 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
969 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
970 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
971 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
972 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
973 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
974 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
975 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
976 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
977 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
978 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
979 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
980 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
981 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
982 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
983 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
984 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
988 /***********************************************************************
989 Allocate talloc context for container object
990 **********************************************************************/
992 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
994 if ( !ctr )
995 return;
997 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
999 return;
1002 /***********************************************************************
1003 release all allocated memory and zero out structure
1004 **********************************************************************/
1006 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1008 if ( !ctr )
1009 return;
1011 if ( ctr->ctx )
1012 talloc_destroy(ctr->ctx);
1014 ZERO_STRUCTP(ctr);
1016 return;
1019 /***********************************************************************
1020 **********************************************************************/
1022 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1024 if ( !ctr )
1025 return NULL;
1027 return ctr->ctx;
1030 /***********************************************************************
1031 **********************************************************************/
1033 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1035 if ( !ctr || !ctr->msg_groups )
1036 return NULL;
1038 if ( idx >= ctr->num_groups )
1039 return NULL;
1041 return &ctr->msg_groups[idx];
1045 /***********************************************************************
1046 How many groups of change messages do we have ?
1047 **********************************************************************/
1049 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1051 if ( !ctr )
1052 return 0;
1054 return ctr->num_groups;
1057 /***********************************************************************
1058 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1059 **********************************************************************/
1061 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
1063 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
1064 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
1065 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
1066 int i, new_slot;
1068 if ( !ctr || !msg )
1069 return 0;
1071 /* loop over all groups looking for a matching printer name */
1073 for ( i=0; i<ctr->num_groups; i++ ) {
1074 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
1075 break;
1078 /* add a new group? */
1080 if ( i == ctr->num_groups ) {
1081 ctr->num_groups++;
1083 if ( !(groups = talloc_realloc( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
1084 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1085 return 0;
1087 ctr->msg_groups = groups;
1089 /* clear the new entry and set the printer name */
1091 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
1092 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
1095 /* add the change messages; 'i' is the correct index now regardless */
1097 msg_grp = &ctr->msg_groups[i];
1099 msg_grp->num_msgs++;
1101 if ( !(msg_list = talloc_realloc( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
1102 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
1103 return 0;
1105 msg_grp->msgs = msg_list;
1107 new_slot = msg_grp->num_msgs-1;
1108 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
1110 /* need to allocate own copy of data */
1112 if ( msg->len != 0 )
1113 msg_grp->msgs[new_slot].notify.data = (char *)
1114 talloc_memdup( ctr->ctx, msg->notify.data, msg->len );
1116 return ctr->num_groups;
1119 static void construct_info_data(struct spoolss_Notify *info_data,
1120 enum spoolss_NotifyType type,
1121 uint16_t field, int id);
1123 /***********************************************************************
1124 Send a change notication message on all handles which have a call
1125 back registered
1126 **********************************************************************/
1128 static int build_notify2_messages(TALLOC_CTX *mem_ctx,
1129 struct printer_handle *prn_hnd,
1130 SPOOLSS_NOTIFY_MSG *messages,
1131 uint32_t num_msgs,
1132 struct spoolss_Notify **_notifies,
1133 int *_count)
1135 struct spoolss_Notify *notifies;
1136 SPOOLSS_NOTIFY_MSG *msg;
1137 int count = 0;
1138 uint32_t id;
1139 int i;
1141 notifies = talloc_zero_array(mem_ctx,
1142 struct spoolss_Notify, num_msgs);
1143 if (!notifies) {
1144 return ENOMEM;
1147 for (i = 0; i < num_msgs; i++) {
1149 msg = &messages[i];
1151 /* Are we monitoring this event? */
1153 if (!is_monitoring_event(prn_hnd, msg->type, msg->field)) {
1154 continue;
1157 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1158 "for printer [%s]\n",
1159 msg->type, msg->field, prn_hnd->sharename));
1162 * if the is a printer notification handle and not a job
1163 * notification type, then set the id to 0.
1164 * Otherwise just use what was specified in the message.
1166 * When registering change notification on a print server
1167 * handle we always need to send back the id (snum) matching
1168 * the printer for which the change took place.
1169 * For change notify registered on a printer handle,
1170 * this does not matter and the id should be 0.
1172 * --jerry
1175 if ((msg->type == PRINTER_NOTIFY_TYPE) &&
1176 (prn_hnd->printer_type == SPLHND_PRINTER)) {
1177 id = 0;
1178 } else {
1179 id = msg->id;
1182 /* Convert unix jobid to smb jobid */
1184 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1185 id = sysjob_to_jobid(msg->id);
1187 if (id == -1) {
1188 DEBUG(3, ("no such unix jobid %d\n",
1189 msg->id));
1190 continue;
1194 construct_info_data(&notifies[count],
1195 msg->type, msg->field, id);
1197 switch(msg->type) {
1198 case PRINTER_NOTIFY_TYPE:
1199 if (printer_notify_table[msg->field].fn) {
1200 printer_notify_table[msg->field].fn(msg,
1201 &notifies[count], mem_ctx);
1203 break;
1205 case JOB_NOTIFY_TYPE:
1206 if (job_notify_table[msg->field].fn) {
1207 job_notify_table[msg->field].fn(msg,
1208 &notifies[count], mem_ctx);
1210 break;
1212 default:
1213 DEBUG(5, ("Unknown notification type %d\n",
1214 msg->type));
1215 continue;
1218 count++;
1221 *_notifies = notifies;
1222 *_count = count;
1224 return 0;
1227 static int send_notify2_printer(TALLOC_CTX *mem_ctx,
1228 struct printer_handle *prn_hnd,
1229 SPOOLSS_NOTIFY_MSG_GROUP *msg_group)
1231 struct spoolss_Notify *notifies;
1232 int count = 0;
1233 union spoolss_ReplyPrinterInfo info;
1234 struct spoolss_NotifyInfo info0;
1235 uint32_t reply_result;
1236 NTSTATUS status;
1237 WERROR werr;
1238 int ret;
1240 /* Is there notification on this handle? */
1241 if (prn_hnd->notify.cli_chan == NULL ||
1242 prn_hnd->notify.cli_chan->cli_pipe == NULL ||
1243 prn_hnd->notify.cli_chan->cli_pipe->binding_handle == NULL ||
1244 prn_hnd->notify.cli_chan->active_connections == 0) {
1245 return 0;
1248 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1249 prn_hnd->servername, prn_hnd->sharename));
1251 /* For this printer? Print servers always receive notifications. */
1252 if ((prn_hnd->printer_type == SPLHND_PRINTER) &&
1253 (!strequal(msg_group->printername, prn_hnd->sharename))) {
1254 return 0;
1257 DEBUG(10,("Our printer\n"));
1259 /* build the array of change notifications */
1260 ret = build_notify2_messages(mem_ctx, prn_hnd,
1261 msg_group->msgs,
1262 msg_group->num_msgs,
1263 &notifies, &count);
1264 if (ret) {
1265 return ret;
1268 info0.version = 0x2;
1269 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1270 info0.count = count;
1271 info0.notifies = notifies;
1273 info.info0 = &info0;
1275 status = dcerpc_spoolss_RouterReplyPrinterEx(
1276 prn_hnd->notify.cli_chan->cli_pipe->binding_handle,
1277 mem_ctx,
1278 &prn_hnd->notify.cli_hnd,
1279 prn_hnd->notify.change, /* color */
1280 prn_hnd->notify.flags,
1281 &reply_result,
1282 0, /* reply_type, must be 0 */
1283 info, &werr);
1284 if (!NT_STATUS_IS_OK(status)) {
1285 DEBUG(1, ("dcerpc_spoolss_RouterReplyPrinterEx to client: %s "
1286 "failed: %s\n",
1287 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1288 nt_errstr(status)));
1289 werr = ntstatus_to_werror(status);
1290 } else if (!W_ERROR_IS_OK(werr)) {
1291 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1292 "failed: %s\n",
1293 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1294 win_errstr(werr)));
1296 switch (reply_result) {
1297 case 0:
1298 break;
1299 case PRINTER_NOTIFY_INFO_DISCARDED:
1300 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1301 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1302 break;
1303 default:
1304 break;
1307 return 0;
1310 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1312 struct printer_handle *p;
1313 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
1314 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
1315 int ret;
1317 if ( !msg_group ) {
1318 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1319 return;
1322 if (!msg_group->msgs) {
1323 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1324 return;
1327 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
1329 /* loop over all printers */
1331 for (p = printers_list; p; p = p->next) {
1332 ret = send_notify2_printer(mem_ctx, p, msg_group);
1333 if (ret) {
1334 goto done;
1338 done:
1339 DEBUG(8,("send_notify2_changes: Exit...\n"));
1340 return;
1343 /***********************************************************************
1344 **********************************************************************/
1346 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1349 uint32_t tv_sec, tv_usec;
1350 size_t offset = 0;
1352 /* Unpack message */
1354 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1355 msg->printer);
1357 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1358 &tv_sec, &tv_usec,
1359 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1361 if (msg->len == 0)
1362 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1363 &msg->notify.value[0], &msg->notify.value[1]);
1364 else
1365 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1366 &msg->len, &msg->notify.data);
1368 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1369 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1371 tv->tv_sec = tv_sec;
1372 tv->tv_usec = tv_usec;
1374 if (msg->len == 0)
1375 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1376 msg->notify.value[1]));
1377 else
1378 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1380 return true;
1383 /********************************************************************
1384 Receive a notify2 message list
1385 ********************************************************************/
1387 static void receive_notify2_message_list(struct messaging_context *msg,
1388 void *private_data,
1389 uint32_t msg_type,
1390 struct server_id server_id,
1391 DATA_BLOB *data)
1393 size_t msg_count, i;
1394 char *buf = (char *)data->data;
1395 char *msg_ptr;
1396 size_t msg_len;
1397 SPOOLSS_NOTIFY_MSG notify;
1398 SPOOLSS_NOTIFY_MSG_CTR messages;
1399 int num_groups;
1401 if (data->length < 4) {
1402 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1403 return;
1406 msg_count = IVAL(buf, 0);
1407 msg_ptr = buf + 4;
1409 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1411 if (msg_count == 0) {
1412 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1413 return;
1416 /* initialize the container */
1418 ZERO_STRUCT( messages );
1419 notify_msg_ctr_init( &messages );
1422 * build message groups for each printer identified
1423 * in a change_notify msg. Remember that a PCN message
1424 * includes the handle returned for the srv_spoolss_replyopenprinter()
1425 * call. Therefore messages are grouped according to printer handle.
1428 for ( i=0; i<msg_count; i++ ) {
1429 struct timeval msg_tv;
1431 if (msg_ptr + 4 - buf > data->length) {
1432 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1433 return;
1436 msg_len = IVAL(msg_ptr,0);
1437 msg_ptr += 4;
1439 if (msg_ptr + msg_len - buf > data->length) {
1440 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1441 return;
1444 /* unpack messages */
1446 ZERO_STRUCT( notify );
1447 notify2_unpack_msg( &notify, &msg_tv, msg_ptr, msg_len );
1448 msg_ptr += msg_len;
1450 /* add to correct list in container */
1452 notify_msg_ctr_addmsg( &messages, &notify );
1454 /* free memory that might have been allocated by notify2_unpack_msg() */
1456 if ( notify.len != 0 )
1457 SAFE_FREE( notify.notify.data );
1460 /* process each group of messages */
1462 num_groups = notify_msg_ctr_numgroups( &messages );
1463 for ( i=0; i<num_groups; i++ )
1464 send_notify2_changes( &messages, i );
1467 /* cleanup */
1469 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1470 (uint32_t)msg_count ));
1472 notify_msg_ctr_destroy( &messages );
1474 return;
1477 /********************************************************************
1478 Send a message to ourself about new driver being installed
1479 so we can upgrade the information for each printer bound to this
1480 driver
1481 ********************************************************************/
1483 static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
1484 struct messaging_context *msg_ctx)
1486 int len = strlen(drivername);
1488 if (!len)
1489 return false;
1491 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1492 drivername));
1494 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
1495 MSG_PRINTER_DRVUPGRADE,
1496 (const uint8_t *)drivername, len+1);
1498 return true;
1501 void srv_spoolss_cleanup(void)
1503 struct printer_session_counter *session_counter;
1505 for (session_counter = counter_list;
1506 session_counter != NULL;
1507 session_counter = counter_list) {
1508 DLIST_REMOVE(counter_list, session_counter);
1509 TALLOC_FREE(session_counter);
1513 /**********************************************************************
1514 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1515 over all printers, upgrading ones as necessary
1516 **********************************************************************/
1518 void do_drv_upgrade_printer(struct messaging_context *msg,
1519 void *private_data,
1520 uint32_t msg_type,
1521 struct server_id server_id,
1522 DATA_BLOB *data)
1524 TALLOC_CTX *tmp_ctx;
1525 const struct auth_session_info *session_info = get_session_info_system();
1526 struct spoolss_PrinterInfo2 *pinfo2;
1527 WERROR result;
1528 const char *drivername;
1529 int snum;
1530 int n_services = lp_numservices();
1531 struct dcerpc_binding_handle *b = NULL;
1533 tmp_ctx = talloc_new(NULL);
1534 if (!tmp_ctx) return;
1536 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, data->length);
1537 if (!drivername) {
1538 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1539 goto done;
1542 DEBUG(10, ("do_drv_upgrade_printer: "
1543 "Got message for new driver [%s]\n", drivername));
1545 /* Iterate the printer list */
1547 for (snum = 0; snum < n_services; snum++) {
1548 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1549 continue;
1552 /* ignore [printers] share */
1553 if (strequal(lp_const_servicename(snum), "printers")) {
1554 continue;
1557 if (b == NULL) {
1558 result = winreg_printer_binding_handle(tmp_ctx,
1559 session_info,
1560 msg,
1561 &b);
1562 if (!W_ERROR_IS_OK(result)) {
1563 break;
1567 result = winreg_get_printer(tmp_ctx, b,
1568 lp_const_servicename(snum),
1569 &pinfo2);
1571 if (!W_ERROR_IS_OK(result)) {
1572 continue;
1575 if (!pinfo2->drivername) {
1576 continue;
1579 if (strcmp(drivername, pinfo2->drivername) != 0) {
1580 continue;
1583 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1585 /* all we care about currently is the change_id */
1586 result = winreg_printer_update_changeid(tmp_ctx, b,
1587 pinfo2->printername);
1589 if (!W_ERROR_IS_OK(result)) {
1590 DEBUG(3, ("do_drv_upgrade_printer: "
1591 "Failed to update changeid [%s]\n",
1592 win_errstr(result)));
1596 /* all done */
1597 done:
1598 talloc_free(tmp_ctx);
1601 /********************************************************************
1602 Update the cache for all printq's with a registered client
1603 connection
1604 ********************************************************************/
1606 void update_monitored_printq_cache(struct messaging_context *msg_ctx)
1608 struct printer_handle *printer = printers_list;
1609 int snum;
1611 /* loop through all printers and update the cache where
1612 a client is connected */
1613 while (printer) {
1614 if ((printer->printer_type == SPLHND_PRINTER) &&
1615 ((printer->notify.cli_chan != NULL) &&
1616 (printer->notify.cli_chan->active_connections > 0))) {
1617 snum = print_queue_snum(printer->sharename);
1618 print_queue_status(msg_ctx, snum, NULL, NULL);
1621 printer = printer->next;
1624 return;
1627 /****************************************************************
1628 _spoolss_OpenPrinter
1629 ****************************************************************/
1631 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1632 struct spoolss_OpenPrinter *r)
1634 struct spoolss_OpenPrinterEx e;
1635 struct spoolss_UserLevel1 level1;
1636 WERROR werr;
1638 ZERO_STRUCT(level1);
1640 e.in.printername = r->in.printername;
1641 e.in.datatype = r->in.datatype;
1642 e.in.devmode_ctr = r->in.devmode_ctr;
1643 e.in.access_mask = r->in.access_mask;
1644 e.in.userlevel_ctr.level = 1;
1645 e.in.userlevel_ctr.user_info.level1 = &level1;
1647 e.out.handle = r->out.handle;
1649 werr = _spoolss_OpenPrinterEx(p, &e);
1651 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1652 /* OpenPrinterEx returns this for a bad
1653 * printer name. We must return WERR_INVALID_PRINTER_NAME
1654 * instead.
1656 werr = WERR_INVALID_PRINTER_NAME;
1659 return werr;
1662 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1663 struct spoolss_DeviceMode *orig,
1664 struct spoolss_DeviceMode **dest)
1666 struct spoolss_DeviceMode *dm;
1668 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1669 if (!dm) {
1670 return WERR_NOMEM;
1673 /* copy all values, then duplicate strings and structs */
1674 *dm = *orig;
1676 dm->devicename = talloc_strdup(dm, orig->devicename);
1677 if (!dm->devicename) {
1678 return WERR_NOMEM;
1680 dm->formname = talloc_strdup(dm, orig->formname);
1681 if (!dm->formname) {
1682 return WERR_NOMEM;
1684 if (orig->driverextra_data.data) {
1685 dm->driverextra_data.data =
1686 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1687 orig->driverextra_data.length);
1688 if (!dm->driverextra_data.data) {
1689 return WERR_NOMEM;
1693 *dest = dm;
1694 return WERR_OK;
1697 /****************************************************************
1698 _spoolss_OpenPrinterEx
1699 ****************************************************************/
1701 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1702 struct spoolss_OpenPrinterEx *r)
1704 int snum;
1705 char *raddr;
1706 char *rhost;
1707 struct printer_handle *Printer=NULL;
1708 WERROR result;
1709 int rc;
1711 if (!r->in.printername) {
1712 return WERR_INVALID_PARAM;
1715 if (!*r->in.printername) {
1716 return WERR_INVALID_PARAM;
1719 if (r->in.userlevel_ctr.level > 3) {
1720 return WERR_INVALID_PARAM;
1722 if ((r->in.userlevel_ctr.level == 1 && !r->in.userlevel_ctr.user_info.level1) ||
1723 (r->in.userlevel_ctr.level == 2 && !r->in.userlevel_ctr.user_info.level2) ||
1724 (r->in.userlevel_ctr.level == 3 && !r->in.userlevel_ctr.user_info.level3)) {
1725 return WERR_INVALID_PARAM;
1728 /* some sanity check because you can open a printer or a print server */
1729 /* aka: \\server\printer or \\server */
1731 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1733 result = open_printer_hnd(p, r->out.handle, r->in.printername, 0);
1734 if (!W_ERROR_IS_OK(result)) {
1735 DEBUG(3,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1736 "for printer %s\n", r->in.printername));
1737 ZERO_STRUCTP(r->out.handle);
1738 return result;
1741 Printer = find_printer_index_by_hnd(p, r->out.handle);
1742 if ( !Printer ) {
1743 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1744 "handle we created for printer %s\n", r->in.printername));
1745 close_printer_handle(p, r->out.handle);
1746 ZERO_STRUCTP(r->out.handle);
1747 return WERR_INVALID_PARAM;
1751 * First case: the user is opening the print server:
1753 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1754 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1756 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1757 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1758 * or if the user is listed in the smb.conf printer admin parameter.
1760 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1761 * client view printer folder, but does not show the MSAPW.
1763 * Note: this test needs code to check access rights here too. Jeremy
1764 * could you look at this?
1766 * Second case: the user is opening a printer:
1767 * NT doesn't let us connect to a printer if the connecting user
1768 * doesn't have print permission.
1770 * Third case: user is opening a Port Monitor
1771 * access checks same as opening a handle to the print server.
1774 switch (Printer->printer_type )
1776 case SPLHND_SERVER:
1777 case SPLHND_PORTMON_TCP:
1778 case SPLHND_PORTMON_LOCAL:
1779 /* Printserver handles use global struct... */
1781 snum = -1;
1783 /* Map standard access rights to object specific access rights */
1785 se_map_standard(&r->in.access_mask,
1786 &printserver_std_mapping);
1788 /* Deny any object specific bits that don't apply to print
1789 servers (i.e printer and job specific bits) */
1791 r->in.access_mask &= SEC_MASK_SPECIFIC;
1793 if (r->in.access_mask &
1794 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1795 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1796 close_printer_handle(p, r->out.handle);
1797 ZERO_STRUCTP(r->out.handle);
1798 return WERR_ACCESS_DENIED;
1801 /* Allow admin access */
1803 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1805 if (!lp_ms_add_printer_wizard()) {
1806 close_printer_handle(p, r->out.handle);
1807 ZERO_STRUCTP(r->out.handle);
1808 return WERR_ACCESS_DENIED;
1811 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1812 and not a printer admin, then fail */
1814 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
1815 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
1816 !nt_token_check_sid(&global_sid_Builtin_Print_Operators,
1817 p->session_info->security_token)) {
1818 close_printer_handle(p, r->out.handle);
1819 ZERO_STRUCTP(r->out.handle);
1820 DEBUG(3,("access DENIED as user is not root, "
1821 "has no printoperator privilege, "
1822 "not a member of the printoperator builtin group and "
1823 "is not in printer admin list"));
1824 return WERR_ACCESS_DENIED;
1827 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1829 else
1831 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1834 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1835 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1837 /* We fall through to return WERR_OK */
1838 break;
1840 case SPLHND_PRINTER:
1841 /* NT doesn't let us connect to a printer if the connecting user
1842 doesn't have print permission. */
1844 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1845 close_printer_handle(p, r->out.handle);
1846 ZERO_STRUCTP(r->out.handle);
1847 return WERR_BADFID;
1850 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1851 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1854 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1856 /* map an empty access mask to the minimum access mask */
1857 if (r->in.access_mask == 0x0)
1858 r->in.access_mask = PRINTER_ACCESS_USE;
1861 * If we are not serving the printer driver for this printer,
1862 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1863 * will keep NT clients happy --jerry
1866 if (lp_use_client_driver(snum)
1867 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1869 r->in.access_mask = PRINTER_ACCESS_USE;
1872 /* check smb.conf parameters and the the sec_desc */
1873 raddr = tsocket_address_inet_addr_string(p->remote_address,
1874 p->mem_ctx);
1875 if (raddr == NULL) {
1876 return WERR_NOMEM;
1879 rc = get_remote_hostname(p->remote_address,
1880 &rhost,
1881 p->mem_ctx);
1882 if (rc < 0) {
1883 return WERR_NOMEM;
1885 if (strequal(rhost, "UNKNOWN")) {
1886 rhost = raddr;
1889 if (!allow_access(lp_hostsdeny(snum), lp_hostsallow(snum),
1890 rhost, raddr)) {
1891 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1892 ZERO_STRUCTP(r->out.handle);
1893 return WERR_ACCESS_DENIED;
1896 if (!user_ok_token(uidtoname(p->session_info->unix_token->uid), NULL,
1897 p->session_info->security_token, snum) ||
1898 !print_access_check(p->session_info,
1899 p->msg_ctx,
1900 snum,
1901 r->in.access_mask)) {
1902 DEBUG(3, ("access DENIED for printer open\n"));
1903 close_printer_handle(p, r->out.handle);
1904 ZERO_STRUCTP(r->out.handle);
1905 return WERR_ACCESS_DENIED;
1908 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1909 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1910 close_printer_handle(p, r->out.handle);
1911 ZERO_STRUCTP(r->out.handle);
1912 return WERR_ACCESS_DENIED;
1915 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1916 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1917 else
1918 r->in.access_mask = PRINTER_ACCESS_USE;
1920 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1921 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1923 winreg_create_printer_internal(p->mem_ctx,
1924 get_session_info_system(),
1925 p->msg_ctx,
1926 lp_const_servicename(snum));
1928 break;
1930 default:
1931 /* sanity check to prevent programmer error */
1932 ZERO_STRUCTP(r->out.handle);
1933 return WERR_BADFID;
1936 Printer->access_granted = r->in.access_mask;
1939 * If the client sent a devmode in the OpenPrinter() call, then
1940 * save it here in case we get a job submission on this handle
1943 if ((Printer->printer_type != SPLHND_SERVER)
1944 && (r->in.devmode_ctr.devmode != NULL)) {
1945 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1946 &Printer->devmode);
1949 return WERR_OK;
1952 /****************************************************************
1953 _spoolss_ClosePrinter
1954 ****************************************************************/
1956 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1957 struct spoolss_ClosePrinter *r)
1959 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1961 if (Printer && Printer->document_started) {
1962 struct spoolss_EndDocPrinter e;
1964 e.in.handle = r->in.handle;
1966 _spoolss_EndDocPrinter(p, &e);
1969 if (!close_printer_handle(p, r->in.handle))
1970 return WERR_BADFID;
1972 /* clear the returned printer handle. Observed behavior
1973 from Win2k server. Don't think this really matters.
1974 Previous code just copied the value of the closed
1975 handle. --jerry */
1977 ZERO_STRUCTP(r->out.handle);
1979 return WERR_OK;
1982 /****************************************************************
1983 _spoolss_DeletePrinter
1984 ****************************************************************/
1986 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1987 struct spoolss_DeletePrinter *r)
1989 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1990 WERROR result;
1991 int snum;
1993 if (Printer && Printer->document_started) {
1994 struct spoolss_EndDocPrinter e;
1996 e.in.handle = r->in.handle;
1998 _spoolss_EndDocPrinter(p, &e);
2001 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
2002 winreg_delete_printer_key_internal(p->mem_ctx,
2003 get_session_info_system(),
2004 p->msg_ctx,
2005 lp_const_servicename(snum),
2006 "");
2009 result = delete_printer_handle(p, r->in.handle);
2011 return result;
2014 /*******************************************************************
2015 * static function to lookup the version id corresponding to an
2016 * long architecture string
2017 ******************************************************************/
2019 static const struct print_architecture_table_node archi_table[]= {
2021 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
2022 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
2023 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
2024 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
2025 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
2026 {"Windows IA64", SPL_ARCH_IA64, 3 },
2027 {"Windows x64", SPL_ARCH_X64, 3 },
2028 {NULL, "", -1 }
2031 static const int drv_cversion[] = {SPOOLSS_DRIVER_VERSION_9X,
2032 SPOOLSS_DRIVER_VERSION_NT35,
2033 SPOOLSS_DRIVER_VERSION_NT4,
2034 SPOOLSS_DRIVER_VERSION_200X,
2035 -1};
2037 static int get_version_id(const char *arch)
2039 int i;
2041 for (i=0; archi_table[i].long_archi != NULL; i++)
2043 if (strcmp(arch, archi_table[i].long_archi) == 0)
2044 return (archi_table[i].version);
2047 return -1;
2050 /****************************************************************
2051 _spoolss_DeletePrinterDriver
2052 ****************************************************************/
2054 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
2055 struct spoolss_DeletePrinterDriver *r)
2058 struct spoolss_DriverInfo8 *info = NULL;
2059 int version;
2060 WERROR status;
2061 struct dcerpc_binding_handle *b;
2062 TALLOC_CTX *tmp_ctx = NULL;
2063 int i;
2064 bool found;
2066 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2067 and not a printer admin, then fail */
2069 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
2070 !security_token_has_privilege(p->session_info->security_token,
2071 SEC_PRIV_PRINT_OPERATOR)) {
2072 return WERR_ACCESS_DENIED;
2075 /* check that we have a valid driver name first */
2077 if ((version = get_version_id(r->in.architecture)) == -1) {
2078 return WERR_INVALID_ENVIRONMENT;
2081 tmp_ctx = talloc_new(p->mem_ctx);
2082 if (!tmp_ctx) {
2083 return WERR_NOMEM;
2086 status = winreg_printer_binding_handle(tmp_ctx,
2087 get_session_info_system(),
2088 p->msg_ctx,
2089 &b);
2090 if (!W_ERROR_IS_OK(status)) {
2091 goto done;
2094 for (found = false, i = 0; drv_cversion[i] >= 0; i++) {
2095 status = winreg_get_driver(tmp_ctx, b,
2096 r->in.architecture, r->in.driver,
2097 drv_cversion[i], &info);
2098 if (!W_ERROR_IS_OK(status)) {
2099 DEBUG(5, ("skipping del of driver with version %d\n",
2100 drv_cversion[i]));
2101 continue;
2103 found = true;
2105 if (printer_driver_in_use(tmp_ctx, b, info)) {
2106 status = WERR_PRINTER_DRIVER_IN_USE;
2107 goto done;
2110 status = winreg_del_driver(tmp_ctx, b, info, drv_cversion[i]);
2111 if (!W_ERROR_IS_OK(status)) {
2112 DEBUG(0, ("failed del of driver with version %d\n",
2113 drv_cversion[i]));
2114 goto done;
2117 if (found == false) {
2118 DEBUG(0, ("driver %s not found for deletion\n", r->in.driver));
2119 status = WERR_UNKNOWN_PRINTER_DRIVER;
2120 } else {
2121 status = WERR_OK;
2124 done:
2125 talloc_free(tmp_ctx);
2127 return status;
2130 static WERROR spoolss_dpd_version(TALLOC_CTX *mem_ctx,
2131 struct pipes_struct *p,
2132 struct spoolss_DeletePrinterDriverEx *r,
2133 struct dcerpc_binding_handle *b,
2134 struct spoolss_DriverInfo8 *info)
2136 WERROR status;
2137 bool delete_files;
2139 if (printer_driver_in_use(mem_ctx, b, info)) {
2140 status = WERR_PRINTER_DRIVER_IN_USE;
2141 goto done;
2145 * we have a couple of cases to consider.
2146 * (1) Are any files in use? If so and DPD_DELETE_ALL_FILES is set,
2147 * then the delete should fail if **any** files overlap with
2148 * other drivers
2149 * (2) If DPD_DELETE_UNUSED_FILES is set, then delete all
2150 * non-overlapping files
2151 * (3) If neither DPD_DELETE_ALL_FILES nor DPD_DELETE_UNUSED_FILES
2152 * are set, then do not delete any files
2153 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2156 delete_files = r->in.delete_flags
2157 & (DPD_DELETE_ALL_FILES | DPD_DELETE_UNUSED_FILES);
2160 if (delete_files) {
2161 bool in_use = printer_driver_files_in_use(mem_ctx, b, info);
2162 if (in_use && (r->in.delete_flags & DPD_DELETE_ALL_FILES)) {
2163 status = WERR_PRINTER_DRIVER_IN_USE;
2164 goto done;
2167 * printer_driver_files_in_use() has trimmed overlapping files
2168 * from info so they are not removed on DPD_DELETE_UNUSED_FILES
2173 status = winreg_del_driver(mem_ctx, b, info, info->version);
2174 if (!W_ERROR_IS_OK(status)) {
2175 goto done;
2179 * now delete any associated files if delete_files is
2180 * true. Even if this part failes, we return succes
2181 * because the driver doesn not exist any more
2183 if (delete_files) {
2184 delete_driver_files(p->session_info, info);
2187 done:
2188 return status;
2191 /****************************************************************
2192 _spoolss_DeletePrinterDriverEx
2193 ****************************************************************/
2195 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
2196 struct spoolss_DeletePrinterDriverEx *r)
2198 struct spoolss_DriverInfo8 *info = NULL;
2199 WERROR status;
2200 struct dcerpc_binding_handle *b;
2201 TALLOC_CTX *tmp_ctx = NULL;
2202 int i;
2203 bool found;
2205 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2206 and not a printer admin, then fail */
2208 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
2209 !security_token_has_privilege(p->session_info->security_token,
2210 SEC_PRIV_PRINT_OPERATOR)) {
2211 return WERR_ACCESS_DENIED;
2214 /* check that we have a valid driver name first */
2215 if (get_version_id(r->in.architecture) == -1) {
2216 /* this is what NT returns */
2217 return WERR_INVALID_ENVIRONMENT;
2220 tmp_ctx = talloc_new(p->mem_ctx);
2221 if (!tmp_ctx) {
2222 return WERR_NOMEM;
2225 status = winreg_printer_binding_handle(tmp_ctx,
2226 get_session_info_system(),
2227 p->msg_ctx,
2228 &b);
2229 if (!W_ERROR_IS_OK(status)) {
2230 goto done;
2233 for (found = false, i = 0; drv_cversion[i] >= 0; i++) {
2234 if ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2235 && (drv_cversion[i] != r->in.version)) {
2236 continue;
2239 /* check if a driver with this version exists before delete */
2240 status = winreg_get_driver(tmp_ctx, b,
2241 r->in.architecture, r->in.driver,
2242 drv_cversion[i], &info);
2243 if (!W_ERROR_IS_OK(status)) {
2244 DEBUG(5, ("skipping del of driver with version %d\n",
2245 drv_cversion[i]));
2246 continue;
2248 found = true;
2250 status = spoolss_dpd_version(tmp_ctx, p, r, b, info);
2251 if (!W_ERROR_IS_OK(status)) {
2252 DEBUG(0, ("failed to delete driver with version %d\n",
2253 drv_cversion[i]));
2254 goto done;
2257 if (found == false) {
2258 DEBUG(0, ("driver %s not found for deletion\n", r->in.driver));
2259 status = WERR_UNKNOWN_PRINTER_DRIVER;
2260 } else {
2261 status = WERR_OK;
2264 done:
2265 talloc_free(tmp_ctx);
2266 return status;
2270 /********************************************************************
2271 GetPrinterData on a printer server Handle.
2272 ********************************************************************/
2274 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2275 const char *value,
2276 enum winreg_Type *type,
2277 union spoolss_PrinterData *data)
2279 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2281 if (!strcasecmp_m(value, "W3SvcInstalled")) {
2282 *type = REG_DWORD;
2283 SIVAL(&data->value, 0, 0x00);
2284 return WERR_OK;
2287 if (!strcasecmp_m(value, "BeepEnabled")) {
2288 *type = REG_DWORD;
2289 SIVAL(&data->value, 0, 0x00);
2290 return WERR_OK;
2293 if (!strcasecmp_m(value, "EventLog")) {
2294 *type = REG_DWORD;
2295 /* formally was 0x1b */
2296 SIVAL(&data->value, 0, 0x00);
2297 return WERR_OK;
2300 if (!strcasecmp_m(value, "NetPopup")) {
2301 *type = REG_DWORD;
2302 SIVAL(&data->value, 0, 0x00);
2303 return WERR_OK;
2306 if (!strcasecmp_m(value, "MajorVersion")) {
2307 *type = REG_DWORD;
2309 /* Windows NT 4.0 seems to not allow uploading of drivers
2310 to a server that reports 0x3 as the MajorVersion.
2311 need to investigate more how Win2k gets around this .
2312 -- jerry */
2314 if (RA_WINNT == get_remote_arch()) {
2315 SIVAL(&data->value, 0, 0x02);
2316 } else {
2317 SIVAL(&data->value, 0, 0x03);
2320 return WERR_OK;
2323 if (!strcasecmp_m(value, "MinorVersion")) {
2324 *type = REG_DWORD;
2325 SIVAL(&data->value, 0, 0x00);
2326 return WERR_OK;
2329 /* REG_BINARY
2330 * uint32_t size = 0x114
2331 * uint32_t major = 5
2332 * uint32_t minor = [0|1]
2333 * uint32_t build = [2195|2600]
2334 * extra unicode string = e.g. "Service Pack 3"
2336 if (!strcasecmp_m(value, "OSVersion")) {
2337 DATA_BLOB blob;
2338 enum ndr_err_code ndr_err;
2339 struct spoolss_OSVersion os;
2341 os.major = lp_parm_int(GLOBAL_SECTION_SNUM,
2342 "spoolss", "os_major", 5);
2343 /* Windows 2000 == 5.0 */
2344 os.minor = lp_parm_int(GLOBAL_SECTION_SNUM,
2345 "spoolss", "os_minor", 0);
2346 os.build = lp_parm_int(GLOBAL_SECTION_SNUM,
2347 "spoolss", "os_build", 2195);
2348 os.extra_string = ""; /* leave extra string empty */
2350 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2351 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2352 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2353 return WERR_GENERAL_FAILURE;
2356 if (DEBUGLEVEL >= 10) {
2357 NDR_PRINT_DEBUG(spoolss_OSVersion, &os);
2360 *type = REG_BINARY;
2361 data->binary = blob;
2363 return WERR_OK;
2367 if (!strcasecmp_m(value, "DefaultSpoolDirectory")) {
2368 *type = REG_SZ;
2370 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2371 W_ERROR_HAVE_NO_MEMORY(data->string);
2373 return WERR_OK;
2376 if (!strcasecmp_m(value, "Architecture")) {
2377 *type = REG_SZ;
2378 data->string = talloc_strdup(mem_ctx,
2379 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2380 W_ERROR_HAVE_NO_MEMORY(data->string);
2382 return WERR_OK;
2385 if (!strcasecmp_m(value, "DsPresent")) {
2386 *type = REG_DWORD;
2388 /* only show the publish check box if we are a
2389 member of a AD domain */
2391 if (lp_security() == SEC_ADS) {
2392 SIVAL(&data->value, 0, 0x01);
2393 } else {
2394 SIVAL(&data->value, 0, 0x00);
2396 return WERR_OK;
2399 if (!strcasecmp_m(value, "DNSMachineName")) {
2400 const char *hostname = get_mydnsfullname();
2402 if (!hostname) {
2403 return WERR_BADFILE;
2406 *type = REG_SZ;
2407 data->string = talloc_strdup(mem_ctx, hostname);
2408 W_ERROR_HAVE_NO_MEMORY(data->string);
2410 return WERR_OK;
2413 *type = REG_NONE;
2415 return WERR_INVALID_PARAM;
2418 /****************************************************************
2419 _spoolss_GetPrinterData
2420 ****************************************************************/
2422 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2423 struct spoolss_GetPrinterData *r)
2425 struct spoolss_GetPrinterDataEx r2;
2427 r2.in.handle = r->in.handle;
2428 r2.in.key_name = "PrinterDriverData";
2429 r2.in.value_name = r->in.value_name;
2430 r2.in.offered = r->in.offered;
2431 r2.out.type = r->out.type;
2432 r2.out.data = r->out.data;
2433 r2.out.needed = r->out.needed;
2435 return _spoolss_GetPrinterDataEx(p, &r2);
2438 /*********************************************************
2439 Connect to the client machine.
2440 **********************************************************/
2442 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2443 struct sockaddr_storage *client_ss, const char *remote_machine)
2445 NTSTATUS ret;
2446 struct cli_state *the_cli;
2447 struct sockaddr_storage rm_addr;
2448 char addr[INET6_ADDRSTRLEN];
2450 if ( is_zero_addr(client_ss) ) {
2451 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2452 remote_machine));
2453 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2454 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2455 return false;
2457 print_sockaddr(addr, sizeof(addr), &rm_addr);
2458 } else {
2459 rm_addr = *client_ss;
2460 print_sockaddr(addr, sizeof(addr), &rm_addr);
2461 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2462 addr));
2465 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2466 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2467 addr));
2468 return false;
2471 /* setup the connection */
2472 ret = cli_full_connection( &the_cli, lp_netbios_name(), remote_machine,
2473 &rm_addr, 0, "IPC$", "IPC",
2474 "", /* username */
2475 "", /* domain */
2476 "", /* password */
2477 0, lp_client_signing());
2479 if ( !NT_STATUS_IS_OK( ret ) ) {
2480 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2481 remote_machine ));
2482 return false;
2485 if ( smbXcli_conn_protocol(the_cli->conn) != PROTOCOL_NT1 ) {
2486 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2487 cli_shutdown(the_cli);
2488 return false;
2492 * Ok - we have an anonymous connection to the IPC$ share.
2493 * Now start the NT Domain stuff :-).
2496 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2497 if (!NT_STATUS_IS_OK(ret)) {
2498 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2499 remote_machine, nt_errstr(ret)));
2500 cli_shutdown(the_cli);
2501 return false;
2504 return true;
2507 /***************************************************************************
2508 Connect to the client.
2509 ****************************************************************************/
2511 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2512 uint32_t localprinter,
2513 enum winreg_Type type,
2514 struct policy_handle *handle,
2515 struct notify_back_channel **_chan,
2516 struct sockaddr_storage *client_ss,
2517 struct messaging_context *msg_ctx)
2519 WERROR result;
2520 NTSTATUS status;
2521 struct notify_back_channel *chan;
2523 for (chan = back_channels; chan; chan = chan->next) {
2524 if (memcmp(&chan->client_address, client_ss,
2525 sizeof(struct sockaddr_storage)) == 0) {
2526 break;
2531 * If it's the first connection, contact the client
2532 * and connect to the IPC$ share anonymously
2534 if (!chan) {
2535 fstring unix_printer;
2537 /* the +2 is to strip the leading 2 backslashs */
2538 fstrcpy(unix_printer, printer + 2);
2540 chan = talloc_zero(NULL, struct notify_back_channel);
2541 if (!chan) {
2542 return false;
2544 chan->client_address = *client_ss;
2546 if (!spoolss_connect_to_client(&chan->cli_pipe, client_ss, unix_printer)) {
2547 TALLOC_FREE(chan);
2548 return false;
2551 DLIST_ADD(back_channels, chan);
2553 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2554 receive_notify2_message_list);
2557 if (chan->cli_pipe == NULL ||
2558 chan->cli_pipe->binding_handle == NULL) {
2559 DEBUG(0, ("srv_spoolss_replyopenprinter: error - "
2560 "NULL %s for printer %s\n",
2561 chan->cli_pipe == NULL ?
2562 "chan->cli_pipe" : "chan->cli_pipe->binding_handle",
2563 printer));
2564 return false;
2568 * Tell the specific printing tdb we want messages for this printer
2569 * by registering our PID.
2572 if (!print_notify_register_pid(snum)) {
2573 DEBUG(0, ("Failed to register our pid for printer %s\n",
2574 printer));
2577 status = dcerpc_spoolss_ReplyOpenPrinter(chan->cli_pipe->binding_handle,
2578 talloc_tos(),
2579 printer,
2580 localprinter,
2581 type,
2583 NULL,
2584 handle,
2585 &result);
2586 if (!NT_STATUS_IS_OK(status)) {
2587 DEBUG(5, ("dcerpc_spoolss_ReplyOpenPrinter returned [%s]\n", nt_errstr(status)));
2588 result = ntstatus_to_werror(status);
2589 } else if (!W_ERROR_IS_OK(result)) {
2590 DEBUG(5, ("ReplyOpenPrinter returned [%s]\n", win_errstr(result)));
2593 chan->active_connections++;
2594 *_chan = chan;
2596 return (W_ERROR_IS_OK(result));
2599 /****************************************************************
2600 ****************************************************************/
2602 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2603 const struct spoolss_NotifyOption *r)
2605 struct spoolss_NotifyOption *option;
2606 uint32_t i,k;
2608 if (!r) {
2609 return NULL;
2612 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2613 if (!option) {
2614 return NULL;
2617 *option = *r;
2619 if (!option->count) {
2620 return option;
2623 option->types = talloc_zero_array(option,
2624 struct spoolss_NotifyOptionType, option->count);
2625 if (!option->types) {
2626 talloc_free(option);
2627 return NULL;
2630 for (i=0; i < option->count; i++) {
2631 option->types[i] = r->types[i];
2633 if (option->types[i].count) {
2634 option->types[i].fields = talloc_zero_array(option,
2635 union spoolss_Field, option->types[i].count);
2636 if (!option->types[i].fields) {
2637 talloc_free(option);
2638 return NULL;
2640 for (k=0; k<option->types[i].count; k++) {
2641 option->types[i].fields[k] =
2642 r->types[i].fields[k];
2647 return option;
2650 /****************************************************************
2651 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2653 * before replying OK: status=0 a rpc call is made to the workstation
2654 * asking ReplyOpenPrinter
2656 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2657 * called from api_spoolss_rffpcnex
2658 ****************************************************************/
2660 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2661 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2663 int snum = -1;
2664 struct spoolss_NotifyOption *option = r->in.notify_options;
2665 struct sockaddr_storage client_ss;
2666 ssize_t client_len;
2668 /* store the notify value in the printer struct */
2670 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2672 if (!Printer) {
2673 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2674 "Invalid handle (%s:%u:%u).\n",
2675 OUR_HANDLE(r->in.handle)));
2676 return WERR_BADFID;
2679 Printer->notify.flags = r->in.flags;
2680 Printer->notify.options = r->in.options;
2681 Printer->notify.printerlocal = r->in.printer_local;
2682 Printer->notify.msg_ctx = p->msg_ctx;
2684 TALLOC_FREE(Printer->notify.option);
2685 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2687 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2689 /* Connect to the client machine and send a ReplyOpenPrinter */
2691 if ( Printer->printer_type == SPLHND_SERVER)
2692 snum = -1;
2693 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2694 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2695 return WERR_BADFID;
2697 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2698 "remote_address is %s\n",
2699 tsocket_address_string(p->remote_address, p->mem_ctx)));
2701 if (!lp_print_notify_backchannel(snum)) {
2702 DEBUG(10, ("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2703 "backchannel disabled\n"));
2704 return WERR_SERVER_UNAVAILABLE;
2707 client_len = tsocket_address_bsd_sockaddr(p->remote_address,
2708 (struct sockaddr *) &client_ss,
2709 sizeof(struct sockaddr_storage));
2710 if (client_len < 0) {
2711 return WERR_NOMEM;
2714 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2715 Printer->notify.printerlocal, REG_SZ,
2716 &Printer->notify.cli_hnd,
2717 &Printer->notify.cli_chan,
2718 &client_ss, p->msg_ctx)) {
2719 return WERR_SERVER_UNAVAILABLE;
2722 return WERR_OK;
2725 /*******************************************************************
2726 * fill a notify_info_data with the servername
2727 ********************************************************************/
2729 static void spoolss_notify_server_name(struct messaging_context *msg_ctx,
2730 int snum,
2731 struct spoolss_Notify *data,
2732 print_queue_struct *queue,
2733 struct spoolss_PrinterInfo2 *pinfo2,
2734 TALLOC_CTX *mem_ctx)
2736 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2739 /*******************************************************************
2740 * fill a notify_info_data with the printername (not including the servername).
2741 ********************************************************************/
2743 static void spoolss_notify_printer_name(struct messaging_context *msg_ctx,
2744 int snum,
2745 struct spoolss_Notify *data,
2746 print_queue_struct *queue,
2747 struct spoolss_PrinterInfo2 *pinfo2,
2748 TALLOC_CTX *mem_ctx)
2750 /* the notify name should not contain the \\server\ part */
2751 const char *p = strrchr(pinfo2->printername, '\\');
2753 if (!p) {
2754 p = pinfo2->printername;
2755 } else {
2756 p++;
2759 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2762 /*******************************************************************
2763 * fill a notify_info_data with the servicename
2764 ********************************************************************/
2766 static void spoolss_notify_share_name(struct messaging_context *msg_ctx,
2767 int snum,
2768 struct spoolss_Notify *data,
2769 print_queue_struct *queue,
2770 struct spoolss_PrinterInfo2 *pinfo2,
2771 TALLOC_CTX *mem_ctx)
2773 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(talloc_tos(), snum));
2776 /*******************************************************************
2777 * fill a notify_info_data with the port name
2778 ********************************************************************/
2780 static void spoolss_notify_port_name(struct messaging_context *msg_ctx,
2781 int snum,
2782 struct spoolss_Notify *data,
2783 print_queue_struct *queue,
2784 struct spoolss_PrinterInfo2 *pinfo2,
2785 TALLOC_CTX *mem_ctx)
2787 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2790 /*******************************************************************
2791 * fill a notify_info_data with the printername
2792 * but it doesn't exist, have to see what to do
2793 ********************************************************************/
2795 static void spoolss_notify_driver_name(struct messaging_context *msg_ctx,
2796 int snum,
2797 struct spoolss_Notify *data,
2798 print_queue_struct *queue,
2799 struct spoolss_PrinterInfo2 *pinfo2,
2800 TALLOC_CTX *mem_ctx)
2802 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2805 /*******************************************************************
2806 * fill a notify_info_data with the comment
2807 ********************************************************************/
2809 static void spoolss_notify_comment(struct messaging_context *msg_ctx,
2810 int snum,
2811 struct spoolss_Notify *data,
2812 print_queue_struct *queue,
2813 struct spoolss_PrinterInfo2 *pinfo2,
2814 TALLOC_CTX *mem_ctx)
2816 const char *p;
2818 if (*pinfo2->comment == '\0') {
2819 p = lp_comment(talloc_tos(), snum);
2820 } else {
2821 p = pinfo2->comment;
2824 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2827 /*******************************************************************
2828 * fill a notify_info_data with the comment
2829 * location = "Room 1, floor 2, building 3"
2830 ********************************************************************/
2832 static void spoolss_notify_location(struct messaging_context *msg_ctx,
2833 int snum,
2834 struct spoolss_Notify *data,
2835 print_queue_struct *queue,
2836 struct spoolss_PrinterInfo2 *pinfo2,
2837 TALLOC_CTX *mem_ctx)
2839 const char *loc = pinfo2->location;
2840 NTSTATUS status;
2842 status = printer_list_get_printer(mem_ctx,
2843 pinfo2->sharename,
2844 NULL,
2845 &loc,
2846 NULL);
2847 if (NT_STATUS_IS_OK(status)) {
2848 if (loc == NULL) {
2849 loc = pinfo2->location;
2853 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, loc);
2856 /*******************************************************************
2857 * fill a notify_info_data with the device mode
2858 * jfm:xxxx don't to it for know but that's a real problem !!!
2859 ********************************************************************/
2861 static void spoolss_notify_devmode(struct messaging_context *msg_ctx,
2862 int snum,
2863 struct spoolss_Notify *data,
2864 print_queue_struct *queue,
2865 struct spoolss_PrinterInfo2 *pinfo2,
2866 TALLOC_CTX *mem_ctx)
2868 /* for a dummy implementation we have to zero the fields */
2869 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2872 /*******************************************************************
2873 * fill a notify_info_data with the separator file name
2874 ********************************************************************/
2876 static void spoolss_notify_sepfile(struct messaging_context *msg_ctx,
2877 int snum,
2878 struct spoolss_Notify *data,
2879 print_queue_struct *queue,
2880 struct spoolss_PrinterInfo2 *pinfo2,
2881 TALLOC_CTX *mem_ctx)
2883 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2886 /*******************************************************************
2887 * fill a notify_info_data with the print processor
2888 * jfm:xxxx return always winprint to indicate we don't do anything to it
2889 ********************************************************************/
2891 static void spoolss_notify_print_processor(struct messaging_context *msg_ctx,
2892 int snum,
2893 struct spoolss_Notify *data,
2894 print_queue_struct *queue,
2895 struct spoolss_PrinterInfo2 *pinfo2,
2896 TALLOC_CTX *mem_ctx)
2898 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2901 /*******************************************************************
2902 * fill a notify_info_data with the print processor options
2903 * jfm:xxxx send an empty string
2904 ********************************************************************/
2906 static void spoolss_notify_parameters(struct messaging_context *msg_ctx,
2907 int snum,
2908 struct spoolss_Notify *data,
2909 print_queue_struct *queue,
2910 struct spoolss_PrinterInfo2 *pinfo2,
2911 TALLOC_CTX *mem_ctx)
2913 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2916 /*******************************************************************
2917 * fill a notify_info_data with the data type
2918 * jfm:xxxx always send RAW as data type
2919 ********************************************************************/
2921 static void spoolss_notify_datatype(struct messaging_context *msg_ctx,
2922 int snum,
2923 struct spoolss_Notify *data,
2924 print_queue_struct *queue,
2925 struct spoolss_PrinterInfo2 *pinfo2,
2926 TALLOC_CTX *mem_ctx)
2928 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2931 /*******************************************************************
2932 * fill a notify_info_data with the security descriptor
2933 * jfm:xxxx send an null pointer to say no security desc
2934 * have to implement security before !
2935 ********************************************************************/
2937 static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
2938 int snum,
2939 struct spoolss_Notify *data,
2940 print_queue_struct *queue,
2941 struct spoolss_PrinterInfo2 *pinfo2,
2942 TALLOC_CTX *mem_ctx)
2944 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2947 /*******************************************************************
2948 * fill a notify_info_data with the attributes
2949 * jfm:xxxx a samba printer is always shared
2950 ********************************************************************/
2952 static void spoolss_notify_attributes(struct messaging_context *msg_ctx,
2953 int snum,
2954 struct spoolss_Notify *data,
2955 print_queue_struct *queue,
2956 struct spoolss_PrinterInfo2 *pinfo2,
2957 TALLOC_CTX *mem_ctx)
2959 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2962 /*******************************************************************
2963 * fill a notify_info_data with the priority
2964 ********************************************************************/
2966 static void spoolss_notify_priority(struct messaging_context *msg_ctx,
2967 int snum,
2968 struct spoolss_Notify *data,
2969 print_queue_struct *queue,
2970 struct spoolss_PrinterInfo2 *pinfo2,
2971 TALLOC_CTX *mem_ctx)
2973 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2976 /*******************************************************************
2977 * fill a notify_info_data with the default priority
2978 ********************************************************************/
2980 static void spoolss_notify_default_priority(struct messaging_context *msg_ctx,
2981 int snum,
2982 struct spoolss_Notify *data,
2983 print_queue_struct *queue,
2984 struct spoolss_PrinterInfo2 *pinfo2,
2985 TALLOC_CTX *mem_ctx)
2987 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
2990 /*******************************************************************
2991 * fill a notify_info_data with the start time
2992 ********************************************************************/
2994 static void spoolss_notify_start_time(struct messaging_context *msg_ctx,
2995 int snum,
2996 struct spoolss_Notify *data,
2997 print_queue_struct *queue,
2998 struct spoolss_PrinterInfo2 *pinfo2,
2999 TALLOC_CTX *mem_ctx)
3001 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
3004 /*******************************************************************
3005 * fill a notify_info_data with the until time
3006 ********************************************************************/
3008 static void spoolss_notify_until_time(struct messaging_context *msg_ctx,
3009 int snum,
3010 struct spoolss_Notify *data,
3011 print_queue_struct *queue,
3012 struct spoolss_PrinterInfo2 *pinfo2,
3013 TALLOC_CTX *mem_ctx)
3015 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
3018 /*******************************************************************
3019 * fill a notify_info_data with the status
3020 ********************************************************************/
3022 static void spoolss_notify_status(struct messaging_context *msg_ctx,
3023 int snum,
3024 struct spoolss_Notify *data,
3025 print_queue_struct *queue,
3026 struct spoolss_PrinterInfo2 *pinfo2,
3027 TALLOC_CTX *mem_ctx)
3029 print_status_struct status;
3031 print_queue_length(msg_ctx, snum, &status);
3032 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3035 /*******************************************************************
3036 * fill a notify_info_data with the number of jobs queued
3037 ********************************************************************/
3039 static void spoolss_notify_cjobs(struct messaging_context *msg_ctx,
3040 int snum,
3041 struct spoolss_Notify *data,
3042 print_queue_struct *queue,
3043 struct spoolss_PrinterInfo2 *pinfo2,
3044 TALLOC_CTX *mem_ctx)
3046 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3047 data, print_queue_length(msg_ctx, snum, NULL));
3050 /*******************************************************************
3051 * fill a notify_info_data with the average ppm
3052 ********************************************************************/
3054 static void spoolss_notify_average_ppm(struct messaging_context *msg_ctx,
3055 int snum,
3056 struct spoolss_Notify *data,
3057 print_queue_struct *queue,
3058 struct spoolss_PrinterInfo2 *pinfo2,
3059 TALLOC_CTX *mem_ctx)
3061 /* always respond 8 pages per minutes */
3062 /* a little hard ! */
3063 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
3066 /*******************************************************************
3067 * fill a notify_info_data with username
3068 ********************************************************************/
3070 static void spoolss_notify_username(struct messaging_context *msg_ctx,
3071 int snum,
3072 struct spoolss_Notify *data,
3073 print_queue_struct *queue,
3074 struct spoolss_PrinterInfo2 *pinfo2,
3075 TALLOC_CTX *mem_ctx)
3077 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3080 /*******************************************************************
3081 * fill a notify_info_data with job status
3082 ********************************************************************/
3084 static void spoolss_notify_job_status(struct messaging_context *msg_ctx,
3085 int snum,
3086 struct spoolss_Notify *data,
3087 print_queue_struct *queue,
3088 struct spoolss_PrinterInfo2 *pinfo2,
3089 TALLOC_CTX *mem_ctx)
3091 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3094 /*******************************************************************
3095 * fill a notify_info_data with job name
3096 ********************************************************************/
3098 static void spoolss_notify_job_name(struct messaging_context *msg_ctx,
3099 int snum,
3100 struct spoolss_Notify *data,
3101 print_queue_struct *queue,
3102 struct spoolss_PrinterInfo2 *pinfo2,
3103 TALLOC_CTX *mem_ctx)
3105 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3108 /*******************************************************************
3109 * fill a notify_info_data with job status
3110 ********************************************************************/
3112 static void spoolss_notify_job_status_string(struct messaging_context *msg_ctx,
3113 int snum,
3114 struct spoolss_Notify *data,
3115 print_queue_struct *queue,
3116 struct spoolss_PrinterInfo2 *pinfo2,
3117 TALLOC_CTX *mem_ctx)
3120 * Now we're returning job status codes we just return a "" here. JRA.
3123 const char *p = "";
3125 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3126 p = "unknown";
3128 switch (queue->status) {
3129 case LPQ_QUEUED:
3130 p = "Queued";
3131 break;
3132 case LPQ_PAUSED:
3133 p = ""; /* NT provides the paused string */
3134 break;
3135 case LPQ_SPOOLING:
3136 p = "Spooling";
3137 break;
3138 case LPQ_PRINTING:
3139 p = "Printing";
3140 break;
3142 #endif /* NO LONGER NEEDED. */
3144 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3147 /*******************************************************************
3148 * fill a notify_info_data with job time
3149 ********************************************************************/
3151 static void spoolss_notify_job_time(struct messaging_context *msg_ctx,
3152 int snum,
3153 struct spoolss_Notify *data,
3154 print_queue_struct *queue,
3155 struct spoolss_PrinterInfo2 *pinfo2,
3156 TALLOC_CTX *mem_ctx)
3158 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3161 /*******************************************************************
3162 * fill a notify_info_data with job size
3163 ********************************************************************/
3165 static void spoolss_notify_job_size(struct messaging_context *msg_ctx,
3166 int snum,
3167 struct spoolss_Notify *data,
3168 print_queue_struct *queue,
3169 struct spoolss_PrinterInfo2 *pinfo2,
3170 TALLOC_CTX *mem_ctx)
3172 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3175 /*******************************************************************
3176 * fill a notify_info_data with page info
3177 ********************************************************************/
3178 static void spoolss_notify_total_pages(struct messaging_context *msg_ctx,
3179 int snum,
3180 struct spoolss_Notify *data,
3181 print_queue_struct *queue,
3182 struct spoolss_PrinterInfo2 *pinfo2,
3183 TALLOC_CTX *mem_ctx)
3185 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3188 /*******************************************************************
3189 * fill a notify_info_data with pages printed info.
3190 ********************************************************************/
3191 static void spoolss_notify_pages_printed(struct messaging_context *msg_ctx,
3192 int snum,
3193 struct spoolss_Notify *data,
3194 print_queue_struct *queue,
3195 struct spoolss_PrinterInfo2 *pinfo2,
3196 TALLOC_CTX *mem_ctx)
3198 /* Add code when back-end tracks this */
3199 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3202 /*******************************************************************
3203 Fill a notify_info_data with job position.
3204 ********************************************************************/
3206 static void spoolss_notify_job_position(struct messaging_context *msg_ctx,
3207 int snum,
3208 struct spoolss_Notify *data,
3209 print_queue_struct *queue,
3210 struct spoolss_PrinterInfo2 *pinfo2,
3211 TALLOC_CTX *mem_ctx)
3213 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->sysjob);
3216 /*******************************************************************
3217 Fill a notify_info_data with submitted time.
3218 ********************************************************************/
3220 static void spoolss_notify_submitted_time(struct messaging_context *msg_ctx,
3221 int snum,
3222 struct spoolss_Notify *data,
3223 print_queue_struct *queue,
3224 struct spoolss_PrinterInfo2 *pinfo2,
3225 TALLOC_CTX *mem_ctx)
3227 data->data.string.string = NULL;
3228 data->data.string.size = 0;
3230 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3231 &data->data.string.string,
3232 &data->data.string.size);
3236 struct s_notify_info_data_table
3238 enum spoolss_NotifyType type;
3239 uint16_t field;
3240 const char *name;
3241 enum spoolss_NotifyTable variable_type;
3242 void (*fn) (struct messaging_context *msg_ctx,
3243 int snum, struct spoolss_Notify *data,
3244 print_queue_struct *queue,
3245 struct spoolss_PrinterInfo2 *pinfo2,
3246 TALLOC_CTX *mem_ctx);
3249 /* A table describing the various print notification constants and
3250 whether the notification data is a pointer to a variable sized
3251 buffer, a one value uint32_t or a two value uint32_t. */
3253 static const struct s_notify_info_data_table notify_info_data_table[] =
3255 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3256 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3257 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3258 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3259 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3260 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3261 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3262 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3263 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3264 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3265 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3266 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3267 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3268 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3269 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3270 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3271 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3272 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3273 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3274 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3275 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3276 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3277 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3278 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3279 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3280 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3281 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3282 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3283 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3284 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3285 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3286 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3287 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3288 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3289 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3290 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3291 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3292 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3293 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3294 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3295 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3296 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3297 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3298 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3299 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3300 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3301 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3302 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3303 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3306 /*******************************************************************
3307 Return the variable_type of info_data structure.
3308 ********************************************************************/
3310 static enum spoolss_NotifyTable variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3311 uint16_t field)
3313 int i=0;
3315 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3316 if ( (notify_info_data_table[i].type == type) &&
3317 (notify_info_data_table[i].field == field) ) {
3318 return notify_info_data_table[i].variable_type;
3322 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3324 return (enum spoolss_NotifyTable) 0;
3327 /****************************************************************************
3328 ****************************************************************************/
3330 static bool search_notify(enum spoolss_NotifyType type,
3331 uint16_t field,
3332 int *value)
3334 int i;
3336 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3337 if (notify_info_data_table[i].type == type &&
3338 notify_info_data_table[i].field == field &&
3339 notify_info_data_table[i].fn != NULL) {
3340 *value = i;
3341 return true;
3345 return false;
3348 /****************************************************************************
3349 ****************************************************************************/
3351 static void construct_info_data(struct spoolss_Notify *info_data,
3352 enum spoolss_NotifyType type,
3353 uint16_t field, int id)
3355 info_data->type = type;
3356 info_data->field.field = field;
3357 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3358 info_data->job_id = id;
3361 /*******************************************************************
3363 * fill a notify_info struct with info asked
3365 ********************************************************************/
3367 static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
3368 struct printer_handle *print_hnd,
3369 struct spoolss_NotifyInfo *info,
3370 struct spoolss_PrinterInfo2 *pinfo2,
3371 int snum,
3372 const struct spoolss_NotifyOptionType *option_type,
3373 uint32_t id,
3374 TALLOC_CTX *mem_ctx)
3376 int field_num,j;
3377 enum spoolss_NotifyType type;
3378 uint16_t field;
3380 struct spoolss_Notify *current_data;
3382 type = option_type->type;
3384 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3385 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3386 option_type->count, lp_servicename(talloc_tos(), snum)));
3388 for(field_num=0; field_num < option_type->count; field_num++) {
3389 field = option_type->fields[field_num].field;
3391 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3393 if (!search_notify(type, field, &j) )
3394 continue;
3396 info->notifies = talloc_realloc(info, info->notifies,
3397 struct spoolss_Notify,
3398 info->count + 1);
3399 if (info->notifies == NULL) {
3400 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3401 return false;
3404 current_data = &info->notifies[info->count];
3406 construct_info_data(current_data, type, field, id);
3408 DEBUG(10, ("construct_notify_printer_info: "
3409 "calling [%s] snum=%d printername=[%s])\n",
3410 notify_info_data_table[j].name, snum,
3411 pinfo2->printername));
3413 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3414 NULL, pinfo2, mem_ctx);
3416 info->count++;
3419 return true;
3422 /*******************************************************************
3424 * fill a notify_info struct with info asked
3426 ********************************************************************/
3428 static bool construct_notify_jobs_info(struct messaging_context *msg_ctx,
3429 print_queue_struct *queue,
3430 struct spoolss_NotifyInfo *info,
3431 struct spoolss_PrinterInfo2 *pinfo2,
3432 int snum,
3433 const struct spoolss_NotifyOptionType *option_type,
3434 uint32_t id,
3435 TALLOC_CTX *mem_ctx)
3437 int field_num,j;
3438 enum spoolss_NotifyType type;
3439 uint16_t field;
3440 struct spoolss_Notify *current_data;
3442 DEBUG(4,("construct_notify_jobs_info\n"));
3444 type = option_type->type;
3446 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3447 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3448 option_type->count));
3450 for(field_num=0; field_num<option_type->count; field_num++) {
3451 field = option_type->fields[field_num].field;
3453 if (!search_notify(type, field, &j) )
3454 continue;
3456 info->notifies = talloc_realloc(info, info->notifies,
3457 struct spoolss_Notify,
3458 info->count + 1);
3459 if (info->notifies == NULL) {
3460 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3461 return false;
3464 current_data=&(info->notifies[info->count]);
3466 construct_info_data(current_data, type, field, id);
3467 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3468 queue, pinfo2, mem_ctx);
3469 info->count++;
3472 return true;
3476 * JFM: The enumeration is not that simple, it's even non obvious.
3478 * let's take an example: I want to monitor the PRINTER SERVER for
3479 * the printer's name and the number of jobs currently queued.
3480 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3481 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3483 * I have 3 printers on the back of my server.
3485 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3486 * structures.
3487 * Number Data Id
3488 * 1 printer 1 name 1
3489 * 2 printer 1 cjob 1
3490 * 3 printer 2 name 2
3491 * 4 printer 2 cjob 2
3492 * 5 printer 3 name 3
3493 * 6 printer 3 name 3
3495 * that's the print server case, the printer case is even worse.
3498 /*******************************************************************
3500 * enumerate all printers on the printserver
3501 * fill a notify_info struct with info asked
3503 ********************************************************************/
3505 static WERROR printserver_notify_info(struct pipes_struct *p,
3506 struct policy_handle *hnd,
3507 struct spoolss_NotifyInfo *info,
3508 TALLOC_CTX *mem_ctx)
3510 int snum;
3511 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3512 int n_services=lp_numservices();
3513 int i;
3514 struct spoolss_NotifyOption *option;
3515 struct spoolss_NotifyOptionType option_type;
3516 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3517 WERROR result;
3519 DEBUG(4,("printserver_notify_info\n"));
3521 if (!Printer)
3522 return WERR_BADFID;
3524 option = Printer->notify.option;
3526 info->version = 2;
3527 info->notifies = NULL;
3528 info->count = 0;
3530 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3531 sending a ffpcn() request first */
3533 if ( !option )
3534 return WERR_BADFID;
3536 for (i=0; i<option->count; i++) {
3537 option_type = option->types[i];
3539 if (option_type.type != PRINTER_NOTIFY_TYPE)
3540 continue;
3542 for (snum = 0; snum < n_services; snum++) {
3543 if (!lp_browseable(snum) ||
3544 !lp_snum_ok(snum) ||
3545 !lp_print_ok(snum)) {
3546 continue; /* skip */
3549 /* Maybe we should use the SYSTEM session_info here... */
3550 result = winreg_get_printer_internal(mem_ctx,
3551 get_session_info_system(),
3552 p->msg_ctx,
3553 lp_servicename(talloc_tos(), snum),
3554 &pinfo2);
3555 if (!W_ERROR_IS_OK(result)) {
3556 DEBUG(4, ("printserver_notify_info: "
3557 "Failed to get printer [%s]\n",
3558 lp_servicename(talloc_tos(), snum)));
3559 continue;
3563 construct_notify_printer_info(p->msg_ctx,
3564 Printer, info,
3565 pinfo2, snum,
3566 &option_type, snum,
3567 mem_ctx);
3569 TALLOC_FREE(pinfo2);
3573 #if 0
3575 * Debugging information, don't delete.
3578 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3579 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3580 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3582 for (i=0; i<info->count; i++) {
3583 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3584 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3585 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3587 #endif
3589 return WERR_OK;
3592 /*******************************************************************
3594 * fill a notify_info struct with info asked
3596 ********************************************************************/
3598 static WERROR printer_notify_info(struct pipes_struct *p,
3599 struct policy_handle *hnd,
3600 struct spoolss_NotifyInfo *info,
3601 TALLOC_CTX *mem_ctx)
3603 int snum;
3604 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3605 int i;
3606 uint32_t id;
3607 struct spoolss_NotifyOption *option;
3608 struct spoolss_NotifyOptionType option_type;
3609 int count,j;
3610 print_queue_struct *queue=NULL;
3611 print_status_struct status;
3612 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3613 WERROR result;
3615 DEBUG(4,("printer_notify_info\n"));
3617 if (!Printer)
3618 return WERR_BADFID;
3620 option = Printer->notify.option;
3621 id = 0x0;
3623 info->version = 2;
3624 info->notifies = NULL;
3625 info->count = 0;
3627 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3628 sending a ffpcn() request first */
3630 if ( !option )
3631 return WERR_BADFID;
3633 if (!get_printer_snum(p, hnd, &snum, NULL)) {
3634 return WERR_BADFID;
3637 /* Maybe we should use the SYSTEM session_info here... */
3638 result = winreg_get_printer_internal(mem_ctx,
3639 get_session_info_system(),
3640 p->msg_ctx,
3641 lp_servicename(talloc_tos(), snum), &pinfo2);
3642 if (!W_ERROR_IS_OK(result)) {
3643 return WERR_BADFID;
3647 * When sending a PRINTER_NOTIFY_FIELD_SERVER_NAME we should send the
3648 * correct servername.
3650 pinfo2->servername = talloc_strdup(pinfo2, Printer->servername);
3651 if (pinfo2->servername == NULL) {
3652 return WERR_NOMEM;
3655 for (i=0; i<option->count; i++) {
3656 option_type = option->types[i];
3658 switch (option_type.type) {
3659 case PRINTER_NOTIFY_TYPE:
3660 if (construct_notify_printer_info(p->msg_ctx,
3661 Printer, info,
3662 pinfo2, snum,
3663 &option_type, id,
3664 mem_ctx)) {
3665 id--;
3667 break;
3669 case JOB_NOTIFY_TYPE:
3671 count = print_queue_status(p->msg_ctx, snum, &queue,
3672 &status);
3674 for (j=0; j<count; j++) {
3675 construct_notify_jobs_info(p->msg_ctx,
3676 &queue[j], info,
3677 pinfo2, snum,
3678 &option_type,
3679 queue[j].sysjob,
3680 mem_ctx);
3683 SAFE_FREE(queue);
3684 break;
3689 * Debugging information, don't delete.
3692 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3693 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3694 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3696 for (i=0; i<info->count; i++) {
3697 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3698 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3699 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3703 talloc_free(pinfo2);
3704 return WERR_OK;
3707 /****************************************************************
3708 _spoolss_RouterRefreshPrinterChangeNotify
3709 ****************************************************************/
3711 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3712 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3714 struct spoolss_NotifyInfo *info;
3716 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
3717 WERROR result = WERR_BADFID;
3719 /* we always have a spoolss_NotifyInfo struct */
3720 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3721 if (!info) {
3722 result = WERR_NOMEM;
3723 goto done;
3726 *r->out.info = info;
3728 if (!Printer) {
3729 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3730 "Invalid handle (%s:%u:%u).\n",
3731 OUR_HANDLE(r->in.handle)));
3732 goto done;
3735 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3738 * We are now using the change value, and
3739 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3740 * I don't have a global notification system, I'm sending back all the
3741 * information even when _NOTHING_ has changed.
3744 /* We need to keep track of the change value to send back in
3745 RRPCN replies otherwise our updates are ignored. */
3747 Printer->notify.fnpcn = true;
3749 if (Printer->notify.cli_chan != NULL &&
3750 Printer->notify.cli_chan->active_connections > 0) {
3751 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3752 "Saving change value in request [%x]\n",
3753 r->in.change_low));
3754 Printer->notify.change = r->in.change_low;
3757 /* just ignore the spoolss_NotifyOption */
3759 switch (Printer->printer_type) {
3760 case SPLHND_SERVER:
3761 result = printserver_notify_info(p, r->in.handle,
3762 info, p->mem_ctx);
3763 break;
3765 case SPLHND_PRINTER:
3766 result = printer_notify_info(p, r->in.handle,
3767 info, p->mem_ctx);
3768 break;
3771 Printer->notify.fnpcn = false;
3773 done:
3774 return result;
3777 /********************************************************************
3778 ********************************************************************/
3780 static WERROR create_printername(TALLOC_CTX *mem_ctx,
3781 const char *servername,
3782 const char *printername,
3783 const char **printername_p)
3785 /* FIXME: add lp_force_printername() */
3787 if (servername == NULL) {
3788 *printername_p = talloc_strdup(mem_ctx, printername);
3789 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3790 return WERR_OK;
3793 if (servername[0] == '\\' && servername[1] == '\\') {
3794 servername += 2;
3797 *printername_p = talloc_asprintf(mem_ctx, "\\\\%s\\%s", servername, printername);
3798 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3800 return WERR_OK;
3803 /********************************************************************
3804 ********************************************************************/
3806 static void compose_devicemode_devicename(struct spoolss_DeviceMode *dm,
3807 const char *printername)
3809 if (dm == NULL) {
3810 return;
3813 dm->devicename = talloc_strndup(dm, printername,
3814 MIN(strlen(printername), 31));
3817 /********************************************************************
3818 * construct_printer_info_0
3819 * fill a printer_info_0 struct
3820 ********************************************************************/
3822 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3823 const struct auth_session_info *session_info,
3824 struct messaging_context *msg_ctx,
3825 struct spoolss_PrinterInfo2 *info2,
3826 const char *servername,
3827 struct spoolss_PrinterInfo0 *r,
3828 int snum)
3830 int count;
3831 struct printer_session_counter *session_counter;
3832 struct timeval setuptime;
3833 print_status_struct status;
3834 WERROR result;
3836 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3837 if (!W_ERROR_IS_OK(result)) {
3838 return result;
3841 if (servername) {
3842 r->servername = talloc_strdup(mem_ctx, servername);
3843 W_ERROR_HAVE_NO_MEMORY(r->servername);
3844 } else {
3845 r->servername = NULL;
3848 count = print_queue_length(msg_ctx, snum, &status);
3850 /* check if we already have a counter for this printer */
3851 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3852 if (session_counter->snum == snum)
3853 break;
3856 /* it's the first time, add it to the list */
3857 if (session_counter == NULL) {
3858 session_counter = talloc_zero(counter_list, struct printer_session_counter);
3859 W_ERROR_HAVE_NO_MEMORY(session_counter);
3860 session_counter->snum = snum;
3861 session_counter->counter = 0;
3862 DLIST_ADD(counter_list, session_counter);
3865 /* increment it */
3866 session_counter->counter++;
3868 r->cjobs = count;
3869 r->total_jobs = 0;
3870 r->total_bytes = 0;
3872 get_startup_time(&setuptime);
3873 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3875 /* JFM:
3876 * the global_counter should be stored in a TDB as it's common to all the clients
3877 * and should be zeroed on samba startup
3879 r->global_counter = session_counter->counter;
3880 r->total_pages = 0;
3881 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3882 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3883 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3884 r->free_build = SPOOLSS_RELEASE_BUILD;
3885 r->spooling = 0;
3886 r->max_spooling = 0;
3887 r->session_counter = session_counter->counter;
3888 r->num_error_out_of_paper = 0x0;
3889 r->num_error_not_ready = 0x0; /* number of print failure */
3890 r->job_error = 0x0;
3891 r->number_of_processors = 0x1;
3892 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3893 r->high_part_total_bytes = 0x0;
3895 /* ChangeID in milliseconds*/
3896 winreg_printer_get_changeid_internal(mem_ctx, session_info, msg_ctx,
3897 info2->sharename, &r->change_id);
3899 r->last_error = WERR_OK;
3900 r->status = nt_printq_status(status.status);
3901 r->enumerate_network_printers = 0x0;
3902 r->c_setprinter = 0x0;
3903 r->processor_architecture = PROCESSOR_ARCHITECTURE_INTEL;
3904 r->processor_level = 0x6; /* 6 ???*/
3905 r->ref_ic = 0;
3906 r->reserved2 = 0;
3907 r->reserved3 = 0;
3909 return WERR_OK;
3913 /********************************************************************
3914 * construct_printer_info1
3915 * fill a spoolss_PrinterInfo1 struct
3916 ********************************************************************/
3918 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3919 const struct spoolss_PrinterInfo2 *info2,
3920 uint32_t flags,
3921 const char *servername,
3922 struct spoolss_PrinterInfo1 *r,
3923 int snum)
3925 WERROR result;
3927 r->flags = flags;
3929 if (info2->comment == NULL || info2->comment[0] == '\0') {
3930 r->comment = lp_comment(mem_ctx, snum);
3931 } else {
3932 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3934 W_ERROR_HAVE_NO_MEMORY(r->comment);
3936 result = create_printername(mem_ctx, servername, info2->printername, &r->name);
3937 if (!W_ERROR_IS_OK(result)) {
3938 return result;
3941 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3942 r->name,
3943 info2->drivername,
3944 r->comment);
3945 W_ERROR_HAVE_NO_MEMORY(r->description);
3947 return WERR_OK;
3950 /********************************************************************
3951 * construct_printer_info2
3952 * fill a spoolss_PrinterInfo2 struct
3953 ********************************************************************/
3955 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3956 struct messaging_context *msg_ctx,
3957 const struct spoolss_PrinterInfo2 *info2,
3958 const char *servername,
3959 struct spoolss_PrinterInfo2 *r,
3960 int snum)
3962 int count;
3963 print_status_struct status;
3964 WERROR result;
3966 count = print_queue_length(msg_ctx, snum, &status);
3968 if (servername) {
3969 r->servername = talloc_strdup(mem_ctx, servername);
3970 W_ERROR_HAVE_NO_MEMORY(r->servername);
3971 } else {
3972 r->servername = NULL;
3975 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3976 if (!W_ERROR_IS_OK(result)) {
3977 return result;
3980 r->sharename = lp_servicename(mem_ctx, snum);
3981 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3982 r->portname = talloc_strdup(mem_ctx, info2->portname);
3983 W_ERROR_HAVE_NO_MEMORY(r->portname);
3984 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
3985 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3987 if (info2->comment[0] == '\0') {
3988 r->comment = lp_comment(mem_ctx, snum);
3989 } else {
3990 r->comment = talloc_strdup(mem_ctx, info2->comment);
3992 W_ERROR_HAVE_NO_MEMORY(r->comment);
3994 r->location = talloc_strdup(mem_ctx, info2->location);
3995 if (info2->location[0] == '\0') {
3996 const char *loc = NULL;
3997 NTSTATUS nt_status;
3999 nt_status = printer_list_get_printer(mem_ctx,
4000 info2->sharename,
4001 NULL,
4002 &loc,
4003 NULL);
4004 if (NT_STATUS_IS_OK(nt_status)) {
4005 if (loc != NULL) {
4006 r->location = talloc_strdup(mem_ctx, loc);
4010 W_ERROR_HAVE_NO_MEMORY(r->location);
4012 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
4013 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
4014 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
4015 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
4016 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
4017 W_ERROR_HAVE_NO_MEMORY(r->datatype);
4018 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
4019 W_ERROR_HAVE_NO_MEMORY(r->parameters);
4021 r->attributes = info2->attributes;
4023 r->priority = info2->priority;
4024 r->defaultpriority = info2->defaultpriority;
4025 r->starttime = info2->starttime;
4026 r->untiltime = info2->untiltime;
4027 r->status = nt_printq_status(status.status);
4028 r->cjobs = count;
4029 r->averageppm = info2->averageppm;
4031 if (info2->devmode != NULL) {
4032 result = copy_devicemode(mem_ctx,
4033 info2->devmode,
4034 &r->devmode);
4035 if (!W_ERROR_IS_OK(result)) {
4036 return result;
4038 } else if (lp_default_devmode(snum)) {
4039 result = spoolss_create_default_devmode(mem_ctx,
4040 info2->printername,
4041 &r->devmode);
4042 if (!W_ERROR_IS_OK(result)) {
4043 return result;
4045 } else {
4046 r->devmode = NULL;
4047 DEBUG(8,("Returning NULL Devicemode!\n"));
4050 compose_devicemode_devicename(r->devmode, r->printername);
4052 r->secdesc = NULL;
4054 if (info2->secdesc != NULL) {
4055 /* don't use talloc_steal() here unless you do a deep steal of all
4056 the SEC_DESC members */
4058 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4061 return WERR_OK;
4064 /********************************************************************
4065 * construct_printer_info3
4066 * fill a spoolss_PrinterInfo3 struct
4067 ********************************************************************/
4069 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
4070 const struct spoolss_PrinterInfo2 *info2,
4071 const char *servername,
4072 struct spoolss_PrinterInfo3 *r,
4073 int snum)
4075 /* These are the components of the SD we are returning. */
4077 if (info2->secdesc != NULL) {
4078 /* don't use talloc_steal() here unless you do a deep steal of all
4079 the SEC_DESC members */
4081 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4082 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
4085 return WERR_OK;
4088 /********************************************************************
4089 * construct_printer_info4
4090 * fill a spoolss_PrinterInfo4 struct
4091 ********************************************************************/
4093 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4094 const struct spoolss_PrinterInfo2 *info2,
4095 const char *servername,
4096 struct spoolss_PrinterInfo4 *r,
4097 int snum)
4099 WERROR result;
4101 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4102 if (!W_ERROR_IS_OK(result)) {
4103 return result;
4106 if (servername) {
4107 r->servername = talloc_strdup(mem_ctx, servername);
4108 W_ERROR_HAVE_NO_MEMORY(r->servername);
4109 } else {
4110 r->servername = NULL;
4113 r->attributes = info2->attributes;
4115 return WERR_OK;
4118 /********************************************************************
4119 * construct_printer_info5
4120 * fill a spoolss_PrinterInfo5 struct
4121 ********************************************************************/
4123 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4124 const struct spoolss_PrinterInfo2 *info2,
4125 const char *servername,
4126 struct spoolss_PrinterInfo5 *r,
4127 int snum)
4129 WERROR result;
4131 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4132 if (!W_ERROR_IS_OK(result)) {
4133 return result;
4136 r->portname = talloc_strdup(mem_ctx, info2->portname);
4137 W_ERROR_HAVE_NO_MEMORY(r->portname);
4139 r->attributes = info2->attributes;
4141 /* these two are not used by NT+ according to MSDN */
4142 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4143 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4145 return WERR_OK;
4148 /********************************************************************
4149 * construct_printer_info_6
4150 * fill a spoolss_PrinterInfo6 struct
4151 ********************************************************************/
4153 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4154 struct messaging_context *msg_ctx,
4155 const struct spoolss_PrinterInfo2 *info2,
4156 const char *servername,
4157 struct spoolss_PrinterInfo6 *r,
4158 int snum)
4160 print_status_struct status;
4162 print_queue_length(msg_ctx, snum, &status);
4164 r->status = nt_printq_status(status.status);
4166 return WERR_OK;
4169 /********************************************************************
4170 * construct_printer_info7
4171 * fill a spoolss_PrinterInfo7 struct
4172 ********************************************************************/
4174 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4175 struct messaging_context *msg_ctx,
4176 const char *servername,
4177 struct spoolss_PrinterInfo7 *r,
4178 int snum)
4180 const struct auth_session_info *session_info;
4181 char *printer;
4182 WERROR werr;
4183 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
4184 if (tmp_ctx == NULL) {
4185 return WERR_NOMEM;
4188 session_info = get_session_info_system();
4189 SMB_ASSERT(session_info != NULL);
4191 printer = lp_servicename(tmp_ctx, snum);
4192 if (printer == NULL) {
4193 DEBUG(0, ("invalid printer snum %d\n", snum));
4194 werr = WERR_INVALID_PARAM;
4195 goto out_tmp_free;
4198 if (is_printer_published(tmp_ctx, session_info, msg_ctx,
4199 servername, printer, NULL)) {
4200 struct GUID guid;
4201 werr = nt_printer_guid_get(tmp_ctx, session_info, msg_ctx,
4202 printer, &guid);
4203 if (!W_ERROR_IS_OK(werr)) {
4204 goto out_tmp_free;
4206 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4207 r->action = DSPRINT_PUBLISH;
4208 } else {
4209 r->guid = talloc_strdup(mem_ctx, "");
4210 r->action = DSPRINT_UNPUBLISH;
4212 if (r->guid == NULL) {
4213 werr = WERR_NOMEM;
4214 goto out_tmp_free;
4217 werr = WERR_OK;
4218 out_tmp_free:
4219 talloc_free(tmp_ctx);
4220 return werr;
4223 /********************************************************************
4224 * construct_printer_info8
4225 * fill a spoolss_PrinterInfo8 struct
4226 ********************************************************************/
4228 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4229 const struct spoolss_PrinterInfo2 *info2,
4230 const char *servername,
4231 struct spoolss_DeviceModeInfo *r,
4232 int snum)
4234 WERROR result;
4235 const char *printername;
4237 result = create_printername(mem_ctx, servername, info2->printername, &printername);
4238 if (!W_ERROR_IS_OK(result)) {
4239 return result;
4242 if (info2->devmode != NULL) {
4243 result = copy_devicemode(mem_ctx,
4244 info2->devmode,
4245 &r->devmode);
4246 if (!W_ERROR_IS_OK(result)) {
4247 return result;
4249 } else if (lp_default_devmode(snum)) {
4250 result = spoolss_create_default_devmode(mem_ctx,
4251 info2->printername,
4252 &r->devmode);
4253 if (!W_ERROR_IS_OK(result)) {
4254 return result;
4256 } else {
4257 r->devmode = NULL;
4258 DEBUG(8,("Returning NULL Devicemode!\n"));
4261 compose_devicemode_devicename(r->devmode, printername);
4263 return WERR_OK;
4267 /********************************************************************
4268 ********************************************************************/
4270 static bool snum_is_shared_printer(int snum)
4272 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4275 /********************************************************************
4276 Spoolss_enumprinters.
4277 ********************************************************************/
4279 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4280 const struct auth_session_info *session_info,
4281 struct messaging_context *msg_ctx,
4282 const char *servername,
4283 uint32_t level,
4284 uint32_t flags,
4285 union spoolss_PrinterInfo **info_p,
4286 uint32_t *count_p)
4288 int snum;
4289 int n_services = lp_numservices();
4290 union spoolss_PrinterInfo *info = NULL;
4291 uint32_t count = 0;
4292 WERROR result = WERR_OK;
4293 struct dcerpc_binding_handle *b = NULL;
4294 TALLOC_CTX *tmp_ctx = NULL;
4296 tmp_ctx = talloc_new(mem_ctx);
4297 if (!tmp_ctx) {
4298 return WERR_NOMEM;
4301 *count_p = 0;
4302 *info_p = NULL;
4304 for (snum = 0; snum < n_services; snum++) {
4306 const char *printer;
4307 struct spoolss_PrinterInfo2 *info2;
4309 if (!snum_is_shared_printer(snum)) {
4310 continue;
4313 printer = lp_const_servicename(snum);
4315 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4316 printer, snum));
4318 if (b == NULL) {
4319 result = winreg_printer_binding_handle(tmp_ctx,
4320 session_info,
4321 msg_ctx,
4322 &b);
4323 if (!W_ERROR_IS_OK(result)) {
4324 goto out;
4328 result = winreg_create_printer(tmp_ctx, b,
4329 printer);
4330 if (!W_ERROR_IS_OK(result)) {
4331 goto out;
4334 info = talloc_realloc(tmp_ctx, info,
4335 union spoolss_PrinterInfo,
4336 count + 1);
4337 if (!info) {
4338 result = WERR_NOMEM;
4339 goto out;
4342 result = winreg_get_printer(tmp_ctx, b,
4343 printer, &info2);
4344 if (!W_ERROR_IS_OK(result)) {
4345 goto out;
4348 switch (level) {
4349 case 0:
4350 result = construct_printer_info0(info, session_info,
4351 msg_ctx, info2,
4352 servername,
4353 &info[count].info0, snum);
4354 break;
4355 case 1:
4356 result = construct_printer_info1(info, info2, flags,
4357 servername,
4358 &info[count].info1, snum);
4359 break;
4360 case 2:
4361 result = construct_printer_info2(info, msg_ctx, info2,
4362 servername,
4363 &info[count].info2, snum);
4364 break;
4365 case 4:
4366 result = construct_printer_info4(info, info2,
4367 servername,
4368 &info[count].info4, snum);
4369 break;
4370 case 5:
4371 result = construct_printer_info5(info, info2,
4372 servername,
4373 &info[count].info5, snum);
4374 break;
4376 default:
4377 result = WERR_UNKNOWN_LEVEL;
4378 goto out;
4381 if (!W_ERROR_IS_OK(result)) {
4382 goto out;
4385 count++;
4388 out:
4389 if (W_ERROR_IS_OK(result)) {
4390 *info_p = talloc_move(mem_ctx, &info);
4391 *count_p = count;
4394 talloc_free(tmp_ctx);
4396 return result;
4399 /********************************************************************
4400 * handle enumeration of printers at level 0
4401 ********************************************************************/
4403 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4404 const struct auth_session_info *session_info,
4405 struct messaging_context *msg_ctx,
4406 uint32_t flags,
4407 const char *servername,
4408 union spoolss_PrinterInfo **info,
4409 uint32_t *count)
4411 DEBUG(4,("enum_all_printers_info_0\n"));
4413 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4414 servername, 0, flags, info, count);
4418 /********************************************************************
4419 ********************************************************************/
4421 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4422 const struct auth_session_info *session_info,
4423 struct messaging_context *msg_ctx,
4424 const char *servername,
4425 uint32_t flags,
4426 union spoolss_PrinterInfo **info,
4427 uint32_t *count)
4429 DEBUG(4,("enum_all_printers_info_1\n"));
4431 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4432 servername, 1, flags, info, count);
4435 /********************************************************************
4436 enum_all_printers_info_1_local.
4437 *********************************************************************/
4439 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4440 const struct auth_session_info *session_info,
4441 struct messaging_context *msg_ctx,
4442 const char *servername,
4443 union spoolss_PrinterInfo **info,
4444 uint32_t *count)
4446 DEBUG(4,("enum_all_printers_info_1_local\n"));
4448 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4449 servername, PRINTER_ENUM_ICON8, info, count);
4452 /********************************************************************
4453 enum_all_printers_info_1_name.
4454 *********************************************************************/
4456 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4457 const struct auth_session_info *session_info,
4458 struct messaging_context *msg_ctx,
4459 const char *servername,
4460 union spoolss_PrinterInfo **info,
4461 uint32_t *count)
4463 const char *s = servername;
4465 DEBUG(4,("enum_all_printers_info_1_name\n"));
4467 if (servername != NULL &&
4468 (servername[0] == '\\') && (servername[1] == '\\')) {
4469 s = servername + 2;
4472 if (!is_myname_or_ipaddr(s)) {
4473 return WERR_INVALID_NAME;
4476 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4477 servername, PRINTER_ENUM_ICON8, info, count);
4480 /********************************************************************
4481 enum_all_printers_info_1_network.
4482 *********************************************************************/
4484 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4485 const struct auth_session_info *session_info,
4486 struct messaging_context *msg_ctx,
4487 const char *servername,
4488 union spoolss_PrinterInfo **info,
4489 uint32_t *count)
4491 const char *s = servername;
4493 DEBUG(4,("enum_all_printers_info_1_network\n"));
4495 /* If we respond to a enum_printers level 1 on our name with flags
4496 set to PRINTER_ENUM_REMOTE with a list of printers then these
4497 printers incorrectly appear in the APW browse list.
4498 Specifically the printers for the server appear at the workgroup
4499 level where all the other servers in the domain are
4500 listed. Windows responds to this call with a
4501 WERR_CAN_NOT_COMPLETE so we should do the same. */
4503 if (servername != NULL &&
4504 (servername[0] == '\\') && (servername[1] == '\\')) {
4505 s = servername + 2;
4508 if (is_myname_or_ipaddr(s)) {
4509 return WERR_CAN_NOT_COMPLETE;
4512 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4513 servername, PRINTER_ENUM_NAME, info, count);
4516 /********************************************************************
4517 * api_spoolss_enumprinters
4519 * called from api_spoolss_enumprinters (see this to understand)
4520 ********************************************************************/
4522 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4523 const struct auth_session_info *session_info,
4524 struct messaging_context *msg_ctx,
4525 const char *servername,
4526 union spoolss_PrinterInfo **info,
4527 uint32_t *count)
4529 DEBUG(4,("enum_all_printers_info_2\n"));
4531 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4532 servername, 2, 0, info, count);
4535 /********************************************************************
4536 * handle enumeration of printers at level 1
4537 ********************************************************************/
4539 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4540 const struct auth_session_info *session_info,
4541 struct messaging_context *msg_ctx,
4542 uint32_t flags,
4543 const char *servername,
4544 union spoolss_PrinterInfo **info,
4545 uint32_t *count)
4547 /* Not all the flags are equals */
4549 if (flags & PRINTER_ENUM_LOCAL) {
4550 return enum_all_printers_info_1_local(mem_ctx, session_info,
4551 msg_ctx, servername, info, count);
4554 if (flags & PRINTER_ENUM_NAME) {
4555 return enum_all_printers_info_1_name(mem_ctx, session_info,
4556 msg_ctx, servername, info,
4557 count);
4560 if (flags & PRINTER_ENUM_NETWORK) {
4561 return enum_all_printers_info_1_network(mem_ctx, session_info,
4562 msg_ctx, servername, info,
4563 count);
4566 return WERR_OK; /* NT4sp5 does that */
4569 /********************************************************************
4570 * handle enumeration of printers at level 2
4571 ********************************************************************/
4573 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4574 const struct auth_session_info *session_info,
4575 struct messaging_context *msg_ctx,
4576 uint32_t flags,
4577 const char *servername,
4578 union spoolss_PrinterInfo **info,
4579 uint32_t *count)
4581 if (flags & PRINTER_ENUM_LOCAL) {
4583 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4584 servername,
4585 info, count);
4588 if (flags & PRINTER_ENUM_NAME) {
4589 if (servername && !is_myname_or_ipaddr(canon_servername(servername))) {
4590 return WERR_INVALID_NAME;
4593 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4594 servername,
4595 info, count);
4598 if (flags & PRINTER_ENUM_REMOTE) {
4599 return WERR_UNKNOWN_LEVEL;
4602 return WERR_OK;
4605 /********************************************************************
4606 * handle enumeration of printers at level 4
4607 ********************************************************************/
4609 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4610 const struct auth_session_info *session_info,
4611 struct messaging_context *msg_ctx,
4612 uint32_t flags,
4613 const char *servername,
4614 union spoolss_PrinterInfo **info,
4615 uint32_t *count)
4617 DEBUG(4,("enum_all_printers_info_4\n"));
4619 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4620 servername, 4, flags, info, count);
4624 /********************************************************************
4625 * handle enumeration of printers at level 5
4626 ********************************************************************/
4628 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4629 const struct auth_session_info *session_info,
4630 struct messaging_context *msg_ctx,
4631 uint32_t flags,
4632 const char *servername,
4633 union spoolss_PrinterInfo **info,
4634 uint32_t *count)
4636 DEBUG(4,("enum_all_printers_info_5\n"));
4638 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4639 servername, 5, flags, info, count);
4642 /****************************************************************
4643 _spoolss_EnumPrinters
4644 ****************************************************************/
4646 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4647 struct spoolss_EnumPrinters *r)
4649 const struct auth_session_info *session_info = get_session_info_system();
4650 WERROR result;
4652 /* that's an [in out] buffer */
4654 if (!r->in.buffer && (r->in.offered != 0)) {
4655 return WERR_INVALID_PARAM;
4658 DEBUG(4,("_spoolss_EnumPrinters\n"));
4660 *r->out.needed = 0;
4661 *r->out.count = 0;
4662 *r->out.info = NULL;
4665 * Level 1:
4666 * flags==PRINTER_ENUM_NAME
4667 * if name=="" then enumerates all printers
4668 * if name!="" then enumerate the printer
4669 * flags==PRINTER_ENUM_REMOTE
4670 * name is NULL, enumerate printers
4671 * Level 2: name!="" enumerates printers, name can't be NULL
4672 * Level 3: doesn't exist
4673 * Level 4: does a local registry lookup
4674 * Level 5: same as Level 2
4677 if (r->in.server && r->in.server[0] == '\0') {
4678 r->in.server = NULL;
4681 switch (r->in.level) {
4682 case 0:
4683 result = enumprinters_level0(p->mem_ctx, session_info,
4684 p->msg_ctx, r->in.flags,
4685 r->in.server,
4686 r->out.info, r->out.count);
4687 break;
4688 case 1:
4689 result = enumprinters_level1(p->mem_ctx, session_info,
4690 p->msg_ctx, r->in.flags,
4691 r->in.server,
4692 r->out.info, r->out.count);
4693 break;
4694 case 2:
4695 result = enumprinters_level2(p->mem_ctx, session_info,
4696 p->msg_ctx, r->in.flags,
4697 r->in.server,
4698 r->out.info, r->out.count);
4699 break;
4700 case 4:
4701 result = enumprinters_level4(p->mem_ctx, session_info,
4702 p->msg_ctx, r->in.flags,
4703 r->in.server,
4704 r->out.info, r->out.count);
4705 break;
4706 case 5:
4707 result = enumprinters_level5(p->mem_ctx, session_info,
4708 p->msg_ctx, r->in.flags,
4709 r->in.server,
4710 r->out.info, r->out.count);
4711 break;
4712 default:
4713 return WERR_UNKNOWN_LEVEL;
4716 if (!W_ERROR_IS_OK(result)) {
4717 return result;
4720 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4721 spoolss_EnumPrinters,
4722 *r->out.info, r->in.level,
4723 *r->out.count);
4724 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4725 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4727 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4730 /****************************************************************
4731 _spoolss_GetPrinter
4732 ****************************************************************/
4734 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4735 struct spoolss_GetPrinter *r)
4737 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
4738 struct spoolss_PrinterInfo2 *info2 = NULL;
4739 WERROR result = WERR_OK;
4740 int snum;
4742 /* that's an [in out] buffer */
4744 if (!r->in.buffer && (r->in.offered != 0)) {
4745 return WERR_INVALID_PARAM;
4748 *r->out.needed = 0;
4750 if (Printer == NULL) {
4751 return WERR_BADFID;
4754 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4755 return WERR_BADFID;
4758 result = winreg_get_printer_internal(p->mem_ctx,
4759 get_session_info_system(),
4760 p->msg_ctx,
4761 lp_const_servicename(snum),
4762 &info2);
4763 if (!W_ERROR_IS_OK(result)) {
4764 goto out;
4767 switch (r->in.level) {
4768 case 0:
4769 result = construct_printer_info0(p->mem_ctx,
4770 get_session_info_system(),
4771 p->msg_ctx,
4772 info2,
4773 Printer->servername,
4774 &r->out.info->info0,
4775 snum);
4776 break;
4777 case 1:
4778 result = construct_printer_info1(p->mem_ctx, info2,
4779 PRINTER_ENUM_ICON8,
4780 Printer->servername,
4781 &r->out.info->info1, snum);
4782 break;
4783 case 2:
4784 result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
4785 Printer->servername,
4786 &r->out.info->info2, snum);
4787 break;
4788 case 3:
4789 result = construct_printer_info3(p->mem_ctx, info2,
4790 Printer->servername,
4791 &r->out.info->info3, snum);
4792 break;
4793 case 4:
4794 result = construct_printer_info4(p->mem_ctx, info2,
4795 Printer->servername,
4796 &r->out.info->info4, snum);
4797 break;
4798 case 5:
4799 result = construct_printer_info5(p->mem_ctx, info2,
4800 Printer->servername,
4801 &r->out.info->info5, snum);
4802 break;
4803 case 6:
4804 result = construct_printer_info6(p->mem_ctx, p->msg_ctx, info2,
4805 Printer->servername,
4806 &r->out.info->info6, snum);
4807 break;
4808 case 7:
4809 result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
4810 Printer->servername,
4811 &r->out.info->info7, snum);
4812 break;
4813 case 8:
4814 result = construct_printer_info8(p->mem_ctx, info2,
4815 Printer->servername,
4816 &r->out.info->info8, snum);
4817 break;
4818 default:
4819 result = WERR_UNKNOWN_LEVEL;
4820 break;
4822 TALLOC_FREE(info2);
4824 out:
4825 if (!W_ERROR_IS_OK(result)) {
4826 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4827 r->in.level, win_errstr(result)));
4828 TALLOC_FREE(r->out.info);
4829 return result;
4832 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4833 r->out.info, r->in.level);
4834 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4836 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4839 /********************************************************************
4840 ********************************************************************/
4842 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4843 do { \
4844 if (in && strlen(in)) { \
4845 out = talloc_strdup(mem_ctx, in); \
4846 } else { \
4847 out = talloc_strdup(mem_ctx, ""); \
4849 W_ERROR_HAVE_NO_MEMORY(out); \
4850 } while (0);
4852 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4853 do { \
4854 if (in && strlen(in)) { \
4855 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4856 } else { \
4857 out = talloc_strdup(mem_ctx, ""); \
4859 W_ERROR_HAVE_NO_MEMORY(out); \
4860 } while (0);
4862 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4863 const char **string_array,
4864 const char ***presult,
4865 const char *cservername,
4866 const char *arch,
4867 int version)
4869 int i, num_strings = 0;
4870 const char **array = NULL;
4872 if (string_array == NULL) {
4873 return WERR_INVALID_PARAMETER;
4876 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4877 const char *str = NULL;
4879 if (cservername == NULL || arch == NULL) {
4880 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4881 } else {
4882 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4885 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4886 TALLOC_FREE(array);
4887 return WERR_NOMEM;
4891 if (i > 0) {
4892 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4893 &array, &num_strings);
4896 if (presult != NULL) {
4897 *presult = array;
4898 } else {
4899 talloc_free(array);
4902 return WERR_OK;
4905 /********************************************************************
4906 * fill a spoolss_DriverInfo1 struct
4907 ********************************************************************/
4909 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4910 struct spoolss_DriverInfo1 *r,
4911 const struct spoolss_DriverInfo8 *driver,
4912 const char *servername)
4914 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4915 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4917 return WERR_OK;
4920 /********************************************************************
4921 * fill a spoolss_DriverInfo2 struct
4922 ********************************************************************/
4924 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4925 struct spoolss_DriverInfo2 *r,
4926 const struct spoolss_DriverInfo8 *driver,
4927 const char *servername)
4930 const char *cservername = canon_servername(servername);
4932 r->version = driver->version;
4934 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4935 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4936 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4937 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4939 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4940 driver->architecture,
4941 driver->version,
4942 driver->driver_path,
4943 r->driver_path);
4945 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4946 driver->architecture,
4947 driver->version,
4948 driver->data_file,
4949 r->data_file);
4951 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4952 driver->architecture,
4953 driver->version,
4954 driver->config_file,
4955 r->config_file);
4957 return WERR_OK;
4960 /********************************************************************
4961 * fill a spoolss_DriverInfo3 struct
4962 ********************************************************************/
4964 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4965 struct spoolss_DriverInfo3 *r,
4966 const struct spoolss_DriverInfo8 *driver,
4967 const char *servername)
4969 const char *cservername = canon_servername(servername);
4971 r->version = driver->version;
4973 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4974 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4975 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4976 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4978 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4979 driver->architecture,
4980 driver->version,
4981 driver->driver_path,
4982 r->driver_path);
4984 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4985 driver->architecture,
4986 driver->version,
4987 driver->data_file,
4988 r->data_file);
4990 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4991 driver->architecture,
4992 driver->version,
4993 driver->config_file,
4994 r->config_file);
4996 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4997 driver->architecture,
4998 driver->version,
4999 driver->help_file,
5000 r->help_file);
5002 FILL_DRIVER_STRING(mem_ctx,
5003 driver->monitor_name,
5004 r->monitor_name);
5006 FILL_DRIVER_STRING(mem_ctx,
5007 driver->default_datatype,
5008 r->default_datatype);
5010 return string_array_from_driver_info(mem_ctx,
5011 driver->dependent_files,
5012 &r->dependent_files,
5013 cservername,
5014 driver->architecture,
5015 driver->version);
5018 /********************************************************************
5019 * fill a spoolss_DriverInfo4 struct
5020 ********************************************************************/
5022 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
5023 struct spoolss_DriverInfo4 *r,
5024 const struct spoolss_DriverInfo8 *driver,
5025 const char *servername)
5027 const char *cservername = canon_servername(servername);
5028 WERROR result;
5030 r->version = driver->version;
5032 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5033 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5034 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5035 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5037 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5038 driver->architecture,
5039 driver->version,
5040 driver->driver_path,
5041 r->driver_path);
5043 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5044 driver->architecture,
5045 driver->version,
5046 driver->data_file,
5047 r->data_file);
5049 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5050 driver->architecture,
5051 driver->version,
5052 driver->config_file,
5053 r->config_file);
5055 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5056 driver->architecture,
5057 driver->version,
5058 driver->help_file,
5059 r->help_file);
5061 result = string_array_from_driver_info(mem_ctx,
5062 driver->dependent_files,
5063 &r->dependent_files,
5064 cservername,
5065 driver->architecture,
5066 driver->version);
5067 if (!W_ERROR_IS_OK(result)) {
5068 return result;
5071 FILL_DRIVER_STRING(mem_ctx,
5072 driver->monitor_name,
5073 r->monitor_name);
5075 FILL_DRIVER_STRING(mem_ctx,
5076 driver->default_datatype,
5077 r->default_datatype);
5080 result = string_array_from_driver_info(mem_ctx,
5081 driver->previous_names,
5082 &r->previous_names,
5083 NULL, NULL, 0);
5085 return result;
5088 /********************************************************************
5089 * fill a spoolss_DriverInfo5 struct
5090 ********************************************************************/
5092 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
5093 struct spoolss_DriverInfo5 *r,
5094 const struct spoolss_DriverInfo8 *driver,
5095 const char *servername)
5097 const char *cservername = canon_servername(servername);
5099 r->version = driver->version;
5101 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5102 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5103 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5104 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5106 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5107 driver->architecture,
5108 driver->version,
5109 driver->driver_path,
5110 r->driver_path);
5112 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5113 driver->architecture,
5114 driver->version,
5115 driver->data_file,
5116 r->data_file);
5118 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5119 driver->architecture,
5120 driver->version,
5121 driver->config_file,
5122 r->config_file);
5124 r->driver_attributes = 0;
5125 r->config_version = 0;
5126 r->driver_version = 0;
5128 return WERR_OK;
5130 /********************************************************************
5131 * fill a spoolss_DriverInfo6 struct
5132 ********************************************************************/
5134 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
5135 struct spoolss_DriverInfo6 *r,
5136 const struct spoolss_DriverInfo8 *driver,
5137 const char *servername)
5139 const char *cservername = canon_servername(servername);
5140 WERROR result;
5142 r->version = driver->version;
5144 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5145 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5146 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5147 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5149 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5150 driver->architecture,
5151 driver->version,
5152 driver->driver_path,
5153 r->driver_path);
5155 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5156 driver->architecture,
5157 driver->version,
5158 driver->data_file,
5159 r->data_file);
5161 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5162 driver->architecture,
5163 driver->version,
5164 driver->config_file,
5165 r->config_file);
5167 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5168 driver->architecture,
5169 driver->version,
5170 driver->help_file,
5171 r->help_file);
5173 FILL_DRIVER_STRING(mem_ctx,
5174 driver->monitor_name,
5175 r->monitor_name);
5177 FILL_DRIVER_STRING(mem_ctx,
5178 driver->default_datatype,
5179 r->default_datatype);
5181 result = string_array_from_driver_info(mem_ctx,
5182 driver->dependent_files,
5183 &r->dependent_files,
5184 cservername,
5185 driver->architecture,
5186 driver->version);
5187 if (!W_ERROR_IS_OK(result)) {
5188 return result;
5191 result = string_array_from_driver_info(mem_ctx,
5192 driver->previous_names,
5193 &r->previous_names,
5194 NULL, NULL, 0);
5195 if (!W_ERROR_IS_OK(result)) {
5196 return result;
5199 r->driver_date = driver->driver_date;
5200 r->driver_version = driver->driver_version;
5202 FILL_DRIVER_STRING(mem_ctx,
5203 driver->manufacturer_name,
5204 r->manufacturer_name);
5205 FILL_DRIVER_STRING(mem_ctx,
5206 driver->manufacturer_url,
5207 r->manufacturer_url);
5208 FILL_DRIVER_STRING(mem_ctx,
5209 driver->hardware_id,
5210 r->hardware_id);
5211 FILL_DRIVER_STRING(mem_ctx,
5212 driver->provider,
5213 r->provider);
5215 return WERR_OK;
5218 /********************************************************************
5219 * fill a spoolss_DriverInfo8 struct
5220 ********************************************************************/
5222 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
5223 struct spoolss_DriverInfo8 *r,
5224 const struct spoolss_DriverInfo8 *driver,
5225 const char *servername)
5227 const char *cservername = canon_servername(servername);
5228 WERROR result;
5230 r->version = driver->version;
5232 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5233 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5234 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5235 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5237 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5238 driver->architecture,
5239 driver->version,
5240 driver->driver_path,
5241 r->driver_path);
5243 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5244 driver->architecture,
5245 driver->version,
5246 driver->data_file,
5247 r->data_file);
5249 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5250 driver->architecture,
5251 driver->version,
5252 driver->config_file,
5253 r->config_file);
5255 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5256 driver->architecture,
5257 driver->version,
5258 driver->help_file,
5259 r->help_file);
5261 FILL_DRIVER_STRING(mem_ctx,
5262 driver->monitor_name,
5263 r->monitor_name);
5265 FILL_DRIVER_STRING(mem_ctx,
5266 driver->default_datatype,
5267 r->default_datatype);
5269 result = string_array_from_driver_info(mem_ctx,
5270 driver->dependent_files,
5271 &r->dependent_files,
5272 cservername,
5273 driver->architecture,
5274 driver->version);
5275 if (!W_ERROR_IS_OK(result)) {
5276 return result;
5279 result = string_array_from_driver_info(mem_ctx,
5280 driver->previous_names,
5281 &r->previous_names,
5282 NULL, NULL, 0);
5283 if (!W_ERROR_IS_OK(result)) {
5284 return result;
5287 r->driver_date = driver->driver_date;
5288 r->driver_version = driver->driver_version;
5290 FILL_DRIVER_STRING(mem_ctx,
5291 driver->manufacturer_name,
5292 r->manufacturer_name);
5293 FILL_DRIVER_STRING(mem_ctx,
5294 driver->manufacturer_url,
5295 r->manufacturer_url);
5296 FILL_DRIVER_STRING(mem_ctx,
5297 driver->hardware_id,
5298 r->hardware_id);
5299 FILL_DRIVER_STRING(mem_ctx,
5300 driver->provider,
5301 r->provider);
5303 FILL_DRIVER_STRING(mem_ctx,
5304 driver->print_processor,
5305 r->print_processor);
5306 FILL_DRIVER_STRING(mem_ctx,
5307 driver->vendor_setup,
5308 r->vendor_setup);
5310 result = string_array_from_driver_info(mem_ctx,
5311 driver->color_profiles,
5312 &r->color_profiles,
5313 NULL, NULL, 0);
5314 if (!W_ERROR_IS_OK(result)) {
5315 return result;
5318 FILL_DRIVER_STRING(mem_ctx,
5319 driver->inf_path,
5320 r->inf_path);
5322 r->printer_driver_attributes = driver->printer_driver_attributes;
5324 result = string_array_from_driver_info(mem_ctx,
5325 driver->core_driver_dependencies,
5326 &r->core_driver_dependencies,
5327 NULL, NULL, 0);
5328 if (!W_ERROR_IS_OK(result)) {
5329 return result;
5332 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
5333 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
5335 return WERR_OK;
5338 #if 0 /* disabled until marshalling issues are resolved - gd */
5339 /********************************************************************
5340 ********************************************************************/
5342 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5343 struct spoolss_DriverFileInfo *r,
5344 const char *cservername,
5345 const char *file_name,
5346 enum spoolss_DriverFileType file_type,
5347 uint32_t file_version)
5349 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5350 cservername, file_name);
5351 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5352 r->file_type = file_type;
5353 r->file_version = file_version;
5355 return WERR_OK;
5358 /********************************************************************
5359 ********************************************************************/
5361 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5362 const struct spoolss_DriverInfo8 *driver,
5363 const char *cservername,
5364 struct spoolss_DriverFileInfo **info_p,
5365 uint32_t *count_p)
5367 struct spoolss_DriverFileInfo *info = NULL;
5368 uint32_t count = 0;
5369 WERROR result;
5370 uint32_t i;
5372 *info_p = NULL;
5373 *count_p = 0;
5375 if (strlen(driver->driver_path)) {
5376 info = talloc_realloc(mem_ctx, info,
5377 struct spoolss_DriverFileInfo,
5378 count + 1);
5379 W_ERROR_HAVE_NO_MEMORY(info);
5380 result = fill_spoolss_DriverFileInfo(info,
5381 &info[count],
5382 cservername,
5383 driver->driver_path,
5384 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5386 W_ERROR_NOT_OK_RETURN(result);
5387 count++;
5390 if (strlen(driver->config_file)) {
5391 info = talloc_realloc(mem_ctx, info,
5392 struct spoolss_DriverFileInfo,
5393 count + 1);
5394 W_ERROR_HAVE_NO_MEMORY(info);
5395 result = fill_spoolss_DriverFileInfo(info,
5396 &info[count],
5397 cservername,
5398 driver->config_file,
5399 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5401 W_ERROR_NOT_OK_RETURN(result);
5402 count++;
5405 if (strlen(driver->data_file)) {
5406 info = talloc_realloc(mem_ctx, info,
5407 struct spoolss_DriverFileInfo,
5408 count + 1);
5409 W_ERROR_HAVE_NO_MEMORY(info);
5410 result = fill_spoolss_DriverFileInfo(info,
5411 &info[count],
5412 cservername,
5413 driver->data_file,
5414 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5416 W_ERROR_NOT_OK_RETURN(result);
5417 count++;
5420 if (strlen(driver->help_file)) {
5421 info = talloc_realloc(mem_ctx, info,
5422 struct spoolss_DriverFileInfo,
5423 count + 1);
5424 W_ERROR_HAVE_NO_MEMORY(info);
5425 result = fill_spoolss_DriverFileInfo(info,
5426 &info[count],
5427 cservername,
5428 driver->help_file,
5429 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5431 W_ERROR_NOT_OK_RETURN(result);
5432 count++;
5435 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
5436 info = talloc_realloc(mem_ctx, info,
5437 struct spoolss_DriverFileInfo,
5438 count + 1);
5439 W_ERROR_HAVE_NO_MEMORY(info);
5440 result = fill_spoolss_DriverFileInfo(info,
5441 &info[count],
5442 cservername,
5443 driver->dependent_files[i],
5444 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5446 W_ERROR_NOT_OK_RETURN(result);
5447 count++;
5450 *info_p = info;
5451 *count_p = count;
5453 return WERR_OK;
5456 /********************************************************************
5457 * fill a spoolss_DriverInfo101 struct
5458 ********************************************************************/
5460 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5461 struct spoolss_DriverInfo101 *r,
5462 const struct spoolss_DriverInfo8 *driver,
5463 const char *servername)
5465 const char *cservername = canon_servername(servername);
5466 WERROR result;
5468 r->version = driver->version;
5470 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5471 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5472 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5473 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5475 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5476 cservername,
5477 &r->file_info,
5478 &r->file_count);
5479 if (!W_ERROR_IS_OK(result)) {
5480 return result;
5483 FILL_DRIVER_STRING(mem_ctx,
5484 driver->monitor_name,
5485 r->monitor_name);
5487 FILL_DRIVER_STRING(mem_ctx,
5488 driver->default_datatype,
5489 r->default_datatype);
5491 result = string_array_from_driver_info(mem_ctx,
5492 driver->previous_names,
5493 &r->previous_names,
5494 NULL, NULL, 0);
5495 if (!W_ERROR_IS_OK(result)) {
5496 return result;
5499 r->driver_date = driver->driver_date;
5500 r->driver_version = driver->driver_version;
5502 FILL_DRIVER_STRING(mem_ctx,
5503 driver->manufacturer_name,
5504 r->manufacturer_name);
5505 FILL_DRIVER_STRING(mem_ctx,
5506 driver->manufacturer_url,
5507 r->manufacturer_url);
5508 FILL_DRIVER_STRING(mem_ctx,
5509 driver->hardware_id,
5510 r->hardware_id);
5511 FILL_DRIVER_STRING(mem_ctx,
5512 driver->provider,
5513 r->provider);
5515 return WERR_OK;
5517 #endif
5518 /********************************************************************
5519 ********************************************************************/
5521 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5522 const struct auth_session_info *session_info,
5523 struct messaging_context *msg_ctx,
5524 uint32_t level,
5525 union spoolss_DriverInfo *r,
5526 int snum,
5527 const char *servername,
5528 const char *architecture,
5529 uint32_t version)
5531 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5532 struct spoolss_DriverInfo8 *driver;
5533 WERROR result;
5534 struct dcerpc_binding_handle *b;
5535 TALLOC_CTX *tmp_ctx = NULL;
5537 if (level == 101) {
5538 return WERR_UNKNOWN_LEVEL;
5541 tmp_ctx = talloc_new(mem_ctx);
5542 if (!tmp_ctx) {
5543 return WERR_NOMEM;
5546 result = winreg_printer_binding_handle(tmp_ctx,
5547 session_info,
5548 msg_ctx,
5549 &b);
5550 if (!W_ERROR_IS_OK(result)) {
5551 goto done;
5554 result = winreg_get_printer(tmp_ctx, b,
5555 lp_const_servicename(snum),
5556 &pinfo2);
5558 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5559 win_errstr(result)));
5561 if (!W_ERROR_IS_OK(result)) {
5562 result = WERR_INVALID_PRINTER_NAME;
5563 goto done;
5566 result = winreg_get_driver(tmp_ctx, b,
5567 architecture,
5568 pinfo2->drivername, version, &driver);
5570 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5571 win_errstr(result)));
5573 if (!W_ERROR_IS_OK(result)) {
5575 * Is this a W2k client ?
5578 if (version < 3) {
5579 result = WERR_UNKNOWN_PRINTER_DRIVER;
5580 goto done;
5583 /* Yes - try again with a WinNT driver. */
5584 version = 2;
5585 result = winreg_get_driver(tmp_ctx, b,
5586 architecture,
5587 pinfo2->drivername,
5588 version, &driver);
5589 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5590 win_errstr(result)));
5591 if (!W_ERROR_IS_OK(result)) {
5592 result = WERR_UNKNOWN_PRINTER_DRIVER;
5593 goto done;
5597 /* these are allocated on mem_ctx and not tmp_ctx because they are
5598 * the 'return value' and need to utlive this call */
5599 switch (level) {
5600 case 1:
5601 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5602 break;
5603 case 2:
5604 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5605 break;
5606 case 3:
5607 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5608 break;
5609 case 4:
5610 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5611 break;
5612 case 5:
5613 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5614 break;
5615 case 6:
5616 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5617 break;
5618 case 8:
5619 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5620 break;
5621 #if 0 /* disabled until marshalling issues are resolved - gd */
5622 case 101:
5623 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5624 break;
5625 #endif
5626 default:
5627 result = WERR_UNKNOWN_LEVEL;
5628 break;
5631 done:
5632 talloc_free(tmp_ctx);
5633 return result;
5636 /****************************************************************
5637 _spoolss_GetPrinterDriver2
5638 ****************************************************************/
5640 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5641 struct spoolss_GetPrinterDriver2 *r)
5643 struct printer_handle *printer;
5644 WERROR result;
5645 uint32_t version = r->in.client_major_version;
5647 int snum;
5649 /* that's an [in out] buffer */
5651 if (!r->in.buffer && (r->in.offered != 0)) {
5652 return WERR_INVALID_PARAM;
5655 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5657 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5658 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5659 return WERR_INVALID_PRINTER_NAME;
5662 *r->out.needed = 0;
5663 *r->out.server_major_version = 0;
5664 *r->out.server_minor_version = 0;
5666 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5667 return WERR_BADFID;
5670 if (r->in.client_major_version == SPOOLSS_DRIVER_VERSION_2012) {
5671 DEBUG(3,("_spoolss_GetPrinterDriver2: v4 driver requested, "
5672 "downgrading to v3\n"));
5673 version = SPOOLSS_DRIVER_VERSION_200X;
5676 result = construct_printer_driver_info_level(p->mem_ctx,
5677 get_session_info_system(),
5678 p->msg_ctx,
5679 r->in.level, r->out.info,
5680 snum, printer->servername,
5681 r->in.architecture,
5682 version);
5683 if (!W_ERROR_IS_OK(result)) {
5684 TALLOC_FREE(r->out.info);
5685 return result;
5688 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5689 r->out.info, r->in.level);
5690 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5692 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5696 /****************************************************************
5697 _spoolss_StartPagePrinter
5698 ****************************************************************/
5700 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5701 struct spoolss_StartPagePrinter *r)
5703 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5705 if (!Printer) {
5706 DEBUG(3,("_spoolss_StartPagePrinter: "
5707 "Error in startpageprinter printer handle\n"));
5708 return WERR_BADFID;
5711 Printer->page_started = true;
5712 return WERR_OK;
5715 /****************************************************************
5716 _spoolss_EndPagePrinter
5717 ****************************************************************/
5719 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5720 struct spoolss_EndPagePrinter *r)
5722 int snum;
5724 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5726 if (!Printer) {
5727 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5728 OUR_HANDLE(r->in.handle)));
5729 return WERR_BADFID;
5732 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5733 return WERR_BADFID;
5735 Printer->page_started = false;
5736 print_job_endpage(p->msg_ctx, snum, Printer->jobid);
5738 return WERR_OK;
5741 /****************************************************************
5742 _spoolss_StartDocPrinter
5743 ****************************************************************/
5745 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5746 struct spoolss_StartDocPrinter *r)
5748 struct spoolss_DocumentInfo1 *info_1;
5749 int snum;
5750 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5751 WERROR werr;
5752 char *rhost;
5753 int rc;
5755 if (!Printer) {
5756 DEBUG(2,("_spoolss_StartDocPrinter: "
5757 "Invalid handle (%s:%u:%u)\n",
5758 OUR_HANDLE(r->in.handle)));
5759 return WERR_BADFID;
5762 if (Printer->jobid) {
5763 DEBUG(2, ("_spoolss_StartDocPrinter: "
5764 "StartDocPrinter called twice! "
5765 "(existing jobid = %d)\n", Printer->jobid));
5766 return WERR_INVALID_HANDLE;
5769 if (r->in.info_ctr->level != 1) {
5770 return WERR_UNKNOWN_LEVEL;
5773 info_1 = r->in.info_ctr->info.info1;
5776 * a nice thing with NT is it doesn't listen to what you tell it.
5777 * when asked to send _only_ RAW datas, it tries to send datas
5778 * in EMF format.
5780 * So I add checks like in NT Server ...
5783 if (info_1->datatype) {
5784 if (strcmp(info_1->datatype, "RAW") != 0) {
5785 *r->out.job_id = 0;
5786 return WERR_INVALID_DATATYPE;
5790 /* get the share number of the printer */
5791 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5792 return WERR_BADFID;
5795 rc = get_remote_hostname(p->remote_address,
5796 &rhost,
5797 p->mem_ctx);
5798 if (rc < 0) {
5799 return WERR_NOMEM;
5801 if (strequal(rhost,"UNKNOWN")) {
5802 rhost = tsocket_address_inet_addr_string(p->remote_address,
5803 p->mem_ctx);
5804 if (rhost == NULL) {
5805 return WERR_NOMEM;
5809 werr = print_job_start(p->session_info,
5810 p->msg_ctx,
5811 rhost,
5812 snum,
5813 info_1->document_name,
5814 info_1->output_file,
5815 Printer->devmode,
5816 &Printer->jobid);
5818 /* An error occured in print_job_start() so return an appropriate
5819 NT error code. */
5821 if (!W_ERROR_IS_OK(werr)) {
5822 return werr;
5825 Printer->document_started = true;
5826 *r->out.job_id = Printer->jobid;
5828 return WERR_OK;
5831 /****************************************************************
5832 _spoolss_EndDocPrinter
5833 ****************************************************************/
5835 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5836 struct spoolss_EndDocPrinter *r)
5838 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5839 NTSTATUS status;
5840 int snum;
5842 if (!Printer) {
5843 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5844 OUR_HANDLE(r->in.handle)));
5845 return WERR_BADFID;
5848 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5849 return WERR_BADFID;
5852 Printer->document_started = false;
5853 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5854 if (!NT_STATUS_IS_OK(status)) {
5855 DEBUG(2, ("_spoolss_EndDocPrinter: "
5856 "print_job_end failed [%s]\n",
5857 nt_errstr(status)));
5860 Printer->jobid = 0;
5861 return ntstatus_to_werror(status);
5864 /****************************************************************
5865 _spoolss_WritePrinter
5866 ****************************************************************/
5868 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5869 struct spoolss_WritePrinter *r)
5871 ssize_t buffer_written;
5872 int snum;
5873 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5875 if (!Printer) {
5876 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5877 OUR_HANDLE(r->in.handle)));
5878 *r->out.num_written = r->in._data_size;
5879 return WERR_BADFID;
5882 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5883 return WERR_BADFID;
5885 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5886 buffer_written = print_job_write(server_event_context(),p->msg_ctx,
5887 snum, Printer->jobid,
5888 (const char *)r->in.data.data,
5889 (size_t)r->in._data_size);
5890 if (buffer_written == (ssize_t)-1) {
5891 *r->out.num_written = 0;
5892 if (errno == ENOSPC)
5893 return WERR_NO_SPOOL_SPACE;
5894 else
5895 return WERR_ACCESS_DENIED;
5898 *r->out.num_written = r->in._data_size;
5900 return WERR_OK;
5903 /********************************************************************
5904 * api_spoolss_getprinter
5905 * called from the spoolss dispatcher
5907 ********************************************************************/
5909 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5910 struct pipes_struct *p)
5912 const struct auth_session_info *session_info = p->session_info;
5913 int snum;
5914 WERROR errcode = WERR_BADFUNC;
5915 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5917 if (!Printer) {
5918 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5919 OUR_HANDLE(handle)));
5920 return WERR_BADFID;
5923 if (!get_printer_snum(p, handle, &snum, NULL))
5924 return WERR_BADFID;
5926 switch (command) {
5927 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5928 errcode = print_queue_pause(session_info, p->msg_ctx, snum);
5929 break;
5930 case SPOOLSS_PRINTER_CONTROL_RESUME:
5931 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5932 errcode = print_queue_resume(session_info, p->msg_ctx, snum);
5933 break;
5934 case SPOOLSS_PRINTER_CONTROL_PURGE:
5935 errcode = print_queue_purge(session_info, p->msg_ctx, snum);
5936 break;
5937 default:
5938 return WERR_UNKNOWN_LEVEL;
5941 return errcode;
5945 /****************************************************************
5946 _spoolss_AbortPrinter
5947 * From MSDN: "Deletes printer's spool file if printer is configured
5948 * for spooling"
5949 ****************************************************************/
5951 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5952 struct spoolss_AbortPrinter *r)
5954 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5955 int snum;
5956 WERROR errcode = WERR_OK;
5958 if (!Printer) {
5959 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5960 OUR_HANDLE(r->in.handle)));
5961 return WERR_BADFID;
5964 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5965 return WERR_BADFID;
5967 if (!Printer->document_started) {
5968 return WERR_SPL_NO_STARTDOC;
5971 errcode = print_job_delete(p->session_info,
5972 p->msg_ctx,
5973 snum,
5974 Printer->jobid);
5976 return errcode;
5979 /********************************************************************
5980 * called by spoolss_api_setprinter
5981 * when updating a printer description
5982 ********************************************************************/
5984 static WERROR update_printer_sec(struct policy_handle *handle,
5985 struct pipes_struct *p,
5986 struct sec_desc_buf *secdesc_ctr)
5988 struct spoolss_security_descriptor *new_secdesc = NULL;
5989 struct spoolss_security_descriptor *old_secdesc = NULL;
5990 const char *printer;
5991 WERROR result;
5992 int snum;
5993 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5994 struct dcerpc_binding_handle *b;
5995 TALLOC_CTX *tmp_ctx = NULL;
5997 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5998 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5999 OUR_HANDLE(handle)));
6001 result = WERR_BADFID;
6002 goto done;
6005 if (secdesc_ctr == NULL) {
6006 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
6007 result = WERR_INVALID_PARAM;
6008 goto done;
6010 printer = lp_const_servicename(snum);
6012 /* Check the user has permissions to change the security
6013 descriptor. By experimentation with two NT machines, the user
6014 requires Full Access to the printer to change security
6015 information. */
6017 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
6018 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
6019 result = WERR_ACCESS_DENIED;
6020 goto done;
6023 tmp_ctx = talloc_new(p->mem_ctx);
6024 if (!tmp_ctx) {
6025 return WERR_NOMEM;
6028 result = winreg_printer_binding_handle(tmp_ctx,
6029 get_session_info_system(),
6030 p->msg_ctx,
6031 &b);
6032 if (!W_ERROR_IS_OK(result)) {
6033 goto done;
6036 /* NT seems to like setting the security descriptor even though
6037 nothing may have actually changed. */
6038 result = winreg_get_printer_secdesc(tmp_ctx, b,
6039 printer,
6040 &old_secdesc);
6041 if (!W_ERROR_IS_OK(result)) {
6042 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc_internal() failed\n"));
6043 result = WERR_BADFID;
6044 goto done;
6047 if (DEBUGLEVEL >= 10) {
6048 struct security_acl *the_acl;
6049 int i;
6051 the_acl = old_secdesc->dacl;
6052 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
6053 printer, the_acl->num_aces));
6055 for (i = 0; i < the_acl->num_aces; i++) {
6056 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6057 &the_acl->aces[i].trustee),
6058 the_acl->aces[i].access_mask));
6061 the_acl = secdesc_ctr->sd->dacl;
6063 if (the_acl) {
6064 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
6065 printer, the_acl->num_aces));
6067 for (i = 0; i < the_acl->num_aces; i++) {
6068 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6069 &the_acl->aces[i].trustee),
6070 the_acl->aces[i].access_mask));
6072 } else {
6073 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
6077 new_secdesc = sec_desc_merge(tmp_ctx, secdesc_ctr->sd, old_secdesc);
6078 if (new_secdesc == NULL) {
6079 result = WERR_NOMEM;
6080 goto done;
6083 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
6084 result = WERR_OK;
6085 goto done;
6088 result = winreg_set_printer_secdesc(tmp_ctx, b,
6089 printer,
6090 new_secdesc);
6092 done:
6093 talloc_free(tmp_ctx);
6094 return result;
6097 /********************************************************************
6098 Canonicalize printer info from a client
6099 ********************************************************************/
6101 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
6102 struct spoolss_SetPrinterInfo2 *info2,
6103 int snum)
6105 fstring printername;
6106 const char *p;
6108 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
6109 "portname=%s drivername=%s comment=%s location=%s\n",
6110 info2->servername, info2->printername, info2->sharename,
6111 info2->portname, info2->drivername, info2->comment,
6112 info2->location));
6114 /* we force some elements to "correct" values */
6115 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", lp_netbios_name());
6116 if (info2->servername == NULL) {
6117 return false;
6119 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
6120 if (info2->sharename == NULL) {
6121 return false;
6124 /* check to see if we allow printername != sharename */
6125 if (lp_force_printername(snum)) {
6126 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6127 lp_netbios_name(), info2->sharename);
6128 } else {
6129 /* make sure printername is in \\server\printername format */
6130 fstrcpy(printername, info2->printername);
6131 p = printername;
6132 if ( printername[0] == '\\' && printername[1] == '\\' ) {
6133 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
6134 p++;
6137 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6138 lp_netbios_name(), p);
6140 if (info2->printername == NULL) {
6141 return false;
6144 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
6145 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
6147 return true;
6150 /****************************************************************************
6151 ****************************************************************************/
6153 static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const char *portname, const char *uri)
6155 char *cmd = lp_addport_cmd(talloc_tos());
6156 char *command = NULL;
6157 int ret;
6158 bool is_print_op = false;
6160 if ( !*cmd ) {
6161 return WERR_ACCESS_DENIED;
6164 command = talloc_asprintf(ctx,
6165 "%s \"%s\" \"%s\"", cmd, portname, uri );
6166 if (!command) {
6167 return WERR_NOMEM;
6170 if ( token )
6171 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6173 DEBUG(10,("Running [%s]\n", command));
6175 /********* BEGIN SePrintOperatorPrivilege **********/
6177 if ( is_print_op )
6178 become_root();
6180 ret = smbrun(command, NULL);
6182 if ( is_print_op )
6183 unbecome_root();
6185 /********* END SePrintOperatorPrivilege **********/
6187 DEBUGADD(10,("returned [%d]\n", ret));
6189 TALLOC_FREE(command);
6191 if ( ret != 0 ) {
6192 return WERR_ACCESS_DENIED;
6195 return WERR_OK;
6198 /****************************************************************************
6199 ****************************************************************************/
6201 static bool spoolss_conn_snum_used(struct smbd_server_connection *sconn,
6202 int snum)
6205 * As we do not know if we are embedded in the file server process
6206 * or not, we have to pretend that all shares are in use.
6208 return true;
6211 static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
6212 struct spoolss_SetPrinterInfo2 *info2,
6213 const char *remote_machine,
6214 struct messaging_context *msg_ctx)
6216 char *cmd = lp_addprinter_cmd(talloc_tos());
6217 char **qlines;
6218 char *command = NULL;
6219 int numlines;
6220 int ret;
6221 int fd;
6222 bool is_print_op = false;
6224 if (!remote_machine) {
6225 return false;
6228 command = talloc_asprintf(ctx,
6229 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6230 cmd, info2->printername, info2->sharename,
6231 info2->portname, info2->drivername,
6232 info2->location, info2->comment, remote_machine);
6233 if (!command) {
6234 return false;
6237 if ( token )
6238 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6240 DEBUG(10,("Running [%s]\n", command));
6242 /********* BEGIN SePrintOperatorPrivilege **********/
6244 if ( is_print_op )
6245 become_root();
6247 if ( (ret = smbrun(command, &fd)) == 0 ) {
6248 /* Tell everyone we updated smb.conf. */
6249 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6252 if ( is_print_op )
6253 unbecome_root();
6255 /********* END SePrintOperatorPrivilege **********/
6257 DEBUGADD(10,("returned [%d]\n", ret));
6259 TALLOC_FREE(command);
6261 if ( ret != 0 ) {
6262 if (fd != -1)
6263 close(fd);
6264 return false;
6267 /* reload our services immediately */
6268 become_root();
6269 reload_services(NULL, spoolss_conn_snum_used, false);
6270 unbecome_root();
6272 numlines = 0;
6273 /* Get lines and convert them back to dos-codepage */
6274 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6275 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6276 close(fd);
6278 /* Set the portname to what the script says the portname should be. */
6279 /* but don't require anything to be return from the script exit a good error code */
6281 if (numlines) {
6282 /* Set the portname to what the script says the portname should be. */
6283 info2->portname = talloc_strdup(ctx, qlines[0]);
6284 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6287 TALLOC_FREE(qlines);
6288 return true;
6291 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
6292 const struct auth_session_info *session_info,
6293 struct messaging_context *msg_ctx,
6294 int snum,
6295 struct spoolss_SetPrinterInfo2 *printer,
6296 struct spoolss_PrinterInfo2 *old_printer)
6298 bool force_update = (old_printer == NULL);
6299 const char *dnsdomname;
6300 const char *longname;
6301 const char *uncname;
6302 const char *spooling;
6303 DATA_BLOB buffer;
6304 WERROR result = WERR_OK;
6305 struct dcerpc_binding_handle *b;
6306 TALLOC_CTX *tmp_ctx;
6307 bool ok;
6309 tmp_ctx = talloc_new(mem_ctx);
6310 if (!tmp_ctx) {
6311 return WERR_NOMEM;
6314 result = winreg_printer_binding_handle(tmp_ctx,
6315 session_info,
6316 msg_ctx,
6317 &b);
6318 if (!W_ERROR_IS_OK(result)) {
6319 goto done;
6322 if (printer->drivername != NULL &&
6323 (force_update ||
6324 !strequal(printer->drivername, old_printer->drivername))) {
6325 ok = push_reg_sz(tmp_ctx, &buffer, printer->drivername);
6326 if (!ok) {
6327 DEBUG(0, ("%s data corrupted\n", SPOOL_REG_DRIVERNAME));
6328 result = WERR_INVALID_DATA;
6329 goto done;
6331 result = winreg_set_printer_dataex(tmp_ctx, b,
6332 printer->sharename,
6333 SPOOL_DSSPOOLER_KEY,
6334 SPOOL_REG_DRIVERNAME,
6335 REG_SZ,
6336 buffer.data,
6337 buffer.length);
6338 if (!W_ERROR_IS_OK(result)) {
6339 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DRIVERNAME));
6340 goto done;
6343 if (!force_update) {
6344 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6345 printer->drivername));
6347 notify_printer_driver(server_event_context(), msg_ctx,
6348 snum, printer->drivername ?
6349 printer->drivername : "");
6353 if (printer->comment != NULL &&
6354 (force_update ||
6355 !strequal(printer->comment, old_printer->comment))) {
6356 ok = push_reg_sz(tmp_ctx, &buffer, printer->comment);
6357 if (!ok) {
6358 DEBUG(0, ("comment data corrupted\n"));
6359 result = WERR_INVALID_DATA;
6360 goto done;
6362 result = winreg_set_printer_dataex(tmp_ctx, b,
6363 printer->sharename,
6364 SPOOL_DSSPOOLER_KEY,
6365 SPOOL_REG_DESCRIPTION,
6366 REG_SZ,
6367 buffer.data,
6368 buffer.length);
6369 if (!W_ERROR_IS_OK(result)) {
6370 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DESCRIPTION));
6371 goto done;
6374 if (!force_update) {
6375 notify_printer_comment(server_event_context(), msg_ctx,
6376 snum, printer->comment ?
6377 printer->comment : "");
6381 if (printer->sharename != NULL &&
6382 (force_update ||
6383 !strequal(printer->sharename, old_printer->sharename))) {
6384 ok = push_reg_sz(tmp_ctx, &buffer, printer->sharename);
6385 if (!ok) {
6386 DEBUG(0, ("sharename data corrupted\n"));
6387 result = WERR_INVALID_DATA;
6388 goto done;
6390 result = winreg_set_printer_dataex(tmp_ctx, b,
6391 printer->sharename,
6392 SPOOL_DSSPOOLER_KEY,
6393 SPOOL_REG_PRINTSHARENAME,
6394 REG_SZ,
6395 buffer.data,
6396 buffer.length);
6397 if (!W_ERROR_IS_OK(result)) {
6398 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME));
6399 goto done;
6402 if (!force_update) {
6403 notify_printer_sharename(server_event_context(),
6404 msg_ctx,
6405 snum, printer->sharename ?
6406 printer->sharename : "");
6410 if (printer->printername != NULL &&
6411 (force_update ||
6412 !strequal(printer->printername, old_printer->printername))) {
6413 const char *p;
6415 p = strrchr(printer->printername, '\\' );
6416 if (p != NULL) {
6417 p++;
6418 } else {
6419 p = printer->printername;
6422 ok = push_reg_sz(tmp_ctx, &buffer, p);
6423 if (!ok) {
6424 DEBUG(0, ("printername data corrupted\n"));
6425 result = WERR_INVALID_DATA;
6426 goto done;
6428 result = winreg_set_printer_dataex(tmp_ctx, b,
6429 printer->sharename,
6430 SPOOL_DSSPOOLER_KEY,
6431 SPOOL_REG_PRINTERNAME,
6432 REG_SZ,
6433 buffer.data,
6434 buffer.length);
6435 if (!W_ERROR_IS_OK(result)) {
6436 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME));
6437 goto done;
6440 if (!force_update) {
6441 notify_printer_printername(server_event_context(),
6442 msg_ctx, snum, p ? p : "");
6446 if (printer->portname != NULL &&
6447 (force_update ||
6448 !strequal(printer->portname, old_printer->portname))) {
6449 ok = push_reg_sz(tmp_ctx, &buffer, printer->portname);
6450 if (!ok) {
6451 DEBUG(0, ("portname data corrupted\n"));
6452 result = WERR_INVALID_DATA;
6453 goto done;
6455 result = winreg_set_printer_dataex(tmp_ctx, b,
6456 printer->sharename,
6457 SPOOL_DSSPOOLER_KEY,
6458 SPOOL_REG_PORTNAME,
6459 REG_SZ,
6460 buffer.data,
6461 buffer.length);
6462 if (!W_ERROR_IS_OK(result)) {
6463 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PORTNAME));
6464 goto done;
6467 if (!force_update) {
6468 notify_printer_port(server_event_context(),
6469 msg_ctx, snum, printer->portname ?
6470 printer->portname : "");
6474 if (printer->location != NULL &&
6475 (force_update ||
6476 !strequal(printer->location, old_printer->location))) {
6477 ok = push_reg_sz(tmp_ctx, &buffer, printer->location);
6478 if (!ok) {
6479 DEBUG(0, ("location data corrupted\n"));
6480 result = WERR_INVALID_DATA;
6481 goto done;
6483 result = winreg_set_printer_dataex(tmp_ctx, b,
6484 printer->sharename,
6485 SPOOL_DSSPOOLER_KEY,
6486 SPOOL_REG_LOCATION,
6487 REG_SZ,
6488 buffer.data,
6489 buffer.length);
6490 if (!W_ERROR_IS_OK(result)) {
6491 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_LOCATION));
6492 goto done;
6495 if (!force_update) {
6496 notify_printer_location(server_event_context(),
6497 msg_ctx, snum,
6498 printer->location ?
6499 printer->location : "");
6503 if (printer->sepfile != NULL &&
6504 (force_update ||
6505 !strequal(printer->sepfile, old_printer->sepfile))) {
6506 ok = push_reg_sz(tmp_ctx, &buffer, printer->sepfile);
6507 if (!ok) {
6508 DEBUG(0, ("sepfile data corrupted\n"));
6509 result = WERR_INVALID_DATA;
6510 goto done;
6512 result = winreg_set_printer_dataex(tmp_ctx, b,
6513 printer->sharename,
6514 SPOOL_DSSPOOLER_KEY,
6515 SPOOL_REG_PRINTSEPARATORFILE,
6516 REG_SZ,
6517 buffer.data,
6518 buffer.length);
6519 if (!W_ERROR_IS_OK(result)) {
6520 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSEPARATORFILE));
6521 goto done;
6524 if (!force_update) {
6525 notify_printer_sepfile(server_event_context(),
6526 msg_ctx, snum,
6527 printer->sepfile ?
6528 printer->sepfile : "");
6532 if (printer->starttime != 0 &&
6533 (force_update ||
6534 printer->starttime != old_printer->starttime)) {
6535 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6536 SIVAL(buffer.data, 0, printer->starttime);
6537 result = winreg_set_printer_dataex(tmp_ctx, b,
6538 printer->sharename,
6539 SPOOL_DSSPOOLER_KEY,
6540 SPOOL_REG_PRINTSTARTTIME,
6541 REG_DWORD,
6542 buffer.data,
6543 buffer.length);
6544 if (!W_ERROR_IS_OK(result)) {
6545 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSTARTTIME));
6546 goto done;
6550 if (printer->untiltime != 0 &&
6551 (force_update ||
6552 printer->untiltime != old_printer->untiltime)) {
6553 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6554 SIVAL(buffer.data, 0, printer->untiltime);
6555 result = winreg_set_printer_dataex(tmp_ctx, b,
6556 printer->sharename,
6557 SPOOL_DSSPOOLER_KEY,
6558 SPOOL_REG_PRINTENDTIME,
6559 REG_DWORD,
6560 buffer.data,
6561 buffer.length);
6562 if (!W_ERROR_IS_OK(result)) {
6563 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME));
6564 goto done;
6568 if (force_update || printer->priority != old_printer->priority) {
6569 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6570 SIVAL(buffer.data, 0, printer->priority);
6571 result = winreg_set_printer_dataex(tmp_ctx, b,
6572 printer->sharename,
6573 SPOOL_DSSPOOLER_KEY,
6574 SPOOL_REG_PRIORITY,
6575 REG_DWORD,
6576 buffer.data,
6577 buffer.length);
6578 if (!W_ERROR_IS_OK(result)) {
6579 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME));
6580 goto done;
6584 if (force_update || printer->attributes != old_printer->attributes) {
6585 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6586 SIVAL(buffer.data, 0, (printer->attributes &
6587 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
6588 result = winreg_set_printer_dataex(tmp_ctx, b,
6589 printer->sharename,
6590 SPOOL_DSSPOOLER_KEY,
6591 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
6592 REG_DWORD,
6593 buffer.data,
6594 buffer.length);
6595 if (!W_ERROR_IS_OK(result)) {
6596 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME));
6597 goto done;
6600 switch (printer->attributes & 0x3) {
6601 case 0:
6602 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
6603 break;
6604 case 1:
6605 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
6606 break;
6607 case 2:
6608 spooling = SPOOL_REGVAL_PRINTDIRECT;
6609 break;
6610 default:
6611 spooling = "unknown";
6613 ok = push_reg_sz(tmp_ctx, &buffer, spooling);
6614 if (!ok) {
6615 DEBUG(0, ("printSpooling data corrupted\n"));
6616 result = WERR_INVALID_DATA;
6617 goto done;
6619 winreg_set_printer_dataex(tmp_ctx, b,
6620 printer->sharename,
6621 SPOOL_DSSPOOLER_KEY,
6622 SPOOL_REG_PRINTSPOOLING,
6623 REG_SZ,
6624 buffer.data,
6625 buffer.length);
6628 ok = push_reg_sz(tmp_ctx, &buffer, lp_netbios_name());
6629 if (!ok) {
6630 DEBUG(0, ("shortServerName data corrupted\n"));
6631 result = WERR_INVALID_DATA;
6632 goto done;
6634 result = winreg_set_printer_dataex(tmp_ctx, b,
6635 printer->sharename,
6636 SPOOL_DSSPOOLER_KEY,
6637 SPOOL_REG_SHORTSERVERNAME,
6638 REG_SZ,
6639 buffer.data,
6640 buffer.length);
6641 if (!W_ERROR_IS_OK(result)) {
6642 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SHORTSERVERNAME));
6643 goto done;
6646 dnsdomname = get_mydnsfullname();
6647 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
6648 longname = talloc_strdup(tmp_ctx, dnsdomname);
6649 } else {
6650 longname = talloc_strdup(tmp_ctx, lp_netbios_name());
6652 if (longname == NULL) {
6653 result = WERR_NOMEM;
6654 goto done;
6657 ok = push_reg_sz(tmp_ctx, &buffer, longname);
6658 if (!ok) {
6659 DEBUG(0, ("longname data corrupted\n"));
6660 result = WERR_INVALID_DATA;
6661 goto done;
6663 result = winreg_set_printer_dataex(tmp_ctx, b,
6664 printer->sharename,
6665 SPOOL_DSSPOOLER_KEY,
6666 SPOOL_REG_SERVERNAME,
6667 REG_SZ,
6668 buffer.data,
6669 buffer.length);
6670 if (!W_ERROR_IS_OK(result)) {
6671 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SERVERNAME));
6672 goto done;
6675 uncname = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
6676 lp_netbios_name(), printer->sharename);
6677 ok = push_reg_sz(tmp_ctx, &buffer, uncname);
6678 if (!ok) {
6679 DEBUG(0, ("uncName data corrupted\n"));
6680 result = WERR_INVALID_DATA;
6681 goto done;
6683 result = winreg_set_printer_dataex(tmp_ctx, b,
6684 printer->sharename,
6685 SPOOL_DSSPOOLER_KEY,
6686 SPOOL_REG_UNCNAME,
6687 REG_SZ,
6688 buffer.data,
6689 buffer.length);
6690 if (!W_ERROR_IS_OK(result)) {
6691 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_UNCNAME));
6692 goto done;
6695 done:
6696 talloc_free(tmp_ctx);
6697 return result;
6700 /********************************************************************
6701 * Called by spoolss_api_setprinter
6702 * when updating a printer description.
6703 ********************************************************************/
6705 static WERROR update_printer(struct pipes_struct *p,
6706 struct policy_handle *handle,
6707 struct spoolss_SetPrinterInfoCtr *info_ctr,
6708 struct spoolss_DeviceMode *devmode)
6710 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6711 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6712 struct spoolss_PrinterInfo2 *old_printer;
6713 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6714 int snum;
6715 WERROR result = WERR_OK;
6716 TALLOC_CTX *tmp_ctx;
6717 struct dcerpc_binding_handle *b;
6719 DEBUG(8,("update_printer\n"));
6721 tmp_ctx = talloc_new(p->mem_ctx);
6722 if (tmp_ctx == NULL) {
6723 return WERR_NOMEM;
6726 if (!Printer) {
6727 result = WERR_BADFID;
6728 goto done;
6731 if (!get_printer_snum(p, handle, &snum, NULL)) {
6732 result = WERR_BADFID;
6733 goto done;
6736 result = winreg_printer_binding_handle(tmp_ctx,
6737 get_session_info_system(),
6738 p->msg_ctx,
6739 &b);
6740 if (!W_ERROR_IS_OK(result)) {
6741 goto done;
6744 result = winreg_get_printer(tmp_ctx, b,
6745 lp_const_servicename(snum),
6746 &old_printer);
6747 if (!W_ERROR_IS_OK(result)) {
6748 result = WERR_BADFID;
6749 goto done;
6752 /* Do sanity check on the requested changes for Samba */
6753 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6754 result = WERR_INVALID_PARAM;
6755 goto done;
6758 /* FIXME!!! If the driver has changed we really should verify that
6759 it is installed before doing much else --jerry */
6761 /* Check calling user has permission to update printer description */
6762 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6763 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6764 result = WERR_ACCESS_DENIED;
6765 goto done;
6768 /* Call addprinter hook */
6769 /* Check changes to see if this is really needed */
6771 if (*lp_addprinter_cmd(talloc_tos()) &&
6772 (!strequal(printer->drivername, old_printer->drivername) ||
6773 !strequal(printer->comment, old_printer->comment) ||
6774 !strequal(printer->portname, old_printer->portname) ||
6775 !strequal(printer->location, old_printer->location)) )
6777 char *raddr;
6779 raddr = tsocket_address_inet_addr_string(p->remote_address,
6780 p->mem_ctx);
6781 if (raddr == NULL) {
6782 return WERR_NOMEM;
6785 /* add_printer_hook() will call reload_services() */
6786 if (!add_printer_hook(tmp_ctx, p->session_info->security_token,
6787 printer, raddr,
6788 p->msg_ctx)) {
6789 result = WERR_ACCESS_DENIED;
6790 goto done;
6794 result = update_dsspooler(tmp_ctx,
6795 get_session_info_system(),
6796 p->msg_ctx,
6797 snum,
6798 printer,
6799 old_printer);
6800 if (!W_ERROR_IS_OK(result)) {
6801 goto done;
6804 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6806 if (devmode == NULL) {
6807 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6809 result = winreg_update_printer(tmp_ctx, b,
6810 printer->sharename,
6811 printer_mask,
6812 printer,
6813 devmode,
6814 NULL);
6816 done:
6817 talloc_free(tmp_ctx);
6819 return result;
6822 /****************************************************************************
6823 ****************************************************************************/
6824 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6825 struct policy_handle *handle,
6826 struct spoolss_SetPrinterInfo7 *info7)
6828 #ifdef HAVE_ADS
6829 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6830 WERROR result;
6831 int snum;
6832 struct printer_handle *Printer;
6834 if ( lp_security() != SEC_ADS ) {
6835 return WERR_UNKNOWN_LEVEL;
6838 Printer = find_printer_index_by_hnd(p, handle);
6840 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6842 if (!Printer)
6843 return WERR_BADFID;
6845 if (!get_printer_snum(p, handle, &snum, NULL))
6846 return WERR_BADFID;
6848 result = winreg_get_printer_internal(p->mem_ctx,
6849 get_session_info_system(),
6850 p->msg_ctx,
6851 lp_servicename(talloc_tos(), snum),
6852 &pinfo2);
6853 if (!W_ERROR_IS_OK(result)) {
6854 return WERR_BADFID;
6857 nt_printer_publish(pinfo2,
6858 get_session_info_system(),
6859 p->msg_ctx,
6860 pinfo2,
6861 info7->action);
6863 TALLOC_FREE(pinfo2);
6864 return WERR_OK;
6865 #else
6866 return WERR_UNKNOWN_LEVEL;
6867 #endif
6870 /********************************************************************
6871 ********************************************************************/
6873 static WERROR update_printer_devmode(struct pipes_struct *p,
6874 struct policy_handle *handle,
6875 struct spoolss_DeviceMode *devmode)
6877 int snum;
6878 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6879 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6881 DEBUG(8,("update_printer_devmode\n"));
6883 if (!Printer) {
6884 return WERR_BADFID;
6887 if (!get_printer_snum(p, handle, &snum, NULL)) {
6888 return WERR_BADFID;
6891 /* Check calling user has permission to update printer description */
6892 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6893 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6894 return WERR_ACCESS_DENIED;
6897 return winreg_update_printer_internal(p->mem_ctx,
6898 get_session_info_system(),
6899 p->msg_ctx,
6900 lp_const_servicename(snum),
6901 info2_mask,
6902 NULL,
6903 devmode,
6904 NULL);
6908 /****************************************************************
6909 _spoolss_SetPrinter
6910 ****************************************************************/
6912 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6913 struct spoolss_SetPrinter *r)
6915 WERROR result;
6917 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6919 if (!Printer) {
6920 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6921 OUR_HANDLE(r->in.handle)));
6922 return WERR_BADFID;
6925 /* check the level */
6926 switch (r->in.info_ctr->level) {
6927 case 0:
6928 return control_printer(r->in.handle, r->in.command, p);
6929 case 2:
6930 result = update_printer(p, r->in.handle,
6931 r->in.info_ctr,
6932 r->in.devmode_ctr->devmode);
6933 if (!W_ERROR_IS_OK(result))
6934 return result;
6935 if (r->in.secdesc_ctr->sd)
6936 result = update_printer_sec(r->in.handle, p,
6937 r->in.secdesc_ctr);
6938 return result;
6939 case 3:
6940 return update_printer_sec(r->in.handle, p,
6941 r->in.secdesc_ctr);
6942 case 7:
6943 return publish_or_unpublish_printer(p, r->in.handle,
6944 r->in.info_ctr->info.info7);
6945 case 8:
6946 return update_printer_devmode(p, r->in.handle,
6947 r->in.devmode_ctr->devmode);
6948 default:
6949 return WERR_UNKNOWN_LEVEL;
6953 /****************************************************************
6954 _spoolss_FindClosePrinterNotify
6955 ****************************************************************/
6957 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6958 struct spoolss_FindClosePrinterNotify *r)
6960 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6962 if (!Printer) {
6963 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6964 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6965 return WERR_BADFID;
6968 if (Printer->notify.cli_chan != NULL &&
6969 Printer->notify.cli_chan->active_connections > 0) {
6970 int snum = -1;
6972 if (Printer->printer_type == SPLHND_PRINTER) {
6973 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6974 return WERR_BADFID;
6978 srv_spoolss_replycloseprinter(snum, Printer);
6981 Printer->notify.flags=0;
6982 Printer->notify.options=0;
6983 Printer->notify.localmachine[0]='\0';
6984 Printer->notify.printerlocal=0;
6985 TALLOC_FREE(Printer->notify.option);
6987 return WERR_OK;
6990 /****************************************************************
6991 _spoolss_AddJob
6992 ****************************************************************/
6994 WERROR _spoolss_AddJob(struct pipes_struct *p,
6995 struct spoolss_AddJob *r)
6997 if (!r->in.buffer && (r->in.offered != 0)) {
6998 return WERR_INVALID_PARAM;
7001 /* this is what a NT server returns for AddJob. AddJob must fail on
7002 * non-local printers */
7004 if (r->in.level != 1) {
7005 return WERR_UNKNOWN_LEVEL;
7008 return WERR_INVALID_PARAM;
7011 /****************************************************************************
7012 fill_job_info1
7013 ****************************************************************************/
7015 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
7016 struct spoolss_JobInfo1 *r,
7017 const print_queue_struct *queue,
7018 int position, int snum,
7019 struct spoolss_PrinterInfo2 *pinfo2)
7021 struct tm *t;
7023 t = gmtime(&queue->time);
7025 r->job_id = queue->sysjob;
7027 r->printer_name = lp_servicename(mem_ctx, snum);
7028 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
7029 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
7030 W_ERROR_HAVE_NO_MEMORY(r->server_name);
7031 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
7032 W_ERROR_HAVE_NO_MEMORY(r->user_name);
7033 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
7034 W_ERROR_HAVE_NO_MEMORY(r->document_name);
7035 r->data_type = talloc_strdup(mem_ctx, "RAW");
7036 W_ERROR_HAVE_NO_MEMORY(r->data_type);
7037 r->text_status = talloc_strdup(mem_ctx, "");
7038 W_ERROR_HAVE_NO_MEMORY(r->text_status);
7040 r->status = nt_printj_status(queue->status);
7041 r->priority = queue->priority;
7042 r->position = position;
7043 r->total_pages = queue->page_count;
7044 r->pages_printed = 0; /* ??? */
7046 init_systemtime(&r->submitted, t);
7048 return WERR_OK;
7051 /****************************************************************************
7052 fill_job_info2
7053 ****************************************************************************/
7055 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
7056 struct spoolss_JobInfo2 *r,
7057 const print_queue_struct *queue,
7058 int position, int snum,
7059 struct spoolss_PrinterInfo2 *pinfo2,
7060 struct spoolss_DeviceMode *devmode)
7062 struct tm *t;
7064 t = gmtime(&queue->time);
7066 r->job_id = queue->sysjob;
7068 r->printer_name = lp_servicename(mem_ctx, snum);
7069 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
7070 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
7071 W_ERROR_HAVE_NO_MEMORY(r->server_name);
7072 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
7073 W_ERROR_HAVE_NO_MEMORY(r->user_name);
7074 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
7075 W_ERROR_HAVE_NO_MEMORY(r->document_name);
7076 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
7077 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
7078 r->data_type = talloc_strdup(mem_ctx, "RAW");
7079 W_ERROR_HAVE_NO_MEMORY(r->data_type);
7080 r->print_processor = talloc_strdup(mem_ctx, "winprint");
7081 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
7082 r->parameters = talloc_strdup(mem_ctx, "");
7083 W_ERROR_HAVE_NO_MEMORY(r->parameters);
7084 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
7085 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
7087 r->devmode = devmode;
7089 r->text_status = talloc_strdup(mem_ctx, "");
7090 W_ERROR_HAVE_NO_MEMORY(r->text_status);
7092 r->secdesc = NULL;
7094 r->status = nt_printj_status(queue->status);
7095 r->priority = queue->priority;
7096 r->position = position;
7097 r->start_time = 0;
7098 r->until_time = 0;
7099 r->total_pages = queue->page_count;
7100 r->size = queue->size;
7101 init_systemtime(&r->submitted, t);
7102 r->time = 0;
7103 r->pages_printed = 0; /* ??? */
7105 return WERR_OK;
7108 /****************************************************************************
7109 fill_job_info3
7110 ****************************************************************************/
7112 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
7113 struct spoolss_JobInfo3 *r,
7114 const print_queue_struct *queue,
7115 const print_queue_struct *next_queue,
7116 int position, int snum,
7117 struct spoolss_PrinterInfo2 *pinfo2)
7119 r->job_id = queue->sysjob;
7120 r->next_job_id = 0;
7121 if (next_queue) {
7122 r->next_job_id = next_queue->sysjob;
7124 r->reserved = 0;
7126 return WERR_OK;
7129 /****************************************************************************
7130 Enumjobs at level 1.
7131 ****************************************************************************/
7133 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
7134 const print_queue_struct *queue,
7135 uint32_t num_queues, int snum,
7136 struct spoolss_PrinterInfo2 *pinfo2,
7137 union spoolss_JobInfo **info_p,
7138 uint32_t *count)
7140 union spoolss_JobInfo *info;
7141 int i;
7142 WERROR result = WERR_OK;
7144 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7145 W_ERROR_HAVE_NO_MEMORY(info);
7147 *count = num_queues;
7149 for (i=0; i<*count; i++) {
7150 result = fill_job_info1(info,
7151 &info[i].info1,
7152 &queue[i],
7154 snum,
7155 pinfo2);
7156 if (!W_ERROR_IS_OK(result)) {
7157 goto out;
7161 out:
7162 if (!W_ERROR_IS_OK(result)) {
7163 TALLOC_FREE(info);
7164 *count = 0;
7165 return result;
7168 *info_p = info;
7170 return WERR_OK;
7173 /****************************************************************************
7174 Enumjobs at level 2.
7175 ****************************************************************************/
7177 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
7178 const print_queue_struct *queue,
7179 uint32_t num_queues, int snum,
7180 struct spoolss_PrinterInfo2 *pinfo2,
7181 union spoolss_JobInfo **info_p,
7182 uint32_t *count)
7184 union spoolss_JobInfo *info;
7185 int i;
7186 WERROR result = WERR_OK;
7188 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7189 W_ERROR_HAVE_NO_MEMORY(info);
7191 *count = num_queues;
7193 for (i=0; i<*count; i++) {
7194 struct spoolss_DeviceMode *devmode;
7196 result = spoolss_create_default_devmode(info,
7197 pinfo2->printername,
7198 &devmode);
7199 if (!W_ERROR_IS_OK(result)) {
7200 DEBUG(3, ("Can't proceed w/o a devmode!"));
7201 goto out;
7204 result = fill_job_info2(info,
7205 &info[i].info2,
7206 &queue[i],
7208 snum,
7209 pinfo2,
7210 devmode);
7211 if (!W_ERROR_IS_OK(result)) {
7212 goto out;
7216 out:
7217 if (!W_ERROR_IS_OK(result)) {
7218 TALLOC_FREE(info);
7219 *count = 0;
7220 return result;
7223 *info_p = info;
7225 return WERR_OK;
7228 /****************************************************************************
7229 Enumjobs at level 3.
7230 ****************************************************************************/
7232 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
7233 const print_queue_struct *queue,
7234 uint32_t num_queues, int snum,
7235 struct spoolss_PrinterInfo2 *pinfo2,
7236 union spoolss_JobInfo **info_p,
7237 uint32_t *count)
7239 union spoolss_JobInfo *info;
7240 int i;
7241 WERROR result = WERR_OK;
7243 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7244 W_ERROR_HAVE_NO_MEMORY(info);
7246 *count = num_queues;
7248 for (i=0; i<*count; i++) {
7249 const print_queue_struct *next_queue = NULL;
7251 if (i+1 < *count) {
7252 next_queue = &queue[i+1];
7255 result = fill_job_info3(info,
7256 &info[i].info3,
7257 &queue[i],
7258 next_queue,
7260 snum,
7261 pinfo2);
7262 if (!W_ERROR_IS_OK(result)) {
7263 goto out;
7267 out:
7268 if (!W_ERROR_IS_OK(result)) {
7269 TALLOC_FREE(info);
7270 *count = 0;
7271 return result;
7274 *info_p = info;
7276 return WERR_OK;
7279 /****************************************************************
7280 _spoolss_EnumJobs
7281 ****************************************************************/
7283 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
7284 struct spoolss_EnumJobs *r)
7286 WERROR result;
7287 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
7288 int snum;
7289 print_status_struct prt_status;
7290 print_queue_struct *queue = NULL;
7291 uint32_t count;
7293 /* that's an [in out] buffer */
7295 if (!r->in.buffer && (r->in.offered != 0)) {
7296 return WERR_INVALID_PARAM;
7299 DEBUG(4,("_spoolss_EnumJobs\n"));
7301 *r->out.needed = 0;
7302 *r->out.count = 0;
7303 *r->out.info = NULL;
7305 /* lookup the printer snum and tdb entry */
7307 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7308 return WERR_BADFID;
7311 result = winreg_get_printer_internal(p->mem_ctx,
7312 get_session_info_system(),
7313 p->msg_ctx,
7314 lp_const_servicename(snum),
7315 &pinfo2);
7316 if (!W_ERROR_IS_OK(result)) {
7317 return result;
7320 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
7321 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7322 count, prt_status.status, prt_status.message));
7324 if (count == 0) {
7325 SAFE_FREE(queue);
7326 TALLOC_FREE(pinfo2);
7327 return WERR_OK;
7330 switch (r->in.level) {
7331 case 1:
7332 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
7333 pinfo2, r->out.info, r->out.count);
7334 break;
7335 case 2:
7336 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
7337 pinfo2, r->out.info, r->out.count);
7338 break;
7339 case 3:
7340 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
7341 pinfo2, r->out.info, r->out.count);
7342 break;
7343 default:
7344 result = WERR_UNKNOWN_LEVEL;
7345 break;
7348 SAFE_FREE(queue);
7349 TALLOC_FREE(pinfo2);
7351 if (!W_ERROR_IS_OK(result)) {
7352 return result;
7355 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7356 spoolss_EnumJobs,
7357 *r->out.info, r->in.level,
7358 *r->out.count);
7359 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7360 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7362 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7365 /****************************************************************
7366 _spoolss_ScheduleJob
7367 ****************************************************************/
7369 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
7370 struct spoolss_ScheduleJob *r)
7372 return WERR_OK;
7375 /****************************************************************
7376 ****************************************************************/
7378 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
7379 struct messaging_context *msg_ctx,
7380 const char *printer_name,
7381 uint32_t job_id,
7382 struct spoolss_SetJobInfo1 *r)
7384 char *old_doc_name;
7386 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
7387 return WERR_BADFID;
7390 if (strequal(old_doc_name, r->document_name)) {
7391 return WERR_OK;
7394 if (!print_job_set_name(server_event_context(), msg_ctx,
7395 printer_name, job_id, r->document_name)) {
7396 return WERR_BADFID;
7399 return WERR_OK;
7402 /****************************************************************
7403 _spoolss_SetJob
7404 ****************************************************************/
7406 WERROR _spoolss_SetJob(struct pipes_struct *p,
7407 struct spoolss_SetJob *r)
7409 const struct auth_session_info *session_info = p->session_info;
7410 int snum;
7411 WERROR errcode = WERR_BADFUNC;
7413 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7414 return WERR_BADFID;
7417 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
7418 return WERR_INVALID_PRINTER_NAME;
7421 switch (r->in.command) {
7422 case SPOOLSS_JOB_CONTROL_CANCEL:
7423 case SPOOLSS_JOB_CONTROL_DELETE:
7424 errcode = print_job_delete(session_info, p->msg_ctx,
7425 snum, r->in.job_id);
7426 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
7427 errcode = WERR_OK;
7429 break;
7430 case SPOOLSS_JOB_CONTROL_PAUSE:
7431 errcode = print_job_pause(session_info, p->msg_ctx,
7432 snum, r->in.job_id);
7433 break;
7434 case SPOOLSS_JOB_CONTROL_RESTART:
7435 case SPOOLSS_JOB_CONTROL_RESUME:
7436 errcode = print_job_resume(session_info, p->msg_ctx,
7437 snum, r->in.job_id);
7438 break;
7439 case 0:
7440 errcode = WERR_OK;
7441 break;
7442 default:
7443 return WERR_UNKNOWN_LEVEL;
7446 if (!W_ERROR_IS_OK(errcode)) {
7447 return errcode;
7450 if (r->in.ctr == NULL) {
7451 return errcode;
7454 switch (r->in.ctr->level) {
7455 case 1:
7456 errcode = spoolss_setjob_1(p->mem_ctx, p->msg_ctx,
7457 lp_const_servicename(snum),
7458 r->in.job_id,
7459 r->in.ctr->info.info1);
7460 break;
7461 case 2:
7462 case 3:
7463 case 4:
7464 default:
7465 return WERR_UNKNOWN_LEVEL;
7468 return errcode;
7471 /****************************************************************************
7472 Enumerates all printer drivers by level and architecture.
7473 ****************************************************************************/
7475 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
7476 const struct auth_session_info *session_info,
7477 struct messaging_context *msg_ctx,
7478 const char *servername,
7479 const char *architecture,
7480 uint32_t level,
7481 union spoolss_DriverInfo **info_p,
7482 uint32_t *count_p)
7484 int i;
7485 uint32_t version;
7486 struct spoolss_DriverInfo8 *driver;
7487 union spoolss_DriverInfo *info = NULL;
7488 uint32_t count = 0;
7489 WERROR result = WERR_OK;
7490 uint32_t num_drivers;
7491 const char **drivers;
7492 struct dcerpc_binding_handle *b;
7493 TALLOC_CTX *tmp_ctx = NULL;
7495 *count_p = 0;
7496 *info_p = NULL;
7498 tmp_ctx = talloc_new(mem_ctx);
7499 if (!tmp_ctx) {
7500 return WERR_NOMEM;
7503 result = winreg_printer_binding_handle(tmp_ctx,
7504 session_info,
7505 msg_ctx,
7506 &b);
7507 if (!W_ERROR_IS_OK(result)) {
7508 goto out;
7511 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7512 result = winreg_get_driver_list(tmp_ctx, b,
7513 architecture, version,
7514 &num_drivers, &drivers);
7515 if (!W_ERROR_IS_OK(result)) {
7516 goto out;
7518 DEBUG(4, ("we have:[%d] drivers in environment"
7519 " [%s] and version [%d]\n",
7520 num_drivers, architecture, version));
7522 if (num_drivers != 0) {
7523 info = talloc_realloc(tmp_ctx, info,
7524 union spoolss_DriverInfo,
7525 count + num_drivers);
7526 if (!info) {
7527 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7528 "failed to enlarge driver info buffer!\n"));
7529 result = WERR_NOMEM;
7530 goto out;
7534 for (i = 0; i < num_drivers; i++) {
7535 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
7537 result = winreg_get_driver(tmp_ctx, b,
7538 architecture, drivers[i],
7539 version, &driver);
7540 if (!W_ERROR_IS_OK(result)) {
7541 goto out;
7544 switch (level) {
7545 case 1:
7546 result = fill_printer_driver_info1(info, &info[count+i].info1,
7547 driver, servername);
7548 break;
7549 case 2:
7550 result = fill_printer_driver_info2(info, &info[count+i].info2,
7551 driver, servername);
7552 break;
7553 case 3:
7554 result = fill_printer_driver_info3(info, &info[count+i].info3,
7555 driver, servername);
7556 break;
7557 case 4:
7558 result = fill_printer_driver_info4(info, &info[count+i].info4,
7559 driver, servername);
7560 break;
7561 case 5:
7562 result = fill_printer_driver_info5(info, &info[count+i].info5,
7563 driver, servername);
7564 break;
7565 case 6:
7566 result = fill_printer_driver_info6(info, &info[count+i].info6,
7567 driver, servername);
7568 break;
7569 case 8:
7570 result = fill_printer_driver_info8(info, &info[count+i].info8,
7571 driver, servername);
7572 break;
7573 default:
7574 result = WERR_UNKNOWN_LEVEL;
7575 break;
7578 TALLOC_FREE(driver);
7580 if (!W_ERROR_IS_OK(result)) {
7581 goto out;
7585 count += num_drivers;
7586 TALLOC_FREE(drivers);
7589 out:
7590 if (W_ERROR_IS_OK(result)) {
7591 *info_p = talloc_move(mem_ctx, &info);
7592 *count_p = count;
7595 talloc_free(tmp_ctx);
7596 return result;
7599 /****************************************************************************
7600 Enumerates all printer drivers by level.
7601 ****************************************************************************/
7603 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
7604 const struct auth_session_info *session_info,
7605 struct messaging_context *msg_ctx,
7606 const char *servername,
7607 const char *architecture,
7608 uint32_t level,
7609 union spoolss_DriverInfo **info_p,
7610 uint32_t *count_p)
7612 uint32_t a,i;
7613 WERROR result = WERR_OK;
7615 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
7617 for (a=0; archi_table[a].long_archi != NULL; a++) {
7619 union spoolss_DriverInfo *info = NULL;
7620 uint32_t count = 0;
7622 result = enumprinterdrivers_level_by_architecture(mem_ctx,
7623 session_info,
7624 msg_ctx,
7625 servername,
7626 archi_table[a].long_archi,
7627 level,
7628 &info,
7629 &count);
7630 if (!W_ERROR_IS_OK(result)) {
7631 continue;
7634 for (i=0; i < count; i++) {
7635 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
7636 info[i], info_p, count_p);
7640 return result;
7643 return enumprinterdrivers_level_by_architecture(mem_ctx,
7644 session_info,
7645 msg_ctx,
7646 servername,
7647 architecture,
7648 level,
7649 info_p,
7650 count_p);
7653 /****************************************************************
7654 _spoolss_EnumPrinterDrivers
7655 ****************************************************************/
7657 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
7658 struct spoolss_EnumPrinterDrivers *r)
7660 const char *cservername;
7661 WERROR result;
7663 /* that's an [in out] buffer */
7665 if (!r->in.buffer && (r->in.offered != 0)) {
7666 return WERR_INVALID_PARAM;
7669 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7671 *r->out.needed = 0;
7672 *r->out.count = 0;
7673 *r->out.info = NULL;
7675 cservername = canon_servername(r->in.server);
7677 if (!is_myname_or_ipaddr(cservername)) {
7678 return WERR_UNKNOWN_PRINTER_DRIVER;
7681 result = enumprinterdrivers_level(p->mem_ctx,
7682 get_session_info_system(),
7683 p->msg_ctx,
7684 cservername,
7685 r->in.environment,
7686 r->in.level,
7687 r->out.info,
7688 r->out.count);
7689 if (!W_ERROR_IS_OK(result)) {
7690 return result;
7693 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7694 spoolss_EnumPrinterDrivers,
7695 *r->out.info, r->in.level,
7696 *r->out.count);
7697 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7698 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7700 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7703 /****************************************************************
7704 _spoolss_EnumForms
7705 ****************************************************************/
7707 WERROR _spoolss_EnumForms(struct pipes_struct *p,
7708 struct spoolss_EnumForms *r)
7710 WERROR result;
7712 *r->out.count = 0;
7713 *r->out.needed = 0;
7714 *r->out.info = NULL;
7716 /* that's an [in out] buffer */
7718 if (!r->in.buffer && (r->in.offered != 0) ) {
7719 return WERR_INVALID_PARAM;
7722 DEBUG(4,("_spoolss_EnumForms\n"));
7723 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7724 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7726 switch (r->in.level) {
7727 case 1:
7728 result = winreg_printer_enumforms1_internal(p->mem_ctx,
7729 get_session_info_system(),
7730 p->msg_ctx,
7731 r->out.count,
7732 r->out.info);
7733 break;
7734 default:
7735 result = WERR_UNKNOWN_LEVEL;
7736 break;
7739 if (!W_ERROR_IS_OK(result)) {
7740 return result;
7743 if (*r->out.count == 0) {
7744 return WERR_NO_MORE_ITEMS;
7747 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7748 spoolss_EnumForms,
7749 *r->out.info, r->in.level,
7750 *r->out.count);
7751 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7752 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7754 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7757 /****************************************************************
7758 _spoolss_GetForm
7759 ****************************************************************/
7761 WERROR _spoolss_GetForm(struct pipes_struct *p,
7762 struct spoolss_GetForm *r)
7764 WERROR result;
7766 /* that's an [in out] buffer */
7768 if (!r->in.buffer && (r->in.offered != 0)) {
7769 return WERR_INVALID_PARAM;
7772 DEBUG(4,("_spoolss_GetForm\n"));
7773 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7774 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7776 switch (r->in.level) {
7777 case 1:
7778 result = winreg_printer_getform1_internal(p->mem_ctx,
7779 get_session_info_system(),
7780 p->msg_ctx,
7781 r->in.form_name,
7782 &r->out.info->info1);
7783 break;
7784 default:
7785 result = WERR_UNKNOWN_LEVEL;
7786 break;
7789 if (!W_ERROR_IS_OK(result)) {
7790 TALLOC_FREE(r->out.info);
7791 return result;
7794 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7795 r->out.info, r->in.level);
7796 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7798 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7801 /****************************************************************************
7802 ****************************************************************************/
7804 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7805 struct spoolss_PortInfo1 *r,
7806 const char *name)
7808 r->port_name = talloc_strdup(mem_ctx, name);
7809 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7811 return WERR_OK;
7814 /****************************************************************************
7815 TODO: This probably needs distinguish between TCP/IP and Local ports
7816 somehow.
7817 ****************************************************************************/
7819 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7820 struct spoolss_PortInfo2 *r,
7821 const char *name)
7823 r->port_name = talloc_strdup(mem_ctx, name);
7824 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7826 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7827 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7829 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7830 W_ERROR_HAVE_NO_MEMORY(r->description);
7832 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7833 r->reserved = 0;
7835 return WERR_OK;
7839 /****************************************************************************
7840 wrapper around the enumer ports command
7841 ****************************************************************************/
7843 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7845 char *cmd = lp_enumports_cmd(talloc_tos());
7846 char **qlines = NULL;
7847 char *command = NULL;
7848 int numlines;
7849 int ret;
7850 int fd;
7852 *count = 0;
7853 *lines = NULL;
7855 /* if no hook then just fill in the default port */
7857 if ( !*cmd ) {
7858 if (!(qlines = talloc_array( NULL, char*, 2 ))) {
7859 return WERR_NOMEM;
7861 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7862 TALLOC_FREE(qlines);
7863 return WERR_NOMEM;
7865 qlines[1] = NULL;
7866 numlines = 1;
7868 else {
7869 /* we have a valid enumport command */
7871 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7872 if (!command) {
7873 return WERR_NOMEM;
7876 DEBUG(10,("Running [%s]\n", command));
7877 ret = smbrun(command, &fd);
7878 DEBUG(10,("Returned [%d]\n", ret));
7879 TALLOC_FREE(command);
7880 if (ret != 0) {
7881 if (fd != -1) {
7882 close(fd);
7884 return WERR_ACCESS_DENIED;
7887 numlines = 0;
7888 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7889 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7890 close(fd);
7893 *count = numlines;
7894 *lines = qlines;
7896 return WERR_OK;
7899 /****************************************************************************
7900 enumports level 1.
7901 ****************************************************************************/
7903 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7904 union spoolss_PortInfo **info_p,
7905 uint32_t *count)
7907 union spoolss_PortInfo *info = NULL;
7908 int i=0;
7909 WERROR result = WERR_OK;
7910 char **qlines = NULL;
7911 int numlines = 0;
7913 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7914 if (!W_ERROR_IS_OK(result)) {
7915 goto out;
7918 if (numlines) {
7919 info = talloc_array(mem_ctx, union spoolss_PortInfo, numlines);
7920 if (!info) {
7921 DEBUG(10,("Returning WERR_NOMEM\n"));
7922 result = WERR_NOMEM;
7923 goto out;
7926 for (i=0; i<numlines; i++) {
7927 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7928 result = fill_port_1(info, &info[i].info1, qlines[i]);
7929 if (!W_ERROR_IS_OK(result)) {
7930 goto out;
7934 TALLOC_FREE(qlines);
7936 out:
7937 if (!W_ERROR_IS_OK(result)) {
7938 TALLOC_FREE(info);
7939 TALLOC_FREE(qlines);
7940 *count = 0;
7941 *info_p = NULL;
7942 return result;
7945 *info_p = info;
7946 *count = numlines;
7948 return WERR_OK;
7951 /****************************************************************************
7952 enumports level 2.
7953 ****************************************************************************/
7955 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7956 union spoolss_PortInfo **info_p,
7957 uint32_t *count)
7959 union spoolss_PortInfo *info = NULL;
7960 int i=0;
7961 WERROR result = WERR_OK;
7962 char **qlines = NULL;
7963 int numlines = 0;
7965 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7966 if (!W_ERROR_IS_OK(result)) {
7967 goto out;
7970 if (numlines) {
7971 info = talloc_array(mem_ctx, union spoolss_PortInfo, numlines);
7972 if (!info) {
7973 DEBUG(10,("Returning WERR_NOMEM\n"));
7974 result = WERR_NOMEM;
7975 goto out;
7978 for (i=0; i<numlines; i++) {
7979 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7980 result = fill_port_2(info, &info[i].info2, qlines[i]);
7981 if (!W_ERROR_IS_OK(result)) {
7982 goto out;
7986 TALLOC_FREE(qlines);
7988 out:
7989 if (!W_ERROR_IS_OK(result)) {
7990 TALLOC_FREE(info);
7991 TALLOC_FREE(qlines);
7992 *count = 0;
7993 *info_p = NULL;
7994 return result;
7997 *info_p = info;
7998 *count = numlines;
8000 return WERR_OK;
8003 /****************************************************************
8004 _spoolss_EnumPorts
8005 ****************************************************************/
8007 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
8008 struct spoolss_EnumPorts *r)
8010 WERROR result;
8012 /* that's an [in out] buffer */
8014 if (!r->in.buffer && (r->in.offered != 0)) {
8015 return WERR_INVALID_PARAM;
8018 DEBUG(4,("_spoolss_EnumPorts\n"));
8020 *r->out.count = 0;
8021 *r->out.needed = 0;
8022 *r->out.info = NULL;
8024 switch (r->in.level) {
8025 case 1:
8026 result = enumports_level_1(p->mem_ctx, r->out.info,
8027 r->out.count);
8028 break;
8029 case 2:
8030 result = enumports_level_2(p->mem_ctx, r->out.info,
8031 r->out.count);
8032 break;
8033 default:
8034 return WERR_UNKNOWN_LEVEL;
8037 if (!W_ERROR_IS_OK(result)) {
8038 return result;
8041 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8042 spoolss_EnumPorts,
8043 *r->out.info, r->in.level,
8044 *r->out.count);
8045 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8046 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8048 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8051 /****************************************************************************
8052 ****************************************************************************/
8054 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
8055 const char *server,
8056 struct spoolss_SetPrinterInfoCtr *info_ctr,
8057 struct spoolss_DeviceMode *devmode,
8058 struct security_descriptor *secdesc,
8059 struct spoolss_UserLevelCtr *user_ctr,
8060 struct policy_handle *handle)
8062 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
8063 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
8064 int snum;
8065 WERROR err = WERR_OK;
8067 /* samba does not have a concept of local, non-shared printers yet, so
8068 * make sure we always setup sharename - gd */
8069 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
8070 (info2->printername != NULL && info2->printername[0] != '\0')) {
8071 DEBUG(5, ("spoolss_addprinterex_level_2: "
8072 "no sharename has been set, setting printername %s as sharename\n",
8073 info2->printername));
8074 info2->sharename = info2->printername;
8077 /* check to see if the printer already exists */
8078 if ((snum = print_queue_snum(info2->sharename)) != -1) {
8079 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8080 info2->sharename));
8081 return WERR_PRINTER_ALREADY_EXISTS;
8084 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
8085 if ((snum = print_queue_snum(info2->printername)) != -1) {
8086 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8087 info2->printername));
8088 return WERR_PRINTER_ALREADY_EXISTS;
8092 /* validate printer info struct */
8093 if (!info2->printername || strlen(info2->printername) == 0) {
8094 return WERR_INVALID_PRINTER_NAME;
8096 if (!info2->portname || strlen(info2->portname) == 0) {
8097 return WERR_UNKNOWN_PORT;
8099 if (!info2->drivername || strlen(info2->drivername) == 0) {
8100 return WERR_UNKNOWN_PRINTER_DRIVER;
8102 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
8103 return WERR_UNKNOWN_PRINTPROCESSOR;
8106 /* FIXME!!! smbd should check to see if the driver is installed before
8107 trying to add a printer like this --jerry */
8109 if (*lp_addprinter_cmd(talloc_tos()) ) {
8110 char *raddr;
8112 raddr = tsocket_address_inet_addr_string(p->remote_address,
8113 p->mem_ctx);
8114 if (raddr == NULL) {
8115 return WERR_NOMEM;
8118 if ( !add_printer_hook(p->mem_ctx, p->session_info->security_token,
8119 info2, raddr,
8120 p->msg_ctx) ) {
8121 return WERR_ACCESS_DENIED;
8123 } else {
8124 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no "
8125 "smb.conf parameter \"addprinter command\" is defined. This "
8126 "parameter must exist for this call to succeed\n",
8127 info2->sharename ));
8130 if ((snum = print_queue_snum(info2->sharename)) == -1) {
8131 return WERR_ACCESS_DENIED;
8134 /* you must be a printer admin to add a new printer */
8135 if (!print_access_check(p->session_info,
8136 p->msg_ctx,
8137 snum,
8138 PRINTER_ACCESS_ADMINISTER)) {
8139 return WERR_ACCESS_DENIED;
8143 * Do sanity check on the requested changes for Samba.
8146 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
8147 return WERR_INVALID_PARAM;
8150 if (devmode == NULL) {
8151 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
8154 err = update_dsspooler(p->mem_ctx,
8155 get_session_info_system(),
8156 p->msg_ctx,
8158 info2,
8159 NULL);
8160 if (!W_ERROR_IS_OK(err)) {
8161 return err;
8164 err = winreg_update_printer_internal(p->mem_ctx,
8165 get_session_info_system(),
8166 p->msg_ctx,
8167 info2->sharename,
8168 info2_mask,
8169 info2,
8170 devmode,
8171 secdesc);
8172 if (!W_ERROR_IS_OK(err)) {
8173 return err;
8176 err = open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER);
8177 if (!W_ERROR_IS_OK(err)) {
8178 /* Handle open failed - remove addition. */
8179 ZERO_STRUCTP(handle);
8180 return err;
8183 return WERR_OK;
8186 /****************************************************************
8187 _spoolss_AddPrinterEx
8188 ****************************************************************/
8190 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
8191 struct spoolss_AddPrinterEx *r)
8193 switch (r->in.info_ctr->level) {
8194 case 1:
8195 /* we don't handle yet */
8196 /* but I know what to do ... */
8197 return WERR_UNKNOWN_LEVEL;
8198 case 2:
8199 return spoolss_addprinterex_level_2(p, r->in.server,
8200 r->in.info_ctr,
8201 r->in.devmode_ctr->devmode,
8202 r->in.secdesc_ctr->sd,
8203 r->in.userlevel_ctr,
8204 r->out.handle);
8205 default:
8206 return WERR_UNKNOWN_LEVEL;
8210 /****************************************************************
8211 _spoolss_AddPrinter
8212 ****************************************************************/
8214 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
8215 struct spoolss_AddPrinter *r)
8217 struct spoolss_AddPrinterEx a;
8218 struct spoolss_UserLevelCtr userlevel_ctr;
8220 ZERO_STRUCT(userlevel_ctr);
8222 userlevel_ctr.level = 1;
8224 a.in.server = r->in.server;
8225 a.in.info_ctr = r->in.info_ctr;
8226 a.in.devmode_ctr = r->in.devmode_ctr;
8227 a.in.secdesc_ctr = r->in.secdesc_ctr;
8228 a.in.userlevel_ctr = &userlevel_ctr;
8229 a.out.handle = r->out.handle;
8231 return _spoolss_AddPrinterEx(p, &a);
8234 /****************************************************************
8235 _spoolss_AddPrinterDriverEx
8236 ****************************************************************/
8238 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
8239 struct spoolss_AddPrinterDriverEx *r)
8241 WERROR err = WERR_OK;
8242 const char *driver_name = NULL;
8243 uint32_t version;
8244 const char *fn;
8246 switch (p->opnum) {
8247 case NDR_SPOOLSS_ADDPRINTERDRIVER:
8248 fn = "_spoolss_AddPrinterDriver";
8249 break;
8250 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
8251 fn = "_spoolss_AddPrinterDriverEx";
8252 break;
8253 default:
8254 return WERR_INVALID_PARAM;
8258 * we only support the semantics of AddPrinterDriver()
8259 * i.e. only copy files that are newer than existing ones
8262 if (r->in.flags == 0) {
8263 return WERR_INVALID_PARAM;
8266 if (r->in.flags != APD_COPY_NEW_FILES) {
8267 return WERR_ACCESS_DENIED;
8270 /* FIXME */
8271 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
8272 /* Clever hack from Martin Zielinski <mz@seh.de>
8273 * to allow downgrade from level 8 (Vista).
8275 DEBUG(0,("%s: level %d not yet implemented\n", fn,
8276 r->in.info_ctr->level));
8277 return WERR_UNKNOWN_LEVEL;
8280 DEBUG(5,("Cleaning driver's information\n"));
8281 err = clean_up_driver_struct(p->mem_ctx, p->session_info, r->in.info_ctr);
8282 if (!W_ERROR_IS_OK(err))
8283 goto done;
8285 DEBUG(5,("Moving driver to final destination\n"));
8286 err = move_driver_to_download_area(p->session_info, r->in.info_ctr);
8287 if (!W_ERROR_IS_OK(err)) {
8288 goto done;
8291 err = winreg_add_driver_internal(p->mem_ctx,
8292 get_session_info_system(),
8293 p->msg_ctx,
8294 r->in.info_ctr,
8295 &driver_name,
8296 &version);
8297 if (!W_ERROR_IS_OK(err)) {
8298 goto done;
8302 * I think this is where he DrvUpgradePrinter() hook would be
8303 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8304 * server. Right now, we just need to send ourselves a message
8305 * to update each printer bound to this driver. --jerry
8308 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
8309 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8310 fn, driver_name));
8313 done:
8314 return err;
8317 /****************************************************************
8318 _spoolss_AddPrinterDriver
8319 ****************************************************************/
8321 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
8322 struct spoolss_AddPrinterDriver *r)
8324 struct spoolss_AddPrinterDriverEx a;
8326 switch (r->in.info_ctr->level) {
8327 case 2:
8328 case 3:
8329 case 4:
8330 case 5:
8331 break;
8332 default:
8333 return WERR_UNKNOWN_LEVEL;
8336 a.in.servername = r->in.servername;
8337 a.in.info_ctr = r->in.info_ctr;
8338 a.in.flags = APD_COPY_NEW_FILES;
8340 return _spoolss_AddPrinterDriverEx(p, &a);
8343 /****************************************************************************
8344 ****************************************************************************/
8346 struct _spoolss_paths {
8347 int type;
8348 const char *share;
8349 const char *dir;
8352 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
8354 static const struct _spoolss_paths spoolss_paths[]= {
8355 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
8356 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
8359 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
8360 const char *servername,
8361 const char *environment,
8362 int component,
8363 char **path)
8365 const char *pservername = NULL;
8366 const char *long_archi;
8367 const char *short_archi;
8369 *path = NULL;
8371 /* environment may be empty */
8372 if (environment && strlen(environment)) {
8373 long_archi = environment;
8374 } else {
8375 long_archi = lp_parm_const_string(GLOBAL_SECTION_SNUM,
8376 "spoolss", "architecture",
8377 SPOOLSS_ARCHITECTURE_NT_X86);
8380 /* servername may be empty */
8381 if (servername && strlen(servername)) {
8382 pservername = canon_servername(servername);
8384 if (!is_myname_or_ipaddr(pservername)) {
8385 return WERR_INVALID_PARAM;
8389 if (!(short_archi = get_short_archi(long_archi))) {
8390 return WERR_INVALID_ENVIRONMENT;
8393 switch (component) {
8394 case SPOOLSS_PRTPROCS_PATH:
8395 case SPOOLSS_DRIVER_PATH:
8396 if (pservername) {
8397 *path = talloc_asprintf(mem_ctx,
8398 "\\\\%s\\%s\\%s",
8399 pservername,
8400 spoolss_paths[component].share,
8401 short_archi);
8402 } else {
8403 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
8404 SPOOLSS_DEFAULT_SERVER_PATH,
8405 spoolss_paths[component].dir,
8406 short_archi);
8408 break;
8409 default:
8410 return WERR_INVALID_PARAM;
8413 if (!*path) {
8414 return WERR_NOMEM;
8417 return WERR_OK;
8420 /****************************************************************************
8421 ****************************************************************************/
8423 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
8424 const char *servername,
8425 const char *environment,
8426 struct spoolss_DriverDirectoryInfo1 *r)
8428 WERROR werr;
8429 char *path = NULL;
8431 werr = compose_spoolss_server_path(mem_ctx,
8432 servername,
8433 environment,
8434 SPOOLSS_DRIVER_PATH,
8435 &path);
8436 if (!W_ERROR_IS_OK(werr)) {
8437 return werr;
8440 DEBUG(4,("printer driver directory: [%s]\n", path));
8442 r->directory_name = path;
8444 return WERR_OK;
8447 /****************************************************************
8448 _spoolss_GetPrinterDriverDirectory
8449 ****************************************************************/
8451 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
8452 struct spoolss_GetPrinterDriverDirectory *r)
8454 WERROR werror;
8456 /* that's an [in out] buffer */
8458 if (!r->in.buffer && (r->in.offered != 0)) {
8459 return WERR_INVALID_PARAM;
8462 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8463 r->in.level));
8465 *r->out.needed = 0;
8467 /* r->in.level is ignored */
8469 werror = getprinterdriverdir_level_1(p->mem_ctx,
8470 r->in.server,
8471 r->in.environment,
8472 &r->out.info->info1);
8473 if (!W_ERROR_IS_OK(werror)) {
8474 TALLOC_FREE(r->out.info);
8475 return werror;
8478 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
8479 r->out.info, r->in.level);
8480 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8482 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8485 /****************************************************************
8486 _spoolss_EnumPrinterData
8487 ****************************************************************/
8489 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
8490 struct spoolss_EnumPrinterData *r)
8492 WERROR result;
8493 struct spoolss_EnumPrinterDataEx r2;
8494 uint32_t count;
8495 struct spoolss_PrinterEnumValues *info, *val = NULL;
8496 uint32_t needed;
8498 r2.in.handle = r->in.handle;
8499 r2.in.key_name = "PrinterDriverData";
8500 r2.in.offered = 0;
8501 r2.out.count = &count;
8502 r2.out.info = &info;
8503 r2.out.needed = &needed;
8505 result = _spoolss_EnumPrinterDataEx(p, &r2);
8506 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8507 r2.in.offered = needed;
8508 result = _spoolss_EnumPrinterDataEx(p, &r2);
8510 if (!W_ERROR_IS_OK(result)) {
8511 return result;
8515 * The NT machine wants to know the biggest size of value and data
8517 * cf: MSDN EnumPrinterData remark section
8520 if (!r->in.value_offered && !r->in.data_offered) {
8521 uint32_t biggest_valuesize = 0;
8522 uint32_t biggest_datasize = 0;
8523 int i, name_length;
8525 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8527 for (i=0; i<count; i++) {
8529 name_length = strlen(info[i].value_name);
8530 if (strlen(info[i].value_name) > biggest_valuesize) {
8531 biggest_valuesize = name_length;
8534 if (info[i].data_length > biggest_datasize) {
8535 biggest_datasize = info[i].data_length;
8538 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8539 biggest_datasize));
8542 /* the value is an UNICODE string but real_value_size is the length
8543 in bytes including the trailing 0 */
8545 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8546 *r->out.data_needed = biggest_datasize;
8548 DEBUG(6,("final values: [%d], [%d]\n",
8549 *r->out.value_needed, *r->out.data_needed));
8551 return WERR_OK;
8554 if (r->in.enum_index < count) {
8555 val = &info[r->in.enum_index];
8558 if (val == NULL) {
8559 /* out_value should default to "" or else NT4 has
8560 problems unmarshalling the response */
8562 if (r->in.value_offered) {
8563 *r->out.value_needed = 1;
8564 r->out.value_name = talloc_strdup(r, "");
8565 if (!r->out.value_name) {
8566 return WERR_NOMEM;
8568 } else {
8569 r->out.value_name = NULL;
8570 *r->out.value_needed = 0;
8573 /* the data is counted in bytes */
8575 *r->out.data_needed = r->in.data_offered;
8577 result = WERR_NO_MORE_ITEMS;
8578 } else {
8580 * the value is:
8581 * - counted in bytes in the request
8582 * - counted in UNICODE chars in the max reply
8583 * - counted in bytes in the real size
8585 * take a pause *before* coding not *during* coding
8588 /* name */
8589 if (r->in.value_offered) {
8590 r->out.value_name = talloc_strdup(r, val->value_name);
8591 if (!r->out.value_name) {
8592 return WERR_NOMEM;
8594 *r->out.value_needed = val->value_name_len;
8595 } else {
8596 r->out.value_name = NULL;
8597 *r->out.value_needed = 0;
8600 /* type */
8602 *r->out.type = val->type;
8604 /* data - counted in bytes */
8607 * See the section "Dynamically Typed Query Parameters"
8608 * in MS-RPRN.
8611 if (r->out.data && val->data && val->data->data &&
8612 val->data_length && r->in.data_offered) {
8613 memcpy(r->out.data, val->data->data,
8614 MIN(val->data_length,r->in.data_offered));
8617 *r->out.data_needed = val->data_length;
8619 result = WERR_OK;
8622 return result;
8625 /****************************************************************
8626 _spoolss_SetPrinterData
8627 ****************************************************************/
8629 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
8630 struct spoolss_SetPrinterData *r)
8632 struct spoolss_SetPrinterDataEx r2;
8634 r2.in.handle = r->in.handle;
8635 r2.in.key_name = "PrinterDriverData";
8636 r2.in.value_name = r->in.value_name;
8637 r2.in.type = r->in.type;
8638 r2.in.data = r->in.data;
8639 r2.in.offered = r->in.offered;
8641 return _spoolss_SetPrinterDataEx(p, &r2);
8644 /****************************************************************
8645 _spoolss_ResetPrinter
8646 ****************************************************************/
8648 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
8649 struct spoolss_ResetPrinter *r)
8651 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8652 int snum;
8654 DEBUG(5,("_spoolss_ResetPrinter\n"));
8657 * All we do is to check to see if the handle and queue is valid.
8658 * This call really doesn't mean anything to us because we only
8659 * support RAW printing. --jerry
8662 if (!Printer) {
8663 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8664 OUR_HANDLE(r->in.handle)));
8665 return WERR_BADFID;
8668 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8669 return WERR_BADFID;
8672 /* blindly return success */
8673 return WERR_OK;
8676 /****************************************************************
8677 _spoolss_DeletePrinterData
8678 ****************************************************************/
8680 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
8681 struct spoolss_DeletePrinterData *r)
8683 struct spoolss_DeletePrinterDataEx r2;
8685 r2.in.handle = r->in.handle;
8686 r2.in.key_name = "PrinterDriverData";
8687 r2.in.value_name = r->in.value_name;
8689 return _spoolss_DeletePrinterDataEx(p, &r2);
8692 /****************************************************************
8693 _spoolss_AddForm
8694 ****************************************************************/
8696 WERROR _spoolss_AddForm(struct pipes_struct *p,
8697 struct spoolss_AddForm *r)
8699 struct spoolss_AddFormInfo1 *form;
8700 int snum = -1;
8701 WERROR status = WERR_OK;
8702 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8703 struct dcerpc_binding_handle *b;
8704 TALLOC_CTX *tmp_ctx = NULL;
8706 DEBUG(5,("_spoolss_AddForm\n"));
8708 if (!Printer) {
8709 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8710 OUR_HANDLE(r->in.handle)));
8711 return WERR_BADFID;
8714 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8715 and not a printer admin, then fail */
8717 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
8718 !security_token_has_privilege(p->session_info->security_token,
8719 SEC_PRIV_PRINT_OPERATOR)) {
8720 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8721 return WERR_ACCESS_DENIED;
8724 if (r->in.info_ctr->level != 1) {
8725 return WERR_INVALID_LEVEL;
8728 form = r->in.info_ctr->info.info1;
8729 if (!form) {
8730 return WERR_INVALID_PARAM;
8733 switch (form->flags) {
8734 case SPOOLSS_FORM_USER:
8735 case SPOOLSS_FORM_BUILTIN:
8736 case SPOOLSS_FORM_PRINTER:
8737 break;
8738 default:
8739 return WERR_INVALID_PARAM;
8742 tmp_ctx = talloc_new(p->mem_ctx);
8743 if (!tmp_ctx) {
8744 return WERR_NOMEM;
8747 status = winreg_printer_binding_handle(tmp_ctx,
8748 get_session_info_system(),
8749 p->msg_ctx,
8750 &b);
8751 if (!W_ERROR_IS_OK(status)) {
8752 goto done;
8755 status = winreg_printer_addform1(tmp_ctx, b, form);
8756 if (!W_ERROR_IS_OK(status)) {
8757 goto done;
8761 * ChangeID must always be set if this is a printer
8763 if (Printer->printer_type == SPLHND_PRINTER) {
8764 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8765 status = WERR_BADFID;
8766 goto done;
8769 status = winreg_printer_update_changeid(tmp_ctx, b,
8770 lp_const_servicename(snum));
8773 done:
8774 talloc_free(tmp_ctx);
8775 return status;
8778 /****************************************************************
8779 _spoolss_DeleteForm
8780 ****************************************************************/
8782 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8783 struct spoolss_DeleteForm *r)
8785 const char *form_name = r->in.form_name;
8786 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8787 int snum = -1;
8788 WERROR status = WERR_OK;
8789 struct dcerpc_binding_handle *b;
8790 TALLOC_CTX *tmp_ctx = NULL;
8792 DEBUG(5,("_spoolss_DeleteForm\n"));
8794 if (!Printer) {
8795 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8796 OUR_HANDLE(r->in.handle)));
8797 return WERR_BADFID;
8800 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
8801 !security_token_has_privilege(p->session_info->security_token,
8802 SEC_PRIV_PRINT_OPERATOR)) {
8803 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8804 return WERR_ACCESS_DENIED;
8807 tmp_ctx = talloc_new(p->mem_ctx);
8808 if (!tmp_ctx) {
8809 return WERR_NOMEM;
8812 status = winreg_printer_binding_handle(tmp_ctx,
8813 get_session_info_system(),
8814 p->msg_ctx,
8815 &b);
8816 if (!W_ERROR_IS_OK(status)) {
8817 goto done;
8820 status = winreg_printer_deleteform1(tmp_ctx, b, form_name);
8821 if (!W_ERROR_IS_OK(status)) {
8822 goto done;
8826 * ChangeID must always be set if this is a printer
8828 if (Printer->printer_type == SPLHND_PRINTER) {
8829 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8830 status = WERR_BADFID;
8831 goto done;
8834 status = winreg_printer_update_changeid(tmp_ctx, b,
8835 lp_const_servicename(snum));
8838 done:
8839 talloc_free(tmp_ctx);
8840 return status;
8843 /****************************************************************
8844 _spoolss_SetForm
8845 ****************************************************************/
8847 WERROR _spoolss_SetForm(struct pipes_struct *p,
8848 struct spoolss_SetForm *r)
8850 struct spoolss_AddFormInfo1 *form;
8851 const char *form_name = r->in.form_name;
8852 int snum = -1;
8853 WERROR status = WERR_OK;
8854 struct dcerpc_binding_handle *b;
8855 TALLOC_CTX *tmp_ctx = NULL;
8857 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8859 DEBUG(5,("_spoolss_SetForm\n"));
8861 if (!Printer) {
8862 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8863 OUR_HANDLE(r->in.handle)));
8864 return WERR_BADFID;
8867 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8868 and not a printer admin, then fail */
8870 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
8871 !security_token_has_privilege(p->session_info->security_token,
8872 SEC_PRIV_PRINT_OPERATOR)) {
8873 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8874 return WERR_ACCESS_DENIED;
8877 if (r->in.info_ctr->level != 1) {
8878 return WERR_INVALID_LEVEL;
8881 form = r->in.info_ctr->info.info1;
8882 if (!form) {
8883 return WERR_INVALID_PARAM;
8886 tmp_ctx = talloc_new(p->mem_ctx);
8887 if (!tmp_ctx) {
8888 return WERR_NOMEM;
8891 status = winreg_printer_binding_handle(tmp_ctx,
8892 get_session_info_system(),
8893 p->msg_ctx,
8894 &b);
8895 if (!W_ERROR_IS_OK(status)) {
8896 goto done;
8899 status = winreg_printer_setform1(tmp_ctx, b,
8900 form_name,
8901 form);
8902 if (!W_ERROR_IS_OK(status)) {
8903 goto done;
8907 * ChangeID must always be set if this is a printer
8909 if (Printer->printer_type == SPLHND_PRINTER) {
8910 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8911 status = WERR_BADFID;
8912 goto done;
8915 status = winreg_printer_update_changeid(tmp_ctx, b,
8916 lp_const_servicename(snum));
8919 done:
8920 talloc_free(tmp_ctx);
8921 return status;
8924 /****************************************************************************
8925 fill_print_processor1
8926 ****************************************************************************/
8928 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8929 struct spoolss_PrintProcessorInfo1 *r,
8930 const char *print_processor_name)
8932 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8933 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8935 return WERR_OK;
8938 /****************************************************************************
8939 enumprintprocessors level 1.
8940 ****************************************************************************/
8942 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8943 union spoolss_PrintProcessorInfo **info_p,
8944 uint32_t *count)
8946 union spoolss_PrintProcessorInfo *info;
8947 WERROR result;
8949 info = talloc_array(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8950 W_ERROR_HAVE_NO_MEMORY(info);
8952 *count = 1;
8954 result = fill_print_processor1(info, &info[0].info1, "winprint");
8955 if (!W_ERROR_IS_OK(result)) {
8956 goto out;
8959 out:
8960 if (!W_ERROR_IS_OK(result)) {
8961 TALLOC_FREE(info);
8962 *count = 0;
8963 return result;
8966 *info_p = info;
8968 return WERR_OK;
8971 /****************************************************************
8972 _spoolss_EnumPrintProcessors
8973 ****************************************************************/
8975 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8976 struct spoolss_EnumPrintProcessors *r)
8978 WERROR result;
8980 /* that's an [in out] buffer */
8982 if (!r->in.buffer && (r->in.offered != 0)) {
8983 return WERR_INVALID_PARAM;
8986 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8989 * Enumerate the print processors ...
8991 * Just reply with "winprint", to keep NT happy
8992 * and I can use my nice printer checker.
8995 *r->out.count = 0;
8996 *r->out.needed = 0;
8997 *r->out.info = NULL;
8999 if (!get_short_archi(r->in.environment)) {
9000 return WERR_INVALID_ENVIRONMENT;
9003 switch (r->in.level) {
9004 case 1:
9005 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
9006 r->out.count);
9007 break;
9008 default:
9009 return WERR_UNKNOWN_LEVEL;
9012 if (!W_ERROR_IS_OK(result)) {
9013 return result;
9016 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9017 spoolss_EnumPrintProcessors,
9018 *r->out.info, r->in.level,
9019 *r->out.count);
9020 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9021 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9023 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9026 /****************************************************************************
9027 fill_printprocdatatype1
9028 ****************************************************************************/
9030 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
9031 struct spoolss_PrintProcDataTypesInfo1 *r,
9032 const char *name_array)
9034 r->name_array = talloc_strdup(mem_ctx, name_array);
9035 W_ERROR_HAVE_NO_MEMORY(r->name_array);
9037 return WERR_OK;
9040 /****************************************************************************
9041 enumprintprocdatatypes level 1.
9042 ****************************************************************************/
9044 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
9045 union spoolss_PrintProcDataTypesInfo **info_p,
9046 uint32_t *count)
9048 WERROR result;
9049 union spoolss_PrintProcDataTypesInfo *info;
9051 info = talloc_array(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
9052 W_ERROR_HAVE_NO_MEMORY(info);
9054 *count = 1;
9056 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
9057 if (!W_ERROR_IS_OK(result)) {
9058 goto out;
9061 out:
9062 if (!W_ERROR_IS_OK(result)) {
9063 TALLOC_FREE(info);
9064 *count = 0;
9065 return result;
9068 *info_p = info;
9070 return WERR_OK;
9073 /****************************************************************
9074 _spoolss_EnumPrintProcDataTypes
9075 ****************************************************************/
9077 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
9078 struct spoolss_EnumPrintProcDataTypes *r)
9080 WERROR result;
9082 /* that's an [in out] buffer */
9084 if (!r->in.buffer && (r->in.offered != 0)) {
9085 return WERR_INVALID_PARAM;
9088 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
9090 *r->out.count = 0;
9091 *r->out.needed = 0;
9092 *r->out.info = NULL;
9094 if (r->in.print_processor_name == NULL ||
9095 !strequal(r->in.print_processor_name, "winprint")) {
9096 return WERR_UNKNOWN_PRINTPROCESSOR;
9099 switch (r->in.level) {
9100 case 1:
9101 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
9102 r->out.count);
9103 break;
9104 default:
9105 return WERR_UNKNOWN_LEVEL;
9108 if (!W_ERROR_IS_OK(result)) {
9109 return result;
9112 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9113 spoolss_EnumPrintProcDataTypes,
9114 *r->out.info, r->in.level,
9115 *r->out.count);
9116 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9117 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9119 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9122 /****************************************************************************
9123 fill_monitor_1
9124 ****************************************************************************/
9126 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
9127 struct spoolss_MonitorInfo1 *r,
9128 const char *monitor_name)
9130 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
9131 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
9133 return WERR_OK;
9136 /****************************************************************************
9137 fill_monitor_2
9138 ****************************************************************************/
9140 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
9141 struct spoolss_MonitorInfo2 *r,
9142 const char *monitor_name,
9143 const char *environment,
9144 const char *dll_name)
9146 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
9147 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
9148 r->environment = talloc_strdup(mem_ctx, environment);
9149 W_ERROR_HAVE_NO_MEMORY(r->environment);
9150 r->dll_name = talloc_strdup(mem_ctx, dll_name);
9151 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
9153 return WERR_OK;
9156 /****************************************************************************
9157 enumprintmonitors level 1.
9158 ****************************************************************************/
9160 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
9161 union spoolss_MonitorInfo **info_p,
9162 uint32_t *count)
9164 union spoolss_MonitorInfo *info;
9165 WERROR result = WERR_OK;
9167 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, 2);
9168 W_ERROR_HAVE_NO_MEMORY(info);
9170 *count = 2;
9172 result = fill_monitor_1(info, &info[0].info1,
9173 SPL_LOCAL_PORT);
9174 if (!W_ERROR_IS_OK(result)) {
9175 goto out;
9178 result = fill_monitor_1(info, &info[1].info1,
9179 SPL_TCPIP_PORT);
9180 if (!W_ERROR_IS_OK(result)) {
9181 goto out;
9184 out:
9185 if (!W_ERROR_IS_OK(result)) {
9186 TALLOC_FREE(info);
9187 *count = 0;
9188 return result;
9191 *info_p = info;
9193 return WERR_OK;
9196 /****************************************************************************
9197 enumprintmonitors level 2.
9198 ****************************************************************************/
9200 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
9201 union spoolss_MonitorInfo **info_p,
9202 uint32_t *count)
9204 union spoolss_MonitorInfo *info;
9205 WERROR result = WERR_OK;
9207 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, 2);
9208 W_ERROR_HAVE_NO_MEMORY(info);
9210 *count = 2;
9212 result = fill_monitor_2(info, &info[0].info2,
9213 SPL_LOCAL_PORT,
9214 "Windows NT X86", /* FIXME */
9215 "localmon.dll");
9216 if (!W_ERROR_IS_OK(result)) {
9217 goto out;
9220 result = fill_monitor_2(info, &info[1].info2,
9221 SPL_TCPIP_PORT,
9222 "Windows NT X86", /* FIXME */
9223 "tcpmon.dll");
9224 if (!W_ERROR_IS_OK(result)) {
9225 goto out;
9228 out:
9229 if (!W_ERROR_IS_OK(result)) {
9230 TALLOC_FREE(info);
9231 *count = 0;
9232 return result;
9235 *info_p = info;
9237 return WERR_OK;
9240 /****************************************************************
9241 _spoolss_EnumMonitors
9242 ****************************************************************/
9244 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
9245 struct spoolss_EnumMonitors *r)
9247 WERROR result;
9249 /* that's an [in out] buffer */
9251 if (!r->in.buffer && (r->in.offered != 0)) {
9252 return WERR_INVALID_PARAM;
9255 DEBUG(5,("_spoolss_EnumMonitors\n"));
9258 * Enumerate the print monitors ...
9260 * Just reply with "Local Port", to keep NT happy
9261 * and I can use my nice printer checker.
9264 *r->out.count = 0;
9265 *r->out.needed = 0;
9266 *r->out.info = NULL;
9268 switch (r->in.level) {
9269 case 1:
9270 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
9271 r->out.count);
9272 break;
9273 case 2:
9274 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
9275 r->out.count);
9276 break;
9277 default:
9278 return WERR_UNKNOWN_LEVEL;
9281 if (!W_ERROR_IS_OK(result)) {
9282 return result;
9285 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9286 spoolss_EnumMonitors,
9287 *r->out.info, r->in.level,
9288 *r->out.count);
9289 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9290 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9292 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9295 /****************************************************************************
9296 ****************************************************************************/
9298 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
9299 const print_queue_struct *queue,
9300 int count, int snum,
9301 struct spoolss_PrinterInfo2 *pinfo2,
9302 uint32_t jobid,
9303 struct spoolss_JobInfo1 *r)
9305 int i = 0;
9306 bool found = false;
9308 for (i=0; i<count; i++) {
9309 if (queue[i].sysjob == (int)jobid) {
9310 found = true;
9311 break;
9315 if (found == false) {
9316 /* NT treats not found as bad param... yet another bad choice */
9317 return WERR_INVALID_PARAM;
9320 return fill_job_info1(mem_ctx,
9322 &queue[i],
9324 snum,
9325 pinfo2);
9328 /****************************************************************************
9329 ****************************************************************************/
9331 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
9332 const print_queue_struct *queue,
9333 int count, int snum,
9334 struct spoolss_PrinterInfo2 *pinfo2,
9335 uint32_t jobid,
9336 struct spoolss_JobInfo2 *r)
9338 int i = 0;
9339 bool found = false;
9340 struct spoolss_DeviceMode *devmode;
9341 WERROR result;
9343 for (i=0; i<count; i++) {
9344 if (queue[i].sysjob == (int)jobid) {
9345 found = true;
9346 break;
9350 if (found == false) {
9351 /* NT treats not found as bad param... yet another bad
9352 choice */
9353 return WERR_INVALID_PARAM;
9357 * if the print job does not have a DEVMODE associated with it,
9358 * just use the one for the printer. A NULL devicemode is not
9359 * a failure condition
9362 devmode = print_job_devmode(mem_ctx, lp_const_servicename(snum), jobid);
9363 if (!devmode) {
9364 result = spoolss_create_default_devmode(mem_ctx,
9365 pinfo2->printername,
9366 &devmode);
9367 if (!W_ERROR_IS_OK(result)) {
9368 DEBUG(3, ("Can't proceed w/o a devmode!"));
9369 return result;
9373 return fill_job_info2(mem_ctx,
9375 &queue[i],
9377 snum,
9378 pinfo2,
9379 devmode);
9382 /****************************************************************
9383 _spoolss_GetJob
9384 ****************************************************************/
9386 WERROR _spoolss_GetJob(struct pipes_struct *p,
9387 struct spoolss_GetJob *r)
9389 WERROR result = WERR_OK;
9390 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9391 int snum;
9392 int count;
9393 print_queue_struct *queue = NULL;
9394 print_status_struct prt_status;
9396 /* that's an [in out] buffer */
9398 if (!r->in.buffer && (r->in.offered != 0)) {
9399 return WERR_INVALID_PARAM;
9402 DEBUG(5,("_spoolss_GetJob\n"));
9404 *r->out.needed = 0;
9406 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9407 return WERR_BADFID;
9410 result = winreg_get_printer_internal(p->mem_ctx,
9411 get_session_info_system(),
9412 p->msg_ctx,
9413 lp_const_servicename(snum),
9414 &pinfo2);
9415 if (!W_ERROR_IS_OK(result)) {
9416 return result;
9419 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
9421 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9422 count, prt_status.status, prt_status.message));
9424 switch (r->in.level) {
9425 case 1:
9426 result = getjob_level_1(p->mem_ctx,
9427 queue, count, snum, pinfo2,
9428 r->in.job_id, &r->out.info->info1);
9429 break;
9430 case 2:
9431 result = getjob_level_2(p->mem_ctx,
9432 queue, count, snum, pinfo2,
9433 r->in.job_id, &r->out.info->info2);
9434 break;
9435 default:
9436 result = WERR_UNKNOWN_LEVEL;
9437 break;
9440 SAFE_FREE(queue);
9441 TALLOC_FREE(pinfo2);
9443 if (!W_ERROR_IS_OK(result)) {
9444 TALLOC_FREE(r->out.info);
9445 return result;
9448 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
9449 r->in.level);
9450 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9452 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9455 /****************************************************************
9456 _spoolss_GetPrinterDataEx
9457 ****************************************************************/
9459 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
9460 struct spoolss_GetPrinterDataEx *r)
9463 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9464 const char *printer;
9465 int snum = 0;
9466 WERROR result = WERR_OK;
9467 DATA_BLOB blob;
9468 enum winreg_Type val_type = REG_NONE;
9469 uint8_t *val_data = NULL;
9470 uint32_t val_size = 0;
9471 struct dcerpc_binding_handle *b;
9472 TALLOC_CTX *tmp_ctx;
9474 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9476 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9477 r->in.key_name, r->in.value_name));
9479 /* in case of problem, return some default values */
9481 *r->out.needed = 0;
9482 *r->out.type = REG_NONE;
9484 tmp_ctx = talloc_new(p->mem_ctx);
9485 if (!tmp_ctx) {
9486 return WERR_NOMEM;
9489 if (!Printer) {
9490 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9491 OUR_HANDLE(r->in.handle)));
9492 result = WERR_BADFID;
9493 goto done;
9496 /* check to see if the keyname is valid */
9497 if (!strlen(r->in.key_name)) {
9498 result = WERR_INVALID_PARAM;
9499 goto done;
9502 /* Is the handle to a printer or to the server? */
9504 if (Printer->printer_type == SPLHND_SERVER) {
9506 union spoolss_PrinterData data;
9508 result = getprinterdata_printer_server(tmp_ctx,
9509 r->in.value_name,
9510 r->out.type,
9511 &data);
9512 if (!W_ERROR_IS_OK(result)) {
9513 goto done;
9516 result = push_spoolss_PrinterData(tmp_ctx, &blob,
9517 *r->out.type, &data);
9518 if (!W_ERROR_IS_OK(result)) {
9519 goto done;
9522 *r->out.needed = blob.length;
9524 if (r->in.offered >= *r->out.needed) {
9525 memcpy(r->out.data, blob.data, blob.length);
9528 result = WERR_OK;
9529 goto done;
9532 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9533 result = WERR_BADFID;
9534 goto done;
9536 printer = lp_const_servicename(snum);
9538 result = winreg_printer_binding_handle(tmp_ctx,
9539 get_session_info_system(),
9540 p->msg_ctx,
9541 &b);
9542 if (!W_ERROR_IS_OK(result)) {
9543 goto done;
9546 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9547 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
9548 strequal(r->in.value_name, "ChangeId")) {
9549 *r->out.type = REG_DWORD;
9550 *r->out.needed = 4;
9551 if (r->in.offered >= *r->out.needed) {
9552 uint32_t changeid = 0;
9554 result = winreg_printer_get_changeid(tmp_ctx, b,
9555 printer,
9556 &changeid);
9557 if (!W_ERROR_IS_OK(result)) {
9558 goto done;
9561 SIVAL(r->out.data, 0, changeid);
9562 result = WERR_OK;
9564 goto done;
9567 result = winreg_get_printer_dataex(tmp_ctx, b,
9568 printer,
9569 r->in.key_name,
9570 r->in.value_name,
9571 &val_type,
9572 &val_data,
9573 &val_size);
9574 if (!W_ERROR_IS_OK(result)) {
9575 goto done;
9578 *r->out.needed = val_size;
9579 *r->out.type = val_type;
9581 if (r->in.offered >= *r->out.needed) {
9582 memcpy(r->out.data, val_data, val_size);
9585 done:
9586 /* NOTE: do not replace type when returning WERR_MORE_DATA */
9588 if (W_ERROR_IS_OK(result)) {
9589 result = SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9592 talloc_free(tmp_ctx);
9593 return result;
9596 /****************************************************************
9597 _spoolss_SetPrinterDataEx
9598 ****************************************************************/
9600 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
9601 struct spoolss_SetPrinterDataEx *r)
9603 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9604 int snum = 0;
9605 WERROR result = WERR_OK;
9606 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9607 char *oid_string;
9608 struct dcerpc_binding_handle *b;
9609 TALLOC_CTX *tmp_ctx;
9611 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9613 /* From MSDN documentation of SetPrinterDataEx: pass request to
9614 SetPrinterData if key is "PrinterDriverData" */
9616 if (!Printer) {
9617 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9618 OUR_HANDLE(r->in.handle)));
9619 return WERR_BADFID;
9622 if (Printer->printer_type == SPLHND_SERVER) {
9623 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9624 "Not implemented for server handles yet\n"));
9625 return WERR_INVALID_PARAM;
9628 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9629 return WERR_BADFID;
9633 * Access check : NT returns "access denied" if you make a
9634 * SetPrinterData call without the necessary privildge.
9635 * we were originally returning OK if nothing changed
9636 * which made Win2k issue **a lot** of SetPrinterData
9637 * when connecting to a printer --jerry
9640 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9641 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9642 "change denied by handle access permissions\n"));
9643 return WERR_ACCESS_DENIED;
9646 tmp_ctx = talloc_new(p->mem_ctx);
9647 if (!tmp_ctx) {
9648 return WERR_NOMEM;
9651 result = winreg_printer_binding_handle(tmp_ctx,
9652 get_session_info_system(),
9653 p->msg_ctx,
9654 &b);
9655 if (!W_ERROR_IS_OK(result)) {
9656 goto done;
9659 result = winreg_get_printer(tmp_ctx, b,
9660 lp_servicename(talloc_tos(), snum),
9661 &pinfo2);
9662 if (!W_ERROR_IS_OK(result)) {
9663 goto done;
9666 /* check for OID in valuename */
9668 oid_string = strchr(r->in.value_name, ',');
9669 if (oid_string) {
9670 *oid_string = '\0';
9671 oid_string++;
9674 /* save the registry data */
9676 result = winreg_set_printer_dataex(tmp_ctx, b,
9677 pinfo2->sharename,
9678 r->in.key_name,
9679 r->in.value_name,
9680 r->in.type,
9681 r->in.data,
9682 r->in.offered);
9684 if (W_ERROR_IS_OK(result)) {
9685 /* save the OID if one was specified */
9686 if (oid_string) {
9687 char *str = talloc_asprintf(tmp_ctx, "%s\\%s",
9688 r->in.key_name, SPOOL_OID_KEY);
9689 if (!str) {
9690 result = WERR_NOMEM;
9691 goto done;
9695 * I'm not checking the status here on purpose. Don't know
9696 * if this is right, but I'm returning the status from the
9697 * previous set_printer_dataex() call. I have no idea if
9698 * this is right. --jerry
9700 winreg_set_printer_dataex(tmp_ctx, b,
9701 pinfo2->sharename,
9702 str,
9703 r->in.value_name,
9704 REG_SZ,
9705 (uint8_t *) oid_string,
9706 strlen(oid_string) + 1);
9709 result = winreg_printer_update_changeid(tmp_ctx, b,
9710 lp_const_servicename(snum));
9714 done:
9715 talloc_free(tmp_ctx);
9716 return result;
9719 /****************************************************************
9720 _spoolss_DeletePrinterDataEx
9721 ****************************************************************/
9723 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
9724 struct spoolss_DeletePrinterDataEx *r)
9726 const char *printer;
9727 int snum=0;
9728 WERROR status = WERR_OK;
9729 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9731 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9733 if (!Printer) {
9734 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9735 "Invalid handle (%s:%u:%u).\n",
9736 OUR_HANDLE(r->in.handle)));
9737 return WERR_BADFID;
9740 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9741 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9742 "printer properties change denied by handle\n"));
9743 return WERR_ACCESS_DENIED;
9746 if (!r->in.value_name || !r->in.key_name) {
9747 return WERR_NOMEM;
9750 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9751 return WERR_BADFID;
9753 printer = lp_const_servicename(snum);
9755 status = winreg_delete_printer_dataex_internal(p->mem_ctx,
9756 get_session_info_system(),
9757 p->msg_ctx,
9758 printer,
9759 r->in.key_name,
9760 r->in.value_name);
9761 if (W_ERROR_IS_OK(status)) {
9762 status = winreg_printer_update_changeid_internal(p->mem_ctx,
9763 get_session_info_system(),
9764 p->msg_ctx,
9765 printer);
9768 return status;
9771 /****************************************************************
9772 _spoolss_EnumPrinterKey
9773 ****************************************************************/
9775 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
9776 struct spoolss_EnumPrinterKey *r)
9778 uint32_t num_keys;
9779 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9780 int snum = 0;
9781 WERROR result = WERR_BADFILE;
9782 const char **array = NULL;
9783 DATA_BLOB blob;
9785 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9787 if (!Printer) {
9788 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9789 OUR_HANDLE(r->in.handle)));
9790 return WERR_BADFID;
9793 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9794 return WERR_BADFID;
9797 result = winreg_enum_printer_key_internal(p->mem_ctx,
9798 get_session_info_system(),
9799 p->msg_ctx,
9800 lp_const_servicename(snum),
9801 r->in.key_name,
9802 &num_keys,
9803 &array);
9804 if (!W_ERROR_IS_OK(result)) {
9805 goto done;
9808 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9809 result = WERR_NOMEM;
9810 goto done;
9813 *r->out._ndr_size = r->in.offered / 2;
9814 *r->out.needed = blob.length;
9816 if (r->in.offered < *r->out.needed) {
9817 result = WERR_MORE_DATA;
9818 } else {
9819 result = WERR_OK;
9820 r->out.key_buffer->string_array = array;
9823 done:
9824 if (!W_ERROR_IS_OK(result)) {
9825 TALLOC_FREE(array);
9826 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9827 *r->out.needed = 0;
9831 return result;
9834 /****************************************************************
9835 _spoolss_DeletePrinterKey
9836 ****************************************************************/
9838 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9839 struct spoolss_DeletePrinterKey *r)
9841 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9842 int snum=0;
9843 WERROR status;
9844 const char *printer;
9845 struct dcerpc_binding_handle *b;
9846 TALLOC_CTX *tmp_ctx;
9848 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9850 if (!Printer) {
9851 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9852 OUR_HANDLE(r->in.handle)));
9853 return WERR_BADFID;
9856 /* if keyname == NULL, return error */
9857 if ( !r->in.key_name )
9858 return WERR_INVALID_PARAM;
9860 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9861 return WERR_BADFID;
9864 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9865 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9866 "printer properties change denied by handle\n"));
9867 return WERR_ACCESS_DENIED;
9870 printer = lp_const_servicename(snum);
9872 tmp_ctx = talloc_new(p->mem_ctx);
9873 if (!tmp_ctx) {
9874 return WERR_NOMEM;
9877 status = winreg_printer_binding_handle(tmp_ctx,
9878 get_session_info_system(),
9879 p->msg_ctx,
9880 &b);
9881 if (!W_ERROR_IS_OK(status)) {
9882 goto done;
9885 /* delete the key and all subkeys */
9886 status = winreg_delete_printer_key(tmp_ctx, b,
9887 printer,
9888 r->in.key_name);
9889 if (W_ERROR_IS_OK(status)) {
9890 status = winreg_printer_update_changeid(tmp_ctx, b,
9891 printer);
9894 done:
9895 talloc_free(tmp_ctx);
9896 return status;
9899 /****************************************************************
9900 _spoolss_EnumPrinterDataEx
9901 ****************************************************************/
9903 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9904 struct spoolss_EnumPrinterDataEx *r)
9906 uint32_t count = 0;
9907 struct spoolss_PrinterEnumValues *info = NULL;
9908 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9909 int snum;
9910 WERROR result;
9912 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9914 *r->out.count = 0;
9915 *r->out.needed = 0;
9916 *r->out.info = NULL;
9918 if (!Printer) {
9919 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9920 OUR_HANDLE(r->in.handle)));
9921 return WERR_BADFID;
9925 * first check for a keyname of NULL or "". Win2k seems to send
9926 * this a lot and we should send back WERR_INVALID_PARAM
9927 * no need to spend time looking up the printer in this case.
9928 * --jerry
9931 if (!strlen(r->in.key_name)) {
9932 result = WERR_INVALID_PARAM;
9933 goto done;
9936 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9937 return WERR_BADFID;
9940 /* now look for a match on the key name */
9941 result = winreg_enum_printer_dataex_internal(p->mem_ctx,
9942 get_session_info_system(),
9943 p->msg_ctx,
9944 lp_const_servicename(snum),
9945 r->in.key_name,
9946 &count,
9947 &info);
9948 if (!W_ERROR_IS_OK(result)) {
9949 goto done;
9952 #if 0 /* FIXME - gd */
9953 /* housekeeping information in the reply */
9955 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9956 * the hand marshalled container size is a multiple
9957 * of 4 bytes for RPC alignment.
9960 if (needed % 4) {
9961 needed += 4-(needed % 4);
9963 #endif
9964 *r->out.count = count;
9965 *r->out.info = info;
9967 done:
9968 if (!W_ERROR_IS_OK(result)) {
9969 return result;
9972 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9973 spoolss_EnumPrinterDataEx,
9974 *r->out.info,
9975 *r->out.count);
9976 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9977 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9979 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9982 /****************************************************************************
9983 ****************************************************************************/
9985 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9986 const char *servername,
9987 const char *environment,
9988 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9990 WERROR werr;
9991 char *path = NULL;
9993 werr = compose_spoolss_server_path(mem_ctx,
9994 servername,
9995 environment,
9996 SPOOLSS_PRTPROCS_PATH,
9997 &path);
9998 if (!W_ERROR_IS_OK(werr)) {
9999 return werr;
10002 DEBUG(4,("print processor directory: [%s]\n", path));
10004 r->directory_name = path;
10006 return WERR_OK;
10009 /****************************************************************
10010 _spoolss_GetPrintProcessorDirectory
10011 ****************************************************************/
10013 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
10014 struct spoolss_GetPrintProcessorDirectory *r)
10016 WERROR result;
10017 char *prnproc_share = NULL;
10018 bool prnproc_share_exists = false;
10019 int snum;
10021 /* that's an [in out] buffer */
10023 if (!r->in.buffer && (r->in.offered != 0)) {
10024 return WERR_INVALID_PARAM;
10027 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
10028 r->in.level));
10030 *r->out.needed = 0;
10032 /* r->in.level is ignored */
10034 /* We always should reply with a local print processor directory so that
10035 * users are not forced to have a [prnproc$] share on the Samba spoolss
10036 * server, if users decide to do so, lets announce it though - Guenther */
10038 snum = find_service(talloc_tos(), "prnproc$", &prnproc_share);
10039 if (!prnproc_share) {
10040 return WERR_NOMEM;
10042 if (snum != -1) {
10043 prnproc_share_exists = true;
10046 result = getprintprocessordirectory_level_1(p->mem_ctx,
10047 prnproc_share_exists ? r->in.server : NULL,
10048 r->in.environment,
10049 &r->out.info->info1);
10050 if (!W_ERROR_IS_OK(result)) {
10051 TALLOC_FREE(r->out.info);
10052 return result;
10055 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
10056 r->out.info, r->in.level);
10057 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
10059 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
10062 /*******************************************************************
10063 ********************************************************************/
10065 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
10066 const char *dllname)
10068 enum ndr_err_code ndr_err;
10069 struct spoolss_MonitorUi ui;
10071 ui.dll_name = dllname;
10073 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
10074 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
10075 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10076 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
10078 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10081 /*******************************************************************
10082 Streams the monitor UI DLL name in UNICODE
10083 *******************************************************************/
10085 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
10086 struct security_token *token, DATA_BLOB *in,
10087 DATA_BLOB *out, uint32_t *needed)
10089 const char *dllname = "tcpmonui.dll";
10091 *needed = (strlen(dllname)+1) * 2;
10093 if (out->length < *needed) {
10094 return WERR_INSUFFICIENT_BUFFER;
10097 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
10098 return WERR_NOMEM;
10101 return WERR_OK;
10104 /*******************************************************************
10105 ********************************************************************/
10107 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
10108 struct spoolss_PortData1 *port1,
10109 const DATA_BLOB *buf)
10111 enum ndr_err_code ndr_err;
10112 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
10113 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
10114 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10115 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
10117 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10120 /*******************************************************************
10121 ********************************************************************/
10123 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
10124 struct spoolss_PortData2 *port2,
10125 const DATA_BLOB *buf)
10127 enum ndr_err_code ndr_err;
10128 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
10129 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
10130 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10131 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
10133 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10136 /*******************************************************************
10137 Create a new TCP/IP port
10138 *******************************************************************/
10140 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
10141 struct security_token *token, DATA_BLOB *in,
10142 DATA_BLOB *out, uint32_t *needed)
10144 struct spoolss_PortData1 port1;
10145 struct spoolss_PortData2 port2;
10146 char *device_uri = NULL;
10147 uint32_t version;
10149 const char *portname;
10150 const char *hostaddress;
10151 const char *queue;
10152 uint32_t port_number;
10153 uint32_t protocol;
10155 /* peek for spoolss_PortData version */
10157 if (!in || (in->length < (128 + 4))) {
10158 return WERR_GENERAL_FAILURE;
10161 version = IVAL(in->data, 128);
10163 switch (version) {
10164 case 1:
10165 ZERO_STRUCT(port1);
10167 if (!pull_port_data_1(mem_ctx, &port1, in)) {
10168 return WERR_NOMEM;
10171 portname = port1.portname;
10172 hostaddress = port1.hostaddress;
10173 queue = port1.queue;
10174 protocol = port1.protocol;
10175 port_number = port1.port_number;
10177 break;
10178 case 2:
10179 ZERO_STRUCT(port2);
10181 if (!pull_port_data_2(mem_ctx, &port2, in)) {
10182 return WERR_NOMEM;
10185 portname = port2.portname;
10186 hostaddress = port2.hostaddress;
10187 queue = port2.queue;
10188 protocol = port2.protocol;
10189 port_number = port2.port_number;
10191 break;
10192 default:
10193 DEBUG(1,("xcvtcp_addport: "
10194 "unknown version of port_data: %d\n", version));
10195 return WERR_UNKNOWN_PORT;
10198 /* create the device URI and call the add_port_hook() */
10200 switch (protocol) {
10201 case PROTOCOL_RAWTCP_TYPE:
10202 device_uri = talloc_asprintf(mem_ctx,
10203 "socket://%s:%d/", hostaddress,
10204 port_number);
10205 break;
10207 case PROTOCOL_LPR_TYPE:
10208 device_uri = talloc_asprintf(mem_ctx,
10209 "lpr://%s/%s", hostaddress, queue );
10210 break;
10212 default:
10213 return WERR_UNKNOWN_PORT;
10216 if (!device_uri) {
10217 return WERR_NOMEM;
10220 return add_port_hook(mem_ctx, token, portname, device_uri);
10223 /*******************************************************************
10224 *******************************************************************/
10226 struct xcv_api_table xcvtcp_cmds[] = {
10227 { "MonitorUI", xcvtcp_monitorui },
10228 { "AddPort", xcvtcp_addport},
10229 { NULL, NULL }
10232 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
10233 struct security_token *token, const char *command,
10234 DATA_BLOB *inbuf,
10235 DATA_BLOB *outbuf,
10236 uint32_t *needed )
10238 int i;
10240 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
10242 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
10243 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
10244 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
10247 return WERR_BADFUNC;
10250 /*******************************************************************
10251 *******************************************************************/
10252 #if 0 /* don't support management using the "Local Port" monitor */
10254 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
10255 struct security_token *token, DATA_BLOB *in,
10256 DATA_BLOB *out, uint32_t *needed)
10258 const char *dllname = "localui.dll";
10260 *needed = (strlen(dllname)+1) * 2;
10262 if (out->length < *needed) {
10263 return WERR_INSUFFICIENT_BUFFER;
10266 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
10267 return WERR_NOMEM;
10270 return WERR_OK;
10273 /*******************************************************************
10274 *******************************************************************/
10276 struct xcv_api_table xcvlocal_cmds[] = {
10277 { "MonitorUI", xcvlocal_monitorui },
10278 { NULL, NULL }
10280 #else
10281 struct xcv_api_table xcvlocal_cmds[] = {
10282 { NULL, NULL }
10284 #endif
10288 /*******************************************************************
10289 *******************************************************************/
10291 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
10292 struct security_token *token, const char *command,
10293 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
10294 uint32_t *needed)
10296 int i;
10298 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
10300 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
10301 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
10302 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
10304 return WERR_BADFUNC;
10307 /****************************************************************
10308 _spoolss_XcvData
10309 ****************************************************************/
10311 WERROR _spoolss_XcvData(struct pipes_struct *p,
10312 struct spoolss_XcvData *r)
10314 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
10315 DATA_BLOB out_data = data_blob_null;
10316 WERROR werror;
10318 if (!Printer) {
10319 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
10320 OUR_HANDLE(r->in.handle)));
10321 return WERR_BADFID;
10324 /* Has to be a handle to the TCP/IP port monitor */
10326 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
10327 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
10328 return WERR_BADFID;
10331 /* requires administrative access to the server */
10333 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
10334 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
10335 return WERR_ACCESS_DENIED;
10338 /* Allocate the outgoing buffer */
10340 if (r->in.out_data_size) {
10341 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
10342 if (out_data.data == NULL) {
10343 return WERR_NOMEM;
10347 switch ( Printer->printer_type ) {
10348 case SPLHND_PORTMON_TCP:
10349 werror = process_xcvtcp_command(p->mem_ctx,
10350 p->session_info->security_token,
10351 r->in.function_name,
10352 &r->in.in_data, &out_data,
10353 r->out.needed);
10354 break;
10355 case SPLHND_PORTMON_LOCAL:
10356 werror = process_xcvlocal_command(p->mem_ctx,
10357 p->session_info->security_token,
10358 r->in.function_name,
10359 &r->in.in_data, &out_data,
10360 r->out.needed);
10361 break;
10362 default:
10363 werror = WERR_INVALID_PRINT_MONITOR;
10366 if (!W_ERROR_IS_OK(werror)) {
10367 return werror;
10370 *r->out.status_code = 0;
10372 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
10373 memcpy(r->out.out_data, out_data.data,
10374 MIN(r->in.out_data_size, out_data.length));
10377 return WERR_OK;
10380 /****************************************************************
10381 _spoolss_AddPrintProcessor
10382 ****************************************************************/
10384 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
10385 struct spoolss_AddPrintProcessor *r)
10387 /* for now, just indicate success and ignore the add. We'll
10388 automatically set the winprint processor for printer
10389 entries later. Used to debug the LexMark Optra S 1855 PCL
10390 driver --jerry */
10392 return WERR_OK;
10395 /****************************************************************
10396 _spoolss_AddPort
10397 ****************************************************************/
10399 WERROR _spoolss_AddPort(struct pipes_struct *p,
10400 struct spoolss_AddPort *r)
10402 /* do what w2k3 does */
10404 return WERR_NOT_SUPPORTED;
10407 /****************************************************************
10408 _spoolss_GetPrinterDriver
10409 ****************************************************************/
10411 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
10412 struct spoolss_GetPrinterDriver *r)
10414 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10415 return WERR_NOT_SUPPORTED;
10418 /****************************************************************
10419 _spoolss_ReadPrinter
10420 ****************************************************************/
10422 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
10423 struct spoolss_ReadPrinter *r)
10425 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10426 return WERR_NOT_SUPPORTED;
10429 /****************************************************************
10430 _spoolss_WaitForPrinterChange
10431 ****************************************************************/
10433 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
10434 struct spoolss_WaitForPrinterChange *r)
10436 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10437 return WERR_NOT_SUPPORTED;
10440 /****************************************************************
10441 _spoolss_ConfigurePort
10442 ****************************************************************/
10444 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
10445 struct spoolss_ConfigurePort *r)
10447 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10448 return WERR_NOT_SUPPORTED;
10451 /****************************************************************
10452 _spoolss_DeletePort
10453 ****************************************************************/
10455 WERROR _spoolss_DeletePort(struct pipes_struct *p,
10456 struct spoolss_DeletePort *r)
10458 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10459 return WERR_NOT_SUPPORTED;
10462 /****************************************************************
10463 _spoolss_CreatePrinterIC
10464 ****************************************************************/
10466 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
10467 struct spoolss_CreatePrinterIC *r)
10469 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10470 return WERR_NOT_SUPPORTED;
10473 /****************************************************************
10474 _spoolss_PlayGDIScriptOnPrinterIC
10475 ****************************************************************/
10477 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
10478 struct spoolss_PlayGDIScriptOnPrinterIC *r)
10480 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10481 return WERR_NOT_SUPPORTED;
10484 /****************************************************************
10485 _spoolss_DeletePrinterIC
10486 ****************************************************************/
10488 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
10489 struct spoolss_DeletePrinterIC *r)
10491 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10492 return WERR_NOT_SUPPORTED;
10495 /****************************************************************
10496 _spoolss_AddPrinterConnection
10497 ****************************************************************/
10499 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
10500 struct spoolss_AddPrinterConnection *r)
10502 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10503 return WERR_NOT_SUPPORTED;
10506 /****************************************************************
10507 _spoolss_DeletePrinterConnection
10508 ****************************************************************/
10510 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
10511 struct spoolss_DeletePrinterConnection *r)
10513 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10514 return WERR_NOT_SUPPORTED;
10517 /****************************************************************
10518 _spoolss_PrinterMessageBox
10519 ****************************************************************/
10521 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
10522 struct spoolss_PrinterMessageBox *r)
10524 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10525 return WERR_NOT_SUPPORTED;
10528 /****************************************************************
10529 _spoolss_AddMonitor
10530 ****************************************************************/
10532 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
10533 struct spoolss_AddMonitor *r)
10535 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10536 return WERR_NOT_SUPPORTED;
10539 /****************************************************************
10540 _spoolss_DeleteMonitor
10541 ****************************************************************/
10543 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
10544 struct spoolss_DeleteMonitor *r)
10546 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10547 return WERR_NOT_SUPPORTED;
10550 /****************************************************************
10551 _spoolss_DeletePrintProcessor
10552 ****************************************************************/
10554 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
10555 struct spoolss_DeletePrintProcessor *r)
10557 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10558 return WERR_NOT_SUPPORTED;
10561 /****************************************************************
10562 _spoolss_AddPrintProvidor
10563 ****************************************************************/
10565 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
10566 struct spoolss_AddPrintProvidor *r)
10568 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10569 return WERR_NOT_SUPPORTED;
10572 /****************************************************************
10573 _spoolss_DeletePrintProvidor
10574 ****************************************************************/
10576 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
10577 struct spoolss_DeletePrintProvidor *r)
10579 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10580 return WERR_NOT_SUPPORTED;
10583 /****************************************************************
10584 _spoolss_FindFirstPrinterChangeNotification
10585 ****************************************************************/
10587 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
10588 struct spoolss_FindFirstPrinterChangeNotification *r)
10590 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10591 return WERR_NOT_SUPPORTED;
10594 /****************************************************************
10595 _spoolss_FindNextPrinterChangeNotification
10596 ****************************************************************/
10598 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
10599 struct spoolss_FindNextPrinterChangeNotification *r)
10601 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10602 return WERR_NOT_SUPPORTED;
10605 /****************************************************************
10606 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10607 ****************************************************************/
10609 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
10610 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10612 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10613 return WERR_NOT_SUPPORTED;
10616 /****************************************************************
10617 _spoolss_ReplyOpenPrinter
10618 ****************************************************************/
10620 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
10621 struct spoolss_ReplyOpenPrinter *r)
10623 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10624 return WERR_NOT_SUPPORTED;
10627 /****************************************************************
10628 _spoolss_RouterReplyPrinter
10629 ****************************************************************/
10631 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
10632 struct spoolss_RouterReplyPrinter *r)
10634 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10635 return WERR_NOT_SUPPORTED;
10638 /****************************************************************
10639 _spoolss_ReplyClosePrinter
10640 ****************************************************************/
10642 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
10643 struct spoolss_ReplyClosePrinter *r)
10645 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10646 return WERR_NOT_SUPPORTED;
10649 /****************************************************************
10650 _spoolss_AddPortEx
10651 ****************************************************************/
10653 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
10654 struct spoolss_AddPortEx *r)
10656 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10657 return WERR_NOT_SUPPORTED;
10660 /****************************************************************
10661 _spoolss_RouterFindFirstPrinterChangeNotification
10662 ****************************************************************/
10664 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
10665 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10667 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10668 return WERR_NOT_SUPPORTED;
10671 /****************************************************************
10672 _spoolss_SpoolerInit
10673 ****************************************************************/
10675 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
10676 struct spoolss_SpoolerInit *r)
10678 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10679 return WERR_NOT_SUPPORTED;
10682 /****************************************************************
10683 _spoolss_ResetPrinterEx
10684 ****************************************************************/
10686 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
10687 struct spoolss_ResetPrinterEx *r)
10689 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10690 return WERR_NOT_SUPPORTED;
10693 /****************************************************************
10694 _spoolss_RouterReplyPrinterEx
10695 ****************************************************************/
10697 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
10698 struct spoolss_RouterReplyPrinterEx *r)
10700 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10701 return WERR_NOT_SUPPORTED;
10704 /****************************************************************
10705 _spoolss_44
10706 ****************************************************************/
10708 WERROR _spoolss_44(struct pipes_struct *p,
10709 struct spoolss_44 *r)
10711 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10712 return WERR_NOT_SUPPORTED;
10715 /****************************************************************
10716 _spoolss_SetPort
10717 ****************************************************************/
10719 WERROR _spoolss_SetPort(struct pipes_struct *p,
10720 struct spoolss_SetPort *r)
10722 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10723 return WERR_NOT_SUPPORTED;
10726 /****************************************************************
10727 _spoolss_4a
10728 ****************************************************************/
10730 WERROR _spoolss_4a(struct pipes_struct *p,
10731 struct spoolss_4a *r)
10733 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10734 return WERR_NOT_SUPPORTED;
10737 /****************************************************************
10738 _spoolss_4b
10739 ****************************************************************/
10741 WERROR _spoolss_4b(struct pipes_struct *p,
10742 struct spoolss_4b *r)
10744 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10745 return WERR_NOT_SUPPORTED;
10748 /****************************************************************
10749 _spoolss_4c
10750 ****************************************************************/
10752 WERROR _spoolss_4c(struct pipes_struct *p,
10753 struct spoolss_4c *r)
10755 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10756 return WERR_NOT_SUPPORTED;
10759 /****************************************************************
10760 _spoolss_53
10761 ****************************************************************/
10763 WERROR _spoolss_53(struct pipes_struct *p,
10764 struct spoolss_53 *r)
10766 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10767 return WERR_NOT_SUPPORTED;
10770 /****************************************************************
10771 _spoolss_AddPerMachineConnection
10772 ****************************************************************/
10774 WERROR _spoolss_AddPerMachineConnection(struct pipes_struct *p,
10775 struct spoolss_AddPerMachineConnection *r)
10777 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10778 return WERR_NOT_SUPPORTED;
10781 /****************************************************************
10782 _spoolss_DeletePerMachineConnection
10783 ****************************************************************/
10785 WERROR _spoolss_DeletePerMachineConnection(struct pipes_struct *p,
10786 struct spoolss_DeletePerMachineConnection *r)
10788 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10789 return WERR_NOT_SUPPORTED;
10792 /****************************************************************
10793 _spoolss_EnumPerMachineConnections
10794 ****************************************************************/
10796 WERROR _spoolss_EnumPerMachineConnections(struct pipes_struct *p,
10797 struct spoolss_EnumPerMachineConnections *r)
10799 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10800 return WERR_NOT_SUPPORTED;
10803 /****************************************************************
10804 _spoolss_5a
10805 ****************************************************************/
10807 WERROR _spoolss_5a(struct pipes_struct *p,
10808 struct spoolss_5a *r)
10810 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10811 return WERR_NOT_SUPPORTED;
10814 /****************************************************************
10815 _spoolss_5b
10816 ****************************************************************/
10818 WERROR _spoolss_5b(struct pipes_struct *p,
10819 struct spoolss_5b *r)
10821 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10822 return WERR_NOT_SUPPORTED;
10825 /****************************************************************
10826 _spoolss_5c
10827 ****************************************************************/
10829 WERROR _spoolss_5c(struct pipes_struct *p,
10830 struct spoolss_5c *r)
10832 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10833 return WERR_NOT_SUPPORTED;
10836 /****************************************************************
10837 _spoolss_5d
10838 ****************************************************************/
10840 WERROR _spoolss_5d(struct pipes_struct *p,
10841 struct spoolss_5d *r)
10843 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10844 return WERR_NOT_SUPPORTED;
10847 /****************************************************************
10848 _spoolss_5e
10849 ****************************************************************/
10851 WERROR _spoolss_5e(struct pipes_struct *p,
10852 struct spoolss_5e *r)
10854 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10855 return WERR_NOT_SUPPORTED;
10858 /****************************************************************
10859 _spoolss_5f
10860 ****************************************************************/
10862 WERROR _spoolss_5f(struct pipes_struct *p,
10863 struct spoolss_5f *r)
10865 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10866 return WERR_NOT_SUPPORTED;
10869 /****************************************************************
10870 _spoolss_60
10871 ****************************************************************/
10873 WERROR _spoolss_60(struct pipes_struct *p,
10874 struct spoolss_60 *r)
10876 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10877 return WERR_NOT_SUPPORTED;
10880 /****************************************************************
10881 _spoolss_RpcSendRecvBidiData
10882 ****************************************************************/
10884 WERROR _spoolss_RpcSendRecvBidiData(struct pipes_struct *p,
10885 struct spoolss_RpcSendRecvBidiData *r)
10887 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10888 return WERR_NOT_SUPPORTED;
10891 /****************************************************************
10892 _spoolss_62
10893 ****************************************************************/
10895 WERROR _spoolss_62(struct pipes_struct *p,
10896 struct spoolss_62 *r)
10898 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10899 return WERR_NOT_SUPPORTED;
10902 /****************************************************************
10903 _spoolss_63
10904 ****************************************************************/
10906 WERROR _spoolss_63(struct pipes_struct *p,
10907 struct spoolss_63 *r)
10909 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10910 return WERR_NOT_SUPPORTED;
10913 /****************************************************************
10914 _spoolss_64
10915 ****************************************************************/
10917 WERROR _spoolss_64(struct pipes_struct *p,
10918 struct spoolss_64 *r)
10920 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10921 return WERR_NOT_SUPPORTED;
10924 /****************************************************************
10925 _spoolss_65
10926 ****************************************************************/
10928 WERROR _spoolss_65(struct pipes_struct *p,
10929 struct spoolss_65 *r)
10931 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10932 return WERR_NOT_SUPPORTED;
10935 /****************************************************************
10936 _spoolss_GetCorePrinterDrivers
10937 ****************************************************************/
10939 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10940 struct spoolss_GetCorePrinterDrivers *r)
10942 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10943 return WERR_NOT_SUPPORTED;
10946 /****************************************************************
10947 _spoolss_67
10948 ****************************************************************/
10950 WERROR _spoolss_67(struct pipes_struct *p,
10951 struct spoolss_67 *r)
10953 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10954 return WERR_NOT_SUPPORTED;
10957 /****************************************************************
10958 _spoolss_GetPrinterDriverPackagePath
10959 ****************************************************************/
10961 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10962 struct spoolss_GetPrinterDriverPackagePath *r)
10964 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10965 return WERR_NOT_SUPPORTED;
10968 /****************************************************************
10969 _spoolss_69
10970 ****************************************************************/
10972 WERROR _spoolss_69(struct pipes_struct *p,
10973 struct spoolss_69 *r)
10975 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10976 return WERR_NOT_SUPPORTED;
10979 /****************************************************************
10980 _spoolss_6a
10981 ****************************************************************/
10983 WERROR _spoolss_6a(struct pipes_struct *p,
10984 struct spoolss_6a *r)
10986 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10987 return WERR_NOT_SUPPORTED;
10990 /****************************************************************
10991 _spoolss_6b
10992 ****************************************************************/
10994 WERROR _spoolss_6b(struct pipes_struct *p,
10995 struct spoolss_6b *r)
10997 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10998 return WERR_NOT_SUPPORTED;
11001 /****************************************************************
11002 _spoolss_6c
11003 ****************************************************************/
11005 WERROR _spoolss_6c(struct pipes_struct *p,
11006 struct spoolss_6c *r)
11008 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11009 return WERR_NOT_SUPPORTED;
11012 /****************************************************************
11013 _spoolss_6d
11014 ****************************************************************/
11016 WERROR _spoolss_6d(struct pipes_struct *p,
11017 struct spoolss_6d *r)
11019 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11020 return WERR_NOT_SUPPORTED;
11023 /****************************************************************
11024 _spoolss_RpcGetJobNamedPropertyValue
11025 ****************************************************************/
11027 WERROR _spoolss_RpcGetJobNamedPropertyValue(struct pipes_struct *p,
11028 struct spoolss_RpcGetJobNamedPropertyValue *r)
11030 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11031 return WERR_NOT_SUPPORTED;
11034 /****************************************************************
11035 _spoolss_RpcSetJobNamedProperty
11036 ****************************************************************/
11038 WERROR _spoolss_RpcSetJobNamedProperty(struct pipes_struct *p,
11039 struct spoolss_RpcSetJobNamedProperty *r)
11041 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11042 return WERR_NOT_SUPPORTED;
11045 /****************************************************************
11046 _spoolss_RpcDeleteJobNamedProperty
11047 ****************************************************************/
11049 WERROR _spoolss_RpcDeleteJobNamedProperty(struct pipes_struct *p,
11050 struct spoolss_RpcDeleteJobNamedProperty *r)
11052 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11053 return WERR_NOT_SUPPORTED;
11056 /****************************************************************
11057 _spoolss_RpcEnumJobNamedProperties
11058 ****************************************************************/
11060 WERROR _spoolss_RpcEnumJobNamedProperties(struct pipes_struct *p,
11061 struct spoolss_RpcEnumJobNamedProperties *r)
11063 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11064 return WERR_NOT_SUPPORTED;