spoolss: clear JobInfo on GetJob error
[Samba.git] / source3 / rpc_server / spoolss / srv_spoolss_nt.c
blob6e3012ccfbc11031871a19345bc66265beae8cdb
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 This is now *ONLY* called inside the background lpq updater. JRA.
1517 **********************************************************************/
1519 void do_drv_upgrade_printer(struct messaging_context *msg,
1520 void *private_data,
1521 uint32_t msg_type,
1522 struct server_id server_id,
1523 DATA_BLOB *data)
1525 TALLOC_CTX *tmp_ctx;
1526 const struct auth_session_info *session_info = get_session_info_system();
1527 struct spoolss_PrinterInfo2 *pinfo2;
1528 WERROR result;
1529 const char *drivername;
1530 int snum;
1531 int n_services = lp_numservices();
1532 struct dcerpc_binding_handle *b = NULL;
1534 tmp_ctx = talloc_new(NULL);
1535 if (!tmp_ctx) return;
1537 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, data->length);
1538 if (!drivername) {
1539 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1540 goto done;
1543 DEBUG(10, ("do_drv_upgrade_printer: "
1544 "Got message for new driver [%s]\n", drivername));
1546 /* Iterate the printer list */
1548 for (snum = 0; snum < n_services; snum++) {
1549 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1550 continue;
1553 /* ignore [printers] share */
1554 if (strequal(lp_const_servicename(snum), "printers")) {
1555 continue;
1558 if (b == NULL) {
1559 result = winreg_printer_binding_handle(tmp_ctx,
1560 session_info,
1561 msg,
1562 &b);
1563 if (!W_ERROR_IS_OK(result)) {
1564 break;
1568 result = winreg_get_printer(tmp_ctx, b,
1569 lp_const_servicename(snum),
1570 &pinfo2);
1572 if (!W_ERROR_IS_OK(result)) {
1573 continue;
1576 if (!pinfo2->drivername) {
1577 continue;
1580 if (strcmp(drivername, pinfo2->drivername) != 0) {
1581 continue;
1584 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1586 /* all we care about currently is the change_id */
1587 result = winreg_printer_update_changeid(tmp_ctx, b,
1588 pinfo2->printername);
1590 if (!W_ERROR_IS_OK(result)) {
1591 DEBUG(3, ("do_drv_upgrade_printer: "
1592 "Failed to update changeid [%s]\n",
1593 win_errstr(result)));
1597 /* all done */
1598 done:
1599 talloc_free(tmp_ctx);
1602 /********************************************************************
1603 Update the cache for all printq's with a registered client
1604 connection
1605 ********************************************************************/
1607 void update_monitored_printq_cache(struct messaging_context *msg_ctx)
1609 struct printer_handle *printer = printers_list;
1610 int snum;
1612 /* loop through all printers and update the cache where
1613 a client is connected */
1614 while (printer) {
1615 if ((printer->printer_type == SPLHND_PRINTER) &&
1616 ((printer->notify.cli_chan != NULL) &&
1617 (printer->notify.cli_chan->active_connections > 0))) {
1618 snum = print_queue_snum(printer->sharename);
1619 print_queue_status(msg_ctx, snum, NULL, NULL);
1622 printer = printer->next;
1625 return;
1628 /****************************************************************
1629 _spoolss_OpenPrinter
1630 ****************************************************************/
1632 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1633 struct spoolss_OpenPrinter *r)
1635 struct spoolss_OpenPrinterEx e;
1636 struct spoolss_UserLevel1 level1;
1637 WERROR werr;
1639 ZERO_STRUCT(level1);
1641 e.in.printername = r->in.printername;
1642 e.in.datatype = r->in.datatype;
1643 e.in.devmode_ctr = r->in.devmode_ctr;
1644 e.in.access_mask = r->in.access_mask;
1645 e.in.userlevel_ctr.level = 1;
1646 e.in.userlevel_ctr.user_info.level1 = &level1;
1648 e.out.handle = r->out.handle;
1650 werr = _spoolss_OpenPrinterEx(p, &e);
1652 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1653 /* OpenPrinterEx returns this for a bad
1654 * printer name. We must return WERR_INVALID_PRINTER_NAME
1655 * instead.
1657 werr = WERR_INVALID_PRINTER_NAME;
1660 return werr;
1663 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1664 struct spoolss_DeviceMode *orig,
1665 struct spoolss_DeviceMode **dest)
1667 struct spoolss_DeviceMode *dm;
1669 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1670 if (!dm) {
1671 return WERR_NOMEM;
1674 /* copy all values, then duplicate strings and structs */
1675 *dm = *orig;
1677 dm->devicename = talloc_strdup(dm, orig->devicename);
1678 if (!dm->devicename) {
1679 return WERR_NOMEM;
1681 dm->formname = talloc_strdup(dm, orig->formname);
1682 if (!dm->formname) {
1683 return WERR_NOMEM;
1685 if (orig->driverextra_data.data) {
1686 dm->driverextra_data.data =
1687 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1688 orig->driverextra_data.length);
1689 if (!dm->driverextra_data.data) {
1690 return WERR_NOMEM;
1694 *dest = dm;
1695 return WERR_OK;
1698 /****************************************************************
1699 _spoolss_OpenPrinterEx
1700 ****************************************************************/
1702 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1703 struct spoolss_OpenPrinterEx *r)
1705 int snum;
1706 char *raddr;
1707 char *rhost;
1708 struct printer_handle *Printer=NULL;
1709 WERROR result;
1710 int rc;
1712 if (!r->in.printername) {
1713 return WERR_INVALID_PARAM;
1716 if (!*r->in.printername) {
1717 return WERR_INVALID_PARAM;
1720 if (r->in.userlevel_ctr.level > 3) {
1721 return WERR_INVALID_PARAM;
1723 if ((r->in.userlevel_ctr.level == 1 && !r->in.userlevel_ctr.user_info.level1) ||
1724 (r->in.userlevel_ctr.level == 2 && !r->in.userlevel_ctr.user_info.level2) ||
1725 (r->in.userlevel_ctr.level == 3 && !r->in.userlevel_ctr.user_info.level3)) {
1726 return WERR_INVALID_PARAM;
1730 * The printcap printer share inventory is updated on client
1731 * enumeration. For clients that do not perform enumeration prior to
1732 * access, such as cupssmbadd, we reinitialise the printer share
1733 * inventory on open as well.
1735 become_root();
1736 delete_and_reload_printers(server_event_context(), p->msg_ctx);
1737 unbecome_root();
1739 /* some sanity check because you can open a printer or a print server */
1740 /* aka: \\server\printer or \\server */
1742 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1744 result = open_printer_hnd(p, r->out.handle, r->in.printername, 0);
1745 if (!W_ERROR_IS_OK(result)) {
1746 DEBUG(3,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1747 "for printer %s\n", r->in.printername));
1748 ZERO_STRUCTP(r->out.handle);
1749 return result;
1752 Printer = find_printer_index_by_hnd(p, r->out.handle);
1753 if ( !Printer ) {
1754 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1755 "handle we created for printer %s\n", r->in.printername));
1756 close_printer_handle(p, r->out.handle);
1757 ZERO_STRUCTP(r->out.handle);
1758 return WERR_INVALID_PARAM;
1762 * First case: the user is opening the print server:
1764 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1765 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1767 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1768 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1769 * or if the user is listed in the smb.conf printer admin parameter.
1771 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1772 * client view printer folder, but does not show the MSAPW.
1774 * Note: this test needs code to check access rights here too. Jeremy
1775 * could you look at this?
1777 * Second case: the user is opening a printer:
1778 * NT doesn't let us connect to a printer if the connecting user
1779 * doesn't have print permission.
1781 * Third case: user is opening a Port Monitor
1782 * access checks same as opening a handle to the print server.
1785 switch (Printer->printer_type )
1787 case SPLHND_SERVER:
1788 case SPLHND_PORTMON_TCP:
1789 case SPLHND_PORTMON_LOCAL:
1790 /* Printserver handles use global struct... */
1792 snum = -1;
1794 /* Map standard access rights to object specific access rights */
1796 se_map_standard(&r->in.access_mask,
1797 &printserver_std_mapping);
1799 /* Deny any object specific bits that don't apply to print
1800 servers (i.e printer and job specific bits) */
1802 r->in.access_mask &= SEC_MASK_SPECIFIC;
1804 if (r->in.access_mask &
1805 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1806 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1807 close_printer_handle(p, r->out.handle);
1808 ZERO_STRUCTP(r->out.handle);
1809 return WERR_ACCESS_DENIED;
1812 /* Allow admin access */
1814 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1816 if (!lp_ms_add_printer_wizard()) {
1817 close_printer_handle(p, r->out.handle);
1818 ZERO_STRUCTP(r->out.handle);
1819 return WERR_ACCESS_DENIED;
1822 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1823 and not a printer admin, then fail */
1825 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
1826 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
1827 !nt_token_check_sid(&global_sid_Builtin_Print_Operators,
1828 p->session_info->security_token)) {
1829 close_printer_handle(p, r->out.handle);
1830 ZERO_STRUCTP(r->out.handle);
1831 DEBUG(3,("access DENIED as user is not root, "
1832 "has no printoperator privilege, "
1833 "not a member of the printoperator builtin group and "
1834 "is not in printer admin list"));
1835 return WERR_ACCESS_DENIED;
1838 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1840 else
1842 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1845 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1846 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1848 /* We fall through to return WERR_OK */
1849 break;
1851 case SPLHND_PRINTER:
1852 /* NT doesn't let us connect to a printer if the connecting user
1853 doesn't have print permission. */
1855 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1856 close_printer_handle(p, r->out.handle);
1857 ZERO_STRUCTP(r->out.handle);
1858 return WERR_BADFID;
1861 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1862 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1865 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1867 /* map an empty access mask to the minimum access mask */
1868 if (r->in.access_mask == 0x0)
1869 r->in.access_mask = PRINTER_ACCESS_USE;
1872 * If we are not serving the printer driver for this printer,
1873 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1874 * will keep NT clients happy --jerry
1877 if (lp_use_client_driver(snum)
1878 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1880 r->in.access_mask = PRINTER_ACCESS_USE;
1883 /* check smb.conf parameters and the the sec_desc */
1884 raddr = tsocket_address_inet_addr_string(p->remote_address,
1885 p->mem_ctx);
1886 if (raddr == NULL) {
1887 return WERR_NOMEM;
1890 rc = get_remote_hostname(p->remote_address,
1891 &rhost,
1892 p->mem_ctx);
1893 if (rc < 0) {
1894 return WERR_NOMEM;
1896 if (strequal(rhost, "UNKNOWN")) {
1897 rhost = raddr;
1900 if (!allow_access(lp_hostsdeny(snum), lp_hostsallow(snum),
1901 rhost, raddr)) {
1902 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1903 ZERO_STRUCTP(r->out.handle);
1904 return WERR_ACCESS_DENIED;
1907 if (!user_ok_token(uidtoname(p->session_info->unix_token->uid), NULL,
1908 p->session_info->security_token, snum) ||
1909 !print_access_check(p->session_info,
1910 p->msg_ctx,
1911 snum,
1912 r->in.access_mask)) {
1913 DEBUG(3, ("access DENIED for printer open\n"));
1914 close_printer_handle(p, r->out.handle);
1915 ZERO_STRUCTP(r->out.handle);
1916 return WERR_ACCESS_DENIED;
1919 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1920 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1921 close_printer_handle(p, r->out.handle);
1922 ZERO_STRUCTP(r->out.handle);
1923 return WERR_ACCESS_DENIED;
1926 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1927 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1928 else
1929 r->in.access_mask = PRINTER_ACCESS_USE;
1931 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1932 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1934 winreg_create_printer_internal(p->mem_ctx,
1935 get_session_info_system(),
1936 p->msg_ctx,
1937 lp_const_servicename(snum));
1939 break;
1941 default:
1942 /* sanity check to prevent programmer error */
1943 ZERO_STRUCTP(r->out.handle);
1944 return WERR_BADFID;
1947 Printer->access_granted = r->in.access_mask;
1950 * If the client sent a devmode in the OpenPrinter() call, then
1951 * save it here in case we get a job submission on this handle
1954 if ((Printer->printer_type != SPLHND_SERVER)
1955 && (r->in.devmode_ctr.devmode != NULL)) {
1956 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1957 &Printer->devmode);
1960 return WERR_OK;
1963 /****************************************************************
1964 _spoolss_ClosePrinter
1965 ****************************************************************/
1967 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1968 struct spoolss_ClosePrinter *r)
1970 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1972 if (Printer && Printer->document_started) {
1973 struct spoolss_EndDocPrinter e;
1975 e.in.handle = r->in.handle;
1977 _spoolss_EndDocPrinter(p, &e);
1980 if (!close_printer_handle(p, r->in.handle))
1981 return WERR_BADFID;
1983 /* clear the returned printer handle. Observed behavior
1984 from Win2k server. Don't think this really matters.
1985 Previous code just copied the value of the closed
1986 handle. --jerry */
1988 ZERO_STRUCTP(r->out.handle);
1990 return WERR_OK;
1993 /****************************************************************
1994 _spoolss_DeletePrinter
1995 ****************************************************************/
1997 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1998 struct spoolss_DeletePrinter *r)
2000 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2001 WERROR result;
2002 int snum;
2004 if (Printer && Printer->document_started) {
2005 struct spoolss_EndDocPrinter e;
2007 e.in.handle = r->in.handle;
2009 _spoolss_EndDocPrinter(p, &e);
2012 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
2013 winreg_delete_printer_key_internal(p->mem_ctx,
2014 get_session_info_system(),
2015 p->msg_ctx,
2016 lp_const_servicename(snum),
2017 "");
2020 result = delete_printer_handle(p, r->in.handle);
2022 return result;
2025 /*******************************************************************
2026 * static function to lookup the version id corresponding to an
2027 * long architecture string
2028 ******************************************************************/
2030 static const struct print_architecture_table_node archi_table[]= {
2032 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
2033 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
2034 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
2035 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
2036 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
2037 {"Windows IA64", SPL_ARCH_IA64, 3 },
2038 {"Windows x64", SPL_ARCH_X64, 3 },
2039 {NULL, "", -1 }
2042 static const int drv_cversion[] = {SPOOLSS_DRIVER_VERSION_9X,
2043 SPOOLSS_DRIVER_VERSION_NT35,
2044 SPOOLSS_DRIVER_VERSION_NT4,
2045 SPOOLSS_DRIVER_VERSION_200X,
2046 -1};
2048 static int get_version_id(const char *arch)
2050 int i;
2052 for (i=0; archi_table[i].long_archi != NULL; i++)
2054 if (strcmp(arch, archi_table[i].long_archi) == 0)
2055 return (archi_table[i].version);
2058 return -1;
2061 /****************************************************************
2062 _spoolss_DeletePrinterDriver
2063 ****************************************************************/
2065 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
2066 struct spoolss_DeletePrinterDriver *r)
2069 struct spoolss_DriverInfo8 *info = NULL;
2070 int version;
2071 WERROR status;
2072 struct dcerpc_binding_handle *b;
2073 TALLOC_CTX *tmp_ctx = NULL;
2074 int i;
2075 bool found;
2077 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2078 and not a printer admin, then fail */
2080 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
2081 !security_token_has_privilege(p->session_info->security_token,
2082 SEC_PRIV_PRINT_OPERATOR)) {
2083 return WERR_ACCESS_DENIED;
2086 /* check that we have a valid driver name first */
2088 if ((version = get_version_id(r->in.architecture)) == -1) {
2089 return WERR_INVALID_ENVIRONMENT;
2092 tmp_ctx = talloc_new(p->mem_ctx);
2093 if (!tmp_ctx) {
2094 return WERR_NOMEM;
2097 status = winreg_printer_binding_handle(tmp_ctx,
2098 get_session_info_system(),
2099 p->msg_ctx,
2100 &b);
2101 if (!W_ERROR_IS_OK(status)) {
2102 goto done;
2105 for (found = false, i = 0; drv_cversion[i] >= 0; i++) {
2106 status = winreg_get_driver(tmp_ctx, b,
2107 r->in.architecture, r->in.driver,
2108 drv_cversion[i], &info);
2109 if (!W_ERROR_IS_OK(status)) {
2110 DEBUG(5, ("skipping del of driver with version %d\n",
2111 drv_cversion[i]));
2112 continue;
2114 found = true;
2116 if (printer_driver_in_use(tmp_ctx, b, info)) {
2117 status = WERR_PRINTER_DRIVER_IN_USE;
2118 goto done;
2121 status = winreg_del_driver(tmp_ctx, b, info, drv_cversion[i]);
2122 if (!W_ERROR_IS_OK(status)) {
2123 DEBUG(0, ("failed del of driver with version %d\n",
2124 drv_cversion[i]));
2125 goto done;
2128 if (found == false) {
2129 DEBUG(0, ("driver %s not found for deletion\n", r->in.driver));
2130 status = WERR_UNKNOWN_PRINTER_DRIVER;
2131 } else {
2132 status = WERR_OK;
2135 done:
2136 talloc_free(tmp_ctx);
2138 return status;
2141 static WERROR spoolss_dpd_version(TALLOC_CTX *mem_ctx,
2142 struct pipes_struct *p,
2143 struct spoolss_DeletePrinterDriverEx *r,
2144 struct dcerpc_binding_handle *b,
2145 struct spoolss_DriverInfo8 *info)
2147 WERROR status;
2148 bool delete_files;
2150 if (printer_driver_in_use(mem_ctx, b, info)) {
2151 status = WERR_PRINTER_DRIVER_IN_USE;
2152 goto done;
2156 * we have a couple of cases to consider.
2157 * (1) Are any files in use? If so and DPD_DELETE_ALL_FILES is set,
2158 * then the delete should fail if **any** files overlap with
2159 * other drivers
2160 * (2) If DPD_DELETE_UNUSED_FILES is set, then delete all
2161 * non-overlapping files
2162 * (3) If neither DPD_DELETE_ALL_FILES nor DPD_DELETE_UNUSED_FILES
2163 * are set, then do not delete any files
2164 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2167 delete_files = r->in.delete_flags
2168 & (DPD_DELETE_ALL_FILES | DPD_DELETE_UNUSED_FILES);
2171 if (delete_files) {
2172 bool in_use = printer_driver_files_in_use(mem_ctx, b, info);
2173 if (in_use && (r->in.delete_flags & DPD_DELETE_ALL_FILES)) {
2174 status = WERR_PRINTER_DRIVER_IN_USE;
2175 goto done;
2178 * printer_driver_files_in_use() has trimmed overlapping files
2179 * from info so they are not removed on DPD_DELETE_UNUSED_FILES
2184 status = winreg_del_driver(mem_ctx, b, info, info->version);
2185 if (!W_ERROR_IS_OK(status)) {
2186 goto done;
2190 * now delete any associated files if delete_files is
2191 * true. Even if this part failes, we return succes
2192 * because the driver doesn not exist any more
2194 if (delete_files) {
2195 delete_driver_files(p->session_info, info);
2198 done:
2199 return status;
2202 /****************************************************************
2203 _spoolss_DeletePrinterDriverEx
2204 ****************************************************************/
2206 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
2207 struct spoolss_DeletePrinterDriverEx *r)
2209 struct spoolss_DriverInfo8 *info = NULL;
2210 WERROR status;
2211 struct dcerpc_binding_handle *b;
2212 TALLOC_CTX *tmp_ctx = NULL;
2213 int i;
2214 bool found;
2216 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2217 and not a printer admin, then fail */
2219 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
2220 !security_token_has_privilege(p->session_info->security_token,
2221 SEC_PRIV_PRINT_OPERATOR)) {
2222 return WERR_ACCESS_DENIED;
2225 /* check that we have a valid driver name first */
2226 if (get_version_id(r->in.architecture) == -1) {
2227 /* this is what NT returns */
2228 return WERR_INVALID_ENVIRONMENT;
2231 tmp_ctx = talloc_new(p->mem_ctx);
2232 if (!tmp_ctx) {
2233 return WERR_NOMEM;
2236 status = winreg_printer_binding_handle(tmp_ctx,
2237 get_session_info_system(),
2238 p->msg_ctx,
2239 &b);
2240 if (!W_ERROR_IS_OK(status)) {
2241 goto done;
2244 for (found = false, i = 0; drv_cversion[i] >= 0; i++) {
2245 if ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2246 && (drv_cversion[i] != r->in.version)) {
2247 continue;
2250 /* check if a driver with this version exists before delete */
2251 status = winreg_get_driver(tmp_ctx, b,
2252 r->in.architecture, r->in.driver,
2253 drv_cversion[i], &info);
2254 if (!W_ERROR_IS_OK(status)) {
2255 DEBUG(5, ("skipping del of driver with version %d\n",
2256 drv_cversion[i]));
2257 continue;
2259 found = true;
2261 status = spoolss_dpd_version(tmp_ctx, p, r, b, info);
2262 if (!W_ERROR_IS_OK(status)) {
2263 DEBUG(0, ("failed to delete driver with version %d\n",
2264 drv_cversion[i]));
2265 goto done;
2268 if (found == false) {
2269 DEBUG(0, ("driver %s not found for deletion\n", r->in.driver));
2270 status = WERR_UNKNOWN_PRINTER_DRIVER;
2271 } else {
2272 status = WERR_OK;
2275 done:
2276 talloc_free(tmp_ctx);
2277 return status;
2281 /********************************************************************
2282 GetPrinterData on a printer server Handle.
2283 ********************************************************************/
2285 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2286 const char *value,
2287 enum winreg_Type *type,
2288 union spoolss_PrinterData *data)
2290 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2292 if (!strcasecmp_m(value, "W3SvcInstalled")) {
2293 *type = REG_DWORD;
2294 SIVAL(&data->value, 0, 0x00);
2295 return WERR_OK;
2298 if (!strcasecmp_m(value, "BeepEnabled")) {
2299 *type = REG_DWORD;
2300 SIVAL(&data->value, 0, 0x00);
2301 return WERR_OK;
2304 if (!strcasecmp_m(value, "EventLog")) {
2305 *type = REG_DWORD;
2306 /* formally was 0x1b */
2307 SIVAL(&data->value, 0, 0x00);
2308 return WERR_OK;
2311 if (!strcasecmp_m(value, "NetPopup")) {
2312 *type = REG_DWORD;
2313 SIVAL(&data->value, 0, 0x00);
2314 return WERR_OK;
2317 if (!strcasecmp_m(value, "MajorVersion")) {
2318 *type = REG_DWORD;
2320 /* Windows NT 4.0 seems to not allow uploading of drivers
2321 to a server that reports 0x3 as the MajorVersion.
2322 need to investigate more how Win2k gets around this .
2323 -- jerry */
2325 if (RA_WINNT == get_remote_arch()) {
2326 SIVAL(&data->value, 0, 0x02);
2327 } else {
2328 SIVAL(&data->value, 0, 0x03);
2331 return WERR_OK;
2334 if (!strcasecmp_m(value, "MinorVersion")) {
2335 *type = REG_DWORD;
2336 SIVAL(&data->value, 0, 0x00);
2337 return WERR_OK;
2340 /* REG_BINARY
2341 * uint32_t size = 0x114
2342 * uint32_t major = 5
2343 * uint32_t minor = [0|1]
2344 * uint32_t build = [2195|2600]
2345 * extra unicode string = e.g. "Service Pack 3"
2347 if (!strcasecmp_m(value, "OSVersion")) {
2348 DATA_BLOB blob;
2349 enum ndr_err_code ndr_err;
2350 struct spoolss_OSVersion os;
2352 os.major = lp_parm_int(GLOBAL_SECTION_SNUM,
2353 "spoolss", "os_major", 5);
2354 /* Windows 2000 == 5.0 */
2355 os.minor = lp_parm_int(GLOBAL_SECTION_SNUM,
2356 "spoolss", "os_minor", 0);
2357 os.build = lp_parm_int(GLOBAL_SECTION_SNUM,
2358 "spoolss", "os_build", 2195);
2359 os.extra_string = ""; /* leave extra string empty */
2361 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2362 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2363 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2364 return WERR_GENERAL_FAILURE;
2367 if (DEBUGLEVEL >= 10) {
2368 NDR_PRINT_DEBUG(spoolss_OSVersion, &os);
2371 *type = REG_BINARY;
2372 data->binary = blob;
2374 return WERR_OK;
2378 if (!strcasecmp_m(value, "DefaultSpoolDirectory")) {
2379 *type = REG_SZ;
2381 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2382 W_ERROR_HAVE_NO_MEMORY(data->string);
2384 return WERR_OK;
2387 if (!strcasecmp_m(value, "Architecture")) {
2388 *type = REG_SZ;
2389 data->string = talloc_strdup(mem_ctx,
2390 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2391 W_ERROR_HAVE_NO_MEMORY(data->string);
2393 return WERR_OK;
2396 if (!strcasecmp_m(value, "DsPresent")) {
2397 *type = REG_DWORD;
2399 /* only show the publish check box if we are a
2400 member of a AD domain */
2402 if (lp_security() == SEC_ADS) {
2403 SIVAL(&data->value, 0, 0x01);
2404 } else {
2405 SIVAL(&data->value, 0, 0x00);
2407 return WERR_OK;
2410 if (!strcasecmp_m(value, "DNSMachineName")) {
2411 const char *hostname = get_mydnsfullname();
2413 if (!hostname) {
2414 return WERR_BADFILE;
2417 *type = REG_SZ;
2418 data->string = talloc_strdup(mem_ctx, hostname);
2419 W_ERROR_HAVE_NO_MEMORY(data->string);
2421 return WERR_OK;
2424 *type = REG_NONE;
2426 return WERR_INVALID_PARAM;
2429 /****************************************************************
2430 _spoolss_GetPrinterData
2431 ****************************************************************/
2433 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2434 struct spoolss_GetPrinterData *r)
2436 struct spoolss_GetPrinterDataEx r2;
2438 r2.in.handle = r->in.handle;
2439 r2.in.key_name = "PrinterDriverData";
2440 r2.in.value_name = r->in.value_name;
2441 r2.in.offered = r->in.offered;
2442 r2.out.type = r->out.type;
2443 r2.out.data = r->out.data;
2444 r2.out.needed = r->out.needed;
2446 return _spoolss_GetPrinterDataEx(p, &r2);
2449 /*********************************************************
2450 Connect to the client machine.
2451 **********************************************************/
2453 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2454 struct sockaddr_storage *client_ss, const char *remote_machine)
2456 NTSTATUS ret;
2457 struct cli_state *the_cli;
2458 struct sockaddr_storage rm_addr;
2459 char addr[INET6_ADDRSTRLEN];
2461 if ( is_zero_addr(client_ss) ) {
2462 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2463 remote_machine));
2464 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2465 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2466 return false;
2468 print_sockaddr(addr, sizeof(addr), &rm_addr);
2469 } else {
2470 rm_addr = *client_ss;
2471 print_sockaddr(addr, sizeof(addr), &rm_addr);
2472 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2473 addr));
2476 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2477 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2478 addr));
2479 return false;
2482 /* setup the connection */
2483 ret = cli_full_connection( &the_cli, lp_netbios_name(), remote_machine,
2484 &rm_addr, 0, "IPC$", "IPC",
2485 "", /* username */
2486 "", /* domain */
2487 "", /* password */
2488 0, lp_client_signing());
2490 if ( !NT_STATUS_IS_OK( ret ) ) {
2491 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2492 remote_machine ));
2493 return false;
2496 if ( smbXcli_conn_protocol(the_cli->conn) != PROTOCOL_NT1 ) {
2497 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2498 cli_shutdown(the_cli);
2499 return false;
2503 * Ok - we have an anonymous connection to the IPC$ share.
2504 * Now start the NT Domain stuff :-).
2507 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2508 if (!NT_STATUS_IS_OK(ret)) {
2509 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2510 remote_machine, nt_errstr(ret)));
2511 cli_shutdown(the_cli);
2512 return false;
2515 return true;
2518 /***************************************************************************
2519 Connect to the client.
2520 ****************************************************************************/
2522 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2523 uint32_t localprinter,
2524 enum winreg_Type type,
2525 struct policy_handle *handle,
2526 struct notify_back_channel **_chan,
2527 struct sockaddr_storage *client_ss,
2528 struct messaging_context *msg_ctx)
2530 WERROR result;
2531 NTSTATUS status;
2532 struct notify_back_channel *chan;
2534 for (chan = back_channels; chan; chan = chan->next) {
2535 if (memcmp(&chan->client_address, client_ss,
2536 sizeof(struct sockaddr_storage)) == 0) {
2537 break;
2542 * If it's the first connection, contact the client
2543 * and connect to the IPC$ share anonymously
2545 if (!chan) {
2546 fstring unix_printer;
2548 /* the +2 is to strip the leading 2 backslashs */
2549 fstrcpy(unix_printer, printer + 2);
2551 chan = talloc_zero(NULL, struct notify_back_channel);
2552 if (!chan) {
2553 return false;
2555 chan->client_address = *client_ss;
2557 if (!spoolss_connect_to_client(&chan->cli_pipe, client_ss, unix_printer)) {
2558 TALLOC_FREE(chan);
2559 return false;
2562 DLIST_ADD(back_channels, chan);
2564 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2565 receive_notify2_message_list);
2568 if (chan->cli_pipe == NULL ||
2569 chan->cli_pipe->binding_handle == NULL) {
2570 DEBUG(0, ("srv_spoolss_replyopenprinter: error - "
2571 "NULL %s for printer %s\n",
2572 chan->cli_pipe == NULL ?
2573 "chan->cli_pipe" : "chan->cli_pipe->binding_handle",
2574 printer));
2575 return false;
2579 * Tell the specific printing tdb we want messages for this printer
2580 * by registering our PID.
2583 if (!print_notify_register_pid(snum)) {
2584 DEBUG(0, ("Failed to register our pid for printer %s\n",
2585 printer));
2588 status = dcerpc_spoolss_ReplyOpenPrinter(chan->cli_pipe->binding_handle,
2589 talloc_tos(),
2590 printer,
2591 localprinter,
2592 type,
2594 NULL,
2595 handle,
2596 &result);
2597 if (!NT_STATUS_IS_OK(status)) {
2598 DEBUG(5, ("dcerpc_spoolss_ReplyOpenPrinter returned [%s]\n", nt_errstr(status)));
2599 result = ntstatus_to_werror(status);
2600 } else if (!W_ERROR_IS_OK(result)) {
2601 DEBUG(5, ("ReplyOpenPrinter returned [%s]\n", win_errstr(result)));
2604 chan->active_connections++;
2605 *_chan = chan;
2607 return (W_ERROR_IS_OK(result));
2610 /****************************************************************
2611 ****************************************************************/
2613 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2614 const struct spoolss_NotifyOption *r)
2616 struct spoolss_NotifyOption *option;
2617 uint32_t i,k;
2619 if (!r) {
2620 return NULL;
2623 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2624 if (!option) {
2625 return NULL;
2628 *option = *r;
2630 if (!option->count) {
2631 return option;
2634 option->types = talloc_zero_array(option,
2635 struct spoolss_NotifyOptionType, option->count);
2636 if (!option->types) {
2637 talloc_free(option);
2638 return NULL;
2641 for (i=0; i < option->count; i++) {
2642 option->types[i] = r->types[i];
2644 if (option->types[i].count) {
2645 option->types[i].fields = talloc_zero_array(option,
2646 union spoolss_Field, option->types[i].count);
2647 if (!option->types[i].fields) {
2648 talloc_free(option);
2649 return NULL;
2651 for (k=0; k<option->types[i].count; k++) {
2652 option->types[i].fields[k] =
2653 r->types[i].fields[k];
2658 return option;
2661 /****************************************************************
2662 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2664 * before replying OK: status=0 a rpc call is made to the workstation
2665 * asking ReplyOpenPrinter
2667 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2668 * called from api_spoolss_rffpcnex
2669 ****************************************************************/
2671 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2672 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2674 int snum = -1;
2675 struct spoolss_NotifyOption *option = r->in.notify_options;
2676 struct sockaddr_storage client_ss;
2677 ssize_t client_len;
2679 /* store the notify value in the printer struct */
2681 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2683 if (!Printer) {
2684 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2685 "Invalid handle (%s:%u:%u).\n",
2686 OUR_HANDLE(r->in.handle)));
2687 return WERR_BADFID;
2690 Printer->notify.flags = r->in.flags;
2691 Printer->notify.options = r->in.options;
2692 Printer->notify.printerlocal = r->in.printer_local;
2693 Printer->notify.msg_ctx = p->msg_ctx;
2695 TALLOC_FREE(Printer->notify.option);
2696 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2698 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2700 /* Connect to the client machine and send a ReplyOpenPrinter */
2702 if ( Printer->printer_type == SPLHND_SERVER)
2703 snum = -1;
2704 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2705 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2706 return WERR_BADFID;
2708 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2709 "remote_address is %s\n",
2710 tsocket_address_string(p->remote_address, p->mem_ctx)));
2712 if (!lp_print_notify_backchannel(snum)) {
2713 DEBUG(10, ("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2714 "backchannel disabled\n"));
2715 return WERR_SERVER_UNAVAILABLE;
2718 client_len = tsocket_address_bsd_sockaddr(p->remote_address,
2719 (struct sockaddr *) &client_ss,
2720 sizeof(struct sockaddr_storage));
2721 if (client_len < 0) {
2722 return WERR_NOMEM;
2725 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2726 Printer->notify.printerlocal, REG_SZ,
2727 &Printer->notify.cli_hnd,
2728 &Printer->notify.cli_chan,
2729 &client_ss, p->msg_ctx)) {
2730 return WERR_SERVER_UNAVAILABLE;
2733 return WERR_OK;
2736 /*******************************************************************
2737 * fill a notify_info_data with the servername
2738 ********************************************************************/
2740 static void spoolss_notify_server_name(struct messaging_context *msg_ctx,
2741 int snum,
2742 struct spoolss_Notify *data,
2743 print_queue_struct *queue,
2744 struct spoolss_PrinterInfo2 *pinfo2,
2745 TALLOC_CTX *mem_ctx)
2747 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2750 /*******************************************************************
2751 * fill a notify_info_data with the printername (not including the servername).
2752 ********************************************************************/
2754 static void spoolss_notify_printer_name(struct messaging_context *msg_ctx,
2755 int snum,
2756 struct spoolss_Notify *data,
2757 print_queue_struct *queue,
2758 struct spoolss_PrinterInfo2 *pinfo2,
2759 TALLOC_CTX *mem_ctx)
2761 /* the notify name should not contain the \\server\ part */
2762 const char *p = strrchr(pinfo2->printername, '\\');
2764 if (!p) {
2765 p = pinfo2->printername;
2766 } else {
2767 p++;
2770 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2773 /*******************************************************************
2774 * fill a notify_info_data with the servicename
2775 ********************************************************************/
2777 static void spoolss_notify_share_name(struct messaging_context *msg_ctx,
2778 int snum,
2779 struct spoolss_Notify *data,
2780 print_queue_struct *queue,
2781 struct spoolss_PrinterInfo2 *pinfo2,
2782 TALLOC_CTX *mem_ctx)
2784 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(talloc_tos(), snum));
2787 /*******************************************************************
2788 * fill a notify_info_data with the port name
2789 ********************************************************************/
2791 static void spoolss_notify_port_name(struct messaging_context *msg_ctx,
2792 int snum,
2793 struct spoolss_Notify *data,
2794 print_queue_struct *queue,
2795 struct spoolss_PrinterInfo2 *pinfo2,
2796 TALLOC_CTX *mem_ctx)
2798 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2801 /*******************************************************************
2802 * fill a notify_info_data with the printername
2803 * but it doesn't exist, have to see what to do
2804 ********************************************************************/
2806 static void spoolss_notify_driver_name(struct messaging_context *msg_ctx,
2807 int snum,
2808 struct spoolss_Notify *data,
2809 print_queue_struct *queue,
2810 struct spoolss_PrinterInfo2 *pinfo2,
2811 TALLOC_CTX *mem_ctx)
2813 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2816 /*******************************************************************
2817 * fill a notify_info_data with the comment
2818 ********************************************************************/
2820 static void spoolss_notify_comment(struct messaging_context *msg_ctx,
2821 int snum,
2822 struct spoolss_Notify *data,
2823 print_queue_struct *queue,
2824 struct spoolss_PrinterInfo2 *pinfo2,
2825 TALLOC_CTX *mem_ctx)
2827 const char *p;
2829 if (*pinfo2->comment == '\0') {
2830 p = lp_comment(talloc_tos(), snum);
2831 } else {
2832 p = pinfo2->comment;
2835 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2838 /*******************************************************************
2839 * fill a notify_info_data with the comment
2840 * location = "Room 1, floor 2, building 3"
2841 ********************************************************************/
2843 static void spoolss_notify_location(struct messaging_context *msg_ctx,
2844 int snum,
2845 struct spoolss_Notify *data,
2846 print_queue_struct *queue,
2847 struct spoolss_PrinterInfo2 *pinfo2,
2848 TALLOC_CTX *mem_ctx)
2850 const char *loc = pinfo2->location;
2851 NTSTATUS status;
2853 status = printer_list_get_printer(mem_ctx,
2854 pinfo2->sharename,
2855 NULL,
2856 &loc,
2857 NULL);
2858 if (NT_STATUS_IS_OK(status)) {
2859 if (loc == NULL) {
2860 loc = pinfo2->location;
2864 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, loc);
2867 /*******************************************************************
2868 * fill a notify_info_data with the device mode
2869 * jfm:xxxx don't to it for know but that's a real problem !!!
2870 ********************************************************************/
2872 static void spoolss_notify_devmode(struct messaging_context *msg_ctx,
2873 int snum,
2874 struct spoolss_Notify *data,
2875 print_queue_struct *queue,
2876 struct spoolss_PrinterInfo2 *pinfo2,
2877 TALLOC_CTX *mem_ctx)
2879 /* for a dummy implementation we have to zero the fields */
2880 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2883 /*******************************************************************
2884 * fill a notify_info_data with the separator file name
2885 ********************************************************************/
2887 static void spoolss_notify_sepfile(struct messaging_context *msg_ctx,
2888 int snum,
2889 struct spoolss_Notify *data,
2890 print_queue_struct *queue,
2891 struct spoolss_PrinterInfo2 *pinfo2,
2892 TALLOC_CTX *mem_ctx)
2894 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2897 /*******************************************************************
2898 * fill a notify_info_data with the print processor
2899 * jfm:xxxx return always winprint to indicate we don't do anything to it
2900 ********************************************************************/
2902 static void spoolss_notify_print_processor(struct messaging_context *msg_ctx,
2903 int snum,
2904 struct spoolss_Notify *data,
2905 print_queue_struct *queue,
2906 struct spoolss_PrinterInfo2 *pinfo2,
2907 TALLOC_CTX *mem_ctx)
2909 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2912 /*******************************************************************
2913 * fill a notify_info_data with the print processor options
2914 * jfm:xxxx send an empty string
2915 ********************************************************************/
2917 static void spoolss_notify_parameters(struct messaging_context *msg_ctx,
2918 int snum,
2919 struct spoolss_Notify *data,
2920 print_queue_struct *queue,
2921 struct spoolss_PrinterInfo2 *pinfo2,
2922 TALLOC_CTX *mem_ctx)
2924 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2927 /*******************************************************************
2928 * fill a notify_info_data with the data type
2929 * jfm:xxxx always send RAW as data type
2930 ********************************************************************/
2932 static void spoolss_notify_datatype(struct messaging_context *msg_ctx,
2933 int snum,
2934 struct spoolss_Notify *data,
2935 print_queue_struct *queue,
2936 struct spoolss_PrinterInfo2 *pinfo2,
2937 TALLOC_CTX *mem_ctx)
2939 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2942 /*******************************************************************
2943 * fill a notify_info_data with the security descriptor
2944 * jfm:xxxx send an null pointer to say no security desc
2945 * have to implement security before !
2946 ********************************************************************/
2948 static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
2949 int snum,
2950 struct spoolss_Notify *data,
2951 print_queue_struct *queue,
2952 struct spoolss_PrinterInfo2 *pinfo2,
2953 TALLOC_CTX *mem_ctx)
2955 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2958 /*******************************************************************
2959 * fill a notify_info_data with the attributes
2960 * jfm:xxxx a samba printer is always shared
2961 ********************************************************************/
2963 static void spoolss_notify_attributes(struct messaging_context *msg_ctx,
2964 int snum,
2965 struct spoolss_Notify *data,
2966 print_queue_struct *queue,
2967 struct spoolss_PrinterInfo2 *pinfo2,
2968 TALLOC_CTX *mem_ctx)
2970 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2973 /*******************************************************************
2974 * fill a notify_info_data with the priority
2975 ********************************************************************/
2977 static void spoolss_notify_priority(struct messaging_context *msg_ctx,
2978 int snum,
2979 struct spoolss_Notify *data,
2980 print_queue_struct *queue,
2981 struct spoolss_PrinterInfo2 *pinfo2,
2982 TALLOC_CTX *mem_ctx)
2984 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2987 /*******************************************************************
2988 * fill a notify_info_data with the default priority
2989 ********************************************************************/
2991 static void spoolss_notify_default_priority(struct messaging_context *msg_ctx,
2992 int snum,
2993 struct spoolss_Notify *data,
2994 print_queue_struct *queue,
2995 struct spoolss_PrinterInfo2 *pinfo2,
2996 TALLOC_CTX *mem_ctx)
2998 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
3001 /*******************************************************************
3002 * fill a notify_info_data with the start time
3003 ********************************************************************/
3005 static void spoolss_notify_start_time(struct messaging_context *msg_ctx,
3006 int snum,
3007 struct spoolss_Notify *data,
3008 print_queue_struct *queue,
3009 struct spoolss_PrinterInfo2 *pinfo2,
3010 TALLOC_CTX *mem_ctx)
3012 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
3015 /*******************************************************************
3016 * fill a notify_info_data with the until time
3017 ********************************************************************/
3019 static void spoolss_notify_until_time(struct messaging_context *msg_ctx,
3020 int snum,
3021 struct spoolss_Notify *data,
3022 print_queue_struct *queue,
3023 struct spoolss_PrinterInfo2 *pinfo2,
3024 TALLOC_CTX *mem_ctx)
3026 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
3029 /*******************************************************************
3030 * fill a notify_info_data with the status
3031 ********************************************************************/
3033 static void spoolss_notify_status(struct messaging_context *msg_ctx,
3034 int snum,
3035 struct spoolss_Notify *data,
3036 print_queue_struct *queue,
3037 struct spoolss_PrinterInfo2 *pinfo2,
3038 TALLOC_CTX *mem_ctx)
3040 print_status_struct status;
3042 print_queue_length(msg_ctx, snum, &status);
3043 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3046 /*******************************************************************
3047 * fill a notify_info_data with the number of jobs queued
3048 ********************************************************************/
3050 static void spoolss_notify_cjobs(struct messaging_context *msg_ctx,
3051 int snum,
3052 struct spoolss_Notify *data,
3053 print_queue_struct *queue,
3054 struct spoolss_PrinterInfo2 *pinfo2,
3055 TALLOC_CTX *mem_ctx)
3057 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3058 data, print_queue_length(msg_ctx, snum, NULL));
3061 /*******************************************************************
3062 * fill a notify_info_data with the average ppm
3063 ********************************************************************/
3065 static void spoolss_notify_average_ppm(struct messaging_context *msg_ctx,
3066 int snum,
3067 struct spoolss_Notify *data,
3068 print_queue_struct *queue,
3069 struct spoolss_PrinterInfo2 *pinfo2,
3070 TALLOC_CTX *mem_ctx)
3072 /* always respond 8 pages per minutes */
3073 /* a little hard ! */
3074 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
3077 /*******************************************************************
3078 * fill a notify_info_data with username
3079 ********************************************************************/
3081 static void spoolss_notify_username(struct messaging_context *msg_ctx,
3082 int snum,
3083 struct spoolss_Notify *data,
3084 print_queue_struct *queue,
3085 struct spoolss_PrinterInfo2 *pinfo2,
3086 TALLOC_CTX *mem_ctx)
3088 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3091 /*******************************************************************
3092 * fill a notify_info_data with job status
3093 ********************************************************************/
3095 static void spoolss_notify_job_status(struct messaging_context *msg_ctx,
3096 int snum,
3097 struct spoolss_Notify *data,
3098 print_queue_struct *queue,
3099 struct spoolss_PrinterInfo2 *pinfo2,
3100 TALLOC_CTX *mem_ctx)
3102 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3105 /*******************************************************************
3106 * fill a notify_info_data with job name
3107 ********************************************************************/
3109 static void spoolss_notify_job_name(struct messaging_context *msg_ctx,
3110 int snum,
3111 struct spoolss_Notify *data,
3112 print_queue_struct *queue,
3113 struct spoolss_PrinterInfo2 *pinfo2,
3114 TALLOC_CTX *mem_ctx)
3116 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3119 /*******************************************************************
3120 * fill a notify_info_data with job status
3121 ********************************************************************/
3123 static void spoolss_notify_job_status_string(struct messaging_context *msg_ctx,
3124 int snum,
3125 struct spoolss_Notify *data,
3126 print_queue_struct *queue,
3127 struct spoolss_PrinterInfo2 *pinfo2,
3128 TALLOC_CTX *mem_ctx)
3131 * Now we're returning job status codes we just return a "" here. JRA.
3134 const char *p = "";
3136 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3137 p = "unknown";
3139 switch (queue->status) {
3140 case LPQ_QUEUED:
3141 p = "Queued";
3142 break;
3143 case LPQ_PAUSED:
3144 p = ""; /* NT provides the paused string */
3145 break;
3146 case LPQ_SPOOLING:
3147 p = "Spooling";
3148 break;
3149 case LPQ_PRINTING:
3150 p = "Printing";
3151 break;
3153 #endif /* NO LONGER NEEDED. */
3155 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3158 /*******************************************************************
3159 * fill a notify_info_data with job time
3160 ********************************************************************/
3162 static void spoolss_notify_job_time(struct messaging_context *msg_ctx,
3163 int snum,
3164 struct spoolss_Notify *data,
3165 print_queue_struct *queue,
3166 struct spoolss_PrinterInfo2 *pinfo2,
3167 TALLOC_CTX *mem_ctx)
3169 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3172 /*******************************************************************
3173 * fill a notify_info_data with job size
3174 ********************************************************************/
3176 static void spoolss_notify_job_size(struct messaging_context *msg_ctx,
3177 int snum,
3178 struct spoolss_Notify *data,
3179 print_queue_struct *queue,
3180 struct spoolss_PrinterInfo2 *pinfo2,
3181 TALLOC_CTX *mem_ctx)
3183 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3186 /*******************************************************************
3187 * fill a notify_info_data with page info
3188 ********************************************************************/
3189 static void spoolss_notify_total_pages(struct messaging_context *msg_ctx,
3190 int snum,
3191 struct spoolss_Notify *data,
3192 print_queue_struct *queue,
3193 struct spoolss_PrinterInfo2 *pinfo2,
3194 TALLOC_CTX *mem_ctx)
3196 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3199 /*******************************************************************
3200 * fill a notify_info_data with pages printed info.
3201 ********************************************************************/
3202 static void spoolss_notify_pages_printed(struct messaging_context *msg_ctx,
3203 int snum,
3204 struct spoolss_Notify *data,
3205 print_queue_struct *queue,
3206 struct spoolss_PrinterInfo2 *pinfo2,
3207 TALLOC_CTX *mem_ctx)
3209 /* Add code when back-end tracks this */
3210 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3213 /*******************************************************************
3214 Fill a notify_info_data with job position.
3215 ********************************************************************/
3217 static void spoolss_notify_job_position(struct messaging_context *msg_ctx,
3218 int snum,
3219 struct spoolss_Notify *data,
3220 print_queue_struct *queue,
3221 struct spoolss_PrinterInfo2 *pinfo2,
3222 TALLOC_CTX *mem_ctx)
3224 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->sysjob);
3227 /*******************************************************************
3228 Fill a notify_info_data with submitted time.
3229 ********************************************************************/
3231 static void spoolss_notify_submitted_time(struct messaging_context *msg_ctx,
3232 int snum,
3233 struct spoolss_Notify *data,
3234 print_queue_struct *queue,
3235 struct spoolss_PrinterInfo2 *pinfo2,
3236 TALLOC_CTX *mem_ctx)
3238 data->data.string.string = NULL;
3239 data->data.string.size = 0;
3241 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3242 &data->data.string.string,
3243 &data->data.string.size);
3247 struct s_notify_info_data_table
3249 enum spoolss_NotifyType type;
3250 uint16_t field;
3251 const char *name;
3252 enum spoolss_NotifyTable variable_type;
3253 void (*fn) (struct messaging_context *msg_ctx,
3254 int snum, struct spoolss_Notify *data,
3255 print_queue_struct *queue,
3256 struct spoolss_PrinterInfo2 *pinfo2,
3257 TALLOC_CTX *mem_ctx);
3260 /* A table describing the various print notification constants and
3261 whether the notification data is a pointer to a variable sized
3262 buffer, a one value uint32_t or a two value uint32_t. */
3264 static const struct s_notify_info_data_table notify_info_data_table[] =
3266 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3267 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3268 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3269 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3270 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3271 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3272 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3273 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3274 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3275 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3276 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3277 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3278 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3279 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3280 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3281 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3282 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3283 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3284 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3285 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3286 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3287 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3288 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3289 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3290 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3291 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3292 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3293 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3294 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3295 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3296 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3297 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3298 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3299 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3300 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3301 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3302 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3303 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3304 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3305 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3306 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3307 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3308 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3309 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3310 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3311 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3312 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3313 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3314 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3317 /*******************************************************************
3318 Return the variable_type of info_data structure.
3319 ********************************************************************/
3321 static enum spoolss_NotifyTable variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3322 uint16_t field)
3324 int i=0;
3326 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3327 if ( (notify_info_data_table[i].type == type) &&
3328 (notify_info_data_table[i].field == field) ) {
3329 return notify_info_data_table[i].variable_type;
3333 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3335 return (enum spoolss_NotifyTable) 0;
3338 /****************************************************************************
3339 ****************************************************************************/
3341 static bool search_notify(enum spoolss_NotifyType type,
3342 uint16_t field,
3343 int *value)
3345 int i;
3347 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3348 if (notify_info_data_table[i].type == type &&
3349 notify_info_data_table[i].field == field &&
3350 notify_info_data_table[i].fn != NULL) {
3351 *value = i;
3352 return true;
3356 return false;
3359 /****************************************************************************
3360 ****************************************************************************/
3362 static void construct_info_data(struct spoolss_Notify *info_data,
3363 enum spoolss_NotifyType type,
3364 uint16_t field, int id)
3366 info_data->type = type;
3367 info_data->field.field = field;
3368 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3369 info_data->job_id = id;
3372 /*******************************************************************
3374 * fill a notify_info struct with info asked
3376 ********************************************************************/
3378 static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
3379 struct printer_handle *print_hnd,
3380 struct spoolss_NotifyInfo *info,
3381 struct spoolss_PrinterInfo2 *pinfo2,
3382 int snum,
3383 const struct spoolss_NotifyOptionType *option_type,
3384 uint32_t id,
3385 TALLOC_CTX *mem_ctx)
3387 int field_num,j;
3388 enum spoolss_NotifyType type;
3389 uint16_t field;
3391 struct spoolss_Notify *current_data;
3393 type = option_type->type;
3395 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3396 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3397 option_type->count, lp_servicename(talloc_tos(), snum)));
3399 for(field_num=0; field_num < option_type->count; field_num++) {
3400 field = option_type->fields[field_num].field;
3402 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3404 if (!search_notify(type, field, &j) )
3405 continue;
3407 info->notifies = talloc_realloc(info, info->notifies,
3408 struct spoolss_Notify,
3409 info->count + 1);
3410 if (info->notifies == NULL) {
3411 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3412 return false;
3415 current_data = &info->notifies[info->count];
3417 construct_info_data(current_data, type, field, id);
3419 DEBUG(10, ("construct_notify_printer_info: "
3420 "calling [%s] snum=%d printername=[%s])\n",
3421 notify_info_data_table[j].name, snum,
3422 pinfo2->printername));
3424 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3425 NULL, pinfo2, mem_ctx);
3427 info->count++;
3430 return true;
3433 /*******************************************************************
3435 * fill a notify_info struct with info asked
3437 ********************************************************************/
3439 static bool construct_notify_jobs_info(struct messaging_context *msg_ctx,
3440 print_queue_struct *queue,
3441 struct spoolss_NotifyInfo *info,
3442 struct spoolss_PrinterInfo2 *pinfo2,
3443 int snum,
3444 const struct spoolss_NotifyOptionType *option_type,
3445 uint32_t id,
3446 TALLOC_CTX *mem_ctx)
3448 int field_num,j;
3449 enum spoolss_NotifyType type;
3450 uint16_t field;
3451 struct spoolss_Notify *current_data;
3453 DEBUG(4,("construct_notify_jobs_info\n"));
3455 type = option_type->type;
3457 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3458 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3459 option_type->count));
3461 for(field_num=0; field_num<option_type->count; field_num++) {
3462 field = option_type->fields[field_num].field;
3464 if (!search_notify(type, field, &j) )
3465 continue;
3467 info->notifies = talloc_realloc(info, info->notifies,
3468 struct spoolss_Notify,
3469 info->count + 1);
3470 if (info->notifies == NULL) {
3471 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3472 return false;
3475 current_data=&(info->notifies[info->count]);
3477 construct_info_data(current_data, type, field, id);
3478 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3479 queue, pinfo2, mem_ctx);
3480 info->count++;
3483 return true;
3487 * JFM: The enumeration is not that simple, it's even non obvious.
3489 * let's take an example: I want to monitor the PRINTER SERVER for
3490 * the printer's name and the number of jobs currently queued.
3491 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3492 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3494 * I have 3 printers on the back of my server.
3496 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3497 * structures.
3498 * Number Data Id
3499 * 1 printer 1 name 1
3500 * 2 printer 1 cjob 1
3501 * 3 printer 2 name 2
3502 * 4 printer 2 cjob 2
3503 * 5 printer 3 name 3
3504 * 6 printer 3 name 3
3506 * that's the print server case, the printer case is even worse.
3509 /*******************************************************************
3511 * enumerate all printers on the printserver
3512 * fill a notify_info struct with info asked
3514 ********************************************************************/
3516 static WERROR printserver_notify_info(struct pipes_struct *p,
3517 struct policy_handle *hnd,
3518 struct spoolss_NotifyInfo *info,
3519 TALLOC_CTX *mem_ctx)
3521 int snum;
3522 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3523 int n_services=lp_numservices();
3524 int i;
3525 struct spoolss_NotifyOption *option;
3526 struct spoolss_NotifyOptionType option_type;
3527 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3528 WERROR result;
3530 DEBUG(4,("printserver_notify_info\n"));
3532 if (!Printer)
3533 return WERR_BADFID;
3535 option = Printer->notify.option;
3537 info->version = 2;
3538 info->notifies = NULL;
3539 info->count = 0;
3541 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3542 sending a ffpcn() request first */
3544 if ( !option )
3545 return WERR_BADFID;
3547 for (i=0; i<option->count; i++) {
3548 option_type = option->types[i];
3550 if (option_type.type != PRINTER_NOTIFY_TYPE)
3551 continue;
3553 for (snum = 0; snum < n_services; snum++) {
3554 if (!lp_browseable(snum) ||
3555 !lp_snum_ok(snum) ||
3556 !lp_print_ok(snum)) {
3557 continue; /* skip */
3560 /* Maybe we should use the SYSTEM session_info here... */
3561 result = winreg_get_printer_internal(mem_ctx,
3562 get_session_info_system(),
3563 p->msg_ctx,
3564 lp_servicename(talloc_tos(), snum),
3565 &pinfo2);
3566 if (!W_ERROR_IS_OK(result)) {
3567 DEBUG(4, ("printserver_notify_info: "
3568 "Failed to get printer [%s]\n",
3569 lp_servicename(talloc_tos(), snum)));
3570 continue;
3574 construct_notify_printer_info(p->msg_ctx,
3575 Printer, info,
3576 pinfo2, snum,
3577 &option_type, snum,
3578 mem_ctx);
3580 TALLOC_FREE(pinfo2);
3584 #if 0
3586 * Debugging information, don't delete.
3589 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3590 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3591 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3593 for (i=0; i<info->count; i++) {
3594 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3595 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3596 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3598 #endif
3600 return WERR_OK;
3603 /*******************************************************************
3605 * fill a notify_info struct with info asked
3607 ********************************************************************/
3609 static WERROR printer_notify_info(struct pipes_struct *p,
3610 struct policy_handle *hnd,
3611 struct spoolss_NotifyInfo *info,
3612 TALLOC_CTX *mem_ctx)
3614 int snum;
3615 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3616 int i;
3617 uint32_t id;
3618 struct spoolss_NotifyOption *option;
3619 struct spoolss_NotifyOptionType option_type;
3620 int count,j;
3621 print_queue_struct *queue=NULL;
3622 print_status_struct status;
3623 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3624 WERROR result;
3625 struct tdb_print_db *pdb;
3627 DEBUG(4,("printer_notify_info\n"));
3629 if (!Printer)
3630 return WERR_BADFID;
3632 option = Printer->notify.option;
3633 id = 0x0;
3635 info->version = 2;
3636 info->notifies = NULL;
3637 info->count = 0;
3639 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3640 sending a ffpcn() request first */
3642 if ( !option )
3643 return WERR_BADFID;
3645 if (!get_printer_snum(p, hnd, &snum, NULL)) {
3646 return WERR_BADFID;
3649 pdb = get_print_db_byname(Printer->sharename);
3650 if (pdb == NULL) {
3651 return WERR_BADFID;
3654 /* Maybe we should use the SYSTEM session_info here... */
3655 result = winreg_get_printer_internal(mem_ctx,
3656 get_session_info_system(),
3657 p->msg_ctx,
3658 lp_servicename(talloc_tos(), snum), &pinfo2);
3659 if (!W_ERROR_IS_OK(result)) {
3660 result = WERR_BADFID;
3661 goto err_pdb_drop;
3665 * When sending a PRINTER_NOTIFY_FIELD_SERVER_NAME we should send the
3666 * correct servername.
3668 pinfo2->servername = talloc_strdup(pinfo2, Printer->servername);
3669 if (pinfo2->servername == NULL) {
3670 result = WERR_NOMEM;
3671 goto err_pdb_drop;
3674 for (i = 0; i < option->count; i++) {
3675 option_type = option->types[i];
3677 switch (option_type.type) {
3678 case PRINTER_NOTIFY_TYPE:
3679 if (construct_notify_printer_info(p->msg_ctx,
3680 Printer, info,
3681 pinfo2, snum,
3682 &option_type, id,
3683 mem_ctx)) {
3684 id--;
3686 break;
3688 case JOB_NOTIFY_TYPE:
3690 count = print_queue_status(p->msg_ctx, snum, &queue,
3691 &status);
3693 for (j = 0; j < count; j++) {
3694 uint32_t jobid;
3695 jobid = sysjob_to_jobid_pdb(pdb,
3696 queue[j].sysjob);
3697 if (jobid == (uint32_t)-1) {
3698 DEBUG(2, ("ignoring untracked job %d\n",
3699 queue[j].sysjob));
3700 continue;
3702 /* FIXME check return value */
3703 construct_notify_jobs_info(p->msg_ctx,
3704 &queue[j], info,
3705 pinfo2, snum,
3706 &option_type,
3707 jobid,
3708 mem_ctx);
3711 SAFE_FREE(queue);
3712 break;
3717 * Debugging information, don't delete.
3720 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3721 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3722 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3724 for (i=0; i<info->count; i++) {
3725 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3726 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3727 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3731 talloc_free(pinfo2);
3732 result = WERR_OK;
3733 err_pdb_drop:
3734 release_print_db(pdb);
3735 return result;
3738 /****************************************************************
3739 _spoolss_RouterRefreshPrinterChangeNotify
3740 ****************************************************************/
3742 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3743 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3745 struct spoolss_NotifyInfo *info;
3747 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
3748 WERROR result = WERR_BADFID;
3750 /* we always have a spoolss_NotifyInfo struct */
3751 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3752 if (!info) {
3753 result = WERR_NOMEM;
3754 goto done;
3757 *r->out.info = info;
3759 if (!Printer) {
3760 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3761 "Invalid handle (%s:%u:%u).\n",
3762 OUR_HANDLE(r->in.handle)));
3763 goto done;
3766 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3769 * We are now using the change value, and
3770 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3771 * I don't have a global notification system, I'm sending back all the
3772 * information even when _NOTHING_ has changed.
3775 /* We need to keep track of the change value to send back in
3776 RRPCN replies otherwise our updates are ignored. */
3778 Printer->notify.fnpcn = true;
3780 if (Printer->notify.cli_chan != NULL &&
3781 Printer->notify.cli_chan->active_connections > 0) {
3782 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3783 "Saving change value in request [%x]\n",
3784 r->in.change_low));
3785 Printer->notify.change = r->in.change_low;
3788 /* just ignore the spoolss_NotifyOption */
3790 switch (Printer->printer_type) {
3791 case SPLHND_SERVER:
3792 result = printserver_notify_info(p, r->in.handle,
3793 info, p->mem_ctx);
3794 break;
3796 case SPLHND_PRINTER:
3797 result = printer_notify_info(p, r->in.handle,
3798 info, p->mem_ctx);
3799 break;
3802 Printer->notify.fnpcn = false;
3804 done:
3805 return result;
3808 /********************************************************************
3809 ********************************************************************/
3811 static WERROR create_printername(TALLOC_CTX *mem_ctx,
3812 const char *servername,
3813 const char *printername,
3814 const char **printername_p)
3816 /* FIXME: add lp_force_printername() */
3818 if (servername == NULL) {
3819 *printername_p = talloc_strdup(mem_ctx, printername);
3820 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3821 return WERR_OK;
3824 if (servername[0] == '\\' && servername[1] == '\\') {
3825 servername += 2;
3828 *printername_p = talloc_asprintf(mem_ctx, "\\\\%s\\%s", servername, printername);
3829 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3831 return WERR_OK;
3834 /********************************************************************
3835 ********************************************************************/
3837 static void compose_devicemode_devicename(struct spoolss_DeviceMode *dm,
3838 const char *printername)
3840 if (dm == NULL) {
3841 return;
3844 dm->devicename = talloc_strndup(dm, printername,
3845 MIN(strlen(printername), 31));
3848 /********************************************************************
3849 * construct_printer_info_0
3850 * fill a printer_info_0 struct
3851 ********************************************************************/
3853 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3854 const struct auth_session_info *session_info,
3855 struct messaging_context *msg_ctx,
3856 struct spoolss_PrinterInfo2 *info2,
3857 const char *servername,
3858 struct spoolss_PrinterInfo0 *r,
3859 int snum)
3861 int count;
3862 struct printer_session_counter *session_counter;
3863 struct timeval setuptime;
3864 print_status_struct status;
3865 WERROR result;
3867 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3868 if (!W_ERROR_IS_OK(result)) {
3869 return result;
3872 if (servername) {
3873 r->servername = talloc_strdup(mem_ctx, servername);
3874 W_ERROR_HAVE_NO_MEMORY(r->servername);
3875 } else {
3876 r->servername = NULL;
3879 count = print_queue_length(msg_ctx, snum, &status);
3881 /* check if we already have a counter for this printer */
3882 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3883 if (session_counter->snum == snum)
3884 break;
3887 /* it's the first time, add it to the list */
3888 if (session_counter == NULL) {
3889 session_counter = talloc_zero(counter_list, struct printer_session_counter);
3890 W_ERROR_HAVE_NO_MEMORY(session_counter);
3891 session_counter->snum = snum;
3892 session_counter->counter = 0;
3893 DLIST_ADD(counter_list, session_counter);
3896 /* increment it */
3897 session_counter->counter++;
3899 r->cjobs = count;
3900 r->total_jobs = 0;
3901 r->total_bytes = 0;
3903 get_startup_time(&setuptime);
3904 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3906 /* JFM:
3907 * the global_counter should be stored in a TDB as it's common to all the clients
3908 * and should be zeroed on samba startup
3910 r->global_counter = session_counter->counter;
3911 r->total_pages = 0;
3912 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3913 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3914 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3915 r->free_build = SPOOLSS_RELEASE_BUILD;
3916 r->spooling = 0;
3917 r->max_spooling = 0;
3918 r->session_counter = session_counter->counter;
3919 r->num_error_out_of_paper = 0x0;
3920 r->num_error_not_ready = 0x0; /* number of print failure */
3921 r->job_error = 0x0;
3922 r->number_of_processors = 0x1;
3923 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3924 r->high_part_total_bytes = 0x0;
3926 /* ChangeID in milliseconds*/
3927 winreg_printer_get_changeid_internal(mem_ctx, session_info, msg_ctx,
3928 info2->sharename, &r->change_id);
3930 r->last_error = WERR_OK;
3931 r->status = nt_printq_status(status.status);
3932 r->enumerate_network_printers = 0x0;
3933 r->c_setprinter = 0x0;
3934 r->processor_architecture = PROCESSOR_ARCHITECTURE_INTEL;
3935 r->processor_level = 0x6; /* 6 ???*/
3936 r->ref_ic = 0;
3937 r->reserved2 = 0;
3938 r->reserved3 = 0;
3940 return WERR_OK;
3944 /********************************************************************
3945 * construct_printer_info1
3946 * fill a spoolss_PrinterInfo1 struct
3947 ********************************************************************/
3949 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3950 const struct spoolss_PrinterInfo2 *info2,
3951 uint32_t flags,
3952 const char *servername,
3953 struct spoolss_PrinterInfo1 *r,
3954 int snum)
3956 WERROR result;
3958 r->flags = flags;
3960 if (info2->comment == NULL || info2->comment[0] == '\0') {
3961 r->comment = lp_comment(mem_ctx, snum);
3962 } else {
3963 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3965 W_ERROR_HAVE_NO_MEMORY(r->comment);
3967 result = create_printername(mem_ctx, servername, info2->printername, &r->name);
3968 if (!W_ERROR_IS_OK(result)) {
3969 return result;
3972 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3973 r->name,
3974 info2->drivername,
3975 r->comment);
3976 W_ERROR_HAVE_NO_MEMORY(r->description);
3978 return WERR_OK;
3981 /********************************************************************
3982 * construct_printer_info2
3983 * fill a spoolss_PrinterInfo2 struct
3984 ********************************************************************/
3986 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3987 struct messaging_context *msg_ctx,
3988 const struct spoolss_PrinterInfo2 *info2,
3989 const char *servername,
3990 struct spoolss_PrinterInfo2 *r,
3991 int snum)
3993 int count;
3994 print_status_struct status;
3995 WERROR result;
3997 count = print_queue_length(msg_ctx, snum, &status);
3999 if (servername) {
4000 r->servername = talloc_strdup(mem_ctx, servername);
4001 W_ERROR_HAVE_NO_MEMORY(r->servername);
4002 } else {
4003 r->servername = NULL;
4006 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4007 if (!W_ERROR_IS_OK(result)) {
4008 return result;
4011 r->sharename = lp_servicename(mem_ctx, snum);
4012 W_ERROR_HAVE_NO_MEMORY(r->sharename);
4013 r->portname = talloc_strdup(mem_ctx, info2->portname);
4014 W_ERROR_HAVE_NO_MEMORY(r->portname);
4015 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
4016 W_ERROR_HAVE_NO_MEMORY(r->drivername);
4018 if (info2->comment[0] == '\0') {
4019 r->comment = lp_comment(mem_ctx, snum);
4020 } else {
4021 r->comment = talloc_strdup(mem_ctx, info2->comment);
4023 W_ERROR_HAVE_NO_MEMORY(r->comment);
4025 r->location = talloc_strdup(mem_ctx, info2->location);
4026 if (info2->location[0] == '\0') {
4027 const char *loc = NULL;
4028 NTSTATUS nt_status;
4030 nt_status = printer_list_get_printer(mem_ctx,
4031 info2->sharename,
4032 NULL,
4033 &loc,
4034 NULL);
4035 if (NT_STATUS_IS_OK(nt_status)) {
4036 if (loc != NULL) {
4037 r->location = talloc_strdup(mem_ctx, loc);
4041 W_ERROR_HAVE_NO_MEMORY(r->location);
4043 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
4044 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
4045 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
4046 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
4047 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
4048 W_ERROR_HAVE_NO_MEMORY(r->datatype);
4049 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
4050 W_ERROR_HAVE_NO_MEMORY(r->parameters);
4052 r->attributes = info2->attributes;
4054 r->priority = info2->priority;
4055 r->defaultpriority = info2->defaultpriority;
4056 r->starttime = info2->starttime;
4057 r->untiltime = info2->untiltime;
4058 r->status = nt_printq_status(status.status);
4059 r->cjobs = count;
4060 r->averageppm = info2->averageppm;
4062 if (info2->devmode != NULL) {
4063 result = copy_devicemode(mem_ctx,
4064 info2->devmode,
4065 &r->devmode);
4066 if (!W_ERROR_IS_OK(result)) {
4067 return result;
4069 } else if (lp_default_devmode(snum)) {
4070 result = spoolss_create_default_devmode(mem_ctx,
4071 info2->printername,
4072 &r->devmode);
4073 if (!W_ERROR_IS_OK(result)) {
4074 return result;
4076 } else {
4077 r->devmode = NULL;
4078 DEBUG(8,("Returning NULL Devicemode!\n"));
4081 compose_devicemode_devicename(r->devmode, r->printername);
4083 r->secdesc = NULL;
4085 if (info2->secdesc != NULL) {
4086 /* don't use talloc_steal() here unless you do a deep steal of all
4087 the SEC_DESC members */
4089 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4092 return WERR_OK;
4095 /********************************************************************
4096 * construct_printer_info3
4097 * fill a spoolss_PrinterInfo3 struct
4098 ********************************************************************/
4100 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
4101 const struct spoolss_PrinterInfo2 *info2,
4102 const char *servername,
4103 struct spoolss_PrinterInfo3 *r,
4104 int snum)
4106 /* These are the components of the SD we are returning. */
4108 if (info2->secdesc != NULL) {
4109 /* don't use talloc_steal() here unless you do a deep steal of all
4110 the SEC_DESC members */
4112 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4113 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
4116 return WERR_OK;
4119 /********************************************************************
4120 * construct_printer_info4
4121 * fill a spoolss_PrinterInfo4 struct
4122 ********************************************************************/
4124 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4125 const struct spoolss_PrinterInfo2 *info2,
4126 const char *servername,
4127 struct spoolss_PrinterInfo4 *r,
4128 int snum)
4130 WERROR result;
4132 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4133 if (!W_ERROR_IS_OK(result)) {
4134 return result;
4137 if (servername) {
4138 r->servername = talloc_strdup(mem_ctx, servername);
4139 W_ERROR_HAVE_NO_MEMORY(r->servername);
4140 } else {
4141 r->servername = NULL;
4144 r->attributes = info2->attributes;
4146 return WERR_OK;
4149 /********************************************************************
4150 * construct_printer_info5
4151 * fill a spoolss_PrinterInfo5 struct
4152 ********************************************************************/
4154 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4155 const struct spoolss_PrinterInfo2 *info2,
4156 const char *servername,
4157 struct spoolss_PrinterInfo5 *r,
4158 int snum)
4160 WERROR result;
4162 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4163 if (!W_ERROR_IS_OK(result)) {
4164 return result;
4167 r->portname = talloc_strdup(mem_ctx, info2->portname);
4168 W_ERROR_HAVE_NO_MEMORY(r->portname);
4170 r->attributes = info2->attributes;
4172 /* these two are not used by NT+ according to MSDN */
4173 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4174 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4176 return WERR_OK;
4179 /********************************************************************
4180 * construct_printer_info_6
4181 * fill a spoolss_PrinterInfo6 struct
4182 ********************************************************************/
4184 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4185 struct messaging_context *msg_ctx,
4186 const struct spoolss_PrinterInfo2 *info2,
4187 const char *servername,
4188 struct spoolss_PrinterInfo6 *r,
4189 int snum)
4191 print_status_struct status;
4193 print_queue_length(msg_ctx, snum, &status);
4195 r->status = nt_printq_status(status.status);
4197 return WERR_OK;
4200 /********************************************************************
4201 * construct_printer_info7
4202 * fill a spoolss_PrinterInfo7 struct
4203 ********************************************************************/
4205 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4206 struct messaging_context *msg_ctx,
4207 const char *servername,
4208 struct spoolss_PrinterInfo7 *r,
4209 int snum)
4211 const struct auth_session_info *session_info;
4212 char *printer;
4213 WERROR werr;
4214 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
4215 if (tmp_ctx == NULL) {
4216 return WERR_NOMEM;
4219 session_info = get_session_info_system();
4220 SMB_ASSERT(session_info != NULL);
4222 printer = lp_servicename(tmp_ctx, snum);
4223 if (printer == NULL) {
4224 DEBUG(0, ("invalid printer snum %d\n", snum));
4225 werr = WERR_INVALID_PARAM;
4226 goto out_tmp_free;
4229 if (is_printer_published(tmp_ctx, session_info, msg_ctx,
4230 servername, printer, NULL)) {
4231 struct GUID guid;
4232 werr = nt_printer_guid_get(tmp_ctx, session_info, msg_ctx,
4233 printer, &guid);
4234 if (!W_ERROR_IS_OK(werr)) {
4235 goto out_tmp_free;
4237 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4238 r->action = DSPRINT_PUBLISH;
4239 } else {
4240 r->guid = talloc_strdup(mem_ctx, "");
4241 r->action = DSPRINT_UNPUBLISH;
4243 if (r->guid == NULL) {
4244 werr = WERR_NOMEM;
4245 goto out_tmp_free;
4248 werr = WERR_OK;
4249 out_tmp_free:
4250 talloc_free(tmp_ctx);
4251 return werr;
4254 /********************************************************************
4255 * construct_printer_info8
4256 * fill a spoolss_PrinterInfo8 struct
4257 ********************************************************************/
4259 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4260 const struct spoolss_PrinterInfo2 *info2,
4261 const char *servername,
4262 struct spoolss_DeviceModeInfo *r,
4263 int snum)
4265 WERROR result;
4266 const char *printername;
4268 result = create_printername(mem_ctx, servername, info2->printername, &printername);
4269 if (!W_ERROR_IS_OK(result)) {
4270 return result;
4273 if (info2->devmode != NULL) {
4274 result = copy_devicemode(mem_ctx,
4275 info2->devmode,
4276 &r->devmode);
4277 if (!W_ERROR_IS_OK(result)) {
4278 return result;
4280 } else if (lp_default_devmode(snum)) {
4281 result = spoolss_create_default_devmode(mem_ctx,
4282 info2->printername,
4283 &r->devmode);
4284 if (!W_ERROR_IS_OK(result)) {
4285 return result;
4287 } else {
4288 r->devmode = NULL;
4289 DEBUG(8,("Returning NULL Devicemode!\n"));
4292 compose_devicemode_devicename(r->devmode, printername);
4294 return WERR_OK;
4297 /********************************************************************
4298 Spoolss_enumprinters.
4299 ********************************************************************/
4301 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4302 const struct auth_session_info *session_info,
4303 struct messaging_context *msg_ctx,
4304 const char *servername,
4305 uint32_t level,
4306 uint32_t flags,
4307 union spoolss_PrinterInfo **info_p,
4308 uint32_t *count_p)
4310 int snum;
4311 int n_services;
4312 union spoolss_PrinterInfo *info = NULL;
4313 uint32_t count = 0;
4314 WERROR result = WERR_OK;
4315 struct dcerpc_binding_handle *b = NULL;
4316 TALLOC_CTX *tmp_ctx = NULL;
4318 tmp_ctx = talloc_new(mem_ctx);
4319 if (!tmp_ctx) {
4320 return WERR_NOMEM;
4324 * printer shares are updated on client enumeration. The background
4325 * printer process updates printer_list.tdb at regular intervals.
4327 become_root();
4328 delete_and_reload_printers(server_event_context(), msg_ctx);
4329 unbecome_root();
4331 n_services = lp_numservices();
4332 *count_p = 0;
4333 *info_p = NULL;
4335 for (snum = 0; snum < n_services; snum++) {
4337 const char *printer;
4338 struct spoolss_PrinterInfo2 *info2;
4340 if (!snum_is_shared_printer(snum)) {
4341 continue;
4344 printer = lp_const_servicename(snum);
4346 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4347 printer, snum));
4349 if (b == NULL) {
4350 result = winreg_printer_binding_handle(tmp_ctx,
4351 session_info,
4352 msg_ctx,
4353 &b);
4354 if (!W_ERROR_IS_OK(result)) {
4355 goto out;
4359 result = winreg_create_printer(tmp_ctx, b,
4360 printer);
4361 if (!W_ERROR_IS_OK(result)) {
4362 goto out;
4365 info = talloc_realloc(tmp_ctx, info,
4366 union spoolss_PrinterInfo,
4367 count + 1);
4368 if (!info) {
4369 result = WERR_NOMEM;
4370 goto out;
4373 result = winreg_get_printer(tmp_ctx, b,
4374 printer, &info2);
4375 if (!W_ERROR_IS_OK(result)) {
4376 goto out;
4379 switch (level) {
4380 case 0:
4381 result = construct_printer_info0(info, session_info,
4382 msg_ctx, info2,
4383 servername,
4384 &info[count].info0, snum);
4385 break;
4386 case 1:
4387 result = construct_printer_info1(info, info2, flags,
4388 servername,
4389 &info[count].info1, snum);
4390 break;
4391 case 2:
4392 result = construct_printer_info2(info, msg_ctx, info2,
4393 servername,
4394 &info[count].info2, snum);
4395 break;
4396 case 4:
4397 result = construct_printer_info4(info, info2,
4398 servername,
4399 &info[count].info4, snum);
4400 break;
4401 case 5:
4402 result = construct_printer_info5(info, info2,
4403 servername,
4404 &info[count].info5, snum);
4405 break;
4407 default:
4408 result = WERR_UNKNOWN_LEVEL;
4409 goto out;
4412 if (!W_ERROR_IS_OK(result)) {
4413 goto out;
4416 count++;
4419 out:
4420 if (W_ERROR_IS_OK(result)) {
4421 *info_p = talloc_move(mem_ctx, &info);
4422 *count_p = count;
4425 talloc_free(tmp_ctx);
4427 return result;
4430 /********************************************************************
4431 * handle enumeration of printers at level 0
4432 ********************************************************************/
4434 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4435 const struct auth_session_info *session_info,
4436 struct messaging_context *msg_ctx,
4437 uint32_t flags,
4438 const char *servername,
4439 union spoolss_PrinterInfo **info,
4440 uint32_t *count)
4442 DEBUG(4,("enum_all_printers_info_0\n"));
4444 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4445 servername, 0, flags, info, count);
4449 /********************************************************************
4450 ********************************************************************/
4452 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4453 const struct auth_session_info *session_info,
4454 struct messaging_context *msg_ctx,
4455 const char *servername,
4456 uint32_t flags,
4457 union spoolss_PrinterInfo **info,
4458 uint32_t *count)
4460 DEBUG(4,("enum_all_printers_info_1\n"));
4462 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4463 servername, 1, flags, info, count);
4466 /********************************************************************
4467 enum_all_printers_info_1_local.
4468 *********************************************************************/
4470 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4471 const struct auth_session_info *session_info,
4472 struct messaging_context *msg_ctx,
4473 const char *servername,
4474 union spoolss_PrinterInfo **info,
4475 uint32_t *count)
4477 DEBUG(4,("enum_all_printers_info_1_local\n"));
4479 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4480 servername, PRINTER_ENUM_ICON8, info, count);
4483 /********************************************************************
4484 enum_all_printers_info_1_name.
4485 *********************************************************************/
4487 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4488 const struct auth_session_info *session_info,
4489 struct messaging_context *msg_ctx,
4490 const char *servername,
4491 union spoolss_PrinterInfo **info,
4492 uint32_t *count)
4494 const char *s = servername;
4496 DEBUG(4,("enum_all_printers_info_1_name\n"));
4498 if (servername != NULL &&
4499 (servername[0] == '\\') && (servername[1] == '\\')) {
4500 s = servername + 2;
4503 if (!is_myname_or_ipaddr(s)) {
4504 return WERR_INVALID_NAME;
4507 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4508 servername, PRINTER_ENUM_ICON8, info, count);
4511 /********************************************************************
4512 enum_all_printers_info_1_network.
4513 *********************************************************************/
4515 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4516 const struct auth_session_info *session_info,
4517 struct messaging_context *msg_ctx,
4518 const char *servername,
4519 union spoolss_PrinterInfo **info,
4520 uint32_t *count)
4522 const char *s = servername;
4524 DEBUG(4,("enum_all_printers_info_1_network\n"));
4526 /* If we respond to a enum_printers level 1 on our name with flags
4527 set to PRINTER_ENUM_REMOTE with a list of printers then these
4528 printers incorrectly appear in the APW browse list.
4529 Specifically the printers for the server appear at the workgroup
4530 level where all the other servers in the domain are
4531 listed. Windows responds to this call with a
4532 WERR_CAN_NOT_COMPLETE so we should do the same. */
4534 if (servername != NULL &&
4535 (servername[0] == '\\') && (servername[1] == '\\')) {
4536 s = servername + 2;
4539 if (is_myname_or_ipaddr(s)) {
4540 return WERR_CAN_NOT_COMPLETE;
4543 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4544 servername, PRINTER_ENUM_NAME, info, count);
4547 /********************************************************************
4548 * api_spoolss_enumprinters
4550 * called from api_spoolss_enumprinters (see this to understand)
4551 ********************************************************************/
4553 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4554 const struct auth_session_info *session_info,
4555 struct messaging_context *msg_ctx,
4556 const char *servername,
4557 union spoolss_PrinterInfo **info,
4558 uint32_t *count)
4560 DEBUG(4,("enum_all_printers_info_2\n"));
4562 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4563 servername, 2, 0, info, count);
4566 /********************************************************************
4567 * handle enumeration of printers at level 1
4568 ********************************************************************/
4570 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4571 const struct auth_session_info *session_info,
4572 struct messaging_context *msg_ctx,
4573 uint32_t flags,
4574 const char *servername,
4575 union spoolss_PrinterInfo **info,
4576 uint32_t *count)
4578 /* Not all the flags are equals */
4580 if (flags & PRINTER_ENUM_LOCAL) {
4581 return enum_all_printers_info_1_local(mem_ctx, session_info,
4582 msg_ctx, servername, info, count);
4585 if (flags & PRINTER_ENUM_NAME) {
4586 return enum_all_printers_info_1_name(mem_ctx, session_info,
4587 msg_ctx, servername, info,
4588 count);
4591 if (flags & PRINTER_ENUM_NETWORK) {
4592 return enum_all_printers_info_1_network(mem_ctx, session_info,
4593 msg_ctx, servername, info,
4594 count);
4597 return WERR_OK; /* NT4sp5 does that */
4600 /********************************************************************
4601 * handle enumeration of printers at level 2
4602 ********************************************************************/
4604 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4605 const struct auth_session_info *session_info,
4606 struct messaging_context *msg_ctx,
4607 uint32_t flags,
4608 const char *servername,
4609 union spoolss_PrinterInfo **info,
4610 uint32_t *count)
4612 if (flags & PRINTER_ENUM_LOCAL) {
4614 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4615 servername,
4616 info, count);
4619 if (flags & PRINTER_ENUM_NAME) {
4620 if (servername && !is_myname_or_ipaddr(canon_servername(servername))) {
4621 return WERR_INVALID_NAME;
4624 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4625 servername,
4626 info, count);
4629 if (flags & PRINTER_ENUM_REMOTE) {
4630 return WERR_UNKNOWN_LEVEL;
4633 return WERR_OK;
4636 /********************************************************************
4637 * handle enumeration of printers at level 4
4638 ********************************************************************/
4640 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4641 const struct auth_session_info *session_info,
4642 struct messaging_context *msg_ctx,
4643 uint32_t flags,
4644 const char *servername,
4645 union spoolss_PrinterInfo **info,
4646 uint32_t *count)
4648 DEBUG(4,("enum_all_printers_info_4\n"));
4650 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4651 servername, 4, flags, info, count);
4655 /********************************************************************
4656 * handle enumeration of printers at level 5
4657 ********************************************************************/
4659 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4660 const struct auth_session_info *session_info,
4661 struct messaging_context *msg_ctx,
4662 uint32_t flags,
4663 const char *servername,
4664 union spoolss_PrinterInfo **info,
4665 uint32_t *count)
4667 DEBUG(4,("enum_all_printers_info_5\n"));
4669 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4670 servername, 5, flags, info, count);
4673 /****************************************************************
4674 _spoolss_EnumPrinters
4675 ****************************************************************/
4677 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4678 struct spoolss_EnumPrinters *r)
4680 const struct auth_session_info *session_info = get_session_info_system();
4681 WERROR result;
4683 /* that's an [in out] buffer */
4685 if (!r->in.buffer && (r->in.offered != 0)) {
4686 return WERR_INVALID_PARAM;
4689 DEBUG(4,("_spoolss_EnumPrinters\n"));
4691 *r->out.needed = 0;
4692 *r->out.count = 0;
4693 *r->out.info = NULL;
4696 * Level 1:
4697 * flags==PRINTER_ENUM_NAME
4698 * if name=="" then enumerates all printers
4699 * if name!="" then enumerate the printer
4700 * flags==PRINTER_ENUM_REMOTE
4701 * name is NULL, enumerate printers
4702 * Level 2: name!="" enumerates printers, name can't be NULL
4703 * Level 3: doesn't exist
4704 * Level 4: does a local registry lookup
4705 * Level 5: same as Level 2
4708 if (r->in.server && r->in.server[0] == '\0') {
4709 r->in.server = NULL;
4712 switch (r->in.level) {
4713 case 0:
4714 result = enumprinters_level0(p->mem_ctx, session_info,
4715 p->msg_ctx, r->in.flags,
4716 r->in.server,
4717 r->out.info, r->out.count);
4718 break;
4719 case 1:
4720 result = enumprinters_level1(p->mem_ctx, session_info,
4721 p->msg_ctx, r->in.flags,
4722 r->in.server,
4723 r->out.info, r->out.count);
4724 break;
4725 case 2:
4726 result = enumprinters_level2(p->mem_ctx, session_info,
4727 p->msg_ctx, r->in.flags,
4728 r->in.server,
4729 r->out.info, r->out.count);
4730 break;
4731 case 4:
4732 result = enumprinters_level4(p->mem_ctx, session_info,
4733 p->msg_ctx, r->in.flags,
4734 r->in.server,
4735 r->out.info, r->out.count);
4736 break;
4737 case 5:
4738 result = enumprinters_level5(p->mem_ctx, session_info,
4739 p->msg_ctx, r->in.flags,
4740 r->in.server,
4741 r->out.info, r->out.count);
4742 break;
4743 default:
4744 return WERR_UNKNOWN_LEVEL;
4747 if (!W_ERROR_IS_OK(result)) {
4748 return result;
4751 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4752 spoolss_EnumPrinters,
4753 *r->out.info, r->in.level,
4754 *r->out.count);
4755 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4756 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4758 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4761 /****************************************************************
4762 _spoolss_GetPrinter
4763 ****************************************************************/
4765 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4766 struct spoolss_GetPrinter *r)
4768 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
4769 struct spoolss_PrinterInfo2 *info2 = NULL;
4770 WERROR result = WERR_OK;
4771 int snum;
4773 /* that's an [in out] buffer */
4775 if (!r->in.buffer && (r->in.offered != 0)) {
4776 return WERR_INVALID_PARAM;
4779 *r->out.needed = 0;
4781 if (Printer == NULL) {
4782 return WERR_BADFID;
4785 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4786 return WERR_BADFID;
4789 result = winreg_get_printer_internal(p->mem_ctx,
4790 get_session_info_system(),
4791 p->msg_ctx,
4792 lp_const_servicename(snum),
4793 &info2);
4794 if (!W_ERROR_IS_OK(result)) {
4795 goto out;
4798 switch (r->in.level) {
4799 case 0:
4800 result = construct_printer_info0(p->mem_ctx,
4801 get_session_info_system(),
4802 p->msg_ctx,
4803 info2,
4804 Printer->servername,
4805 &r->out.info->info0,
4806 snum);
4807 break;
4808 case 1:
4809 result = construct_printer_info1(p->mem_ctx, info2,
4810 PRINTER_ENUM_ICON8,
4811 Printer->servername,
4812 &r->out.info->info1, snum);
4813 break;
4814 case 2:
4815 result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
4816 Printer->servername,
4817 &r->out.info->info2, snum);
4818 break;
4819 case 3:
4820 result = construct_printer_info3(p->mem_ctx, info2,
4821 Printer->servername,
4822 &r->out.info->info3, snum);
4823 break;
4824 case 4:
4825 result = construct_printer_info4(p->mem_ctx, info2,
4826 Printer->servername,
4827 &r->out.info->info4, snum);
4828 break;
4829 case 5:
4830 result = construct_printer_info5(p->mem_ctx, info2,
4831 Printer->servername,
4832 &r->out.info->info5, snum);
4833 break;
4834 case 6:
4835 result = construct_printer_info6(p->mem_ctx, p->msg_ctx, info2,
4836 Printer->servername,
4837 &r->out.info->info6, snum);
4838 break;
4839 case 7:
4840 result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
4841 Printer->servername,
4842 &r->out.info->info7, snum);
4843 break;
4844 case 8:
4845 result = construct_printer_info8(p->mem_ctx, info2,
4846 Printer->servername,
4847 &r->out.info->info8, snum);
4848 break;
4849 default:
4850 result = WERR_UNKNOWN_LEVEL;
4851 break;
4853 TALLOC_FREE(info2);
4855 out:
4856 if (!W_ERROR_IS_OK(result)) {
4857 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4858 r->in.level, win_errstr(result)));
4859 TALLOC_FREE(r->out.info);
4860 return result;
4863 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4864 r->out.info, r->in.level);
4865 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4867 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4870 /********************************************************************
4871 ********************************************************************/
4873 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4874 do { \
4875 if (in && strlen(in)) { \
4876 out = talloc_strdup(mem_ctx, in); \
4877 } else { \
4878 out = talloc_strdup(mem_ctx, ""); \
4880 W_ERROR_HAVE_NO_MEMORY(out); \
4881 } while (0);
4883 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4884 do { \
4885 if (in && strlen(in)) { \
4886 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4887 } else { \
4888 out = talloc_strdup(mem_ctx, ""); \
4890 W_ERROR_HAVE_NO_MEMORY(out); \
4891 } while (0);
4893 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4894 const char **string_array,
4895 const char ***presult,
4896 const char *cservername,
4897 const char *arch,
4898 int version)
4900 int i;
4901 size_t num_strings = 0;
4902 const char **array = NULL;
4904 if (string_array == NULL) {
4905 return WERR_INVALID_PARAMETER;
4908 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4909 const char *str = NULL;
4911 if (cservername == NULL || arch == NULL) {
4912 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4913 } else {
4914 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4917 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4918 TALLOC_FREE(array);
4919 return WERR_NOMEM;
4923 if (i > 0) {
4924 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4925 &array, &num_strings);
4928 if (presult != NULL) {
4929 *presult = array;
4930 } else {
4931 talloc_free(array);
4934 return WERR_OK;
4937 /********************************************************************
4938 * fill a spoolss_DriverInfo1 struct
4939 ********************************************************************/
4941 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4942 struct spoolss_DriverInfo1 *r,
4943 const struct spoolss_DriverInfo8 *driver,
4944 const char *servername)
4946 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4947 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4949 return WERR_OK;
4952 /********************************************************************
4953 * fill a spoolss_DriverInfo2 struct
4954 ********************************************************************/
4956 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4957 struct spoolss_DriverInfo2 *r,
4958 const struct spoolss_DriverInfo8 *driver,
4959 const char *servername)
4962 const char *cservername = canon_servername(servername);
4964 r->version = driver->version;
4966 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4967 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4968 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4969 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4971 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4972 driver->architecture,
4973 driver->version,
4974 driver->driver_path,
4975 r->driver_path);
4977 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4978 driver->architecture,
4979 driver->version,
4980 driver->data_file,
4981 r->data_file);
4983 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4984 driver->architecture,
4985 driver->version,
4986 driver->config_file,
4987 r->config_file);
4989 return WERR_OK;
4992 /********************************************************************
4993 * fill a spoolss_DriverInfo3 struct
4994 ********************************************************************/
4996 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4997 struct spoolss_DriverInfo3 *r,
4998 const struct spoolss_DriverInfo8 *driver,
4999 const char *servername)
5001 const char *cservername = canon_servername(servername);
5003 r->version = driver->version;
5005 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5006 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5007 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5008 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5010 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5011 driver->architecture,
5012 driver->version,
5013 driver->driver_path,
5014 r->driver_path);
5016 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5017 driver->architecture,
5018 driver->version,
5019 driver->data_file,
5020 r->data_file);
5022 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5023 driver->architecture,
5024 driver->version,
5025 driver->config_file,
5026 r->config_file);
5028 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5029 driver->architecture,
5030 driver->version,
5031 driver->help_file,
5032 r->help_file);
5034 FILL_DRIVER_STRING(mem_ctx,
5035 driver->monitor_name,
5036 r->monitor_name);
5038 FILL_DRIVER_STRING(mem_ctx,
5039 driver->default_datatype,
5040 r->default_datatype);
5042 return string_array_from_driver_info(mem_ctx,
5043 driver->dependent_files,
5044 &r->dependent_files,
5045 cservername,
5046 driver->architecture,
5047 driver->version);
5050 /********************************************************************
5051 * fill a spoolss_DriverInfo4 struct
5052 ********************************************************************/
5054 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
5055 struct spoolss_DriverInfo4 *r,
5056 const struct spoolss_DriverInfo8 *driver,
5057 const char *servername)
5059 const char *cservername = canon_servername(servername);
5060 WERROR result;
5062 r->version = driver->version;
5064 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5065 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5066 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5067 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5069 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5070 driver->architecture,
5071 driver->version,
5072 driver->driver_path,
5073 r->driver_path);
5075 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5076 driver->architecture,
5077 driver->version,
5078 driver->data_file,
5079 r->data_file);
5081 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5082 driver->architecture,
5083 driver->version,
5084 driver->config_file,
5085 r->config_file);
5087 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5088 driver->architecture,
5089 driver->version,
5090 driver->help_file,
5091 r->help_file);
5093 result = string_array_from_driver_info(mem_ctx,
5094 driver->dependent_files,
5095 &r->dependent_files,
5096 cservername,
5097 driver->architecture,
5098 driver->version);
5099 if (!W_ERROR_IS_OK(result)) {
5100 return result;
5103 FILL_DRIVER_STRING(mem_ctx,
5104 driver->monitor_name,
5105 r->monitor_name);
5107 FILL_DRIVER_STRING(mem_ctx,
5108 driver->default_datatype,
5109 r->default_datatype);
5112 result = string_array_from_driver_info(mem_ctx,
5113 driver->previous_names,
5114 &r->previous_names,
5115 NULL, NULL, 0);
5117 return result;
5120 /********************************************************************
5121 * fill a spoolss_DriverInfo5 struct
5122 ********************************************************************/
5124 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
5125 struct spoolss_DriverInfo5 *r,
5126 const struct spoolss_DriverInfo8 *driver,
5127 const char *servername)
5129 const char *cservername = canon_servername(servername);
5131 r->version = driver->version;
5133 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5134 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5135 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5136 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5138 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5139 driver->architecture,
5140 driver->version,
5141 driver->driver_path,
5142 r->driver_path);
5144 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5145 driver->architecture,
5146 driver->version,
5147 driver->data_file,
5148 r->data_file);
5150 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5151 driver->architecture,
5152 driver->version,
5153 driver->config_file,
5154 r->config_file);
5156 r->driver_attributes = 0;
5157 r->config_version = 0;
5158 r->driver_version = 0;
5160 return WERR_OK;
5162 /********************************************************************
5163 * fill a spoolss_DriverInfo6 struct
5164 ********************************************************************/
5166 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
5167 struct spoolss_DriverInfo6 *r,
5168 const struct spoolss_DriverInfo8 *driver,
5169 const char *servername)
5171 const char *cservername = canon_servername(servername);
5172 WERROR result;
5174 r->version = driver->version;
5176 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5177 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5178 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5179 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5181 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5182 driver->architecture,
5183 driver->version,
5184 driver->driver_path,
5185 r->driver_path);
5187 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5188 driver->architecture,
5189 driver->version,
5190 driver->data_file,
5191 r->data_file);
5193 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5194 driver->architecture,
5195 driver->version,
5196 driver->config_file,
5197 r->config_file);
5199 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5200 driver->architecture,
5201 driver->version,
5202 driver->help_file,
5203 r->help_file);
5205 FILL_DRIVER_STRING(mem_ctx,
5206 driver->monitor_name,
5207 r->monitor_name);
5209 FILL_DRIVER_STRING(mem_ctx,
5210 driver->default_datatype,
5211 r->default_datatype);
5213 result = string_array_from_driver_info(mem_ctx,
5214 driver->dependent_files,
5215 &r->dependent_files,
5216 cservername,
5217 driver->architecture,
5218 driver->version);
5219 if (!W_ERROR_IS_OK(result)) {
5220 return result;
5223 result = string_array_from_driver_info(mem_ctx,
5224 driver->previous_names,
5225 &r->previous_names,
5226 NULL, NULL, 0);
5227 if (!W_ERROR_IS_OK(result)) {
5228 return result;
5231 r->driver_date = driver->driver_date;
5232 r->driver_version = driver->driver_version;
5234 FILL_DRIVER_STRING(mem_ctx,
5235 driver->manufacturer_name,
5236 r->manufacturer_name);
5237 FILL_DRIVER_STRING(mem_ctx,
5238 driver->manufacturer_url,
5239 r->manufacturer_url);
5240 FILL_DRIVER_STRING(mem_ctx,
5241 driver->hardware_id,
5242 r->hardware_id);
5243 FILL_DRIVER_STRING(mem_ctx,
5244 driver->provider,
5245 r->provider);
5247 return WERR_OK;
5250 /********************************************************************
5251 * fill a spoolss_DriverInfo8 struct
5252 ********************************************************************/
5254 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
5255 struct spoolss_DriverInfo8 *r,
5256 const struct spoolss_DriverInfo8 *driver,
5257 const char *servername)
5259 const char *cservername = canon_servername(servername);
5260 WERROR result;
5262 r->version = driver->version;
5264 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5265 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5266 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5267 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5269 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5270 driver->architecture,
5271 driver->version,
5272 driver->driver_path,
5273 r->driver_path);
5275 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5276 driver->architecture,
5277 driver->version,
5278 driver->data_file,
5279 r->data_file);
5281 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5282 driver->architecture,
5283 driver->version,
5284 driver->config_file,
5285 r->config_file);
5287 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5288 driver->architecture,
5289 driver->version,
5290 driver->help_file,
5291 r->help_file);
5293 FILL_DRIVER_STRING(mem_ctx,
5294 driver->monitor_name,
5295 r->monitor_name);
5297 FILL_DRIVER_STRING(mem_ctx,
5298 driver->default_datatype,
5299 r->default_datatype);
5301 result = string_array_from_driver_info(mem_ctx,
5302 driver->dependent_files,
5303 &r->dependent_files,
5304 cservername,
5305 driver->architecture,
5306 driver->version);
5307 if (!W_ERROR_IS_OK(result)) {
5308 return result;
5311 result = string_array_from_driver_info(mem_ctx,
5312 driver->previous_names,
5313 &r->previous_names,
5314 NULL, NULL, 0);
5315 if (!W_ERROR_IS_OK(result)) {
5316 return result;
5319 r->driver_date = driver->driver_date;
5320 r->driver_version = driver->driver_version;
5322 FILL_DRIVER_STRING(mem_ctx,
5323 driver->manufacturer_name,
5324 r->manufacturer_name);
5325 FILL_DRIVER_STRING(mem_ctx,
5326 driver->manufacturer_url,
5327 r->manufacturer_url);
5328 FILL_DRIVER_STRING(mem_ctx,
5329 driver->hardware_id,
5330 r->hardware_id);
5331 FILL_DRIVER_STRING(mem_ctx,
5332 driver->provider,
5333 r->provider);
5335 FILL_DRIVER_STRING(mem_ctx,
5336 driver->print_processor,
5337 r->print_processor);
5338 FILL_DRIVER_STRING(mem_ctx,
5339 driver->vendor_setup,
5340 r->vendor_setup);
5342 result = string_array_from_driver_info(mem_ctx,
5343 driver->color_profiles,
5344 &r->color_profiles,
5345 NULL, NULL, 0);
5346 if (!W_ERROR_IS_OK(result)) {
5347 return result;
5350 FILL_DRIVER_STRING(mem_ctx,
5351 driver->inf_path,
5352 r->inf_path);
5354 r->printer_driver_attributes = driver->printer_driver_attributes;
5356 result = string_array_from_driver_info(mem_ctx,
5357 driver->core_driver_dependencies,
5358 &r->core_driver_dependencies,
5359 NULL, NULL, 0);
5360 if (!W_ERROR_IS_OK(result)) {
5361 return result;
5364 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
5365 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
5367 return WERR_OK;
5370 #if 0 /* disabled until marshalling issues are resolved - gd */
5371 /********************************************************************
5372 ********************************************************************/
5374 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5375 struct spoolss_DriverFileInfo *r,
5376 const char *cservername,
5377 const char *file_name,
5378 enum spoolss_DriverFileType file_type,
5379 uint32_t file_version)
5381 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5382 cservername, file_name);
5383 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5384 r->file_type = file_type;
5385 r->file_version = file_version;
5387 return WERR_OK;
5390 /********************************************************************
5391 ********************************************************************/
5393 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5394 const struct spoolss_DriverInfo8 *driver,
5395 const char *cservername,
5396 struct spoolss_DriverFileInfo **info_p,
5397 uint32_t *count_p)
5399 struct spoolss_DriverFileInfo *info = NULL;
5400 uint32_t count = 0;
5401 WERROR result;
5402 uint32_t i;
5404 *info_p = NULL;
5405 *count_p = 0;
5407 if (strlen(driver->driver_path)) {
5408 info = talloc_realloc(mem_ctx, info,
5409 struct spoolss_DriverFileInfo,
5410 count + 1);
5411 W_ERROR_HAVE_NO_MEMORY(info);
5412 result = fill_spoolss_DriverFileInfo(info,
5413 &info[count],
5414 cservername,
5415 driver->driver_path,
5416 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5418 W_ERROR_NOT_OK_RETURN(result);
5419 count++;
5422 if (strlen(driver->config_file)) {
5423 info = talloc_realloc(mem_ctx, info,
5424 struct spoolss_DriverFileInfo,
5425 count + 1);
5426 W_ERROR_HAVE_NO_MEMORY(info);
5427 result = fill_spoolss_DriverFileInfo(info,
5428 &info[count],
5429 cservername,
5430 driver->config_file,
5431 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5433 W_ERROR_NOT_OK_RETURN(result);
5434 count++;
5437 if (strlen(driver->data_file)) {
5438 info = talloc_realloc(mem_ctx, info,
5439 struct spoolss_DriverFileInfo,
5440 count + 1);
5441 W_ERROR_HAVE_NO_MEMORY(info);
5442 result = fill_spoolss_DriverFileInfo(info,
5443 &info[count],
5444 cservername,
5445 driver->data_file,
5446 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5448 W_ERROR_NOT_OK_RETURN(result);
5449 count++;
5452 if (strlen(driver->help_file)) {
5453 info = talloc_realloc(mem_ctx, info,
5454 struct spoolss_DriverFileInfo,
5455 count + 1);
5456 W_ERROR_HAVE_NO_MEMORY(info);
5457 result = fill_spoolss_DriverFileInfo(info,
5458 &info[count],
5459 cservername,
5460 driver->help_file,
5461 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5463 W_ERROR_NOT_OK_RETURN(result);
5464 count++;
5467 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
5468 info = talloc_realloc(mem_ctx, info,
5469 struct spoolss_DriverFileInfo,
5470 count + 1);
5471 W_ERROR_HAVE_NO_MEMORY(info);
5472 result = fill_spoolss_DriverFileInfo(info,
5473 &info[count],
5474 cservername,
5475 driver->dependent_files[i],
5476 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5478 W_ERROR_NOT_OK_RETURN(result);
5479 count++;
5482 *info_p = info;
5483 *count_p = count;
5485 return WERR_OK;
5488 /********************************************************************
5489 * fill a spoolss_DriverInfo101 struct
5490 ********************************************************************/
5492 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5493 struct spoolss_DriverInfo101 *r,
5494 const struct spoolss_DriverInfo8 *driver,
5495 const char *servername)
5497 const char *cservername = canon_servername(servername);
5498 WERROR result;
5500 r->version = driver->version;
5502 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5503 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5504 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5505 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5507 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5508 cservername,
5509 &r->file_info,
5510 &r->file_count);
5511 if (!W_ERROR_IS_OK(result)) {
5512 return result;
5515 FILL_DRIVER_STRING(mem_ctx,
5516 driver->monitor_name,
5517 r->monitor_name);
5519 FILL_DRIVER_STRING(mem_ctx,
5520 driver->default_datatype,
5521 r->default_datatype);
5523 result = string_array_from_driver_info(mem_ctx,
5524 driver->previous_names,
5525 &r->previous_names,
5526 NULL, NULL, 0);
5527 if (!W_ERROR_IS_OK(result)) {
5528 return result;
5531 r->driver_date = driver->driver_date;
5532 r->driver_version = driver->driver_version;
5534 FILL_DRIVER_STRING(mem_ctx,
5535 driver->manufacturer_name,
5536 r->manufacturer_name);
5537 FILL_DRIVER_STRING(mem_ctx,
5538 driver->manufacturer_url,
5539 r->manufacturer_url);
5540 FILL_DRIVER_STRING(mem_ctx,
5541 driver->hardware_id,
5542 r->hardware_id);
5543 FILL_DRIVER_STRING(mem_ctx,
5544 driver->provider,
5545 r->provider);
5547 return WERR_OK;
5549 #endif
5550 /********************************************************************
5551 ********************************************************************/
5553 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5554 const struct auth_session_info *session_info,
5555 struct messaging_context *msg_ctx,
5556 uint32_t level,
5557 union spoolss_DriverInfo *r,
5558 int snum,
5559 const char *servername,
5560 const char *architecture,
5561 uint32_t version)
5563 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5564 struct spoolss_DriverInfo8 *driver;
5565 WERROR result;
5566 struct dcerpc_binding_handle *b;
5567 TALLOC_CTX *tmp_ctx = NULL;
5569 if (level == 101) {
5570 return WERR_UNKNOWN_LEVEL;
5573 tmp_ctx = talloc_new(mem_ctx);
5574 if (!tmp_ctx) {
5575 return WERR_NOMEM;
5578 result = winreg_printer_binding_handle(tmp_ctx,
5579 session_info,
5580 msg_ctx,
5581 &b);
5582 if (!W_ERROR_IS_OK(result)) {
5583 goto done;
5586 result = winreg_get_printer(tmp_ctx, b,
5587 lp_const_servicename(snum),
5588 &pinfo2);
5590 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5591 win_errstr(result)));
5593 if (!W_ERROR_IS_OK(result)) {
5594 result = WERR_INVALID_PRINTER_NAME;
5595 goto done;
5598 result = winreg_get_driver(tmp_ctx, b,
5599 architecture,
5600 pinfo2->drivername, version, &driver);
5602 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5603 win_errstr(result)));
5605 if (!W_ERROR_IS_OK(result)) {
5607 * Is this a W2k client ?
5610 if (version < 3) {
5611 result = WERR_UNKNOWN_PRINTER_DRIVER;
5612 goto done;
5615 /* Yes - try again with a WinNT driver. */
5616 version = 2;
5617 result = winreg_get_driver(tmp_ctx, b,
5618 architecture,
5619 pinfo2->drivername,
5620 version, &driver);
5621 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5622 win_errstr(result)));
5623 if (!W_ERROR_IS_OK(result)) {
5624 result = WERR_UNKNOWN_PRINTER_DRIVER;
5625 goto done;
5629 /* these are allocated on mem_ctx and not tmp_ctx because they are
5630 * the 'return value' and need to utlive this call */
5631 switch (level) {
5632 case 1:
5633 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5634 break;
5635 case 2:
5636 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5637 break;
5638 case 3:
5639 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5640 break;
5641 case 4:
5642 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5643 break;
5644 case 5:
5645 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5646 break;
5647 case 6:
5648 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5649 break;
5650 case 8:
5651 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5652 break;
5653 #if 0 /* disabled until marshalling issues are resolved - gd */
5654 case 101:
5655 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5656 break;
5657 #endif
5658 default:
5659 result = WERR_UNKNOWN_LEVEL;
5660 break;
5663 done:
5664 talloc_free(tmp_ctx);
5665 return result;
5668 /****************************************************************
5669 _spoolss_GetPrinterDriver2
5670 ****************************************************************/
5672 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5673 struct spoolss_GetPrinterDriver2 *r)
5675 struct printer_handle *printer;
5676 WERROR result;
5677 uint32_t version = r->in.client_major_version;
5679 int snum;
5681 /* that's an [in out] buffer */
5683 if (!r->in.buffer && (r->in.offered != 0)) {
5684 return WERR_INVALID_PARAM;
5687 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5689 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5690 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5691 return WERR_INVALID_PRINTER_NAME;
5694 *r->out.needed = 0;
5695 *r->out.server_major_version = 0;
5696 *r->out.server_minor_version = 0;
5698 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5699 return WERR_BADFID;
5702 if (r->in.client_major_version == SPOOLSS_DRIVER_VERSION_2012) {
5703 DEBUG(3,("_spoolss_GetPrinterDriver2: v4 driver requested, "
5704 "downgrading to v3\n"));
5705 version = SPOOLSS_DRIVER_VERSION_200X;
5708 result = construct_printer_driver_info_level(p->mem_ctx,
5709 get_session_info_system(),
5710 p->msg_ctx,
5711 r->in.level, r->out.info,
5712 snum, printer->servername,
5713 r->in.architecture,
5714 version);
5715 if (!W_ERROR_IS_OK(result)) {
5716 TALLOC_FREE(r->out.info);
5717 return result;
5720 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5721 r->out.info, r->in.level);
5722 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5724 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5728 /****************************************************************
5729 _spoolss_StartPagePrinter
5730 ****************************************************************/
5732 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5733 struct spoolss_StartPagePrinter *r)
5735 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5737 if (!Printer) {
5738 DEBUG(3,("_spoolss_StartPagePrinter: "
5739 "Error in startpageprinter printer handle\n"));
5740 return WERR_BADFID;
5743 Printer->page_started = true;
5744 return WERR_OK;
5747 /****************************************************************
5748 _spoolss_EndPagePrinter
5749 ****************************************************************/
5751 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5752 struct spoolss_EndPagePrinter *r)
5754 int snum;
5756 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5758 if (!Printer) {
5759 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5760 OUR_HANDLE(r->in.handle)));
5761 return WERR_BADFID;
5764 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5765 return WERR_BADFID;
5767 Printer->page_started = false;
5768 print_job_endpage(p->msg_ctx, snum, Printer->jobid);
5770 return WERR_OK;
5773 /****************************************************************
5774 _spoolss_StartDocPrinter
5775 ****************************************************************/
5777 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5778 struct spoolss_StartDocPrinter *r)
5780 struct spoolss_DocumentInfo1 *info_1;
5781 int snum;
5782 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5783 WERROR werr;
5784 char *rhost;
5785 int rc;
5787 if (!Printer) {
5788 DEBUG(2,("_spoolss_StartDocPrinter: "
5789 "Invalid handle (%s:%u:%u)\n",
5790 OUR_HANDLE(r->in.handle)));
5791 return WERR_BADFID;
5794 if (Printer->jobid) {
5795 DEBUG(2, ("_spoolss_StartDocPrinter: "
5796 "StartDocPrinter called twice! "
5797 "(existing jobid = %d)\n", Printer->jobid));
5798 return WERR_INVALID_HANDLE;
5801 if (r->in.info_ctr->level != 1) {
5802 return WERR_UNKNOWN_LEVEL;
5805 info_1 = r->in.info_ctr->info.info1;
5808 * a nice thing with NT is it doesn't listen to what you tell it.
5809 * when asked to send _only_ RAW datas, it tries to send datas
5810 * in EMF format.
5812 * So I add checks like in NT Server ...
5815 if (info_1->datatype) {
5817 * The v4 driver model used in Windows 8 declares print jobs
5818 * intended to bypass the XPS processing layer by setting
5819 * datatype to "XPS_PASS" instead of "RAW".
5821 if ((strcmp(info_1->datatype, "RAW") != 0)
5822 && (strcmp(info_1->datatype, "XPS_PASS") != 0)) {
5823 *r->out.job_id = 0;
5824 return WERR_INVALID_DATATYPE;
5828 /* get the share number of the printer */
5829 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5830 return WERR_BADFID;
5833 rc = get_remote_hostname(p->remote_address,
5834 &rhost,
5835 p->mem_ctx);
5836 if (rc < 0) {
5837 return WERR_NOMEM;
5839 if (strequal(rhost,"UNKNOWN")) {
5840 rhost = tsocket_address_inet_addr_string(p->remote_address,
5841 p->mem_ctx);
5842 if (rhost == NULL) {
5843 return WERR_NOMEM;
5847 werr = print_job_start(p->session_info,
5848 p->msg_ctx,
5849 rhost,
5850 snum,
5851 info_1->document_name,
5852 info_1->output_file,
5853 Printer->devmode,
5854 &Printer->jobid);
5856 /* An error occured in print_job_start() so return an appropriate
5857 NT error code. */
5859 if (!W_ERROR_IS_OK(werr)) {
5860 return werr;
5863 Printer->document_started = true;
5864 *r->out.job_id = Printer->jobid;
5866 return WERR_OK;
5869 /****************************************************************
5870 _spoolss_EndDocPrinter
5871 ****************************************************************/
5873 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5874 struct spoolss_EndDocPrinter *r)
5876 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5877 NTSTATUS status;
5878 int snum;
5880 if (!Printer) {
5881 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5882 OUR_HANDLE(r->in.handle)));
5883 return WERR_BADFID;
5886 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5887 return WERR_BADFID;
5890 Printer->document_started = false;
5891 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5892 if (!NT_STATUS_IS_OK(status)) {
5893 DEBUG(2, ("_spoolss_EndDocPrinter: "
5894 "print_job_end failed [%s]\n",
5895 nt_errstr(status)));
5898 Printer->jobid = 0;
5899 return ntstatus_to_werror(status);
5902 /****************************************************************
5903 _spoolss_WritePrinter
5904 ****************************************************************/
5906 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5907 struct spoolss_WritePrinter *r)
5909 ssize_t buffer_written;
5910 int snum;
5911 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5913 if (!Printer) {
5914 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5915 OUR_HANDLE(r->in.handle)));
5916 *r->out.num_written = r->in._data_size;
5917 return WERR_BADFID;
5920 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5921 return WERR_BADFID;
5923 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5924 buffer_written = print_job_write(server_event_context(),p->msg_ctx,
5925 snum, Printer->jobid,
5926 (const char *)r->in.data.data,
5927 (size_t)r->in._data_size);
5928 if (buffer_written == (ssize_t)-1) {
5929 *r->out.num_written = 0;
5930 if (errno == ENOSPC)
5931 return WERR_NO_SPOOL_SPACE;
5932 else
5933 return WERR_ACCESS_DENIED;
5936 *r->out.num_written = r->in._data_size;
5938 return WERR_OK;
5941 /********************************************************************
5942 * api_spoolss_getprinter
5943 * called from the spoolss dispatcher
5945 ********************************************************************/
5947 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5948 struct pipes_struct *p)
5950 const struct auth_session_info *session_info = p->session_info;
5951 int snum;
5952 WERROR errcode = WERR_BADFUNC;
5953 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5955 if (!Printer) {
5956 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5957 OUR_HANDLE(handle)));
5958 return WERR_BADFID;
5961 if (!get_printer_snum(p, handle, &snum, NULL))
5962 return WERR_BADFID;
5964 switch (command) {
5965 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5966 errcode = print_queue_pause(session_info, p->msg_ctx, snum);
5967 break;
5968 case SPOOLSS_PRINTER_CONTROL_RESUME:
5969 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5970 errcode = print_queue_resume(session_info, p->msg_ctx, snum);
5971 break;
5972 case SPOOLSS_PRINTER_CONTROL_PURGE:
5973 errcode = print_queue_purge(session_info, p->msg_ctx, snum);
5974 break;
5975 default:
5976 return WERR_UNKNOWN_LEVEL;
5979 return errcode;
5983 /****************************************************************
5984 _spoolss_AbortPrinter
5985 * From MSDN: "Deletes printer's spool file if printer is configured
5986 * for spooling"
5987 ****************************************************************/
5989 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5990 struct spoolss_AbortPrinter *r)
5992 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5993 int snum;
5994 WERROR errcode = WERR_OK;
5996 if (!Printer) {
5997 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5998 OUR_HANDLE(r->in.handle)));
5999 return WERR_BADFID;
6002 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
6003 return WERR_BADFID;
6005 if (!Printer->document_started) {
6006 return WERR_SPL_NO_STARTDOC;
6009 errcode = print_job_delete(p->session_info,
6010 p->msg_ctx,
6011 snum,
6012 Printer->jobid);
6014 return errcode;
6017 /********************************************************************
6018 * called by spoolss_api_setprinter
6019 * when updating a printer description
6020 ********************************************************************/
6022 static WERROR update_printer_sec(struct policy_handle *handle,
6023 struct pipes_struct *p,
6024 struct sec_desc_buf *secdesc_ctr)
6026 struct spoolss_security_descriptor *new_secdesc = NULL;
6027 struct spoolss_security_descriptor *old_secdesc = NULL;
6028 const char *printer;
6029 WERROR result;
6030 int snum;
6031 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6032 struct dcerpc_binding_handle *b;
6033 TALLOC_CTX *tmp_ctx = NULL;
6035 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
6036 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
6037 OUR_HANDLE(handle)));
6039 result = WERR_BADFID;
6040 goto done;
6043 if (secdesc_ctr == NULL) {
6044 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
6045 result = WERR_INVALID_PARAM;
6046 goto done;
6048 printer = lp_const_servicename(snum);
6050 /* Check the user has permissions to change the security
6051 descriptor. By experimentation with two NT machines, the user
6052 requires Full Access to the printer to change security
6053 information. */
6055 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
6056 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
6057 result = WERR_ACCESS_DENIED;
6058 goto done;
6061 tmp_ctx = talloc_new(p->mem_ctx);
6062 if (!tmp_ctx) {
6063 return WERR_NOMEM;
6066 result = winreg_printer_binding_handle(tmp_ctx,
6067 get_session_info_system(),
6068 p->msg_ctx,
6069 &b);
6070 if (!W_ERROR_IS_OK(result)) {
6071 goto done;
6074 /* NT seems to like setting the security descriptor even though
6075 nothing may have actually changed. */
6076 result = winreg_get_printer_secdesc(tmp_ctx, b,
6077 printer,
6078 &old_secdesc);
6079 if (!W_ERROR_IS_OK(result)) {
6080 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc_internal() failed\n"));
6081 result = WERR_BADFID;
6082 goto done;
6085 if (DEBUGLEVEL >= 10) {
6086 struct security_acl *the_acl;
6087 int i;
6089 the_acl = old_secdesc->dacl;
6090 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
6091 printer, the_acl->num_aces));
6093 for (i = 0; i < the_acl->num_aces; i++) {
6094 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6095 &the_acl->aces[i].trustee),
6096 the_acl->aces[i].access_mask));
6099 the_acl = secdesc_ctr->sd->dacl;
6101 if (the_acl) {
6102 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
6103 printer, the_acl->num_aces));
6105 for (i = 0; i < the_acl->num_aces; i++) {
6106 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6107 &the_acl->aces[i].trustee),
6108 the_acl->aces[i].access_mask));
6110 } else {
6111 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
6115 new_secdesc = sec_desc_merge(tmp_ctx, secdesc_ctr->sd, old_secdesc);
6116 if (new_secdesc == NULL) {
6117 result = WERR_NOMEM;
6118 goto done;
6121 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
6122 result = WERR_OK;
6123 goto done;
6126 result = winreg_set_printer_secdesc(tmp_ctx, b,
6127 printer,
6128 new_secdesc);
6130 done:
6131 talloc_free(tmp_ctx);
6132 return result;
6135 /********************************************************************
6136 Canonicalize printer info from a client
6137 ********************************************************************/
6139 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
6140 struct spoolss_SetPrinterInfo2 *info2,
6141 int snum)
6143 fstring printername;
6144 const char *p;
6146 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
6147 "portname=%s drivername=%s comment=%s location=%s\n",
6148 info2->servername, info2->printername, info2->sharename,
6149 info2->portname, info2->drivername, info2->comment,
6150 info2->location));
6152 /* we force some elements to "correct" values */
6153 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", lp_netbios_name());
6154 if (info2->servername == NULL) {
6155 return false;
6157 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
6158 if (info2->sharename == NULL) {
6159 return false;
6162 /* check to see if we allow printername != sharename */
6163 if (lp_force_printername(snum)) {
6164 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6165 lp_netbios_name(), info2->sharename);
6166 } else {
6167 /* make sure printername is in \\server\printername format */
6168 fstrcpy(printername, info2->printername);
6169 p = printername;
6170 if ( printername[0] == '\\' && printername[1] == '\\' ) {
6171 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
6172 p++;
6175 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6176 lp_netbios_name(), p);
6178 if (info2->printername == NULL) {
6179 return false;
6182 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
6183 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
6185 return true;
6188 /****************************************************************************
6189 ****************************************************************************/
6191 static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const char *portname, const char *uri)
6193 char *cmd = lp_addport_cmd(talloc_tos());
6194 char *command = NULL;
6195 int ret;
6196 bool is_print_op = false;
6198 if ( !*cmd ) {
6199 return WERR_ACCESS_DENIED;
6202 command = talloc_asprintf(ctx,
6203 "%s \"%s\" \"%s\"", cmd, portname, uri );
6204 if (!command) {
6205 return WERR_NOMEM;
6208 if ( token )
6209 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6211 DEBUG(10,("Running [%s]\n", command));
6213 /********* BEGIN SePrintOperatorPrivilege **********/
6215 if ( is_print_op )
6216 become_root();
6218 ret = smbrun(command, NULL);
6220 if ( is_print_op )
6221 unbecome_root();
6223 /********* END SePrintOperatorPrivilege **********/
6225 DEBUGADD(10,("returned [%d]\n", ret));
6227 TALLOC_FREE(command);
6229 if ( ret != 0 ) {
6230 return WERR_ACCESS_DENIED;
6233 return WERR_OK;
6236 /****************************************************************************
6237 ****************************************************************************/
6239 static bool spoolss_conn_snum_used(struct smbd_server_connection *sconn,
6240 int snum)
6243 * As we do not know if we are embedded in the file server process
6244 * or not, we have to pretend that all shares are in use.
6246 return true;
6249 static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
6250 struct spoolss_SetPrinterInfo2 *info2,
6251 const char *remote_machine,
6252 struct messaging_context *msg_ctx)
6254 char *cmd = lp_addprinter_cmd(talloc_tos());
6255 char **qlines;
6256 char *command = NULL;
6257 int numlines;
6258 int ret;
6259 int fd;
6260 bool is_print_op = false;
6262 if (!remote_machine) {
6263 return false;
6266 command = talloc_asprintf(ctx,
6267 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6268 cmd, info2->printername, info2->sharename,
6269 info2->portname, info2->drivername,
6270 info2->location, info2->comment, remote_machine);
6271 if (!command) {
6272 return false;
6275 if ( token )
6276 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6278 DEBUG(10,("Running [%s]\n", command));
6280 /********* BEGIN SePrintOperatorPrivilege **********/
6282 if ( is_print_op )
6283 become_root();
6285 if ( (ret = smbrun(command, &fd)) == 0 ) {
6286 /* Tell everyone we updated smb.conf. */
6287 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6290 if ( is_print_op )
6291 unbecome_root();
6293 /********* END SePrintOperatorPrivilege **********/
6295 DEBUGADD(10,("returned [%d]\n", ret));
6297 TALLOC_FREE(command);
6299 if ( ret != 0 ) {
6300 if (fd != -1)
6301 close(fd);
6302 return false;
6305 /* reload our services immediately */
6306 become_root();
6307 reload_services(NULL, spoolss_conn_snum_used, false);
6308 unbecome_root();
6310 numlines = 0;
6311 /* Get lines and convert them back to dos-codepage */
6312 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6313 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6314 close(fd);
6316 /* Set the portname to what the script says the portname should be. */
6317 /* but don't require anything to be return from the script exit a good error code */
6319 if (numlines) {
6320 /* Set the portname to what the script says the portname should be. */
6321 info2->portname = talloc_strdup(ctx, qlines[0]);
6322 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6325 TALLOC_FREE(qlines);
6326 return true;
6329 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
6330 const struct auth_session_info *session_info,
6331 struct messaging_context *msg_ctx,
6332 int snum,
6333 struct spoolss_SetPrinterInfo2 *printer,
6334 struct spoolss_PrinterInfo2 *old_printer)
6336 bool force_update = (old_printer == NULL);
6337 const char *dnsdomname;
6338 const char *longname;
6339 const char *uncname;
6340 const char *spooling;
6341 DATA_BLOB buffer;
6342 WERROR result = WERR_OK;
6343 struct dcerpc_binding_handle *b;
6344 TALLOC_CTX *tmp_ctx;
6345 bool ok;
6347 tmp_ctx = talloc_new(mem_ctx);
6348 if (!tmp_ctx) {
6349 return WERR_NOMEM;
6352 result = winreg_printer_binding_handle(tmp_ctx,
6353 session_info,
6354 msg_ctx,
6355 &b);
6356 if (!W_ERROR_IS_OK(result)) {
6357 goto done;
6360 if (printer->drivername != NULL &&
6361 (force_update ||
6362 !strequal(printer->drivername, old_printer->drivername))) {
6363 ok = push_reg_sz(tmp_ctx, &buffer, printer->drivername);
6364 if (!ok) {
6365 DEBUG(0, ("%s data corrupted\n", SPOOL_REG_DRIVERNAME));
6366 result = WERR_INVALID_DATA;
6367 goto done;
6369 result = winreg_set_printer_dataex(tmp_ctx, b,
6370 printer->sharename,
6371 SPOOL_DSSPOOLER_KEY,
6372 SPOOL_REG_DRIVERNAME,
6373 REG_SZ,
6374 buffer.data,
6375 buffer.length);
6376 if (!W_ERROR_IS_OK(result)) {
6377 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DRIVERNAME));
6378 goto done;
6381 if (!force_update) {
6382 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6383 printer->drivername));
6385 notify_printer_driver(server_event_context(), msg_ctx,
6386 snum, printer->drivername ?
6387 printer->drivername : "");
6391 if (printer->comment != NULL &&
6392 (force_update ||
6393 !strequal(printer->comment, old_printer->comment))) {
6394 ok = push_reg_sz(tmp_ctx, &buffer, printer->comment);
6395 if (!ok) {
6396 DEBUG(0, ("comment data corrupted\n"));
6397 result = WERR_INVALID_DATA;
6398 goto done;
6400 result = winreg_set_printer_dataex(tmp_ctx, b,
6401 printer->sharename,
6402 SPOOL_DSSPOOLER_KEY,
6403 SPOOL_REG_DESCRIPTION,
6404 REG_SZ,
6405 buffer.data,
6406 buffer.length);
6407 if (!W_ERROR_IS_OK(result)) {
6408 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DESCRIPTION));
6409 goto done;
6412 if (!force_update) {
6413 notify_printer_comment(server_event_context(), msg_ctx,
6414 snum, printer->comment ?
6415 printer->comment : "");
6419 if (printer->sharename != NULL &&
6420 (force_update ||
6421 !strequal(printer->sharename, old_printer->sharename))) {
6422 ok = push_reg_sz(tmp_ctx, &buffer, printer->sharename);
6423 if (!ok) {
6424 DEBUG(0, ("sharename 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_PRINTSHARENAME,
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_sharename(server_event_context(),
6442 msg_ctx,
6443 snum, printer->sharename ?
6444 printer->sharename : "");
6448 if (printer->printername != NULL &&
6449 (force_update ||
6450 !strequal(printer->printername, old_printer->printername))) {
6451 const char *p;
6453 p = strrchr(printer->printername, '\\' );
6454 if (p != NULL) {
6455 p++;
6456 } else {
6457 p = printer->printername;
6460 ok = push_reg_sz(tmp_ctx, &buffer, p);
6461 if (!ok) {
6462 DEBUG(0, ("printername data corrupted\n"));
6463 result = WERR_INVALID_DATA;
6464 goto done;
6466 result = winreg_set_printer_dataex(tmp_ctx, b,
6467 printer->sharename,
6468 SPOOL_DSSPOOLER_KEY,
6469 SPOOL_REG_PRINTERNAME,
6470 REG_SZ,
6471 buffer.data,
6472 buffer.length);
6473 if (!W_ERROR_IS_OK(result)) {
6474 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME));
6475 goto done;
6478 if (!force_update) {
6479 notify_printer_printername(server_event_context(),
6480 msg_ctx, snum, p ? p : "");
6484 if (printer->portname != NULL &&
6485 (force_update ||
6486 !strequal(printer->portname, old_printer->portname))) {
6487 ok = push_reg_sz(tmp_ctx, &buffer, printer->portname);
6488 if (!ok) {
6489 DEBUG(0, ("portname data corrupted\n"));
6490 result = WERR_INVALID_DATA;
6491 goto done;
6493 result = winreg_set_printer_dataex(tmp_ctx, b,
6494 printer->sharename,
6495 SPOOL_DSSPOOLER_KEY,
6496 SPOOL_REG_PORTNAME,
6497 REG_SZ,
6498 buffer.data,
6499 buffer.length);
6500 if (!W_ERROR_IS_OK(result)) {
6501 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PORTNAME));
6502 goto done;
6505 if (!force_update) {
6506 notify_printer_port(server_event_context(),
6507 msg_ctx, snum, printer->portname ?
6508 printer->portname : "");
6512 if (printer->location != NULL &&
6513 (force_update ||
6514 !strequal(printer->location, old_printer->location))) {
6515 ok = push_reg_sz(tmp_ctx, &buffer, printer->location);
6516 if (!ok) {
6517 DEBUG(0, ("location data corrupted\n"));
6518 result = WERR_INVALID_DATA;
6519 goto done;
6521 result = winreg_set_printer_dataex(tmp_ctx, b,
6522 printer->sharename,
6523 SPOOL_DSSPOOLER_KEY,
6524 SPOOL_REG_LOCATION,
6525 REG_SZ,
6526 buffer.data,
6527 buffer.length);
6528 if (!W_ERROR_IS_OK(result)) {
6529 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_LOCATION));
6530 goto done;
6533 if (!force_update) {
6534 notify_printer_location(server_event_context(),
6535 msg_ctx, snum,
6536 printer->location ?
6537 printer->location : "");
6541 if (printer->sepfile != NULL &&
6542 (force_update ||
6543 !strequal(printer->sepfile, old_printer->sepfile))) {
6544 ok = push_reg_sz(tmp_ctx, &buffer, printer->sepfile);
6545 if (!ok) {
6546 DEBUG(0, ("sepfile data corrupted\n"));
6547 result = WERR_INVALID_DATA;
6548 goto done;
6550 result = winreg_set_printer_dataex(tmp_ctx, b,
6551 printer->sharename,
6552 SPOOL_DSSPOOLER_KEY,
6553 SPOOL_REG_PRINTSEPARATORFILE,
6554 REG_SZ,
6555 buffer.data,
6556 buffer.length);
6557 if (!W_ERROR_IS_OK(result)) {
6558 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSEPARATORFILE));
6559 goto done;
6562 if (!force_update) {
6563 notify_printer_sepfile(server_event_context(),
6564 msg_ctx, snum,
6565 printer->sepfile ?
6566 printer->sepfile : "");
6570 if (printer->starttime != 0 &&
6571 (force_update ||
6572 printer->starttime != old_printer->starttime)) {
6573 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6574 SIVAL(buffer.data, 0, printer->starttime);
6575 result = winreg_set_printer_dataex(tmp_ctx, b,
6576 printer->sharename,
6577 SPOOL_DSSPOOLER_KEY,
6578 SPOOL_REG_PRINTSTARTTIME,
6579 REG_DWORD,
6580 buffer.data,
6581 buffer.length);
6582 if (!W_ERROR_IS_OK(result)) {
6583 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSTARTTIME));
6584 goto done;
6588 if (printer->untiltime != 0 &&
6589 (force_update ||
6590 printer->untiltime != old_printer->untiltime)) {
6591 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6592 SIVAL(buffer.data, 0, printer->untiltime);
6593 result = winreg_set_printer_dataex(tmp_ctx, b,
6594 printer->sharename,
6595 SPOOL_DSSPOOLER_KEY,
6596 SPOOL_REG_PRINTENDTIME,
6597 REG_DWORD,
6598 buffer.data,
6599 buffer.length);
6600 if (!W_ERROR_IS_OK(result)) {
6601 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME));
6602 goto done;
6606 if (force_update || printer->priority != old_printer->priority) {
6607 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6608 SIVAL(buffer.data, 0, printer->priority);
6609 result = winreg_set_printer_dataex(tmp_ctx, b,
6610 printer->sharename,
6611 SPOOL_DSSPOOLER_KEY,
6612 SPOOL_REG_PRIORITY,
6613 REG_DWORD,
6614 buffer.data,
6615 buffer.length);
6616 if (!W_ERROR_IS_OK(result)) {
6617 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME));
6618 goto done;
6622 if (force_update || printer->attributes != old_printer->attributes) {
6623 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6624 SIVAL(buffer.data, 0, (printer->attributes &
6625 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
6626 result = winreg_set_printer_dataex(tmp_ctx, b,
6627 printer->sharename,
6628 SPOOL_DSSPOOLER_KEY,
6629 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
6630 REG_DWORD,
6631 buffer.data,
6632 buffer.length);
6633 if (!W_ERROR_IS_OK(result)) {
6634 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME));
6635 goto done;
6638 switch (printer->attributes & 0x3) {
6639 case 0:
6640 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
6641 break;
6642 case 1:
6643 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
6644 break;
6645 case 2:
6646 spooling = SPOOL_REGVAL_PRINTDIRECT;
6647 break;
6648 default:
6649 spooling = "unknown";
6651 ok = push_reg_sz(tmp_ctx, &buffer, spooling);
6652 if (!ok) {
6653 DEBUG(0, ("printSpooling data corrupted\n"));
6654 result = WERR_INVALID_DATA;
6655 goto done;
6657 winreg_set_printer_dataex(tmp_ctx, b,
6658 printer->sharename,
6659 SPOOL_DSSPOOLER_KEY,
6660 SPOOL_REG_PRINTSPOOLING,
6661 REG_SZ,
6662 buffer.data,
6663 buffer.length);
6666 ok = push_reg_sz(tmp_ctx, &buffer, lp_netbios_name());
6667 if (!ok) {
6668 DEBUG(0, ("shortServerName data corrupted\n"));
6669 result = WERR_INVALID_DATA;
6670 goto done;
6672 result = winreg_set_printer_dataex(tmp_ctx, b,
6673 printer->sharename,
6674 SPOOL_DSSPOOLER_KEY,
6675 SPOOL_REG_SHORTSERVERNAME,
6676 REG_SZ,
6677 buffer.data,
6678 buffer.length);
6679 if (!W_ERROR_IS_OK(result)) {
6680 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SHORTSERVERNAME));
6681 goto done;
6684 dnsdomname = get_mydnsfullname();
6685 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
6686 longname = talloc_strdup(tmp_ctx, dnsdomname);
6687 } else {
6688 longname = talloc_strdup(tmp_ctx, lp_netbios_name());
6690 if (longname == NULL) {
6691 result = WERR_NOMEM;
6692 goto done;
6695 ok = push_reg_sz(tmp_ctx, &buffer, longname);
6696 if (!ok) {
6697 DEBUG(0, ("longname data corrupted\n"));
6698 result = WERR_INVALID_DATA;
6699 goto done;
6701 result = winreg_set_printer_dataex(tmp_ctx, b,
6702 printer->sharename,
6703 SPOOL_DSSPOOLER_KEY,
6704 SPOOL_REG_SERVERNAME,
6705 REG_SZ,
6706 buffer.data,
6707 buffer.length);
6708 if (!W_ERROR_IS_OK(result)) {
6709 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SERVERNAME));
6710 goto done;
6713 uncname = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
6714 lp_netbios_name(), printer->sharename);
6715 ok = push_reg_sz(tmp_ctx, &buffer, uncname);
6716 if (!ok) {
6717 DEBUG(0, ("uncName data corrupted\n"));
6718 result = WERR_INVALID_DATA;
6719 goto done;
6721 result = winreg_set_printer_dataex(tmp_ctx, b,
6722 printer->sharename,
6723 SPOOL_DSSPOOLER_KEY,
6724 SPOOL_REG_UNCNAME,
6725 REG_SZ,
6726 buffer.data,
6727 buffer.length);
6728 if (!W_ERROR_IS_OK(result)) {
6729 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_UNCNAME));
6730 goto done;
6733 done:
6734 talloc_free(tmp_ctx);
6735 return result;
6738 /********************************************************************
6739 * Called by spoolss_api_setprinter
6740 * when updating a printer description.
6741 ********************************************************************/
6743 static WERROR update_printer(struct pipes_struct *p,
6744 struct policy_handle *handle,
6745 struct spoolss_SetPrinterInfoCtr *info_ctr,
6746 struct spoolss_DeviceMode *devmode)
6748 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6749 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6750 struct spoolss_PrinterInfo2 *old_printer;
6751 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6752 int snum;
6753 WERROR result = WERR_OK;
6754 TALLOC_CTX *tmp_ctx;
6755 struct dcerpc_binding_handle *b;
6757 DEBUG(8,("update_printer\n"));
6759 tmp_ctx = talloc_new(p->mem_ctx);
6760 if (tmp_ctx == NULL) {
6761 return WERR_NOMEM;
6764 if (!Printer) {
6765 result = WERR_BADFID;
6766 goto done;
6769 if (!get_printer_snum(p, handle, &snum, NULL)) {
6770 result = WERR_BADFID;
6771 goto done;
6774 result = winreg_printer_binding_handle(tmp_ctx,
6775 get_session_info_system(),
6776 p->msg_ctx,
6777 &b);
6778 if (!W_ERROR_IS_OK(result)) {
6779 goto done;
6782 result = winreg_get_printer(tmp_ctx, b,
6783 lp_const_servicename(snum),
6784 &old_printer);
6785 if (!W_ERROR_IS_OK(result)) {
6786 result = WERR_BADFID;
6787 goto done;
6790 /* Do sanity check on the requested changes for Samba */
6791 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6792 result = WERR_INVALID_PARAM;
6793 goto done;
6796 /* FIXME!!! If the driver has changed we really should verify that
6797 it is installed before doing much else --jerry */
6799 /* Check calling user has permission to update printer description */
6800 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6801 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6802 result = WERR_ACCESS_DENIED;
6803 goto done;
6806 /* Call addprinter hook */
6807 /* Check changes to see if this is really needed */
6809 if (*lp_addprinter_cmd(talloc_tos()) &&
6810 (!strequal(printer->drivername, old_printer->drivername) ||
6811 !strequal(printer->comment, old_printer->comment) ||
6812 !strequal(printer->portname, old_printer->portname) ||
6813 !strequal(printer->location, old_printer->location)) )
6815 char *raddr;
6817 raddr = tsocket_address_inet_addr_string(p->remote_address,
6818 p->mem_ctx);
6819 if (raddr == NULL) {
6820 return WERR_NOMEM;
6823 /* add_printer_hook() will call reload_services() */
6824 if (!add_printer_hook(tmp_ctx, p->session_info->security_token,
6825 printer, raddr,
6826 p->msg_ctx)) {
6827 result = WERR_ACCESS_DENIED;
6828 goto done;
6832 result = update_dsspooler(tmp_ctx,
6833 get_session_info_system(),
6834 p->msg_ctx,
6835 snum,
6836 printer,
6837 old_printer);
6838 if (!W_ERROR_IS_OK(result)) {
6839 goto done;
6842 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6844 if (devmode == NULL) {
6845 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6847 result = winreg_update_printer(tmp_ctx, b,
6848 printer->sharename,
6849 printer_mask,
6850 printer,
6851 devmode,
6852 NULL);
6854 done:
6855 talloc_free(tmp_ctx);
6857 return result;
6860 /****************************************************************************
6861 ****************************************************************************/
6862 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6863 struct policy_handle *handle,
6864 struct spoolss_SetPrinterInfo7 *info7)
6866 #ifdef HAVE_ADS
6867 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6868 WERROR result;
6869 int snum;
6870 struct printer_handle *Printer;
6872 if ( lp_security() != SEC_ADS ) {
6873 return WERR_UNKNOWN_LEVEL;
6876 Printer = find_printer_index_by_hnd(p, handle);
6878 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6880 if (!Printer)
6881 return WERR_BADFID;
6883 if (!get_printer_snum(p, handle, &snum, NULL))
6884 return WERR_BADFID;
6886 result = winreg_get_printer_internal(p->mem_ctx,
6887 get_session_info_system(),
6888 p->msg_ctx,
6889 lp_servicename(talloc_tos(), snum),
6890 &pinfo2);
6891 if (!W_ERROR_IS_OK(result)) {
6892 return WERR_BADFID;
6895 nt_printer_publish(pinfo2,
6896 get_session_info_system(),
6897 p->msg_ctx,
6898 pinfo2,
6899 info7->action);
6901 TALLOC_FREE(pinfo2);
6902 return WERR_OK;
6903 #else
6904 return WERR_UNKNOWN_LEVEL;
6905 #endif
6908 /********************************************************************
6909 ********************************************************************/
6911 static WERROR update_printer_devmode(struct pipes_struct *p,
6912 struct policy_handle *handle,
6913 struct spoolss_DeviceMode *devmode)
6915 int snum;
6916 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6917 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6919 DEBUG(8,("update_printer_devmode\n"));
6921 if (!Printer) {
6922 return WERR_BADFID;
6925 if (!get_printer_snum(p, handle, &snum, NULL)) {
6926 return WERR_BADFID;
6929 /* Check calling user has permission to update printer description */
6930 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6931 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6932 return WERR_ACCESS_DENIED;
6935 return winreg_update_printer_internal(p->mem_ctx,
6936 get_session_info_system(),
6937 p->msg_ctx,
6938 lp_const_servicename(snum),
6939 info2_mask,
6940 NULL,
6941 devmode,
6942 NULL);
6946 /****************************************************************
6947 _spoolss_SetPrinter
6948 ****************************************************************/
6950 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6951 struct spoolss_SetPrinter *r)
6953 WERROR result;
6955 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6957 if (!Printer) {
6958 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6959 OUR_HANDLE(r->in.handle)));
6960 return WERR_BADFID;
6963 /* check the level */
6964 switch (r->in.info_ctr->level) {
6965 case 0:
6966 return control_printer(r->in.handle, r->in.command, p);
6967 case 2:
6968 result = update_printer(p, r->in.handle,
6969 r->in.info_ctr,
6970 r->in.devmode_ctr->devmode);
6971 if (!W_ERROR_IS_OK(result))
6972 return result;
6973 if (r->in.secdesc_ctr->sd)
6974 result = update_printer_sec(r->in.handle, p,
6975 r->in.secdesc_ctr);
6976 return result;
6977 case 3:
6978 return update_printer_sec(r->in.handle, p,
6979 r->in.secdesc_ctr);
6980 case 7:
6981 return publish_or_unpublish_printer(p, r->in.handle,
6982 r->in.info_ctr->info.info7);
6983 case 8:
6984 return update_printer_devmode(p, r->in.handle,
6985 r->in.devmode_ctr->devmode);
6986 default:
6987 return WERR_UNKNOWN_LEVEL;
6991 /****************************************************************
6992 _spoolss_FindClosePrinterNotify
6993 ****************************************************************/
6995 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6996 struct spoolss_FindClosePrinterNotify *r)
6998 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
7000 if (!Printer) {
7001 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
7002 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
7003 return WERR_BADFID;
7006 if (Printer->notify.cli_chan != NULL &&
7007 Printer->notify.cli_chan->active_connections > 0) {
7008 int snum = -1;
7010 if (Printer->printer_type == SPLHND_PRINTER) {
7011 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7012 return WERR_BADFID;
7016 srv_spoolss_replycloseprinter(snum, Printer);
7019 Printer->notify.flags=0;
7020 Printer->notify.options=0;
7021 Printer->notify.localmachine[0]='\0';
7022 Printer->notify.printerlocal=0;
7023 TALLOC_FREE(Printer->notify.option);
7025 return WERR_OK;
7028 /****************************************************************
7029 _spoolss_AddJob
7030 ****************************************************************/
7032 WERROR _spoolss_AddJob(struct pipes_struct *p,
7033 struct spoolss_AddJob *r)
7035 if (!r->in.buffer && (r->in.offered != 0)) {
7036 return WERR_INVALID_PARAM;
7039 /* this is what a NT server returns for AddJob. AddJob must fail on
7040 * non-local printers */
7042 if (r->in.level != 1) {
7043 return WERR_UNKNOWN_LEVEL;
7046 return WERR_INVALID_PARAM;
7049 /****************************************************************************
7050 fill_job_info1
7051 ****************************************************************************/
7053 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
7054 struct spoolss_JobInfo1 *r,
7055 const print_queue_struct *queue,
7056 uint32_t jobid,
7057 int position, int snum,
7058 struct spoolss_PrinterInfo2 *pinfo2)
7060 struct tm *t;
7062 t = gmtime(&queue->time);
7064 r->job_id = jobid;
7066 r->printer_name = lp_servicename(mem_ctx, snum);
7067 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
7068 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
7069 W_ERROR_HAVE_NO_MEMORY(r->server_name);
7070 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
7071 W_ERROR_HAVE_NO_MEMORY(r->user_name);
7072 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
7073 W_ERROR_HAVE_NO_MEMORY(r->document_name);
7074 r->data_type = talloc_strdup(mem_ctx, "RAW");
7075 W_ERROR_HAVE_NO_MEMORY(r->data_type);
7076 r->text_status = talloc_strdup(mem_ctx, "");
7077 W_ERROR_HAVE_NO_MEMORY(r->text_status);
7079 r->status = nt_printj_status(queue->status);
7080 r->priority = queue->priority;
7081 r->position = position;
7082 r->total_pages = queue->page_count;
7083 r->pages_printed = 0; /* ??? */
7085 init_systemtime(&r->submitted, t);
7087 return WERR_OK;
7090 /****************************************************************************
7091 fill_job_info2
7092 ****************************************************************************/
7094 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
7095 struct spoolss_JobInfo2 *r,
7096 const print_queue_struct *queue,
7097 uint32_t jobid,
7098 int position, int snum,
7099 struct spoolss_PrinterInfo2 *pinfo2,
7100 struct spoolss_DeviceMode *devmode)
7102 struct tm *t;
7104 t = gmtime(&queue->time);
7106 r->job_id = jobid;
7108 r->printer_name = lp_servicename(mem_ctx, snum);
7109 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
7110 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
7111 W_ERROR_HAVE_NO_MEMORY(r->server_name);
7112 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
7113 W_ERROR_HAVE_NO_MEMORY(r->user_name);
7114 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
7115 W_ERROR_HAVE_NO_MEMORY(r->document_name);
7116 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
7117 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
7118 r->data_type = talloc_strdup(mem_ctx, "RAW");
7119 W_ERROR_HAVE_NO_MEMORY(r->data_type);
7120 r->print_processor = talloc_strdup(mem_ctx, "winprint");
7121 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
7122 r->parameters = talloc_strdup(mem_ctx, "");
7123 W_ERROR_HAVE_NO_MEMORY(r->parameters);
7124 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
7125 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
7127 r->devmode = devmode;
7129 r->text_status = talloc_strdup(mem_ctx, "");
7130 W_ERROR_HAVE_NO_MEMORY(r->text_status);
7132 r->secdesc = NULL;
7134 r->status = nt_printj_status(queue->status);
7135 r->priority = queue->priority;
7136 r->position = position;
7137 r->start_time = 0;
7138 r->until_time = 0;
7139 r->total_pages = queue->page_count;
7140 r->size = queue->size;
7141 init_systemtime(&r->submitted, t);
7142 r->time = 0;
7143 r->pages_printed = 0; /* ??? */
7145 return WERR_OK;
7148 /****************************************************************************
7149 Enumjobs at level 1.
7150 ****************************************************************************/
7152 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
7153 const print_queue_struct *queue,
7154 uint32_t num_queues, int snum,
7155 struct spoolss_PrinterInfo2 *pinfo2,
7156 union spoolss_JobInfo **info_p,
7157 uint32_t *count)
7159 union spoolss_JobInfo *info;
7160 int i;
7161 WERROR result = WERR_OK;
7162 uint32_t num_filled;
7163 struct tdb_print_db *pdb;
7165 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7166 if (info == NULL) {
7167 result = WERR_NOMEM;
7168 goto err_out;
7171 pdb = get_print_db_byname(pinfo2->sharename);
7172 if (pdb == NULL) {
7173 result = WERR_INVALID_PARAM;
7174 goto err_info_free;
7177 num_filled = 0;
7178 for (i = 0; i < num_queues; i++) {
7179 uint32_t jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
7180 if (jobid == (uint32_t)-1) {
7181 DEBUG(4, ("skipping sysjob %d\n", queue[i].sysjob));
7182 continue;
7185 result = fill_job_info1(info,
7186 &info[num_filled].info1,
7187 &queue[i],
7188 jobid,
7190 snum,
7191 pinfo2);
7192 if (!W_ERROR_IS_OK(result)) {
7193 goto err_pdb_drop;
7196 num_filled++;
7199 release_print_db(pdb);
7200 *info_p = info;
7201 *count = num_filled;
7203 return WERR_OK;
7205 err_pdb_drop:
7206 release_print_db(pdb);
7207 err_info_free:
7208 TALLOC_FREE(info);
7209 err_out:
7210 *count = 0;
7211 return result;
7214 /****************************************************************************
7215 Enumjobs at level 2.
7216 ****************************************************************************/
7218 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
7219 const print_queue_struct *queue,
7220 uint32_t num_queues, int snum,
7221 struct spoolss_PrinterInfo2 *pinfo2,
7222 union spoolss_JobInfo **info_p,
7223 uint32_t *count)
7225 union spoolss_JobInfo *info;
7226 int i;
7227 WERROR result = WERR_OK;
7228 uint32_t num_filled;
7229 struct tdb_print_db *pdb;
7231 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7232 if (info == NULL) {
7233 result = WERR_NOMEM;
7234 goto err_out;
7237 pdb = get_print_db_byname(pinfo2->sharename);
7238 if (pdb == NULL) {
7239 result = WERR_INVALID_PARAM;
7240 goto err_info_free;
7243 num_filled = 0;
7244 for (i = 0; i< num_queues; i++) {
7245 struct spoolss_DeviceMode *devmode;
7246 uint32_t jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
7247 if (jobid == (uint32_t)-1) {
7248 DEBUG(4, ("skipping sysjob %d\n", queue[i].sysjob));
7249 continue;
7252 result = spoolss_create_default_devmode(info,
7253 pinfo2->printername,
7254 &devmode);
7255 if (!W_ERROR_IS_OK(result)) {
7256 DEBUG(3, ("Can't proceed w/o a devmode!"));
7257 goto err_pdb_drop;
7260 result = fill_job_info2(info,
7261 &info[num_filled].info2,
7262 &queue[i],
7263 jobid,
7265 snum,
7266 pinfo2,
7267 devmode);
7268 if (!W_ERROR_IS_OK(result)) {
7269 goto err_pdb_drop;
7271 num_filled++;
7274 release_print_db(pdb);
7275 *info_p = info;
7276 *count = num_filled;
7278 return WERR_OK;
7280 err_pdb_drop:
7281 release_print_db(pdb);
7282 err_info_free:
7283 TALLOC_FREE(info);
7284 err_out:
7285 *count = 0;
7286 return result;
7289 /****************************************************************************
7290 Enumjobs at level 3.
7291 ****************************************************************************/
7293 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
7294 const print_queue_struct *queue,
7295 uint32_t num_queues, int snum,
7296 struct spoolss_PrinterInfo2 *pinfo2,
7297 union spoolss_JobInfo **info_p,
7298 uint32_t *count)
7300 union spoolss_JobInfo *info;
7301 int i;
7302 WERROR result = WERR_OK;
7303 uint32_t num_filled;
7304 struct tdb_print_db *pdb;
7306 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7307 if (info == NULL) {
7308 result = WERR_NOMEM;
7309 goto err_out;
7312 pdb = get_print_db_byname(pinfo2->sharename);
7313 if (pdb == NULL) {
7314 result = WERR_INVALID_PARAM;
7315 goto err_info_free;
7318 num_filled = 0;
7319 for (i = 0; i < num_queues; i++) {
7320 uint32_t jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
7321 if (jobid == (uint32_t)-1) {
7322 DEBUG(4, ("skipping sysjob %d\n", queue[i].sysjob));
7323 continue;
7326 info[num_filled].info3.job_id = jobid;
7327 /* next_job_id is overwritten on next iteration */
7328 info[num_filled].info3.next_job_id = 0;
7329 info[num_filled].info3.reserved = 0;
7331 if (num_filled > 0) {
7332 info[num_filled - 1].info3.next_job_id = jobid;
7334 num_filled++;
7337 release_print_db(pdb);
7338 *info_p = info;
7339 *count = num_filled;
7341 return WERR_OK;
7343 err_info_free:
7344 TALLOC_FREE(info);
7345 err_out:
7346 *count = 0;
7347 return result;
7350 /****************************************************************
7351 _spoolss_EnumJobs
7352 ****************************************************************/
7354 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
7355 struct spoolss_EnumJobs *r)
7357 WERROR result;
7358 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
7359 int snum;
7360 print_status_struct prt_status;
7361 print_queue_struct *queue = NULL;
7362 uint32_t count;
7364 /* that's an [in out] buffer */
7366 if (!r->in.buffer && (r->in.offered != 0)) {
7367 return WERR_INVALID_PARAM;
7370 if ((r->in.level != 1) && (r->in.level != 2) && (r->in.level != 3)) {
7371 DEBUG(4, ("EnumJobs level %d not supported\n", r->in.level));
7372 return WERR_UNKNOWN_LEVEL;
7375 DEBUG(4,("_spoolss_EnumJobs\n"));
7377 *r->out.needed = 0;
7378 *r->out.count = 0;
7379 *r->out.info = NULL;
7381 /* lookup the printer snum and tdb entry */
7383 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7384 return WERR_BADFID;
7387 result = winreg_get_printer_internal(p->mem_ctx,
7388 get_session_info_system(),
7389 p->msg_ctx,
7390 lp_const_servicename(snum),
7391 &pinfo2);
7392 if (!W_ERROR_IS_OK(result)) {
7393 return result;
7396 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
7397 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7398 count, prt_status.status, prt_status.message));
7400 if (count == 0) {
7401 SAFE_FREE(queue);
7402 TALLOC_FREE(pinfo2);
7403 return WERR_OK;
7406 switch (r->in.level) {
7407 case 1:
7408 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
7409 pinfo2, r->out.info, r->out.count);
7410 break;
7411 case 2:
7412 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
7413 pinfo2, r->out.info, r->out.count);
7414 break;
7415 case 3:
7416 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
7417 pinfo2, r->out.info, r->out.count);
7418 break;
7419 default:
7420 SMB_ASSERT(false); /* level checked on entry */
7421 break;
7424 SAFE_FREE(queue);
7425 TALLOC_FREE(pinfo2);
7427 if (!W_ERROR_IS_OK(result)) {
7428 return result;
7431 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7432 spoolss_EnumJobs,
7433 *r->out.info, r->in.level,
7434 *r->out.count);
7435 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7436 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7438 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7441 /****************************************************************
7442 _spoolss_ScheduleJob
7443 ****************************************************************/
7445 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
7446 struct spoolss_ScheduleJob *r)
7448 return WERR_OK;
7451 /****************************************************************
7452 ****************************************************************/
7454 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
7455 struct messaging_context *msg_ctx,
7456 const char *printer_name,
7457 uint32_t job_id,
7458 struct spoolss_SetJobInfo1 *r)
7460 char *old_doc_name;
7462 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
7463 return WERR_BADFID;
7466 if (strequal(old_doc_name, r->document_name)) {
7467 return WERR_OK;
7470 if (!print_job_set_name(server_event_context(), msg_ctx,
7471 printer_name, job_id, r->document_name)) {
7472 return WERR_BADFID;
7475 return WERR_OK;
7478 /****************************************************************
7479 _spoolss_SetJob
7480 ****************************************************************/
7482 WERROR _spoolss_SetJob(struct pipes_struct *p,
7483 struct spoolss_SetJob *r)
7485 const struct auth_session_info *session_info = p->session_info;
7486 int snum;
7487 WERROR errcode = WERR_BADFUNC;
7489 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7490 return WERR_BADFID;
7493 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
7494 return WERR_INVALID_PRINTER_NAME;
7497 switch (r->in.command) {
7498 case SPOOLSS_JOB_CONTROL_CANCEL:
7499 case SPOOLSS_JOB_CONTROL_DELETE:
7500 errcode = print_job_delete(session_info, p->msg_ctx,
7501 snum, r->in.job_id);
7502 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
7503 errcode = WERR_OK;
7505 break;
7506 case SPOOLSS_JOB_CONTROL_PAUSE:
7507 errcode = print_job_pause(session_info, p->msg_ctx,
7508 snum, r->in.job_id);
7509 break;
7510 case SPOOLSS_JOB_CONTROL_RESTART:
7511 case SPOOLSS_JOB_CONTROL_RESUME:
7512 errcode = print_job_resume(session_info, p->msg_ctx,
7513 snum, r->in.job_id);
7514 break;
7515 case 0:
7516 errcode = WERR_OK;
7517 break;
7518 default:
7519 return WERR_UNKNOWN_LEVEL;
7522 if (!W_ERROR_IS_OK(errcode)) {
7523 return errcode;
7526 if (r->in.ctr == NULL) {
7527 return errcode;
7530 switch (r->in.ctr->level) {
7531 case 1:
7532 errcode = spoolss_setjob_1(p->mem_ctx, p->msg_ctx,
7533 lp_const_servicename(snum),
7534 r->in.job_id,
7535 r->in.ctr->info.info1);
7536 break;
7537 case 2:
7538 case 3:
7539 case 4:
7540 default:
7541 return WERR_UNKNOWN_LEVEL;
7544 return errcode;
7547 /****************************************************************************
7548 Enumerates all printer drivers by level and architecture.
7549 ****************************************************************************/
7551 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
7552 const struct auth_session_info *session_info,
7553 struct messaging_context *msg_ctx,
7554 const char *servername,
7555 const char *architecture,
7556 uint32_t level,
7557 union spoolss_DriverInfo **info_p,
7558 uint32_t *count_p)
7560 int i;
7561 uint32_t version;
7562 struct spoolss_DriverInfo8 *driver;
7563 union spoolss_DriverInfo *info = NULL;
7564 uint32_t count = 0;
7565 WERROR result = WERR_OK;
7566 uint32_t num_drivers;
7567 const char **drivers;
7568 struct dcerpc_binding_handle *b;
7569 TALLOC_CTX *tmp_ctx = NULL;
7571 *count_p = 0;
7572 *info_p = NULL;
7574 tmp_ctx = talloc_new(mem_ctx);
7575 if (!tmp_ctx) {
7576 return WERR_NOMEM;
7579 result = winreg_printer_binding_handle(tmp_ctx,
7580 session_info,
7581 msg_ctx,
7582 &b);
7583 if (!W_ERROR_IS_OK(result)) {
7584 goto out;
7587 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7588 result = winreg_get_driver_list(tmp_ctx, b,
7589 architecture, version,
7590 &num_drivers, &drivers);
7591 if (!W_ERROR_IS_OK(result)) {
7592 goto out;
7594 DEBUG(4, ("we have:[%d] drivers in environment"
7595 " [%s] and version [%d]\n",
7596 num_drivers, architecture, version));
7598 if (num_drivers != 0) {
7599 info = talloc_realloc(tmp_ctx, info,
7600 union spoolss_DriverInfo,
7601 count + num_drivers);
7602 if (!info) {
7603 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7604 "failed to enlarge driver info buffer!\n"));
7605 result = WERR_NOMEM;
7606 goto out;
7610 for (i = 0; i < num_drivers; i++) {
7611 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
7613 result = winreg_get_driver(tmp_ctx, b,
7614 architecture, drivers[i],
7615 version, &driver);
7616 if (!W_ERROR_IS_OK(result)) {
7617 goto out;
7620 switch (level) {
7621 case 1:
7622 result = fill_printer_driver_info1(info, &info[count+i].info1,
7623 driver, servername);
7624 break;
7625 case 2:
7626 result = fill_printer_driver_info2(info, &info[count+i].info2,
7627 driver, servername);
7628 break;
7629 case 3:
7630 result = fill_printer_driver_info3(info, &info[count+i].info3,
7631 driver, servername);
7632 break;
7633 case 4:
7634 result = fill_printer_driver_info4(info, &info[count+i].info4,
7635 driver, servername);
7636 break;
7637 case 5:
7638 result = fill_printer_driver_info5(info, &info[count+i].info5,
7639 driver, servername);
7640 break;
7641 case 6:
7642 result = fill_printer_driver_info6(info, &info[count+i].info6,
7643 driver, servername);
7644 break;
7645 case 8:
7646 result = fill_printer_driver_info8(info, &info[count+i].info8,
7647 driver, servername);
7648 break;
7649 default:
7650 result = WERR_UNKNOWN_LEVEL;
7651 break;
7654 TALLOC_FREE(driver);
7656 if (!W_ERROR_IS_OK(result)) {
7657 goto out;
7661 count += num_drivers;
7662 TALLOC_FREE(drivers);
7665 out:
7666 if (W_ERROR_IS_OK(result)) {
7667 *info_p = talloc_move(mem_ctx, &info);
7668 *count_p = count;
7671 talloc_free(tmp_ctx);
7672 return result;
7675 /****************************************************************************
7676 Enumerates all printer drivers by level.
7677 ****************************************************************************/
7679 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
7680 const struct auth_session_info *session_info,
7681 struct messaging_context *msg_ctx,
7682 const char *servername,
7683 const char *architecture,
7684 uint32_t level,
7685 union spoolss_DriverInfo **info_p,
7686 uint32_t *count_p)
7688 uint32_t a,i;
7689 WERROR result = WERR_OK;
7691 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
7693 for (a=0; archi_table[a].long_archi != NULL; a++) {
7695 union spoolss_DriverInfo *info = NULL;
7696 uint32_t count = 0;
7698 result = enumprinterdrivers_level_by_architecture(mem_ctx,
7699 session_info,
7700 msg_ctx,
7701 servername,
7702 archi_table[a].long_archi,
7703 level,
7704 &info,
7705 &count);
7706 if (!W_ERROR_IS_OK(result)) {
7707 continue;
7710 for (i=0; i < count; i++) {
7711 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
7712 info[i], info_p, count_p);
7716 return result;
7719 return enumprinterdrivers_level_by_architecture(mem_ctx,
7720 session_info,
7721 msg_ctx,
7722 servername,
7723 architecture,
7724 level,
7725 info_p,
7726 count_p);
7729 /****************************************************************
7730 _spoolss_EnumPrinterDrivers
7731 ****************************************************************/
7733 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
7734 struct spoolss_EnumPrinterDrivers *r)
7736 const char *cservername;
7737 WERROR result;
7739 /* that's an [in out] buffer */
7741 if (!r->in.buffer && (r->in.offered != 0)) {
7742 return WERR_INVALID_PARAM;
7745 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7747 *r->out.needed = 0;
7748 *r->out.count = 0;
7749 *r->out.info = NULL;
7751 cservername = canon_servername(r->in.server);
7753 if (!is_myname_or_ipaddr(cservername)) {
7754 return WERR_UNKNOWN_PRINTER_DRIVER;
7757 result = enumprinterdrivers_level(p->mem_ctx,
7758 get_session_info_system(),
7759 p->msg_ctx,
7760 cservername,
7761 r->in.environment,
7762 r->in.level,
7763 r->out.info,
7764 r->out.count);
7765 if (!W_ERROR_IS_OK(result)) {
7766 return result;
7769 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7770 spoolss_EnumPrinterDrivers,
7771 *r->out.info, r->in.level,
7772 *r->out.count);
7773 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7774 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7776 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7779 /****************************************************************
7780 _spoolss_EnumForms
7781 ****************************************************************/
7783 WERROR _spoolss_EnumForms(struct pipes_struct *p,
7784 struct spoolss_EnumForms *r)
7786 WERROR result;
7788 *r->out.count = 0;
7789 *r->out.needed = 0;
7790 *r->out.info = NULL;
7792 /* that's an [in out] buffer */
7794 if (!r->in.buffer && (r->in.offered != 0) ) {
7795 return WERR_INVALID_PARAM;
7798 DEBUG(4,("_spoolss_EnumForms\n"));
7799 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7800 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7802 switch (r->in.level) {
7803 case 1:
7804 result = winreg_printer_enumforms1_internal(p->mem_ctx,
7805 get_session_info_system(),
7806 p->msg_ctx,
7807 r->out.count,
7808 r->out.info);
7809 break;
7810 default:
7811 result = WERR_UNKNOWN_LEVEL;
7812 break;
7815 if (!W_ERROR_IS_OK(result)) {
7816 return result;
7819 if (*r->out.count == 0) {
7820 return WERR_NO_MORE_ITEMS;
7823 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7824 spoolss_EnumForms,
7825 *r->out.info, r->in.level,
7826 *r->out.count);
7827 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7828 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7830 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7833 /****************************************************************
7834 _spoolss_GetForm
7835 ****************************************************************/
7837 WERROR _spoolss_GetForm(struct pipes_struct *p,
7838 struct spoolss_GetForm *r)
7840 WERROR result;
7842 /* that's an [in out] buffer */
7844 if (!r->in.buffer && (r->in.offered != 0)) {
7845 return WERR_INVALID_PARAM;
7848 DEBUG(4,("_spoolss_GetForm\n"));
7849 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7850 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7852 switch (r->in.level) {
7853 case 1:
7854 result = winreg_printer_getform1_internal(p->mem_ctx,
7855 get_session_info_system(),
7856 p->msg_ctx,
7857 r->in.form_name,
7858 &r->out.info->info1);
7859 break;
7860 default:
7861 result = WERR_UNKNOWN_LEVEL;
7862 break;
7865 if (!W_ERROR_IS_OK(result)) {
7866 TALLOC_FREE(r->out.info);
7867 return result;
7870 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7871 r->out.info, r->in.level);
7872 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7874 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7877 /****************************************************************************
7878 ****************************************************************************/
7880 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7881 struct spoolss_PortInfo1 *r,
7882 const char *name)
7884 r->port_name = talloc_strdup(mem_ctx, name);
7885 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7887 return WERR_OK;
7890 /****************************************************************************
7891 TODO: This probably needs distinguish between TCP/IP and Local ports
7892 somehow.
7893 ****************************************************************************/
7895 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7896 struct spoolss_PortInfo2 *r,
7897 const char *name)
7899 r->port_name = talloc_strdup(mem_ctx, name);
7900 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7902 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7903 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7905 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7906 W_ERROR_HAVE_NO_MEMORY(r->description);
7908 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7909 r->reserved = 0;
7911 return WERR_OK;
7915 /****************************************************************************
7916 wrapper around the enumer ports command
7917 ****************************************************************************/
7919 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7921 char *cmd = lp_enumports_cmd(talloc_tos());
7922 char **qlines = NULL;
7923 char *command = NULL;
7924 int numlines;
7925 int ret;
7926 int fd;
7928 *count = 0;
7929 *lines = NULL;
7931 /* if no hook then just fill in the default port */
7933 if ( !*cmd ) {
7934 if (!(qlines = talloc_array( NULL, char*, 2 ))) {
7935 return WERR_NOMEM;
7937 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7938 TALLOC_FREE(qlines);
7939 return WERR_NOMEM;
7941 qlines[1] = NULL;
7942 numlines = 1;
7944 else {
7945 /* we have a valid enumport command */
7947 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7948 if (!command) {
7949 return WERR_NOMEM;
7952 DEBUG(10,("Running [%s]\n", command));
7953 ret = smbrun(command, &fd);
7954 DEBUG(10,("Returned [%d]\n", ret));
7955 TALLOC_FREE(command);
7956 if (ret != 0) {
7957 if (fd != -1) {
7958 close(fd);
7960 return WERR_ACCESS_DENIED;
7963 numlines = 0;
7964 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7965 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7966 close(fd);
7969 *count = numlines;
7970 *lines = qlines;
7972 return WERR_OK;
7975 /****************************************************************************
7976 enumports level 1.
7977 ****************************************************************************/
7979 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7980 union spoolss_PortInfo **info_p,
7981 uint32_t *count)
7983 union spoolss_PortInfo *info = NULL;
7984 int i=0;
7985 WERROR result = WERR_OK;
7986 char **qlines = NULL;
7987 int numlines = 0;
7989 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7990 if (!W_ERROR_IS_OK(result)) {
7991 goto out;
7994 if (numlines) {
7995 info = talloc_array(mem_ctx, union spoolss_PortInfo, numlines);
7996 if (!info) {
7997 DEBUG(10,("Returning WERR_NOMEM\n"));
7998 result = WERR_NOMEM;
7999 goto out;
8002 for (i=0; i<numlines; i++) {
8003 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
8004 result = fill_port_1(info, &info[i].info1, qlines[i]);
8005 if (!W_ERROR_IS_OK(result)) {
8006 goto out;
8010 TALLOC_FREE(qlines);
8012 out:
8013 if (!W_ERROR_IS_OK(result)) {
8014 TALLOC_FREE(info);
8015 TALLOC_FREE(qlines);
8016 *count = 0;
8017 *info_p = NULL;
8018 return result;
8021 *info_p = info;
8022 *count = numlines;
8024 return WERR_OK;
8027 /****************************************************************************
8028 enumports level 2.
8029 ****************************************************************************/
8031 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
8032 union spoolss_PortInfo **info_p,
8033 uint32_t *count)
8035 union spoolss_PortInfo *info = NULL;
8036 int i=0;
8037 WERROR result = WERR_OK;
8038 char **qlines = NULL;
8039 int numlines = 0;
8041 result = enumports_hook(talloc_tos(), &numlines, &qlines );
8042 if (!W_ERROR_IS_OK(result)) {
8043 goto out;
8046 if (numlines) {
8047 info = talloc_array(mem_ctx, union spoolss_PortInfo, numlines);
8048 if (!info) {
8049 DEBUG(10,("Returning WERR_NOMEM\n"));
8050 result = WERR_NOMEM;
8051 goto out;
8054 for (i=0; i<numlines; i++) {
8055 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
8056 result = fill_port_2(info, &info[i].info2, qlines[i]);
8057 if (!W_ERROR_IS_OK(result)) {
8058 goto out;
8062 TALLOC_FREE(qlines);
8064 out:
8065 if (!W_ERROR_IS_OK(result)) {
8066 TALLOC_FREE(info);
8067 TALLOC_FREE(qlines);
8068 *count = 0;
8069 *info_p = NULL;
8070 return result;
8073 *info_p = info;
8074 *count = numlines;
8076 return WERR_OK;
8079 /****************************************************************
8080 _spoolss_EnumPorts
8081 ****************************************************************/
8083 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
8084 struct spoolss_EnumPorts *r)
8086 WERROR result;
8088 /* that's an [in out] buffer */
8090 if (!r->in.buffer && (r->in.offered != 0)) {
8091 return WERR_INVALID_PARAM;
8094 DEBUG(4,("_spoolss_EnumPorts\n"));
8096 *r->out.count = 0;
8097 *r->out.needed = 0;
8098 *r->out.info = NULL;
8100 switch (r->in.level) {
8101 case 1:
8102 result = enumports_level_1(p->mem_ctx, r->out.info,
8103 r->out.count);
8104 break;
8105 case 2:
8106 result = enumports_level_2(p->mem_ctx, r->out.info,
8107 r->out.count);
8108 break;
8109 default:
8110 return WERR_UNKNOWN_LEVEL;
8113 if (!W_ERROR_IS_OK(result)) {
8114 return result;
8117 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8118 spoolss_EnumPorts,
8119 *r->out.info, r->in.level,
8120 *r->out.count);
8121 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8122 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8124 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8127 /****************************************************************************
8128 ****************************************************************************/
8130 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
8131 const char *server,
8132 struct spoolss_SetPrinterInfoCtr *info_ctr,
8133 struct spoolss_DeviceMode *devmode,
8134 struct security_descriptor *secdesc,
8135 struct spoolss_UserLevelCtr *user_ctr,
8136 struct policy_handle *handle)
8138 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
8139 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
8140 int snum;
8141 WERROR err = WERR_OK;
8143 /* samba does not have a concept of local, non-shared printers yet, so
8144 * make sure we always setup sharename - gd */
8145 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
8146 (info2->printername != NULL && info2->printername[0] != '\0')) {
8147 DEBUG(5, ("spoolss_addprinterex_level_2: "
8148 "no sharename has been set, setting printername %s as sharename\n",
8149 info2->printername));
8150 info2->sharename = info2->printername;
8153 /* check to see if the printer already exists */
8154 if ((snum = print_queue_snum(info2->sharename)) != -1) {
8155 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8156 info2->sharename));
8157 return WERR_PRINTER_ALREADY_EXISTS;
8160 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
8161 if ((snum = print_queue_snum(info2->printername)) != -1) {
8162 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8163 info2->printername));
8164 return WERR_PRINTER_ALREADY_EXISTS;
8168 /* validate printer info struct */
8169 if (!info2->printername || strlen(info2->printername) == 0) {
8170 return WERR_INVALID_PRINTER_NAME;
8172 if (!info2->portname || strlen(info2->portname) == 0) {
8173 return WERR_UNKNOWN_PORT;
8175 if (!info2->drivername || strlen(info2->drivername) == 0) {
8176 return WERR_UNKNOWN_PRINTER_DRIVER;
8178 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
8179 return WERR_UNKNOWN_PRINTPROCESSOR;
8182 /* FIXME!!! smbd should check to see if the driver is installed before
8183 trying to add a printer like this --jerry */
8185 if (*lp_addprinter_cmd(talloc_tos()) ) {
8186 char *raddr;
8188 raddr = tsocket_address_inet_addr_string(p->remote_address,
8189 p->mem_ctx);
8190 if (raddr == NULL) {
8191 return WERR_NOMEM;
8194 if ( !add_printer_hook(p->mem_ctx, p->session_info->security_token,
8195 info2, raddr,
8196 p->msg_ctx) ) {
8197 return WERR_ACCESS_DENIED;
8199 } else {
8200 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no "
8201 "smb.conf parameter \"addprinter command\" is defined. This "
8202 "parameter must exist for this call to succeed\n",
8203 info2->sharename ));
8206 if ((snum = print_queue_snum(info2->sharename)) == -1) {
8207 return WERR_ACCESS_DENIED;
8210 /* you must be a printer admin to add a new printer */
8211 if (!print_access_check(p->session_info,
8212 p->msg_ctx,
8213 snum,
8214 PRINTER_ACCESS_ADMINISTER)) {
8215 return WERR_ACCESS_DENIED;
8219 * Do sanity check on the requested changes for Samba.
8222 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
8223 return WERR_INVALID_PARAM;
8226 if (devmode == NULL) {
8227 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
8230 err = update_dsspooler(p->mem_ctx,
8231 get_session_info_system(),
8232 p->msg_ctx,
8234 info2,
8235 NULL);
8236 if (!W_ERROR_IS_OK(err)) {
8237 return err;
8240 err = winreg_update_printer_internal(p->mem_ctx,
8241 get_session_info_system(),
8242 p->msg_ctx,
8243 info2->sharename,
8244 info2_mask,
8245 info2,
8246 devmode,
8247 secdesc);
8248 if (!W_ERROR_IS_OK(err)) {
8249 return err;
8252 err = open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER);
8253 if (!W_ERROR_IS_OK(err)) {
8254 /* Handle open failed - remove addition. */
8255 ZERO_STRUCTP(handle);
8256 return err;
8259 return WERR_OK;
8262 /****************************************************************
8263 _spoolss_AddPrinterEx
8264 ****************************************************************/
8266 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
8267 struct spoolss_AddPrinterEx *r)
8269 switch (r->in.info_ctr->level) {
8270 case 1:
8271 /* we don't handle yet */
8272 /* but I know what to do ... */
8273 return WERR_UNKNOWN_LEVEL;
8274 case 2:
8275 return spoolss_addprinterex_level_2(p, r->in.server,
8276 r->in.info_ctr,
8277 r->in.devmode_ctr->devmode,
8278 r->in.secdesc_ctr->sd,
8279 r->in.userlevel_ctr,
8280 r->out.handle);
8281 default:
8282 return WERR_UNKNOWN_LEVEL;
8286 /****************************************************************
8287 _spoolss_AddPrinter
8288 ****************************************************************/
8290 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
8291 struct spoolss_AddPrinter *r)
8293 struct spoolss_AddPrinterEx a;
8294 struct spoolss_UserLevelCtr userlevel_ctr;
8296 ZERO_STRUCT(userlevel_ctr);
8298 userlevel_ctr.level = 1;
8300 a.in.server = r->in.server;
8301 a.in.info_ctr = r->in.info_ctr;
8302 a.in.devmode_ctr = r->in.devmode_ctr;
8303 a.in.secdesc_ctr = r->in.secdesc_ctr;
8304 a.in.userlevel_ctr = &userlevel_ctr;
8305 a.out.handle = r->out.handle;
8307 return _spoolss_AddPrinterEx(p, &a);
8310 /****************************************************************
8311 _spoolss_AddPrinterDriverEx
8312 ****************************************************************/
8314 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
8315 struct spoolss_AddPrinterDriverEx *r)
8317 WERROR err = WERR_OK;
8318 const char *driver_name = NULL;
8319 uint32_t version;
8320 const char *fn;
8322 switch (p->opnum) {
8323 case NDR_SPOOLSS_ADDPRINTERDRIVER:
8324 fn = "_spoolss_AddPrinterDriver";
8325 break;
8326 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
8327 fn = "_spoolss_AddPrinterDriverEx";
8328 break;
8329 default:
8330 return WERR_INVALID_PARAM;
8334 * we only support the semantics of AddPrinterDriver()
8335 * i.e. only copy files that are newer than existing ones
8338 if (r->in.flags == 0) {
8339 return WERR_INVALID_PARAM;
8342 if (r->in.flags != APD_COPY_NEW_FILES) {
8343 return WERR_ACCESS_DENIED;
8346 /* FIXME */
8347 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
8348 /* Clever hack from Martin Zielinski <mz@seh.de>
8349 * to allow downgrade from level 8 (Vista).
8351 DEBUG(0,("%s: level %d not yet implemented\n", fn,
8352 r->in.info_ctr->level));
8353 return WERR_UNKNOWN_LEVEL;
8356 DEBUG(5,("Cleaning driver's information\n"));
8357 err = clean_up_driver_struct(p->mem_ctx, p->session_info, r->in.info_ctr);
8358 if (!W_ERROR_IS_OK(err))
8359 goto done;
8361 DEBUG(5,("Moving driver to final destination\n"));
8362 err = move_driver_to_download_area(p->session_info, r->in.info_ctr);
8363 if (!W_ERROR_IS_OK(err)) {
8364 goto done;
8367 err = winreg_add_driver_internal(p->mem_ctx,
8368 get_session_info_system(),
8369 p->msg_ctx,
8370 r->in.info_ctr,
8371 &driver_name,
8372 &version);
8373 if (!W_ERROR_IS_OK(err)) {
8374 goto done;
8378 * I think this is where he DrvUpgradePrinter() hook would be
8379 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8380 * server. Right now, we just need to send ourselves a message
8381 * to update each printer bound to this driver. --jerry
8384 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
8385 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8386 fn, driver_name));
8389 done:
8390 return err;
8393 /****************************************************************
8394 _spoolss_AddPrinterDriver
8395 ****************************************************************/
8397 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
8398 struct spoolss_AddPrinterDriver *r)
8400 struct spoolss_AddPrinterDriverEx a;
8402 switch (r->in.info_ctr->level) {
8403 case 2:
8404 case 3:
8405 case 4:
8406 case 5:
8407 break;
8408 default:
8409 return WERR_UNKNOWN_LEVEL;
8412 a.in.servername = r->in.servername;
8413 a.in.info_ctr = r->in.info_ctr;
8414 a.in.flags = APD_COPY_NEW_FILES;
8416 return _spoolss_AddPrinterDriverEx(p, &a);
8419 /****************************************************************************
8420 ****************************************************************************/
8422 struct _spoolss_paths {
8423 int type;
8424 const char *share;
8425 const char *dir;
8428 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
8430 static const struct _spoolss_paths spoolss_paths[]= {
8431 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
8432 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
8435 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
8436 const char *servername,
8437 const char *environment,
8438 int component,
8439 char **path)
8441 const char *pservername = NULL;
8442 const char *long_archi;
8443 const char *short_archi;
8445 *path = NULL;
8447 /* environment may be empty */
8448 if (environment && strlen(environment)) {
8449 long_archi = environment;
8450 } else {
8451 long_archi = lp_parm_const_string(GLOBAL_SECTION_SNUM,
8452 "spoolss", "architecture",
8453 SPOOLSS_ARCHITECTURE_NT_X86);
8456 /* servername may be empty */
8457 if (servername && strlen(servername)) {
8458 pservername = canon_servername(servername);
8460 if (!is_myname_or_ipaddr(pservername)) {
8461 return WERR_INVALID_PARAM;
8465 if (!(short_archi = get_short_archi(long_archi))) {
8466 return WERR_INVALID_ENVIRONMENT;
8469 switch (component) {
8470 case SPOOLSS_PRTPROCS_PATH:
8471 case SPOOLSS_DRIVER_PATH:
8472 if (pservername) {
8473 *path = talloc_asprintf(mem_ctx,
8474 "\\\\%s\\%s\\%s",
8475 pservername,
8476 spoolss_paths[component].share,
8477 short_archi);
8478 } else {
8479 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
8480 SPOOLSS_DEFAULT_SERVER_PATH,
8481 spoolss_paths[component].dir,
8482 short_archi);
8484 break;
8485 default:
8486 return WERR_INVALID_PARAM;
8489 if (!*path) {
8490 return WERR_NOMEM;
8493 return WERR_OK;
8496 /****************************************************************************
8497 ****************************************************************************/
8499 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
8500 const char *servername,
8501 const char *environment,
8502 struct spoolss_DriverDirectoryInfo1 *r)
8504 WERROR werr;
8505 char *path = NULL;
8507 werr = compose_spoolss_server_path(mem_ctx,
8508 servername,
8509 environment,
8510 SPOOLSS_DRIVER_PATH,
8511 &path);
8512 if (!W_ERROR_IS_OK(werr)) {
8513 return werr;
8516 DEBUG(4,("printer driver directory: [%s]\n", path));
8518 r->directory_name = path;
8520 return WERR_OK;
8523 /****************************************************************
8524 _spoolss_GetPrinterDriverDirectory
8525 ****************************************************************/
8527 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
8528 struct spoolss_GetPrinterDriverDirectory *r)
8530 WERROR werror;
8532 /* that's an [in out] buffer */
8534 if (!r->in.buffer && (r->in.offered != 0)) {
8535 return WERR_INVALID_PARAM;
8538 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8539 r->in.level));
8541 *r->out.needed = 0;
8543 /* r->in.level is ignored */
8545 werror = getprinterdriverdir_level_1(p->mem_ctx,
8546 r->in.server,
8547 r->in.environment,
8548 &r->out.info->info1);
8549 if (!W_ERROR_IS_OK(werror)) {
8550 TALLOC_FREE(r->out.info);
8551 return werror;
8554 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
8555 r->out.info, r->in.level);
8556 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8558 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8561 /****************************************************************
8562 _spoolss_EnumPrinterData
8563 ****************************************************************/
8565 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
8566 struct spoolss_EnumPrinterData *r)
8568 WERROR result;
8569 struct spoolss_EnumPrinterDataEx r2;
8570 uint32_t count;
8571 struct spoolss_PrinterEnumValues *info, *val = NULL;
8572 uint32_t needed;
8574 r2.in.handle = r->in.handle;
8575 r2.in.key_name = "PrinterDriverData";
8576 r2.in.offered = 0;
8577 r2.out.count = &count;
8578 r2.out.info = &info;
8579 r2.out.needed = &needed;
8581 result = _spoolss_EnumPrinterDataEx(p, &r2);
8582 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8583 r2.in.offered = needed;
8584 result = _spoolss_EnumPrinterDataEx(p, &r2);
8586 if (!W_ERROR_IS_OK(result)) {
8587 return result;
8591 * The NT machine wants to know the biggest size of value and data
8593 * cf: MSDN EnumPrinterData remark section
8596 if (!r->in.value_offered && !r->in.data_offered) {
8597 uint32_t biggest_valuesize = 0;
8598 uint32_t biggest_datasize = 0;
8599 int i, name_length;
8601 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8603 for (i=0; i<count; i++) {
8605 name_length = strlen(info[i].value_name);
8606 if (strlen(info[i].value_name) > biggest_valuesize) {
8607 biggest_valuesize = name_length;
8610 if (info[i].data_length > biggest_datasize) {
8611 biggest_datasize = info[i].data_length;
8614 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8615 biggest_datasize));
8618 /* the value is an UNICODE string but real_value_size is the length
8619 in bytes including the trailing 0 */
8621 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8622 *r->out.data_needed = biggest_datasize;
8624 DEBUG(6,("final values: [%d], [%d]\n",
8625 *r->out.value_needed, *r->out.data_needed));
8627 return WERR_OK;
8630 if (r->in.enum_index < count) {
8631 val = &info[r->in.enum_index];
8634 if (val == NULL) {
8635 /* out_value should default to "" or else NT4 has
8636 problems unmarshalling the response */
8638 if (r->in.value_offered) {
8639 *r->out.value_needed = 1;
8640 r->out.value_name = talloc_strdup(r, "");
8641 if (!r->out.value_name) {
8642 return WERR_NOMEM;
8644 } else {
8645 r->out.value_name = NULL;
8646 *r->out.value_needed = 0;
8649 /* the data is counted in bytes */
8651 *r->out.data_needed = r->in.data_offered;
8653 result = WERR_NO_MORE_ITEMS;
8654 } else {
8656 * the value is:
8657 * - counted in bytes in the request
8658 * - counted in UNICODE chars in the max reply
8659 * - counted in bytes in the real size
8661 * take a pause *before* coding not *during* coding
8664 /* name */
8665 if (r->in.value_offered) {
8666 r->out.value_name = talloc_strdup(r, val->value_name);
8667 if (!r->out.value_name) {
8668 return WERR_NOMEM;
8670 *r->out.value_needed = val->value_name_len;
8671 } else {
8672 r->out.value_name = NULL;
8673 *r->out.value_needed = 0;
8676 /* type */
8678 *r->out.type = val->type;
8680 /* data - counted in bytes */
8683 * See the section "Dynamically Typed Query Parameters"
8684 * in MS-RPRN.
8687 if (r->out.data && val->data && val->data->data &&
8688 val->data_length && r->in.data_offered) {
8689 memcpy(r->out.data, val->data->data,
8690 MIN(val->data_length,r->in.data_offered));
8693 *r->out.data_needed = val->data_length;
8695 result = WERR_OK;
8698 return result;
8701 /****************************************************************
8702 _spoolss_SetPrinterData
8703 ****************************************************************/
8705 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
8706 struct spoolss_SetPrinterData *r)
8708 struct spoolss_SetPrinterDataEx r2;
8710 r2.in.handle = r->in.handle;
8711 r2.in.key_name = "PrinterDriverData";
8712 r2.in.value_name = r->in.value_name;
8713 r2.in.type = r->in.type;
8714 r2.in.data = r->in.data;
8715 r2.in.offered = r->in.offered;
8717 return _spoolss_SetPrinterDataEx(p, &r2);
8720 /****************************************************************
8721 _spoolss_ResetPrinter
8722 ****************************************************************/
8724 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
8725 struct spoolss_ResetPrinter *r)
8727 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8728 int snum;
8730 DEBUG(5,("_spoolss_ResetPrinter\n"));
8733 * All we do is to check to see if the handle and queue is valid.
8734 * This call really doesn't mean anything to us because we only
8735 * support RAW printing. --jerry
8738 if (!Printer) {
8739 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8740 OUR_HANDLE(r->in.handle)));
8741 return WERR_BADFID;
8744 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8745 return WERR_BADFID;
8748 /* blindly return success */
8749 return WERR_OK;
8752 /****************************************************************
8753 _spoolss_DeletePrinterData
8754 ****************************************************************/
8756 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
8757 struct spoolss_DeletePrinterData *r)
8759 struct spoolss_DeletePrinterDataEx r2;
8761 r2.in.handle = r->in.handle;
8762 r2.in.key_name = "PrinterDriverData";
8763 r2.in.value_name = r->in.value_name;
8765 return _spoolss_DeletePrinterDataEx(p, &r2);
8768 /****************************************************************
8769 _spoolss_AddForm
8770 ****************************************************************/
8772 WERROR _spoolss_AddForm(struct pipes_struct *p,
8773 struct spoolss_AddForm *r)
8775 struct spoolss_AddFormInfo1 *form;
8776 int snum = -1;
8777 WERROR status = WERR_OK;
8778 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8779 struct dcerpc_binding_handle *b;
8780 TALLOC_CTX *tmp_ctx = NULL;
8782 DEBUG(5,("_spoolss_AddForm\n"));
8784 if (!Printer) {
8785 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8786 OUR_HANDLE(r->in.handle)));
8787 return WERR_BADFID;
8790 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8791 and not a printer admin, then fail */
8793 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
8794 !security_token_has_privilege(p->session_info->security_token,
8795 SEC_PRIV_PRINT_OPERATOR)) {
8796 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8797 return WERR_ACCESS_DENIED;
8800 if (r->in.info_ctr->level != 1) {
8801 return WERR_INVALID_LEVEL;
8804 form = r->in.info_ctr->info.info1;
8805 if (!form) {
8806 return WERR_INVALID_PARAM;
8809 switch (form->flags) {
8810 case SPOOLSS_FORM_USER:
8811 case SPOOLSS_FORM_BUILTIN:
8812 case SPOOLSS_FORM_PRINTER:
8813 break;
8814 default:
8815 return WERR_INVALID_PARAM;
8818 tmp_ctx = talloc_new(p->mem_ctx);
8819 if (!tmp_ctx) {
8820 return WERR_NOMEM;
8823 status = winreg_printer_binding_handle(tmp_ctx,
8824 get_session_info_system(),
8825 p->msg_ctx,
8826 &b);
8827 if (!W_ERROR_IS_OK(status)) {
8828 goto done;
8831 status = winreg_printer_addform1(tmp_ctx, b, form);
8832 if (!W_ERROR_IS_OK(status)) {
8833 goto done;
8837 * ChangeID must always be set if this is a printer
8839 if (Printer->printer_type == SPLHND_PRINTER) {
8840 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8841 status = WERR_BADFID;
8842 goto done;
8845 status = winreg_printer_update_changeid(tmp_ctx, b,
8846 lp_const_servicename(snum));
8849 done:
8850 talloc_free(tmp_ctx);
8851 return status;
8854 /****************************************************************
8855 _spoolss_DeleteForm
8856 ****************************************************************/
8858 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8859 struct spoolss_DeleteForm *r)
8861 const char *form_name = r->in.form_name;
8862 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8863 int snum = -1;
8864 WERROR status = WERR_OK;
8865 struct dcerpc_binding_handle *b;
8866 TALLOC_CTX *tmp_ctx = NULL;
8868 DEBUG(5,("_spoolss_DeleteForm\n"));
8870 if (!Printer) {
8871 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8872 OUR_HANDLE(r->in.handle)));
8873 return WERR_BADFID;
8876 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
8877 !security_token_has_privilege(p->session_info->security_token,
8878 SEC_PRIV_PRINT_OPERATOR)) {
8879 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8880 return WERR_ACCESS_DENIED;
8883 tmp_ctx = talloc_new(p->mem_ctx);
8884 if (!tmp_ctx) {
8885 return WERR_NOMEM;
8888 status = winreg_printer_binding_handle(tmp_ctx,
8889 get_session_info_system(),
8890 p->msg_ctx,
8891 &b);
8892 if (!W_ERROR_IS_OK(status)) {
8893 goto done;
8896 status = winreg_printer_deleteform1(tmp_ctx, b, form_name);
8897 if (!W_ERROR_IS_OK(status)) {
8898 goto done;
8902 * ChangeID must always be set if this is a printer
8904 if (Printer->printer_type == SPLHND_PRINTER) {
8905 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8906 status = WERR_BADFID;
8907 goto done;
8910 status = winreg_printer_update_changeid(tmp_ctx, b,
8911 lp_const_servicename(snum));
8914 done:
8915 talloc_free(tmp_ctx);
8916 return status;
8919 /****************************************************************
8920 _spoolss_SetForm
8921 ****************************************************************/
8923 WERROR _spoolss_SetForm(struct pipes_struct *p,
8924 struct spoolss_SetForm *r)
8926 struct spoolss_AddFormInfo1 *form;
8927 const char *form_name = r->in.form_name;
8928 int snum = -1;
8929 WERROR status = WERR_OK;
8930 struct dcerpc_binding_handle *b;
8931 TALLOC_CTX *tmp_ctx = NULL;
8933 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8935 DEBUG(5,("_spoolss_SetForm\n"));
8937 if (!Printer) {
8938 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8939 OUR_HANDLE(r->in.handle)));
8940 return WERR_BADFID;
8943 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8944 and not a printer admin, then fail */
8946 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
8947 !security_token_has_privilege(p->session_info->security_token,
8948 SEC_PRIV_PRINT_OPERATOR)) {
8949 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8950 return WERR_ACCESS_DENIED;
8953 if (r->in.info_ctr->level != 1) {
8954 return WERR_INVALID_LEVEL;
8957 form = r->in.info_ctr->info.info1;
8958 if (!form) {
8959 return WERR_INVALID_PARAM;
8962 tmp_ctx = talloc_new(p->mem_ctx);
8963 if (!tmp_ctx) {
8964 return WERR_NOMEM;
8967 status = winreg_printer_binding_handle(tmp_ctx,
8968 get_session_info_system(),
8969 p->msg_ctx,
8970 &b);
8971 if (!W_ERROR_IS_OK(status)) {
8972 goto done;
8975 status = winreg_printer_setform1(tmp_ctx, b,
8976 form_name,
8977 form);
8978 if (!W_ERROR_IS_OK(status)) {
8979 goto done;
8983 * ChangeID must always be set if this is a printer
8985 if (Printer->printer_type == SPLHND_PRINTER) {
8986 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8987 status = WERR_BADFID;
8988 goto done;
8991 status = winreg_printer_update_changeid(tmp_ctx, b,
8992 lp_const_servicename(snum));
8995 done:
8996 talloc_free(tmp_ctx);
8997 return status;
9000 /****************************************************************************
9001 fill_print_processor1
9002 ****************************************************************************/
9004 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
9005 struct spoolss_PrintProcessorInfo1 *r,
9006 const char *print_processor_name)
9008 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
9009 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
9011 return WERR_OK;
9014 /****************************************************************************
9015 enumprintprocessors level 1.
9016 ****************************************************************************/
9018 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
9019 union spoolss_PrintProcessorInfo **info_p,
9020 uint32_t *count)
9022 union spoolss_PrintProcessorInfo *info;
9023 WERROR result;
9025 info = talloc_array(mem_ctx, union spoolss_PrintProcessorInfo, 1);
9026 W_ERROR_HAVE_NO_MEMORY(info);
9028 *count = 1;
9030 result = fill_print_processor1(info, &info[0].info1, "winprint");
9031 if (!W_ERROR_IS_OK(result)) {
9032 goto out;
9035 out:
9036 if (!W_ERROR_IS_OK(result)) {
9037 TALLOC_FREE(info);
9038 *count = 0;
9039 return result;
9042 *info_p = info;
9044 return WERR_OK;
9047 /****************************************************************
9048 _spoolss_EnumPrintProcessors
9049 ****************************************************************/
9051 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
9052 struct spoolss_EnumPrintProcessors *r)
9054 WERROR result;
9056 /* that's an [in out] buffer */
9058 if (!r->in.buffer && (r->in.offered != 0)) {
9059 return WERR_INVALID_PARAM;
9062 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
9065 * Enumerate the print processors ...
9067 * Just reply with "winprint", to keep NT happy
9068 * and I can use my nice printer checker.
9071 *r->out.count = 0;
9072 *r->out.needed = 0;
9073 *r->out.info = NULL;
9075 if (!get_short_archi(r->in.environment)) {
9076 return WERR_INVALID_ENVIRONMENT;
9079 switch (r->in.level) {
9080 case 1:
9081 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
9082 r->out.count);
9083 break;
9084 default:
9085 return WERR_UNKNOWN_LEVEL;
9088 if (!W_ERROR_IS_OK(result)) {
9089 return result;
9092 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9093 spoolss_EnumPrintProcessors,
9094 *r->out.info, r->in.level,
9095 *r->out.count);
9096 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9097 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9099 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9102 /****************************************************************************
9103 fill_printprocdatatype1
9104 ****************************************************************************/
9106 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
9107 struct spoolss_PrintProcDataTypesInfo1 *r,
9108 const char *name_array)
9110 r->name_array = talloc_strdup(mem_ctx, name_array);
9111 W_ERROR_HAVE_NO_MEMORY(r->name_array);
9113 return WERR_OK;
9116 /****************************************************************************
9117 enumprintprocdatatypes level 1.
9118 ****************************************************************************/
9120 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
9121 union spoolss_PrintProcDataTypesInfo **info_p,
9122 uint32_t *count)
9124 WERROR result;
9125 union spoolss_PrintProcDataTypesInfo *info;
9127 info = talloc_array(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
9128 W_ERROR_HAVE_NO_MEMORY(info);
9130 *count = 1;
9132 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
9133 if (!W_ERROR_IS_OK(result)) {
9134 goto out;
9137 out:
9138 if (!W_ERROR_IS_OK(result)) {
9139 TALLOC_FREE(info);
9140 *count = 0;
9141 return result;
9144 *info_p = info;
9146 return WERR_OK;
9149 /****************************************************************
9150 _spoolss_EnumPrintProcDataTypes
9151 ****************************************************************/
9153 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
9154 struct spoolss_EnumPrintProcDataTypes *r)
9156 WERROR result;
9158 /* that's an [in out] buffer */
9160 if (!r->in.buffer && (r->in.offered != 0)) {
9161 return WERR_INVALID_PARAM;
9164 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
9166 *r->out.count = 0;
9167 *r->out.needed = 0;
9168 *r->out.info = NULL;
9170 if (r->in.print_processor_name == NULL ||
9171 !strequal(r->in.print_processor_name, "winprint")) {
9172 return WERR_UNKNOWN_PRINTPROCESSOR;
9175 switch (r->in.level) {
9176 case 1:
9177 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
9178 r->out.count);
9179 break;
9180 default:
9181 return WERR_UNKNOWN_LEVEL;
9184 if (!W_ERROR_IS_OK(result)) {
9185 return result;
9188 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9189 spoolss_EnumPrintProcDataTypes,
9190 *r->out.info, r->in.level,
9191 *r->out.count);
9192 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9193 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9195 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9198 /****************************************************************************
9199 fill_monitor_1
9200 ****************************************************************************/
9202 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
9203 struct spoolss_MonitorInfo1 *r,
9204 const char *monitor_name)
9206 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
9207 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
9209 return WERR_OK;
9212 /****************************************************************************
9213 fill_monitor_2
9214 ****************************************************************************/
9216 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
9217 struct spoolss_MonitorInfo2 *r,
9218 const char *monitor_name,
9219 const char *environment,
9220 const char *dll_name)
9222 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
9223 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
9224 r->environment = talloc_strdup(mem_ctx, environment);
9225 W_ERROR_HAVE_NO_MEMORY(r->environment);
9226 r->dll_name = talloc_strdup(mem_ctx, dll_name);
9227 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
9229 return WERR_OK;
9232 /****************************************************************************
9233 enumprintmonitors level 1.
9234 ****************************************************************************/
9236 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
9237 union spoolss_MonitorInfo **info_p,
9238 uint32_t *count)
9240 union spoolss_MonitorInfo *info;
9241 WERROR result = WERR_OK;
9243 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, 2);
9244 W_ERROR_HAVE_NO_MEMORY(info);
9246 *count = 2;
9248 result = fill_monitor_1(info, &info[0].info1,
9249 SPL_LOCAL_PORT);
9250 if (!W_ERROR_IS_OK(result)) {
9251 goto out;
9254 result = fill_monitor_1(info, &info[1].info1,
9255 SPL_TCPIP_PORT);
9256 if (!W_ERROR_IS_OK(result)) {
9257 goto out;
9260 out:
9261 if (!W_ERROR_IS_OK(result)) {
9262 TALLOC_FREE(info);
9263 *count = 0;
9264 return result;
9267 *info_p = info;
9269 return WERR_OK;
9272 /****************************************************************************
9273 enumprintmonitors level 2.
9274 ****************************************************************************/
9276 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
9277 union spoolss_MonitorInfo **info_p,
9278 uint32_t *count)
9280 union spoolss_MonitorInfo *info;
9281 WERROR result = WERR_OK;
9283 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, 2);
9284 W_ERROR_HAVE_NO_MEMORY(info);
9286 *count = 2;
9288 result = fill_monitor_2(info, &info[0].info2,
9289 SPL_LOCAL_PORT,
9290 "Windows NT X86", /* FIXME */
9291 "localmon.dll");
9292 if (!W_ERROR_IS_OK(result)) {
9293 goto out;
9296 result = fill_monitor_2(info, &info[1].info2,
9297 SPL_TCPIP_PORT,
9298 "Windows NT X86", /* FIXME */
9299 "tcpmon.dll");
9300 if (!W_ERROR_IS_OK(result)) {
9301 goto out;
9304 out:
9305 if (!W_ERROR_IS_OK(result)) {
9306 TALLOC_FREE(info);
9307 *count = 0;
9308 return result;
9311 *info_p = info;
9313 return WERR_OK;
9316 /****************************************************************
9317 _spoolss_EnumMonitors
9318 ****************************************************************/
9320 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
9321 struct spoolss_EnumMonitors *r)
9323 WERROR result;
9325 /* that's an [in out] buffer */
9327 if (!r->in.buffer && (r->in.offered != 0)) {
9328 return WERR_INVALID_PARAM;
9331 DEBUG(5,("_spoolss_EnumMonitors\n"));
9334 * Enumerate the print monitors ...
9336 * Just reply with "Local Port", to keep NT happy
9337 * and I can use my nice printer checker.
9340 *r->out.count = 0;
9341 *r->out.needed = 0;
9342 *r->out.info = NULL;
9344 switch (r->in.level) {
9345 case 1:
9346 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
9347 r->out.count);
9348 break;
9349 case 2:
9350 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
9351 r->out.count);
9352 break;
9353 default:
9354 return WERR_UNKNOWN_LEVEL;
9357 if (!W_ERROR_IS_OK(result)) {
9358 return result;
9361 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9362 spoolss_EnumMonitors,
9363 *r->out.info, r->in.level,
9364 *r->out.count);
9365 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9366 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9368 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9371 /****************************************************************************
9372 ****************************************************************************/
9374 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
9375 const print_queue_struct *queue,
9376 int count, int snum,
9377 struct spoolss_PrinterInfo2 *pinfo2,
9378 uint32_t jobid,
9379 int sysjob,
9380 struct spoolss_JobInfo1 *r)
9382 int i = 0;
9383 bool found = false;
9385 for (i=0; i<count; i++) {
9386 if (queue[i].sysjob == sysjob) {
9387 found = true;
9388 break;
9392 if (found == false) {
9393 /* NT treats not found as bad param... yet another bad choice */
9394 return WERR_INVALID_PARAM;
9397 return fill_job_info1(mem_ctx,
9399 &queue[i],
9400 jobid,
9402 snum,
9403 pinfo2);
9406 /****************************************************************************
9407 ****************************************************************************/
9409 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
9410 const print_queue_struct *queue,
9411 int count, int snum,
9412 struct spoolss_PrinterInfo2 *pinfo2,
9413 uint32_t jobid,
9414 int sysjob,
9415 struct spoolss_JobInfo2 *r)
9417 int i = 0;
9418 bool found = false;
9419 struct spoolss_DeviceMode *devmode;
9420 WERROR result;
9422 for (i=0; i<count; i++) {
9423 if (queue[i].sysjob == sysjob) {
9424 found = true;
9425 break;
9429 if (found == false) {
9430 /* NT treats not found as bad param... yet another bad
9431 choice */
9432 return WERR_INVALID_PARAM;
9436 * if the print job does not have a DEVMODE associated with it,
9437 * just use the one for the printer. A NULL devicemode is not
9438 * a failure condition
9441 devmode = print_job_devmode(mem_ctx, lp_const_servicename(snum), jobid);
9442 if (!devmode) {
9443 result = spoolss_create_default_devmode(mem_ctx,
9444 pinfo2->printername,
9445 &devmode);
9446 if (!W_ERROR_IS_OK(result)) {
9447 DEBUG(3, ("Can't proceed w/o a devmode!"));
9448 return result;
9452 return fill_job_info2(mem_ctx,
9454 &queue[i],
9455 jobid,
9457 snum,
9458 pinfo2,
9459 devmode);
9462 /****************************************************************
9463 _spoolss_GetJob
9464 ****************************************************************/
9466 WERROR _spoolss_GetJob(struct pipes_struct *p,
9467 struct spoolss_GetJob *r)
9469 WERROR result = WERR_OK;
9470 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9471 const char *svc_name;
9472 int sysjob;
9473 int snum;
9474 int count;
9475 struct tdb_print_db *pdb;
9476 print_queue_struct *queue = NULL;
9477 print_status_struct prt_status;
9479 /* that's an [in out] buffer */
9481 if (!r->in.buffer && (r->in.offered != 0)) {
9482 result = WERR_INVALID_PARAM;
9483 goto err_jinfo_free;
9486 DEBUG(5,("_spoolss_GetJob\n"));
9488 *r->out.needed = 0;
9490 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9491 result = WERR_BADFID;
9492 goto err_jinfo_free;
9495 svc_name = lp_const_servicename(snum);
9496 if (svc_name == NULL) {
9497 result = WERR_INVALID_PARAM;
9498 goto err_jinfo_free;
9501 result = winreg_get_printer_internal(p->mem_ctx,
9502 get_session_info_system(),
9503 p->msg_ctx,
9504 svc_name,
9505 &pinfo2);
9506 if (!W_ERROR_IS_OK(result)) {
9507 goto err_jinfo_free;
9510 pdb = get_print_db_byname(svc_name);
9511 if (pdb == NULL) {
9512 DEBUG(3, ("failed to get print db for svc %s\n", svc_name));
9513 result = WERR_INVALID_PARAM;
9514 goto err_pinfo_free;
9517 sysjob = jobid_to_sysjob_pdb(pdb, r->in.job_id);
9518 release_print_db(pdb);
9519 if (sysjob == -1) {
9520 DEBUG(3, ("no sysjob for spoolss jobid %u\n", r->in.job_id));
9521 result = WERR_INVALID_PARAM;
9522 goto err_pinfo_free;
9525 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
9527 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9528 count, prt_status.status, prt_status.message));
9530 switch (r->in.level) {
9531 case 1:
9532 result = getjob_level_1(p->mem_ctx,
9533 queue, count, snum, pinfo2,
9534 r->in.job_id, sysjob,
9535 &r->out.info->info1);
9536 break;
9537 case 2:
9538 result = getjob_level_2(p->mem_ctx,
9539 queue, count, snum, pinfo2,
9540 r->in.job_id, sysjob,
9541 &r->out.info->info2);
9542 break;
9543 default:
9544 result = WERR_UNKNOWN_LEVEL;
9545 break;
9548 SAFE_FREE(queue);
9549 TALLOC_FREE(pinfo2);
9551 if (!W_ERROR_IS_OK(result)) {
9552 goto err_jinfo_free;
9555 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
9556 r->in.level);
9557 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9559 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9561 err_pinfo_free:
9562 TALLOC_FREE(pinfo2);
9563 err_jinfo_free:
9564 TALLOC_FREE(r->out.info);
9565 return result;
9568 /****************************************************************
9569 _spoolss_GetPrinterDataEx
9570 ****************************************************************/
9572 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
9573 struct spoolss_GetPrinterDataEx *r)
9576 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9577 const char *printer;
9578 int snum = 0;
9579 WERROR result = WERR_OK;
9580 DATA_BLOB blob;
9581 enum winreg_Type val_type = REG_NONE;
9582 uint8_t *val_data = NULL;
9583 uint32_t val_size = 0;
9584 struct dcerpc_binding_handle *b;
9585 TALLOC_CTX *tmp_ctx;
9587 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9589 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9590 r->in.key_name, r->in.value_name));
9592 /* in case of problem, return some default values */
9594 *r->out.needed = 0;
9595 *r->out.type = REG_NONE;
9597 tmp_ctx = talloc_new(p->mem_ctx);
9598 if (!tmp_ctx) {
9599 return WERR_NOMEM;
9602 if (!Printer) {
9603 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9604 OUR_HANDLE(r->in.handle)));
9605 result = WERR_BADFID;
9606 goto done;
9609 /* check to see if the keyname is valid */
9610 if (!strlen(r->in.key_name)) {
9611 result = WERR_INVALID_PARAM;
9612 goto done;
9615 /* Is the handle to a printer or to the server? */
9617 if (Printer->printer_type == SPLHND_SERVER) {
9619 union spoolss_PrinterData data;
9621 result = getprinterdata_printer_server(tmp_ctx,
9622 r->in.value_name,
9623 r->out.type,
9624 &data);
9625 if (!W_ERROR_IS_OK(result)) {
9626 goto done;
9629 result = push_spoolss_PrinterData(tmp_ctx, &blob,
9630 *r->out.type, &data);
9631 if (!W_ERROR_IS_OK(result)) {
9632 goto done;
9635 *r->out.needed = blob.length;
9637 if (r->in.offered >= *r->out.needed) {
9638 memcpy(r->out.data, blob.data, blob.length);
9641 result = WERR_OK;
9642 goto done;
9645 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9646 result = WERR_BADFID;
9647 goto done;
9649 printer = lp_const_servicename(snum);
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 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9660 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
9661 strequal(r->in.value_name, "ChangeId")) {
9662 *r->out.type = REG_DWORD;
9663 *r->out.needed = 4;
9664 if (r->in.offered >= *r->out.needed) {
9665 uint32_t changeid = 0;
9667 result = winreg_printer_get_changeid(tmp_ctx, b,
9668 printer,
9669 &changeid);
9670 if (!W_ERROR_IS_OK(result)) {
9671 goto done;
9674 SIVAL(r->out.data, 0, changeid);
9675 result = WERR_OK;
9677 goto done;
9680 result = winreg_get_printer_dataex(tmp_ctx, b,
9681 printer,
9682 r->in.key_name,
9683 r->in.value_name,
9684 &val_type,
9685 &val_data,
9686 &val_size);
9687 if (!W_ERROR_IS_OK(result)) {
9688 goto done;
9691 *r->out.needed = val_size;
9692 *r->out.type = val_type;
9694 if (r->in.offered >= *r->out.needed) {
9695 memcpy(r->out.data, val_data, val_size);
9698 done:
9699 /* NOTE: do not replace type when returning WERR_MORE_DATA */
9701 if (W_ERROR_IS_OK(result)) {
9702 result = SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9705 talloc_free(tmp_ctx);
9706 return result;
9709 /****************************************************************
9710 _spoolss_SetPrinterDataEx
9711 ****************************************************************/
9713 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
9714 struct spoolss_SetPrinterDataEx *r)
9716 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9717 int snum = 0;
9718 WERROR result = WERR_OK;
9719 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9720 char *oid_string;
9721 struct dcerpc_binding_handle *b;
9722 TALLOC_CTX *tmp_ctx;
9724 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9726 /* From MSDN documentation of SetPrinterDataEx: pass request to
9727 SetPrinterData if key is "PrinterDriverData" */
9729 if (!Printer) {
9730 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9731 OUR_HANDLE(r->in.handle)));
9732 return WERR_BADFID;
9735 if (Printer->printer_type == SPLHND_SERVER) {
9736 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9737 "Not implemented for server handles yet\n"));
9738 return WERR_INVALID_PARAM;
9741 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9742 return WERR_BADFID;
9746 * Access check : NT returns "access denied" if you make a
9747 * SetPrinterData call without the necessary privildge.
9748 * we were originally returning OK if nothing changed
9749 * which made Win2k issue **a lot** of SetPrinterData
9750 * when connecting to a printer --jerry
9753 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9754 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9755 "change denied by handle access permissions\n"));
9756 return WERR_ACCESS_DENIED;
9759 tmp_ctx = talloc_new(p->mem_ctx);
9760 if (!tmp_ctx) {
9761 return WERR_NOMEM;
9764 result = winreg_printer_binding_handle(tmp_ctx,
9765 get_session_info_system(),
9766 p->msg_ctx,
9767 &b);
9768 if (!W_ERROR_IS_OK(result)) {
9769 goto done;
9772 result = winreg_get_printer(tmp_ctx, b,
9773 lp_servicename(talloc_tos(), snum),
9774 &pinfo2);
9775 if (!W_ERROR_IS_OK(result)) {
9776 goto done;
9779 /* check for OID in valuename */
9781 oid_string = strchr(r->in.value_name, ',');
9782 if (oid_string) {
9783 *oid_string = '\0';
9784 oid_string++;
9787 /* save the registry data */
9789 result = winreg_set_printer_dataex(tmp_ctx, b,
9790 pinfo2->sharename,
9791 r->in.key_name,
9792 r->in.value_name,
9793 r->in.type,
9794 r->in.data,
9795 r->in.offered);
9797 if (W_ERROR_IS_OK(result)) {
9798 /* save the OID if one was specified */
9799 if (oid_string) {
9800 char *str = talloc_asprintf(tmp_ctx, "%s\\%s",
9801 r->in.key_name, SPOOL_OID_KEY);
9802 if (!str) {
9803 result = WERR_NOMEM;
9804 goto done;
9808 * I'm not checking the status here on purpose. Don't know
9809 * if this is right, but I'm returning the status from the
9810 * previous set_printer_dataex() call. I have no idea if
9811 * this is right. --jerry
9813 winreg_set_printer_dataex(tmp_ctx, b,
9814 pinfo2->sharename,
9815 str,
9816 r->in.value_name,
9817 REG_SZ,
9818 (uint8_t *) oid_string,
9819 strlen(oid_string) + 1);
9822 result = winreg_printer_update_changeid(tmp_ctx, b,
9823 lp_const_servicename(snum));
9827 done:
9828 talloc_free(tmp_ctx);
9829 return result;
9832 /****************************************************************
9833 _spoolss_DeletePrinterDataEx
9834 ****************************************************************/
9836 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
9837 struct spoolss_DeletePrinterDataEx *r)
9839 const char *printer;
9840 int snum=0;
9841 WERROR status = WERR_OK;
9842 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9844 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9846 if (!Printer) {
9847 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9848 "Invalid handle (%s:%u:%u).\n",
9849 OUR_HANDLE(r->in.handle)));
9850 return WERR_BADFID;
9853 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9854 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9855 "printer properties change denied by handle\n"));
9856 return WERR_ACCESS_DENIED;
9859 if (!r->in.value_name || !r->in.key_name) {
9860 return WERR_NOMEM;
9863 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9864 return WERR_BADFID;
9866 printer = lp_const_servicename(snum);
9868 status = winreg_delete_printer_dataex_internal(p->mem_ctx,
9869 get_session_info_system(),
9870 p->msg_ctx,
9871 printer,
9872 r->in.key_name,
9873 r->in.value_name);
9874 if (W_ERROR_IS_OK(status)) {
9875 status = winreg_printer_update_changeid_internal(p->mem_ctx,
9876 get_session_info_system(),
9877 p->msg_ctx,
9878 printer);
9881 return status;
9884 /****************************************************************
9885 _spoolss_EnumPrinterKey
9886 ****************************************************************/
9888 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
9889 struct spoolss_EnumPrinterKey *r)
9891 uint32_t num_keys;
9892 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9893 int snum = 0;
9894 WERROR result = WERR_BADFILE;
9895 const char **array = NULL;
9896 DATA_BLOB blob;
9898 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9900 if (!Printer) {
9901 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9902 OUR_HANDLE(r->in.handle)));
9903 return WERR_BADFID;
9906 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9907 return WERR_BADFID;
9910 result = winreg_enum_printer_key_internal(p->mem_ctx,
9911 get_session_info_system(),
9912 p->msg_ctx,
9913 lp_const_servicename(snum),
9914 r->in.key_name,
9915 &num_keys,
9916 &array);
9917 if (!W_ERROR_IS_OK(result)) {
9918 goto done;
9921 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9922 result = WERR_NOMEM;
9923 goto done;
9926 *r->out._ndr_size = r->in.offered / 2;
9927 *r->out.needed = blob.length;
9929 if (r->in.offered < *r->out.needed) {
9930 result = WERR_MORE_DATA;
9931 } else {
9932 result = WERR_OK;
9933 r->out.key_buffer->string_array = array;
9936 done:
9937 if (!W_ERROR_IS_OK(result)) {
9938 TALLOC_FREE(array);
9939 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9940 *r->out.needed = 0;
9944 return result;
9947 /****************************************************************
9948 _spoolss_DeletePrinterKey
9949 ****************************************************************/
9951 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9952 struct spoolss_DeletePrinterKey *r)
9954 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9955 int snum=0;
9956 WERROR status;
9957 const char *printer;
9958 struct dcerpc_binding_handle *b;
9959 TALLOC_CTX *tmp_ctx;
9961 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9963 if (!Printer) {
9964 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9965 OUR_HANDLE(r->in.handle)));
9966 return WERR_BADFID;
9969 /* if keyname == NULL, return error */
9970 if ( !r->in.key_name )
9971 return WERR_INVALID_PARAM;
9973 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9974 return WERR_BADFID;
9977 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9978 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9979 "printer properties change denied by handle\n"));
9980 return WERR_ACCESS_DENIED;
9983 printer = lp_const_servicename(snum);
9985 tmp_ctx = talloc_new(p->mem_ctx);
9986 if (!tmp_ctx) {
9987 return WERR_NOMEM;
9990 status = winreg_printer_binding_handle(tmp_ctx,
9991 get_session_info_system(),
9992 p->msg_ctx,
9993 &b);
9994 if (!W_ERROR_IS_OK(status)) {
9995 goto done;
9998 /* delete the key and all subkeys */
9999 status = winreg_delete_printer_key(tmp_ctx, b,
10000 printer,
10001 r->in.key_name);
10002 if (W_ERROR_IS_OK(status)) {
10003 status = winreg_printer_update_changeid(tmp_ctx, b,
10004 printer);
10007 done:
10008 talloc_free(tmp_ctx);
10009 return status;
10012 /****************************************************************
10013 _spoolss_EnumPrinterDataEx
10014 ****************************************************************/
10016 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
10017 struct spoolss_EnumPrinterDataEx *r)
10019 uint32_t count = 0;
10020 struct spoolss_PrinterEnumValues *info = NULL;
10021 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
10022 int snum;
10023 WERROR result;
10025 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
10027 *r->out.count = 0;
10028 *r->out.needed = 0;
10029 *r->out.info = NULL;
10031 if (!Printer) {
10032 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
10033 OUR_HANDLE(r->in.handle)));
10034 return WERR_BADFID;
10038 * first check for a keyname of NULL or "". Win2k seems to send
10039 * this a lot and we should send back WERR_INVALID_PARAM
10040 * no need to spend time looking up the printer in this case.
10041 * --jerry
10044 if (!strlen(r->in.key_name)) {
10045 result = WERR_INVALID_PARAM;
10046 goto done;
10049 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
10050 return WERR_BADFID;
10053 /* now look for a match on the key name */
10054 result = winreg_enum_printer_dataex_internal(p->mem_ctx,
10055 get_session_info_system(),
10056 p->msg_ctx,
10057 lp_const_servicename(snum),
10058 r->in.key_name,
10059 &count,
10060 &info);
10061 if (!W_ERROR_IS_OK(result)) {
10062 goto done;
10065 #if 0 /* FIXME - gd */
10066 /* housekeeping information in the reply */
10068 /* Fix from Martin Zielinski <mz@seh.de> - ensure
10069 * the hand marshalled container size is a multiple
10070 * of 4 bytes for RPC alignment.
10073 if (needed % 4) {
10074 needed += 4-(needed % 4);
10076 #endif
10077 *r->out.count = count;
10078 *r->out.info = info;
10080 done:
10081 if (!W_ERROR_IS_OK(result)) {
10082 return result;
10085 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
10086 spoolss_EnumPrinterDataEx,
10087 *r->out.info,
10088 *r->out.count);
10089 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
10090 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
10092 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
10095 /****************************************************************************
10096 ****************************************************************************/
10098 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
10099 const char *servername,
10100 const char *environment,
10101 struct spoolss_PrintProcessorDirectoryInfo1 *r)
10103 WERROR werr;
10104 char *path = NULL;
10106 werr = compose_spoolss_server_path(mem_ctx,
10107 servername,
10108 environment,
10109 SPOOLSS_PRTPROCS_PATH,
10110 &path);
10111 if (!W_ERROR_IS_OK(werr)) {
10112 return werr;
10115 DEBUG(4,("print processor directory: [%s]\n", path));
10117 r->directory_name = path;
10119 return WERR_OK;
10122 /****************************************************************
10123 _spoolss_GetPrintProcessorDirectory
10124 ****************************************************************/
10126 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
10127 struct spoolss_GetPrintProcessorDirectory *r)
10129 WERROR result;
10130 char *prnproc_share = NULL;
10131 bool prnproc_share_exists = false;
10132 int snum;
10134 /* that's an [in out] buffer */
10136 if (!r->in.buffer && (r->in.offered != 0)) {
10137 return WERR_INVALID_PARAM;
10140 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
10141 r->in.level));
10143 *r->out.needed = 0;
10145 /* r->in.level is ignored */
10147 /* We always should reply with a local print processor directory so that
10148 * users are not forced to have a [prnproc$] share on the Samba spoolss
10149 * server, if users decide to do so, lets announce it though - Guenther */
10151 snum = find_service(talloc_tos(), "prnproc$", &prnproc_share);
10152 if (!prnproc_share) {
10153 return WERR_NOMEM;
10155 if (snum != -1) {
10156 prnproc_share_exists = true;
10159 result = getprintprocessordirectory_level_1(p->mem_ctx,
10160 prnproc_share_exists ? r->in.server : NULL,
10161 r->in.environment,
10162 &r->out.info->info1);
10163 if (!W_ERROR_IS_OK(result)) {
10164 TALLOC_FREE(r->out.info);
10165 return result;
10168 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
10169 r->out.info, r->in.level);
10170 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
10172 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
10175 /*******************************************************************
10176 ********************************************************************/
10178 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
10179 const char *dllname)
10181 enum ndr_err_code ndr_err;
10182 struct spoolss_MonitorUi ui;
10184 ui.dll_name = dllname;
10186 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
10187 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
10188 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10189 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
10191 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10194 /*******************************************************************
10195 Streams the monitor UI DLL name in UNICODE
10196 *******************************************************************/
10198 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
10199 struct security_token *token, DATA_BLOB *in,
10200 DATA_BLOB *out, uint32_t *needed)
10202 const char *dllname = "tcpmonui.dll";
10204 *needed = (strlen(dllname)+1) * 2;
10206 if (out->length < *needed) {
10207 return WERR_INSUFFICIENT_BUFFER;
10210 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
10211 return WERR_NOMEM;
10214 return WERR_OK;
10217 /*******************************************************************
10218 ********************************************************************/
10220 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
10221 struct spoolss_PortData1 *port1,
10222 const DATA_BLOB *buf)
10224 enum ndr_err_code ndr_err;
10225 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
10226 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
10227 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10228 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
10230 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10233 /*******************************************************************
10234 ********************************************************************/
10236 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
10237 struct spoolss_PortData2 *port2,
10238 const DATA_BLOB *buf)
10240 enum ndr_err_code ndr_err;
10241 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
10242 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
10243 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10244 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
10246 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10249 /*******************************************************************
10250 Create a new TCP/IP port
10251 *******************************************************************/
10253 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
10254 struct security_token *token, DATA_BLOB *in,
10255 DATA_BLOB *out, uint32_t *needed)
10257 struct spoolss_PortData1 port1;
10258 struct spoolss_PortData2 port2;
10259 char *device_uri = NULL;
10260 uint32_t version;
10262 const char *portname;
10263 const char *hostaddress;
10264 const char *queue;
10265 uint32_t port_number;
10266 uint32_t protocol;
10268 /* peek for spoolss_PortData version */
10270 if (!in || (in->length < (128 + 4))) {
10271 return WERR_GENERAL_FAILURE;
10274 version = IVAL(in->data, 128);
10276 switch (version) {
10277 case 1:
10278 ZERO_STRUCT(port1);
10280 if (!pull_port_data_1(mem_ctx, &port1, in)) {
10281 return WERR_NOMEM;
10284 portname = port1.portname;
10285 hostaddress = port1.hostaddress;
10286 queue = port1.queue;
10287 protocol = port1.protocol;
10288 port_number = port1.port_number;
10290 break;
10291 case 2:
10292 ZERO_STRUCT(port2);
10294 if (!pull_port_data_2(mem_ctx, &port2, in)) {
10295 return WERR_NOMEM;
10298 portname = port2.portname;
10299 hostaddress = port2.hostaddress;
10300 queue = port2.queue;
10301 protocol = port2.protocol;
10302 port_number = port2.port_number;
10304 break;
10305 default:
10306 DEBUG(1,("xcvtcp_addport: "
10307 "unknown version of port_data: %d\n", version));
10308 return WERR_UNKNOWN_PORT;
10311 /* create the device URI and call the add_port_hook() */
10313 switch (protocol) {
10314 case PROTOCOL_RAWTCP_TYPE:
10315 device_uri = talloc_asprintf(mem_ctx,
10316 "socket://%s:%d/", hostaddress,
10317 port_number);
10318 break;
10320 case PROTOCOL_LPR_TYPE:
10321 device_uri = talloc_asprintf(mem_ctx,
10322 "lpr://%s/%s", hostaddress, queue );
10323 break;
10325 default:
10326 return WERR_UNKNOWN_PORT;
10329 if (!device_uri) {
10330 return WERR_NOMEM;
10333 return add_port_hook(mem_ctx, token, portname, device_uri);
10336 /*******************************************************************
10337 *******************************************************************/
10339 struct xcv_api_table xcvtcp_cmds[] = {
10340 { "MonitorUI", xcvtcp_monitorui },
10341 { "AddPort", xcvtcp_addport},
10342 { NULL, NULL }
10345 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
10346 struct security_token *token, const char *command,
10347 DATA_BLOB *inbuf,
10348 DATA_BLOB *outbuf,
10349 uint32_t *needed )
10351 int i;
10353 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
10355 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
10356 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
10357 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
10360 return WERR_BADFUNC;
10363 /*******************************************************************
10364 *******************************************************************/
10365 #if 0 /* don't support management using the "Local Port" monitor */
10367 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
10368 struct security_token *token, DATA_BLOB *in,
10369 DATA_BLOB *out, uint32_t *needed)
10371 const char *dllname = "localui.dll";
10373 *needed = (strlen(dllname)+1) * 2;
10375 if (out->length < *needed) {
10376 return WERR_INSUFFICIENT_BUFFER;
10379 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
10380 return WERR_NOMEM;
10383 return WERR_OK;
10386 /*******************************************************************
10387 *******************************************************************/
10389 struct xcv_api_table xcvlocal_cmds[] = {
10390 { "MonitorUI", xcvlocal_monitorui },
10391 { NULL, NULL }
10393 #else
10394 struct xcv_api_table xcvlocal_cmds[] = {
10395 { NULL, NULL }
10397 #endif
10401 /*******************************************************************
10402 *******************************************************************/
10404 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
10405 struct security_token *token, const char *command,
10406 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
10407 uint32_t *needed)
10409 int i;
10411 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
10413 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
10414 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
10415 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
10417 return WERR_BADFUNC;
10420 /****************************************************************
10421 _spoolss_XcvData
10422 ****************************************************************/
10424 WERROR _spoolss_XcvData(struct pipes_struct *p,
10425 struct spoolss_XcvData *r)
10427 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
10428 DATA_BLOB out_data = data_blob_null;
10429 WERROR werror;
10431 if (!Printer) {
10432 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
10433 OUR_HANDLE(r->in.handle)));
10434 return WERR_BADFID;
10437 /* Has to be a handle to the TCP/IP port monitor */
10439 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
10440 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
10441 return WERR_BADFID;
10444 /* requires administrative access to the server */
10446 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
10447 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
10448 return WERR_ACCESS_DENIED;
10451 /* Allocate the outgoing buffer */
10453 if (r->in.out_data_size) {
10454 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
10455 if (out_data.data == NULL) {
10456 return WERR_NOMEM;
10460 switch ( Printer->printer_type ) {
10461 case SPLHND_PORTMON_TCP:
10462 werror = process_xcvtcp_command(p->mem_ctx,
10463 p->session_info->security_token,
10464 r->in.function_name,
10465 &r->in.in_data, &out_data,
10466 r->out.needed);
10467 break;
10468 case SPLHND_PORTMON_LOCAL:
10469 werror = process_xcvlocal_command(p->mem_ctx,
10470 p->session_info->security_token,
10471 r->in.function_name,
10472 &r->in.in_data, &out_data,
10473 r->out.needed);
10474 break;
10475 default:
10476 werror = WERR_INVALID_PRINT_MONITOR;
10479 if (!W_ERROR_IS_OK(werror)) {
10480 return werror;
10483 *r->out.status_code = 0;
10485 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
10486 memcpy(r->out.out_data, out_data.data,
10487 MIN(r->in.out_data_size, out_data.length));
10490 return WERR_OK;
10493 /****************************************************************
10494 _spoolss_AddPrintProcessor
10495 ****************************************************************/
10497 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
10498 struct spoolss_AddPrintProcessor *r)
10500 /* for now, just indicate success and ignore the add. We'll
10501 automatically set the winprint processor for printer
10502 entries later. Used to debug the LexMark Optra S 1855 PCL
10503 driver --jerry */
10505 return WERR_OK;
10508 /****************************************************************
10509 _spoolss_AddPort
10510 ****************************************************************/
10512 WERROR _spoolss_AddPort(struct pipes_struct *p,
10513 struct spoolss_AddPort *r)
10515 /* do what w2k3 does */
10517 return WERR_NOT_SUPPORTED;
10520 /****************************************************************
10521 _spoolss_GetPrinterDriver
10522 ****************************************************************/
10524 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
10525 struct spoolss_GetPrinterDriver *r)
10527 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10528 return WERR_NOT_SUPPORTED;
10531 /****************************************************************
10532 _spoolss_ReadPrinter
10533 ****************************************************************/
10535 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
10536 struct spoolss_ReadPrinter *r)
10538 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10539 return WERR_NOT_SUPPORTED;
10542 /****************************************************************
10543 _spoolss_WaitForPrinterChange
10544 ****************************************************************/
10546 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
10547 struct spoolss_WaitForPrinterChange *r)
10549 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10550 return WERR_NOT_SUPPORTED;
10553 /****************************************************************
10554 _spoolss_ConfigurePort
10555 ****************************************************************/
10557 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
10558 struct spoolss_ConfigurePort *r)
10560 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10561 return WERR_NOT_SUPPORTED;
10564 /****************************************************************
10565 _spoolss_DeletePort
10566 ****************************************************************/
10568 WERROR _spoolss_DeletePort(struct pipes_struct *p,
10569 struct spoolss_DeletePort *r)
10571 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10572 return WERR_NOT_SUPPORTED;
10575 /****************************************************************
10576 _spoolss_CreatePrinterIC
10577 ****************************************************************/
10579 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
10580 struct spoolss_CreatePrinterIC *r)
10582 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10583 return WERR_NOT_SUPPORTED;
10586 /****************************************************************
10587 _spoolss_PlayGDIScriptOnPrinterIC
10588 ****************************************************************/
10590 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
10591 struct spoolss_PlayGDIScriptOnPrinterIC *r)
10593 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10594 return WERR_NOT_SUPPORTED;
10597 /****************************************************************
10598 _spoolss_DeletePrinterIC
10599 ****************************************************************/
10601 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
10602 struct spoolss_DeletePrinterIC *r)
10604 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10605 return WERR_NOT_SUPPORTED;
10608 /****************************************************************
10609 _spoolss_AddPrinterConnection
10610 ****************************************************************/
10612 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
10613 struct spoolss_AddPrinterConnection *r)
10615 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10616 return WERR_NOT_SUPPORTED;
10619 /****************************************************************
10620 _spoolss_DeletePrinterConnection
10621 ****************************************************************/
10623 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
10624 struct spoolss_DeletePrinterConnection *r)
10626 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10627 return WERR_NOT_SUPPORTED;
10630 /****************************************************************
10631 _spoolss_PrinterMessageBox
10632 ****************************************************************/
10634 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
10635 struct spoolss_PrinterMessageBox *r)
10637 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10638 return WERR_NOT_SUPPORTED;
10641 /****************************************************************
10642 _spoolss_AddMonitor
10643 ****************************************************************/
10645 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
10646 struct spoolss_AddMonitor *r)
10648 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10649 return WERR_NOT_SUPPORTED;
10652 /****************************************************************
10653 _spoolss_DeleteMonitor
10654 ****************************************************************/
10656 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
10657 struct spoolss_DeleteMonitor *r)
10659 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10660 return WERR_NOT_SUPPORTED;
10663 /****************************************************************
10664 _spoolss_DeletePrintProcessor
10665 ****************************************************************/
10667 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
10668 struct spoolss_DeletePrintProcessor *r)
10670 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10671 return WERR_NOT_SUPPORTED;
10674 /****************************************************************
10675 _spoolss_AddPrintProvidor
10676 ****************************************************************/
10678 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
10679 struct spoolss_AddPrintProvidor *r)
10681 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10682 return WERR_NOT_SUPPORTED;
10685 /****************************************************************
10686 _spoolss_DeletePrintProvidor
10687 ****************************************************************/
10689 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
10690 struct spoolss_DeletePrintProvidor *r)
10692 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10693 return WERR_NOT_SUPPORTED;
10696 /****************************************************************
10697 _spoolss_FindFirstPrinterChangeNotification
10698 ****************************************************************/
10700 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
10701 struct spoolss_FindFirstPrinterChangeNotification *r)
10703 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10704 return WERR_NOT_SUPPORTED;
10707 /****************************************************************
10708 _spoolss_FindNextPrinterChangeNotification
10709 ****************************************************************/
10711 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
10712 struct spoolss_FindNextPrinterChangeNotification *r)
10714 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10715 return WERR_NOT_SUPPORTED;
10718 /****************************************************************
10719 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10720 ****************************************************************/
10722 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
10723 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10725 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10726 return WERR_NOT_SUPPORTED;
10729 /****************************************************************
10730 _spoolss_ReplyOpenPrinter
10731 ****************************************************************/
10733 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
10734 struct spoolss_ReplyOpenPrinter *r)
10736 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10737 return WERR_NOT_SUPPORTED;
10740 /****************************************************************
10741 _spoolss_RouterReplyPrinter
10742 ****************************************************************/
10744 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
10745 struct spoolss_RouterReplyPrinter *r)
10747 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10748 return WERR_NOT_SUPPORTED;
10751 /****************************************************************
10752 _spoolss_ReplyClosePrinter
10753 ****************************************************************/
10755 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
10756 struct spoolss_ReplyClosePrinter *r)
10758 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10759 return WERR_NOT_SUPPORTED;
10762 /****************************************************************
10763 _spoolss_AddPortEx
10764 ****************************************************************/
10766 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
10767 struct spoolss_AddPortEx *r)
10769 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10770 return WERR_NOT_SUPPORTED;
10773 /****************************************************************
10774 _spoolss_RouterFindFirstPrinterChangeNotification
10775 ****************************************************************/
10777 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
10778 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10780 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10781 return WERR_NOT_SUPPORTED;
10784 /****************************************************************
10785 _spoolss_SpoolerInit
10786 ****************************************************************/
10788 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
10789 struct spoolss_SpoolerInit *r)
10791 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10792 return WERR_NOT_SUPPORTED;
10795 /****************************************************************
10796 _spoolss_ResetPrinterEx
10797 ****************************************************************/
10799 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
10800 struct spoolss_ResetPrinterEx *r)
10802 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10803 return WERR_NOT_SUPPORTED;
10806 /****************************************************************
10807 _spoolss_RouterReplyPrinterEx
10808 ****************************************************************/
10810 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
10811 struct spoolss_RouterReplyPrinterEx *r)
10813 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10814 return WERR_NOT_SUPPORTED;
10817 /****************************************************************
10818 _spoolss_44
10819 ****************************************************************/
10821 WERROR _spoolss_44(struct pipes_struct *p,
10822 struct spoolss_44 *r)
10824 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10825 return WERR_NOT_SUPPORTED;
10828 /****************************************************************
10829 _spoolss_SetPort
10830 ****************************************************************/
10832 WERROR _spoolss_SetPort(struct pipes_struct *p,
10833 struct spoolss_SetPort *r)
10835 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10836 return WERR_NOT_SUPPORTED;
10839 /****************************************************************
10840 _spoolss_4a
10841 ****************************************************************/
10843 WERROR _spoolss_4a(struct pipes_struct *p,
10844 struct spoolss_4a *r)
10846 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10847 return WERR_NOT_SUPPORTED;
10850 /****************************************************************
10851 _spoolss_4b
10852 ****************************************************************/
10854 WERROR _spoolss_4b(struct pipes_struct *p,
10855 struct spoolss_4b *r)
10857 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10858 return WERR_NOT_SUPPORTED;
10861 /****************************************************************
10862 _spoolss_4c
10863 ****************************************************************/
10865 WERROR _spoolss_4c(struct pipes_struct *p,
10866 struct spoolss_4c *r)
10868 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10869 return WERR_NOT_SUPPORTED;
10872 /****************************************************************
10873 _spoolss_53
10874 ****************************************************************/
10876 WERROR _spoolss_53(struct pipes_struct *p,
10877 struct spoolss_53 *r)
10879 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10880 return WERR_NOT_SUPPORTED;
10883 /****************************************************************
10884 _spoolss_AddPerMachineConnection
10885 ****************************************************************/
10887 WERROR _spoolss_AddPerMachineConnection(struct pipes_struct *p,
10888 struct spoolss_AddPerMachineConnection *r)
10890 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10891 return WERR_NOT_SUPPORTED;
10894 /****************************************************************
10895 _spoolss_DeletePerMachineConnection
10896 ****************************************************************/
10898 WERROR _spoolss_DeletePerMachineConnection(struct pipes_struct *p,
10899 struct spoolss_DeletePerMachineConnection *r)
10901 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10902 return WERR_NOT_SUPPORTED;
10905 /****************************************************************
10906 _spoolss_EnumPerMachineConnections
10907 ****************************************************************/
10909 WERROR _spoolss_EnumPerMachineConnections(struct pipes_struct *p,
10910 struct spoolss_EnumPerMachineConnections *r)
10912 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10913 return WERR_NOT_SUPPORTED;
10916 /****************************************************************
10917 _spoolss_5a
10918 ****************************************************************/
10920 WERROR _spoolss_5a(struct pipes_struct *p,
10921 struct spoolss_5a *r)
10923 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10924 return WERR_NOT_SUPPORTED;
10927 /****************************************************************
10928 _spoolss_5b
10929 ****************************************************************/
10931 WERROR _spoolss_5b(struct pipes_struct *p,
10932 struct spoolss_5b *r)
10934 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10935 return WERR_NOT_SUPPORTED;
10938 /****************************************************************
10939 _spoolss_5c
10940 ****************************************************************/
10942 WERROR _spoolss_5c(struct pipes_struct *p,
10943 struct spoolss_5c *r)
10945 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10946 return WERR_NOT_SUPPORTED;
10949 /****************************************************************
10950 _spoolss_5d
10951 ****************************************************************/
10953 WERROR _spoolss_5d(struct pipes_struct *p,
10954 struct spoolss_5d *r)
10956 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10957 return WERR_NOT_SUPPORTED;
10960 /****************************************************************
10961 _spoolss_5e
10962 ****************************************************************/
10964 WERROR _spoolss_5e(struct pipes_struct *p,
10965 struct spoolss_5e *r)
10967 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10968 return WERR_NOT_SUPPORTED;
10971 /****************************************************************
10972 _spoolss_5f
10973 ****************************************************************/
10975 WERROR _spoolss_5f(struct pipes_struct *p,
10976 struct spoolss_5f *r)
10978 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10979 return WERR_NOT_SUPPORTED;
10982 /****************************************************************
10983 _spoolss_60
10984 ****************************************************************/
10986 WERROR _spoolss_60(struct pipes_struct *p,
10987 struct spoolss_60 *r)
10989 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
10990 return WERR_NOT_SUPPORTED;
10993 /****************************************************************
10994 _spoolss_RpcSendRecvBidiData
10995 ****************************************************************/
10997 WERROR _spoolss_RpcSendRecvBidiData(struct pipes_struct *p,
10998 struct spoolss_RpcSendRecvBidiData *r)
11000 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11001 return WERR_NOT_SUPPORTED;
11004 /****************************************************************
11005 _spoolss_62
11006 ****************************************************************/
11008 WERROR _spoolss_62(struct pipes_struct *p,
11009 struct spoolss_62 *r)
11011 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11012 return WERR_NOT_SUPPORTED;
11015 /****************************************************************
11016 _spoolss_63
11017 ****************************************************************/
11019 WERROR _spoolss_63(struct pipes_struct *p,
11020 struct spoolss_63 *r)
11022 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11023 return WERR_NOT_SUPPORTED;
11026 /****************************************************************
11027 _spoolss_64
11028 ****************************************************************/
11030 WERROR _spoolss_64(struct pipes_struct *p,
11031 struct spoolss_64 *r)
11033 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11034 return WERR_NOT_SUPPORTED;
11037 /****************************************************************
11038 _spoolss_65
11039 ****************************************************************/
11041 WERROR _spoolss_65(struct pipes_struct *p,
11042 struct spoolss_65 *r)
11044 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11045 return WERR_NOT_SUPPORTED;
11048 /****************************************************************
11049 _spoolss_GetCorePrinterDrivers
11050 ****************************************************************/
11052 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
11053 struct spoolss_GetCorePrinterDrivers *r)
11055 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11056 return WERR_NOT_SUPPORTED;
11059 /****************************************************************
11060 _spoolss_67
11061 ****************************************************************/
11063 WERROR _spoolss_67(struct pipes_struct *p,
11064 struct spoolss_67 *r)
11066 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11067 return WERR_NOT_SUPPORTED;
11070 /****************************************************************
11071 _spoolss_GetPrinterDriverPackagePath
11072 ****************************************************************/
11074 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
11075 struct spoolss_GetPrinterDriverPackagePath *r)
11077 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11078 return WERR_NOT_SUPPORTED;
11081 /****************************************************************
11082 _spoolss_69
11083 ****************************************************************/
11085 WERROR _spoolss_69(struct pipes_struct *p,
11086 struct spoolss_69 *r)
11088 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11089 return WERR_NOT_SUPPORTED;
11092 /****************************************************************
11093 _spoolss_6a
11094 ****************************************************************/
11096 WERROR _spoolss_6a(struct pipes_struct *p,
11097 struct spoolss_6a *r)
11099 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11100 return WERR_NOT_SUPPORTED;
11103 /****************************************************************
11104 _spoolss_6b
11105 ****************************************************************/
11107 WERROR _spoolss_6b(struct pipes_struct *p,
11108 struct spoolss_6b *r)
11110 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11111 return WERR_NOT_SUPPORTED;
11114 /****************************************************************
11115 _spoolss_6c
11116 ****************************************************************/
11118 WERROR _spoolss_6c(struct pipes_struct *p,
11119 struct spoolss_6c *r)
11121 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11122 return WERR_NOT_SUPPORTED;
11125 /****************************************************************
11126 _spoolss_6d
11127 ****************************************************************/
11129 WERROR _spoolss_6d(struct pipes_struct *p,
11130 struct spoolss_6d *r)
11132 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11133 return WERR_NOT_SUPPORTED;
11136 /****************************************************************
11137 _spoolss_RpcGetJobNamedPropertyValue
11138 ****************************************************************/
11140 WERROR _spoolss_RpcGetJobNamedPropertyValue(struct pipes_struct *p,
11141 struct spoolss_RpcGetJobNamedPropertyValue *r)
11143 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11144 return WERR_NOT_SUPPORTED;
11147 /****************************************************************
11148 _spoolss_RpcSetJobNamedProperty
11149 ****************************************************************/
11151 WERROR _spoolss_RpcSetJobNamedProperty(struct pipes_struct *p,
11152 struct spoolss_RpcSetJobNamedProperty *r)
11154 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11155 return WERR_NOT_SUPPORTED;
11158 /****************************************************************
11159 _spoolss_RpcDeleteJobNamedProperty
11160 ****************************************************************/
11162 WERROR _spoolss_RpcDeleteJobNamedProperty(struct pipes_struct *p,
11163 struct spoolss_RpcDeleteJobNamedProperty *r)
11165 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11166 return WERR_NOT_SUPPORTED;
11169 /****************************************************************
11170 _spoolss_RpcEnumJobNamedProperties
11171 ****************************************************************/
11173 WERROR _spoolss_RpcEnumJobNamedProperties(struct pipes_struct *p,
11174 struct spoolss_RpcEnumJobNamedProperties *r)
11176 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
11177 return WERR_NOT_SUPPORTED;