s3-spoolss: fix spoolss GetPrinterData behaviour
[Samba/gebeck_regimport.git] / source3 / rpc_server / srv_spoolss_nt.c
blobc0f953bdf4ee6c8799aa299214d8f4a2683fadde
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Jeremy Allison 2001-2002,
8 * Copyright (C) Gerald Carter 2000-2004,
9 * Copyright (C) Tim Potter 2001-2002.
10 * Copyright (C) Guenther Deschner 2009-2010.
11 * Copyright (C) Andreas Schneider 2010.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
28 up, all the errors returned are DOS errors, not NT status codes. */
30 #include "includes.h"
31 #include "nt_printing.h"
32 #include "srv_spoolss_util.h"
33 #include "../librpc/gen_ndr/srv_spoolss.h"
34 #include "../librpc/gen_ndr/cli_spoolss.h"
35 #include "rpc_client/init_spoolss.h"
36 #include "librpc/gen_ndr/messaging.h"
37 #include "../libcli/security/security.h"
38 #include "librpc/gen_ndr/ndr_security.h"
39 #include "registry.h"
40 #include "registry/reg_objects.h"
41 #include "include/printing.h"
42 #include "secrets.h"
43 #include "../librpc/gen_ndr/netlogon.h"
44 #include "rpc_misc.h"
46 /* macros stolen from s4 spoolss server */
47 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
48 ((info)?ndr_size_##fn(info, level, 0):0)
50 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
51 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
53 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
54 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
56 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
58 #undef DBGC_CLASS
59 #define DBGC_CLASS DBGC_RPC_SRV
61 #ifndef MAX_OPEN_PRINTER_EXS
62 #define MAX_OPEN_PRINTER_EXS 50
63 #endif
65 struct notify_back_channel;
67 /* structure to store the printer handles */
68 /* and a reference to what it's pointing to */
69 /* and the notify info asked about */
70 /* that's the central struct */
71 struct printer_handle {
72 struct printer_handle *prev, *next;
73 bool document_started;
74 bool page_started;
75 uint32 jobid; /* jobid in printing backend */
76 int printer_type;
77 const char *servername;
78 fstring sharename;
79 uint32 type;
80 uint32 access_granted;
81 struct {
82 uint32 flags;
83 uint32 options;
84 fstring localmachine;
85 uint32 printerlocal;
86 struct spoolss_NotifyOption *option;
87 struct policy_handle cli_hnd;
88 struct notify_back_channel *cli_chan;
89 uint32 change;
90 /* are we in a FindNextPrinterChangeNotify() call? */
91 bool fnpcn;
92 struct messaging_context *msg_ctx;
93 } notify;
94 struct {
95 fstring machine;
96 fstring user;
97 } client;
99 /* devmode sent in the OpenPrinter() call */
100 struct spoolss_DeviceMode *devmode;
102 /* TODO cache the printer info2 structure */
103 struct spoolss_PrinterInfo2 *info2;
107 static struct printer_handle *printers_list;
109 struct printer_session_counter {
110 struct printer_session_counter *next;
111 struct printer_session_counter *prev;
113 int snum;
114 uint32_t counter;
117 static struct printer_session_counter *counter_list;
119 struct notify_back_channel {
120 struct notify_back_channel *prev, *next;
122 /* associated client */
123 struct sockaddr_storage client_address;
125 /* print notify back-channel pipe handle*/
126 struct rpc_pipe_client *cli_pipe;
127 uint32_t active_connections;
130 static struct notify_back_channel *back_channels;
132 /* Map generic permissions to printer object specific permissions */
134 const struct standard_mapping printer_std_mapping = {
135 PRINTER_READ,
136 PRINTER_WRITE,
137 PRINTER_EXECUTE,
138 PRINTER_ALL_ACCESS
141 /* Map generic permissions to print server object specific permissions */
143 const struct standard_mapping printserver_std_mapping = {
144 SERVER_READ,
145 SERVER_WRITE,
146 SERVER_EXECUTE,
147 SERVER_ALL_ACCESS
150 /* API table for Xcv Monitor functions */
152 struct xcv_api_table {
153 const char *name;
154 WERROR(*fn) (TALLOC_CTX *mem_ctx, struct security_token *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
157 static void prune_printername_cache(void);
159 /********************************************************************
160 * Canonicalize servername.
161 ********************************************************************/
163 static const char *canon_servername(const char *servername)
165 const char *pservername = servername;
166 while (*pservername == '\\') {
167 pservername++;
169 return pservername;
172 /* translate between internal status numbers and NT status numbers */
173 static int nt_printj_status(int v)
175 switch (v) {
176 case LPQ_QUEUED:
177 return 0;
178 case LPQ_PAUSED:
179 return JOB_STATUS_PAUSED;
180 case LPQ_SPOOLING:
181 return JOB_STATUS_SPOOLING;
182 case LPQ_PRINTING:
183 return JOB_STATUS_PRINTING;
184 case LPQ_ERROR:
185 return JOB_STATUS_ERROR;
186 case LPQ_DELETING:
187 return JOB_STATUS_DELETING;
188 case LPQ_OFFLINE:
189 return JOB_STATUS_OFFLINE;
190 case LPQ_PAPEROUT:
191 return JOB_STATUS_PAPEROUT;
192 case LPQ_PRINTED:
193 return JOB_STATUS_PRINTED;
194 case LPQ_DELETED:
195 return JOB_STATUS_DELETED;
196 case LPQ_BLOCKED:
197 return JOB_STATUS_BLOCKED_DEVQ;
198 case LPQ_USER_INTERVENTION:
199 return JOB_STATUS_USER_INTERVENTION;
201 return 0;
204 static int nt_printq_status(int v)
206 switch (v) {
207 case LPQ_PAUSED:
208 return PRINTER_STATUS_PAUSED;
209 case LPQ_QUEUED:
210 case LPQ_SPOOLING:
211 case LPQ_PRINTING:
212 return 0;
214 return 0;
217 /***************************************************************************
218 Disconnect from the client
219 ****************************************************************************/
221 static void srv_spoolss_replycloseprinter(int snum,
222 struct printer_handle *prn_hnd)
224 WERROR result;
225 NTSTATUS status;
228 * Tell the specific printing tdb we no longer want messages for this printer
229 * by deregistering our PID.
232 if (!print_notify_deregister_pid(snum)) {
233 DEBUG(0, ("Failed to register our pid for printer %s\n",
234 lp_const_servicename(snum)));
237 /* weird if the test succeeds !!! */
238 if (prn_hnd->notify.cli_chan == NULL ||
239 prn_hnd->notify.cli_chan->active_connections == 0) {
240 DEBUG(0, ("Trying to close unexisting backchannel!\n"));
241 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
242 TALLOC_FREE(prn_hnd->notify.cli_chan);
243 return;
246 status = rpccli_spoolss_ReplyClosePrinter(
247 prn_hnd->notify.cli_chan->cli_pipe,
248 talloc_tos(),
249 &prn_hnd->notify.cli_hnd,
250 &result);
251 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
252 DEBUG(0, ("reply_close_printer failed [%s].\n",
253 win_errstr(result)));
256 /* if it's the last connection, deconnect the IPC$ share */
257 if (prn_hnd->notify.cli_chan->active_connections == 1) {
259 cli_shutdown(rpc_pipe_np_smb_conn(prn_hnd->notify.cli_chan->cli_pipe));
260 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
261 TALLOC_FREE(prn_hnd->notify.cli_chan);
263 if (prn_hnd->notify.msg_ctx != NULL) {
264 messaging_deregister(prn_hnd->notify.msg_ctx,
265 MSG_PRINTER_NOTIFY2, NULL);
268 * Tell the serverid.tdb we're no longer
269 * interested in printer notify messages.
272 serverid_register_msg_flags(
273 messaging_server_id(prn_hnd->notify.msg_ctx),
274 false, FLAG_MSG_PRINT_NOTIFY);
278 if (prn_hnd->notify.cli_chan) {
279 prn_hnd->notify.cli_chan->active_connections--;
283 /****************************************************************************
284 Functions to free a printer entry datastruct.
285 ****************************************************************************/
287 static int printer_entry_destructor(struct printer_handle *Printer)
289 if (Printer->notify.cli_chan != NULL &&
290 Printer->notify.cli_chan->active_connections > 0) {
291 int snum = -1;
293 switch(Printer->printer_type) {
294 case SPLHND_SERVER:
295 srv_spoolss_replycloseprinter(snum, Printer);
296 break;
298 case SPLHND_PRINTER:
299 snum = print_queue_snum(Printer->sharename);
300 if (snum != -1) {
301 srv_spoolss_replycloseprinter(snum, Printer);
303 break;
304 default:
305 break;
309 Printer->notify.flags=0;
310 Printer->notify.options=0;
311 Printer->notify.localmachine[0]='\0';
312 Printer->notify.printerlocal=0;
313 TALLOC_FREE(Printer->notify.option);
314 TALLOC_FREE(Printer->devmode);
316 /* Remove from the internal list. */
317 DLIST_REMOVE(printers_list, Printer);
318 return 0;
321 /****************************************************************************
322 find printer index by handle
323 ****************************************************************************/
325 static struct printer_handle *find_printer_index_by_hnd(struct pipes_struct *p,
326 struct policy_handle *hnd)
328 struct printer_handle *find_printer = NULL;
330 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
331 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
332 return NULL;
335 return find_printer;
338 /****************************************************************************
339 Close printer index by handle.
340 ****************************************************************************/
342 static bool close_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
344 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
346 if (!Printer) {
347 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
348 OUR_HANDLE(hnd)));
349 return false;
352 close_policy_hnd(p, hnd);
354 return true;
357 /****************************************************************************
358 Delete a printer given a handle.
359 ****************************************************************************/
361 static WERROR delete_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
362 const char *sharename,
363 struct messaging_context *msg_ctx)
365 char *cmd = lp_deleteprinter_cmd();
366 char *command = NULL;
367 int ret;
368 bool is_print_op = false;
370 /* can't fail if we don't try */
372 if ( !*cmd )
373 return WERR_OK;
375 command = talloc_asprintf(ctx,
376 "%s \"%s\"",
377 cmd, sharename);
378 if (!command) {
379 return WERR_NOMEM;
381 if ( token )
382 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
384 DEBUG(10,("Running [%s]\n", command));
386 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
388 if ( is_print_op )
389 become_root();
391 if ( (ret = smbrun(command, NULL)) == 0 ) {
392 /* Tell everyone we updated smb.conf. */
393 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
396 if ( is_print_op )
397 unbecome_root();
399 /********** END SePrintOperatorPrivlege BLOCK **********/
401 DEBUGADD(10,("returned [%d]\n", ret));
403 TALLOC_FREE(command);
405 if (ret != 0)
406 return WERR_BADFID; /* What to return here? */
408 /* go ahead and re-read the services immediately */
409 become_root();
410 reload_services(msg_ctx, -1, false);
411 unbecome_root();
413 if ( lp_servicenumber( sharename ) >= 0 )
414 return WERR_ACCESS_DENIED;
416 return WERR_OK;
419 /****************************************************************************
420 Delete a printer given a handle.
421 ****************************************************************************/
423 static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
425 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
426 WERROR result;
428 if (!Printer) {
429 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
430 OUR_HANDLE(hnd)));
431 return WERR_BADFID;
435 * It turns out that Windows allows delete printer on a handle
436 * opened by an admin user, then used on a pipe handle created
437 * by an anonymous user..... but they're working on security.... riiight !
438 * JRA.
441 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
442 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
443 return WERR_ACCESS_DENIED;
446 /* this does not need a become root since the access check has been
447 done on the handle already */
449 result = winreg_delete_printer_key(p->mem_ctx,
450 get_server_info_system(),
451 p->msg_ctx,
452 Printer->sharename,
453 "");
454 if (!W_ERROR_IS_OK(result)) {
455 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
456 return WERR_BADFID;
459 result = delete_printer_hook(p->mem_ctx, p->server_info->ptok,
460 Printer->sharename, p->msg_ctx);
461 if (!W_ERROR_IS_OK(result)) {
462 return result;
464 prune_printername_cache();
465 return WERR_OK;
468 /****************************************************************************
469 Return the snum of a printer corresponding to an handle.
470 ****************************************************************************/
472 static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
473 int *number, struct share_params **params)
475 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
477 if (!Printer) {
478 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
479 OUR_HANDLE(hnd)));
480 return false;
483 switch (Printer->printer_type) {
484 case SPLHND_PRINTER:
485 DEBUG(4,("short name:%s\n", Printer->sharename));
486 *number = print_queue_snum(Printer->sharename);
487 return (*number != -1);
488 case SPLHND_SERVER:
489 return false;
490 default:
491 return false;
495 /****************************************************************************
496 Set printer handle type.
497 Check if it's \\server or \\server\printer
498 ****************************************************************************/
500 static bool set_printer_hnd_printertype(struct printer_handle *Printer, const char *handlename)
502 DEBUG(3,("Setting printer type=%s\n", handlename));
504 /* it's a print server */
505 if (handlename && *handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
506 DEBUGADD(4,("Printer is a print server\n"));
507 Printer->printer_type = SPLHND_SERVER;
509 /* it's a printer (set_printer_hnd_name() will handle port monitors */
510 else {
511 DEBUGADD(4,("Printer is a printer\n"));
512 Printer->printer_type = SPLHND_PRINTER;
515 return true;
518 static void prune_printername_cache_fn(const char *key, const char *value,
519 time_t timeout, void *private_data)
521 gencache_del(key);
524 static void prune_printername_cache(void)
526 gencache_iterate(prune_printername_cache_fn, NULL, "PRINTERNAME/*");
529 /****************************************************************************
530 Set printer handle name.. Accept names like \\server, \\server\printer,
531 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
532 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
533 XcvDataPort() interface.
534 ****************************************************************************/
536 static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
537 const struct auth_serversupplied_info *server_info,
538 struct messaging_context *msg_ctx,
539 struct printer_handle *Printer,
540 const char *handlename)
542 int snum;
543 int n_services=lp_numservices();
544 char *aprinter;
545 const char *printername;
546 const char *servername = NULL;
547 fstring sname;
548 bool found = false;
549 struct spoolss_PrinterInfo2 *info2 = NULL;
550 WERROR result;
551 char *p;
554 * Hopefully nobody names his printers like this. Maybe \ or ,
555 * are illegal in printer names even?
557 const char printer_not_found[] = "Printer \\, !@#$%^&*( not found";
558 char *cache_key;
559 char *tmp;
561 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
562 (unsigned long)strlen(handlename)));
564 aprinter = CONST_DISCARD(char *, handlename);
565 if ( *handlename == '\\' ) {
566 servername = canon_servername(handlename);
567 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
568 *aprinter = '\0';
569 aprinter++;
571 if (!is_myname_or_ipaddr(servername)) {
572 return WERR_INVALID_PRINTER_NAME;
574 Printer->servername = talloc_asprintf(Printer, "\\\\%s", servername);
575 if (Printer->servername == NULL) {
576 return WERR_NOMEM;
580 if (Printer->printer_type == SPLHND_SERVER) {
581 return WERR_OK;
584 if (Printer->printer_type != SPLHND_PRINTER) {
585 return WERR_INVALID_HANDLE;
588 DEBUGADD(5, ("searching for [%s]\n", aprinter));
590 p = strchr(aprinter, ',');
591 if (p != NULL) {
592 char *p2 = p;
593 p++;
594 if (*p == ' ') {
595 p++;
597 if (strncmp(p, "DrvConvert", strlen("DrvConvert")) == 0) {
598 *p2 = '\0';
599 } else if (strncmp(p, "LocalOnly", strlen("LocalOnly")) == 0) {
600 *p2 = '\0';
604 if (p) {
605 DEBUGADD(5, ("stripped handlename: [%s]\n", aprinter));
608 /* check for the Port Monitor Interface */
609 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
610 Printer->printer_type = SPLHND_PORTMON_TCP;
611 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
612 found = true;
614 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
615 Printer->printer_type = SPLHND_PORTMON_LOCAL;
616 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
617 found = true;
621 * With hundreds of printers, the "for" loop iterating all
622 * shares can be quite expensive, as it is done on every
623 * OpenPrinter. The loop maps "aprinter" to "sname", the
624 * result of which we cache in gencache.
627 cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
628 aprinter);
629 if ((cache_key != NULL) && gencache_get(cache_key, &tmp, NULL)) {
631 found = (strcmp(tmp, printer_not_found) != 0);
632 if (!found) {
633 DEBUG(4, ("Printer %s not found\n", aprinter));
634 SAFE_FREE(tmp);
635 return WERR_INVALID_PRINTER_NAME;
637 fstrcpy(sname, tmp);
638 SAFE_FREE(tmp);
641 /* Search all sharenames first as this is easier than pulling
642 the printer_info_2 off of disk. Don't use find_service() since
643 that calls out to map_username() */
645 /* do another loop to look for printernames */
646 for (snum = 0; !found && snum < n_services; snum++) {
647 const char *printer = lp_const_servicename(snum);
649 /* no point going on if this is not a printer */
650 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
651 continue;
654 /* ignore [printers] share */
655 if (strequal(printer, "printers")) {
656 continue;
659 fstrcpy(sname, printer);
660 if (strequal(aprinter, printer)) {
661 found = true;
662 break;
665 /* no point looking up the printer object if
666 we aren't allowing printername != sharename */
667 if (lp_force_printername(snum)) {
668 continue;
671 result = winreg_get_printer(mem_ctx,
672 server_info,
673 msg_ctx,
674 sname,
675 &info2);
676 if ( !W_ERROR_IS_OK(result) ) {
677 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
678 sname, win_errstr(result)));
679 continue;
682 printername = strrchr(info2->printername, '\\');
683 if (printername == NULL) {
684 printername = info2->printername;
685 } else {
686 printername++;
689 if (strequal(printername, aprinter)) {
690 found = true;
691 break;
694 DEBUGADD(10, ("printername: %s\n", printername));
696 TALLOC_FREE(info2);
699 if ( !found ) {
700 if (cache_key != NULL) {
701 gencache_set(cache_key, printer_not_found,
702 time(NULL)+300);
703 TALLOC_FREE(cache_key);
705 DEBUGADD(4,("Printer not found\n"));
706 return WERR_INVALID_PRINTER_NAME;
709 if (cache_key != NULL) {
710 gencache_set(cache_key, sname, time(NULL)+300);
711 TALLOC_FREE(cache_key);
714 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
716 fstrcpy(Printer->sharename, sname);
718 return WERR_OK;
721 /****************************************************************************
722 Find first available printer slot. creates a printer handle for you.
723 ****************************************************************************/
725 static WERROR open_printer_hnd(struct pipes_struct *p,
726 struct policy_handle *hnd,
727 const char *name,
728 uint32_t access_granted)
730 struct printer_handle *new_printer;
731 WERROR result;
733 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
735 new_printer = talloc_zero(p->mem_ctx, struct printer_handle);
736 if (new_printer == NULL) {
737 return WERR_NOMEM;
739 talloc_set_destructor(new_printer, printer_entry_destructor);
741 /* This also steals the printer_handle on the policy_handle */
742 if (!create_policy_hnd(p, hnd, new_printer)) {
743 TALLOC_FREE(new_printer);
744 return WERR_INVALID_HANDLE;
747 /* Add to the internal list. */
748 DLIST_ADD(printers_list, new_printer);
750 new_printer->notify.option=NULL;
752 if (!set_printer_hnd_printertype(new_printer, name)) {
753 close_printer_handle(p, hnd);
754 return WERR_INVALID_HANDLE;
757 result = set_printer_hnd_name(p->mem_ctx,
758 get_server_info_system(),
759 p->msg_ctx,
760 new_printer, name);
761 if (!W_ERROR_IS_OK(result)) {
762 close_printer_handle(p, hnd);
763 return result;
766 new_printer->access_granted = access_granted;
768 DEBUG(5, ("%d printer handles active\n",
769 (int)num_pipe_handles(p)));
771 return WERR_OK;
774 /***************************************************************************
775 check to see if the client motify handle is monitoring the notification
776 given by (notify_type, notify_field).
777 **************************************************************************/
779 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
780 uint16_t notify_field)
782 return true;
785 static bool is_monitoring_event(struct printer_handle *p, uint16_t notify_type,
786 uint16_t notify_field)
788 struct spoolss_NotifyOption *option = p->notify.option;
789 uint32_t i, j;
792 * Flags should always be zero when the change notify
793 * is registered by the client's spooler. A user Win32 app
794 * might use the flags though instead of the NOTIFY_OPTION_INFO
795 * --jerry
798 if (!option) {
799 return false;
802 if (p->notify.flags)
803 return is_monitoring_event_flags(
804 p->notify.flags, notify_type, notify_field);
806 for (i = 0; i < option->count; i++) {
808 /* Check match for notify_type */
810 if (option->types[i].type != notify_type)
811 continue;
813 /* Check match for field */
815 for (j = 0; j < option->types[i].count; j++) {
816 if (option->types[i].fields[j].field == notify_field) {
817 return true;
822 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
823 p->servername, p->sharename, notify_type, notify_field));
825 return false;
828 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
829 _data->data.integer[0] = _integer; \
830 _data->data.integer[1] = 0;
833 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
834 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
835 if (!_data->data.string.string) {\
836 _data->data.string.size = 0; \
838 _data->data.string.size = strlen_m_term(_p) * 2;
840 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
841 _data->data.devmode.devmode = _devmode;
843 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
844 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
845 if (!_data->data.sd.sd) { \
846 _data->data.sd.sd_size = 0; \
848 _data->data.sd.sd_size = \
849 ndr_size_security_descriptor(_data->data.sd.sd, 0);
851 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
852 struct tm *t,
853 const char **pp,
854 uint32_t *plen)
856 struct spoolss_Time st;
857 uint32_t len = 16;
858 char *p;
860 if (!init_systemtime(&st, t)) {
861 return;
864 p = talloc_array(mem_ctx, char, len);
865 if (!p) {
866 return;
870 * Systemtime must be linearized as a set of UINT16's.
871 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
874 SSVAL(p, 0, st.year);
875 SSVAL(p, 2, st.month);
876 SSVAL(p, 4, st.day_of_week);
877 SSVAL(p, 6, st.day);
878 SSVAL(p, 8, st.hour);
879 SSVAL(p, 10, st.minute);
880 SSVAL(p, 12, st.second);
881 SSVAL(p, 14, st.millisecond);
883 *pp = p;
884 *plen = len;
887 /* Convert a notification message to a struct spoolss_Notify */
889 static void notify_one_value(struct spoolss_notify_msg *msg,
890 struct spoolss_Notify *data,
891 TALLOC_CTX *mem_ctx)
893 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
896 static void notify_string(struct spoolss_notify_msg *msg,
897 struct spoolss_Notify *data,
898 TALLOC_CTX *mem_ctx)
900 /* The length of the message includes the trailing \0 */
902 data->data.string.size = msg->len * 2;
903 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
904 if (!data->data.string.string) {
905 data->data.string.size = 0;
906 return;
910 static void notify_system_time(struct spoolss_notify_msg *msg,
911 struct spoolss_Notify *data,
912 TALLOC_CTX *mem_ctx)
914 data->data.string.string = NULL;
915 data->data.string.size = 0;
917 if (msg->len != sizeof(time_t)) {
918 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
919 msg->len));
920 return;
923 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
924 &data->data.string.string,
925 &data->data.string.size);
928 struct notify2_message_table {
929 const char *name;
930 void (*fn)(struct spoolss_notify_msg *msg,
931 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
934 static struct notify2_message_table printer_notify_table[] = {
935 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
936 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
937 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
938 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
939 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
940 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
941 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
942 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
943 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
944 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
945 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
946 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
947 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
948 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
949 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
950 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
951 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
952 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
953 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
956 static struct notify2_message_table job_notify_table[] = {
957 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
958 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
959 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
960 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
961 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
962 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
963 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
964 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
965 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
966 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
967 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
968 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
969 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
970 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
971 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
972 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
973 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
974 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
975 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
976 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
977 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
978 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
979 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
980 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
984 /***********************************************************************
985 Allocate talloc context for container object
986 **********************************************************************/
988 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
990 if ( !ctr )
991 return;
993 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
995 return;
998 /***********************************************************************
999 release all allocated memory and zero out structure
1000 **********************************************************************/
1002 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1004 if ( !ctr )
1005 return;
1007 if ( ctr->ctx )
1008 talloc_destroy(ctr->ctx);
1010 ZERO_STRUCTP(ctr);
1012 return;
1015 /***********************************************************************
1016 **********************************************************************/
1018 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1020 if ( !ctr )
1021 return NULL;
1023 return ctr->ctx;
1026 /***********************************************************************
1027 **********************************************************************/
1029 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1031 if ( !ctr || !ctr->msg_groups )
1032 return NULL;
1034 if ( idx >= ctr->num_groups )
1035 return NULL;
1037 return &ctr->msg_groups[idx];
1041 /***********************************************************************
1042 How many groups of change messages do we have ?
1043 **********************************************************************/
1045 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1047 if ( !ctr )
1048 return 0;
1050 return ctr->num_groups;
1053 /***********************************************************************
1054 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1055 **********************************************************************/
1057 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
1059 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
1060 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
1061 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
1062 int i, new_slot;
1064 if ( !ctr || !msg )
1065 return 0;
1067 /* loop over all groups looking for a matching printer name */
1069 for ( i=0; i<ctr->num_groups; i++ ) {
1070 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
1071 break;
1074 /* add a new group? */
1076 if ( i == ctr->num_groups ) {
1077 ctr->num_groups++;
1079 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
1080 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1081 return 0;
1083 ctr->msg_groups = groups;
1085 /* clear the new entry and set the printer name */
1087 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
1088 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
1091 /* add the change messages; 'i' is the correct index now regardless */
1093 msg_grp = &ctr->msg_groups[i];
1095 msg_grp->num_msgs++;
1097 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
1098 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
1099 return 0;
1101 msg_grp->msgs = msg_list;
1103 new_slot = msg_grp->num_msgs-1;
1104 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
1106 /* need to allocate own copy of data */
1108 if ( msg->len != 0 )
1109 msg_grp->msgs[new_slot].notify.data = (char *)
1110 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
1112 return ctr->num_groups;
1115 static void construct_info_data(struct spoolss_Notify *info_data,
1116 enum spoolss_NotifyType type,
1117 uint16_t field, int id);
1119 /***********************************************************************
1120 Send a change notication message on all handles which have a call
1121 back registered
1122 **********************************************************************/
1124 static int build_notify2_messages(TALLOC_CTX *mem_ctx,
1125 struct printer_handle *prn_hnd,
1126 SPOOLSS_NOTIFY_MSG *messages,
1127 uint32_t num_msgs,
1128 struct spoolss_Notify **_notifies,
1129 int *_count)
1131 struct spoolss_Notify *notifies;
1132 SPOOLSS_NOTIFY_MSG *msg;
1133 int count = 0;
1134 uint32_t id;
1135 int i;
1137 notifies = talloc_zero_array(mem_ctx,
1138 struct spoolss_Notify, num_msgs);
1139 if (!notifies) {
1140 return ENOMEM;
1143 for (i = 0; i < num_msgs; i++) {
1145 msg = &messages[i];
1147 /* Are we monitoring this event? */
1149 if (!is_monitoring_event(prn_hnd, msg->type, msg->field)) {
1150 continue;
1153 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1154 "for printer [%s]\n",
1155 msg->type, msg->field, prn_hnd->sharename));
1158 * if the is a printer notification handle and not a job
1159 * notification type, then set the id to 0.
1160 * Otherwise just use what was specified in the message.
1162 * When registering change notification on a print server
1163 * handle we always need to send back the id (snum) matching
1164 * the printer for which the change took place.
1165 * For change notify registered on a printer handle,
1166 * this does not matter and the id should be 0.
1168 * --jerry
1171 if ((msg->type == PRINTER_NOTIFY_TYPE) &&
1172 (prn_hnd->printer_type == SPLHND_PRINTER)) {
1173 id = 0;
1174 } else {
1175 id = msg->id;
1178 /* Convert unix jobid to smb jobid */
1180 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1181 id = sysjob_to_jobid(msg->id);
1183 if (id == -1) {
1184 DEBUG(3, ("no such unix jobid %d\n",
1185 msg->id));
1186 continue;
1190 construct_info_data(&notifies[count],
1191 msg->type, msg->field, id);
1193 switch(msg->type) {
1194 case PRINTER_NOTIFY_TYPE:
1195 if (printer_notify_table[msg->field].fn) {
1196 printer_notify_table[msg->field].fn(msg,
1197 &notifies[count], mem_ctx);
1199 break;
1201 case JOB_NOTIFY_TYPE:
1202 if (job_notify_table[msg->field].fn) {
1203 job_notify_table[msg->field].fn(msg,
1204 &notifies[count], mem_ctx);
1206 break;
1208 default:
1209 DEBUG(5, ("Unknown notification type %d\n",
1210 msg->type));
1211 continue;
1214 count++;
1217 *_notifies = notifies;
1218 *_count = count;
1220 return 0;
1223 static int send_notify2_printer(TALLOC_CTX *mem_ctx,
1224 struct printer_handle *prn_hnd,
1225 SPOOLSS_NOTIFY_MSG_GROUP *msg_group)
1227 struct spoolss_Notify *notifies;
1228 int count = 0;
1229 union spoolss_ReplyPrinterInfo info;
1230 struct spoolss_NotifyInfo info0;
1231 uint32_t reply_result;
1232 NTSTATUS status;
1233 WERROR werr;
1234 int ret;
1236 /* Is there notification on this handle? */
1237 if (prn_hnd->notify.cli_chan == NULL ||
1238 prn_hnd->notify.cli_chan->active_connections == 0) {
1239 return 0;
1242 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1243 prn_hnd->servername, prn_hnd->sharename));
1245 /* For this printer? Print servers always receive notifications. */
1246 if ((prn_hnd->printer_type == SPLHND_PRINTER) &&
1247 (!strequal(msg_group->printername, prn_hnd->sharename))) {
1248 return 0;
1251 DEBUG(10,("Our printer\n"));
1253 /* build the array of change notifications */
1254 ret = build_notify2_messages(mem_ctx, prn_hnd,
1255 msg_group->msgs,
1256 msg_group->num_msgs,
1257 &notifies, &count);
1258 if (ret) {
1259 return ret;
1262 info0.version = 0x2;
1263 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1264 info0.count = count;
1265 info0.notifies = notifies;
1267 info.info0 = &info0;
1269 status = rpccli_spoolss_RouterReplyPrinterEx(
1270 prn_hnd->notify.cli_chan->cli_pipe,
1271 mem_ctx,
1272 &prn_hnd->notify.cli_hnd,
1273 prn_hnd->notify.change, /* color */
1274 prn_hnd->notify.flags,
1275 &reply_result,
1276 0, /* reply_type, must be 0 */
1277 info, &werr);
1278 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1279 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1280 "failed: %s\n",
1281 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1282 win_errstr(werr)));
1284 switch (reply_result) {
1285 case 0:
1286 break;
1287 case PRINTER_NOTIFY_INFO_DISCARDED:
1288 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1289 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1290 break;
1291 default:
1292 break;
1295 return 0;
1298 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1300 struct printer_handle *p;
1301 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
1302 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
1303 int ret;
1305 if ( !msg_group ) {
1306 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1307 return;
1310 if (!msg_group->msgs) {
1311 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1312 return;
1315 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
1317 /* loop over all printers */
1319 for (p = printers_list; p; p = p->next) {
1320 ret = send_notify2_printer(mem_ctx, p, msg_group);
1321 if (ret) {
1322 goto done;
1326 done:
1327 DEBUG(8,("send_notify2_changes: Exit...\n"));
1328 return;
1331 /***********************************************************************
1332 **********************************************************************/
1334 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1337 uint32_t tv_sec, tv_usec;
1338 size_t offset = 0;
1340 /* Unpack message */
1342 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1343 msg->printer);
1345 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1346 &tv_sec, &tv_usec,
1347 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1349 if (msg->len == 0)
1350 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1351 &msg->notify.value[0], &msg->notify.value[1]);
1352 else
1353 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1354 &msg->len, &msg->notify.data);
1356 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1357 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1359 tv->tv_sec = tv_sec;
1360 tv->tv_usec = tv_usec;
1362 if (msg->len == 0)
1363 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1364 msg->notify.value[1]));
1365 else
1366 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1368 return true;
1371 /********************************************************************
1372 Receive a notify2 message list
1373 ********************************************************************/
1375 static void receive_notify2_message_list(struct messaging_context *msg,
1376 void *private_data,
1377 uint32_t msg_type,
1378 struct server_id server_id,
1379 DATA_BLOB *data)
1381 size_t msg_count, i;
1382 char *buf = (char *)data->data;
1383 char *msg_ptr;
1384 size_t msg_len;
1385 SPOOLSS_NOTIFY_MSG notify;
1386 SPOOLSS_NOTIFY_MSG_CTR messages;
1387 int num_groups;
1389 if (data->length < 4) {
1390 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1391 return;
1394 msg_count = IVAL(buf, 0);
1395 msg_ptr = buf + 4;
1397 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1399 if (msg_count == 0) {
1400 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1401 return;
1404 /* initialize the container */
1406 ZERO_STRUCT( messages );
1407 notify_msg_ctr_init( &messages );
1410 * build message groups for each printer identified
1411 * in a change_notify msg. Remember that a PCN message
1412 * includes the handle returned for the srv_spoolss_replyopenprinter()
1413 * call. Therefore messages are grouped according to printer handle.
1416 for ( i=0; i<msg_count; i++ ) {
1417 struct timeval msg_tv;
1419 if (msg_ptr + 4 - buf > data->length) {
1420 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1421 return;
1424 msg_len = IVAL(msg_ptr,0);
1425 msg_ptr += 4;
1427 if (msg_ptr + msg_len - buf > data->length) {
1428 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1429 return;
1432 /* unpack messages */
1434 ZERO_STRUCT( notify );
1435 notify2_unpack_msg( &notify, &msg_tv, msg_ptr, msg_len );
1436 msg_ptr += msg_len;
1438 /* add to correct list in container */
1440 notify_msg_ctr_addmsg( &messages, &notify );
1442 /* free memory that might have been allocated by notify2_unpack_msg() */
1444 if ( notify.len != 0 )
1445 SAFE_FREE( notify.notify.data );
1448 /* process each group of messages */
1450 num_groups = notify_msg_ctr_numgroups( &messages );
1451 for ( i=0; i<num_groups; i++ )
1452 send_notify2_changes( &messages, i );
1455 /* cleanup */
1457 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1458 (uint32_t)msg_count ));
1460 notify_msg_ctr_destroy( &messages );
1462 return;
1465 /********************************************************************
1466 Send a message to ourself about new driver being installed
1467 so we can upgrade the information for each printer bound to this
1468 driver
1469 ********************************************************************/
1471 static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
1472 struct messaging_context *msg_ctx)
1474 int len = strlen(drivername);
1476 if (!len)
1477 return false;
1479 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1480 drivername));
1482 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
1483 MSG_PRINTER_DRVUPGRADE,
1484 (uint8_t *)drivername, len+1);
1486 return true;
1489 void srv_spoolss_cleanup(void)
1491 struct printer_session_counter *session_counter;
1493 for (session_counter = counter_list;
1494 session_counter != NULL;
1495 session_counter = counter_list) {
1496 DLIST_REMOVE(counter_list, session_counter);
1497 TALLOC_FREE(session_counter);
1501 /**********************************************************************
1502 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1503 over all printers, upgrading ones as necessary
1504 **********************************************************************/
1506 void do_drv_upgrade_printer(struct messaging_context *msg,
1507 void *private_data,
1508 uint32_t msg_type,
1509 struct server_id server_id,
1510 DATA_BLOB *data)
1512 TALLOC_CTX *tmp_ctx;
1513 struct auth_serversupplied_info *server_info = NULL;
1514 struct spoolss_PrinterInfo2 *pinfo2;
1515 NTSTATUS status;
1516 WERROR result;
1517 const char *drivername;
1518 int snum;
1519 int n_services = lp_numservices();
1521 tmp_ctx = talloc_new(NULL);
1522 if (!tmp_ctx) return;
1524 status = make_server_info_system(tmp_ctx, &server_info);
1525 if (!NT_STATUS_IS_OK(status)) {
1526 DEBUG(0, ("do_drv_upgrade_printer: "
1527 "Could not create system server_info\n"));
1528 goto done;
1531 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, data->length);
1532 if (!drivername) {
1533 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1534 goto done;
1537 DEBUG(10, ("do_drv_upgrade_printer: "
1538 "Got message for new driver [%s]\n", drivername));
1540 /* Iterate the printer list */
1542 for (snum = 0; snum < n_services; snum++) {
1543 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1544 continue;
1547 /* ignore [printers] share */
1548 if (strequal(lp_const_servicename(snum), "printers")) {
1549 continue;
1552 result = winreg_get_printer(tmp_ctx, server_info, msg,
1553 lp_const_servicename(snum),
1554 &pinfo2);
1556 if (!W_ERROR_IS_OK(result)) {
1557 continue;
1560 if (!pinfo2->drivername) {
1561 continue;
1564 if (strcmp(drivername, pinfo2->drivername) != 0) {
1565 continue;
1568 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1570 /* all we care about currently is the change_id */
1571 result = winreg_printer_update_changeid(tmp_ctx,
1572 server_info,
1573 msg,
1574 pinfo2->printername);
1576 if (!W_ERROR_IS_OK(result)) {
1577 DEBUG(3, ("do_drv_upgrade_printer: "
1578 "Failed to update changeid [%s]\n",
1579 win_errstr(result)));
1583 /* all done */
1584 done:
1585 talloc_free(tmp_ctx);
1588 /********************************************************************
1589 Update the cache for all printq's with a registered client
1590 connection
1591 ********************************************************************/
1593 void update_monitored_printq_cache(struct messaging_context *msg_ctx)
1595 struct printer_handle *printer = printers_list;
1596 int snum;
1598 /* loop through all printers and update the cache where
1599 a client is connected */
1600 while (printer) {
1601 if ((printer->printer_type == SPLHND_PRINTER) &&
1602 ((printer->notify.cli_chan != NULL) &&
1603 (printer->notify.cli_chan->active_connections > 0))) {
1604 snum = print_queue_snum(printer->sharename);
1605 print_queue_status(msg_ctx, snum, NULL, NULL);
1608 printer = printer->next;
1611 return;
1614 /****************************************************************
1615 _spoolss_OpenPrinter
1616 ****************************************************************/
1618 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1619 struct spoolss_OpenPrinter *r)
1621 struct spoolss_OpenPrinterEx e;
1622 WERROR werr;
1624 ZERO_STRUCT(e.in.userlevel);
1626 e.in.printername = r->in.printername;
1627 e.in.datatype = r->in.datatype;
1628 e.in.devmode_ctr = r->in.devmode_ctr;
1629 e.in.access_mask = r->in.access_mask;
1630 e.in.level = 0;
1632 e.out.handle = r->out.handle;
1634 werr = _spoolss_OpenPrinterEx(p, &e);
1636 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1637 /* OpenPrinterEx returns this for a bad
1638 * printer name. We must return WERR_INVALID_PRINTER_NAME
1639 * instead.
1641 werr = WERR_INVALID_PRINTER_NAME;
1644 return werr;
1647 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1648 struct spoolss_DeviceMode *orig,
1649 struct spoolss_DeviceMode **dest)
1651 struct spoolss_DeviceMode *dm;
1653 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1654 if (!dm) {
1655 return WERR_NOMEM;
1658 /* copy all values, then duplicate strings and structs */
1659 *dm = *orig;
1661 dm->devicename = talloc_strdup(dm, orig->devicename);
1662 if (!dm->devicename) {
1663 return WERR_NOMEM;
1665 dm->formname = talloc_strdup(dm, orig->formname);
1666 if (!dm->formname) {
1667 return WERR_NOMEM;
1669 if (orig->driverextra_data.data) {
1670 dm->driverextra_data.data =
1671 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1672 orig->driverextra_data.length);
1673 if (!dm->driverextra_data.data) {
1674 return WERR_NOMEM;
1678 *dest = dm;
1679 return WERR_OK;
1682 /****************************************************************
1683 _spoolss_OpenPrinterEx
1684 ****************************************************************/
1686 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1687 struct spoolss_OpenPrinterEx *r)
1689 int snum;
1690 struct printer_handle *Printer=NULL;
1691 WERROR result;
1693 if (!r->in.printername) {
1694 return WERR_INVALID_PARAM;
1697 if (r->in.level < 0 || r->in.level > 3) {
1698 return WERR_INVALID_PARAM;
1700 if ((r->in.level == 1 && !r->in.userlevel.level1) ||
1701 (r->in.level == 2 && !r->in.userlevel.level2) ||
1702 (r->in.level == 3 && !r->in.userlevel.level3)) {
1703 return WERR_INVALID_PARAM;
1706 /* some sanity check because you can open a printer or a print server */
1707 /* aka: \\server\printer or \\server */
1709 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1711 result = open_printer_hnd(p, r->out.handle, r->in.printername, 0);
1712 if (!W_ERROR_IS_OK(result)) {
1713 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1714 "for printer %s\n", r->in.printername));
1715 ZERO_STRUCTP(r->out.handle);
1716 return result;
1719 Printer = find_printer_index_by_hnd(p, r->out.handle);
1720 if ( !Printer ) {
1721 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1722 "handle we created for printer %s\n", r->in.printername));
1723 close_printer_handle(p, r->out.handle);
1724 ZERO_STRUCTP(r->out.handle);
1725 return WERR_INVALID_PARAM;
1729 * First case: the user is opening the print server:
1731 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1732 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1734 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1735 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1736 * or if the user is listed in the smb.conf printer admin parameter.
1738 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1739 * client view printer folder, but does not show the MSAPW.
1741 * Note: this test needs code to check access rights here too. Jeremy
1742 * could you look at this?
1744 * Second case: the user is opening a printer:
1745 * NT doesn't let us connect to a printer if the connecting user
1746 * doesn't have print permission.
1748 * Third case: user is opening a Port Monitor
1749 * access checks same as opening a handle to the print server.
1752 switch (Printer->printer_type )
1754 case SPLHND_SERVER:
1755 case SPLHND_PORTMON_TCP:
1756 case SPLHND_PORTMON_LOCAL:
1757 /* Printserver handles use global struct... */
1759 snum = -1;
1761 /* Map standard access rights to object specific access rights */
1763 se_map_standard(&r->in.access_mask,
1764 &printserver_std_mapping);
1766 /* Deny any object specific bits that don't apply to print
1767 servers (i.e printer and job specific bits) */
1769 r->in.access_mask &= SEC_MASK_SPECIFIC;
1771 if (r->in.access_mask &
1772 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1773 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1774 close_printer_handle(p, r->out.handle);
1775 ZERO_STRUCTP(r->out.handle);
1776 return WERR_ACCESS_DENIED;
1779 /* Allow admin access */
1781 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1783 if (!lp_ms_add_printer_wizard()) {
1784 close_printer_handle(p, r->out.handle);
1785 ZERO_STRUCTP(r->out.handle);
1786 return WERR_ACCESS_DENIED;
1789 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1790 and not a printer admin, then fail */
1792 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1793 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
1794 !token_contains_name_in_list(
1795 uidtoname(p->server_info->utok.uid),
1796 p->server_info->info3->base.domain.string,
1797 NULL,
1798 p->server_info->ptok,
1799 lp_printer_admin(snum))) {
1800 close_printer_handle(p, r->out.handle);
1801 ZERO_STRUCTP(r->out.handle);
1802 return WERR_ACCESS_DENIED;
1805 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1807 else
1809 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1812 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1813 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1815 /* We fall through to return WERR_OK */
1816 break;
1818 case SPLHND_PRINTER:
1819 /* NT doesn't let us connect to a printer if the connecting user
1820 doesn't have print permission. */
1822 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1823 close_printer_handle(p, r->out.handle);
1824 ZERO_STRUCTP(r->out.handle);
1825 return WERR_BADFID;
1828 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1829 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1832 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1834 /* map an empty access mask to the minimum access mask */
1835 if (r->in.access_mask == 0x0)
1836 r->in.access_mask = PRINTER_ACCESS_USE;
1839 * If we are not serving the printer driver for this printer,
1840 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1841 * will keep NT clients happy --jerry
1844 if (lp_use_client_driver(snum)
1845 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1847 r->in.access_mask = PRINTER_ACCESS_USE;
1850 /* check smb.conf parameters and the the sec_desc */
1852 if (!allow_access(lp_hostsdeny(snum), lp_hostsallow(snum),
1853 p->client_id->name, p->client_id->addr)) {
1854 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1855 ZERO_STRUCTP(r->out.handle);
1856 return WERR_ACCESS_DENIED;
1859 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1860 p->server_info->ptok, snum) ||
1861 !print_access_check(p->server_info,
1862 p->msg_ctx,
1863 snum,
1864 r->in.access_mask)) {
1865 DEBUG(3, ("access DENIED for printer open\n"));
1866 close_printer_handle(p, r->out.handle);
1867 ZERO_STRUCTP(r->out.handle);
1868 return WERR_ACCESS_DENIED;
1871 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1872 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1873 close_printer_handle(p, r->out.handle);
1874 ZERO_STRUCTP(r->out.handle);
1875 return WERR_ACCESS_DENIED;
1878 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1879 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1880 else
1881 r->in.access_mask = PRINTER_ACCESS_USE;
1883 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1884 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1886 winreg_create_printer(p->mem_ctx,
1887 get_server_info_system(),
1888 p->msg_ctx,
1889 lp_const_servicename(snum));
1891 break;
1893 default:
1894 /* sanity check to prevent programmer error */
1895 ZERO_STRUCTP(r->out.handle);
1896 return WERR_BADFID;
1899 Printer->access_granted = r->in.access_mask;
1902 * If the client sent a devmode in the OpenPrinter() call, then
1903 * save it here in case we get a job submission on this handle
1906 if ((Printer->printer_type != SPLHND_SERVER) &&
1907 r->in.devmode_ctr.devmode) {
1908 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1909 &Printer->devmode);
1912 #if 0 /* JERRY -- I'm doubtful this is really effective */
1913 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1914 optimization in Windows 2000 clients --jerry */
1916 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1917 && (RA_WIN2K == get_remote_arch()) )
1919 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1920 sys_usleep( 500000 );
1922 #endif
1924 return WERR_OK;
1927 /****************************************************************
1928 _spoolss_ClosePrinter
1929 ****************************************************************/
1931 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1932 struct spoolss_ClosePrinter *r)
1934 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1936 if (Printer && Printer->document_started) {
1937 struct spoolss_EndDocPrinter e;
1939 e.in.handle = r->in.handle;
1941 _spoolss_EndDocPrinter(p, &e);
1944 if (!close_printer_handle(p, r->in.handle))
1945 return WERR_BADFID;
1947 /* clear the returned printer handle. Observed behavior
1948 from Win2k server. Don't think this really matters.
1949 Previous code just copied the value of the closed
1950 handle. --jerry */
1952 ZERO_STRUCTP(r->out.handle);
1954 return WERR_OK;
1957 /****************************************************************
1958 _spoolss_DeletePrinter
1959 ****************************************************************/
1961 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1962 struct spoolss_DeletePrinter *r)
1964 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1965 WERROR result;
1966 int snum;
1968 if (Printer && Printer->document_started) {
1969 struct spoolss_EndDocPrinter e;
1971 e.in.handle = r->in.handle;
1973 _spoolss_EndDocPrinter(p, &e);
1976 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
1977 winreg_delete_printer_key(p->mem_ctx,
1978 get_server_info_system(),
1979 p->msg_ctx,
1980 lp_const_servicename(snum),
1981 "");
1984 result = delete_printer_handle(p, r->in.handle);
1986 return result;
1989 /*******************************************************************
1990 * static function to lookup the version id corresponding to an
1991 * long architecture string
1992 ******************************************************************/
1994 static const struct print_architecture_table_node archi_table[]= {
1996 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1997 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1998 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1999 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
2000 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
2001 {"Windows IA64", SPL_ARCH_IA64, 3 },
2002 {"Windows x64", SPL_ARCH_X64, 3 },
2003 {NULL, "", -1 }
2006 static int get_version_id(const char *arch)
2008 int i;
2010 for (i=0; archi_table[i].long_archi != NULL; i++)
2012 if (strcmp(arch, archi_table[i].long_archi) == 0)
2013 return (archi_table[i].version);
2016 return -1;
2019 /****************************************************************
2020 _spoolss_DeletePrinterDriver
2021 ****************************************************************/
2023 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
2024 struct spoolss_DeletePrinterDriver *r)
2027 struct spoolss_DriverInfo8 *info = NULL;
2028 struct spoolss_DriverInfo8 *info_win2k = NULL;
2029 int version;
2030 WERROR status;
2032 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2033 and not a printer admin, then fail */
2035 if ( (p->server_info->utok.uid != sec_initial_uid())
2036 && !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR)
2037 && !token_contains_name_in_list(
2038 uidtoname(p->server_info->utok.uid),
2039 p->server_info->info3->base.domain.string,
2040 NULL,
2041 p->server_info->ptok,
2042 lp_printer_admin(-1)) )
2044 return WERR_ACCESS_DENIED;
2047 /* check that we have a valid driver name first */
2049 if ((version = get_version_id(r->in.architecture)) == -1)
2050 return WERR_INVALID_ENVIRONMENT;
2052 status = winreg_get_driver(p->mem_ctx,
2053 get_server_info_system(),
2054 p->msg_ctx,
2055 r->in.architecture, r->in.driver,
2056 version, &info);
2057 if (!W_ERROR_IS_OK(status)) {
2058 /* try for Win2k driver if "Windows NT x86" */
2060 if ( version == 2 ) {
2061 version = 3;
2063 status = winreg_get_driver(p->mem_ctx,
2064 get_server_info_system(),
2065 p->msg_ctx,
2066 r->in.architecture,
2067 r->in.driver,
2068 version, &info);
2069 if (!W_ERROR_IS_OK(status)) {
2070 status = WERR_UNKNOWN_PRINTER_DRIVER;
2071 goto done;
2074 /* otherwise it was a failure */
2075 else {
2076 status = WERR_UNKNOWN_PRINTER_DRIVER;
2077 goto done;
2082 if (printer_driver_in_use(p->mem_ctx,
2083 get_server_info_system(),
2084 p->msg_ctx,
2085 info)) {
2086 status = WERR_PRINTER_DRIVER_IN_USE;
2087 goto done;
2090 if (version == 2) {
2091 status = winreg_get_driver(p->mem_ctx,
2092 get_server_info_system(),
2093 p->msg_ctx,
2094 r->in.architecture,
2095 r->in.driver, 3, &info_win2k);
2096 if (W_ERROR_IS_OK(status)) {
2097 /* if we get to here, we now have 2 driver info structures to remove */
2098 /* remove the Win2k driver first*/
2100 status = winreg_del_driver(p->mem_ctx,
2101 get_server_info_system(),
2102 p->msg_ctx,
2103 info_win2k, 3);
2104 talloc_free(info_win2k);
2106 /* this should not have failed---if it did, report to client */
2107 if (!W_ERROR_IS_OK(status)) {
2108 goto done;
2113 status = winreg_del_driver(p->mem_ctx,
2114 get_server_info_system(),
2115 p->msg_ctx,
2116 info, version);
2118 done:
2119 talloc_free(info);
2121 return status;
2124 /****************************************************************
2125 _spoolss_DeletePrinterDriverEx
2126 ****************************************************************/
2128 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
2129 struct spoolss_DeletePrinterDriverEx *r)
2131 struct spoolss_DriverInfo8 *info = NULL;
2132 struct spoolss_DriverInfo8 *info_win2k = NULL;
2133 int version;
2134 bool delete_files;
2135 WERROR status;
2137 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2138 and not a printer admin, then fail */
2140 if ( (p->server_info->utok.uid != sec_initial_uid())
2141 && !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR)
2142 && !token_contains_name_in_list(
2143 uidtoname(p->server_info->utok.uid),
2144 p->server_info->info3->base.domain.string,
2145 NULL,
2146 p->server_info->ptok, lp_printer_admin(-1)) )
2148 return WERR_ACCESS_DENIED;
2151 /* check that we have a valid driver name first */
2152 if ((version = get_version_id(r->in.architecture)) == -1) {
2153 /* this is what NT returns */
2154 return WERR_INVALID_ENVIRONMENT;
2157 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2158 version = r->in.version;
2160 status = winreg_get_driver(p->mem_ctx,
2161 get_server_info_system(),
2162 p->msg_ctx,
2163 r->in.architecture,
2164 r->in.driver,
2165 version,
2166 &info);
2167 if (!W_ERROR_IS_OK(status)) {
2168 status = WERR_UNKNOWN_PRINTER_DRIVER;
2171 * if the client asked for a specific version,
2172 * or this is something other than Windows NT x86,
2173 * then we've failed
2176 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2177 goto done;
2179 /* try for Win2k driver if "Windows NT x86" */
2181 version = 3;
2182 status = winreg_get_driver(info,
2183 get_server_info_system(),
2184 p->msg_ctx,
2185 r->in.architecture,
2186 r->in.driver,
2187 version, &info);
2188 if (!W_ERROR_IS_OK(status)) {
2189 status = WERR_UNKNOWN_PRINTER_DRIVER;
2190 goto done;
2194 if (printer_driver_in_use(info,
2195 get_server_info_system(),
2196 p->msg_ctx,
2197 info)) {
2198 status = WERR_PRINTER_DRIVER_IN_USE;
2199 goto done;
2203 * we have a couple of cases to consider.
2204 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2205 * then the delete should fail if **any** files overlap with
2206 * other drivers
2207 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2208 * non-overlapping files
2209 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2210 * is set, the do not delete any files
2211 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2214 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2216 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2218 if (delete_files &&
2219 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2220 printer_driver_files_in_use(info,
2221 get_server_info_system(),
2222 p->msg_ctx,
2223 info)) {
2224 /* no idea of the correct error here */
2225 status = WERR_ACCESS_DENIED;
2226 goto done;
2230 /* also check for W32X86/3 if necessary; maybe we already have? */
2232 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2233 status = winreg_get_driver(info,
2234 get_server_info_system(),
2235 p->msg_ctx,
2236 r->in.architecture,
2237 r->in.driver, 3, &info_win2k);
2238 if (W_ERROR_IS_OK(status)) {
2240 if (delete_files &&
2241 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2242 printer_driver_files_in_use(info,
2243 get_server_info_system(),
2244 p->msg_ctx,
2245 info_win2k)) {
2246 /* no idea of the correct error here */
2247 talloc_free(info_win2k);
2248 status = WERR_ACCESS_DENIED;
2249 goto done;
2252 /* if we get to here, we now have 2 driver info structures to remove */
2253 /* remove the Win2k driver first*/
2255 status = winreg_del_driver(info,
2256 get_server_info_system(),
2257 p->msg_ctx,
2258 info_win2k,
2261 /* this should not have failed---if it did, report to client */
2263 if (!W_ERROR_IS_OK(status)) {
2264 goto done;
2268 * now delete any associated files if delete_files is
2269 * true. Even if this part failes, we return succes
2270 * because the driver doesn not exist any more
2272 if (delete_files) {
2273 delete_driver_files(get_server_info_system(),
2274 info_win2k);
2279 status = winreg_del_driver(info,
2280 get_server_info_system(),
2281 p->msg_ctx,
2282 info,
2283 version);
2284 if (!W_ERROR_IS_OK(status)) {
2285 goto done;
2289 * now delete any associated files if delete_files is
2290 * true. Even if this part failes, we return succes
2291 * because the driver doesn not exist any more
2293 if (delete_files) {
2294 delete_driver_files(get_server_info_system(), info);
2297 done:
2298 talloc_free(info);
2299 return status;
2303 /********************************************************************
2304 GetPrinterData on a printer server Handle.
2305 ********************************************************************/
2307 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2308 const char *value,
2309 enum winreg_Type *type,
2310 union spoolss_PrinterData *data)
2312 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2314 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2315 *type = REG_DWORD;
2316 data->value = 0x00;
2317 return WERR_OK;
2320 if (!StrCaseCmp(value, "BeepEnabled")) {
2321 *type = REG_DWORD;
2322 data->value = 0x00;
2323 return WERR_OK;
2326 if (!StrCaseCmp(value, "EventLog")) {
2327 *type = REG_DWORD;
2328 /* formally was 0x1b */
2329 data->value = 0x00;
2330 return WERR_OK;
2333 if (!StrCaseCmp(value, "NetPopup")) {
2334 *type = REG_DWORD;
2335 data->value = 0x00;
2336 return WERR_OK;
2339 if (!StrCaseCmp(value, "MajorVersion")) {
2340 *type = REG_DWORD;
2342 /* Windows NT 4.0 seems to not allow uploading of drivers
2343 to a server that reports 0x3 as the MajorVersion.
2344 need to investigate more how Win2k gets around this .
2345 -- jerry */
2347 if (RA_WINNT == get_remote_arch()) {
2348 data->value = 0x02;
2349 } else {
2350 data->value = 0x03;
2353 return WERR_OK;
2356 if (!StrCaseCmp(value, "MinorVersion")) {
2357 *type = REG_DWORD;
2358 data->value = 0x00;
2359 return WERR_OK;
2362 /* REG_BINARY
2363 * uint32_t size = 0x114
2364 * uint32_t major = 5
2365 * uint32_t minor = [0|1]
2366 * uint32_t build = [2195|2600]
2367 * extra unicode string = e.g. "Service Pack 3"
2369 if (!StrCaseCmp(value, "OSVersion")) {
2370 DATA_BLOB blob;
2371 enum ndr_err_code ndr_err;
2372 struct spoolss_OSVersion os;
2374 os.major = 5; /* Windows 2000 == 5.0 */
2375 os.minor = 0;
2376 os.build = 2195; /* build */
2377 os.extra_string = ""; /* leave extra string empty */
2379 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2380 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2381 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2382 return WERR_GENERAL_FAILURE;
2385 *type = REG_BINARY;
2386 data->binary = blob;
2388 return WERR_OK;
2392 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2393 *type = REG_SZ;
2395 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2396 W_ERROR_HAVE_NO_MEMORY(data->string);
2398 return WERR_OK;
2401 if (!StrCaseCmp(value, "Architecture")) {
2402 *type = REG_SZ;
2403 data->string = talloc_strdup(mem_ctx,
2404 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2405 W_ERROR_HAVE_NO_MEMORY(data->string);
2407 return WERR_OK;
2410 if (!StrCaseCmp(value, "DsPresent")) {
2411 *type = REG_DWORD;
2413 /* only show the publish check box if we are a
2414 member of a AD domain */
2416 if (lp_security() == SEC_ADS) {
2417 data->value = 0x01;
2418 } else {
2419 data->value = 0x00;
2421 return WERR_OK;
2424 if (!StrCaseCmp(value, "DNSMachineName")) {
2425 const char *hostname = get_mydnsfullname();
2427 if (!hostname) {
2428 return WERR_BADFILE;
2431 *type = REG_SZ;
2432 data->string = talloc_strdup(mem_ctx, hostname);
2433 W_ERROR_HAVE_NO_MEMORY(data->string);
2435 return WERR_OK;
2438 *type = REG_NONE;
2440 return WERR_INVALID_PARAM;
2443 /****************************************************************
2444 _spoolss_GetPrinterData
2445 ****************************************************************/
2447 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2448 struct spoolss_GetPrinterData *r)
2450 struct spoolss_GetPrinterDataEx r2;
2452 r2.in.handle = r->in.handle;
2453 r2.in.key_name = "PrinterDriverData";
2454 r2.in.value_name = r->in.value_name;
2455 r2.in.offered = r->in.offered;
2456 r2.out.type = r->out.type;
2457 r2.out.data = r->out.data;
2458 r2.out.needed = r->out.needed;
2460 return _spoolss_GetPrinterDataEx(p, &r2);
2463 /*********************************************************
2464 Connect to the client machine.
2465 **********************************************************/
2467 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2468 struct sockaddr_storage *client_ss, const char *remote_machine)
2470 NTSTATUS ret;
2471 struct cli_state *the_cli;
2472 struct sockaddr_storage rm_addr;
2473 char addr[INET6_ADDRSTRLEN];
2475 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2476 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2477 remote_machine));
2478 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2479 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2480 return false;
2482 print_sockaddr(addr, sizeof(addr), &rm_addr);
2483 } else {
2484 rm_addr = *client_ss;
2485 print_sockaddr(addr, sizeof(addr), &rm_addr);
2486 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2487 addr));
2490 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2491 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2492 addr));
2493 return false;
2496 /* setup the connection */
2497 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2498 &rm_addr, 0, "IPC$", "IPC",
2499 "", /* username */
2500 "", /* domain */
2501 "", /* password */
2502 0, lp_client_signing(), NULL );
2504 if ( !NT_STATUS_IS_OK( ret ) ) {
2505 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2506 remote_machine ));
2507 return false;
2510 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2511 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2512 cli_shutdown(the_cli);
2513 return false;
2517 * Ok - we have an anonymous connection to the IPC$ share.
2518 * Now start the NT Domain stuff :-).
2521 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2522 if (!NT_STATUS_IS_OK(ret)) {
2523 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2524 remote_machine, nt_errstr(ret)));
2525 cli_shutdown(the_cli);
2526 return false;
2529 return true;
2532 /***************************************************************************
2533 Connect to the client.
2534 ****************************************************************************/
2536 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2537 uint32_t localprinter,
2538 enum winreg_Type type,
2539 struct policy_handle *handle,
2540 struct notify_back_channel **_chan,
2541 struct sockaddr_storage *client_ss,
2542 struct messaging_context *msg_ctx)
2544 WERROR result;
2545 NTSTATUS status;
2546 struct notify_back_channel *chan;
2548 for (chan = back_channels; chan; chan = chan->next) {
2549 if (memcmp(&chan->client_address, client_ss,
2550 sizeof(struct sockaddr_storage)) == 0) {
2551 break;
2556 * If it's the first connection, contact the client
2557 * and connect to the IPC$ share anonymously
2559 if (!chan) {
2560 fstring unix_printer;
2562 /* the +2 is to strip the leading 2 backslashs */
2563 fstrcpy(unix_printer, printer + 2);
2565 chan = talloc_zero(back_channels, struct notify_back_channel);
2566 if (!chan) {
2567 return false;
2569 chan->client_address = *client_ss;
2571 if (!spoolss_connect_to_client(&chan->cli_pipe, client_ss, unix_printer)) {
2572 TALLOC_FREE(chan);
2573 return false;
2576 DLIST_ADD(back_channels, chan);
2578 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2579 receive_notify2_message_list);
2580 /* Tell the connections db we're now interested in printer
2581 * notify messages. */
2582 serverid_register_msg_flags(messaging_server_id(msg_ctx),
2583 true, FLAG_MSG_PRINT_NOTIFY);
2587 * Tell the specific printing tdb we want messages for this printer
2588 * by registering our PID.
2591 if (!print_notify_register_pid(snum)) {
2592 DEBUG(0, ("Failed to register our pid for printer %s\n",
2593 printer));
2596 status = rpccli_spoolss_ReplyOpenPrinter(chan->cli_pipe, talloc_tos(),
2597 printer,
2598 localprinter,
2599 type,
2601 NULL,
2602 handle,
2603 &result);
2604 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
2605 DEBUG(5, ("Client RPC returned [%s]\n", win_errstr(result)));
2608 chan->active_connections++;
2609 *_chan = chan;
2611 return (W_ERROR_IS_OK(result));
2614 /****************************************************************
2615 ****************************************************************/
2617 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2618 const struct spoolss_NotifyOption *r)
2620 struct spoolss_NotifyOption *option;
2621 uint32_t i,k;
2623 if (!r) {
2624 return NULL;
2627 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2628 if (!option) {
2629 return NULL;
2632 *option = *r;
2634 if (!option->count) {
2635 return option;
2638 option->types = talloc_zero_array(option,
2639 struct spoolss_NotifyOptionType, option->count);
2640 if (!option->types) {
2641 talloc_free(option);
2642 return NULL;
2645 for (i=0; i < option->count; i++) {
2646 option->types[i] = r->types[i];
2648 if (option->types[i].count) {
2649 option->types[i].fields = talloc_zero_array(option,
2650 union spoolss_Field, option->types[i].count);
2651 if (!option->types[i].fields) {
2652 talloc_free(option);
2653 return NULL;
2655 for (k=0; k<option->types[i].count; k++) {
2656 option->types[i].fields[k] =
2657 r->types[i].fields[k];
2662 return option;
2665 /****************************************************************
2666 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2668 * before replying OK: status=0 a rpc call is made to the workstation
2669 * asking ReplyOpenPrinter
2671 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2672 * called from api_spoolss_rffpcnex
2673 ****************************************************************/
2675 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2676 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2678 int snum = -1;
2679 struct spoolss_NotifyOption *option = r->in.notify_options;
2680 struct sockaddr_storage client_ss;
2682 /* store the notify value in the printer struct */
2684 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2686 if (!Printer) {
2687 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2688 "Invalid handle (%s:%u:%u).\n",
2689 OUR_HANDLE(r->in.handle)));
2690 return WERR_BADFID;
2693 Printer->notify.flags = r->in.flags;
2694 Printer->notify.options = r->in.options;
2695 Printer->notify.printerlocal = r->in.printer_local;
2696 Printer->notify.msg_ctx = p->msg_ctx;
2698 TALLOC_FREE(Printer->notify.option);
2699 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2701 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2703 /* Connect to the client machine and send a ReplyOpenPrinter */
2705 if ( Printer->printer_type == SPLHND_SERVER)
2706 snum = -1;
2707 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2708 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2709 return WERR_BADFID;
2711 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2712 "client_address is %s\n", p->client_id->addr));
2714 if (!interpret_string_addr(&client_ss, p->client_id->addr,
2715 AI_NUMERICHOST)) {
2716 return WERR_SERVER_UNAVAILABLE;
2719 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2720 Printer->notify.printerlocal, REG_SZ,
2721 &Printer->notify.cli_hnd,
2722 &Printer->notify.cli_chan,
2723 &client_ss, p->msg_ctx)) {
2724 return WERR_SERVER_UNAVAILABLE;
2727 return WERR_OK;
2730 /*******************************************************************
2731 * fill a notify_info_data with the servername
2732 ********************************************************************/
2734 static void spoolss_notify_server_name(struct messaging_context *msg_ctx,
2735 int snum,
2736 struct spoolss_Notify *data,
2737 print_queue_struct *queue,
2738 struct spoolss_PrinterInfo2 *pinfo2,
2739 TALLOC_CTX *mem_ctx)
2741 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2744 /*******************************************************************
2745 * fill a notify_info_data with the printername (not including the servername).
2746 ********************************************************************/
2748 static void spoolss_notify_printer_name(struct messaging_context *msg_ctx,
2749 int snum,
2750 struct spoolss_Notify *data,
2751 print_queue_struct *queue,
2752 struct spoolss_PrinterInfo2 *pinfo2,
2753 TALLOC_CTX *mem_ctx)
2755 /* the notify name should not contain the \\server\ part */
2756 const char *p = strrchr(pinfo2->printername, '\\');
2758 if (!p) {
2759 p = pinfo2->printername;
2760 } else {
2761 p++;
2764 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2767 /*******************************************************************
2768 * fill a notify_info_data with the servicename
2769 ********************************************************************/
2771 static void spoolss_notify_share_name(struct messaging_context *msg_ctx,
2772 int snum,
2773 struct spoolss_Notify *data,
2774 print_queue_struct *queue,
2775 struct spoolss_PrinterInfo2 *pinfo2,
2776 TALLOC_CTX *mem_ctx)
2778 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2781 /*******************************************************************
2782 * fill a notify_info_data with the port name
2783 ********************************************************************/
2785 static void spoolss_notify_port_name(struct messaging_context *msg_ctx,
2786 int snum,
2787 struct spoolss_Notify *data,
2788 print_queue_struct *queue,
2789 struct spoolss_PrinterInfo2 *pinfo2,
2790 TALLOC_CTX *mem_ctx)
2792 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2795 /*******************************************************************
2796 * fill a notify_info_data with the printername
2797 * but it doesn't exist, have to see what to do
2798 ********************************************************************/
2800 static void spoolss_notify_driver_name(struct messaging_context *msg_ctx,
2801 int snum,
2802 struct spoolss_Notify *data,
2803 print_queue_struct *queue,
2804 struct spoolss_PrinterInfo2 *pinfo2,
2805 TALLOC_CTX *mem_ctx)
2807 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2810 /*******************************************************************
2811 * fill a notify_info_data with the comment
2812 ********************************************************************/
2814 static void spoolss_notify_comment(struct messaging_context *msg_ctx,
2815 int snum,
2816 struct spoolss_Notify *data,
2817 print_queue_struct *queue,
2818 struct spoolss_PrinterInfo2 *pinfo2,
2819 TALLOC_CTX *mem_ctx)
2821 const char *p;
2823 if (*pinfo2->comment == '\0') {
2824 p = lp_comment(snum);
2825 } else {
2826 p = pinfo2->comment;
2829 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2832 /*******************************************************************
2833 * fill a notify_info_data with the comment
2834 * location = "Room 1, floor 2, building 3"
2835 ********************************************************************/
2837 static void spoolss_notify_location(struct messaging_context *msg_ctx,
2838 int snum,
2839 struct spoolss_Notify *data,
2840 print_queue_struct *queue,
2841 struct spoolss_PrinterInfo2 *pinfo2,
2842 TALLOC_CTX *mem_ctx)
2844 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
2847 /*******************************************************************
2848 * fill a notify_info_data with the device mode
2849 * jfm:xxxx don't to it for know but that's a real problem !!!
2850 ********************************************************************/
2852 static void spoolss_notify_devmode(struct messaging_context *msg_ctx,
2853 int snum,
2854 struct spoolss_Notify *data,
2855 print_queue_struct *queue,
2856 struct spoolss_PrinterInfo2 *pinfo2,
2857 TALLOC_CTX *mem_ctx)
2859 /* for a dummy implementation we have to zero the fields */
2860 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2863 /*******************************************************************
2864 * fill a notify_info_data with the separator file name
2865 ********************************************************************/
2867 static void spoolss_notify_sepfile(struct messaging_context *msg_ctx,
2868 int snum,
2869 struct spoolss_Notify *data,
2870 print_queue_struct *queue,
2871 struct spoolss_PrinterInfo2 *pinfo2,
2872 TALLOC_CTX *mem_ctx)
2874 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2877 /*******************************************************************
2878 * fill a notify_info_data with the print processor
2879 * jfm:xxxx return always winprint to indicate we don't do anything to it
2880 ********************************************************************/
2882 static void spoolss_notify_print_processor(struct messaging_context *msg_ctx,
2883 int snum,
2884 struct spoolss_Notify *data,
2885 print_queue_struct *queue,
2886 struct spoolss_PrinterInfo2 *pinfo2,
2887 TALLOC_CTX *mem_ctx)
2889 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2892 /*******************************************************************
2893 * fill a notify_info_data with the print processor options
2894 * jfm:xxxx send an empty string
2895 ********************************************************************/
2897 static void spoolss_notify_parameters(struct messaging_context *msg_ctx,
2898 int snum,
2899 struct spoolss_Notify *data,
2900 print_queue_struct *queue,
2901 struct spoolss_PrinterInfo2 *pinfo2,
2902 TALLOC_CTX *mem_ctx)
2904 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2907 /*******************************************************************
2908 * fill a notify_info_data with the data type
2909 * jfm:xxxx always send RAW as data type
2910 ********************************************************************/
2912 static void spoolss_notify_datatype(struct messaging_context *msg_ctx,
2913 int snum,
2914 struct spoolss_Notify *data,
2915 print_queue_struct *queue,
2916 struct spoolss_PrinterInfo2 *pinfo2,
2917 TALLOC_CTX *mem_ctx)
2919 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2922 /*******************************************************************
2923 * fill a notify_info_data with the security descriptor
2924 * jfm:xxxx send an null pointer to say no security desc
2925 * have to implement security before !
2926 ********************************************************************/
2928 static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
2929 int snum,
2930 struct spoolss_Notify *data,
2931 print_queue_struct *queue,
2932 struct spoolss_PrinterInfo2 *pinfo2,
2933 TALLOC_CTX *mem_ctx)
2935 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2938 /*******************************************************************
2939 * fill a notify_info_data with the attributes
2940 * jfm:xxxx a samba printer is always shared
2941 ********************************************************************/
2943 static void spoolss_notify_attributes(struct messaging_context *msg_ctx,
2944 int snum,
2945 struct spoolss_Notify *data,
2946 print_queue_struct *queue,
2947 struct spoolss_PrinterInfo2 *pinfo2,
2948 TALLOC_CTX *mem_ctx)
2950 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2953 /*******************************************************************
2954 * fill a notify_info_data with the priority
2955 ********************************************************************/
2957 static void spoolss_notify_priority(struct messaging_context *msg_ctx,
2958 int snum,
2959 struct spoolss_Notify *data,
2960 print_queue_struct *queue,
2961 struct spoolss_PrinterInfo2 *pinfo2,
2962 TALLOC_CTX *mem_ctx)
2964 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2967 /*******************************************************************
2968 * fill a notify_info_data with the default priority
2969 ********************************************************************/
2971 static void spoolss_notify_default_priority(struct messaging_context *msg_ctx,
2972 int snum,
2973 struct spoolss_Notify *data,
2974 print_queue_struct *queue,
2975 struct spoolss_PrinterInfo2 *pinfo2,
2976 TALLOC_CTX *mem_ctx)
2978 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
2981 /*******************************************************************
2982 * fill a notify_info_data with the start time
2983 ********************************************************************/
2985 static void spoolss_notify_start_time(struct messaging_context *msg_ctx,
2986 int snum,
2987 struct spoolss_Notify *data,
2988 print_queue_struct *queue,
2989 struct spoolss_PrinterInfo2 *pinfo2,
2990 TALLOC_CTX *mem_ctx)
2992 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
2995 /*******************************************************************
2996 * fill a notify_info_data with the until time
2997 ********************************************************************/
2999 static void spoolss_notify_until_time(struct messaging_context *msg_ctx,
3000 int snum,
3001 struct spoolss_Notify *data,
3002 print_queue_struct *queue,
3003 struct spoolss_PrinterInfo2 *pinfo2,
3004 TALLOC_CTX *mem_ctx)
3006 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
3009 /*******************************************************************
3010 * fill a notify_info_data with the status
3011 ********************************************************************/
3013 static void spoolss_notify_status(struct messaging_context *msg_ctx,
3014 int snum,
3015 struct spoolss_Notify *data,
3016 print_queue_struct *queue,
3017 struct spoolss_PrinterInfo2 *pinfo2,
3018 TALLOC_CTX *mem_ctx)
3020 print_status_struct status;
3022 print_queue_length(msg_ctx, snum, &status);
3023 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3026 /*******************************************************************
3027 * fill a notify_info_data with the number of jobs queued
3028 ********************************************************************/
3030 static void spoolss_notify_cjobs(struct messaging_context *msg_ctx,
3031 int snum,
3032 struct spoolss_Notify *data,
3033 print_queue_struct *queue,
3034 struct spoolss_PrinterInfo2 *pinfo2,
3035 TALLOC_CTX *mem_ctx)
3037 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3038 data, print_queue_length(msg_ctx, snum, NULL));
3041 /*******************************************************************
3042 * fill a notify_info_data with the average ppm
3043 ********************************************************************/
3045 static void spoolss_notify_average_ppm(struct messaging_context *msg_ctx,
3046 int snum,
3047 struct spoolss_Notify *data,
3048 print_queue_struct *queue,
3049 struct spoolss_PrinterInfo2 *pinfo2,
3050 TALLOC_CTX *mem_ctx)
3052 /* always respond 8 pages per minutes */
3053 /* a little hard ! */
3054 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
3057 /*******************************************************************
3058 * fill a notify_info_data with username
3059 ********************************************************************/
3061 static void spoolss_notify_username(struct messaging_context *msg_ctx,
3062 int snum,
3063 struct spoolss_Notify *data,
3064 print_queue_struct *queue,
3065 struct spoolss_PrinterInfo2 *pinfo2,
3066 TALLOC_CTX *mem_ctx)
3068 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3071 /*******************************************************************
3072 * fill a notify_info_data with job status
3073 ********************************************************************/
3075 static void spoolss_notify_job_status(struct messaging_context *msg_ctx,
3076 int snum,
3077 struct spoolss_Notify *data,
3078 print_queue_struct *queue,
3079 struct spoolss_PrinterInfo2 *pinfo2,
3080 TALLOC_CTX *mem_ctx)
3082 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3085 /*******************************************************************
3086 * fill a notify_info_data with job name
3087 ********************************************************************/
3089 static void spoolss_notify_job_name(struct messaging_context *msg_ctx,
3090 int snum,
3091 struct spoolss_Notify *data,
3092 print_queue_struct *queue,
3093 struct spoolss_PrinterInfo2 *pinfo2,
3094 TALLOC_CTX *mem_ctx)
3096 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3099 /*******************************************************************
3100 * fill a notify_info_data with job status
3101 ********************************************************************/
3103 static void spoolss_notify_job_status_string(struct messaging_context *msg_ctx,
3104 int snum,
3105 struct spoolss_Notify *data,
3106 print_queue_struct *queue,
3107 struct spoolss_PrinterInfo2 *pinfo2,
3108 TALLOC_CTX *mem_ctx)
3111 * Now we're returning job status codes we just return a "" here. JRA.
3114 const char *p = "";
3116 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3117 p = "unknown";
3119 switch (queue->status) {
3120 case LPQ_QUEUED:
3121 p = "Queued";
3122 break;
3123 case LPQ_PAUSED:
3124 p = ""; /* NT provides the paused string */
3125 break;
3126 case LPQ_SPOOLING:
3127 p = "Spooling";
3128 break;
3129 case LPQ_PRINTING:
3130 p = "Printing";
3131 break;
3133 #endif /* NO LONGER NEEDED. */
3135 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3138 /*******************************************************************
3139 * fill a notify_info_data with job time
3140 ********************************************************************/
3142 static void spoolss_notify_job_time(struct messaging_context *msg_ctx,
3143 int snum,
3144 struct spoolss_Notify *data,
3145 print_queue_struct *queue,
3146 struct spoolss_PrinterInfo2 *pinfo2,
3147 TALLOC_CTX *mem_ctx)
3149 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3152 /*******************************************************************
3153 * fill a notify_info_data with job size
3154 ********************************************************************/
3156 static void spoolss_notify_job_size(struct messaging_context *msg_ctx,
3157 int snum,
3158 struct spoolss_Notify *data,
3159 print_queue_struct *queue,
3160 struct spoolss_PrinterInfo2 *pinfo2,
3161 TALLOC_CTX *mem_ctx)
3163 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3166 /*******************************************************************
3167 * fill a notify_info_data with page info
3168 ********************************************************************/
3169 static void spoolss_notify_total_pages(struct messaging_context *msg_ctx,
3170 int snum,
3171 struct spoolss_Notify *data,
3172 print_queue_struct *queue,
3173 struct spoolss_PrinterInfo2 *pinfo2,
3174 TALLOC_CTX *mem_ctx)
3176 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3179 /*******************************************************************
3180 * fill a notify_info_data with pages printed info.
3181 ********************************************************************/
3182 static void spoolss_notify_pages_printed(struct messaging_context *msg_ctx,
3183 int snum,
3184 struct spoolss_Notify *data,
3185 print_queue_struct *queue,
3186 struct spoolss_PrinterInfo2 *pinfo2,
3187 TALLOC_CTX *mem_ctx)
3189 /* Add code when back-end tracks this */
3190 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3193 /*******************************************************************
3194 Fill a notify_info_data with job position.
3195 ********************************************************************/
3197 static void spoolss_notify_job_position(struct messaging_context *msg_ctx,
3198 int snum,
3199 struct spoolss_Notify *data,
3200 print_queue_struct *queue,
3201 struct spoolss_PrinterInfo2 *pinfo2,
3202 TALLOC_CTX *mem_ctx)
3204 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3207 /*******************************************************************
3208 Fill a notify_info_data with submitted time.
3209 ********************************************************************/
3211 static void spoolss_notify_submitted_time(struct messaging_context *msg_ctx,
3212 int snum,
3213 struct spoolss_Notify *data,
3214 print_queue_struct *queue,
3215 struct spoolss_PrinterInfo2 *pinfo2,
3216 TALLOC_CTX *mem_ctx)
3218 data->data.string.string = NULL;
3219 data->data.string.size = 0;
3221 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3222 &data->data.string.string,
3223 &data->data.string.size);
3227 struct s_notify_info_data_table
3229 enum spoolss_NotifyType type;
3230 uint16_t field;
3231 const char *name;
3232 enum spoolss_NotifyTable variable_type;
3233 void (*fn) (struct messaging_context *msg_ctx,
3234 int snum, struct spoolss_Notify *data,
3235 print_queue_struct *queue,
3236 struct spoolss_PrinterInfo2 *pinfo2,
3237 TALLOC_CTX *mem_ctx);
3240 /* A table describing the various print notification constants and
3241 whether the notification data is a pointer to a variable sized
3242 buffer, a one value uint32_t or a two value uint32_t. */
3244 static const struct s_notify_info_data_table notify_info_data_table[] =
3246 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3247 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3248 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3249 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3250 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3251 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3252 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3253 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3254 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3255 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3256 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3257 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3258 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3259 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3260 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3261 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3262 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3263 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3264 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3265 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3266 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3267 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3268 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3269 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3270 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3271 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3272 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3273 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3274 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3275 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3276 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3277 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3278 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3279 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3280 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3281 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3282 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3283 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3284 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3285 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3286 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3287 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3288 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3289 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3290 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3291 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3292 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3293 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3294 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3297 /*******************************************************************
3298 Return the variable_type of info_data structure.
3299 ********************************************************************/
3301 static enum spoolss_NotifyTable variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3302 uint16_t field)
3304 int i=0;
3306 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3307 if ( (notify_info_data_table[i].type == type) &&
3308 (notify_info_data_table[i].field == field) ) {
3309 return notify_info_data_table[i].variable_type;
3313 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3315 return (enum spoolss_NotifyTable) 0;
3318 /****************************************************************************
3319 ****************************************************************************/
3321 static bool search_notify(enum spoolss_NotifyType type,
3322 uint16_t field,
3323 int *value)
3325 int i;
3327 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3328 if (notify_info_data_table[i].type == type &&
3329 notify_info_data_table[i].field == field &&
3330 notify_info_data_table[i].fn != NULL) {
3331 *value = i;
3332 return true;
3336 return false;
3339 /****************************************************************************
3340 ****************************************************************************/
3342 static void construct_info_data(struct spoolss_Notify *info_data,
3343 enum spoolss_NotifyType type,
3344 uint16_t field, int id)
3346 info_data->type = type;
3347 info_data->field.field = field;
3348 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3349 info_data->job_id = id;
3352 /*******************************************************************
3354 * fill a notify_info struct with info asked
3356 ********************************************************************/
3358 static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
3359 struct printer_handle *print_hnd,
3360 struct spoolss_NotifyInfo *info,
3361 struct spoolss_PrinterInfo2 *pinfo2,
3362 int snum,
3363 const struct spoolss_NotifyOptionType *option_type,
3364 uint32_t id,
3365 TALLOC_CTX *mem_ctx)
3367 int field_num,j;
3368 enum spoolss_NotifyType type;
3369 uint16_t field;
3371 struct spoolss_Notify *current_data;
3372 print_queue_struct *queue=NULL;
3374 type = option_type->type;
3376 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3377 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3378 option_type->count, lp_servicename(snum)));
3380 for(field_num=0; field_num < option_type->count; field_num++) {
3381 field = option_type->fields[field_num].field;
3383 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3385 if (!search_notify(type, field, &j) )
3386 continue;
3388 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3389 struct spoolss_Notify,
3390 info->count + 1);
3391 if (info->notifies == NULL) {
3392 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3393 return false;
3396 current_data = &info->notifies[info->count];
3398 construct_info_data(current_data, type, field, id);
3400 DEBUG(10, ("construct_notify_printer_info: "
3401 "calling [%s] snum=%d printername=[%s])\n",
3402 notify_info_data_table[j].name, snum,
3403 pinfo2->printername));
3405 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3406 queue, pinfo2, mem_ctx);
3408 info->count++;
3411 return true;
3414 /*******************************************************************
3416 * fill a notify_info struct with info asked
3418 ********************************************************************/
3420 static bool construct_notify_jobs_info(struct messaging_context *msg_ctx,
3421 print_queue_struct *queue,
3422 struct spoolss_NotifyInfo *info,
3423 struct spoolss_PrinterInfo2 *pinfo2,
3424 int snum,
3425 const struct spoolss_NotifyOptionType *option_type,
3426 uint32_t id,
3427 TALLOC_CTX *mem_ctx)
3429 int field_num,j;
3430 enum spoolss_NotifyType type;
3431 uint16_t field;
3432 struct spoolss_Notify *current_data;
3434 DEBUG(4,("construct_notify_jobs_info\n"));
3436 type = option_type->type;
3438 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3439 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3440 option_type->count));
3442 for(field_num=0; field_num<option_type->count; field_num++) {
3443 field = option_type->fields[field_num].field;
3445 if (!search_notify(type, field, &j) )
3446 continue;
3448 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3449 struct spoolss_Notify,
3450 info->count + 1);
3451 if (info->notifies == NULL) {
3452 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3453 return false;
3456 current_data=&(info->notifies[info->count]);
3458 construct_info_data(current_data, type, field, id);
3459 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3460 queue, pinfo2, mem_ctx);
3461 info->count++;
3464 return true;
3468 * JFM: The enumeration is not that simple, it's even non obvious.
3470 * let's take an example: I want to monitor the PRINTER SERVER for
3471 * the printer's name and the number of jobs currently queued.
3472 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3473 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3475 * I have 3 printers on the back of my server.
3477 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3478 * structures.
3479 * Number Data Id
3480 * 1 printer 1 name 1
3481 * 2 printer 1 cjob 1
3482 * 3 printer 2 name 2
3483 * 4 printer 2 cjob 2
3484 * 5 printer 3 name 3
3485 * 6 printer 3 name 3
3487 * that's the print server case, the printer case is even worse.
3490 /*******************************************************************
3492 * enumerate all printers on the printserver
3493 * fill a notify_info struct with info asked
3495 ********************************************************************/
3497 static WERROR printserver_notify_info(struct pipes_struct *p,
3498 struct policy_handle *hnd,
3499 struct spoolss_NotifyInfo *info,
3500 TALLOC_CTX *mem_ctx)
3502 int snum;
3503 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3504 int n_services=lp_numservices();
3505 int i;
3506 struct spoolss_NotifyOption *option;
3507 struct spoolss_NotifyOptionType option_type;
3508 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3509 WERROR result;
3511 DEBUG(4,("printserver_notify_info\n"));
3513 if (!Printer)
3514 return WERR_BADFID;
3516 option = Printer->notify.option;
3518 info->version = 2;
3519 info->notifies = NULL;
3520 info->count = 0;
3522 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3523 sending a ffpcn() request first */
3525 if ( !option )
3526 return WERR_BADFID;
3528 for (i=0; i<option->count; i++) {
3529 option_type = option->types[i];
3531 if (option_type.type != PRINTER_NOTIFY_TYPE)
3532 continue;
3534 for (snum = 0; snum < n_services; snum++) {
3535 if (!lp_browseable(snum) ||
3536 !lp_snum_ok(snum) ||
3537 !lp_print_ok(snum)) {
3538 continue; /* skip */
3541 /* Maybe we should use the SYSTEM server_info here... */
3542 result = winreg_get_printer(mem_ctx,
3543 get_server_info_system(),
3544 p->msg_ctx,
3545 lp_servicename(snum),
3546 &pinfo2);
3547 if (!W_ERROR_IS_OK(result)) {
3548 DEBUG(4, ("printserver_notify_info: "
3549 "Failed to get printer [%s]\n",
3550 lp_servicename(snum)));
3551 continue;
3555 construct_notify_printer_info(p->msg_ctx,
3556 Printer, info,
3557 pinfo2, snum,
3558 &option_type, snum,
3559 mem_ctx);
3561 TALLOC_FREE(pinfo2);
3565 #if 0
3567 * Debugging information, don't delete.
3570 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3571 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3572 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3574 for (i=0; i<info->count; i++) {
3575 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3576 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3577 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3579 #endif
3581 return WERR_OK;
3584 /*******************************************************************
3586 * fill a notify_info struct with info asked
3588 ********************************************************************/
3590 static WERROR printer_notify_info(struct pipes_struct *p,
3591 struct policy_handle *hnd,
3592 struct spoolss_NotifyInfo *info,
3593 TALLOC_CTX *mem_ctx)
3595 int snum;
3596 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3597 int i;
3598 uint32_t id;
3599 struct spoolss_NotifyOption *option;
3600 struct spoolss_NotifyOptionType option_type;
3601 int count,j;
3602 print_queue_struct *queue=NULL;
3603 print_status_struct status;
3604 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3605 WERROR result;
3607 DEBUG(4,("printer_notify_info\n"));
3609 if (!Printer)
3610 return WERR_BADFID;
3612 option = Printer->notify.option;
3613 id = 0x0;
3615 info->version = 2;
3616 info->notifies = NULL;
3617 info->count = 0;
3619 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3620 sending a ffpcn() request first */
3622 if ( !option )
3623 return WERR_BADFID;
3625 get_printer_snum(p, hnd, &snum, NULL);
3627 /* Maybe we should use the SYSTEM server_info here... */
3628 result = winreg_get_printer(mem_ctx,
3629 get_server_info_system(),
3630 p->msg_ctx,
3631 lp_servicename(snum), &pinfo2);
3632 if (!W_ERROR_IS_OK(result)) {
3633 return WERR_BADFID;
3636 for (i=0; i<option->count; i++) {
3637 option_type = option->types[i];
3639 switch (option_type.type) {
3640 case PRINTER_NOTIFY_TYPE:
3641 if (construct_notify_printer_info(p->msg_ctx,
3642 Printer, info,
3643 pinfo2, snum,
3644 &option_type, id,
3645 mem_ctx)) {
3646 id--;
3648 break;
3650 case JOB_NOTIFY_TYPE:
3652 count = print_queue_status(p->msg_ctx, snum, &queue,
3653 &status);
3655 for (j=0; j<count; j++) {
3656 construct_notify_jobs_info(p->msg_ctx,
3657 &queue[j], info,
3658 pinfo2, snum,
3659 &option_type,
3660 queue[j].job,
3661 mem_ctx);
3664 SAFE_FREE(queue);
3665 break;
3670 * Debugging information, don't delete.
3673 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3674 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3675 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3677 for (i=0; i<info->count; i++) {
3678 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3679 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3680 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3684 talloc_free(pinfo2);
3685 return WERR_OK;
3688 /****************************************************************
3689 _spoolss_RouterRefreshPrinterChangeNotify
3690 ****************************************************************/
3692 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3693 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3695 struct spoolss_NotifyInfo *info;
3697 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
3698 WERROR result = WERR_BADFID;
3700 /* we always have a spoolss_NotifyInfo struct */
3701 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3702 if (!info) {
3703 result = WERR_NOMEM;
3704 goto done;
3707 *r->out.info = info;
3709 if (!Printer) {
3710 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3711 "Invalid handle (%s:%u:%u).\n",
3712 OUR_HANDLE(r->in.handle)));
3713 goto done;
3716 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3719 * We are now using the change value, and
3720 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3721 * I don't have a global notification system, I'm sending back all the
3722 * informations even when _NOTHING_ has changed.
3725 /* We need to keep track of the change value to send back in
3726 RRPCN replies otherwise our updates are ignored. */
3728 Printer->notify.fnpcn = true;
3730 if (Printer->notify.cli_chan != NULL &&
3731 Printer->notify.cli_chan->active_connections > 0) {
3732 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3733 "Saving change value in request [%x]\n",
3734 r->in.change_low));
3735 Printer->notify.change = r->in.change_low;
3738 /* just ignore the spoolss_NotifyOption */
3740 switch (Printer->printer_type) {
3741 case SPLHND_SERVER:
3742 result = printserver_notify_info(p, r->in.handle,
3743 info, p->mem_ctx);
3744 break;
3746 case SPLHND_PRINTER:
3747 result = printer_notify_info(p, r->in.handle,
3748 info, p->mem_ctx);
3749 break;
3752 Printer->notify.fnpcn = false;
3754 done:
3755 return result;
3758 /********************************************************************
3759 ********************************************************************/
3761 static WERROR create_printername(TALLOC_CTX *mem_ctx,
3762 const char *servername,
3763 const char *printername,
3764 const char **printername_p)
3766 /* FIXME: add lp_force_printername() */
3768 if (servername == NULL) {
3769 *printername_p = talloc_strdup(mem_ctx, printername);
3770 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3771 return WERR_OK;
3774 if (servername[0] == '\\' && servername[1] == '\\') {
3775 servername += 2;
3778 *printername_p = talloc_asprintf(mem_ctx, "\\\\%s\\%s", servername, printername);
3779 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3781 return WERR_OK;
3784 /********************************************************************
3785 ********************************************************************/
3787 static void compose_devicemode_devicename(struct spoolss_DeviceMode *dm,
3788 const char *printername)
3790 if (dm == NULL) {
3791 return;
3794 dm->devicename = talloc_strndup(dm, printername,
3795 MIN(strlen(printername), 31));
3798 /********************************************************************
3799 * construct_printer_info_0
3800 * fill a printer_info_0 struct
3801 ********************************************************************/
3803 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3804 const struct auth_serversupplied_info *server_info,
3805 struct messaging_context *msg_ctx,
3806 struct spoolss_PrinterInfo2 *info2,
3807 const char *servername,
3808 struct spoolss_PrinterInfo0 *r,
3809 int snum)
3811 int count;
3812 struct printer_session_counter *session_counter;
3813 struct timeval setuptime;
3814 print_status_struct status;
3815 WERROR result;
3817 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3818 if (!W_ERROR_IS_OK(result)) {
3819 return result;
3822 if (servername) {
3823 r->servername = talloc_strdup(mem_ctx, servername);
3824 W_ERROR_HAVE_NO_MEMORY(r->servername);
3825 } else {
3826 r->servername = NULL;
3829 count = print_queue_length(msg_ctx, snum, &status);
3831 /* check if we already have a counter for this printer */
3832 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3833 if (session_counter->snum == snum)
3834 break;
3837 /* it's the first time, add it to the list */
3838 if (session_counter == NULL) {
3839 session_counter = talloc_zero(counter_list, struct printer_session_counter);
3840 W_ERROR_HAVE_NO_MEMORY(session_counter);
3841 session_counter->snum = snum;
3842 session_counter->counter = 0;
3843 DLIST_ADD(counter_list, session_counter);
3846 /* increment it */
3847 session_counter->counter++;
3849 r->cjobs = count;
3850 r->total_jobs = 0;
3851 r->total_bytes = 0;
3853 get_startup_time(&setuptime);
3854 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3856 /* JFM:
3857 * the global_counter should be stored in a TDB as it's common to all the clients
3858 * and should be zeroed on samba startup
3860 r->global_counter = session_counter->counter;
3861 r->total_pages = 0;
3862 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3863 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3864 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3865 r->free_build = SPOOLSS_RELEASE_BUILD;
3866 r->spooling = 0;
3867 r->max_spooling = 0;
3868 r->session_counter = session_counter->counter;
3869 r->num_error_out_of_paper = 0x0;
3870 r->num_error_not_ready = 0x0; /* number of print failure */
3871 r->job_error = 0x0;
3872 r->number_of_processors = 0x1;
3873 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3874 r->high_part_total_bytes = 0x0;
3876 /* ChangeID in milliseconds*/
3877 winreg_printer_get_changeid(mem_ctx, server_info, msg_ctx,
3878 info2->sharename, &r->change_id);
3880 r->last_error = WERR_OK;
3881 r->status = nt_printq_status(status.status);
3882 r->enumerate_network_printers = 0x0;
3883 r->c_setprinter = 0x0;
3884 r->processor_architecture = PROCESSOR_ARCHITECTURE_INTEL;
3885 r->processor_level = 0x6; /* 6 ???*/
3886 r->ref_ic = 0;
3887 r->reserved2 = 0;
3888 r->reserved3 = 0;
3890 return WERR_OK;
3894 /********************************************************************
3895 * construct_printer_info1
3896 * fill a spoolss_PrinterInfo1 struct
3897 ********************************************************************/
3899 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3900 const struct spoolss_PrinterInfo2 *info2,
3901 uint32_t flags,
3902 const char *servername,
3903 struct spoolss_PrinterInfo1 *r,
3904 int snum)
3906 WERROR result;
3908 r->flags = flags;
3910 if (info2->comment == NULL || info2->comment[0] == '\0') {
3911 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3912 } else {
3913 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3915 W_ERROR_HAVE_NO_MEMORY(r->comment);
3917 result = create_printername(mem_ctx, servername, info2->printername, &r->name);
3918 if (!W_ERROR_IS_OK(result)) {
3919 return result;
3922 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3923 r->name,
3924 info2->drivername,
3925 r->comment);
3926 W_ERROR_HAVE_NO_MEMORY(r->description);
3928 return WERR_OK;
3931 /********************************************************************
3932 * construct_printer_info2
3933 * fill a spoolss_PrinterInfo2 struct
3934 ********************************************************************/
3936 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3937 struct messaging_context *msg_ctx,
3938 const struct spoolss_PrinterInfo2 *info2,
3939 const char *servername,
3940 struct spoolss_PrinterInfo2 *r,
3941 int snum)
3943 int count;
3944 print_status_struct status;
3945 WERROR result;
3947 count = print_queue_length(msg_ctx, snum, &status);
3949 if (servername) {
3950 r->servername = talloc_strdup(mem_ctx, servername);
3951 W_ERROR_HAVE_NO_MEMORY(r->servername);
3952 } else {
3953 r->servername = NULL;
3956 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3957 if (!W_ERROR_IS_OK(result)) {
3958 return result;
3961 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3962 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3963 r->portname = talloc_strdup(mem_ctx, info2->portname);
3964 W_ERROR_HAVE_NO_MEMORY(r->portname);
3965 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
3966 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3968 if (info2->comment[0] == '\0') {
3969 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3970 } else {
3971 r->comment = talloc_strdup(mem_ctx, info2->comment);
3973 W_ERROR_HAVE_NO_MEMORY(r->comment);
3975 r->location = talloc_strdup(mem_ctx, info2->location);
3976 W_ERROR_HAVE_NO_MEMORY(r->location);
3977 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
3978 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3979 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
3980 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3981 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
3982 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3983 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
3984 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3986 r->attributes = info2->attributes;
3988 r->priority = info2->priority;
3989 r->defaultpriority = info2->defaultpriority;
3990 r->starttime = info2->starttime;
3991 r->untiltime = info2->untiltime;
3992 r->status = nt_printq_status(status.status);
3993 r->cjobs = count;
3994 r->averageppm = info2->averageppm;
3996 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3997 if (!r->devmode) {
3998 DEBUG(8,("Returning NULL Devicemode!\n"));
4001 compose_devicemode_devicename(r->devmode, r->printername);
4003 r->secdesc = NULL;
4005 if (info2->secdesc != NULL) {
4006 /* don't use talloc_steal() here unless you do a deep steal of all
4007 the SEC_DESC members */
4009 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4012 return WERR_OK;
4015 /********************************************************************
4016 * construct_printer_info3
4017 * fill a spoolss_PrinterInfo3 struct
4018 ********************************************************************/
4020 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
4021 const struct spoolss_PrinterInfo2 *info2,
4022 const char *servername,
4023 struct spoolss_PrinterInfo3 *r,
4024 int snum)
4026 /* These are the components of the SD we are returning. */
4028 if (info2->secdesc != NULL) {
4029 /* don't use talloc_steal() here unless you do a deep steal of all
4030 the SEC_DESC members */
4032 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4033 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
4036 return WERR_OK;
4039 /********************************************************************
4040 * construct_printer_info4
4041 * fill a spoolss_PrinterInfo4 struct
4042 ********************************************************************/
4044 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4045 const struct spoolss_PrinterInfo2 *info2,
4046 const char *servername,
4047 struct spoolss_PrinterInfo4 *r,
4048 int snum)
4050 WERROR result;
4052 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4053 if (!W_ERROR_IS_OK(result)) {
4054 return result;
4057 if (servername) {
4058 r->servername = talloc_strdup(mem_ctx, servername);
4059 W_ERROR_HAVE_NO_MEMORY(r->servername);
4060 } else {
4061 r->servername = NULL;
4064 r->attributes = info2->attributes;
4066 return WERR_OK;
4069 /********************************************************************
4070 * construct_printer_info5
4071 * fill a spoolss_PrinterInfo5 struct
4072 ********************************************************************/
4074 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4075 const struct spoolss_PrinterInfo2 *info2,
4076 const char *servername,
4077 struct spoolss_PrinterInfo5 *r,
4078 int snum)
4080 WERROR result;
4082 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4083 if (!W_ERROR_IS_OK(result)) {
4084 return result;
4087 r->portname = talloc_strdup(mem_ctx, info2->portname);
4088 W_ERROR_HAVE_NO_MEMORY(r->portname);
4090 r->attributes = info2->attributes;
4092 /* these two are not used by NT+ according to MSDN */
4093 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4094 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4096 return WERR_OK;
4099 /********************************************************************
4100 * construct_printer_info_6
4101 * fill a spoolss_PrinterInfo6 struct
4102 ********************************************************************/
4104 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4105 struct messaging_context *msg_ctx,
4106 const struct spoolss_PrinterInfo2 *info2,
4107 const char *servername,
4108 struct spoolss_PrinterInfo6 *r,
4109 int snum)
4111 int count;
4112 print_status_struct status;
4114 count = print_queue_length(msg_ctx, snum, &status);
4116 r->status = nt_printq_status(status.status);
4118 return WERR_OK;
4121 /********************************************************************
4122 * construct_printer_info7
4123 * fill a spoolss_PrinterInfo7 struct
4124 ********************************************************************/
4126 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4127 struct messaging_context *msg_ctx,
4128 const char *servername,
4129 struct spoolss_PrinterInfo7 *r,
4130 int snum)
4132 struct auth_serversupplied_info *server_info;
4133 struct GUID guid;
4134 NTSTATUS status;
4136 status = make_server_info_system(mem_ctx, &server_info);
4137 if (!NT_STATUS_IS_OK(status)) {
4138 DEBUG(0, ("construct_printer_info7: "
4139 "Could not create system server_info\n"));
4140 return WERR_NOMEM;
4143 if (is_printer_published(mem_ctx, server_info, msg_ctx,
4144 servername,
4145 lp_servicename(snum), &guid, NULL)) {
4146 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4147 r->action = DSPRINT_PUBLISH;
4148 } else {
4149 r->guid = talloc_strdup(mem_ctx, "");
4150 r->action = DSPRINT_UNPUBLISH;
4152 W_ERROR_HAVE_NO_MEMORY(r->guid);
4154 TALLOC_FREE(server_info);
4155 return WERR_OK;
4158 /********************************************************************
4159 * construct_printer_info8
4160 * fill a spoolss_PrinterInfo8 struct
4161 ********************************************************************/
4163 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4164 const struct spoolss_PrinterInfo2 *info2,
4165 const char *servername,
4166 struct spoolss_DeviceModeInfo *r,
4167 int snum)
4169 WERROR result;
4170 const char *printername;
4172 result = create_printername(mem_ctx, servername, info2->printername, &printername);
4173 if (!W_ERROR_IS_OK(result)) {
4174 return result;
4177 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
4178 if (!r->devmode) {
4179 DEBUG(8,("Returning NULL Devicemode!\n"));
4182 compose_devicemode_devicename(r->devmode, printername);
4184 return WERR_OK;
4188 /********************************************************************
4189 ********************************************************************/
4191 static bool snum_is_shared_printer(int snum)
4193 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4196 /********************************************************************
4197 Spoolss_enumprinters.
4198 ********************************************************************/
4200 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4201 const struct auth_serversupplied_info *server_info,
4202 struct messaging_context *msg_ctx,
4203 const char *servername,
4204 uint32_t level,
4205 uint32_t flags,
4206 union spoolss_PrinterInfo **info_p,
4207 uint32_t *count_p)
4209 int snum;
4210 int n_services = lp_numservices();
4211 union spoolss_PrinterInfo *info = NULL;
4212 uint32_t count = 0;
4213 WERROR result = WERR_OK;
4215 *count_p = 0;
4216 *info_p = NULL;
4218 for (snum = 0; snum < n_services; snum++) {
4220 const char *printer;
4221 struct spoolss_PrinterInfo2 *info2;
4223 if (!snum_is_shared_printer(snum)) {
4224 continue;
4227 printer = lp_const_servicename(snum);
4229 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4230 printer, snum));
4232 result = winreg_create_printer(mem_ctx,
4233 server_info,
4234 msg_ctx,
4235 printer);
4236 if (!W_ERROR_IS_OK(result)) {
4237 goto out;
4240 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4241 union spoolss_PrinterInfo,
4242 count + 1);
4243 if (!info) {
4244 result = WERR_NOMEM;
4245 goto out;
4248 result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
4249 printer, &info2);
4250 if (!W_ERROR_IS_OK(result)) {
4251 goto out;
4254 switch (level) {
4255 case 0:
4256 result = construct_printer_info0(info, server_info,
4257 msg_ctx, info2,
4258 servername,
4259 &info[count].info0, snum);
4260 break;
4261 case 1:
4262 result = construct_printer_info1(info, info2, flags,
4263 servername,
4264 &info[count].info1, snum);
4265 break;
4266 case 2:
4267 result = construct_printer_info2(info, msg_ctx, info2,
4268 servername,
4269 &info[count].info2, snum);
4270 break;
4271 case 4:
4272 result = construct_printer_info4(info, info2,
4273 servername,
4274 &info[count].info4, snum);
4275 break;
4276 case 5:
4277 result = construct_printer_info5(info, info2,
4278 servername,
4279 &info[count].info5, snum);
4280 break;
4282 default:
4283 result = WERR_UNKNOWN_LEVEL;
4284 goto out;
4287 if (!W_ERROR_IS_OK(result)) {
4288 goto out;
4291 count++;
4294 *count_p = count;
4295 *info_p = info;
4297 out:
4298 if (!W_ERROR_IS_OK(result)) {
4299 TALLOC_FREE(info);
4300 return result;
4303 *info_p = info;
4305 return WERR_OK;
4308 /********************************************************************
4309 * handle enumeration of printers at level 0
4310 ********************************************************************/
4312 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4313 const struct auth_serversupplied_info *server_info,
4314 struct messaging_context *msg_ctx,
4315 uint32_t flags,
4316 const char *servername,
4317 union spoolss_PrinterInfo **info,
4318 uint32_t *count)
4320 DEBUG(4,("enum_all_printers_info_0\n"));
4322 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4323 servername, 0, flags, info, count);
4327 /********************************************************************
4328 ********************************************************************/
4330 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4331 const struct auth_serversupplied_info *server_info,
4332 struct messaging_context *msg_ctx,
4333 const char *servername,
4334 uint32_t flags,
4335 union spoolss_PrinterInfo **info,
4336 uint32_t *count)
4338 DEBUG(4,("enum_all_printers_info_1\n"));
4340 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4341 servername, 1, flags, info, count);
4344 /********************************************************************
4345 enum_all_printers_info_1_local.
4346 *********************************************************************/
4348 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4349 const struct auth_serversupplied_info *server_info,
4350 struct messaging_context *msg_ctx,
4351 const char *servername,
4352 union spoolss_PrinterInfo **info,
4353 uint32_t *count)
4355 DEBUG(4,("enum_all_printers_info_1_local\n"));
4357 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4358 servername, PRINTER_ENUM_ICON8, info, count);
4361 /********************************************************************
4362 enum_all_printers_info_1_name.
4363 *********************************************************************/
4365 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4366 const struct auth_serversupplied_info *server_info,
4367 struct messaging_context *msg_ctx,
4368 const char *servername,
4369 union spoolss_PrinterInfo **info,
4370 uint32_t *count)
4372 const char *s = servername;
4374 DEBUG(4,("enum_all_printers_info_1_name\n"));
4376 if ((servername[0] == '\\') && (servername[1] == '\\')) {
4377 s = servername + 2;
4380 if (!is_myname_or_ipaddr(s)) {
4381 return WERR_INVALID_NAME;
4384 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4385 servername, PRINTER_ENUM_ICON8, info, count);
4388 /********************************************************************
4389 enum_all_printers_info_1_network.
4390 *********************************************************************/
4392 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4393 const struct auth_serversupplied_info *server_info,
4394 struct messaging_context *msg_ctx,
4395 const char *servername,
4396 union spoolss_PrinterInfo **info,
4397 uint32_t *count)
4399 const char *s = servername;
4401 DEBUG(4,("enum_all_printers_info_1_network\n"));
4403 /* If we respond to a enum_printers level 1 on our name with flags
4404 set to PRINTER_ENUM_REMOTE with a list of printers then these
4405 printers incorrectly appear in the APW browse list.
4406 Specifically the printers for the server appear at the workgroup
4407 level where all the other servers in the domain are
4408 listed. Windows responds to this call with a
4409 WERR_CAN_NOT_COMPLETE so we should do the same. */
4411 if (servername[0] == '\\' && servername[1] == '\\') {
4412 s = servername + 2;
4415 if (is_myname_or_ipaddr(s)) {
4416 return WERR_CAN_NOT_COMPLETE;
4419 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4420 servername, PRINTER_ENUM_NAME, info, count);
4423 /********************************************************************
4424 * api_spoolss_enumprinters
4426 * called from api_spoolss_enumprinters (see this to understand)
4427 ********************************************************************/
4429 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4430 const struct auth_serversupplied_info *server_info,
4431 struct messaging_context *msg_ctx,
4432 const char *servername,
4433 union spoolss_PrinterInfo **info,
4434 uint32_t *count)
4436 DEBUG(4,("enum_all_printers_info_2\n"));
4438 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4439 servername, 2, 0, info, count);
4442 /********************************************************************
4443 * handle enumeration of printers at level 1
4444 ********************************************************************/
4446 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4447 const struct auth_serversupplied_info *server_info,
4448 struct messaging_context *msg_ctx,
4449 uint32_t flags,
4450 const char *servername,
4451 union spoolss_PrinterInfo **info,
4452 uint32_t *count)
4454 /* Not all the flags are equals */
4456 if (flags & PRINTER_ENUM_LOCAL) {
4457 return enum_all_printers_info_1_local(mem_ctx, server_info,
4458 msg_ctx, servername, info, count);
4461 if (flags & PRINTER_ENUM_NAME) {
4462 return enum_all_printers_info_1_name(mem_ctx, server_info,
4463 msg_ctx, servername, info,
4464 count);
4467 if (flags & PRINTER_ENUM_NETWORK) {
4468 return enum_all_printers_info_1_network(mem_ctx, server_info,
4469 msg_ctx, servername, info,
4470 count);
4473 return WERR_OK; /* NT4sp5 does that */
4476 /********************************************************************
4477 * handle enumeration of printers at level 2
4478 ********************************************************************/
4480 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4481 const struct auth_serversupplied_info *server_info,
4482 struct messaging_context *msg_ctx,
4483 uint32_t flags,
4484 const char *servername,
4485 union spoolss_PrinterInfo **info,
4486 uint32_t *count)
4488 if (flags & PRINTER_ENUM_LOCAL) {
4490 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4491 servername,
4492 info, count);
4495 if (flags & PRINTER_ENUM_NAME) {
4496 if (servername && !is_myname_or_ipaddr(canon_servername(servername))) {
4497 return WERR_INVALID_NAME;
4500 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4501 servername,
4502 info, count);
4505 if (flags & PRINTER_ENUM_REMOTE) {
4506 return WERR_UNKNOWN_LEVEL;
4509 return WERR_OK;
4512 /********************************************************************
4513 * handle enumeration of printers at level 4
4514 ********************************************************************/
4516 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4517 const struct auth_serversupplied_info *server_info,
4518 struct messaging_context *msg_ctx,
4519 uint32_t flags,
4520 const char *servername,
4521 union spoolss_PrinterInfo **info,
4522 uint32_t *count)
4524 DEBUG(4,("enum_all_printers_info_4\n"));
4526 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4527 servername, 4, flags, info, count);
4531 /********************************************************************
4532 * handle enumeration of printers at level 5
4533 ********************************************************************/
4535 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4536 const struct auth_serversupplied_info *server_info,
4537 struct messaging_context *msg_ctx,
4538 uint32_t flags,
4539 const char *servername,
4540 union spoolss_PrinterInfo **info,
4541 uint32_t *count)
4543 DEBUG(4,("enum_all_printers_info_5\n"));
4545 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4546 servername, 5, flags, info, count);
4549 /****************************************************************
4550 _spoolss_EnumPrinters
4551 ****************************************************************/
4553 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4554 struct spoolss_EnumPrinters *r)
4556 const struct auth_serversupplied_info *server_info = get_server_info_system();
4557 WERROR result;
4559 /* that's an [in out] buffer */
4561 if (!r->in.buffer && (r->in.offered != 0)) {
4562 return WERR_INVALID_PARAM;
4565 DEBUG(4,("_spoolss_EnumPrinters\n"));
4567 *r->out.needed = 0;
4568 *r->out.count = 0;
4569 *r->out.info = NULL;
4572 * Level 1:
4573 * flags==PRINTER_ENUM_NAME
4574 * if name=="" then enumerates all printers
4575 * if name!="" then enumerate the printer
4576 * flags==PRINTER_ENUM_REMOTE
4577 * name is NULL, enumerate printers
4578 * Level 2: name!="" enumerates printers, name can't be NULL
4579 * Level 3: doesn't exist
4580 * Level 4: does a local registry lookup
4581 * Level 5: same as Level 2
4584 if (r->in.server && r->in.server[0] == '\0') {
4585 r->in.server = NULL;
4588 switch (r->in.level) {
4589 case 0:
4590 result = enumprinters_level0(p->mem_ctx, server_info,
4591 p->msg_ctx, r->in.flags,
4592 r->in.server,
4593 r->out.info, r->out.count);
4594 break;
4595 case 1:
4596 result = enumprinters_level1(p->mem_ctx, server_info,
4597 p->msg_ctx, r->in.flags,
4598 r->in.server,
4599 r->out.info, r->out.count);
4600 break;
4601 case 2:
4602 result = enumprinters_level2(p->mem_ctx, server_info,
4603 p->msg_ctx, r->in.flags,
4604 r->in.server,
4605 r->out.info, r->out.count);
4606 break;
4607 case 4:
4608 result = enumprinters_level4(p->mem_ctx, server_info,
4609 p->msg_ctx, r->in.flags,
4610 r->in.server,
4611 r->out.info, r->out.count);
4612 break;
4613 case 5:
4614 result = enumprinters_level5(p->mem_ctx, server_info,
4615 p->msg_ctx, r->in.flags,
4616 r->in.server,
4617 r->out.info, r->out.count);
4618 break;
4619 default:
4620 return WERR_UNKNOWN_LEVEL;
4623 if (!W_ERROR_IS_OK(result)) {
4624 return result;
4627 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4628 spoolss_EnumPrinters,
4629 *r->out.info, r->in.level,
4630 *r->out.count);
4631 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4632 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4634 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4637 /****************************************************************
4638 _spoolss_GetPrinter
4639 ****************************************************************/
4641 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4642 struct spoolss_GetPrinter *r)
4644 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
4645 struct spoolss_PrinterInfo2 *info2 = NULL;
4646 WERROR result = WERR_OK;
4647 int snum;
4649 /* that's an [in out] buffer */
4651 if (!r->in.buffer && (r->in.offered != 0)) {
4652 return WERR_INVALID_PARAM;
4655 *r->out.needed = 0;
4657 if (Printer == NULL) {
4658 return WERR_BADFID;
4661 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4662 return WERR_BADFID;
4665 result = winreg_get_printer(p->mem_ctx,
4666 get_server_info_system(),
4667 p->msg_ctx,
4668 lp_const_servicename(snum),
4669 &info2);
4670 if (!W_ERROR_IS_OK(result)) {
4671 goto out;
4674 switch (r->in.level) {
4675 case 0:
4676 result = construct_printer_info0(p->mem_ctx,
4677 get_server_info_system(),
4678 p->msg_ctx,
4679 info2,
4680 Printer->servername,
4681 &r->out.info->info0,
4682 snum);
4683 break;
4684 case 1:
4685 result = construct_printer_info1(p->mem_ctx, info2,
4686 PRINTER_ENUM_ICON8,
4687 Printer->servername,
4688 &r->out.info->info1, snum);
4689 break;
4690 case 2:
4691 result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
4692 Printer->servername,
4693 &r->out.info->info2, snum);
4694 break;
4695 case 3:
4696 result = construct_printer_info3(p->mem_ctx, info2,
4697 Printer->servername,
4698 &r->out.info->info3, snum);
4699 break;
4700 case 4:
4701 result = construct_printer_info4(p->mem_ctx, info2,
4702 Printer->servername,
4703 &r->out.info->info4, snum);
4704 break;
4705 case 5:
4706 result = construct_printer_info5(p->mem_ctx, info2,
4707 Printer->servername,
4708 &r->out.info->info5, snum);
4709 break;
4710 case 6:
4711 result = construct_printer_info6(p->mem_ctx, p->msg_ctx, info2,
4712 Printer->servername,
4713 &r->out.info->info6, snum);
4714 break;
4715 case 7:
4716 result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
4717 Printer->servername,
4718 &r->out.info->info7, snum);
4719 break;
4720 case 8:
4721 result = construct_printer_info8(p->mem_ctx, info2,
4722 Printer->servername,
4723 &r->out.info->info8, snum);
4724 break;
4725 default:
4726 result = WERR_UNKNOWN_LEVEL;
4727 break;
4730 out:
4731 if (!W_ERROR_IS_OK(result)) {
4732 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4733 r->in.level, win_errstr(result)));
4734 TALLOC_FREE(r->out.info);
4735 return result;
4738 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4739 r->out.info, r->in.level);
4740 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4742 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4745 /********************************************************************
4746 ********************************************************************/
4748 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4749 do { \
4750 if (in && strlen(in)) { \
4751 out = talloc_strdup(mem_ctx, in); \
4752 } else { \
4753 out = talloc_strdup(mem_ctx, ""); \
4755 W_ERROR_HAVE_NO_MEMORY(out); \
4756 } while (0);
4758 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4759 do { \
4760 if (in && strlen(in)) { \
4761 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4762 } else { \
4763 out = talloc_strdup(mem_ctx, ""); \
4765 W_ERROR_HAVE_NO_MEMORY(out); \
4766 } while (0);
4768 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4769 const char **string_array,
4770 const char ***presult,
4771 const char *cservername,
4772 const char *arch,
4773 int version)
4775 int i, num_strings = 0;
4776 const char **array = NULL;
4778 if (string_array == NULL) {
4779 return WERR_INVALID_PARAMETER;;
4782 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4783 const char *str = NULL;
4785 if (cservername == NULL || arch == NULL) {
4786 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4787 } else {
4788 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4791 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4792 TALLOC_FREE(array);
4793 return WERR_NOMEM;
4797 if (i > 0) {
4798 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4799 &array, &num_strings);
4802 if (presult) {
4803 *presult = array;
4806 return WERR_OK;
4809 /********************************************************************
4810 * fill a spoolss_DriverInfo1 struct
4811 ********************************************************************/
4813 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4814 struct spoolss_DriverInfo1 *r,
4815 const struct spoolss_DriverInfo8 *driver,
4816 const char *servername)
4818 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4819 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4821 return WERR_OK;
4824 /********************************************************************
4825 * fill a spoolss_DriverInfo2 struct
4826 ********************************************************************/
4828 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4829 struct spoolss_DriverInfo2 *r,
4830 const struct spoolss_DriverInfo8 *driver,
4831 const char *servername)
4834 const char *cservername = canon_servername(servername);
4836 r->version = driver->version;
4838 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4839 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4840 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4841 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4843 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4844 driver->architecture,
4845 driver->version,
4846 driver->driver_path,
4847 r->driver_path);
4849 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4850 driver->architecture,
4851 driver->version,
4852 driver->data_file,
4853 r->data_file);
4855 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4856 driver->architecture,
4857 driver->version,
4858 driver->config_file,
4859 r->config_file);
4861 return WERR_OK;
4864 /********************************************************************
4865 * fill a spoolss_DriverInfo3 struct
4866 ********************************************************************/
4868 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4869 struct spoolss_DriverInfo3 *r,
4870 const struct spoolss_DriverInfo8 *driver,
4871 const char *servername)
4873 const char *cservername = canon_servername(servername);
4875 r->version = driver->version;
4877 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4878 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4879 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4880 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4882 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4883 driver->architecture,
4884 driver->version,
4885 driver->driver_path,
4886 r->driver_path);
4888 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4889 driver->architecture,
4890 driver->version,
4891 driver->data_file,
4892 r->data_file);
4894 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4895 driver->architecture,
4896 driver->version,
4897 driver->config_file,
4898 r->config_file);
4900 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4901 driver->architecture,
4902 driver->version,
4903 driver->help_file,
4904 r->help_file);
4906 FILL_DRIVER_STRING(mem_ctx,
4907 driver->monitor_name,
4908 r->monitor_name);
4910 FILL_DRIVER_STRING(mem_ctx,
4911 driver->default_datatype,
4912 r->default_datatype);
4914 return string_array_from_driver_info(mem_ctx,
4915 driver->dependent_files,
4916 &r->dependent_files,
4917 cservername,
4918 driver->architecture,
4919 driver->version);
4922 /********************************************************************
4923 * fill a spoolss_DriverInfo4 struct
4924 ********************************************************************/
4926 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4927 struct spoolss_DriverInfo4 *r,
4928 const struct spoolss_DriverInfo8 *driver,
4929 const char *servername)
4931 const char *cservername = canon_servername(servername);
4932 WERROR result;
4934 r->version = driver->version;
4936 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4937 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4938 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4939 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4941 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4942 driver->architecture,
4943 driver->version,
4944 driver->driver_path,
4945 r->driver_path);
4947 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4948 driver->architecture,
4949 driver->version,
4950 driver->data_file,
4951 r->data_file);
4953 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4954 driver->architecture,
4955 driver->version,
4956 driver->config_file,
4957 r->config_file);
4959 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4960 driver->architecture,
4961 driver->version,
4962 driver->help_file,
4963 r->help_file);
4965 result = string_array_from_driver_info(mem_ctx,
4966 driver->dependent_files,
4967 &r->dependent_files,
4968 cservername,
4969 driver->architecture,
4970 driver->version);
4971 if (!W_ERROR_IS_OK(result)) {
4972 return result;
4975 FILL_DRIVER_STRING(mem_ctx,
4976 driver->monitor_name,
4977 r->monitor_name);
4979 FILL_DRIVER_STRING(mem_ctx,
4980 driver->default_datatype,
4981 r->default_datatype);
4984 result = string_array_from_driver_info(mem_ctx,
4985 driver->previous_names,
4986 &r->previous_names,
4987 NULL, NULL, 0);
4989 return result;
4992 /********************************************************************
4993 * fill a spoolss_DriverInfo5 struct
4994 ********************************************************************/
4996 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4997 struct spoolss_DriverInfo5 *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 r->driver_attributes = 0;
5029 r->config_version = 0;
5030 r->driver_version = 0;
5032 return WERR_OK;
5034 /********************************************************************
5035 * fill a spoolss_DriverInfo6 struct
5036 ********************************************************************/
5038 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
5039 struct spoolss_DriverInfo6 *r,
5040 const struct spoolss_DriverInfo8 *driver,
5041 const char *servername)
5043 const char *cservername = canon_servername(servername);
5044 WERROR result;
5046 r->version = driver->version;
5048 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5049 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5050 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5051 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5053 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5054 driver->architecture,
5055 driver->version,
5056 driver->driver_path,
5057 r->driver_path);
5059 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5060 driver->architecture,
5061 driver->version,
5062 driver->data_file,
5063 r->data_file);
5065 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5066 driver->architecture,
5067 driver->version,
5068 driver->config_file,
5069 r->config_file);
5071 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5072 driver->architecture,
5073 driver->version,
5074 driver->help_file,
5075 r->help_file);
5077 FILL_DRIVER_STRING(mem_ctx,
5078 driver->monitor_name,
5079 r->monitor_name);
5081 FILL_DRIVER_STRING(mem_ctx,
5082 driver->default_datatype,
5083 r->default_datatype);
5085 result = string_array_from_driver_info(mem_ctx,
5086 driver->dependent_files,
5087 &r->dependent_files,
5088 cservername,
5089 driver->architecture,
5090 driver->version);
5091 if (!W_ERROR_IS_OK(result)) {
5092 return result;
5095 result = string_array_from_driver_info(mem_ctx,
5096 driver->previous_names,
5097 &r->previous_names,
5098 NULL, NULL, 0);
5099 if (!W_ERROR_IS_OK(result)) {
5100 return result;
5103 r->driver_date = driver->driver_date;
5104 r->driver_version = driver->driver_version;
5106 FILL_DRIVER_STRING(mem_ctx,
5107 driver->manufacturer_name,
5108 r->manufacturer_name);
5109 FILL_DRIVER_STRING(mem_ctx,
5110 driver->manufacturer_url,
5111 r->manufacturer_url);
5112 FILL_DRIVER_STRING(mem_ctx,
5113 driver->hardware_id,
5114 r->hardware_id);
5115 FILL_DRIVER_STRING(mem_ctx,
5116 driver->provider,
5117 r->provider);
5119 return WERR_OK;
5122 /********************************************************************
5123 * fill a spoolss_DriverInfo8 struct
5124 ********************************************************************/
5126 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
5127 struct spoolss_DriverInfo8 *r,
5128 const struct spoolss_DriverInfo8 *driver,
5129 const char *servername)
5131 const char *cservername = canon_servername(servername);
5132 WERROR result;
5134 r->version = driver->version;
5136 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5137 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5138 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5139 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5141 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5142 driver->architecture,
5143 driver->version,
5144 driver->driver_path,
5145 r->driver_path);
5147 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5148 driver->architecture,
5149 driver->version,
5150 driver->data_file,
5151 r->data_file);
5153 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5154 driver->architecture,
5155 driver->version,
5156 driver->config_file,
5157 r->config_file);
5159 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5160 driver->architecture,
5161 driver->version,
5162 driver->help_file,
5163 r->help_file);
5165 FILL_DRIVER_STRING(mem_ctx,
5166 driver->monitor_name,
5167 r->monitor_name);
5169 FILL_DRIVER_STRING(mem_ctx,
5170 driver->default_datatype,
5171 r->default_datatype);
5173 result = string_array_from_driver_info(mem_ctx,
5174 driver->dependent_files,
5175 &r->dependent_files,
5176 cservername,
5177 driver->architecture,
5178 driver->version);
5179 if (!W_ERROR_IS_OK(result)) {
5180 return result;
5183 result = string_array_from_driver_info(mem_ctx,
5184 driver->previous_names,
5185 &r->previous_names,
5186 NULL, NULL, 0);
5187 if (!W_ERROR_IS_OK(result)) {
5188 return result;
5191 r->driver_date = driver->driver_date;
5192 r->driver_version = driver->driver_version;
5194 FILL_DRIVER_STRING(mem_ctx,
5195 driver->manufacturer_name,
5196 r->manufacturer_name);
5197 FILL_DRIVER_STRING(mem_ctx,
5198 driver->manufacturer_url,
5199 r->manufacturer_url);
5200 FILL_DRIVER_STRING(mem_ctx,
5201 driver->hardware_id,
5202 r->hardware_id);
5203 FILL_DRIVER_STRING(mem_ctx,
5204 driver->provider,
5205 r->provider);
5207 FILL_DRIVER_STRING(mem_ctx,
5208 driver->print_processor,
5209 r->print_processor);
5210 FILL_DRIVER_STRING(mem_ctx,
5211 driver->vendor_setup,
5212 r->vendor_setup);
5214 result = string_array_from_driver_info(mem_ctx,
5215 driver->color_profiles,
5216 &r->color_profiles,
5217 NULL, NULL, 0);
5218 if (!W_ERROR_IS_OK(result)) {
5219 return result;
5222 FILL_DRIVER_STRING(mem_ctx,
5223 driver->inf_path,
5224 r->inf_path);
5226 r->printer_driver_attributes = driver->printer_driver_attributes;
5228 result = string_array_from_driver_info(mem_ctx,
5229 driver->core_driver_dependencies,
5230 &r->core_driver_dependencies,
5231 NULL, NULL, 0);
5232 if (!W_ERROR_IS_OK(result)) {
5233 return result;
5236 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
5237 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
5239 return WERR_OK;
5242 #if 0 /* disabled until marshalling issues are resolved - gd */
5243 /********************************************************************
5244 ********************************************************************/
5246 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5247 struct spoolss_DriverFileInfo *r,
5248 const char *cservername,
5249 const char *file_name,
5250 enum spoolss_DriverFileType file_type,
5251 uint32_t file_version)
5253 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5254 cservername, file_name);
5255 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5256 r->file_type = file_type;
5257 r->file_version = file_version;
5259 return WERR_OK;
5262 /********************************************************************
5263 ********************************************************************/
5265 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5266 const struct spoolss_DriverInfo8 *driver,
5267 const char *cservername,
5268 struct spoolss_DriverFileInfo **info_p,
5269 uint32_t *count_p)
5271 struct spoolss_DriverFileInfo *info = NULL;
5272 uint32_t count = 0;
5273 WERROR result;
5274 uint32_t i;
5276 *info_p = NULL;
5277 *count_p = 0;
5279 if (strlen(driver->driver_path)) {
5280 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5281 struct spoolss_DriverFileInfo,
5282 count + 1);
5283 W_ERROR_HAVE_NO_MEMORY(info);
5284 result = fill_spoolss_DriverFileInfo(info,
5285 &info[count],
5286 cservername,
5287 driver->driver_path,
5288 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5290 W_ERROR_NOT_OK_RETURN(result);
5291 count++;
5294 if (strlen(driver->config_file)) {
5295 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5296 struct spoolss_DriverFileInfo,
5297 count + 1);
5298 W_ERROR_HAVE_NO_MEMORY(info);
5299 result = fill_spoolss_DriverFileInfo(info,
5300 &info[count],
5301 cservername,
5302 driver->config_file,
5303 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5305 W_ERROR_NOT_OK_RETURN(result);
5306 count++;
5309 if (strlen(driver->data_file)) {
5310 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5311 struct spoolss_DriverFileInfo,
5312 count + 1);
5313 W_ERROR_HAVE_NO_MEMORY(info);
5314 result = fill_spoolss_DriverFileInfo(info,
5315 &info[count],
5316 cservername,
5317 driver->data_file,
5318 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5320 W_ERROR_NOT_OK_RETURN(result);
5321 count++;
5324 if (strlen(driver->help_file)) {
5325 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5326 struct spoolss_DriverFileInfo,
5327 count + 1);
5328 W_ERROR_HAVE_NO_MEMORY(info);
5329 result = fill_spoolss_DriverFileInfo(info,
5330 &info[count],
5331 cservername,
5332 driver->help_file,
5333 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5335 W_ERROR_NOT_OK_RETURN(result);
5336 count++;
5339 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
5340 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5341 struct spoolss_DriverFileInfo,
5342 count + 1);
5343 W_ERROR_HAVE_NO_MEMORY(info);
5344 result = fill_spoolss_DriverFileInfo(info,
5345 &info[count],
5346 cservername,
5347 driver->dependent_files[i],
5348 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5350 W_ERROR_NOT_OK_RETURN(result);
5351 count++;
5354 *info_p = info;
5355 *count_p = count;
5357 return WERR_OK;
5360 /********************************************************************
5361 * fill a spoolss_DriverInfo101 struct
5362 ********************************************************************/
5364 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5365 struct spoolss_DriverInfo101 *r,
5366 const struct spoolss_DriverInfo8 *driver,
5367 const char *servername)
5369 const char *cservername = canon_servername(servername);
5370 WERROR result;
5372 r->version = driver->version;
5374 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5375 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5376 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5377 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5379 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5380 cservername,
5381 &r->file_info,
5382 &r->file_count);
5383 if (!W_ERROR_IS_OK(result)) {
5384 return result;
5387 FILL_DRIVER_STRING(mem_ctx,
5388 driver->monitor_name,
5389 r->monitor_name);
5391 FILL_DRIVER_STRING(mem_ctx,
5392 driver->default_datatype,
5393 r->default_datatype);
5395 result = string_array_from_driver_info(mem_ctx,
5396 driver->previous_names,
5397 &r->previous_names,
5398 NULL, NULL, 0);
5399 if (!W_ERROR_IS_OK(result)) {
5400 return result;
5403 r->driver_date = driver->driver_date;
5404 r->driver_version = driver->driver_version;
5406 FILL_DRIVER_STRING(mem_ctx,
5407 driver->manufacturer_name,
5408 r->manufacturer_name);
5409 FILL_DRIVER_STRING(mem_ctx,
5410 driver->manufacturer_url,
5411 r->manufacturer_url);
5412 FILL_DRIVER_STRING(mem_ctx,
5413 driver->hardware_id,
5414 r->hardware_id);
5415 FILL_DRIVER_STRING(mem_ctx,
5416 driver->provider,
5417 r->provider);
5419 return WERR_OK;
5421 #endif
5422 /********************************************************************
5423 ********************************************************************/
5425 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5426 const struct auth_serversupplied_info *server_info,
5427 struct messaging_context *msg_ctx,
5428 uint32_t level,
5429 union spoolss_DriverInfo *r,
5430 int snum,
5431 const char *servername,
5432 const char *architecture,
5433 uint32_t version)
5435 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5436 struct spoolss_DriverInfo8 *driver;
5437 WERROR result;
5439 if (level == 101) {
5440 return WERR_UNKNOWN_LEVEL;
5443 result = winreg_get_printer(mem_ctx,
5444 server_info,
5445 msg_ctx,
5446 lp_const_servicename(snum),
5447 &pinfo2);
5449 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5450 win_errstr(result)));
5452 if (!W_ERROR_IS_OK(result)) {
5453 return WERR_INVALID_PRINTER_NAME;
5456 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5457 architecture,
5458 pinfo2->drivername, version, &driver);
5460 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5461 win_errstr(result)));
5463 if (!W_ERROR_IS_OK(result)) {
5465 * Is this a W2k client ?
5468 if (version < 3) {
5469 talloc_free(pinfo2);
5470 return WERR_UNKNOWN_PRINTER_DRIVER;
5473 /* Yes - try again with a WinNT driver. */
5474 version = 2;
5475 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5476 architecture,
5477 pinfo2->drivername,
5478 version, &driver);
5479 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5480 win_errstr(result)));
5481 if (!W_ERROR_IS_OK(result)) {
5482 talloc_free(pinfo2);
5483 return WERR_UNKNOWN_PRINTER_DRIVER;
5487 switch (level) {
5488 case 1:
5489 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5490 break;
5491 case 2:
5492 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5493 break;
5494 case 3:
5495 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5496 break;
5497 case 4:
5498 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5499 break;
5500 case 5:
5501 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5502 break;
5503 case 6:
5504 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5505 break;
5506 case 8:
5507 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5508 break;
5509 #if 0 /* disabled until marshalling issues are resolved - gd */
5510 case 101:
5511 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5512 break;
5513 #endif
5514 default:
5515 result = WERR_UNKNOWN_LEVEL;
5516 break;
5519 talloc_free(pinfo2);
5520 talloc_free(driver);
5522 return result;
5525 /****************************************************************
5526 _spoolss_GetPrinterDriver2
5527 ****************************************************************/
5529 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5530 struct spoolss_GetPrinterDriver2 *r)
5532 struct printer_handle *printer;
5533 WERROR result;
5535 int snum;
5537 /* that's an [in out] buffer */
5539 if (!r->in.buffer && (r->in.offered != 0)) {
5540 return WERR_INVALID_PARAM;
5543 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5545 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5546 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5547 return WERR_INVALID_PRINTER_NAME;
5550 *r->out.needed = 0;
5551 *r->out.server_major_version = 0;
5552 *r->out.server_minor_version = 0;
5554 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5555 return WERR_BADFID;
5558 result = construct_printer_driver_info_level(p->mem_ctx,
5559 get_server_info_system(),
5560 p->msg_ctx,
5561 r->in.level, r->out.info,
5562 snum, printer->servername,
5563 r->in.architecture,
5564 r->in.client_major_version);
5565 if (!W_ERROR_IS_OK(result)) {
5566 TALLOC_FREE(r->out.info);
5567 return result;
5570 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5571 r->out.info, r->in.level);
5572 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5574 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5578 /****************************************************************
5579 _spoolss_StartPagePrinter
5580 ****************************************************************/
5582 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5583 struct spoolss_StartPagePrinter *r)
5585 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5587 if (!Printer) {
5588 DEBUG(3,("_spoolss_StartPagePrinter: "
5589 "Error in startpageprinter printer handle\n"));
5590 return WERR_BADFID;
5593 Printer->page_started = true;
5594 return WERR_OK;
5597 /****************************************************************
5598 _spoolss_EndPagePrinter
5599 ****************************************************************/
5601 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5602 struct spoolss_EndPagePrinter *r)
5604 int snum;
5606 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5608 if (!Printer) {
5609 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5610 OUR_HANDLE(r->in.handle)));
5611 return WERR_BADFID;
5614 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5615 return WERR_BADFID;
5617 Printer->page_started = false;
5618 print_job_endpage(p->msg_ctx, snum, Printer->jobid);
5620 return WERR_OK;
5623 /****************************************************************
5624 _spoolss_StartDocPrinter
5625 ****************************************************************/
5627 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5628 struct spoolss_StartDocPrinter *r)
5630 struct spoolss_DocumentInfo1 *info_1;
5631 int snum;
5632 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5633 WERROR werr;
5635 if (!Printer) {
5636 DEBUG(2,("_spoolss_StartDocPrinter: "
5637 "Invalid handle (%s:%u:%u)\n",
5638 OUR_HANDLE(r->in.handle)));
5639 return WERR_BADFID;
5642 if (Printer->jobid) {
5643 DEBUG(2, ("_spoolss_StartDocPrinter: "
5644 "StartDocPrinter called twice! "
5645 "(existing jobid = %d)\n", Printer->jobid));
5646 return WERR_INVALID_HANDLE;
5649 if (r->in.level != 1) {
5650 return WERR_UNKNOWN_LEVEL;
5653 info_1 = r->in.info.info1;
5656 * a nice thing with NT is it doesn't listen to what you tell it.
5657 * when asked to send _only_ RAW datas, it tries to send datas
5658 * in EMF format.
5660 * So I add checks like in NT Server ...
5663 if (info_1->datatype) {
5664 if (strcmp(info_1->datatype, "RAW") != 0) {
5665 *r->out.job_id = 0;
5666 return WERR_INVALID_DATATYPE;
5670 /* get the share number of the printer */
5671 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5672 return WERR_BADFID;
5675 werr = print_job_start(p->server_info,
5676 p->msg_ctx,
5677 p->client_id->name,
5678 snum,
5679 info_1->document_name,
5680 info_1->output_file,
5681 Printer->devmode,
5682 &Printer->jobid);
5684 /* An error occured in print_job_start() so return an appropriate
5685 NT error code. */
5687 if (!W_ERROR_IS_OK(werr)) {
5688 return werr;
5691 Printer->document_started = true;
5692 *r->out.job_id = Printer->jobid;
5694 return WERR_OK;
5697 /****************************************************************
5698 _spoolss_EndDocPrinter
5699 ****************************************************************/
5701 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5702 struct spoolss_EndDocPrinter *r)
5704 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5705 NTSTATUS status;
5706 int snum;
5708 if (!Printer) {
5709 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5710 OUR_HANDLE(r->in.handle)));
5711 return WERR_BADFID;
5714 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5715 return WERR_BADFID;
5718 Printer->document_started = false;
5719 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5720 if (!NT_STATUS_IS_OK(status)) {
5721 DEBUG(2, ("_spoolss_EndDocPrinter: "
5722 "print_job_end failed [%s]\n",
5723 nt_errstr(status)));
5726 Printer->jobid = 0;
5727 return ntstatus_to_werror(status);
5730 /****************************************************************
5731 _spoolss_WritePrinter
5732 ****************************************************************/
5734 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5735 struct spoolss_WritePrinter *r)
5737 ssize_t buffer_written;
5738 int snum;
5739 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5741 if (!Printer) {
5742 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5743 OUR_HANDLE(r->in.handle)));
5744 *r->out.num_written = r->in._data_size;
5745 return WERR_BADFID;
5748 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5749 return WERR_BADFID;
5751 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5752 buffer_written = print_job_write(server_event_context(),p->msg_ctx,
5753 snum, Printer->jobid,
5754 (const char *)r->in.data.data,
5755 (size_t)r->in._data_size);
5756 if (buffer_written == (ssize_t)-1) {
5757 *r->out.num_written = 0;
5758 if (errno == ENOSPC)
5759 return WERR_NO_SPOOL_SPACE;
5760 else
5761 return WERR_ACCESS_DENIED;
5764 *r->out.num_written = r->in._data_size;
5766 return WERR_OK;
5769 /********************************************************************
5770 * api_spoolss_getprinter
5771 * called from the spoolss dispatcher
5773 ********************************************************************/
5775 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5776 struct pipes_struct *p)
5778 const struct auth_serversupplied_info *server_info = p->server_info;
5779 int snum;
5780 WERROR errcode = WERR_BADFUNC;
5781 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5783 if (!Printer) {
5784 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5785 OUR_HANDLE(handle)));
5786 return WERR_BADFID;
5789 if (!get_printer_snum(p, handle, &snum, NULL))
5790 return WERR_BADFID;
5792 switch (command) {
5793 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5794 errcode = print_queue_pause(server_info, p->msg_ctx, snum);
5795 break;
5796 case SPOOLSS_PRINTER_CONTROL_RESUME:
5797 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5798 errcode = print_queue_resume(server_info, p->msg_ctx, snum);
5799 break;
5800 case SPOOLSS_PRINTER_CONTROL_PURGE:
5801 errcode = print_queue_purge(server_info, p->msg_ctx, snum);
5802 break;
5803 default:
5804 return WERR_UNKNOWN_LEVEL;
5807 return errcode;
5811 /****************************************************************
5812 _spoolss_AbortPrinter
5813 * From MSDN: "Deletes printer's spool file if printer is configured
5814 * for spooling"
5815 ****************************************************************/
5817 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5818 struct spoolss_AbortPrinter *r)
5820 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5821 int snum;
5822 WERROR errcode = WERR_OK;
5824 if (!Printer) {
5825 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5826 OUR_HANDLE(r->in.handle)));
5827 return WERR_BADFID;
5830 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5831 return WERR_BADFID;
5833 if (!Printer->document_started) {
5834 return WERR_SPL_NO_STARTDOC;
5837 errcode = print_job_delete(p->server_info,
5838 p->msg_ctx,
5839 snum,
5840 Printer->jobid);
5842 return errcode;
5845 /********************************************************************
5846 * called by spoolss_api_setprinter
5847 * when updating a printer description
5848 ********************************************************************/
5850 static WERROR update_printer_sec(struct policy_handle *handle,
5851 struct pipes_struct *p,
5852 struct sec_desc_buf *secdesc_ctr)
5854 struct spoolss_security_descriptor *new_secdesc = NULL;
5855 struct spoolss_security_descriptor *old_secdesc = NULL;
5856 const char *printer;
5857 WERROR result;
5858 int snum;
5860 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5862 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5863 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5864 OUR_HANDLE(handle)));
5866 result = WERR_BADFID;
5867 goto done;
5870 if (secdesc_ctr == NULL) {
5871 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5872 result = WERR_INVALID_PARAM;
5873 goto done;
5875 printer = lp_const_servicename(snum);
5877 /* Check the user has permissions to change the security
5878 descriptor. By experimentation with two NT machines, the user
5879 requires Full Access to the printer to change security
5880 information. */
5882 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5883 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5884 result = WERR_ACCESS_DENIED;
5885 goto done;
5888 /* NT seems to like setting the security descriptor even though
5889 nothing may have actually changed. */
5890 result = winreg_get_printer_secdesc(p->mem_ctx,
5891 get_server_info_system(),
5892 p->msg_ctx,
5893 printer,
5894 &old_secdesc);
5895 if (!W_ERROR_IS_OK(result)) {
5896 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5897 result = WERR_BADFID;
5898 goto done;
5901 if (DEBUGLEVEL >= 10) {
5902 struct security_acl *the_acl;
5903 int i;
5905 the_acl = old_secdesc->dacl;
5906 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5907 printer, the_acl->num_aces));
5909 for (i = 0; i < the_acl->num_aces; i++) {
5910 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5911 &the_acl->aces[i].trustee),
5912 the_acl->aces[i].access_mask));
5915 the_acl = secdesc_ctr->sd->dacl;
5917 if (the_acl) {
5918 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5919 printer, the_acl->num_aces));
5921 for (i = 0; i < the_acl->num_aces; i++) {
5922 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5923 &the_acl->aces[i].trustee),
5924 the_acl->aces[i].access_mask));
5926 } else {
5927 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5931 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
5932 if (new_secdesc == NULL) {
5933 result = WERR_NOMEM;
5934 goto done;
5937 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
5938 result = WERR_OK;
5939 goto done;
5942 result = winreg_set_printer_secdesc(p->mem_ctx,
5943 get_server_info_system(),
5944 p->msg_ctx,
5945 printer,
5946 new_secdesc);
5948 done:
5949 return result;
5952 /********************************************************************
5953 Canonicalize printer info from a client
5954 ********************************************************************/
5956 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
5957 struct spoolss_SetPrinterInfo2 *info2,
5958 int snum)
5960 fstring printername;
5961 const char *p;
5963 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5964 "portname=%s drivername=%s comment=%s location=%s\n",
5965 info2->servername, info2->printername, info2->sharename,
5966 info2->portname, info2->drivername, info2->comment,
5967 info2->location));
5969 /* we force some elements to "correct" values */
5970 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
5971 if (info2->servername == NULL) {
5972 return false;
5974 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
5975 if (info2->sharename == NULL) {
5976 return false;
5979 /* check to see if we allow printername != sharename */
5980 if (lp_force_printername(snum)) {
5981 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5982 global_myname(), info2->sharename);
5983 } else {
5984 /* make sure printername is in \\server\printername format */
5985 fstrcpy(printername, info2->printername);
5986 p = printername;
5987 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5988 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5989 p++;
5992 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5993 global_myname(), p);
5995 if (info2->printername == NULL) {
5996 return false;
5999 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
6000 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
6002 return true;
6005 /****************************************************************************
6006 ****************************************************************************/
6008 static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const char *portname, const char *uri)
6010 char *cmd = lp_addport_cmd();
6011 char *command = NULL;
6012 int ret;
6013 bool is_print_op = false;
6015 if ( !*cmd ) {
6016 return WERR_ACCESS_DENIED;
6019 command = talloc_asprintf(ctx,
6020 "%s \"%s\" \"%s\"", cmd, portname, uri );
6021 if (!command) {
6022 return WERR_NOMEM;
6025 if ( token )
6026 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6028 DEBUG(10,("Running [%s]\n", command));
6030 /********* BEGIN SePrintOperatorPrivilege **********/
6032 if ( is_print_op )
6033 become_root();
6035 ret = smbrun(command, NULL);
6037 if ( is_print_op )
6038 unbecome_root();
6040 /********* END SePrintOperatorPrivilege **********/
6042 DEBUGADD(10,("returned [%d]\n", ret));
6044 TALLOC_FREE(command);
6046 if ( ret != 0 ) {
6047 return WERR_ACCESS_DENIED;
6050 return WERR_OK;
6053 /****************************************************************************
6054 ****************************************************************************/
6056 static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
6057 struct spoolss_SetPrinterInfo2 *info2,
6058 const char *remote_machine,
6059 struct messaging_context *msg_ctx)
6061 char *cmd = lp_addprinter_cmd();
6062 char **qlines;
6063 char *command = NULL;
6064 int numlines;
6065 int ret;
6066 int fd;
6067 bool is_print_op = false;
6069 if (!remote_machine) {
6070 return false;
6073 command = talloc_asprintf(ctx,
6074 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6075 cmd, info2->printername, info2->sharename,
6076 info2->portname, info2->drivername,
6077 info2->location, info2->comment, remote_machine);
6078 if (!command) {
6079 return false;
6082 if ( token )
6083 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6085 DEBUG(10,("Running [%s]\n", command));
6087 /********* BEGIN SePrintOperatorPrivilege **********/
6089 if ( is_print_op )
6090 become_root();
6092 if ( (ret = smbrun(command, &fd)) == 0 ) {
6093 /* Tell everyone we updated smb.conf. */
6094 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6097 if ( is_print_op )
6098 unbecome_root();
6100 /********* END SePrintOperatorPrivilege **********/
6102 DEBUGADD(10,("returned [%d]\n", ret));
6104 TALLOC_FREE(command);
6106 if ( ret != 0 ) {
6107 if (fd != -1)
6108 close(fd);
6109 return false;
6112 /* reload our services immediately */
6113 become_root();
6114 reload_services(msg_ctx, -1, false);
6115 unbecome_root();
6117 numlines = 0;
6118 /* Get lines and convert them back to dos-codepage */
6119 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6120 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6121 close(fd);
6123 /* Set the portname to what the script says the portname should be. */
6124 /* but don't require anything to be return from the script exit a good error code */
6126 if (numlines) {
6127 /* Set the portname to what the script says the portname should be. */
6128 info2->portname = talloc_strdup(ctx, qlines[0]);
6129 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6132 TALLOC_FREE(qlines);
6133 return true;
6136 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
6137 const struct auth_serversupplied_info *server_info,
6138 struct messaging_context *msg_ctx,
6139 int snum,
6140 struct spoolss_SetPrinterInfo2 *printer,
6141 struct spoolss_PrinterInfo2 *old_printer)
6143 bool force_update = (old_printer == NULL);
6144 const char *dnsdomname;
6145 const char *longname;
6146 const char *uncname;
6147 const char *spooling;
6148 DATA_BLOB buffer;
6149 WERROR result = WERR_OK;
6151 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
6152 push_reg_sz(mem_ctx, &buffer, printer->drivername);
6153 winreg_set_printer_dataex(mem_ctx,
6154 server_info,
6155 msg_ctx,
6156 printer->sharename,
6157 SPOOL_DSSPOOLER_KEY,
6158 SPOOL_REG_DRIVERNAME,
6159 REG_SZ,
6160 buffer.data,
6161 buffer.length);
6163 if (!force_update) {
6164 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6165 printer->drivername));
6167 notify_printer_driver(server_event_context(), msg_ctx,
6168 snum, printer->drivername ?
6169 printer->drivername : "");
6173 if (force_update || !strequal(printer->comment, old_printer->comment)) {
6174 push_reg_sz(mem_ctx, &buffer, printer->comment);
6175 winreg_set_printer_dataex(mem_ctx,
6176 server_info,
6177 msg_ctx,
6178 printer->sharename,
6179 SPOOL_DSSPOOLER_KEY,
6180 SPOOL_REG_DESCRIPTION,
6181 REG_SZ,
6182 buffer.data,
6183 buffer.length);
6185 if (!force_update) {
6186 notify_printer_comment(server_event_context(), msg_ctx,
6187 snum, printer->comment ?
6188 printer->comment : "");
6192 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
6193 push_reg_sz(mem_ctx, &buffer, printer->sharename);
6194 winreg_set_printer_dataex(mem_ctx,
6195 server_info,
6196 msg_ctx,
6197 printer->sharename,
6198 SPOOL_DSSPOOLER_KEY,
6199 SPOOL_REG_PRINTSHARENAME,
6200 REG_SZ,
6201 buffer.data,
6202 buffer.length);
6204 if (!force_update) {
6205 notify_printer_sharename(server_event_context(),
6206 msg_ctx,
6207 snum, printer->sharename ?
6208 printer->sharename : "");
6212 if (force_update || !strequal(printer->printername, old_printer->printername)) {
6213 const char *p;
6215 p = strrchr(printer->printername, '\\' );
6216 if (p != NULL) {
6217 p++;
6218 } else {
6219 p = printer->printername;
6222 push_reg_sz(mem_ctx, &buffer, p);
6223 winreg_set_printer_dataex(mem_ctx,
6224 server_info,
6225 msg_ctx,
6226 printer->sharename,
6227 SPOOL_DSSPOOLER_KEY,
6228 SPOOL_REG_PRINTERNAME,
6229 REG_SZ,
6230 buffer.data,
6231 buffer.length);
6233 if (!force_update) {
6234 notify_printer_printername(server_event_context(),
6235 msg_ctx, snum, p ? p : "");
6239 if (force_update || !strequal(printer->portname, old_printer->portname)) {
6240 push_reg_sz(mem_ctx, &buffer, printer->portname);
6241 winreg_set_printer_dataex(mem_ctx,
6242 server_info,
6243 msg_ctx,
6244 printer->sharename,
6245 SPOOL_DSSPOOLER_KEY,
6246 SPOOL_REG_PORTNAME,
6247 REG_SZ,
6248 buffer.data,
6249 buffer.length);
6251 if (!force_update) {
6252 notify_printer_port(server_event_context(),
6253 msg_ctx, snum, printer->portname ?
6254 printer->portname : "");
6258 if (force_update || !strequal(printer->location, old_printer->location)) {
6259 push_reg_sz(mem_ctx, &buffer, printer->location);
6260 winreg_set_printer_dataex(mem_ctx,
6261 server_info,
6262 msg_ctx,
6263 printer->sharename,
6264 SPOOL_DSSPOOLER_KEY,
6265 SPOOL_REG_LOCATION,
6266 REG_SZ,
6267 buffer.data,
6268 buffer.length);
6270 if (!force_update) {
6271 notify_printer_location(server_event_context(),
6272 msg_ctx, snum,
6273 printer->location ?
6274 printer->location : "");
6278 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
6279 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
6280 winreg_set_printer_dataex(mem_ctx,
6281 server_info,
6282 msg_ctx,
6283 printer->sharename,
6284 SPOOL_DSSPOOLER_KEY,
6285 SPOOL_REG_PRINTSEPARATORFILE,
6286 REG_SZ,
6287 buffer.data,
6288 buffer.length);
6290 if (!force_update) {
6291 notify_printer_sepfile(server_event_context(),
6292 msg_ctx, snum,
6293 printer->sepfile ?
6294 printer->sepfile : "");
6298 if (force_update || printer->starttime != old_printer->starttime) {
6299 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6300 SIVAL(buffer.data, 0, printer->starttime);
6301 winreg_set_printer_dataex(mem_ctx,
6302 server_info,
6303 msg_ctx,
6304 printer->sharename,
6305 SPOOL_DSSPOOLER_KEY,
6306 SPOOL_REG_PRINTSTARTTIME,
6307 REG_DWORD,
6308 buffer.data,
6309 buffer.length);
6312 if (force_update || printer->untiltime != old_printer->untiltime) {
6313 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6314 SIVAL(buffer.data, 0, printer->untiltime);
6315 winreg_set_printer_dataex(mem_ctx,
6316 server_info,
6317 msg_ctx,
6318 printer->sharename,
6319 SPOOL_DSSPOOLER_KEY,
6320 SPOOL_REG_PRINTENDTIME,
6321 REG_DWORD,
6322 buffer.data,
6323 buffer.length);
6326 if (force_update || printer->priority != old_printer->priority) {
6327 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6328 SIVAL(buffer.data, 0, printer->priority);
6329 winreg_set_printer_dataex(mem_ctx,
6330 server_info,
6331 msg_ctx,
6332 printer->sharename,
6333 SPOOL_DSSPOOLER_KEY,
6334 SPOOL_REG_PRIORITY,
6335 REG_DWORD,
6336 buffer.data,
6337 buffer.length);
6340 if (force_update || printer->attributes != old_printer->attributes) {
6341 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6342 SIVAL(buffer.data, 0, (printer->attributes &
6343 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
6344 winreg_set_printer_dataex(mem_ctx,
6345 server_info,
6346 msg_ctx,
6347 printer->sharename,
6348 SPOOL_DSSPOOLER_KEY,
6349 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
6350 REG_DWORD,
6351 buffer.data,
6352 buffer.length);
6354 switch (printer->attributes & 0x3) {
6355 case 0:
6356 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
6357 break;
6358 case 1:
6359 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
6360 break;
6361 case 2:
6362 spooling = SPOOL_REGVAL_PRINTDIRECT;
6363 break;
6364 default:
6365 spooling = "unknown";
6367 push_reg_sz(mem_ctx, &buffer, spooling);
6368 winreg_set_printer_dataex(mem_ctx,
6369 server_info,
6370 msg_ctx,
6371 printer->sharename,
6372 SPOOL_DSSPOOLER_KEY,
6373 SPOOL_REG_PRINTSPOOLING,
6374 REG_SZ,
6375 buffer.data,
6376 buffer.length);
6379 push_reg_sz(mem_ctx, &buffer, global_myname());
6380 winreg_set_printer_dataex(mem_ctx,
6381 server_info,
6382 msg_ctx,
6383 printer->sharename,
6384 SPOOL_DSSPOOLER_KEY,
6385 SPOOL_REG_SHORTSERVERNAME,
6386 REG_SZ,
6387 buffer.data,
6388 buffer.length);
6390 dnsdomname = get_mydnsfullname();
6391 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
6392 longname = talloc_strdup(mem_ctx, dnsdomname);
6393 } else {
6394 longname = talloc_strdup(mem_ctx, global_myname());
6396 if (longname == NULL) {
6397 result = WERR_NOMEM;
6398 goto done;
6401 push_reg_sz(mem_ctx, &buffer, longname);
6402 winreg_set_printer_dataex(mem_ctx,
6403 server_info,
6404 msg_ctx,
6405 printer->sharename,
6406 SPOOL_DSSPOOLER_KEY,
6407 SPOOL_REG_SERVERNAME,
6408 REG_SZ,
6409 buffer.data,
6410 buffer.length);
6412 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6413 global_myname(), printer->sharename);
6414 push_reg_sz(mem_ctx, &buffer, uncname);
6415 winreg_set_printer_dataex(mem_ctx,
6416 server_info,
6417 msg_ctx,
6418 printer->sharename,
6419 SPOOL_DSSPOOLER_KEY,
6420 SPOOL_REG_UNCNAME,
6421 REG_SZ,
6422 buffer.data,
6423 buffer.length);
6425 done:
6426 return result;
6429 /********************************************************************
6430 * Called by spoolss_api_setprinter
6431 * when updating a printer description.
6432 ********************************************************************/
6434 static WERROR update_printer(struct pipes_struct *p,
6435 struct policy_handle *handle,
6436 struct spoolss_SetPrinterInfoCtr *info_ctr,
6437 struct spoolss_DeviceMode *devmode)
6439 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6440 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6441 struct spoolss_PrinterInfo2 *old_printer;
6442 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6443 int snum;
6444 WERROR result = WERR_OK;
6445 TALLOC_CTX *tmp_ctx;
6447 DEBUG(8,("update_printer\n"));
6449 tmp_ctx = talloc_new(p->mem_ctx);
6450 if (tmp_ctx == NULL) {
6451 return WERR_NOMEM;
6454 if (!Printer) {
6455 result = WERR_BADFID;
6456 goto done;
6459 if (!get_printer_snum(p, handle, &snum, NULL)) {
6460 result = WERR_BADFID;
6461 goto done;
6464 result = winreg_get_printer(tmp_ctx,
6465 get_server_info_system(),
6466 p->msg_ctx,
6467 lp_const_servicename(snum),
6468 &old_printer);
6469 if (!W_ERROR_IS_OK(result)) {
6470 result = WERR_BADFID;
6471 goto done;
6474 /* Do sanity check on the requested changes for Samba */
6475 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6476 result = WERR_INVALID_PARAM;
6477 goto done;
6480 /* FIXME!!! If the driver has changed we really should verify that
6481 it is installed before doing much else --jerry */
6483 /* Check calling user has permission to update printer description */
6484 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6485 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6486 result = WERR_ACCESS_DENIED;
6487 goto done;
6490 /* Call addprinter hook */
6491 /* Check changes to see if this is really needed */
6493 if (*lp_addprinter_cmd() &&
6494 (!strequal(printer->drivername, old_printer->drivername) ||
6495 !strequal(printer->comment, old_printer->comment) ||
6496 !strequal(printer->portname, old_printer->portname) ||
6497 !strequal(printer->location, old_printer->location)) )
6499 /* add_printer_hook() will call reload_services() */
6500 if (!add_printer_hook(tmp_ctx, p->server_info->ptok,
6501 printer, p->client_id->addr,
6502 p->msg_ctx)) {
6503 result = WERR_ACCESS_DENIED;
6504 goto done;
6508 update_dsspooler(tmp_ctx,
6509 get_server_info_system(),
6510 p->msg_ctx,
6511 snum,
6512 printer,
6513 old_printer);
6515 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6517 if (devmode == NULL) {
6518 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6520 result = winreg_update_printer(tmp_ctx,
6521 get_server_info_system(),
6522 p->msg_ctx,
6523 printer->sharename,
6524 printer_mask,
6525 printer,
6526 devmode,
6527 NULL);
6529 done:
6530 talloc_free(tmp_ctx);
6532 return result;
6535 /****************************************************************************
6536 ****************************************************************************/
6537 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6538 struct policy_handle *handle,
6539 struct spoolss_SetPrinterInfo7 *info7)
6541 #ifdef HAVE_ADS
6542 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6543 WERROR result;
6544 int snum;
6545 struct printer_handle *Printer;
6547 if ( lp_security() != SEC_ADS ) {
6548 return WERR_UNKNOWN_LEVEL;
6551 Printer = find_printer_index_by_hnd(p, handle);
6553 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6555 if (!Printer)
6556 return WERR_BADFID;
6558 if (!get_printer_snum(p, handle, &snum, NULL))
6559 return WERR_BADFID;
6561 result = winreg_get_printer(p->mem_ctx,
6562 get_server_info_system(),
6563 p->msg_ctx,
6564 lp_servicename(snum),
6565 &pinfo2);
6566 if (!W_ERROR_IS_OK(result)) {
6567 return WERR_BADFID;
6570 nt_printer_publish(pinfo2,
6571 get_server_info_system(),
6572 p->msg_ctx,
6573 pinfo2,
6574 info7->action);
6576 TALLOC_FREE(pinfo2);
6577 return WERR_OK;
6578 #else
6579 return WERR_UNKNOWN_LEVEL;
6580 #endif
6583 /********************************************************************
6584 ********************************************************************/
6586 static WERROR update_printer_devmode(struct pipes_struct *p,
6587 struct policy_handle *handle,
6588 struct spoolss_DeviceMode *devmode)
6590 int snum;
6591 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6592 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6594 DEBUG(8,("update_printer_devmode\n"));
6596 if (!Printer) {
6597 return WERR_BADFID;
6600 if (!get_printer_snum(p, handle, &snum, NULL)) {
6601 return WERR_BADFID;
6604 /* Check calling user has permission to update printer description */
6605 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6606 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6607 return WERR_ACCESS_DENIED;
6610 return winreg_update_printer(p->mem_ctx,
6611 get_server_info_system(),
6612 p->msg_ctx,
6613 lp_const_servicename(snum),
6614 info2_mask,
6615 NULL,
6616 devmode,
6617 NULL);
6621 /****************************************************************
6622 _spoolss_SetPrinter
6623 ****************************************************************/
6625 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6626 struct spoolss_SetPrinter *r)
6628 WERROR result;
6630 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6632 if (!Printer) {
6633 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6634 OUR_HANDLE(r->in.handle)));
6635 return WERR_BADFID;
6638 /* check the level */
6639 switch (r->in.info_ctr->level) {
6640 case 0:
6641 return control_printer(r->in.handle, r->in.command, p);
6642 case 2:
6643 result = update_printer(p, r->in.handle,
6644 r->in.info_ctr,
6645 r->in.devmode_ctr->devmode);
6646 if (!W_ERROR_IS_OK(result))
6647 return result;
6648 if (r->in.secdesc_ctr->sd)
6649 result = update_printer_sec(r->in.handle, p,
6650 r->in.secdesc_ctr);
6651 return result;
6652 case 3:
6653 return update_printer_sec(r->in.handle, p,
6654 r->in.secdesc_ctr);
6655 case 7:
6656 return publish_or_unpublish_printer(p, r->in.handle,
6657 r->in.info_ctr->info.info7);
6658 case 8:
6659 return update_printer_devmode(p, r->in.handle,
6660 r->in.devmode_ctr->devmode);
6661 default:
6662 return WERR_UNKNOWN_LEVEL;
6666 /****************************************************************
6667 _spoolss_FindClosePrinterNotify
6668 ****************************************************************/
6670 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6671 struct spoolss_FindClosePrinterNotify *r)
6673 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6675 if (!Printer) {
6676 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6677 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6678 return WERR_BADFID;
6681 if (Printer->notify.cli_chan != NULL &&
6682 Printer->notify.cli_chan->active_connections > 0) {
6683 int snum = -1;
6685 if (Printer->printer_type == SPLHND_PRINTER) {
6686 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6687 return WERR_BADFID;
6691 srv_spoolss_replycloseprinter(snum, Printer);
6694 Printer->notify.flags=0;
6695 Printer->notify.options=0;
6696 Printer->notify.localmachine[0]='\0';
6697 Printer->notify.printerlocal=0;
6698 TALLOC_FREE(Printer->notify.option);
6700 return WERR_OK;
6703 /****************************************************************
6704 _spoolss_AddJob
6705 ****************************************************************/
6707 WERROR _spoolss_AddJob(struct pipes_struct *p,
6708 struct spoolss_AddJob *r)
6710 if (!r->in.buffer && (r->in.offered != 0)) {
6711 return WERR_INVALID_PARAM;
6714 /* this is what a NT server returns for AddJob. AddJob must fail on
6715 * non-local printers */
6717 if (r->in.level != 1) {
6718 return WERR_UNKNOWN_LEVEL;
6721 return WERR_INVALID_PARAM;
6724 /****************************************************************************
6725 fill_job_info1
6726 ****************************************************************************/
6728 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6729 struct spoolss_JobInfo1 *r,
6730 const print_queue_struct *queue,
6731 int position, int snum,
6732 struct spoolss_PrinterInfo2 *pinfo2)
6734 struct tm *t;
6736 t = gmtime(&queue->time);
6738 r->job_id = queue->job;
6740 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6741 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6742 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6743 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6744 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6745 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6746 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6747 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6748 r->data_type = talloc_strdup(mem_ctx, "RAW");
6749 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6750 r->text_status = talloc_strdup(mem_ctx, "");
6751 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6753 r->status = nt_printj_status(queue->status);
6754 r->priority = queue->priority;
6755 r->position = position;
6756 r->total_pages = queue->page_count;
6757 r->pages_printed = 0; /* ??? */
6759 init_systemtime(&r->submitted, t);
6761 return WERR_OK;
6764 /****************************************************************************
6765 fill_job_info2
6766 ****************************************************************************/
6768 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6769 struct spoolss_JobInfo2 *r,
6770 const print_queue_struct *queue,
6771 int position, int snum,
6772 struct spoolss_PrinterInfo2 *pinfo2,
6773 struct spoolss_DeviceMode *devmode)
6775 struct tm *t;
6777 t = gmtime(&queue->time);
6779 r->job_id = queue->job;
6781 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6782 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6783 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6784 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6785 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6786 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6787 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6788 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6789 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6790 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6791 r->data_type = talloc_strdup(mem_ctx, "RAW");
6792 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6793 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6794 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6795 r->parameters = talloc_strdup(mem_ctx, "");
6796 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6797 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6798 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6800 r->devmode = devmode;
6802 r->text_status = talloc_strdup(mem_ctx, "");
6803 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6805 r->secdesc = NULL;
6807 r->status = nt_printj_status(queue->status);
6808 r->priority = queue->priority;
6809 r->position = position;
6810 r->start_time = 0;
6811 r->until_time = 0;
6812 r->total_pages = queue->page_count;
6813 r->size = queue->size;
6814 init_systemtime(&r->submitted, t);
6815 r->time = 0;
6816 r->pages_printed = 0; /* ??? */
6818 return WERR_OK;
6821 /****************************************************************************
6822 fill_job_info3
6823 ****************************************************************************/
6825 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6826 struct spoolss_JobInfo3 *r,
6827 const print_queue_struct *queue,
6828 const print_queue_struct *next_queue,
6829 int position, int snum,
6830 struct spoolss_PrinterInfo2 *pinfo2)
6832 r->job_id = queue->job;
6833 r->next_job_id = 0;
6834 if (next_queue) {
6835 r->next_job_id = next_queue->job;
6837 r->reserved = 0;
6839 return WERR_OK;
6842 /****************************************************************************
6843 Enumjobs at level 1.
6844 ****************************************************************************/
6846 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6847 const print_queue_struct *queue,
6848 uint32_t num_queues, int snum,
6849 struct spoolss_PrinterInfo2 *pinfo2,
6850 union spoolss_JobInfo **info_p,
6851 uint32_t *count)
6853 union spoolss_JobInfo *info;
6854 int i;
6855 WERROR result = WERR_OK;
6857 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6858 W_ERROR_HAVE_NO_MEMORY(info);
6860 *count = num_queues;
6862 for (i=0; i<*count; i++) {
6863 result = fill_job_info1(info,
6864 &info[i].info1,
6865 &queue[i],
6867 snum,
6868 pinfo2);
6869 if (!W_ERROR_IS_OK(result)) {
6870 goto out;
6874 out:
6875 if (!W_ERROR_IS_OK(result)) {
6876 TALLOC_FREE(info);
6877 *count = 0;
6878 return result;
6881 *info_p = info;
6883 return WERR_OK;
6886 /****************************************************************************
6887 Enumjobs at level 2.
6888 ****************************************************************************/
6890 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6891 const print_queue_struct *queue,
6892 uint32_t num_queues, int snum,
6893 struct spoolss_PrinterInfo2 *pinfo2,
6894 union spoolss_JobInfo **info_p,
6895 uint32_t *count)
6897 union spoolss_JobInfo *info;
6898 int i;
6899 WERROR result = WERR_OK;
6901 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6902 W_ERROR_HAVE_NO_MEMORY(info);
6904 *count = num_queues;
6906 for (i=0; i<*count; i++) {
6907 struct spoolss_DeviceMode *devmode;
6909 result = spoolss_create_default_devmode(info,
6910 pinfo2->printername,
6911 &devmode);
6912 if (!W_ERROR_IS_OK(result)) {
6913 DEBUG(3, ("Can't proceed w/o a devmode!"));
6914 goto out;
6917 result = fill_job_info2(info,
6918 &info[i].info2,
6919 &queue[i],
6921 snum,
6922 pinfo2,
6923 devmode);
6924 if (!W_ERROR_IS_OK(result)) {
6925 goto out;
6929 out:
6930 if (!W_ERROR_IS_OK(result)) {
6931 TALLOC_FREE(info);
6932 *count = 0;
6933 return result;
6936 *info_p = info;
6938 return WERR_OK;
6941 /****************************************************************************
6942 Enumjobs at level 3.
6943 ****************************************************************************/
6945 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6946 const print_queue_struct *queue,
6947 uint32_t num_queues, int snum,
6948 struct spoolss_PrinterInfo2 *pinfo2,
6949 union spoolss_JobInfo **info_p,
6950 uint32_t *count)
6952 union spoolss_JobInfo *info;
6953 int i;
6954 WERROR result = WERR_OK;
6956 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6957 W_ERROR_HAVE_NO_MEMORY(info);
6959 *count = num_queues;
6961 for (i=0; i<*count; i++) {
6962 const print_queue_struct *next_queue = NULL;
6964 if (i+1 < *count) {
6965 next_queue = &queue[i+1];
6968 result = fill_job_info3(info,
6969 &info[i].info3,
6970 &queue[i],
6971 next_queue,
6973 snum,
6974 pinfo2);
6975 if (!W_ERROR_IS_OK(result)) {
6976 goto out;
6980 out:
6981 if (!W_ERROR_IS_OK(result)) {
6982 TALLOC_FREE(info);
6983 *count = 0;
6984 return result;
6987 *info_p = info;
6989 return WERR_OK;
6992 /****************************************************************
6993 _spoolss_EnumJobs
6994 ****************************************************************/
6996 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
6997 struct spoolss_EnumJobs *r)
6999 WERROR result;
7000 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
7001 int snum;
7002 print_status_struct prt_status;
7003 print_queue_struct *queue = NULL;
7004 uint32_t count;
7006 /* that's an [in out] buffer */
7008 if (!r->in.buffer && (r->in.offered != 0)) {
7009 return WERR_INVALID_PARAM;
7012 DEBUG(4,("_spoolss_EnumJobs\n"));
7014 *r->out.needed = 0;
7015 *r->out.count = 0;
7016 *r->out.info = NULL;
7018 /* lookup the printer snum and tdb entry */
7020 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7021 return WERR_BADFID;
7024 result = winreg_get_printer(p->mem_ctx,
7025 get_server_info_system(),
7026 p->msg_ctx,
7027 lp_const_servicename(snum),
7028 &pinfo2);
7029 if (!W_ERROR_IS_OK(result)) {
7030 return result;
7033 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
7034 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7035 count, prt_status.status, prt_status.message));
7037 if (count == 0) {
7038 SAFE_FREE(queue);
7039 TALLOC_FREE(pinfo2);
7040 return WERR_OK;
7043 switch (r->in.level) {
7044 case 1:
7045 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
7046 pinfo2, r->out.info, r->out.count);
7047 break;
7048 case 2:
7049 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
7050 pinfo2, r->out.info, r->out.count);
7051 break;
7052 case 3:
7053 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
7054 pinfo2, r->out.info, r->out.count);
7055 break;
7056 default:
7057 result = WERR_UNKNOWN_LEVEL;
7058 break;
7061 SAFE_FREE(queue);
7062 TALLOC_FREE(pinfo2);
7064 if (!W_ERROR_IS_OK(result)) {
7065 return result;
7068 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7069 spoolss_EnumJobs,
7070 *r->out.info, r->in.level,
7071 *r->out.count);
7072 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7073 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7075 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7078 /****************************************************************
7079 _spoolss_ScheduleJob
7080 ****************************************************************/
7082 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
7083 struct spoolss_ScheduleJob *r)
7085 return WERR_OK;
7088 /****************************************************************
7089 ****************************************************************/
7091 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
7092 struct messaging_context *msg_ctx,
7093 const char *printer_name,
7094 uint32_t job_id,
7095 struct spoolss_SetJobInfo1 *r)
7097 char *old_doc_name;
7099 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
7100 return WERR_BADFID;
7103 if (strequal(old_doc_name, r->document_name)) {
7104 return WERR_OK;
7107 if (!print_job_set_name(server_event_context(), msg_ctx,
7108 printer_name, job_id, r->document_name)) {
7109 return WERR_BADFID;
7112 return WERR_OK;
7115 /****************************************************************
7116 _spoolss_SetJob
7117 ****************************************************************/
7119 WERROR _spoolss_SetJob(struct pipes_struct *p,
7120 struct spoolss_SetJob *r)
7122 const struct auth_serversupplied_info *server_info = p->server_info;
7123 int snum;
7124 WERROR errcode = WERR_BADFUNC;
7126 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7127 return WERR_BADFID;
7130 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
7131 return WERR_INVALID_PRINTER_NAME;
7134 switch (r->in.command) {
7135 case SPOOLSS_JOB_CONTROL_CANCEL:
7136 case SPOOLSS_JOB_CONTROL_DELETE:
7137 errcode = print_job_delete(server_info, p->msg_ctx,
7138 snum, r->in.job_id);
7139 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
7140 errcode = WERR_OK;
7142 break;
7143 case SPOOLSS_JOB_CONTROL_PAUSE:
7144 if (print_job_pause(server_info, p->msg_ctx,
7145 snum, r->in.job_id, &errcode)) {
7146 errcode = WERR_OK;
7148 break;
7149 case SPOOLSS_JOB_CONTROL_RESTART:
7150 case SPOOLSS_JOB_CONTROL_RESUME:
7151 if (print_job_resume(server_info, p->msg_ctx,
7152 snum, r->in.job_id, &errcode)) {
7153 errcode = WERR_OK;
7155 break;
7156 case 0:
7157 errcode = WERR_OK;
7158 break;
7159 default:
7160 return WERR_UNKNOWN_LEVEL;
7163 if (!W_ERROR_IS_OK(errcode)) {
7164 return errcode;
7167 if (r->in.ctr == NULL) {
7168 return errcode;
7171 switch (r->in.ctr->level) {
7172 case 1:
7173 errcode = spoolss_setjob_1(p->mem_ctx, p->msg_ctx,
7174 lp_const_servicename(snum),
7175 r->in.job_id,
7176 r->in.ctr->info.info1);
7177 break;
7178 case 2:
7179 case 3:
7180 case 4:
7181 default:
7182 return WERR_UNKNOWN_LEVEL;
7185 return errcode;
7188 /****************************************************************************
7189 Enumerates all printer drivers by level and architecture.
7190 ****************************************************************************/
7192 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
7193 const struct auth_serversupplied_info *server_info,
7194 struct messaging_context *msg_ctx,
7195 const char *servername,
7196 const char *architecture,
7197 uint32_t level,
7198 union spoolss_DriverInfo **info_p,
7199 uint32_t *count_p)
7201 int i;
7202 uint32_t version;
7203 struct spoolss_DriverInfo8 *driver;
7204 union spoolss_DriverInfo *info = NULL;
7205 uint32_t count = 0;
7206 WERROR result = WERR_OK;
7207 uint32_t num_drivers;
7208 const char **drivers;
7210 *count_p = 0;
7211 *info_p = NULL;
7213 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7214 result = winreg_get_driver_list(mem_ctx, server_info, msg_ctx,
7215 architecture, version,
7216 &num_drivers, &drivers);
7217 if (!W_ERROR_IS_OK(result)) {
7218 goto out;
7220 DEBUG(4, ("we have:[%d] drivers in environment"
7221 " [%s] and version [%d]\n",
7222 num_drivers, architecture, version));
7224 if (num_drivers != 0) {
7225 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
7226 union spoolss_DriverInfo,
7227 count + num_drivers);
7228 if (!info) {
7229 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7230 "failed to enlarge driver info buffer!\n"));
7231 result = WERR_NOMEM;
7232 goto out;
7236 for (i = 0; i < num_drivers; i++) {
7237 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
7239 result = winreg_get_driver(mem_ctx, server_info,
7240 msg_ctx,
7241 architecture, drivers[i],
7242 version, &driver);
7243 if (!W_ERROR_IS_OK(result)) {
7244 goto out;
7247 switch (level) {
7248 case 1:
7249 result = fill_printer_driver_info1(info, &info[count+i].info1,
7250 driver, servername);
7251 break;
7252 case 2:
7253 result = fill_printer_driver_info2(info, &info[count+i].info2,
7254 driver, servername);
7255 break;
7256 case 3:
7257 result = fill_printer_driver_info3(info, &info[count+i].info3,
7258 driver, servername);
7259 break;
7260 case 4:
7261 result = fill_printer_driver_info4(info, &info[count+i].info4,
7262 driver, servername);
7263 break;
7264 case 5:
7265 result = fill_printer_driver_info5(info, &info[count+i].info5,
7266 driver, servername);
7267 break;
7268 case 6:
7269 result = fill_printer_driver_info6(info, &info[count+i].info6,
7270 driver, servername);
7271 break;
7272 case 8:
7273 result = fill_printer_driver_info8(info, &info[count+i].info8,
7274 driver, servername);
7275 break;
7276 default:
7277 result = WERR_UNKNOWN_LEVEL;
7278 break;
7281 TALLOC_FREE(driver);
7283 if (!W_ERROR_IS_OK(result)) {
7284 goto out;
7288 count += num_drivers;
7289 TALLOC_FREE(drivers);
7292 out:
7293 TALLOC_FREE(drivers);
7295 if (!W_ERROR_IS_OK(result)) {
7296 TALLOC_FREE(info);
7297 return result;
7300 *info_p = info;
7301 *count_p = count;
7303 return WERR_OK;
7306 /****************************************************************************
7307 Enumerates all printer drivers by level.
7308 ****************************************************************************/
7310 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
7311 const struct auth_serversupplied_info *server_info,
7312 struct messaging_context *msg_ctx,
7313 const char *servername,
7314 const char *architecture,
7315 uint32_t level,
7316 union spoolss_DriverInfo **info_p,
7317 uint32_t *count_p)
7319 uint32_t a,i;
7320 WERROR result = WERR_OK;
7322 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
7324 for (a=0; archi_table[a].long_archi != NULL; a++) {
7326 union spoolss_DriverInfo *info = NULL;
7327 uint32_t count = 0;
7329 result = enumprinterdrivers_level_by_architecture(mem_ctx,
7330 server_info,
7331 msg_ctx,
7332 servername,
7333 archi_table[a].long_archi,
7334 level,
7335 &info,
7336 &count);
7337 if (!W_ERROR_IS_OK(result)) {
7338 continue;
7341 for (i=0; i < count; i++) {
7342 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
7343 info[i], info_p, count_p);
7347 return result;
7350 return enumprinterdrivers_level_by_architecture(mem_ctx,
7351 server_info,
7352 msg_ctx,
7353 servername,
7354 architecture,
7355 level,
7356 info_p,
7357 count_p);
7360 /****************************************************************
7361 _spoolss_EnumPrinterDrivers
7362 ****************************************************************/
7364 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
7365 struct spoolss_EnumPrinterDrivers *r)
7367 const char *cservername;
7368 WERROR result;
7370 /* that's an [in out] buffer */
7372 if (!r->in.buffer && (r->in.offered != 0)) {
7373 return WERR_INVALID_PARAM;
7376 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7378 *r->out.needed = 0;
7379 *r->out.count = 0;
7380 *r->out.info = NULL;
7382 cservername = canon_servername(r->in.server);
7384 if (!is_myname_or_ipaddr(cservername)) {
7385 return WERR_UNKNOWN_PRINTER_DRIVER;
7388 result = enumprinterdrivers_level(p->mem_ctx,
7389 get_server_info_system(),
7390 p->msg_ctx,
7391 cservername,
7392 r->in.environment,
7393 r->in.level,
7394 r->out.info,
7395 r->out.count);
7396 if (!W_ERROR_IS_OK(result)) {
7397 return result;
7400 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7401 spoolss_EnumPrinterDrivers,
7402 *r->out.info, r->in.level,
7403 *r->out.count);
7404 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7405 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7407 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7410 /****************************************************************
7411 _spoolss_EnumForms
7412 ****************************************************************/
7414 WERROR _spoolss_EnumForms(struct pipes_struct *p,
7415 struct spoolss_EnumForms *r)
7417 WERROR result;
7419 *r->out.count = 0;
7420 *r->out.needed = 0;
7421 *r->out.info = NULL;
7423 /* that's an [in out] buffer */
7425 if (!r->in.buffer && (r->in.offered != 0) ) {
7426 return WERR_INVALID_PARAM;
7429 DEBUG(4,("_spoolss_EnumForms\n"));
7430 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7431 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7433 switch (r->in.level) {
7434 case 1:
7435 result = winreg_printer_enumforms1(p->mem_ctx,
7436 get_server_info_system(),
7437 p->msg_ctx,
7438 r->out.count,
7439 r->out.info);
7440 break;
7441 default:
7442 result = WERR_UNKNOWN_LEVEL;
7443 break;
7446 if (!W_ERROR_IS_OK(result)) {
7447 return result;
7450 if (*r->out.count == 0) {
7451 return WERR_NO_MORE_ITEMS;
7454 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7455 spoolss_EnumForms,
7456 *r->out.info, r->in.level,
7457 *r->out.count);
7458 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7459 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7461 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7464 /****************************************************************
7465 _spoolss_GetForm
7466 ****************************************************************/
7468 WERROR _spoolss_GetForm(struct pipes_struct *p,
7469 struct spoolss_GetForm *r)
7471 WERROR result;
7473 /* that's an [in out] buffer */
7475 if (!r->in.buffer && (r->in.offered != 0)) {
7476 return WERR_INVALID_PARAM;
7479 DEBUG(4,("_spoolss_GetForm\n"));
7480 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7481 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7483 switch (r->in.level) {
7484 case 1:
7485 result = winreg_printer_getform1(p->mem_ctx,
7486 get_server_info_system(),
7487 p->msg_ctx,
7488 r->in.form_name,
7489 &r->out.info->info1);
7490 break;
7491 default:
7492 result = WERR_UNKNOWN_LEVEL;
7493 break;
7496 if (!W_ERROR_IS_OK(result)) {
7497 TALLOC_FREE(r->out.info);
7498 return result;
7501 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7502 r->out.info, r->in.level);
7503 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7505 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7508 /****************************************************************************
7509 ****************************************************************************/
7511 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7512 struct spoolss_PortInfo1 *r,
7513 const char *name)
7515 r->port_name = talloc_strdup(mem_ctx, name);
7516 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7518 return WERR_OK;
7521 /****************************************************************************
7522 TODO: This probably needs distinguish between TCP/IP and Local ports
7523 somehow.
7524 ****************************************************************************/
7526 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7527 struct spoolss_PortInfo2 *r,
7528 const char *name)
7530 r->port_name = talloc_strdup(mem_ctx, name);
7531 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7533 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7534 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7536 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7537 W_ERROR_HAVE_NO_MEMORY(r->description);
7539 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7540 r->reserved = 0;
7542 return WERR_OK;
7546 /****************************************************************************
7547 wrapper around the enumer ports command
7548 ****************************************************************************/
7550 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7552 char *cmd = lp_enumports_cmd();
7553 char **qlines = NULL;
7554 char *command = NULL;
7555 int numlines;
7556 int ret;
7557 int fd;
7559 *count = 0;
7560 *lines = NULL;
7562 /* if no hook then just fill in the default port */
7564 if ( !*cmd ) {
7565 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7566 return WERR_NOMEM;
7568 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7569 TALLOC_FREE(qlines);
7570 return WERR_NOMEM;
7572 qlines[1] = NULL;
7573 numlines = 1;
7575 else {
7576 /* we have a valid enumport command */
7578 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7579 if (!command) {
7580 return WERR_NOMEM;
7583 DEBUG(10,("Running [%s]\n", command));
7584 ret = smbrun(command, &fd);
7585 DEBUG(10,("Returned [%d]\n", ret));
7586 TALLOC_FREE(command);
7587 if (ret != 0) {
7588 if (fd != -1) {
7589 close(fd);
7591 return WERR_ACCESS_DENIED;
7594 numlines = 0;
7595 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7596 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7597 close(fd);
7600 *count = numlines;
7601 *lines = qlines;
7603 return WERR_OK;
7606 /****************************************************************************
7607 enumports level 1.
7608 ****************************************************************************/
7610 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7611 union spoolss_PortInfo **info_p,
7612 uint32_t *count)
7614 union spoolss_PortInfo *info = NULL;
7615 int i=0;
7616 WERROR result = WERR_OK;
7617 char **qlines = NULL;
7618 int numlines = 0;
7620 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7621 if (!W_ERROR_IS_OK(result)) {
7622 goto out;
7625 if (numlines) {
7626 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7627 if (!info) {
7628 DEBUG(10,("Returning WERR_NOMEM\n"));
7629 result = WERR_NOMEM;
7630 goto out;
7633 for (i=0; i<numlines; i++) {
7634 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7635 result = fill_port_1(info, &info[i].info1, qlines[i]);
7636 if (!W_ERROR_IS_OK(result)) {
7637 goto out;
7641 TALLOC_FREE(qlines);
7643 out:
7644 if (!W_ERROR_IS_OK(result)) {
7645 TALLOC_FREE(info);
7646 TALLOC_FREE(qlines);
7647 *count = 0;
7648 *info_p = NULL;
7649 return result;
7652 *info_p = info;
7653 *count = numlines;
7655 return WERR_OK;
7658 /****************************************************************************
7659 enumports level 2.
7660 ****************************************************************************/
7662 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7663 union spoolss_PortInfo **info_p,
7664 uint32_t *count)
7666 union spoolss_PortInfo *info = NULL;
7667 int i=0;
7668 WERROR result = WERR_OK;
7669 char **qlines = NULL;
7670 int numlines = 0;
7672 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7673 if (!W_ERROR_IS_OK(result)) {
7674 goto out;
7677 if (numlines) {
7678 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7679 if (!info) {
7680 DEBUG(10,("Returning WERR_NOMEM\n"));
7681 result = WERR_NOMEM;
7682 goto out;
7685 for (i=0; i<numlines; i++) {
7686 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7687 result = fill_port_2(info, &info[i].info2, qlines[i]);
7688 if (!W_ERROR_IS_OK(result)) {
7689 goto out;
7693 TALLOC_FREE(qlines);
7695 out:
7696 if (!W_ERROR_IS_OK(result)) {
7697 TALLOC_FREE(info);
7698 TALLOC_FREE(qlines);
7699 *count = 0;
7700 *info_p = NULL;
7701 return result;
7704 *info_p = info;
7705 *count = numlines;
7707 return WERR_OK;
7710 /****************************************************************
7711 _spoolss_EnumPorts
7712 ****************************************************************/
7714 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
7715 struct spoolss_EnumPorts *r)
7717 WERROR result;
7719 /* that's an [in out] buffer */
7721 if (!r->in.buffer && (r->in.offered != 0)) {
7722 return WERR_INVALID_PARAM;
7725 DEBUG(4,("_spoolss_EnumPorts\n"));
7727 *r->out.count = 0;
7728 *r->out.needed = 0;
7729 *r->out.info = NULL;
7731 switch (r->in.level) {
7732 case 1:
7733 result = enumports_level_1(p->mem_ctx, r->out.info,
7734 r->out.count);
7735 break;
7736 case 2:
7737 result = enumports_level_2(p->mem_ctx, r->out.info,
7738 r->out.count);
7739 break;
7740 default:
7741 return WERR_UNKNOWN_LEVEL;
7744 if (!W_ERROR_IS_OK(result)) {
7745 return result;
7748 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7749 spoolss_EnumPorts,
7750 *r->out.info, r->in.level,
7751 *r->out.count);
7752 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7753 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7755 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7758 /****************************************************************************
7759 ****************************************************************************/
7761 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
7762 const char *server,
7763 struct spoolss_SetPrinterInfoCtr *info_ctr,
7764 struct spoolss_DeviceMode *devmode,
7765 struct security_descriptor *secdesc,
7766 struct spoolss_UserLevelCtr *user_ctr,
7767 struct policy_handle *handle)
7769 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7770 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7771 int snum;
7772 WERROR err = WERR_OK;
7774 /* samba does not have a concept of local, non-shared printers yet, so
7775 * make sure we always setup sharename - gd */
7776 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7777 (info2->printername != NULL && info2->printername[0] != '\0')) {
7778 DEBUG(5, ("spoolss_addprinterex_level_2: "
7779 "no sharename has been set, setting printername %s as sharename\n",
7780 info2->printername));
7781 info2->sharename = info2->printername;
7784 /* check to see if the printer already exists */
7785 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7786 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7787 info2->sharename));
7788 return WERR_PRINTER_ALREADY_EXISTS;
7791 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7792 if ((snum = print_queue_snum(info2->printername)) != -1) {
7793 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7794 info2->printername));
7795 return WERR_PRINTER_ALREADY_EXISTS;
7799 /* validate printer info struct */
7800 if (!info2->printername || strlen(info2->printername) == 0) {
7801 return WERR_INVALID_PRINTER_NAME;
7803 if (!info2->portname || strlen(info2->portname) == 0) {
7804 return WERR_UNKNOWN_PORT;
7806 if (!info2->drivername || strlen(info2->drivername) == 0) {
7807 return WERR_UNKNOWN_PRINTER_DRIVER;
7809 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7810 return WERR_UNKNOWN_PRINTPROCESSOR;
7813 /* FIXME!!! smbd should check to see if the driver is installed before
7814 trying to add a printer like this --jerry */
7816 if (*lp_addprinter_cmd() ) {
7817 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7818 info2, p->client_id->addr,
7819 p->msg_ctx) ) {
7820 return WERR_ACCESS_DENIED;
7822 } else {
7823 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7824 "smb.conf parameter \"addprinter command\" is defined. This"
7825 "parameter must exist for this call to succeed\n",
7826 info2->sharename ));
7829 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7830 return WERR_ACCESS_DENIED;
7833 /* you must be a printer admin to add a new printer */
7834 if (!print_access_check(p->server_info,
7835 p->msg_ctx,
7836 snum,
7837 PRINTER_ACCESS_ADMINISTER)) {
7838 return WERR_ACCESS_DENIED;
7842 * Do sanity check on the requested changes for Samba.
7845 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7846 return WERR_INVALID_PARAM;
7849 if (devmode == NULL) {
7850 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7853 update_dsspooler(p->mem_ctx,
7854 get_server_info_system(),
7855 p->msg_ctx,
7857 info2,
7858 NULL);
7860 err = winreg_update_printer(p->mem_ctx,
7861 get_server_info_system(),
7862 p->msg_ctx,
7863 info2->sharename,
7864 info2_mask,
7865 info2,
7866 devmode,
7867 secdesc);
7868 if (!W_ERROR_IS_OK(err)) {
7869 return err;
7872 err = open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER);
7873 if (!W_ERROR_IS_OK(err)) {
7874 /* Handle open failed - remove addition. */
7875 ZERO_STRUCTP(handle);
7876 return err;
7879 return WERR_OK;
7882 /****************************************************************
7883 _spoolss_AddPrinterEx
7884 ****************************************************************/
7886 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
7887 struct spoolss_AddPrinterEx *r)
7889 switch (r->in.info_ctr->level) {
7890 case 1:
7891 /* we don't handle yet */
7892 /* but I know what to do ... */
7893 return WERR_UNKNOWN_LEVEL;
7894 case 2:
7895 return spoolss_addprinterex_level_2(p, r->in.server,
7896 r->in.info_ctr,
7897 r->in.devmode_ctr->devmode,
7898 r->in.secdesc_ctr->sd,
7899 r->in.userlevel_ctr,
7900 r->out.handle);
7901 default:
7902 return WERR_UNKNOWN_LEVEL;
7906 /****************************************************************
7907 _spoolss_AddPrinter
7908 ****************************************************************/
7910 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
7911 struct spoolss_AddPrinter *r)
7913 struct spoolss_AddPrinterEx a;
7914 struct spoolss_UserLevelCtr userlevel_ctr;
7916 ZERO_STRUCT(userlevel_ctr);
7918 userlevel_ctr.level = 1;
7920 a.in.server = r->in.server;
7921 a.in.info_ctr = r->in.info_ctr;
7922 a.in.devmode_ctr = r->in.devmode_ctr;
7923 a.in.secdesc_ctr = r->in.secdesc_ctr;
7924 a.in.userlevel_ctr = &userlevel_ctr;
7925 a.out.handle = r->out.handle;
7927 return _spoolss_AddPrinterEx(p, &a);
7930 /****************************************************************
7931 _spoolss_AddPrinterDriverEx
7932 ****************************************************************/
7934 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
7935 struct spoolss_AddPrinterDriverEx *r)
7937 WERROR err = WERR_OK;
7938 const char *driver_name = NULL;
7939 uint32_t version;
7940 const char *fn;
7942 switch (p->opnum) {
7943 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7944 fn = "_spoolss_AddPrinterDriver";
7945 break;
7946 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7947 fn = "_spoolss_AddPrinterDriverEx";
7948 break;
7949 default:
7950 return WERR_INVALID_PARAM;
7954 * we only support the semantics of AddPrinterDriver()
7955 * i.e. only copy files that are newer than existing ones
7958 if (r->in.flags == 0) {
7959 return WERR_INVALID_PARAM;
7962 if (r->in.flags != APD_COPY_NEW_FILES) {
7963 return WERR_ACCESS_DENIED;
7966 /* FIXME */
7967 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7968 /* Clever hack from Martin Zielinski <mz@seh.de>
7969 * to allow downgrade from level 8 (Vista).
7971 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7972 r->in.info_ctr->level));
7973 return WERR_UNKNOWN_LEVEL;
7976 DEBUG(5,("Cleaning driver's information\n"));
7977 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
7978 if (!W_ERROR_IS_OK(err))
7979 goto done;
7981 DEBUG(5,("Moving driver to final destination\n"));
7982 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7983 &err)) ) {
7984 goto done;
7987 err = winreg_add_driver(p->mem_ctx,
7988 get_server_info_system(),
7989 p->msg_ctx,
7990 r->in.info_ctr,
7991 &driver_name,
7992 &version);
7993 if (!W_ERROR_IS_OK(err)) {
7994 goto done;
7998 * I think this is where he DrvUpgradePrinter() hook would be
7999 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8000 * server. Right now, we just need to send ourselves a message
8001 * to update each printer bound to this driver. --jerry
8004 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
8005 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8006 fn, driver_name));
8009 done:
8010 return err;
8013 /****************************************************************
8014 _spoolss_AddPrinterDriver
8015 ****************************************************************/
8017 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
8018 struct spoolss_AddPrinterDriver *r)
8020 struct spoolss_AddPrinterDriverEx a;
8022 switch (r->in.info_ctr->level) {
8023 case 2:
8024 case 3:
8025 case 4:
8026 case 5:
8027 break;
8028 default:
8029 return WERR_UNKNOWN_LEVEL;
8032 a.in.servername = r->in.servername;
8033 a.in.info_ctr = r->in.info_ctr;
8034 a.in.flags = APD_COPY_NEW_FILES;
8036 return _spoolss_AddPrinterDriverEx(p, &a);
8039 /****************************************************************************
8040 ****************************************************************************/
8042 struct _spoolss_paths {
8043 int type;
8044 const char *share;
8045 const char *dir;
8048 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
8050 static const struct _spoolss_paths spoolss_paths[]= {
8051 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
8052 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
8055 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
8056 const char *servername,
8057 const char *environment,
8058 int component,
8059 char **path)
8061 const char *pservername = NULL;
8062 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
8063 const char *short_archi;
8065 *path = NULL;
8067 /* environment may be empty */
8068 if (environment && strlen(environment)) {
8069 long_archi = environment;
8072 /* servername may be empty */
8073 if (servername && strlen(servername)) {
8074 pservername = canon_servername(servername);
8076 if (!is_myname_or_ipaddr(pservername)) {
8077 return WERR_INVALID_PARAM;
8081 if (!(short_archi = get_short_archi(long_archi))) {
8082 return WERR_INVALID_ENVIRONMENT;
8085 switch (component) {
8086 case SPOOLSS_PRTPROCS_PATH:
8087 case SPOOLSS_DRIVER_PATH:
8088 if (pservername) {
8089 *path = talloc_asprintf(mem_ctx,
8090 "\\\\%s\\%s\\%s",
8091 pservername,
8092 spoolss_paths[component].share,
8093 short_archi);
8094 } else {
8095 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
8096 SPOOLSS_DEFAULT_SERVER_PATH,
8097 spoolss_paths[component].dir,
8098 short_archi);
8100 break;
8101 default:
8102 return WERR_INVALID_PARAM;
8105 if (!*path) {
8106 return WERR_NOMEM;
8109 return WERR_OK;
8112 /****************************************************************************
8113 ****************************************************************************/
8115 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
8116 const char *servername,
8117 const char *environment,
8118 struct spoolss_DriverDirectoryInfo1 *r)
8120 WERROR werr;
8121 char *path = NULL;
8123 werr = compose_spoolss_server_path(mem_ctx,
8124 servername,
8125 environment,
8126 SPOOLSS_DRIVER_PATH,
8127 &path);
8128 if (!W_ERROR_IS_OK(werr)) {
8129 return werr;
8132 DEBUG(4,("printer driver directory: [%s]\n", path));
8134 r->directory_name = path;
8136 return WERR_OK;
8139 /****************************************************************
8140 _spoolss_GetPrinterDriverDirectory
8141 ****************************************************************/
8143 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
8144 struct spoolss_GetPrinterDriverDirectory *r)
8146 WERROR werror;
8148 /* that's an [in out] buffer */
8150 if (!r->in.buffer && (r->in.offered != 0)) {
8151 return WERR_INVALID_PARAM;
8154 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8155 r->in.level));
8157 *r->out.needed = 0;
8159 /* r->in.level is ignored */
8161 werror = getprinterdriverdir_level_1(p->mem_ctx,
8162 r->in.server,
8163 r->in.environment,
8164 &r->out.info->info1);
8165 if (!W_ERROR_IS_OK(werror)) {
8166 TALLOC_FREE(r->out.info);
8167 return werror;
8170 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
8171 r->out.info, r->in.level);
8172 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8174 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8177 /****************************************************************
8178 _spoolss_EnumPrinterData
8179 ****************************************************************/
8181 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
8182 struct spoolss_EnumPrinterData *r)
8184 WERROR result;
8185 struct spoolss_EnumPrinterDataEx r2;
8186 uint32_t count;
8187 struct spoolss_PrinterEnumValues *info, *val = NULL;
8188 uint32_t needed;
8190 r2.in.handle = r->in.handle;
8191 r2.in.key_name = "PrinterDriverData";
8192 r2.in.offered = 0;
8193 r2.out.count = &count;
8194 r2.out.info = &info;
8195 r2.out.needed = &needed;
8197 result = _spoolss_EnumPrinterDataEx(p, &r2);
8198 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8199 r2.in.offered = needed;
8200 result = _spoolss_EnumPrinterDataEx(p, &r2);
8202 if (!W_ERROR_IS_OK(result)) {
8203 return result;
8207 * The NT machine wants to know the biggest size of value and data
8209 * cf: MSDN EnumPrinterData remark section
8212 if (!r->in.value_offered && !r->in.data_offered) {
8213 uint32_t biggest_valuesize = 0;
8214 uint32_t biggest_datasize = 0;
8215 int i, name_length;
8217 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8219 for (i=0; i<count; i++) {
8221 name_length = strlen(info[i].value_name);
8222 if (strlen(info[i].value_name) > biggest_valuesize) {
8223 biggest_valuesize = name_length;
8226 if (info[i].data_length > biggest_datasize) {
8227 biggest_datasize = info[i].data_length;
8230 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8231 biggest_datasize));
8234 /* the value is an UNICODE string but real_value_size is the length
8235 in bytes including the trailing 0 */
8237 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8238 *r->out.data_needed = biggest_datasize;
8240 DEBUG(6,("final values: [%d], [%d]\n",
8241 *r->out.value_needed, *r->out.data_needed));
8243 return WERR_OK;
8246 if (r->in.enum_index < count) {
8247 val = &info[r->in.enum_index];
8250 if (val == NULL) {
8251 /* out_value should default to "" or else NT4 has
8252 problems unmarshalling the response */
8254 if (r->in.value_offered) {
8255 *r->out.value_needed = 1;
8256 r->out.value_name = talloc_strdup(r, "");
8257 if (!r->out.value_name) {
8258 return WERR_NOMEM;
8260 } else {
8261 r->out.value_name = NULL;
8262 *r->out.value_needed = 0;
8265 /* the data is counted in bytes */
8267 *r->out.data_needed = r->in.data_offered;
8269 result = WERR_NO_MORE_ITEMS;
8270 } else {
8272 * the value is:
8273 * - counted in bytes in the request
8274 * - counted in UNICODE chars in the max reply
8275 * - counted in bytes in the real size
8277 * take a pause *before* coding not *during* coding
8280 /* name */
8281 if (r->in.value_offered) {
8282 r->out.value_name = talloc_strdup(r, val->value_name);
8283 if (!r->out.value_name) {
8284 return WERR_NOMEM;
8286 *r->out.value_needed = val->value_name_len;
8287 } else {
8288 r->out.value_name = NULL;
8289 *r->out.value_needed = 0;
8292 /* type */
8294 *r->out.type = val->type;
8296 /* data - counted in bytes */
8299 * See the section "Dynamically Typed Query Parameters"
8300 * in MS-RPRN.
8303 if (r->out.data && val->data && val->data->data &&
8304 val->data_length && r->in.data_offered) {
8305 memcpy(r->out.data, val->data->data,
8306 MIN(val->data_length,r->in.data_offered));
8309 *r->out.data_needed = val->data_length;
8311 result = WERR_OK;
8314 return result;
8317 /****************************************************************
8318 _spoolss_SetPrinterData
8319 ****************************************************************/
8321 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
8322 struct spoolss_SetPrinterData *r)
8324 struct spoolss_SetPrinterDataEx r2;
8326 r2.in.handle = r->in.handle;
8327 r2.in.key_name = "PrinterDriverData";
8328 r2.in.value_name = r->in.value_name;
8329 r2.in.type = r->in.type;
8330 r2.in.data = r->in.data;
8331 r2.in.offered = r->in.offered;
8333 return _spoolss_SetPrinterDataEx(p, &r2);
8336 /****************************************************************
8337 _spoolss_ResetPrinter
8338 ****************************************************************/
8340 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
8341 struct spoolss_ResetPrinter *r)
8343 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8344 int snum;
8346 DEBUG(5,("_spoolss_ResetPrinter\n"));
8349 * All we do is to check to see if the handle and queue is valid.
8350 * This call really doesn't mean anything to us because we only
8351 * support RAW printing. --jerry
8354 if (!Printer) {
8355 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8356 OUR_HANDLE(r->in.handle)));
8357 return WERR_BADFID;
8360 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8361 return WERR_BADFID;
8364 /* blindly return success */
8365 return WERR_OK;
8368 /****************************************************************
8369 _spoolss_DeletePrinterData
8370 ****************************************************************/
8372 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
8373 struct spoolss_DeletePrinterData *r)
8375 struct spoolss_DeletePrinterDataEx r2;
8377 r2.in.handle = r->in.handle;
8378 r2.in.key_name = "PrinterDriverData";
8379 r2.in.value_name = r->in.value_name;
8381 return _spoolss_DeletePrinterDataEx(p, &r2);
8384 /****************************************************************
8385 _spoolss_AddForm
8386 ****************************************************************/
8388 WERROR _spoolss_AddForm(struct pipes_struct *p,
8389 struct spoolss_AddForm *r)
8391 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8392 int snum = -1;
8393 WERROR status = WERR_OK;
8395 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8397 DEBUG(5,("_spoolss_AddForm\n"));
8399 if (!Printer) {
8400 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8401 OUR_HANDLE(r->in.handle)));
8402 return WERR_BADFID;
8405 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8406 and not a printer admin, then fail */
8408 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8409 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
8410 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8411 p->server_info->info3->base.domain.string,
8412 NULL,
8413 p->server_info->ptok,
8414 lp_printer_admin(snum))) {
8415 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8416 return WERR_ACCESS_DENIED;
8419 switch (form->flags) {
8420 case SPOOLSS_FORM_USER:
8421 case SPOOLSS_FORM_BUILTIN:
8422 case SPOOLSS_FORM_PRINTER:
8423 break;
8424 default:
8425 return WERR_INVALID_PARAM;
8428 status = winreg_printer_addform1(p->mem_ctx,
8429 get_server_info_system(),
8430 p->msg_ctx,
8431 form);
8432 if (!W_ERROR_IS_OK(status)) {
8433 return status;
8437 * ChangeID must always be set if this is a printer
8439 if (Printer->printer_type == SPLHND_PRINTER) {
8440 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8441 return WERR_BADFID;
8444 status = winreg_printer_update_changeid(p->mem_ctx,
8445 get_server_info_system(),
8446 p->msg_ctx,
8447 lp_const_servicename(snum));
8448 if (!W_ERROR_IS_OK(status)) {
8449 return status;
8453 return status;
8456 /****************************************************************
8457 _spoolss_DeleteForm
8458 ****************************************************************/
8460 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8461 struct spoolss_DeleteForm *r)
8463 const char *form_name = r->in.form_name;
8464 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8465 int snum = -1;
8466 WERROR status = WERR_OK;
8468 DEBUG(5,("_spoolss_DeleteForm\n"));
8470 if (!Printer) {
8471 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8472 OUR_HANDLE(r->in.handle)));
8473 return WERR_BADFID;
8476 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8477 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
8478 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8479 p->server_info->info3->base.domain.string,
8480 NULL,
8481 p->server_info->ptok,
8482 lp_printer_admin(snum))) {
8483 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8484 return WERR_ACCESS_DENIED;
8487 status = winreg_printer_deleteform1(p->mem_ctx,
8488 get_server_info_system(),
8489 p->msg_ctx,
8490 form_name);
8491 if (!W_ERROR_IS_OK(status)) {
8492 return status;
8496 * ChangeID must always be set if this is a printer
8498 if (Printer->printer_type == SPLHND_PRINTER) {
8499 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8500 return WERR_BADFID;
8503 status = winreg_printer_update_changeid(p->mem_ctx,
8504 get_server_info_system(),
8505 p->msg_ctx,
8506 lp_const_servicename(snum));
8507 if (!W_ERROR_IS_OK(status)) {
8508 return status;
8512 return status;
8515 /****************************************************************
8516 _spoolss_SetForm
8517 ****************************************************************/
8519 WERROR _spoolss_SetForm(struct pipes_struct *p,
8520 struct spoolss_SetForm *r)
8522 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8523 const char *form_name = r->in.form_name;
8524 int snum = -1;
8525 WERROR status = WERR_OK;
8527 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8529 DEBUG(5,("_spoolss_SetForm\n"));
8531 if (!Printer) {
8532 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8533 OUR_HANDLE(r->in.handle)));
8534 return WERR_BADFID;
8537 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8538 and not a printer admin, then fail */
8540 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8541 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
8542 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8543 p->server_info->info3->base.domain.string,
8544 NULL,
8545 p->server_info->ptok,
8546 lp_printer_admin(snum))) {
8547 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8548 return WERR_ACCESS_DENIED;
8551 status = winreg_printer_setform1(p->mem_ctx,
8552 get_server_info_system(),
8553 p->msg_ctx,
8554 form_name,
8555 form);
8556 if (!W_ERROR_IS_OK(status)) {
8557 return status;
8561 * ChangeID must always be set if this is a printer
8563 if (Printer->printer_type == SPLHND_PRINTER) {
8564 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8565 return WERR_BADFID;
8568 status = winreg_printer_update_changeid(p->mem_ctx,
8569 get_server_info_system(),
8570 p->msg_ctx,
8571 lp_const_servicename(snum));
8572 if (!W_ERROR_IS_OK(status)) {
8573 return status;
8577 return status;
8580 /****************************************************************************
8581 fill_print_processor1
8582 ****************************************************************************/
8584 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8585 struct spoolss_PrintProcessorInfo1 *r,
8586 const char *print_processor_name)
8588 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8589 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8591 return WERR_OK;
8594 /****************************************************************************
8595 enumprintprocessors level 1.
8596 ****************************************************************************/
8598 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8599 union spoolss_PrintProcessorInfo **info_p,
8600 uint32_t *count)
8602 union spoolss_PrintProcessorInfo *info;
8603 WERROR result;
8605 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8606 W_ERROR_HAVE_NO_MEMORY(info);
8608 *count = 1;
8610 result = fill_print_processor1(info, &info[0].info1, "winprint");
8611 if (!W_ERROR_IS_OK(result)) {
8612 goto out;
8615 out:
8616 if (!W_ERROR_IS_OK(result)) {
8617 TALLOC_FREE(info);
8618 *count = 0;
8619 return result;
8622 *info_p = info;
8624 return WERR_OK;
8627 /****************************************************************
8628 _spoolss_EnumPrintProcessors
8629 ****************************************************************/
8631 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8632 struct spoolss_EnumPrintProcessors *r)
8634 WERROR result;
8636 /* that's an [in out] buffer */
8638 if (!r->in.buffer && (r->in.offered != 0)) {
8639 return WERR_INVALID_PARAM;
8642 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8645 * Enumerate the print processors ...
8647 * Just reply with "winprint", to keep NT happy
8648 * and I can use my nice printer checker.
8651 *r->out.count = 0;
8652 *r->out.needed = 0;
8653 *r->out.info = NULL;
8655 if (!get_short_archi(r->in.environment)) {
8656 return WERR_INVALID_ENVIRONMENT;
8659 switch (r->in.level) {
8660 case 1:
8661 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8662 r->out.count);
8663 break;
8664 default:
8665 return WERR_UNKNOWN_LEVEL;
8668 if (!W_ERROR_IS_OK(result)) {
8669 return result;
8672 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8673 spoolss_EnumPrintProcessors,
8674 *r->out.info, r->in.level,
8675 *r->out.count);
8676 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8677 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8679 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8682 /****************************************************************************
8683 fill_printprocdatatype1
8684 ****************************************************************************/
8686 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8687 struct spoolss_PrintProcDataTypesInfo1 *r,
8688 const char *name_array)
8690 r->name_array = talloc_strdup(mem_ctx, name_array);
8691 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8693 return WERR_OK;
8696 /****************************************************************************
8697 enumprintprocdatatypes level 1.
8698 ****************************************************************************/
8700 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8701 union spoolss_PrintProcDataTypesInfo **info_p,
8702 uint32_t *count)
8704 WERROR result;
8705 union spoolss_PrintProcDataTypesInfo *info;
8707 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8708 W_ERROR_HAVE_NO_MEMORY(info);
8710 *count = 1;
8712 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8713 if (!W_ERROR_IS_OK(result)) {
8714 goto out;
8717 out:
8718 if (!W_ERROR_IS_OK(result)) {
8719 TALLOC_FREE(info);
8720 *count = 0;
8721 return result;
8724 *info_p = info;
8726 return WERR_OK;
8729 /****************************************************************
8730 _spoolss_EnumPrintProcDataTypes
8731 ****************************************************************/
8733 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
8734 struct spoolss_EnumPrintProcDataTypes *r)
8736 WERROR result;
8738 /* that's an [in out] buffer */
8740 if (!r->in.buffer && (r->in.offered != 0)) {
8741 return WERR_INVALID_PARAM;
8744 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8746 *r->out.count = 0;
8747 *r->out.needed = 0;
8748 *r->out.info = NULL;
8750 if (r->in.print_processor_name == NULL ||
8751 !strequal(r->in.print_processor_name, "winprint")) {
8752 return WERR_UNKNOWN_PRINTPROCESSOR;
8755 switch (r->in.level) {
8756 case 1:
8757 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8758 r->out.count);
8759 break;
8760 default:
8761 return WERR_UNKNOWN_LEVEL;
8764 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8765 spoolss_EnumPrintProcDataTypes,
8766 *r->out.info, r->in.level,
8767 *r->out.count);
8768 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8769 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8771 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8774 /****************************************************************************
8775 fill_monitor_1
8776 ****************************************************************************/
8778 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8779 struct spoolss_MonitorInfo1 *r,
8780 const char *monitor_name)
8782 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8783 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8785 return WERR_OK;
8788 /****************************************************************************
8789 fill_monitor_2
8790 ****************************************************************************/
8792 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8793 struct spoolss_MonitorInfo2 *r,
8794 const char *monitor_name,
8795 const char *environment,
8796 const char *dll_name)
8798 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8799 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8800 r->environment = talloc_strdup(mem_ctx, environment);
8801 W_ERROR_HAVE_NO_MEMORY(r->environment);
8802 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8803 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8805 return WERR_OK;
8808 /****************************************************************************
8809 enumprintmonitors level 1.
8810 ****************************************************************************/
8812 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8813 union spoolss_MonitorInfo **info_p,
8814 uint32_t *count)
8816 union spoolss_MonitorInfo *info;
8817 WERROR result = WERR_OK;
8819 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8820 W_ERROR_HAVE_NO_MEMORY(info);
8822 *count = 2;
8824 result = fill_monitor_1(info, &info[0].info1,
8825 SPL_LOCAL_PORT);
8826 if (!W_ERROR_IS_OK(result)) {
8827 goto out;
8830 result = fill_monitor_1(info, &info[1].info1,
8831 SPL_TCPIP_PORT);
8832 if (!W_ERROR_IS_OK(result)) {
8833 goto out;
8836 out:
8837 if (!W_ERROR_IS_OK(result)) {
8838 TALLOC_FREE(info);
8839 *count = 0;
8840 return result;
8843 *info_p = info;
8845 return WERR_OK;
8848 /****************************************************************************
8849 enumprintmonitors level 2.
8850 ****************************************************************************/
8852 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8853 union spoolss_MonitorInfo **info_p,
8854 uint32_t *count)
8856 union spoolss_MonitorInfo *info;
8857 WERROR result = WERR_OK;
8859 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8860 W_ERROR_HAVE_NO_MEMORY(info);
8862 *count = 2;
8864 result = fill_monitor_2(info, &info[0].info2,
8865 SPL_LOCAL_PORT,
8866 "Windows NT X86", /* FIXME */
8867 "localmon.dll");
8868 if (!W_ERROR_IS_OK(result)) {
8869 goto out;
8872 result = fill_monitor_2(info, &info[1].info2,
8873 SPL_TCPIP_PORT,
8874 "Windows NT X86", /* FIXME */
8875 "tcpmon.dll");
8876 if (!W_ERROR_IS_OK(result)) {
8877 goto out;
8880 out:
8881 if (!W_ERROR_IS_OK(result)) {
8882 TALLOC_FREE(info);
8883 *count = 0;
8884 return result;
8887 *info_p = info;
8889 return WERR_OK;
8892 /****************************************************************
8893 _spoolss_EnumMonitors
8894 ****************************************************************/
8896 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
8897 struct spoolss_EnumMonitors *r)
8899 WERROR result;
8901 /* that's an [in out] buffer */
8903 if (!r->in.buffer && (r->in.offered != 0)) {
8904 return WERR_INVALID_PARAM;
8907 DEBUG(5,("_spoolss_EnumMonitors\n"));
8910 * Enumerate the print monitors ...
8912 * Just reply with "Local Port", to keep NT happy
8913 * and I can use my nice printer checker.
8916 *r->out.count = 0;
8917 *r->out.needed = 0;
8918 *r->out.info = NULL;
8920 switch (r->in.level) {
8921 case 1:
8922 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8923 r->out.count);
8924 break;
8925 case 2:
8926 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8927 r->out.count);
8928 break;
8929 default:
8930 return WERR_UNKNOWN_LEVEL;
8933 if (!W_ERROR_IS_OK(result)) {
8934 return result;
8937 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8938 spoolss_EnumMonitors,
8939 *r->out.info, r->in.level,
8940 *r->out.count);
8941 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8942 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8944 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8947 /****************************************************************************
8948 ****************************************************************************/
8950 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8951 const print_queue_struct *queue,
8952 int count, int snum,
8953 struct spoolss_PrinterInfo2 *pinfo2,
8954 uint32_t jobid,
8955 struct spoolss_JobInfo1 *r)
8957 int i = 0;
8958 bool found = false;
8960 for (i=0; i<count; i++) {
8961 if (queue[i].job == (int)jobid) {
8962 found = true;
8963 break;
8967 if (found == false) {
8968 /* NT treats not found as bad param... yet another bad choice */
8969 return WERR_INVALID_PARAM;
8972 return fill_job_info1(mem_ctx,
8974 &queue[i],
8976 snum,
8977 pinfo2);
8980 /****************************************************************************
8981 ****************************************************************************/
8983 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8984 const print_queue_struct *queue,
8985 int count, int snum,
8986 struct spoolss_PrinterInfo2 *pinfo2,
8987 uint32_t jobid,
8988 struct spoolss_JobInfo2 *r)
8990 int i = 0;
8991 bool found = false;
8992 struct spoolss_DeviceMode *devmode;
8993 WERROR result;
8995 for (i=0; i<count; i++) {
8996 if (queue[i].job == (int)jobid) {
8997 found = true;
8998 break;
9002 if (found == false) {
9003 /* NT treats not found as bad param... yet another bad
9004 choice */
9005 return WERR_INVALID_PARAM;
9009 * if the print job does not have a DEVMODE associated with it,
9010 * just use the one for the printer. A NULL devicemode is not
9011 * a failure condition
9014 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
9015 if (!devmode) {
9016 result = spoolss_create_default_devmode(mem_ctx,
9017 pinfo2->printername,
9018 &devmode);
9019 if (!W_ERROR_IS_OK(result)) {
9020 DEBUG(3, ("Can't proceed w/o a devmode!"));
9021 return result;
9025 return fill_job_info2(mem_ctx,
9027 &queue[i],
9029 snum,
9030 pinfo2,
9031 devmode);
9034 /****************************************************************
9035 _spoolss_GetJob
9036 ****************************************************************/
9038 WERROR _spoolss_GetJob(struct pipes_struct *p,
9039 struct spoolss_GetJob *r)
9041 WERROR result = WERR_OK;
9042 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9043 int snum;
9044 int count;
9045 print_queue_struct *queue = NULL;
9046 print_status_struct prt_status;
9048 /* that's an [in out] buffer */
9050 if (!r->in.buffer && (r->in.offered != 0)) {
9051 return WERR_INVALID_PARAM;
9054 DEBUG(5,("_spoolss_GetJob\n"));
9056 *r->out.needed = 0;
9058 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9059 return WERR_BADFID;
9062 result = winreg_get_printer(p->mem_ctx,
9063 get_server_info_system(),
9064 p->msg_ctx,
9065 lp_const_servicename(snum),
9066 &pinfo2);
9067 if (!W_ERROR_IS_OK(result)) {
9068 return result;
9071 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
9073 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9074 count, prt_status.status, prt_status.message));
9076 switch (r->in.level) {
9077 case 1:
9078 result = getjob_level_1(p->mem_ctx,
9079 queue, count, snum, pinfo2,
9080 r->in.job_id, &r->out.info->info1);
9081 break;
9082 case 2:
9083 result = getjob_level_2(p->mem_ctx,
9084 queue, count, snum, pinfo2,
9085 r->in.job_id, &r->out.info->info2);
9086 break;
9087 default:
9088 result = WERR_UNKNOWN_LEVEL;
9089 break;
9092 SAFE_FREE(queue);
9093 TALLOC_FREE(pinfo2);
9095 if (!W_ERROR_IS_OK(result)) {
9096 TALLOC_FREE(r->out.info);
9097 return result;
9100 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
9101 r->in.level);
9102 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9104 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9107 /****************************************************************
9108 _spoolss_GetPrinterDataEx
9109 ****************************************************************/
9111 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
9112 struct spoolss_GetPrinterDataEx *r)
9115 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9116 const char *printer;
9117 int snum = 0;
9118 WERROR result = WERR_OK;
9119 DATA_BLOB blob;
9120 enum winreg_Type val_type;
9121 uint8_t *val_data;
9122 uint32_t val_size;
9125 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9127 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9128 r->in.key_name, r->in.value_name));
9130 /* in case of problem, return some default values */
9132 *r->out.needed = 0;
9133 *r->out.type = REG_NONE;
9135 if (!Printer) {
9136 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9137 OUR_HANDLE(r->in.handle)));
9138 result = WERR_BADFID;
9139 goto done;
9142 /* Is the handle to a printer or to the server? */
9144 if (Printer->printer_type == SPLHND_SERVER) {
9146 union spoolss_PrinterData data;
9148 result = getprinterdata_printer_server(p->mem_ctx,
9149 r->in.value_name,
9150 r->out.type,
9151 &data);
9152 if (!W_ERROR_IS_OK(result)) {
9153 return result;
9156 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
9157 *r->out.type, &data);
9158 if (!W_ERROR_IS_OK(result)) {
9159 return result;
9162 *r->out.needed = blob.length;
9164 if (r->in.offered >= *r->out.needed) {
9165 memcpy(r->out.data, blob.data, blob.length);
9168 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9171 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9172 return WERR_BADFID;
9174 printer = lp_const_servicename(snum);
9176 /* check to see if the keyname is valid */
9177 if (!strlen(r->in.key_name)) {
9178 return WERR_INVALID_PARAM;
9181 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9182 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
9183 strequal(r->in.value_name, "ChangeId")) {
9184 *r->out.type = REG_DWORD;
9185 *r->out.needed = 4;
9186 if (r->in.offered >= *r->out.needed) {
9187 uint32_t changeid = 0;
9189 result = winreg_printer_get_changeid(p->mem_ctx,
9190 get_server_info_system(),
9191 p->msg_ctx,
9192 printer,
9193 &changeid);
9194 if (!W_ERROR_IS_OK(result)) {
9195 return result;
9198 SIVAL(r->out.data, 0, changeid);
9199 result = WERR_OK;
9201 goto done;
9204 result = winreg_get_printer_dataex(p->mem_ctx,
9205 get_server_info_system(),
9206 p->msg_ctx,
9207 printer,
9208 r->in.key_name,
9209 r->in.value_name,
9210 &val_type,
9211 &val_data,
9212 &val_size);
9213 if (!W_ERROR_IS_OK(result)) {
9214 return result;
9217 *r->out.needed = val_size;
9218 *r->out.type = val_type;
9220 if (r->in.offered >= *r->out.needed) {
9221 memcpy(r->out.data, val_data, val_size);
9224 done:
9225 /* retain type when returning WERR_MORE_DATA */
9226 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
9228 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9231 /****************************************************************
9232 _spoolss_SetPrinterDataEx
9233 ****************************************************************/
9235 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
9236 struct spoolss_SetPrinterDataEx *r)
9238 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9239 int snum = 0;
9240 WERROR result = WERR_OK;
9241 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9242 char *oid_string;
9244 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9246 /* From MSDN documentation of SetPrinterDataEx: pass request to
9247 SetPrinterData if key is "PrinterDriverData" */
9249 if (!Printer) {
9250 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9251 OUR_HANDLE(r->in.handle)));
9252 return WERR_BADFID;
9255 if (Printer->printer_type == SPLHND_SERVER) {
9256 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9257 "Not implemented for server handles yet\n"));
9258 return WERR_INVALID_PARAM;
9261 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9262 return WERR_BADFID;
9266 * Access check : NT returns "access denied" if you make a
9267 * SetPrinterData call without the necessary privildge.
9268 * we were originally returning OK if nothing changed
9269 * which made Win2k issue **a lot** of SetPrinterData
9270 * when connecting to a printer --jerry
9273 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9274 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9275 "change denied by handle access permissions\n"));
9276 return WERR_ACCESS_DENIED;
9279 result = winreg_get_printer(Printer,
9280 get_server_info_system(),
9281 p->msg_ctx,
9282 lp_servicename(snum),
9283 &pinfo2);
9284 if (!W_ERROR_IS_OK(result)) {
9285 return result;
9288 /* check for OID in valuename */
9290 oid_string = strchr(r->in.value_name, ',');
9291 if (oid_string) {
9292 *oid_string = '\0';
9293 oid_string++;
9296 /* save the registry data */
9298 result = winreg_set_printer_dataex(p->mem_ctx,
9299 get_server_info_system(),
9300 p->msg_ctx,
9301 pinfo2->sharename,
9302 r->in.key_name,
9303 r->in.value_name,
9304 r->in.type,
9305 r->in.data,
9306 r->in.offered);
9308 if (W_ERROR_IS_OK(result)) {
9309 /* save the OID if one was specified */
9310 if (oid_string) {
9311 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9312 r->in.key_name, SPOOL_OID_KEY);
9313 if (!str) {
9314 result = WERR_NOMEM;
9315 goto done;
9319 * I'm not checking the status here on purpose. Don't know
9320 * if this is right, but I'm returning the status from the
9321 * previous set_printer_dataex() call. I have no idea if
9322 * this is right. --jerry
9324 winreg_set_printer_dataex(p->mem_ctx,
9325 get_server_info_system(),
9326 p->msg_ctx,
9327 pinfo2->sharename,
9328 str,
9329 r->in.value_name,
9330 REG_SZ,
9331 (uint8_t *) oid_string,
9332 strlen(oid_string) + 1);
9335 result = winreg_printer_update_changeid(p->mem_ctx,
9336 get_server_info_system(),
9337 p->msg_ctx,
9338 lp_const_servicename(snum));
9342 done:
9343 talloc_free(pinfo2);
9344 return result;
9347 /****************************************************************
9348 _spoolss_DeletePrinterDataEx
9349 ****************************************************************/
9351 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
9352 struct spoolss_DeletePrinterDataEx *r)
9354 const char *printer;
9355 int snum=0;
9356 WERROR status = WERR_OK;
9357 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9359 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9361 if (!Printer) {
9362 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9363 "Invalid handle (%s:%u:%u).\n",
9364 OUR_HANDLE(r->in.handle)));
9365 return WERR_BADFID;
9368 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9369 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9370 "printer properties change denied by handle\n"));
9371 return WERR_ACCESS_DENIED;
9374 if (!r->in.value_name || !r->in.key_name) {
9375 return WERR_NOMEM;
9378 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9379 return WERR_BADFID;
9381 printer = lp_const_servicename(snum);
9383 status = winreg_delete_printer_dataex(p->mem_ctx,
9384 get_server_info_system(),
9385 p->msg_ctx,
9386 printer,
9387 r->in.key_name,
9388 r->in.value_name);
9389 if (W_ERROR_IS_OK(status)) {
9390 status = winreg_printer_update_changeid(p->mem_ctx,
9391 get_server_info_system(),
9392 p->msg_ctx,
9393 printer);
9396 return status;
9399 /****************************************************************
9400 _spoolss_EnumPrinterKey
9401 ****************************************************************/
9403 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
9404 struct spoolss_EnumPrinterKey *r)
9406 uint32_t num_keys;
9407 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9408 int snum = 0;
9409 WERROR result = WERR_BADFILE;
9410 const char **array = NULL;
9411 DATA_BLOB blob;
9413 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9415 if (!Printer) {
9416 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9417 OUR_HANDLE(r->in.handle)));
9418 return WERR_BADFID;
9421 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9422 return WERR_BADFID;
9425 result = winreg_enum_printer_key(p->mem_ctx,
9426 get_server_info_system(),
9427 p->msg_ctx,
9428 lp_const_servicename(snum),
9429 r->in.key_name,
9430 &num_keys,
9431 &array);
9432 if (!W_ERROR_IS_OK(result)) {
9433 goto done;
9436 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9437 result = WERR_NOMEM;
9438 goto done;
9441 *r->out._ndr_size = r->in.offered / 2;
9442 *r->out.needed = blob.length;
9444 if (r->in.offered < *r->out.needed) {
9445 result = WERR_MORE_DATA;
9446 } else {
9447 result = WERR_OK;
9448 r->out.key_buffer->string_array = array;
9451 done:
9452 if (!W_ERROR_IS_OK(result)) {
9453 TALLOC_FREE(array);
9454 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9455 *r->out.needed = 0;
9459 return result;
9462 /****************************************************************
9463 _spoolss_DeletePrinterKey
9464 ****************************************************************/
9466 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9467 struct spoolss_DeletePrinterKey *r)
9469 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9470 int snum=0;
9471 WERROR status;
9472 const char *printer;
9474 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9476 if (!Printer) {
9477 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9478 OUR_HANDLE(r->in.handle)));
9479 return WERR_BADFID;
9482 /* if keyname == NULL, return error */
9483 if ( !r->in.key_name )
9484 return WERR_INVALID_PARAM;
9486 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9487 return WERR_BADFID;
9490 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9491 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9492 "printer properties change denied by handle\n"));
9493 return WERR_ACCESS_DENIED;
9496 printer = lp_const_servicename(snum);
9498 /* delete the key and all subkeys */
9499 status = winreg_delete_printer_key(p->mem_ctx,
9500 get_server_info_system(),
9501 p->msg_ctx,
9502 printer,
9503 r->in.key_name);
9504 if (W_ERROR_IS_OK(status)) {
9505 status = winreg_printer_update_changeid(p->mem_ctx,
9506 get_server_info_system(),
9507 p->msg_ctx,
9508 printer);
9511 return status;
9514 /****************************************************************
9515 _spoolss_EnumPrinterDataEx
9516 ****************************************************************/
9518 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9519 struct spoolss_EnumPrinterDataEx *r)
9521 uint32_t count = 0;
9522 struct spoolss_PrinterEnumValues *info = NULL;
9523 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9524 int snum;
9525 WERROR result;
9527 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9529 *r->out.count = 0;
9530 *r->out.needed = 0;
9531 *r->out.info = NULL;
9533 if (!Printer) {
9534 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9535 OUR_HANDLE(r->in.handle)));
9536 return WERR_BADFID;
9540 * first check for a keyname of NULL or "". Win2k seems to send
9541 * this a lot and we should send back WERR_INVALID_PARAM
9542 * no need to spend time looking up the printer in this case.
9543 * --jerry
9546 if (!strlen(r->in.key_name)) {
9547 result = WERR_INVALID_PARAM;
9548 goto done;
9551 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9552 return WERR_BADFID;
9555 /* now look for a match on the key name */
9556 result = winreg_enum_printer_dataex(p->mem_ctx,
9557 get_server_info_system(),
9558 p->msg_ctx,
9559 lp_const_servicename(snum),
9560 r->in.key_name,
9561 &count,
9562 &info);
9563 if (!W_ERROR_IS_OK(result)) {
9564 goto done;
9567 #if 0 /* FIXME - gd */
9568 /* housekeeping information in the reply */
9570 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9571 * the hand marshalled container size is a multiple
9572 * of 4 bytes for RPC alignment.
9575 if (needed % 4) {
9576 needed += 4-(needed % 4);
9578 #endif
9579 *r->out.count = count;
9580 *r->out.info = info;
9582 done:
9583 if (!W_ERROR_IS_OK(result)) {
9584 return result;
9587 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9588 spoolss_EnumPrinterDataEx,
9589 *r->out.info,
9590 *r->out.count);
9591 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9592 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9594 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9597 /****************************************************************************
9598 ****************************************************************************/
9600 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9601 const char *servername,
9602 const char *environment,
9603 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9605 WERROR werr;
9606 char *path = NULL;
9608 werr = compose_spoolss_server_path(mem_ctx,
9609 servername,
9610 environment,
9611 SPOOLSS_PRTPROCS_PATH,
9612 &path);
9613 if (!W_ERROR_IS_OK(werr)) {
9614 return werr;
9617 DEBUG(4,("print processor directory: [%s]\n", path));
9619 r->directory_name = path;
9621 return WERR_OK;
9624 /****************************************************************
9625 _spoolss_GetPrintProcessorDirectory
9626 ****************************************************************/
9628 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
9629 struct spoolss_GetPrintProcessorDirectory *r)
9631 WERROR result;
9632 char *prnproc_share = NULL;
9633 bool prnproc_share_exists = false;
9634 int snum;
9636 /* that's an [in out] buffer */
9638 if (!r->in.buffer && (r->in.offered != 0)) {
9639 return WERR_INVALID_PARAM;
9642 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9643 r->in.level));
9645 *r->out.needed = 0;
9647 /* r->in.level is ignored */
9649 /* We always should reply with a local print processor directory so that
9650 * users are not forced to have a [prnproc$] share on the Samba spoolss
9651 * server, if users decide to do so, lets announce it though - Guenther */
9653 snum = find_service(talloc_tos(), "prnproc$", &prnproc_share);
9654 if (!prnproc_share) {
9655 return WERR_NOMEM;
9657 if (snum != -1) {
9658 prnproc_share_exists = true;
9661 result = getprintprocessordirectory_level_1(p->mem_ctx,
9662 prnproc_share_exists ? r->in.server : NULL,
9663 r->in.environment,
9664 &r->out.info->info1);
9665 if (!W_ERROR_IS_OK(result)) {
9666 TALLOC_FREE(r->out.info);
9667 return result;
9670 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9671 r->out.info, r->in.level);
9672 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9674 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9677 /*******************************************************************
9678 ********************************************************************/
9680 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9681 const char *dllname)
9683 enum ndr_err_code ndr_err;
9684 struct spoolss_MonitorUi ui;
9686 ui.dll_name = dllname;
9688 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9689 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9690 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9691 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9693 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9696 /*******************************************************************
9697 Streams the monitor UI DLL name in UNICODE
9698 *******************************************************************/
9700 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9701 struct security_token *token, DATA_BLOB *in,
9702 DATA_BLOB *out, uint32_t *needed)
9704 const char *dllname = "tcpmonui.dll";
9706 *needed = (strlen(dllname)+1) * 2;
9708 if (out->length < *needed) {
9709 return WERR_INSUFFICIENT_BUFFER;
9712 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9713 return WERR_NOMEM;
9716 return WERR_OK;
9719 /*******************************************************************
9720 ********************************************************************/
9722 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9723 struct spoolss_PortData1 *port1,
9724 const DATA_BLOB *buf)
9726 enum ndr_err_code ndr_err;
9727 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9728 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9729 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9730 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9732 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9735 /*******************************************************************
9736 ********************************************************************/
9738 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9739 struct spoolss_PortData2 *port2,
9740 const DATA_BLOB *buf)
9742 enum ndr_err_code ndr_err;
9743 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9744 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9745 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9746 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9748 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9751 /*******************************************************************
9752 Create a new TCP/IP port
9753 *******************************************************************/
9755 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9756 struct security_token *token, DATA_BLOB *in,
9757 DATA_BLOB *out, uint32_t *needed)
9759 struct spoolss_PortData1 port1;
9760 struct spoolss_PortData2 port2;
9761 char *device_uri = NULL;
9762 uint32_t version;
9764 const char *portname;
9765 const char *hostaddress;
9766 const char *queue;
9767 uint32_t port_number;
9768 uint32_t protocol;
9770 /* peek for spoolss_PortData version */
9772 if (!in || (in->length < (128 + 4))) {
9773 return WERR_GENERAL_FAILURE;
9776 version = IVAL(in->data, 128);
9778 switch (version) {
9779 case 1:
9780 ZERO_STRUCT(port1);
9782 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9783 return WERR_NOMEM;
9786 portname = port1.portname;
9787 hostaddress = port1.hostaddress;
9788 queue = port1.queue;
9789 protocol = port1.protocol;
9790 port_number = port1.port_number;
9792 break;
9793 case 2:
9794 ZERO_STRUCT(port2);
9796 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9797 return WERR_NOMEM;
9800 portname = port2.portname;
9801 hostaddress = port2.hostaddress;
9802 queue = port2.queue;
9803 protocol = port2.protocol;
9804 port_number = port2.port_number;
9806 break;
9807 default:
9808 DEBUG(1,("xcvtcp_addport: "
9809 "unknown version of port_data: %d\n", version));
9810 return WERR_UNKNOWN_PORT;
9813 /* create the device URI and call the add_port_hook() */
9815 switch (protocol) {
9816 case PROTOCOL_RAWTCP_TYPE:
9817 device_uri = talloc_asprintf(mem_ctx,
9818 "socket://%s:%d/", hostaddress,
9819 port_number);
9820 break;
9822 case PROTOCOL_LPR_TYPE:
9823 device_uri = talloc_asprintf(mem_ctx,
9824 "lpr://%s/%s", hostaddress, queue );
9825 break;
9827 default:
9828 return WERR_UNKNOWN_PORT;
9831 if (!device_uri) {
9832 return WERR_NOMEM;
9835 return add_port_hook(mem_ctx, token, portname, device_uri);
9838 /*******************************************************************
9839 *******************************************************************/
9841 struct xcv_api_table xcvtcp_cmds[] = {
9842 { "MonitorUI", xcvtcp_monitorui },
9843 { "AddPort", xcvtcp_addport},
9844 { NULL, NULL }
9847 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9848 struct security_token *token, const char *command,
9849 DATA_BLOB *inbuf,
9850 DATA_BLOB *outbuf,
9851 uint32_t *needed )
9853 int i;
9855 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9857 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9858 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9859 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9862 return WERR_BADFUNC;
9865 /*******************************************************************
9866 *******************************************************************/
9867 #if 0 /* don't support management using the "Local Port" monitor */
9869 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9870 struct security_token *token, DATA_BLOB *in,
9871 DATA_BLOB *out, uint32_t *needed)
9873 const char *dllname = "localui.dll";
9875 *needed = (strlen(dllname)+1) * 2;
9877 if (out->length < *needed) {
9878 return WERR_INSUFFICIENT_BUFFER;
9881 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9882 return WERR_NOMEM;
9885 return WERR_OK;
9888 /*******************************************************************
9889 *******************************************************************/
9891 struct xcv_api_table xcvlocal_cmds[] = {
9892 { "MonitorUI", xcvlocal_monitorui },
9893 { NULL, NULL }
9895 #else
9896 struct xcv_api_table xcvlocal_cmds[] = {
9897 { NULL, NULL }
9899 #endif
9903 /*******************************************************************
9904 *******************************************************************/
9906 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9907 struct security_token *token, const char *command,
9908 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9909 uint32_t *needed)
9911 int i;
9913 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9915 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9916 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9917 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9919 return WERR_BADFUNC;
9922 /****************************************************************
9923 _spoolss_XcvData
9924 ****************************************************************/
9926 WERROR _spoolss_XcvData(struct pipes_struct *p,
9927 struct spoolss_XcvData *r)
9929 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9930 DATA_BLOB out_data = data_blob_null;
9931 WERROR werror;
9933 if (!Printer) {
9934 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9935 OUR_HANDLE(r->in.handle)));
9936 return WERR_BADFID;
9939 /* Has to be a handle to the TCP/IP port monitor */
9941 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9942 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9943 return WERR_BADFID;
9946 /* requires administrative access to the server */
9948 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9949 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9950 return WERR_ACCESS_DENIED;
9953 /* Allocate the outgoing buffer */
9955 if (r->in.out_data_size) {
9956 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9957 if (out_data.data == NULL) {
9958 return WERR_NOMEM;
9962 switch ( Printer->printer_type ) {
9963 case SPLHND_PORTMON_TCP:
9964 werror = process_xcvtcp_command(p->mem_ctx,
9965 p->server_info->ptok,
9966 r->in.function_name,
9967 &r->in.in_data, &out_data,
9968 r->out.needed);
9969 break;
9970 case SPLHND_PORTMON_LOCAL:
9971 werror = process_xcvlocal_command(p->mem_ctx,
9972 p->server_info->ptok,
9973 r->in.function_name,
9974 &r->in.in_data, &out_data,
9975 r->out.needed);
9976 break;
9977 default:
9978 werror = WERR_INVALID_PRINT_MONITOR;
9981 if (!W_ERROR_IS_OK(werror)) {
9982 return werror;
9985 *r->out.status_code = 0;
9987 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9988 memcpy(r->out.out_data, out_data.data,
9989 MIN(r->in.out_data_size, out_data.length));
9992 return WERR_OK;
9995 /****************************************************************
9996 _spoolss_AddPrintProcessor
9997 ****************************************************************/
9999 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
10000 struct spoolss_AddPrintProcessor *r)
10002 /* for now, just indicate success and ignore the add. We'll
10003 automatically set the winprint processor for printer
10004 entries later. Used to debug the LexMark Optra S 1855 PCL
10005 driver --jerry */
10007 return WERR_OK;
10010 /****************************************************************
10011 _spoolss_AddPort
10012 ****************************************************************/
10014 WERROR _spoolss_AddPort(struct pipes_struct *p,
10015 struct spoolss_AddPort *r)
10017 /* do what w2k3 does */
10019 return WERR_NOT_SUPPORTED;
10022 /****************************************************************
10023 _spoolss_GetPrinterDriver
10024 ****************************************************************/
10026 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
10027 struct spoolss_GetPrinterDriver *r)
10029 p->rng_fault_state = true;
10030 return WERR_NOT_SUPPORTED;
10033 /****************************************************************
10034 _spoolss_ReadPrinter
10035 ****************************************************************/
10037 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
10038 struct spoolss_ReadPrinter *r)
10040 p->rng_fault_state = true;
10041 return WERR_NOT_SUPPORTED;
10044 /****************************************************************
10045 _spoolss_WaitForPrinterChange
10046 ****************************************************************/
10048 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
10049 struct spoolss_WaitForPrinterChange *r)
10051 p->rng_fault_state = true;
10052 return WERR_NOT_SUPPORTED;
10055 /****************************************************************
10056 _spoolss_ConfigurePort
10057 ****************************************************************/
10059 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
10060 struct spoolss_ConfigurePort *r)
10062 p->rng_fault_state = true;
10063 return WERR_NOT_SUPPORTED;
10066 /****************************************************************
10067 _spoolss_DeletePort
10068 ****************************************************************/
10070 WERROR _spoolss_DeletePort(struct pipes_struct *p,
10071 struct spoolss_DeletePort *r)
10073 p->rng_fault_state = true;
10074 return WERR_NOT_SUPPORTED;
10077 /****************************************************************
10078 _spoolss_CreatePrinterIC
10079 ****************************************************************/
10081 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
10082 struct spoolss_CreatePrinterIC *r)
10084 p->rng_fault_state = true;
10085 return WERR_NOT_SUPPORTED;
10088 /****************************************************************
10089 _spoolss_PlayGDIScriptOnPrinterIC
10090 ****************************************************************/
10092 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
10093 struct spoolss_PlayGDIScriptOnPrinterIC *r)
10095 p->rng_fault_state = true;
10096 return WERR_NOT_SUPPORTED;
10099 /****************************************************************
10100 _spoolss_DeletePrinterIC
10101 ****************************************************************/
10103 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
10104 struct spoolss_DeletePrinterIC *r)
10106 p->rng_fault_state = true;
10107 return WERR_NOT_SUPPORTED;
10110 /****************************************************************
10111 _spoolss_AddPrinterConnection
10112 ****************************************************************/
10114 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
10115 struct spoolss_AddPrinterConnection *r)
10117 p->rng_fault_state = true;
10118 return WERR_NOT_SUPPORTED;
10121 /****************************************************************
10122 _spoolss_DeletePrinterConnection
10123 ****************************************************************/
10125 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
10126 struct spoolss_DeletePrinterConnection *r)
10128 p->rng_fault_state = true;
10129 return WERR_NOT_SUPPORTED;
10132 /****************************************************************
10133 _spoolss_PrinterMessageBox
10134 ****************************************************************/
10136 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
10137 struct spoolss_PrinterMessageBox *r)
10139 p->rng_fault_state = true;
10140 return WERR_NOT_SUPPORTED;
10143 /****************************************************************
10144 _spoolss_AddMonitor
10145 ****************************************************************/
10147 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
10148 struct spoolss_AddMonitor *r)
10150 p->rng_fault_state = true;
10151 return WERR_NOT_SUPPORTED;
10154 /****************************************************************
10155 _spoolss_DeleteMonitor
10156 ****************************************************************/
10158 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
10159 struct spoolss_DeleteMonitor *r)
10161 p->rng_fault_state = true;
10162 return WERR_NOT_SUPPORTED;
10165 /****************************************************************
10166 _spoolss_DeletePrintProcessor
10167 ****************************************************************/
10169 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
10170 struct spoolss_DeletePrintProcessor *r)
10172 p->rng_fault_state = true;
10173 return WERR_NOT_SUPPORTED;
10176 /****************************************************************
10177 _spoolss_AddPrintProvidor
10178 ****************************************************************/
10180 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
10181 struct spoolss_AddPrintProvidor *r)
10183 p->rng_fault_state = true;
10184 return WERR_NOT_SUPPORTED;
10187 /****************************************************************
10188 _spoolss_DeletePrintProvidor
10189 ****************************************************************/
10191 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
10192 struct spoolss_DeletePrintProvidor *r)
10194 p->rng_fault_state = true;
10195 return WERR_NOT_SUPPORTED;
10198 /****************************************************************
10199 _spoolss_FindFirstPrinterChangeNotification
10200 ****************************************************************/
10202 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
10203 struct spoolss_FindFirstPrinterChangeNotification *r)
10205 p->rng_fault_state = true;
10206 return WERR_NOT_SUPPORTED;
10209 /****************************************************************
10210 _spoolss_FindNextPrinterChangeNotification
10211 ****************************************************************/
10213 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
10214 struct spoolss_FindNextPrinterChangeNotification *r)
10216 p->rng_fault_state = true;
10217 return WERR_NOT_SUPPORTED;
10220 /****************************************************************
10221 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10222 ****************************************************************/
10224 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
10225 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10227 p->rng_fault_state = true;
10228 return WERR_NOT_SUPPORTED;
10231 /****************************************************************
10232 _spoolss_ReplyOpenPrinter
10233 ****************************************************************/
10235 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
10236 struct spoolss_ReplyOpenPrinter *r)
10238 p->rng_fault_state = true;
10239 return WERR_NOT_SUPPORTED;
10242 /****************************************************************
10243 _spoolss_RouterReplyPrinter
10244 ****************************************************************/
10246 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
10247 struct spoolss_RouterReplyPrinter *r)
10249 p->rng_fault_state = true;
10250 return WERR_NOT_SUPPORTED;
10253 /****************************************************************
10254 _spoolss_ReplyClosePrinter
10255 ****************************************************************/
10257 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
10258 struct spoolss_ReplyClosePrinter *r)
10260 p->rng_fault_state = true;
10261 return WERR_NOT_SUPPORTED;
10264 /****************************************************************
10265 _spoolss_AddPortEx
10266 ****************************************************************/
10268 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
10269 struct spoolss_AddPortEx *r)
10271 p->rng_fault_state = true;
10272 return WERR_NOT_SUPPORTED;
10275 /****************************************************************
10276 _spoolss_RouterFindFirstPrinterChangeNotification
10277 ****************************************************************/
10279 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
10280 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10282 p->rng_fault_state = true;
10283 return WERR_NOT_SUPPORTED;
10286 /****************************************************************
10287 _spoolss_SpoolerInit
10288 ****************************************************************/
10290 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
10291 struct spoolss_SpoolerInit *r)
10293 p->rng_fault_state = true;
10294 return WERR_NOT_SUPPORTED;
10297 /****************************************************************
10298 _spoolss_ResetPrinterEx
10299 ****************************************************************/
10301 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
10302 struct spoolss_ResetPrinterEx *r)
10304 p->rng_fault_state = true;
10305 return WERR_NOT_SUPPORTED;
10308 /****************************************************************
10309 _spoolss_RouterReplyPrinterEx
10310 ****************************************************************/
10312 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
10313 struct spoolss_RouterReplyPrinterEx *r)
10315 p->rng_fault_state = true;
10316 return WERR_NOT_SUPPORTED;
10319 /****************************************************************
10320 _spoolss_44
10321 ****************************************************************/
10323 WERROR _spoolss_44(struct pipes_struct *p,
10324 struct spoolss_44 *r)
10326 p->rng_fault_state = true;
10327 return WERR_NOT_SUPPORTED;
10330 /****************************************************************
10331 _spoolss_SetPort
10332 ****************************************************************/
10334 WERROR _spoolss_SetPort(struct pipes_struct *p,
10335 struct spoolss_SetPort *r)
10337 p->rng_fault_state = true;
10338 return WERR_NOT_SUPPORTED;
10341 /****************************************************************
10342 _spoolss_4a
10343 ****************************************************************/
10345 WERROR _spoolss_4a(struct pipes_struct *p,
10346 struct spoolss_4a *r)
10348 p->rng_fault_state = true;
10349 return WERR_NOT_SUPPORTED;
10352 /****************************************************************
10353 _spoolss_4b
10354 ****************************************************************/
10356 WERROR _spoolss_4b(struct pipes_struct *p,
10357 struct spoolss_4b *r)
10359 p->rng_fault_state = true;
10360 return WERR_NOT_SUPPORTED;
10363 /****************************************************************
10364 _spoolss_4c
10365 ****************************************************************/
10367 WERROR _spoolss_4c(struct pipes_struct *p,
10368 struct spoolss_4c *r)
10370 p->rng_fault_state = true;
10371 return WERR_NOT_SUPPORTED;
10374 /****************************************************************
10375 _spoolss_53
10376 ****************************************************************/
10378 WERROR _spoolss_53(struct pipes_struct *p,
10379 struct spoolss_53 *r)
10381 p->rng_fault_state = true;
10382 return WERR_NOT_SUPPORTED;
10385 /****************************************************************
10386 _spoolss_55
10387 ****************************************************************/
10389 WERROR _spoolss_55(struct pipes_struct *p,
10390 struct spoolss_55 *r)
10392 p->rng_fault_state = true;
10393 return WERR_NOT_SUPPORTED;
10396 /****************************************************************
10397 _spoolss_56
10398 ****************************************************************/
10400 WERROR _spoolss_56(struct pipes_struct *p,
10401 struct spoolss_56 *r)
10403 p->rng_fault_state = true;
10404 return WERR_NOT_SUPPORTED;
10407 /****************************************************************
10408 _spoolss_57
10409 ****************************************************************/
10411 WERROR _spoolss_57(struct pipes_struct *p,
10412 struct spoolss_57 *r)
10414 p->rng_fault_state = true;
10415 return WERR_NOT_SUPPORTED;
10418 /****************************************************************
10419 _spoolss_5a
10420 ****************************************************************/
10422 WERROR _spoolss_5a(struct pipes_struct *p,
10423 struct spoolss_5a *r)
10425 p->rng_fault_state = true;
10426 return WERR_NOT_SUPPORTED;
10429 /****************************************************************
10430 _spoolss_5b
10431 ****************************************************************/
10433 WERROR _spoolss_5b(struct pipes_struct *p,
10434 struct spoolss_5b *r)
10436 p->rng_fault_state = true;
10437 return WERR_NOT_SUPPORTED;
10440 /****************************************************************
10441 _spoolss_5c
10442 ****************************************************************/
10444 WERROR _spoolss_5c(struct pipes_struct *p,
10445 struct spoolss_5c *r)
10447 p->rng_fault_state = true;
10448 return WERR_NOT_SUPPORTED;
10451 /****************************************************************
10452 _spoolss_5d
10453 ****************************************************************/
10455 WERROR _spoolss_5d(struct pipes_struct *p,
10456 struct spoolss_5d *r)
10458 p->rng_fault_state = true;
10459 return WERR_NOT_SUPPORTED;
10462 /****************************************************************
10463 _spoolss_5e
10464 ****************************************************************/
10466 WERROR _spoolss_5e(struct pipes_struct *p,
10467 struct spoolss_5e *r)
10469 p->rng_fault_state = true;
10470 return WERR_NOT_SUPPORTED;
10473 /****************************************************************
10474 _spoolss_5f
10475 ****************************************************************/
10477 WERROR _spoolss_5f(struct pipes_struct *p,
10478 struct spoolss_5f *r)
10480 p->rng_fault_state = true;
10481 return WERR_NOT_SUPPORTED;
10484 /****************************************************************
10485 _spoolss_60
10486 ****************************************************************/
10488 WERROR _spoolss_60(struct pipes_struct *p,
10489 struct spoolss_60 *r)
10491 p->rng_fault_state = true;
10492 return WERR_NOT_SUPPORTED;
10495 /****************************************************************
10496 _spoolss_61
10497 ****************************************************************/
10499 WERROR _spoolss_61(struct pipes_struct *p,
10500 struct spoolss_61 *r)
10502 p->rng_fault_state = true;
10503 return WERR_NOT_SUPPORTED;
10506 /****************************************************************
10507 _spoolss_62
10508 ****************************************************************/
10510 WERROR _spoolss_62(struct pipes_struct *p,
10511 struct spoolss_62 *r)
10513 p->rng_fault_state = true;
10514 return WERR_NOT_SUPPORTED;
10517 /****************************************************************
10518 _spoolss_63
10519 ****************************************************************/
10521 WERROR _spoolss_63(struct pipes_struct *p,
10522 struct spoolss_63 *r)
10524 p->rng_fault_state = true;
10525 return WERR_NOT_SUPPORTED;
10528 /****************************************************************
10529 _spoolss_64
10530 ****************************************************************/
10532 WERROR _spoolss_64(struct pipes_struct *p,
10533 struct spoolss_64 *r)
10535 p->rng_fault_state = true;
10536 return WERR_NOT_SUPPORTED;
10539 /****************************************************************
10540 _spoolss_65
10541 ****************************************************************/
10543 WERROR _spoolss_65(struct pipes_struct *p,
10544 struct spoolss_65 *r)
10546 p->rng_fault_state = true;
10547 return WERR_NOT_SUPPORTED;
10550 /****************************************************************
10551 _spoolss_GetCorePrinterDrivers
10552 ****************************************************************/
10554 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10555 struct spoolss_GetCorePrinterDrivers *r)
10557 p->rng_fault_state = true;
10558 return WERR_NOT_SUPPORTED;
10561 /****************************************************************
10562 _spoolss_67
10563 ****************************************************************/
10565 WERROR _spoolss_67(struct pipes_struct *p,
10566 struct spoolss_67 *r)
10568 p->rng_fault_state = true;
10569 return WERR_NOT_SUPPORTED;
10572 /****************************************************************
10573 _spoolss_GetPrinterDriverPackagePath
10574 ****************************************************************/
10576 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10577 struct spoolss_GetPrinterDriverPackagePath *r)
10579 p->rng_fault_state = true;
10580 return WERR_NOT_SUPPORTED;
10583 /****************************************************************
10584 _spoolss_69
10585 ****************************************************************/
10587 WERROR _spoolss_69(struct pipes_struct *p,
10588 struct spoolss_69 *r)
10590 p->rng_fault_state = true;
10591 return WERR_NOT_SUPPORTED;
10594 /****************************************************************
10595 _spoolss_6a
10596 ****************************************************************/
10598 WERROR _spoolss_6a(struct pipes_struct *p,
10599 struct spoolss_6a *r)
10601 p->rng_fault_state = true;
10602 return WERR_NOT_SUPPORTED;
10605 /****************************************************************
10606 _spoolss_6b
10607 ****************************************************************/
10609 WERROR _spoolss_6b(struct pipes_struct *p,
10610 struct spoolss_6b *r)
10612 p->rng_fault_state = true;
10613 return WERR_NOT_SUPPORTED;
10616 /****************************************************************
10617 _spoolss_6c
10618 ****************************************************************/
10620 WERROR _spoolss_6c(struct pipes_struct *p,
10621 struct spoolss_6c *r)
10623 p->rng_fault_state = true;
10624 return WERR_NOT_SUPPORTED;
10627 /****************************************************************
10628 _spoolss_6d
10629 ****************************************************************/
10631 WERROR _spoolss_6d(struct pipes_struct *p,
10632 struct spoolss_6d *r)
10634 p->rng_fault_state = true;
10635 return WERR_NOT_SUPPORTED;