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. */
31 #include "nt_printing.h"
32 #include "srv_spoolss_util.h"
33 #include "../librpc/gen_ndr/srv_spoolss.h"
34 #include "../librpc/gen_ndr/ndr_spoolss_c.h"
35 #include "rpc_client/init_spoolss.h"
36 #include "rpc_client/cli_pipe.h"
37 #include "librpc/gen_ndr/messaging.h"
38 #include "../libcli/security/security.h"
39 #include "librpc/gen_ndr/ndr_security.h"
41 #include "registry/reg_objects.h"
42 #include "include/printing.h"
44 #include "../librpc/gen_ndr/netlogon.h"
46 #include "printing/notify.h"
48 /* macros stolen from s4 spoolss server */
49 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
50 ((info)?ndr_size_##fn(info, level, 0):0)
52 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
53 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
55 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
56 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
58 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
61 #define DBGC_CLASS DBGC_RPC_SRV
63 #ifndef MAX_OPEN_PRINTER_EXS
64 #define MAX_OPEN_PRINTER_EXS 50
67 struct notify_back_channel;
69 /* structure to store the printer handles */
70 /* and a reference to what it's pointing to */
71 /* and the notify info asked about */
72 /* that's the central struct */
73 struct printer_handle {
74 struct printer_handle *prev, *next;
75 bool document_started;
77 uint32 jobid; /* jobid in printing backend */
79 const char *servername;
82 uint32 access_granted;
88 struct spoolss_NotifyOption *option;
89 struct policy_handle cli_hnd;
90 struct notify_back_channel *cli_chan;
92 /* are we in a FindNextPrinterChangeNotify() call? */
94 struct messaging_context *msg_ctx;
101 /* devmode sent in the OpenPrinter() call */
102 struct spoolss_DeviceMode *devmode;
104 /* TODO cache the printer info2 structure */
105 struct spoolss_PrinterInfo2 *info2;
109 static struct printer_handle *printers_list;
111 struct printer_session_counter {
112 struct printer_session_counter *next;
113 struct printer_session_counter *prev;
119 static struct printer_session_counter *counter_list;
121 struct notify_back_channel {
122 struct notify_back_channel *prev, *next;
124 /* associated client */
125 struct sockaddr_storage client_address;
127 /* print notify back-channel pipe handle*/
128 struct rpc_pipe_client *cli_pipe;
129 struct dcerpc_binding_handle *binding_handle;
130 uint32_t active_connections;
133 static struct notify_back_channel *back_channels;
135 /* Map generic permissions to printer object specific permissions */
137 const struct standard_mapping printer_std_mapping = {
144 /* Map generic permissions to print server object specific permissions */
146 const struct standard_mapping printserver_std_mapping = {
153 /* API table for Xcv Monitor functions */
155 struct xcv_api_table {
157 WERROR(*fn) (TALLOC_CTX *mem_ctx, struct security_token *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
160 static void prune_printername_cache(void);
162 /********************************************************************
163 * Canonicalize servername.
164 ********************************************************************/
166 static const char *canon_servername(const char *servername)
168 const char *pservername = servername;
169 while (*pservername == '\\') {
175 /* translate between internal status numbers and NT status numbers */
176 static int nt_printj_status(int v)
182 return JOB_STATUS_PAUSED;
184 return JOB_STATUS_SPOOLING;
186 return JOB_STATUS_PRINTING;
188 return JOB_STATUS_ERROR;
190 return JOB_STATUS_DELETING;
192 return JOB_STATUS_OFFLINE;
194 return JOB_STATUS_PAPEROUT;
196 return JOB_STATUS_PRINTED;
198 return JOB_STATUS_DELETED;
200 return JOB_STATUS_BLOCKED_DEVQ;
201 case LPQ_USER_INTERVENTION:
202 return JOB_STATUS_USER_INTERVENTION;
207 static int nt_printq_status(int v)
211 return PRINTER_STATUS_PAUSED;
220 /***************************************************************************
221 Disconnect from the client
222 ****************************************************************************/
224 static void srv_spoolss_replycloseprinter(int snum,
225 struct printer_handle *prn_hnd)
231 * Tell the specific printing tdb we no longer want messages for this printer
232 * by deregistering our PID.
235 if (!print_notify_deregister_pid(snum)) {
236 DEBUG(0, ("Failed to register our pid for printer %s\n",
237 lp_const_servicename(snum)));
240 /* weird if the test succeeds !!! */
241 if (prn_hnd->notify.cli_chan == NULL ||
242 prn_hnd->notify.cli_chan->active_connections == 0) {
243 DEBUG(0, ("Trying to close unexisting backchannel!\n"));
244 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
245 TALLOC_FREE(prn_hnd->notify.cli_chan);
249 status = dcerpc_spoolss_ReplyClosePrinter(
250 prn_hnd->notify.cli_chan->binding_handle,
252 &prn_hnd->notify.cli_hnd,
254 if (!NT_STATUS_IS_OK(status)) {
255 DEBUG(0, ("dcerpc_spoolss_ReplyClosePrinter failed [%s].\n",
257 result = ntstatus_to_werror(status);
258 } else if (!W_ERROR_IS_OK(result)) {
259 DEBUG(0, ("reply_close_printer failed [%s].\n",
260 win_errstr(result)));
263 /* if it's the last connection, deconnect the IPC$ share */
264 if (prn_hnd->notify.cli_chan->active_connections == 1) {
266 prn_hnd->notify.cli_chan->binding_handle = NULL;
267 cli_shutdown(rpc_pipe_np_smb_conn(prn_hnd->notify.cli_chan->cli_pipe));
268 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
269 TALLOC_FREE(prn_hnd->notify.cli_chan);
271 if (prn_hnd->notify.msg_ctx != NULL) {
272 messaging_deregister(prn_hnd->notify.msg_ctx,
273 MSG_PRINTER_NOTIFY2, NULL);
276 * Tell the serverid.tdb we're no longer
277 * interested in printer notify messages.
280 serverid_register_msg_flags(
281 messaging_server_id(prn_hnd->notify.msg_ctx),
282 false, FLAG_MSG_PRINT_NOTIFY);
286 if (prn_hnd->notify.cli_chan) {
287 prn_hnd->notify.cli_chan->active_connections--;
291 /****************************************************************************
292 Functions to free a printer entry datastruct.
293 ****************************************************************************/
295 static int printer_entry_destructor(struct printer_handle *Printer)
297 if (Printer->notify.cli_chan != NULL &&
298 Printer->notify.cli_chan->active_connections > 0) {
301 switch(Printer->printer_type) {
303 srv_spoolss_replycloseprinter(snum, Printer);
307 snum = print_queue_snum(Printer->sharename);
309 srv_spoolss_replycloseprinter(snum, Printer);
317 Printer->notify.flags=0;
318 Printer->notify.options=0;
319 Printer->notify.localmachine[0]='\0';
320 Printer->notify.printerlocal=0;
321 TALLOC_FREE(Printer->notify.option);
322 TALLOC_FREE(Printer->devmode);
324 /* Remove from the internal list. */
325 DLIST_REMOVE(printers_list, Printer);
329 /****************************************************************************
330 find printer index by handle
331 ****************************************************************************/
333 static struct printer_handle *find_printer_index_by_hnd(struct pipes_struct *p,
334 struct policy_handle *hnd)
336 struct printer_handle *find_printer = NULL;
338 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
339 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
346 /****************************************************************************
347 Close printer index by handle.
348 ****************************************************************************/
350 static bool close_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
352 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
355 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
360 close_policy_hnd(p, hnd);
365 /****************************************************************************
366 Delete a printer given a handle.
367 ****************************************************************************/
369 static WERROR delete_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
370 const char *sharename,
371 struct messaging_context *msg_ctx)
373 char *cmd = lp_deleteprinter_cmd();
374 char *command = NULL;
376 bool is_print_op = false;
378 /* can't fail if we don't try */
383 command = talloc_asprintf(ctx,
390 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
392 DEBUG(10,("Running [%s]\n", command));
394 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
399 if ( (ret = smbrun(command, NULL)) == 0 ) {
400 /* Tell everyone we updated smb.conf. */
401 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
407 /********** END SePrintOperatorPrivlege BLOCK **********/
409 DEBUGADD(10,("returned [%d]\n", ret));
411 TALLOC_FREE(command);
414 return WERR_BADFID; /* What to return here? */
416 /* go ahead and re-read the services immediately */
418 reload_services(msg_ctx, -1, false);
421 if ( lp_servicenumber( sharename ) >= 0 )
422 return WERR_ACCESS_DENIED;
427 /****************************************************************************
428 Delete a printer given a handle.
429 ****************************************************************************/
431 static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
433 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
437 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
443 * It turns out that Windows allows delete printer on a handle
444 * opened by an admin user, then used on a pipe handle created
445 * by an anonymous user..... but they're working on security.... riiight !
449 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
450 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
451 return WERR_ACCESS_DENIED;
454 /* this does not need a become root since the access check has been
455 done on the handle already */
457 result = winreg_delete_printer_key(p->mem_ctx,
458 get_session_info_system(),
462 if (!W_ERROR_IS_OK(result)) {
463 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
467 result = delete_printer_hook(p->mem_ctx, p->session_info->security_token,
468 Printer->sharename, p->msg_ctx);
469 if (!W_ERROR_IS_OK(result)) {
472 prune_printername_cache();
476 /****************************************************************************
477 Return the snum of a printer corresponding to an handle.
478 ****************************************************************************/
480 static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
481 int *number, struct share_params **params)
483 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
486 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
491 switch (Printer->printer_type) {
493 DEBUG(4,("short name:%s\n", Printer->sharename));
494 *number = print_queue_snum(Printer->sharename);
495 return (*number != -1);
503 /****************************************************************************
504 Set printer handle type.
505 Check if it's \\server or \\server\printer
506 ****************************************************************************/
508 static bool set_printer_hnd_printertype(struct printer_handle *Printer, const char *handlename)
510 DEBUG(3,("Setting printer type=%s\n", handlename));
512 /* it's a print server */
513 if (handlename && *handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
514 DEBUGADD(4,("Printer is a print server\n"));
515 Printer->printer_type = SPLHND_SERVER;
517 /* it's a printer (set_printer_hnd_name() will handle port monitors */
519 DEBUGADD(4,("Printer is a printer\n"));
520 Printer->printer_type = SPLHND_PRINTER;
526 static void prune_printername_cache_fn(const char *key, const char *value,
527 time_t timeout, void *private_data)
532 static void prune_printername_cache(void)
534 gencache_iterate(prune_printername_cache_fn, NULL, "PRINTERNAME/*");
537 /****************************************************************************
538 Set printer handle name.. Accept names like \\server, \\server\printer,
539 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
540 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
541 XcvDataPort() interface.
542 ****************************************************************************/
544 static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
545 const struct auth_serversupplied_info *session_info,
546 struct messaging_context *msg_ctx,
547 struct printer_handle *Printer,
548 const char *handlename)
551 int n_services=lp_numservices();
553 const char *printername;
554 const char *servername = NULL;
557 struct spoolss_PrinterInfo2 *info2 = NULL;
562 * Hopefully nobody names his printers like this. Maybe \ or ,
563 * are illegal in printer names even?
565 const char printer_not_found[] = "Printer \\, !@#$%^&*( not found";
569 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
570 (unsigned long)strlen(handlename)));
572 aprinter = CONST_DISCARD(char *, handlename);
573 if ( *handlename == '\\' ) {
574 servername = canon_servername(handlename);
575 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
579 if (!is_myname_or_ipaddr(servername)) {
580 return WERR_INVALID_PRINTER_NAME;
582 Printer->servername = talloc_asprintf(Printer, "\\\\%s", servername);
583 if (Printer->servername == NULL) {
588 if (Printer->printer_type == SPLHND_SERVER) {
592 if (Printer->printer_type != SPLHND_PRINTER) {
593 return WERR_INVALID_HANDLE;
596 DEBUGADD(5, ("searching for [%s]\n", aprinter));
598 p = strchr(aprinter, ',');
605 if (strncmp(p, "DrvConvert", strlen("DrvConvert")) == 0) {
607 } else if (strncmp(p, "LocalOnly", strlen("LocalOnly")) == 0) {
613 DEBUGADD(5, ("stripped handlename: [%s]\n", aprinter));
616 /* check for the Port Monitor Interface */
617 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
618 Printer->printer_type = SPLHND_PORTMON_TCP;
619 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
622 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
623 Printer->printer_type = SPLHND_PORTMON_LOCAL;
624 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
629 * With hundreds of printers, the "for" loop iterating all
630 * shares can be quite expensive, as it is done on every
631 * OpenPrinter. The loop maps "aprinter" to "sname", the
632 * result of which we cache in gencache.
635 cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
637 if ((cache_key != NULL) && gencache_get(cache_key, &tmp, NULL)) {
639 found = (strcmp(tmp, printer_not_found) != 0);
641 DEBUG(4, ("Printer %s not found\n", aprinter));
643 return WERR_INVALID_PRINTER_NAME;
649 /* Search all sharenames first as this is easier than pulling
650 the printer_info_2 off of disk. Don't use find_service() since
651 that calls out to map_username() */
653 /* do another loop to look for printernames */
654 for (snum = 0; !found && snum < n_services; snum++) {
655 const char *printer = lp_const_servicename(snum);
657 /* no point going on if this is not a printer */
658 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
662 /* ignore [printers] share */
663 if (strequal(printer, "printers")) {
667 fstrcpy(sname, printer);
668 if (strequal(aprinter, printer)) {
673 /* no point looking up the printer object if
674 we aren't allowing printername != sharename */
675 if (lp_force_printername(snum)) {
679 result = winreg_get_printer(mem_ctx,
684 if ( !W_ERROR_IS_OK(result) ) {
685 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
686 sname, win_errstr(result)));
690 printername = strrchr(info2->printername, '\\');
691 if (printername == NULL) {
692 printername = info2->printername;
697 if (strequal(printername, aprinter)) {
702 DEBUGADD(10, ("printername: %s\n", printername));
708 if (cache_key != NULL) {
709 gencache_set(cache_key, printer_not_found,
711 TALLOC_FREE(cache_key);
713 DEBUGADD(4,("Printer not found\n"));
714 return WERR_INVALID_PRINTER_NAME;
717 if (cache_key != NULL) {
718 gencache_set(cache_key, sname, time(NULL)+300);
719 TALLOC_FREE(cache_key);
722 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
724 fstrcpy(Printer->sharename, sname);
729 /****************************************************************************
730 Find first available printer slot. creates a printer handle for you.
731 ****************************************************************************/
733 static WERROR open_printer_hnd(struct pipes_struct *p,
734 struct policy_handle *hnd,
736 uint32_t access_granted)
738 struct printer_handle *new_printer;
741 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
743 new_printer = talloc_zero(p->mem_ctx, struct printer_handle);
744 if (new_printer == NULL) {
747 talloc_set_destructor(new_printer, printer_entry_destructor);
749 /* This also steals the printer_handle on the policy_handle */
750 if (!create_policy_hnd(p, hnd, new_printer)) {
751 TALLOC_FREE(new_printer);
752 return WERR_INVALID_HANDLE;
755 /* Add to the internal list. */
756 DLIST_ADD(printers_list, new_printer);
758 new_printer->notify.option=NULL;
760 if (!set_printer_hnd_printertype(new_printer, name)) {
761 close_printer_handle(p, hnd);
762 return WERR_INVALID_HANDLE;
765 result = set_printer_hnd_name(p->mem_ctx,
766 get_session_info_system(),
769 if (!W_ERROR_IS_OK(result)) {
770 close_printer_handle(p, hnd);
774 new_printer->access_granted = access_granted;
776 DEBUG(5, ("%d printer handles active\n",
777 (int)num_pipe_handles(p)));
782 /***************************************************************************
783 check to see if the client motify handle is monitoring the notification
784 given by (notify_type, notify_field).
785 **************************************************************************/
787 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
788 uint16_t notify_field)
793 static bool is_monitoring_event(struct printer_handle *p, uint16_t notify_type,
794 uint16_t notify_field)
796 struct spoolss_NotifyOption *option = p->notify.option;
800 * Flags should always be zero when the change notify
801 * is registered by the client's spooler. A user Win32 app
802 * might use the flags though instead of the NOTIFY_OPTION_INFO
811 return is_monitoring_event_flags(
812 p->notify.flags, notify_type, notify_field);
814 for (i = 0; i < option->count; i++) {
816 /* Check match for notify_type */
818 if (option->types[i].type != notify_type)
821 /* Check match for field */
823 for (j = 0; j < option->types[i].count; j++) {
824 if (option->types[i].fields[j].field == notify_field) {
830 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
831 p->servername, p->sharename, notify_type, notify_field));
836 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
837 _data->data.integer[0] = _integer; \
838 _data->data.integer[1] = 0;
841 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
842 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
843 if (!_data->data.string.string) {\
844 _data->data.string.size = 0; \
846 _data->data.string.size = strlen_m_term(_p) * 2;
848 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
849 _data->data.devmode.devmode = _devmode;
851 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
852 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
853 if (!_data->data.sd.sd) { \
854 _data->data.sd.sd_size = 0; \
856 _data->data.sd.sd_size = \
857 ndr_size_security_descriptor(_data->data.sd.sd, 0);
859 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
864 struct spoolss_Time st;
868 if (!init_systemtime(&st, t)) {
872 p = talloc_array(mem_ctx, char, len);
878 * Systemtime must be linearized as a set of UINT16's.
879 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
882 SSVAL(p, 0, st.year);
883 SSVAL(p, 2, st.month);
884 SSVAL(p, 4, st.day_of_week);
886 SSVAL(p, 8, st.hour);
887 SSVAL(p, 10, st.minute);
888 SSVAL(p, 12, st.second);
889 SSVAL(p, 14, st.millisecond);
895 /* Convert a notification message to a struct spoolss_Notify */
897 static void notify_one_value(struct spoolss_notify_msg *msg,
898 struct spoolss_Notify *data,
901 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
904 static void notify_string(struct spoolss_notify_msg *msg,
905 struct spoolss_Notify *data,
908 /* The length of the message includes the trailing \0 */
910 data->data.string.size = msg->len * 2;
911 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
912 if (!data->data.string.string) {
913 data->data.string.size = 0;
918 static void notify_system_time(struct spoolss_notify_msg *msg,
919 struct spoolss_Notify *data,
922 data->data.string.string = NULL;
923 data->data.string.size = 0;
925 if (msg->len != sizeof(time_t)) {
926 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
931 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
932 &data->data.string.string,
933 &data->data.string.size);
936 struct notify2_message_table {
938 void (*fn)(struct spoolss_notify_msg *msg,
939 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
942 static struct notify2_message_table printer_notify_table[] = {
943 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
944 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
945 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
946 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
947 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
948 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
949 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
950 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
951 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
952 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
953 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
954 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
955 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
956 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
957 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
958 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
959 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
960 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
961 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
964 static struct notify2_message_table job_notify_table[] = {
965 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
966 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
967 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
968 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
969 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
970 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
971 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
972 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
973 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
974 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
975 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
976 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
977 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
978 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
979 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
980 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
981 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
982 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
983 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
984 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
985 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
986 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
987 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
988 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
992 /***********************************************************************
993 Allocate talloc context for container object
994 **********************************************************************/
996 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1001 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
1006 /***********************************************************************
1007 release all allocated memory and zero out structure
1008 **********************************************************************/
1010 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1016 talloc_destroy(ctr->ctx);
1023 /***********************************************************************
1024 **********************************************************************/
1026 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1034 /***********************************************************************
1035 **********************************************************************/
1037 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1039 if ( !ctr || !ctr->msg_groups )
1042 if ( idx >= ctr->num_groups )
1045 return &ctr->msg_groups[idx];
1049 /***********************************************************************
1050 How many groups of change messages do we have ?
1051 **********************************************************************/
1053 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1058 return ctr->num_groups;
1061 /***********************************************************************
1062 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1063 **********************************************************************/
1065 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
1067 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
1068 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
1069 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
1075 /* loop over all groups looking for a matching printer name */
1077 for ( i=0; i<ctr->num_groups; i++ ) {
1078 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
1082 /* add a new group? */
1084 if ( i == ctr->num_groups ) {
1087 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
1088 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1091 ctr->msg_groups = groups;
1093 /* clear the new entry and set the printer name */
1095 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
1096 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
1099 /* add the change messages; 'i' is the correct index now regardless */
1101 msg_grp = &ctr->msg_groups[i];
1103 msg_grp->num_msgs++;
1105 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
1106 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
1109 msg_grp->msgs = msg_list;
1111 new_slot = msg_grp->num_msgs-1;
1112 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
1114 /* need to allocate own copy of data */
1116 if ( msg->len != 0 )
1117 msg_grp->msgs[new_slot].notify.data = (char *)
1118 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
1120 return ctr->num_groups;
1123 static void construct_info_data(struct spoolss_Notify *info_data,
1124 enum spoolss_NotifyType type,
1125 uint16_t field, int id);
1127 /***********************************************************************
1128 Send a change notication message on all handles which have a call
1130 **********************************************************************/
1132 static int build_notify2_messages(TALLOC_CTX *mem_ctx,
1133 struct printer_handle *prn_hnd,
1134 SPOOLSS_NOTIFY_MSG *messages,
1136 struct spoolss_Notify **_notifies,
1139 struct spoolss_Notify *notifies;
1140 SPOOLSS_NOTIFY_MSG *msg;
1145 notifies = talloc_zero_array(mem_ctx,
1146 struct spoolss_Notify, num_msgs);
1151 for (i = 0; i < num_msgs; i++) {
1155 /* Are we monitoring this event? */
1157 if (!is_monitoring_event(prn_hnd, msg->type, msg->field)) {
1161 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1162 "for printer [%s]\n",
1163 msg->type, msg->field, prn_hnd->sharename));
1166 * if the is a printer notification handle and not a job
1167 * notification type, then set the id to 0.
1168 * Otherwise just use what was specified in the message.
1170 * When registering change notification on a print server
1171 * handle we always need to send back the id (snum) matching
1172 * the printer for which the change took place.
1173 * For change notify registered on a printer handle,
1174 * this does not matter and the id should be 0.
1179 if ((msg->type == PRINTER_NOTIFY_TYPE) &&
1180 (prn_hnd->printer_type == SPLHND_PRINTER)) {
1186 /* Convert unix jobid to smb jobid */
1188 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1189 id = sysjob_to_jobid(msg->id);
1192 DEBUG(3, ("no such unix jobid %d\n",
1198 construct_info_data(¬ifies[count],
1199 msg->type, msg->field, id);
1202 case PRINTER_NOTIFY_TYPE:
1203 if (printer_notify_table[msg->field].fn) {
1204 printer_notify_table[msg->field].fn(msg,
1205 ¬ifies[count], mem_ctx);
1209 case JOB_NOTIFY_TYPE:
1210 if (job_notify_table[msg->field].fn) {
1211 job_notify_table[msg->field].fn(msg,
1212 ¬ifies[count], mem_ctx);
1217 DEBUG(5, ("Unknown notification type %d\n",
1225 *_notifies = notifies;
1231 static int send_notify2_printer(TALLOC_CTX *mem_ctx,
1232 struct printer_handle *prn_hnd,
1233 SPOOLSS_NOTIFY_MSG_GROUP *msg_group)
1235 struct spoolss_Notify *notifies;
1237 union spoolss_ReplyPrinterInfo info;
1238 struct spoolss_NotifyInfo info0;
1239 uint32_t reply_result;
1244 /* Is there notification on this handle? */
1245 if (prn_hnd->notify.cli_chan == NULL ||
1246 prn_hnd->notify.cli_chan->active_connections == 0) {
1250 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1251 prn_hnd->servername, prn_hnd->sharename));
1253 /* For this printer? Print servers always receive notifications. */
1254 if ((prn_hnd->printer_type == SPLHND_PRINTER) &&
1255 (!strequal(msg_group->printername, prn_hnd->sharename))) {
1259 DEBUG(10,("Our printer\n"));
1261 /* build the array of change notifications */
1262 ret = build_notify2_messages(mem_ctx, prn_hnd,
1264 msg_group->num_msgs,
1270 info0.version = 0x2;
1271 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1272 info0.count = count;
1273 info0.notifies = notifies;
1275 info.info0 = &info0;
1277 status = dcerpc_spoolss_RouterReplyPrinterEx(
1278 prn_hnd->notify.cli_chan->binding_handle,
1280 &prn_hnd->notify.cli_hnd,
1281 prn_hnd->notify.change, /* color */
1282 prn_hnd->notify.flags,
1284 0, /* reply_type, must be 0 */
1286 if (!NT_STATUS_IS_OK(status)) {
1287 DEBUG(1, ("dcerpc_spoolss_RouterReplyPrinterEx to client: %s "
1289 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1290 nt_errstr(status)));
1291 werr = ntstatus_to_werror(status);
1292 } else if (!W_ERROR_IS_OK(werr)) {
1293 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1295 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1298 switch (reply_result) {
1301 case PRINTER_NOTIFY_INFO_DISCARDED:
1302 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1303 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1312 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1314 struct printer_handle *p;
1315 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
1316 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
1320 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1324 if (!msg_group->msgs) {
1325 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1329 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
1331 /* loop over all printers */
1333 for (p = printers_list; p; p = p->next) {
1334 ret = send_notify2_printer(mem_ctx, p, msg_group);
1341 DEBUG(8,("send_notify2_changes: Exit...\n"));
1345 /***********************************************************************
1346 **********************************************************************/
1348 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1351 uint32_t tv_sec, tv_usec;
1354 /* Unpack message */
1356 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1359 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1361 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1364 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1365 &msg->notify.value[0], &msg->notify.value[1]);
1367 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1368 &msg->len, &msg->notify.data);
1370 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1371 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1373 tv->tv_sec = tv_sec;
1374 tv->tv_usec = tv_usec;
1377 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1378 msg->notify.value[1]));
1380 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1385 /********************************************************************
1386 Receive a notify2 message list
1387 ********************************************************************/
1389 static void receive_notify2_message_list(struct messaging_context *msg,
1392 struct server_id server_id,
1395 size_t msg_count, i;
1396 char *buf = (char *)data->data;
1399 SPOOLSS_NOTIFY_MSG notify;
1400 SPOOLSS_NOTIFY_MSG_CTR messages;
1403 if (data->length < 4) {
1404 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1408 msg_count = IVAL(buf, 0);
1411 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1413 if (msg_count == 0) {
1414 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1418 /* initialize the container */
1420 ZERO_STRUCT( messages );
1421 notify_msg_ctr_init( &messages );
1424 * build message groups for each printer identified
1425 * in a change_notify msg. Remember that a PCN message
1426 * includes the handle returned for the srv_spoolss_replyopenprinter()
1427 * call. Therefore messages are grouped according to printer handle.
1430 for ( i=0; i<msg_count; i++ ) {
1431 struct timeval msg_tv;
1433 if (msg_ptr + 4 - buf > data->length) {
1434 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1438 msg_len = IVAL(msg_ptr,0);
1441 if (msg_ptr + msg_len - buf > data->length) {
1442 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1446 /* unpack messages */
1448 ZERO_STRUCT( notify );
1449 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1452 /* add to correct list in container */
1454 notify_msg_ctr_addmsg( &messages, ¬ify );
1456 /* free memory that might have been allocated by notify2_unpack_msg() */
1458 if ( notify.len != 0 )
1459 SAFE_FREE( notify.notify.data );
1462 /* process each group of messages */
1464 num_groups = notify_msg_ctr_numgroups( &messages );
1465 for ( i=0; i<num_groups; i++ )
1466 send_notify2_changes( &messages, i );
1471 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1472 (uint32_t)msg_count ));
1474 notify_msg_ctr_destroy( &messages );
1479 /********************************************************************
1480 Send a message to ourself about new driver being installed
1481 so we can upgrade the information for each printer bound to this
1483 ********************************************************************/
1485 static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
1486 struct messaging_context *msg_ctx)
1488 int len = strlen(drivername);
1493 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1496 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
1497 MSG_PRINTER_DRVUPGRADE,
1498 (uint8_t *)drivername, len+1);
1503 void srv_spoolss_cleanup(void)
1505 struct printer_session_counter *session_counter;
1507 for (session_counter = counter_list;
1508 session_counter != NULL;
1509 session_counter = counter_list) {
1510 DLIST_REMOVE(counter_list, session_counter);
1511 TALLOC_FREE(session_counter);
1515 /**********************************************************************
1516 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1517 over all printers, upgrading ones as necessary
1518 **********************************************************************/
1520 void do_drv_upgrade_printer(struct messaging_context *msg,
1523 struct server_id server_id,
1526 TALLOC_CTX *tmp_ctx;
1527 struct auth_serversupplied_info *session_info = NULL;
1528 struct spoolss_PrinterInfo2 *pinfo2;
1531 const char *drivername;
1533 int n_services = lp_numservices();
1535 tmp_ctx = talloc_new(NULL);
1536 if (!tmp_ctx) return;
1538 status = make_session_info_system(tmp_ctx, &session_info);
1539 if (!NT_STATUS_IS_OK(status)) {
1540 DEBUG(0, ("do_drv_upgrade_printer: "
1541 "Could not create system session_info\n"));
1545 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, data->length);
1547 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1551 DEBUG(10, ("do_drv_upgrade_printer: "
1552 "Got message for new driver [%s]\n", drivername));
1554 /* Iterate the printer list */
1556 for (snum = 0; snum < n_services; snum++) {
1557 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1561 /* ignore [printers] share */
1562 if (strequal(lp_const_servicename(snum), "printers")) {
1566 result = winreg_get_printer(tmp_ctx, session_info, msg,
1567 lp_const_servicename(snum),
1570 if (!W_ERROR_IS_OK(result)) {
1574 if (!pinfo2->drivername) {
1578 if (strcmp(drivername, pinfo2->drivername) != 0) {
1582 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1584 /* all we care about currently is the change_id */
1585 result = winreg_printer_update_changeid(tmp_ctx,
1588 pinfo2->printername);
1590 if (!W_ERROR_IS_OK(result)) {
1591 DEBUG(3, ("do_drv_upgrade_printer: "
1592 "Failed to update changeid [%s]\n",
1593 win_errstr(result)));
1599 talloc_free(tmp_ctx);
1602 /********************************************************************
1603 Update the cache for all printq's with a registered client
1605 ********************************************************************/
1607 void update_monitored_printq_cache(struct messaging_context *msg_ctx)
1609 struct printer_handle *printer = printers_list;
1612 /* loop through all printers and update the cache where
1613 a client is connected */
1615 if ((printer->printer_type == SPLHND_PRINTER) &&
1616 ((printer->notify.cli_chan != NULL) &&
1617 (printer->notify.cli_chan->active_connections > 0))) {
1618 snum = print_queue_snum(printer->sharename);
1619 print_queue_status(msg_ctx, snum, NULL, NULL);
1622 printer = printer->next;
1628 /****************************************************************
1629 _spoolss_OpenPrinter
1630 ****************************************************************/
1632 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1633 struct spoolss_OpenPrinter *r)
1635 struct spoolss_OpenPrinterEx e;
1638 ZERO_STRUCT(e.in.userlevel);
1640 e.in.printername = r->in.printername;
1641 e.in.datatype = r->in.datatype;
1642 e.in.devmode_ctr = r->in.devmode_ctr;
1643 e.in.access_mask = r->in.access_mask;
1646 e.out.handle = r->out.handle;
1648 werr = _spoolss_OpenPrinterEx(p, &e);
1650 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1651 /* OpenPrinterEx returns this for a bad
1652 * printer name. We must return WERR_INVALID_PRINTER_NAME
1655 werr = WERR_INVALID_PRINTER_NAME;
1661 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1662 struct spoolss_DeviceMode *orig,
1663 struct spoolss_DeviceMode **dest)
1665 struct spoolss_DeviceMode *dm;
1667 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1672 /* copy all values, then duplicate strings and structs */
1675 dm->devicename = talloc_strdup(dm, orig->devicename);
1676 if (!dm->devicename) {
1679 dm->formname = talloc_strdup(dm, orig->formname);
1680 if (!dm->formname) {
1683 if (orig->driverextra_data.data) {
1684 dm->driverextra_data.data =
1685 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1686 orig->driverextra_data.length);
1687 if (!dm->driverextra_data.data) {
1696 /****************************************************************
1697 _spoolss_OpenPrinterEx
1698 ****************************************************************/
1700 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1701 struct spoolss_OpenPrinterEx *r)
1704 struct printer_handle *Printer=NULL;
1707 if (!r->in.printername) {
1708 return WERR_INVALID_PARAM;
1711 if (r->in.level < 0 || r->in.level > 3) {
1712 return WERR_INVALID_PARAM;
1714 if ((r->in.level == 1 && !r->in.userlevel.level1) ||
1715 (r->in.level == 2 && !r->in.userlevel.level2) ||
1716 (r->in.level == 3 && !r->in.userlevel.level3)) {
1717 return WERR_INVALID_PARAM;
1720 /* some sanity check because you can open a printer or a print server */
1721 /* aka: \\server\printer or \\server */
1723 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1725 result = open_printer_hnd(p, r->out.handle, r->in.printername, 0);
1726 if (!W_ERROR_IS_OK(result)) {
1727 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1728 "for printer %s\n", r->in.printername));
1729 ZERO_STRUCTP(r->out.handle);
1733 Printer = find_printer_index_by_hnd(p, r->out.handle);
1735 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1736 "handle we created for printer %s\n", r->in.printername));
1737 close_printer_handle(p, r->out.handle);
1738 ZERO_STRUCTP(r->out.handle);
1739 return WERR_INVALID_PARAM;
1743 * First case: the user is opening the print server:
1745 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1746 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1748 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1749 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1750 * or if the user is listed in the smb.conf printer admin parameter.
1752 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1753 * client view printer folder, but does not show the MSAPW.
1755 * Note: this test needs code to check access rights here too. Jeremy
1756 * could you look at this?
1758 * Second case: the user is opening a printer:
1759 * NT doesn't let us connect to a printer if the connecting user
1760 * doesn't have print permission.
1762 * Third case: user is opening a Port Monitor
1763 * access checks same as opening a handle to the print server.
1766 switch (Printer->printer_type )
1769 case SPLHND_PORTMON_TCP:
1770 case SPLHND_PORTMON_LOCAL:
1771 /* Printserver handles use global struct... */
1775 /* Map standard access rights to object specific access rights */
1777 se_map_standard(&r->in.access_mask,
1778 &printserver_std_mapping);
1780 /* Deny any object specific bits that don't apply to print
1781 servers (i.e printer and job specific bits) */
1783 r->in.access_mask &= SEC_MASK_SPECIFIC;
1785 if (r->in.access_mask &
1786 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1787 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1788 close_printer_handle(p, r->out.handle);
1789 ZERO_STRUCTP(r->out.handle);
1790 return WERR_ACCESS_DENIED;
1793 /* Allow admin access */
1795 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1797 if (!lp_ms_add_printer_wizard()) {
1798 close_printer_handle(p, r->out.handle);
1799 ZERO_STRUCTP(r->out.handle);
1800 return WERR_ACCESS_DENIED;
1803 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1804 and not a printer admin, then fail */
1806 if ((p->session_info->utok.uid != sec_initial_uid()) &&
1807 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
1808 !nt_token_check_sid(&global_sid_Builtin_Print_Operators, p->session_info->security_token) &&
1809 !token_contains_name_in_list(
1810 uidtoname(p->session_info->utok.uid),
1811 p->session_info->info3->base.domain.string,
1813 p->session_info->security_token,
1814 lp_printer_admin(snum))) {
1815 close_printer_handle(p, r->out.handle);
1816 ZERO_STRUCTP(r->out.handle);
1817 DEBUG(3,("access DENIED as user is not root, "
1818 "has no printoperator privilege, "
1819 "not a member of the printoperator builtin group and "
1820 "is not in printer admin list"));
1821 return WERR_ACCESS_DENIED;
1824 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1828 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1831 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1832 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1834 /* We fall through to return WERR_OK */
1837 case SPLHND_PRINTER:
1838 /* NT doesn't let us connect to a printer if the connecting user
1839 doesn't have print permission. */
1841 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1842 close_printer_handle(p, r->out.handle);
1843 ZERO_STRUCTP(r->out.handle);
1847 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1848 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1851 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1853 /* map an empty access mask to the minimum access mask */
1854 if (r->in.access_mask == 0x0)
1855 r->in.access_mask = PRINTER_ACCESS_USE;
1858 * If we are not serving the printer driver for this printer,
1859 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1860 * will keep NT clients happy --jerry
1863 if (lp_use_client_driver(snum)
1864 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1866 r->in.access_mask = PRINTER_ACCESS_USE;
1869 /* check smb.conf parameters and the the sec_desc */
1871 if (!allow_access(lp_hostsdeny(snum), lp_hostsallow(snum),
1872 p->client_id->name, p->client_id->addr)) {
1873 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1874 ZERO_STRUCTP(r->out.handle);
1875 return WERR_ACCESS_DENIED;
1878 if (!user_ok_token(uidtoname(p->session_info->utok.uid), NULL,
1879 p->session_info->security_token, snum) ||
1880 !print_access_check(p->session_info,
1883 r->in.access_mask)) {
1884 DEBUG(3, ("access DENIED for printer open\n"));
1885 close_printer_handle(p, r->out.handle);
1886 ZERO_STRUCTP(r->out.handle);
1887 return WERR_ACCESS_DENIED;
1890 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1891 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1892 close_printer_handle(p, r->out.handle);
1893 ZERO_STRUCTP(r->out.handle);
1894 return WERR_ACCESS_DENIED;
1897 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1898 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1900 r->in.access_mask = PRINTER_ACCESS_USE;
1902 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1903 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1905 winreg_create_printer(p->mem_ctx,
1906 get_session_info_system(),
1908 lp_const_servicename(snum));
1913 /* sanity check to prevent programmer error */
1914 ZERO_STRUCTP(r->out.handle);
1918 Printer->access_granted = r->in.access_mask;
1921 * If the client sent a devmode in the OpenPrinter() call, then
1922 * save it here in case we get a job submission on this handle
1925 if ((Printer->printer_type != SPLHND_SERVER) &&
1926 r->in.devmode_ctr.devmode) {
1927 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1931 #if 0 /* JERRY -- I'm doubtful this is really effective */
1932 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1933 optimization in Windows 2000 clients --jerry */
1935 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1936 && (RA_WIN2K == get_remote_arch()) )
1938 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1939 sys_usleep( 500000 );
1946 /****************************************************************
1947 _spoolss_ClosePrinter
1948 ****************************************************************/
1950 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1951 struct spoolss_ClosePrinter *r)
1953 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1955 if (Printer && Printer->document_started) {
1956 struct spoolss_EndDocPrinter e;
1958 e.in.handle = r->in.handle;
1960 _spoolss_EndDocPrinter(p, &e);
1963 if (!close_printer_handle(p, r->in.handle))
1966 /* clear the returned printer handle. Observed behavior
1967 from Win2k server. Don't think this really matters.
1968 Previous code just copied the value of the closed
1971 ZERO_STRUCTP(r->out.handle);
1976 /****************************************************************
1977 _spoolss_DeletePrinter
1978 ****************************************************************/
1980 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1981 struct spoolss_DeletePrinter *r)
1983 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1987 if (Printer && Printer->document_started) {
1988 struct spoolss_EndDocPrinter e;
1990 e.in.handle = r->in.handle;
1992 _spoolss_EndDocPrinter(p, &e);
1995 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
1996 winreg_delete_printer_key(p->mem_ctx,
1997 get_session_info_system(),
1999 lp_const_servicename(snum),
2003 result = delete_printer_handle(p, r->in.handle);
2008 /*******************************************************************
2009 * static function to lookup the version id corresponding to an
2010 * long architecture string
2011 ******************************************************************/
2013 static const struct print_architecture_table_node archi_table[]= {
2015 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
2016 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
2017 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
2018 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
2019 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
2020 {"Windows IA64", SPL_ARCH_IA64, 3 },
2021 {"Windows x64", SPL_ARCH_X64, 3 },
2025 static int get_version_id(const char *arch)
2029 for (i=0; archi_table[i].long_archi != NULL; i++)
2031 if (strcmp(arch, archi_table[i].long_archi) == 0)
2032 return (archi_table[i].version);
2038 /****************************************************************
2039 _spoolss_DeletePrinterDriver
2040 ****************************************************************/
2042 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
2043 struct spoolss_DeletePrinterDriver *r)
2046 struct spoolss_DriverInfo8 *info = NULL;
2047 struct spoolss_DriverInfo8 *info_win2k = NULL;
2051 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2052 and not a printer admin, then fail */
2054 if ( (p->session_info->utok.uid != sec_initial_uid())
2055 && !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR)
2056 && !token_contains_name_in_list(
2057 uidtoname(p->session_info->utok.uid),
2058 p->session_info->info3->base.domain.string,
2060 p->session_info->security_token,
2061 lp_printer_admin(-1)) )
2063 return WERR_ACCESS_DENIED;
2066 /* check that we have a valid driver name first */
2068 if ((version = get_version_id(r->in.architecture)) == -1)
2069 return WERR_INVALID_ENVIRONMENT;
2071 status = winreg_get_driver(p->mem_ctx,
2072 get_session_info_system(),
2074 r->in.architecture, r->in.driver,
2076 if (!W_ERROR_IS_OK(status)) {
2077 /* try for Win2k driver if "Windows NT x86" */
2079 if ( version == 2 ) {
2082 status = winreg_get_driver(p->mem_ctx,
2083 get_session_info_system(),
2088 if (!W_ERROR_IS_OK(status)) {
2089 status = WERR_UNKNOWN_PRINTER_DRIVER;
2093 /* otherwise it was a failure */
2095 status = WERR_UNKNOWN_PRINTER_DRIVER;
2101 if (printer_driver_in_use(p->mem_ctx,
2102 get_session_info_system(),
2105 status = WERR_PRINTER_DRIVER_IN_USE;
2110 status = winreg_get_driver(p->mem_ctx,
2111 get_session_info_system(),
2114 r->in.driver, 3, &info_win2k);
2115 if (W_ERROR_IS_OK(status)) {
2116 /* if we get to here, we now have 2 driver info structures to remove */
2117 /* remove the Win2k driver first*/
2119 status = winreg_del_driver(p->mem_ctx,
2120 get_session_info_system(),
2123 talloc_free(info_win2k);
2125 /* this should not have failed---if it did, report to client */
2126 if (!W_ERROR_IS_OK(status)) {
2132 status = winreg_del_driver(p->mem_ctx,
2133 get_session_info_system(),
2143 /****************************************************************
2144 _spoolss_DeletePrinterDriverEx
2145 ****************************************************************/
2147 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
2148 struct spoolss_DeletePrinterDriverEx *r)
2150 struct spoolss_DriverInfo8 *info = NULL;
2151 struct spoolss_DriverInfo8 *info_win2k = NULL;
2156 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2157 and not a printer admin, then fail */
2159 if ( (p->session_info->utok.uid != sec_initial_uid())
2160 && !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR)
2161 && !token_contains_name_in_list(
2162 uidtoname(p->session_info->utok.uid),
2163 p->session_info->info3->base.domain.string,
2165 p->session_info->security_token, lp_printer_admin(-1)) )
2167 return WERR_ACCESS_DENIED;
2170 /* check that we have a valid driver name first */
2171 if ((version = get_version_id(r->in.architecture)) == -1) {
2172 /* this is what NT returns */
2173 return WERR_INVALID_ENVIRONMENT;
2176 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2177 version = r->in.version;
2179 status = winreg_get_driver(p->mem_ctx,
2180 get_session_info_system(),
2186 if (!W_ERROR_IS_OK(status)) {
2187 status = WERR_UNKNOWN_PRINTER_DRIVER;
2190 * if the client asked for a specific version,
2191 * or this is something other than Windows NT x86,
2195 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2198 /* try for Win2k driver if "Windows NT x86" */
2201 status = winreg_get_driver(info,
2202 get_session_info_system(),
2207 if (!W_ERROR_IS_OK(status)) {
2208 status = WERR_UNKNOWN_PRINTER_DRIVER;
2213 if (printer_driver_in_use(info,
2214 get_session_info_system(),
2217 status = WERR_PRINTER_DRIVER_IN_USE;
2222 * we have a couple of cases to consider.
2223 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2224 * then the delete should fail if **any** files overlap with
2226 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2227 * non-overlapping files
2228 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2229 * is set, the do not delete any files
2230 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2233 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2235 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2238 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2239 printer_driver_files_in_use(info,
2240 get_session_info_system(),
2243 /* no idea of the correct error here */
2244 status = WERR_ACCESS_DENIED;
2249 /* also check for W32X86/3 if necessary; maybe we already have? */
2251 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2252 status = winreg_get_driver(info,
2253 get_session_info_system(),
2256 r->in.driver, 3, &info_win2k);
2257 if (W_ERROR_IS_OK(status)) {
2260 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2261 printer_driver_files_in_use(info,
2262 get_session_info_system(),
2265 /* no idea of the correct error here */
2266 talloc_free(info_win2k);
2267 status = WERR_ACCESS_DENIED;
2271 /* if we get to here, we now have 2 driver info structures to remove */
2272 /* remove the Win2k driver first*/
2274 status = winreg_del_driver(info,
2275 get_session_info_system(),
2280 /* this should not have failed---if it did, report to client */
2282 if (!W_ERROR_IS_OK(status)) {
2287 * now delete any associated files if delete_files is
2288 * true. Even if this part failes, we return succes
2289 * because the driver doesn not exist any more
2292 delete_driver_files(get_session_info_system(),
2298 status = winreg_del_driver(info,
2299 get_session_info_system(),
2303 if (!W_ERROR_IS_OK(status)) {
2308 * now delete any associated files if delete_files is
2309 * true. Even if this part failes, we return succes
2310 * because the driver doesn not exist any more
2313 delete_driver_files(get_session_info_system(), info);
2322 /********************************************************************
2323 GetPrinterData on a printer server Handle.
2324 ********************************************************************/
2326 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2328 enum winreg_Type *type,
2329 union spoolss_PrinterData *data)
2331 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2333 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2339 if (!StrCaseCmp(value, "BeepEnabled")) {
2345 if (!StrCaseCmp(value, "EventLog")) {
2347 /* formally was 0x1b */
2352 if (!StrCaseCmp(value, "NetPopup")) {
2358 if (!StrCaseCmp(value, "MajorVersion")) {
2361 /* Windows NT 4.0 seems to not allow uploading of drivers
2362 to a server that reports 0x3 as the MajorVersion.
2363 need to investigate more how Win2k gets around this .
2366 if (RA_WINNT == get_remote_arch()) {
2375 if (!StrCaseCmp(value, "MinorVersion")) {
2382 * uint32_t size = 0x114
2383 * uint32_t major = 5
2384 * uint32_t minor = [0|1]
2385 * uint32_t build = [2195|2600]
2386 * extra unicode string = e.g. "Service Pack 3"
2388 if (!StrCaseCmp(value, "OSVersion")) {
2390 enum ndr_err_code ndr_err;
2391 struct spoolss_OSVersion os;
2393 os.major = 5; /* Windows 2000 == 5.0 */
2395 os.build = 2195; /* build */
2396 os.extra_string = ""; /* leave extra string empty */
2398 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2399 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2400 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2401 return WERR_GENERAL_FAILURE;
2405 data->binary = blob;
2411 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2414 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2415 W_ERROR_HAVE_NO_MEMORY(data->string);
2420 if (!StrCaseCmp(value, "Architecture")) {
2422 data->string = talloc_strdup(mem_ctx,
2423 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2424 W_ERROR_HAVE_NO_MEMORY(data->string);
2429 if (!StrCaseCmp(value, "DsPresent")) {
2432 /* only show the publish check box if we are a
2433 member of a AD domain */
2435 if (lp_security() == SEC_ADS) {
2443 if (!StrCaseCmp(value, "DNSMachineName")) {
2444 const char *hostname = get_mydnsfullname();
2447 return WERR_BADFILE;
2451 data->string = talloc_strdup(mem_ctx, hostname);
2452 W_ERROR_HAVE_NO_MEMORY(data->string);
2459 return WERR_INVALID_PARAM;
2462 /****************************************************************
2463 _spoolss_GetPrinterData
2464 ****************************************************************/
2466 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2467 struct spoolss_GetPrinterData *r)
2469 struct spoolss_GetPrinterDataEx r2;
2471 r2.in.handle = r->in.handle;
2472 r2.in.key_name = "PrinterDriverData";
2473 r2.in.value_name = r->in.value_name;
2474 r2.in.offered = r->in.offered;
2475 r2.out.type = r->out.type;
2476 r2.out.data = r->out.data;
2477 r2.out.needed = r->out.needed;
2479 return _spoolss_GetPrinterDataEx(p, &r2);
2482 /*********************************************************
2483 Connect to the client machine.
2484 **********************************************************/
2486 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2487 struct sockaddr_storage *client_ss, const char *remote_machine)
2490 struct cli_state *the_cli;
2491 struct sockaddr_storage rm_addr;
2492 char addr[INET6_ADDRSTRLEN];
2494 if ( is_zero_addr(client_ss) ) {
2495 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2497 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2498 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2501 print_sockaddr(addr, sizeof(addr), &rm_addr);
2503 rm_addr = *client_ss;
2504 print_sockaddr(addr, sizeof(addr), &rm_addr);
2505 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2509 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2510 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2515 /* setup the connection */
2516 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2517 &rm_addr, 0, "IPC$", "IPC",
2521 0, lp_client_signing());
2523 if ( !NT_STATUS_IS_OK( ret ) ) {
2524 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2529 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2530 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2531 cli_shutdown(the_cli);
2536 * Ok - we have an anonymous connection to the IPC$ share.
2537 * Now start the NT Domain stuff :-).
2540 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2541 if (!NT_STATUS_IS_OK(ret)) {
2542 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2543 remote_machine, nt_errstr(ret)));
2544 cli_shutdown(the_cli);
2551 /***************************************************************************
2552 Connect to the client.
2553 ****************************************************************************/
2555 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2556 uint32_t localprinter,
2557 enum winreg_Type type,
2558 struct policy_handle *handle,
2559 struct notify_back_channel **_chan,
2560 struct sockaddr_storage *client_ss,
2561 struct messaging_context *msg_ctx)
2565 struct notify_back_channel *chan;
2567 for (chan = back_channels; chan; chan = chan->next) {
2568 if (memcmp(&chan->client_address, client_ss,
2569 sizeof(struct sockaddr_storage)) == 0) {
2575 * If it's the first connection, contact the client
2576 * and connect to the IPC$ share anonymously
2579 fstring unix_printer;
2581 /* the +2 is to strip the leading 2 backslashs */
2582 fstrcpy(unix_printer, printer + 2);
2584 chan = talloc_zero(back_channels, struct notify_back_channel);
2588 chan->client_address = *client_ss;
2590 if (!spoolss_connect_to_client(&chan->cli_pipe, client_ss, unix_printer)) {
2594 chan->binding_handle = chan->cli_pipe->binding_handle;
2596 DLIST_ADD(back_channels, chan);
2598 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2599 receive_notify2_message_list);
2600 /* Tell the connections db we're now interested in printer
2601 * notify messages. */
2602 serverid_register_msg_flags(messaging_server_id(msg_ctx),
2603 true, FLAG_MSG_PRINT_NOTIFY);
2607 * Tell the specific printing tdb we want messages for this printer
2608 * by registering our PID.
2611 if (!print_notify_register_pid(snum)) {
2612 DEBUG(0, ("Failed to register our pid for printer %s\n",
2616 status = dcerpc_spoolss_ReplyOpenPrinter(chan->binding_handle,
2625 if (!NT_STATUS_IS_OK(status)) {
2626 DEBUG(5, ("dcerpc_spoolss_ReplyOpenPrinter returned [%s]\n", nt_errstr(status)));
2627 result = ntstatus_to_werror(status);
2628 } else if (!W_ERROR_IS_OK(result)) {
2629 DEBUG(5, ("ReplyOpenPrinter returned [%s]\n", win_errstr(result)));
2632 chan->active_connections++;
2635 return (W_ERROR_IS_OK(result));
2638 /****************************************************************
2639 ****************************************************************/
2641 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2642 const struct spoolss_NotifyOption *r)
2644 struct spoolss_NotifyOption *option;
2651 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2658 if (!option->count) {
2662 option->types = talloc_zero_array(option,
2663 struct spoolss_NotifyOptionType, option->count);
2664 if (!option->types) {
2665 talloc_free(option);
2669 for (i=0; i < option->count; i++) {
2670 option->types[i] = r->types[i];
2672 if (option->types[i].count) {
2673 option->types[i].fields = talloc_zero_array(option,
2674 union spoolss_Field, option->types[i].count);
2675 if (!option->types[i].fields) {
2676 talloc_free(option);
2679 for (k=0; k<option->types[i].count; k++) {
2680 option->types[i].fields[k] =
2681 r->types[i].fields[k];
2689 /****************************************************************
2690 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2692 * before replying OK: status=0 a rpc call is made to the workstation
2693 * asking ReplyOpenPrinter
2695 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2696 * called from api_spoolss_rffpcnex
2697 ****************************************************************/
2699 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2700 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2703 struct spoolss_NotifyOption *option = r->in.notify_options;
2704 struct sockaddr_storage client_ss;
2706 /* store the notify value in the printer struct */
2708 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2711 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2712 "Invalid handle (%s:%u:%u).\n",
2713 OUR_HANDLE(r->in.handle)));
2717 Printer->notify.flags = r->in.flags;
2718 Printer->notify.options = r->in.options;
2719 Printer->notify.printerlocal = r->in.printer_local;
2720 Printer->notify.msg_ctx = p->msg_ctx;
2722 TALLOC_FREE(Printer->notify.option);
2723 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2725 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2727 /* Connect to the client machine and send a ReplyOpenPrinter */
2729 if ( Printer->printer_type == SPLHND_SERVER)
2731 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2732 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2735 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2736 "client_address is %s\n", p->client_id->addr));
2738 if (!interpret_string_addr(&client_ss, p->client_id->addr,
2740 return WERR_SERVER_UNAVAILABLE;
2743 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2744 Printer->notify.printerlocal, REG_SZ,
2745 &Printer->notify.cli_hnd,
2746 &Printer->notify.cli_chan,
2747 &client_ss, p->msg_ctx)) {
2748 return WERR_SERVER_UNAVAILABLE;
2754 /*******************************************************************
2755 * fill a notify_info_data with the servername
2756 ********************************************************************/
2758 static void spoolss_notify_server_name(struct messaging_context *msg_ctx,
2760 struct spoolss_Notify *data,
2761 print_queue_struct *queue,
2762 struct spoolss_PrinterInfo2 *pinfo2,
2763 TALLOC_CTX *mem_ctx)
2765 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2768 /*******************************************************************
2769 * fill a notify_info_data with the printername (not including the servername).
2770 ********************************************************************/
2772 static void spoolss_notify_printer_name(struct messaging_context *msg_ctx,
2774 struct spoolss_Notify *data,
2775 print_queue_struct *queue,
2776 struct spoolss_PrinterInfo2 *pinfo2,
2777 TALLOC_CTX *mem_ctx)
2779 /* the notify name should not contain the \\server\ part */
2780 const char *p = strrchr(pinfo2->printername, '\\');
2783 p = pinfo2->printername;
2788 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2791 /*******************************************************************
2792 * fill a notify_info_data with the servicename
2793 ********************************************************************/
2795 static void spoolss_notify_share_name(struct messaging_context *msg_ctx,
2797 struct spoolss_Notify *data,
2798 print_queue_struct *queue,
2799 struct spoolss_PrinterInfo2 *pinfo2,
2800 TALLOC_CTX *mem_ctx)
2802 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2805 /*******************************************************************
2806 * fill a notify_info_data with the port name
2807 ********************************************************************/
2809 static void spoolss_notify_port_name(struct messaging_context *msg_ctx,
2811 struct spoolss_Notify *data,
2812 print_queue_struct *queue,
2813 struct spoolss_PrinterInfo2 *pinfo2,
2814 TALLOC_CTX *mem_ctx)
2816 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2819 /*******************************************************************
2820 * fill a notify_info_data with the printername
2821 * but it doesn't exist, have to see what to do
2822 ********************************************************************/
2824 static void spoolss_notify_driver_name(struct messaging_context *msg_ctx,
2826 struct spoolss_Notify *data,
2827 print_queue_struct *queue,
2828 struct spoolss_PrinterInfo2 *pinfo2,
2829 TALLOC_CTX *mem_ctx)
2831 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2834 /*******************************************************************
2835 * fill a notify_info_data with the comment
2836 ********************************************************************/
2838 static void spoolss_notify_comment(struct messaging_context *msg_ctx,
2840 struct spoolss_Notify *data,
2841 print_queue_struct *queue,
2842 struct spoolss_PrinterInfo2 *pinfo2,
2843 TALLOC_CTX *mem_ctx)
2847 if (*pinfo2->comment == '\0') {
2848 p = lp_comment(snum);
2850 p = pinfo2->comment;
2853 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2856 /*******************************************************************
2857 * fill a notify_info_data with the comment
2858 * location = "Room 1, floor 2, building 3"
2859 ********************************************************************/
2861 static void spoolss_notify_location(struct messaging_context *msg_ctx,
2863 struct spoolss_Notify *data,
2864 print_queue_struct *queue,
2865 struct spoolss_PrinterInfo2 *pinfo2,
2866 TALLOC_CTX *mem_ctx)
2868 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
2871 /*******************************************************************
2872 * fill a notify_info_data with the device mode
2873 * jfm:xxxx don't to it for know but that's a real problem !!!
2874 ********************************************************************/
2876 static void spoolss_notify_devmode(struct messaging_context *msg_ctx,
2878 struct spoolss_Notify *data,
2879 print_queue_struct *queue,
2880 struct spoolss_PrinterInfo2 *pinfo2,
2881 TALLOC_CTX *mem_ctx)
2883 /* for a dummy implementation we have to zero the fields */
2884 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2887 /*******************************************************************
2888 * fill a notify_info_data with the separator file name
2889 ********************************************************************/
2891 static void spoolss_notify_sepfile(struct messaging_context *msg_ctx,
2893 struct spoolss_Notify *data,
2894 print_queue_struct *queue,
2895 struct spoolss_PrinterInfo2 *pinfo2,
2896 TALLOC_CTX *mem_ctx)
2898 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2901 /*******************************************************************
2902 * fill a notify_info_data with the print processor
2903 * jfm:xxxx return always winprint to indicate we don't do anything to it
2904 ********************************************************************/
2906 static void spoolss_notify_print_processor(struct messaging_context *msg_ctx,
2908 struct spoolss_Notify *data,
2909 print_queue_struct *queue,
2910 struct spoolss_PrinterInfo2 *pinfo2,
2911 TALLOC_CTX *mem_ctx)
2913 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2916 /*******************************************************************
2917 * fill a notify_info_data with the print processor options
2918 * jfm:xxxx send an empty string
2919 ********************************************************************/
2921 static void spoolss_notify_parameters(struct messaging_context *msg_ctx,
2923 struct spoolss_Notify *data,
2924 print_queue_struct *queue,
2925 struct spoolss_PrinterInfo2 *pinfo2,
2926 TALLOC_CTX *mem_ctx)
2928 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2931 /*******************************************************************
2932 * fill a notify_info_data with the data type
2933 * jfm:xxxx always send RAW as data type
2934 ********************************************************************/
2936 static void spoolss_notify_datatype(struct messaging_context *msg_ctx,
2938 struct spoolss_Notify *data,
2939 print_queue_struct *queue,
2940 struct spoolss_PrinterInfo2 *pinfo2,
2941 TALLOC_CTX *mem_ctx)
2943 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2946 /*******************************************************************
2947 * fill a notify_info_data with the security descriptor
2948 * jfm:xxxx send an null pointer to say no security desc
2949 * have to implement security before !
2950 ********************************************************************/
2952 static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
2954 struct spoolss_Notify *data,
2955 print_queue_struct *queue,
2956 struct spoolss_PrinterInfo2 *pinfo2,
2957 TALLOC_CTX *mem_ctx)
2959 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2962 /*******************************************************************
2963 * fill a notify_info_data with the attributes
2964 * jfm:xxxx a samba printer is always shared
2965 ********************************************************************/
2967 static void spoolss_notify_attributes(struct messaging_context *msg_ctx,
2969 struct spoolss_Notify *data,
2970 print_queue_struct *queue,
2971 struct spoolss_PrinterInfo2 *pinfo2,
2972 TALLOC_CTX *mem_ctx)
2974 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2977 /*******************************************************************
2978 * fill a notify_info_data with the priority
2979 ********************************************************************/
2981 static void spoolss_notify_priority(struct messaging_context *msg_ctx,
2983 struct spoolss_Notify *data,
2984 print_queue_struct *queue,
2985 struct spoolss_PrinterInfo2 *pinfo2,
2986 TALLOC_CTX *mem_ctx)
2988 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2991 /*******************************************************************
2992 * fill a notify_info_data with the default priority
2993 ********************************************************************/
2995 static void spoolss_notify_default_priority(struct messaging_context *msg_ctx,
2997 struct spoolss_Notify *data,
2998 print_queue_struct *queue,
2999 struct spoolss_PrinterInfo2 *pinfo2,
3000 TALLOC_CTX *mem_ctx)
3002 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
3005 /*******************************************************************
3006 * fill a notify_info_data with the start time
3007 ********************************************************************/
3009 static void spoolss_notify_start_time(struct messaging_context *msg_ctx,
3011 struct spoolss_Notify *data,
3012 print_queue_struct *queue,
3013 struct spoolss_PrinterInfo2 *pinfo2,
3014 TALLOC_CTX *mem_ctx)
3016 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
3019 /*******************************************************************
3020 * fill a notify_info_data with the until time
3021 ********************************************************************/
3023 static void spoolss_notify_until_time(struct messaging_context *msg_ctx,
3025 struct spoolss_Notify *data,
3026 print_queue_struct *queue,
3027 struct spoolss_PrinterInfo2 *pinfo2,
3028 TALLOC_CTX *mem_ctx)
3030 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
3033 /*******************************************************************
3034 * fill a notify_info_data with the status
3035 ********************************************************************/
3037 static void spoolss_notify_status(struct messaging_context *msg_ctx,
3039 struct spoolss_Notify *data,
3040 print_queue_struct *queue,
3041 struct spoolss_PrinterInfo2 *pinfo2,
3042 TALLOC_CTX *mem_ctx)
3044 print_status_struct status;
3046 print_queue_length(msg_ctx, snum, &status);
3047 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3050 /*******************************************************************
3051 * fill a notify_info_data with the number of jobs queued
3052 ********************************************************************/
3054 static void spoolss_notify_cjobs(struct messaging_context *msg_ctx,
3056 struct spoolss_Notify *data,
3057 print_queue_struct *queue,
3058 struct spoolss_PrinterInfo2 *pinfo2,
3059 TALLOC_CTX *mem_ctx)
3061 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3062 data, print_queue_length(msg_ctx, snum, NULL));
3065 /*******************************************************************
3066 * fill a notify_info_data with the average ppm
3067 ********************************************************************/
3069 static void spoolss_notify_average_ppm(struct messaging_context *msg_ctx,
3071 struct spoolss_Notify *data,
3072 print_queue_struct *queue,
3073 struct spoolss_PrinterInfo2 *pinfo2,
3074 TALLOC_CTX *mem_ctx)
3076 /* always respond 8 pages per minutes */
3077 /* a little hard ! */
3078 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
3081 /*******************************************************************
3082 * fill a notify_info_data with username
3083 ********************************************************************/
3085 static void spoolss_notify_username(struct messaging_context *msg_ctx,
3087 struct spoolss_Notify *data,
3088 print_queue_struct *queue,
3089 struct spoolss_PrinterInfo2 *pinfo2,
3090 TALLOC_CTX *mem_ctx)
3092 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3095 /*******************************************************************
3096 * fill a notify_info_data with job status
3097 ********************************************************************/
3099 static void spoolss_notify_job_status(struct messaging_context *msg_ctx,
3101 struct spoolss_Notify *data,
3102 print_queue_struct *queue,
3103 struct spoolss_PrinterInfo2 *pinfo2,
3104 TALLOC_CTX *mem_ctx)
3106 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3109 /*******************************************************************
3110 * fill a notify_info_data with job name
3111 ********************************************************************/
3113 static void spoolss_notify_job_name(struct messaging_context *msg_ctx,
3115 struct spoolss_Notify *data,
3116 print_queue_struct *queue,
3117 struct spoolss_PrinterInfo2 *pinfo2,
3118 TALLOC_CTX *mem_ctx)
3120 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3123 /*******************************************************************
3124 * fill a notify_info_data with job status
3125 ********************************************************************/
3127 static void spoolss_notify_job_status_string(struct messaging_context *msg_ctx,
3129 struct spoolss_Notify *data,
3130 print_queue_struct *queue,
3131 struct spoolss_PrinterInfo2 *pinfo2,
3132 TALLOC_CTX *mem_ctx)
3135 * Now we're returning job status codes we just return a "" here. JRA.
3140 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3143 switch (queue->status) {
3148 p = ""; /* NT provides the paused string */
3157 #endif /* NO LONGER NEEDED. */
3159 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3162 /*******************************************************************
3163 * fill a notify_info_data with job time
3164 ********************************************************************/
3166 static void spoolss_notify_job_time(struct messaging_context *msg_ctx,
3168 struct spoolss_Notify *data,
3169 print_queue_struct *queue,
3170 struct spoolss_PrinterInfo2 *pinfo2,
3171 TALLOC_CTX *mem_ctx)
3173 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3176 /*******************************************************************
3177 * fill a notify_info_data with job size
3178 ********************************************************************/
3180 static void spoolss_notify_job_size(struct messaging_context *msg_ctx,
3182 struct spoolss_Notify *data,
3183 print_queue_struct *queue,
3184 struct spoolss_PrinterInfo2 *pinfo2,
3185 TALLOC_CTX *mem_ctx)
3187 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3190 /*******************************************************************
3191 * fill a notify_info_data with page info
3192 ********************************************************************/
3193 static void spoolss_notify_total_pages(struct messaging_context *msg_ctx,
3195 struct spoolss_Notify *data,
3196 print_queue_struct *queue,
3197 struct spoolss_PrinterInfo2 *pinfo2,
3198 TALLOC_CTX *mem_ctx)
3200 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3203 /*******************************************************************
3204 * fill a notify_info_data with pages printed info.
3205 ********************************************************************/
3206 static void spoolss_notify_pages_printed(struct messaging_context *msg_ctx,
3208 struct spoolss_Notify *data,
3209 print_queue_struct *queue,
3210 struct spoolss_PrinterInfo2 *pinfo2,
3211 TALLOC_CTX *mem_ctx)
3213 /* Add code when back-end tracks this */
3214 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3217 /*******************************************************************
3218 Fill a notify_info_data with job position.
3219 ********************************************************************/
3221 static void spoolss_notify_job_position(struct messaging_context *msg_ctx,
3223 struct spoolss_Notify *data,
3224 print_queue_struct *queue,
3225 struct spoolss_PrinterInfo2 *pinfo2,
3226 TALLOC_CTX *mem_ctx)
3228 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3231 /*******************************************************************
3232 Fill a notify_info_data with submitted time.
3233 ********************************************************************/
3235 static void spoolss_notify_submitted_time(struct messaging_context *msg_ctx,
3237 struct spoolss_Notify *data,
3238 print_queue_struct *queue,
3239 struct spoolss_PrinterInfo2 *pinfo2,
3240 TALLOC_CTX *mem_ctx)
3242 data->data.string.string = NULL;
3243 data->data.string.size = 0;
3245 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3246 &data->data.string.string,
3247 &data->data.string.size);
3251 struct s_notify_info_data_table
3253 enum spoolss_NotifyType type;
3256 enum spoolss_NotifyTable variable_type;
3257 void (*fn) (struct messaging_context *msg_ctx,
3258 int snum, struct spoolss_Notify *data,
3259 print_queue_struct *queue,
3260 struct spoolss_PrinterInfo2 *pinfo2,
3261 TALLOC_CTX *mem_ctx);
3264 /* A table describing the various print notification constants and
3265 whether the notification data is a pointer to a variable sized
3266 buffer, a one value uint32_t or a two value uint32_t. */
3268 static const struct s_notify_info_data_table notify_info_data_table[] =
3270 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3271 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3272 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3273 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3274 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3275 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3276 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3277 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3278 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3279 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3280 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3281 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3282 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3283 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3284 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3285 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3286 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3287 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3288 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3289 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3290 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3291 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3292 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3293 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3294 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3295 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3296 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3297 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3298 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3299 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3300 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3301 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3302 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3303 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3304 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3305 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3306 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3307 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3308 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3309 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3310 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3311 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3312 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3313 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3314 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3315 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3316 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3317 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3318 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3321 /*******************************************************************
3322 Return the variable_type of info_data structure.
3323 ********************************************************************/
3325 static enum spoolss_NotifyTable variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3330 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3331 if ( (notify_info_data_table[i].type == type) &&
3332 (notify_info_data_table[i].field == field) ) {
3333 return notify_info_data_table[i].variable_type;
3337 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3339 return (enum spoolss_NotifyTable) 0;
3342 /****************************************************************************
3343 ****************************************************************************/
3345 static bool search_notify(enum spoolss_NotifyType type,
3351 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3352 if (notify_info_data_table[i].type == type &&
3353 notify_info_data_table[i].field == field &&
3354 notify_info_data_table[i].fn != NULL) {
3363 /****************************************************************************
3364 ****************************************************************************/
3366 static void construct_info_data(struct spoolss_Notify *info_data,
3367 enum spoolss_NotifyType type,
3368 uint16_t field, int id)
3370 info_data->type = type;
3371 info_data->field.field = field;
3372 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3373 info_data->job_id = id;
3376 /*******************************************************************
3378 * fill a notify_info struct with info asked
3380 ********************************************************************/
3382 static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
3383 struct printer_handle *print_hnd,
3384 struct spoolss_NotifyInfo *info,
3385 struct spoolss_PrinterInfo2 *pinfo2,
3387 const struct spoolss_NotifyOptionType *option_type,
3389 TALLOC_CTX *mem_ctx)
3392 enum spoolss_NotifyType type;
3395 struct spoolss_Notify *current_data;
3396 print_queue_struct *queue=NULL;
3398 type = option_type->type;
3400 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3401 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3402 option_type->count, lp_servicename(snum)));
3404 for(field_num=0; field_num < option_type->count; field_num++) {
3405 field = option_type->fields[field_num].field;
3407 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3409 if (!search_notify(type, field, &j) )
3412 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3413 struct spoolss_Notify,
3415 if (info->notifies == NULL) {
3416 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3420 current_data = &info->notifies[info->count];
3422 construct_info_data(current_data, type, field, id);
3424 DEBUG(10, ("construct_notify_printer_info: "
3425 "calling [%s] snum=%d printername=[%s])\n",
3426 notify_info_data_table[j].name, snum,
3427 pinfo2->printername));
3429 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3430 queue, pinfo2, mem_ctx);
3438 /*******************************************************************
3440 * fill a notify_info struct with info asked
3442 ********************************************************************/
3444 static bool construct_notify_jobs_info(struct messaging_context *msg_ctx,
3445 print_queue_struct *queue,
3446 struct spoolss_NotifyInfo *info,
3447 struct spoolss_PrinterInfo2 *pinfo2,
3449 const struct spoolss_NotifyOptionType *option_type,
3451 TALLOC_CTX *mem_ctx)
3454 enum spoolss_NotifyType type;
3456 struct spoolss_Notify *current_data;
3458 DEBUG(4,("construct_notify_jobs_info\n"));
3460 type = option_type->type;
3462 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3463 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3464 option_type->count));
3466 for(field_num=0; field_num<option_type->count; field_num++) {
3467 field = option_type->fields[field_num].field;
3469 if (!search_notify(type, field, &j) )
3472 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3473 struct spoolss_Notify,
3475 if (info->notifies == NULL) {
3476 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3480 current_data=&(info->notifies[info->count]);
3482 construct_info_data(current_data, type, field, id);
3483 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3484 queue, pinfo2, mem_ctx);
3492 * JFM: The enumeration is not that simple, it's even non obvious.
3494 * let's take an example: I want to monitor the PRINTER SERVER for
3495 * the printer's name and the number of jobs currently queued.
3496 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3497 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3499 * I have 3 printers on the back of my server.
3501 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3504 * 1 printer 1 name 1
3505 * 2 printer 1 cjob 1
3506 * 3 printer 2 name 2
3507 * 4 printer 2 cjob 2
3508 * 5 printer 3 name 3
3509 * 6 printer 3 name 3
3511 * that's the print server case, the printer case is even worse.
3514 /*******************************************************************
3516 * enumerate all printers on the printserver
3517 * fill a notify_info struct with info asked
3519 ********************************************************************/
3521 static WERROR printserver_notify_info(struct pipes_struct *p,
3522 struct policy_handle *hnd,
3523 struct spoolss_NotifyInfo *info,
3524 TALLOC_CTX *mem_ctx)
3527 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3528 int n_services=lp_numservices();
3530 struct spoolss_NotifyOption *option;
3531 struct spoolss_NotifyOptionType option_type;
3532 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3535 DEBUG(4,("printserver_notify_info\n"));
3540 option = Printer->notify.option;
3543 info->notifies = NULL;
3546 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3547 sending a ffpcn() request first */
3552 for (i=0; i<option->count; i++) {
3553 option_type = option->types[i];
3555 if (option_type.type != PRINTER_NOTIFY_TYPE)
3558 for (snum = 0; snum < n_services; snum++) {
3559 if (!lp_browseable(snum) ||
3560 !lp_snum_ok(snum) ||
3561 !lp_print_ok(snum)) {
3562 continue; /* skip */
3565 /* Maybe we should use the SYSTEM session_info here... */
3566 result = winreg_get_printer(mem_ctx,
3567 get_session_info_system(),
3569 lp_servicename(snum),
3571 if (!W_ERROR_IS_OK(result)) {
3572 DEBUG(4, ("printserver_notify_info: "
3573 "Failed to get printer [%s]\n",
3574 lp_servicename(snum)));
3579 construct_notify_printer_info(p->msg_ctx,
3585 TALLOC_FREE(pinfo2);
3591 * Debugging information, don't delete.
3594 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3595 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3596 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3598 for (i=0; i<info->count; i++) {
3599 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3600 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3601 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3608 /*******************************************************************
3610 * fill a notify_info struct with info asked
3612 ********************************************************************/
3614 static WERROR printer_notify_info(struct pipes_struct *p,
3615 struct policy_handle *hnd,
3616 struct spoolss_NotifyInfo *info,
3617 TALLOC_CTX *mem_ctx)
3620 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3623 struct spoolss_NotifyOption *option;
3624 struct spoolss_NotifyOptionType option_type;
3626 print_queue_struct *queue=NULL;
3627 print_status_struct status;
3628 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3631 DEBUG(4,("printer_notify_info\n"));
3636 option = Printer->notify.option;
3640 info->notifies = NULL;
3643 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3644 sending a ffpcn() request first */
3649 get_printer_snum(p, hnd, &snum, NULL);
3651 /* Maybe we should use the SYSTEM session_info here... */
3652 result = winreg_get_printer(mem_ctx,
3653 get_session_info_system(),
3655 lp_servicename(snum), &pinfo2);
3656 if (!W_ERROR_IS_OK(result)) {
3660 for (i=0; i<option->count; i++) {
3661 option_type = option->types[i];
3663 switch (option_type.type) {
3664 case PRINTER_NOTIFY_TYPE:
3665 if (construct_notify_printer_info(p->msg_ctx,
3674 case JOB_NOTIFY_TYPE:
3676 count = print_queue_status(p->msg_ctx, snum, &queue,
3679 for (j=0; j<count; j++) {
3680 construct_notify_jobs_info(p->msg_ctx,
3694 * Debugging information, don't delete.
3697 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3698 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3699 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3701 for (i=0; i<info->count; i++) {
3702 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3703 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3704 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3708 talloc_free(pinfo2);
3712 /****************************************************************
3713 _spoolss_RouterRefreshPrinterChangeNotify
3714 ****************************************************************/
3716 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3717 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3719 struct spoolss_NotifyInfo *info;
3721 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
3722 WERROR result = WERR_BADFID;
3724 /* we always have a spoolss_NotifyInfo struct */
3725 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3727 result = WERR_NOMEM;
3731 *r->out.info = info;
3734 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3735 "Invalid handle (%s:%u:%u).\n",
3736 OUR_HANDLE(r->in.handle)));
3740 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3743 * We are now using the change value, and
3744 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3745 * I don't have a global notification system, I'm sending back all the
3746 * informations even when _NOTHING_ has changed.
3749 /* We need to keep track of the change value to send back in
3750 RRPCN replies otherwise our updates are ignored. */
3752 Printer->notify.fnpcn = true;
3754 if (Printer->notify.cli_chan != NULL &&
3755 Printer->notify.cli_chan->active_connections > 0) {
3756 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3757 "Saving change value in request [%x]\n",
3759 Printer->notify.change = r->in.change_low;
3762 /* just ignore the spoolss_NotifyOption */
3764 switch (Printer->printer_type) {
3766 result = printserver_notify_info(p, r->in.handle,
3770 case SPLHND_PRINTER:
3771 result = printer_notify_info(p, r->in.handle,
3776 Printer->notify.fnpcn = false;
3782 /********************************************************************
3783 ********************************************************************/
3785 static WERROR create_printername(TALLOC_CTX *mem_ctx,
3786 const char *servername,
3787 const char *printername,
3788 const char **printername_p)
3790 /* FIXME: add lp_force_printername() */
3792 if (servername == NULL) {
3793 *printername_p = talloc_strdup(mem_ctx, printername);
3794 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3798 if (servername[0] == '\\' && servername[1] == '\\') {
3802 *printername_p = talloc_asprintf(mem_ctx, "\\\\%s\\%s", servername, printername);
3803 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3808 /********************************************************************
3809 ********************************************************************/
3811 static void compose_devicemode_devicename(struct spoolss_DeviceMode *dm,
3812 const char *printername)
3818 dm->devicename = talloc_strndup(dm, printername,
3819 MIN(strlen(printername), 31));
3822 /********************************************************************
3823 * construct_printer_info_0
3824 * fill a printer_info_0 struct
3825 ********************************************************************/
3827 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3828 const struct auth_serversupplied_info *session_info,
3829 struct messaging_context *msg_ctx,
3830 struct spoolss_PrinterInfo2 *info2,
3831 const char *servername,
3832 struct spoolss_PrinterInfo0 *r,
3836 struct printer_session_counter *session_counter;
3837 struct timeval setuptime;
3838 print_status_struct status;
3841 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3842 if (!W_ERROR_IS_OK(result)) {
3847 r->servername = talloc_strdup(mem_ctx, servername);
3848 W_ERROR_HAVE_NO_MEMORY(r->servername);
3850 r->servername = NULL;
3853 count = print_queue_length(msg_ctx, snum, &status);
3855 /* check if we already have a counter for this printer */
3856 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3857 if (session_counter->snum == snum)
3861 /* it's the first time, add it to the list */
3862 if (session_counter == NULL) {
3863 session_counter = talloc_zero(counter_list, struct printer_session_counter);
3864 W_ERROR_HAVE_NO_MEMORY(session_counter);
3865 session_counter->snum = snum;
3866 session_counter->counter = 0;
3867 DLIST_ADD(counter_list, session_counter);
3871 session_counter->counter++;
3877 get_startup_time(&setuptime);
3878 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3881 * the global_counter should be stored in a TDB as it's common to all the clients
3882 * and should be zeroed on samba startup
3884 r->global_counter = session_counter->counter;
3886 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3887 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3888 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3889 r->free_build = SPOOLSS_RELEASE_BUILD;
3891 r->max_spooling = 0;
3892 r->session_counter = session_counter->counter;
3893 r->num_error_out_of_paper = 0x0;
3894 r->num_error_not_ready = 0x0; /* number of print failure */
3896 r->number_of_processors = 0x1;
3897 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3898 r->high_part_total_bytes = 0x0;
3900 /* ChangeID in milliseconds*/
3901 winreg_printer_get_changeid(mem_ctx, session_info, msg_ctx,
3902 info2->sharename, &r->change_id);
3904 r->last_error = WERR_OK;
3905 r->status = nt_printq_status(status.status);
3906 r->enumerate_network_printers = 0x0;
3907 r->c_setprinter = 0x0;
3908 r->processor_architecture = PROCESSOR_ARCHITECTURE_INTEL;
3909 r->processor_level = 0x6; /* 6 ???*/
3918 /********************************************************************
3919 * construct_printer_info1
3920 * fill a spoolss_PrinterInfo1 struct
3921 ********************************************************************/
3923 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3924 const struct spoolss_PrinterInfo2 *info2,
3926 const char *servername,
3927 struct spoolss_PrinterInfo1 *r,
3934 if (info2->comment == NULL || info2->comment[0] == '\0') {
3935 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3937 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3939 W_ERROR_HAVE_NO_MEMORY(r->comment);
3941 result = create_printername(mem_ctx, servername, info2->printername, &r->name);
3942 if (!W_ERROR_IS_OK(result)) {
3946 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3950 W_ERROR_HAVE_NO_MEMORY(r->description);
3955 /********************************************************************
3956 * construct_printer_info2
3957 * fill a spoolss_PrinterInfo2 struct
3958 ********************************************************************/
3960 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3961 struct messaging_context *msg_ctx,
3962 const struct spoolss_PrinterInfo2 *info2,
3963 const char *servername,
3964 struct spoolss_PrinterInfo2 *r,
3968 print_status_struct status;
3971 count = print_queue_length(msg_ctx, snum, &status);
3974 r->servername = talloc_strdup(mem_ctx, servername);
3975 W_ERROR_HAVE_NO_MEMORY(r->servername);
3977 r->servername = NULL;
3980 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3981 if (!W_ERROR_IS_OK(result)) {
3985 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3986 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3987 r->portname = talloc_strdup(mem_ctx, info2->portname);
3988 W_ERROR_HAVE_NO_MEMORY(r->portname);
3989 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
3990 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3992 if (info2->comment[0] == '\0') {
3993 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3995 r->comment = talloc_strdup(mem_ctx, info2->comment);
3997 W_ERROR_HAVE_NO_MEMORY(r->comment);
3999 r->location = talloc_strdup(mem_ctx, info2->location);
4000 W_ERROR_HAVE_NO_MEMORY(r->location);
4001 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
4002 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
4003 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
4004 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
4005 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
4006 W_ERROR_HAVE_NO_MEMORY(r->datatype);
4007 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
4008 W_ERROR_HAVE_NO_MEMORY(r->parameters);
4010 r->attributes = info2->attributes;
4012 r->priority = info2->priority;
4013 r->defaultpriority = info2->defaultpriority;
4014 r->starttime = info2->starttime;
4015 r->untiltime = info2->untiltime;
4016 r->status = nt_printq_status(status.status);
4018 r->averageppm = info2->averageppm;
4020 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
4022 DEBUG(8,("Returning NULL Devicemode!\n"));
4025 compose_devicemode_devicename(r->devmode, r->printername);
4029 if (info2->secdesc != NULL) {
4030 /* don't use talloc_steal() here unless you do a deep steal of all
4031 the SEC_DESC members */
4033 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4039 /********************************************************************
4040 * construct_printer_info3
4041 * fill a spoolss_PrinterInfo3 struct
4042 ********************************************************************/
4044 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
4045 const struct spoolss_PrinterInfo2 *info2,
4046 const char *servername,
4047 struct spoolss_PrinterInfo3 *r,
4050 /* These are the components of the SD we are returning. */
4052 if (info2->secdesc != NULL) {
4053 /* don't use talloc_steal() here unless you do a deep steal of all
4054 the SEC_DESC members */
4056 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4057 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
4063 /********************************************************************
4064 * construct_printer_info4
4065 * fill a spoolss_PrinterInfo4 struct
4066 ********************************************************************/
4068 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4069 const struct spoolss_PrinterInfo2 *info2,
4070 const char *servername,
4071 struct spoolss_PrinterInfo4 *r,
4076 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4077 if (!W_ERROR_IS_OK(result)) {
4082 r->servername = talloc_strdup(mem_ctx, servername);
4083 W_ERROR_HAVE_NO_MEMORY(r->servername);
4085 r->servername = NULL;
4088 r->attributes = info2->attributes;
4093 /********************************************************************
4094 * construct_printer_info5
4095 * fill a spoolss_PrinterInfo5 struct
4096 ********************************************************************/
4098 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4099 const struct spoolss_PrinterInfo2 *info2,
4100 const char *servername,
4101 struct spoolss_PrinterInfo5 *r,
4106 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4107 if (!W_ERROR_IS_OK(result)) {
4111 r->portname = talloc_strdup(mem_ctx, info2->portname);
4112 W_ERROR_HAVE_NO_MEMORY(r->portname);
4114 r->attributes = info2->attributes;
4116 /* these two are not used by NT+ according to MSDN */
4117 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4118 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4123 /********************************************************************
4124 * construct_printer_info_6
4125 * fill a spoolss_PrinterInfo6 struct
4126 ********************************************************************/
4128 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4129 struct messaging_context *msg_ctx,
4130 const struct spoolss_PrinterInfo2 *info2,
4131 const char *servername,
4132 struct spoolss_PrinterInfo6 *r,
4136 print_status_struct status;
4138 count = print_queue_length(msg_ctx, snum, &status);
4140 r->status = nt_printq_status(status.status);
4145 /********************************************************************
4146 * construct_printer_info7
4147 * fill a spoolss_PrinterInfo7 struct
4148 ********************************************************************/
4150 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4151 struct messaging_context *msg_ctx,
4152 const char *servername,
4153 struct spoolss_PrinterInfo7 *r,
4156 struct auth_serversupplied_info *session_info;
4160 status = make_session_info_system(mem_ctx, &session_info);
4161 if (!NT_STATUS_IS_OK(status)) {
4162 DEBUG(0, ("construct_printer_info7: "
4163 "Could not create system session_info\n"));
4167 if (is_printer_published(mem_ctx, session_info, msg_ctx,
4169 lp_servicename(snum), &guid, NULL)) {
4170 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4171 r->action = DSPRINT_PUBLISH;
4173 r->guid = talloc_strdup(mem_ctx, "");
4174 r->action = DSPRINT_UNPUBLISH;
4176 W_ERROR_HAVE_NO_MEMORY(r->guid);
4178 TALLOC_FREE(session_info);
4182 /********************************************************************
4183 * construct_printer_info8
4184 * fill a spoolss_PrinterInfo8 struct
4185 ********************************************************************/
4187 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4188 const struct spoolss_PrinterInfo2 *info2,
4189 const char *servername,
4190 struct spoolss_DeviceModeInfo *r,
4194 const char *printername;
4196 result = create_printername(mem_ctx, servername, info2->printername, &printername);
4197 if (!W_ERROR_IS_OK(result)) {
4201 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
4203 DEBUG(8,("Returning NULL Devicemode!\n"));
4206 compose_devicemode_devicename(r->devmode, printername);
4212 /********************************************************************
4213 ********************************************************************/
4215 static bool snum_is_shared_printer(int snum)
4217 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4220 /********************************************************************
4221 Spoolss_enumprinters.
4222 ********************************************************************/
4224 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4225 const struct auth_serversupplied_info *session_info,
4226 struct messaging_context *msg_ctx,
4227 const char *servername,
4230 union spoolss_PrinterInfo **info_p,
4234 int n_services = lp_numservices();
4235 union spoolss_PrinterInfo *info = NULL;
4237 WERROR result = WERR_OK;
4242 for (snum = 0; snum < n_services; snum++) {
4244 const char *printer;
4245 struct spoolss_PrinterInfo2 *info2;
4247 if (!snum_is_shared_printer(snum)) {
4251 printer = lp_const_servicename(snum);
4253 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4256 result = winreg_create_printer(mem_ctx,
4260 if (!W_ERROR_IS_OK(result)) {
4264 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4265 union spoolss_PrinterInfo,
4268 result = WERR_NOMEM;
4272 result = winreg_get_printer(mem_ctx, session_info, msg_ctx,
4274 if (!W_ERROR_IS_OK(result)) {
4280 result = construct_printer_info0(info, session_info,
4283 &info[count].info0, snum);
4286 result = construct_printer_info1(info, info2, flags,
4288 &info[count].info1, snum);
4291 result = construct_printer_info2(info, msg_ctx, info2,
4293 &info[count].info2, snum);
4296 result = construct_printer_info4(info, info2,
4298 &info[count].info4, snum);
4301 result = construct_printer_info5(info, info2,
4303 &info[count].info5, snum);
4307 result = WERR_UNKNOWN_LEVEL;
4311 if (!W_ERROR_IS_OK(result)) {
4322 if (!W_ERROR_IS_OK(result)) {
4332 /********************************************************************
4333 * handle enumeration of printers at level 0
4334 ********************************************************************/
4336 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4337 const struct auth_serversupplied_info *session_info,
4338 struct messaging_context *msg_ctx,
4340 const char *servername,
4341 union spoolss_PrinterInfo **info,
4344 DEBUG(4,("enum_all_printers_info_0\n"));
4346 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4347 servername, 0, flags, info, count);
4351 /********************************************************************
4352 ********************************************************************/
4354 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4355 const struct auth_serversupplied_info *session_info,
4356 struct messaging_context *msg_ctx,
4357 const char *servername,
4359 union spoolss_PrinterInfo **info,
4362 DEBUG(4,("enum_all_printers_info_1\n"));
4364 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4365 servername, 1, flags, info, count);
4368 /********************************************************************
4369 enum_all_printers_info_1_local.
4370 *********************************************************************/
4372 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4373 const struct auth_serversupplied_info *session_info,
4374 struct messaging_context *msg_ctx,
4375 const char *servername,
4376 union spoolss_PrinterInfo **info,
4379 DEBUG(4,("enum_all_printers_info_1_local\n"));
4381 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4382 servername, PRINTER_ENUM_ICON8, info, count);
4385 /********************************************************************
4386 enum_all_printers_info_1_name.
4387 *********************************************************************/
4389 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4390 const struct auth_serversupplied_info *session_info,
4391 struct messaging_context *msg_ctx,
4392 const char *servername,
4393 union spoolss_PrinterInfo **info,
4396 const char *s = servername;
4398 DEBUG(4,("enum_all_printers_info_1_name\n"));
4400 if ((servername[0] == '\\') && (servername[1] == '\\')) {
4404 if (!is_myname_or_ipaddr(s)) {
4405 return WERR_INVALID_NAME;
4408 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4409 servername, PRINTER_ENUM_ICON8, info, count);
4412 /********************************************************************
4413 enum_all_printers_info_1_network.
4414 *********************************************************************/
4416 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4417 const struct auth_serversupplied_info *session_info,
4418 struct messaging_context *msg_ctx,
4419 const char *servername,
4420 union spoolss_PrinterInfo **info,
4423 const char *s = servername;
4425 DEBUG(4,("enum_all_printers_info_1_network\n"));
4427 /* If we respond to a enum_printers level 1 on our name with flags
4428 set to PRINTER_ENUM_REMOTE with a list of printers then these
4429 printers incorrectly appear in the APW browse list.
4430 Specifically the printers for the server appear at the workgroup
4431 level where all the other servers in the domain are
4432 listed. Windows responds to this call with a
4433 WERR_CAN_NOT_COMPLETE so we should do the same. */
4435 if (servername[0] == '\\' && servername[1] == '\\') {
4439 if (is_myname_or_ipaddr(s)) {
4440 return WERR_CAN_NOT_COMPLETE;
4443 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4444 servername, PRINTER_ENUM_NAME, info, count);
4447 /********************************************************************
4448 * api_spoolss_enumprinters
4450 * called from api_spoolss_enumprinters (see this to understand)
4451 ********************************************************************/
4453 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4454 const struct auth_serversupplied_info *session_info,
4455 struct messaging_context *msg_ctx,
4456 const char *servername,
4457 union spoolss_PrinterInfo **info,
4460 DEBUG(4,("enum_all_printers_info_2\n"));
4462 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4463 servername, 2, 0, info, count);
4466 /********************************************************************
4467 * handle enumeration of printers at level 1
4468 ********************************************************************/
4470 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4471 const struct auth_serversupplied_info *session_info,
4472 struct messaging_context *msg_ctx,
4474 const char *servername,
4475 union spoolss_PrinterInfo **info,
4478 /* Not all the flags are equals */
4480 if (flags & PRINTER_ENUM_LOCAL) {
4481 return enum_all_printers_info_1_local(mem_ctx, session_info,
4482 msg_ctx, servername, info, count);
4485 if (flags & PRINTER_ENUM_NAME) {
4486 return enum_all_printers_info_1_name(mem_ctx, session_info,
4487 msg_ctx, servername, info,
4491 if (flags & PRINTER_ENUM_NETWORK) {
4492 return enum_all_printers_info_1_network(mem_ctx, session_info,
4493 msg_ctx, servername, info,
4497 return WERR_OK; /* NT4sp5 does that */
4500 /********************************************************************
4501 * handle enumeration of printers at level 2
4502 ********************************************************************/
4504 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4505 const struct auth_serversupplied_info *session_info,
4506 struct messaging_context *msg_ctx,
4508 const char *servername,
4509 union spoolss_PrinterInfo **info,
4512 if (flags & PRINTER_ENUM_LOCAL) {
4514 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4519 if (flags & PRINTER_ENUM_NAME) {
4520 if (servername && !is_myname_or_ipaddr(canon_servername(servername))) {
4521 return WERR_INVALID_NAME;
4524 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4529 if (flags & PRINTER_ENUM_REMOTE) {
4530 return WERR_UNKNOWN_LEVEL;
4536 /********************************************************************
4537 * handle enumeration of printers at level 4
4538 ********************************************************************/
4540 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4541 const struct auth_serversupplied_info *session_info,
4542 struct messaging_context *msg_ctx,
4544 const char *servername,
4545 union spoolss_PrinterInfo **info,
4548 DEBUG(4,("enum_all_printers_info_4\n"));
4550 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4551 servername, 4, flags, info, count);
4555 /********************************************************************
4556 * handle enumeration of printers at level 5
4557 ********************************************************************/
4559 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4560 const struct auth_serversupplied_info *session_info,
4561 struct messaging_context *msg_ctx,
4563 const char *servername,
4564 union spoolss_PrinterInfo **info,
4567 DEBUG(4,("enum_all_printers_info_5\n"));
4569 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4570 servername, 5, flags, info, count);
4573 /****************************************************************
4574 _spoolss_EnumPrinters
4575 ****************************************************************/
4577 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4578 struct spoolss_EnumPrinters *r)
4580 const struct auth_serversupplied_info *session_info = get_session_info_system();
4583 /* that's an [in out] buffer */
4585 if (!r->in.buffer && (r->in.offered != 0)) {
4586 return WERR_INVALID_PARAM;
4589 DEBUG(4,("_spoolss_EnumPrinters\n"));
4593 *r->out.info = NULL;
4597 * flags==PRINTER_ENUM_NAME
4598 * if name=="" then enumerates all printers
4599 * if name!="" then enumerate the printer
4600 * flags==PRINTER_ENUM_REMOTE
4601 * name is NULL, enumerate printers
4602 * Level 2: name!="" enumerates printers, name can't be NULL
4603 * Level 3: doesn't exist
4604 * Level 4: does a local registry lookup
4605 * Level 5: same as Level 2
4608 if (r->in.server && r->in.server[0] == '\0') {
4609 r->in.server = NULL;
4612 switch (r->in.level) {
4614 result = enumprinters_level0(p->mem_ctx, session_info,
4615 p->msg_ctx, r->in.flags,
4617 r->out.info, r->out.count);
4620 result = enumprinters_level1(p->mem_ctx, session_info,
4621 p->msg_ctx, r->in.flags,
4623 r->out.info, r->out.count);
4626 result = enumprinters_level2(p->mem_ctx, session_info,
4627 p->msg_ctx, r->in.flags,
4629 r->out.info, r->out.count);
4632 result = enumprinters_level4(p->mem_ctx, session_info,
4633 p->msg_ctx, r->in.flags,
4635 r->out.info, r->out.count);
4638 result = enumprinters_level5(p->mem_ctx, session_info,
4639 p->msg_ctx, r->in.flags,
4641 r->out.info, r->out.count);
4644 return WERR_UNKNOWN_LEVEL;
4647 if (!W_ERROR_IS_OK(result)) {
4651 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4652 spoolss_EnumPrinters,
4653 *r->out.info, r->in.level,
4655 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4656 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4658 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4661 /****************************************************************
4663 ****************************************************************/
4665 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4666 struct spoolss_GetPrinter *r)
4668 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
4669 struct spoolss_PrinterInfo2 *info2 = NULL;
4670 WERROR result = WERR_OK;
4673 /* that's an [in out] buffer */
4675 if (!r->in.buffer && (r->in.offered != 0)) {
4676 return WERR_INVALID_PARAM;
4681 if (Printer == NULL) {
4685 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4689 result = winreg_get_printer(p->mem_ctx,
4690 get_session_info_system(),
4692 lp_const_servicename(snum),
4694 if (!W_ERROR_IS_OK(result)) {
4698 switch (r->in.level) {
4700 result = construct_printer_info0(p->mem_ctx,
4701 get_session_info_system(),
4704 Printer->servername,
4705 &r->out.info->info0,
4709 result = construct_printer_info1(p->mem_ctx, info2,
4711 Printer->servername,
4712 &r->out.info->info1, snum);
4715 result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
4716 Printer->servername,
4717 &r->out.info->info2, snum);
4720 result = construct_printer_info3(p->mem_ctx, info2,
4721 Printer->servername,
4722 &r->out.info->info3, snum);
4725 result = construct_printer_info4(p->mem_ctx, info2,
4726 Printer->servername,
4727 &r->out.info->info4, snum);
4730 result = construct_printer_info5(p->mem_ctx, info2,
4731 Printer->servername,
4732 &r->out.info->info5, snum);
4735 result = construct_printer_info6(p->mem_ctx, p->msg_ctx, info2,
4736 Printer->servername,
4737 &r->out.info->info6, snum);
4740 result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
4741 Printer->servername,
4742 &r->out.info->info7, snum);
4745 result = construct_printer_info8(p->mem_ctx, info2,
4746 Printer->servername,
4747 &r->out.info->info8, snum);
4750 result = WERR_UNKNOWN_LEVEL;
4755 if (!W_ERROR_IS_OK(result)) {
4756 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4757 r->in.level, win_errstr(result)));
4758 TALLOC_FREE(r->out.info);
4762 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4763 r->out.info, r->in.level);
4764 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4766 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4769 /********************************************************************
4770 ********************************************************************/
4772 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4774 if (in && strlen(in)) { \
4775 out = talloc_strdup(mem_ctx, in); \
4777 out = talloc_strdup(mem_ctx, ""); \
4779 W_ERROR_HAVE_NO_MEMORY(out); \
4782 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4784 if (in && strlen(in)) { \
4785 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4787 out = talloc_strdup(mem_ctx, ""); \
4789 W_ERROR_HAVE_NO_MEMORY(out); \
4792 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4793 const char **string_array,
4794 const char ***presult,
4795 const char *cservername,
4799 int i, num_strings = 0;
4800 const char **array = NULL;
4802 if (string_array == NULL) {
4803 return WERR_INVALID_PARAMETER;
4806 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4807 const char *str = NULL;
4809 if (cservername == NULL || arch == NULL) {
4810 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4812 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4815 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4822 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4823 &array, &num_strings);
4833 /********************************************************************
4834 * fill a spoolss_DriverInfo1 struct
4835 ********************************************************************/
4837 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4838 struct spoolss_DriverInfo1 *r,
4839 const struct spoolss_DriverInfo8 *driver,
4840 const char *servername)
4842 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4843 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4848 /********************************************************************
4849 * fill a spoolss_DriverInfo2 struct
4850 ********************************************************************/
4852 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4853 struct spoolss_DriverInfo2 *r,
4854 const struct spoolss_DriverInfo8 *driver,
4855 const char *servername)
4858 const char *cservername = canon_servername(servername);
4860 r->version = driver->version;
4862 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4863 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4864 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4865 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4867 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4868 driver->architecture,
4870 driver->driver_path,
4873 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4874 driver->architecture,
4879 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4880 driver->architecture,
4882 driver->config_file,
4888 /********************************************************************
4889 * fill a spoolss_DriverInfo3 struct
4890 ********************************************************************/
4892 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4893 struct spoolss_DriverInfo3 *r,
4894 const struct spoolss_DriverInfo8 *driver,
4895 const char *servername)
4897 const char *cservername = canon_servername(servername);
4899 r->version = driver->version;
4901 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4902 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4903 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4904 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4906 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4907 driver->architecture,
4909 driver->driver_path,
4912 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4913 driver->architecture,
4918 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4919 driver->architecture,
4921 driver->config_file,
4924 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4925 driver->architecture,
4930 FILL_DRIVER_STRING(mem_ctx,
4931 driver->monitor_name,
4934 FILL_DRIVER_STRING(mem_ctx,
4935 driver->default_datatype,
4936 r->default_datatype);
4938 return string_array_from_driver_info(mem_ctx,
4939 driver->dependent_files,
4940 &r->dependent_files,
4942 driver->architecture,
4946 /********************************************************************
4947 * fill a spoolss_DriverInfo4 struct
4948 ********************************************************************/
4950 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4951 struct spoolss_DriverInfo4 *r,
4952 const struct spoolss_DriverInfo8 *driver,
4953 const char *servername)
4955 const char *cservername = canon_servername(servername);
4958 r->version = driver->version;
4960 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4961 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4962 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4963 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4965 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4966 driver->architecture,
4968 driver->driver_path,
4971 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4972 driver->architecture,
4977 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4978 driver->architecture,
4980 driver->config_file,
4983 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4984 driver->architecture,
4989 result = string_array_from_driver_info(mem_ctx,
4990 driver->dependent_files,
4991 &r->dependent_files,
4993 driver->architecture,
4995 if (!W_ERROR_IS_OK(result)) {
4999 FILL_DRIVER_STRING(mem_ctx,
5000 driver->monitor_name,
5003 FILL_DRIVER_STRING(mem_ctx,
5004 driver->default_datatype,
5005 r->default_datatype);
5008 result = string_array_from_driver_info(mem_ctx,
5009 driver->previous_names,
5016 /********************************************************************
5017 * fill a spoolss_DriverInfo5 struct
5018 ********************************************************************/
5020 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
5021 struct spoolss_DriverInfo5 *r,
5022 const struct spoolss_DriverInfo8 *driver,
5023 const char *servername)
5025 const char *cservername = canon_servername(servername);
5027 r->version = driver->version;
5029 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5030 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5031 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5032 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5034 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5035 driver->architecture,
5037 driver->driver_path,
5040 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5041 driver->architecture,
5046 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5047 driver->architecture,
5049 driver->config_file,
5052 r->driver_attributes = 0;
5053 r->config_version = 0;
5054 r->driver_version = 0;
5058 /********************************************************************
5059 * fill a spoolss_DriverInfo6 struct
5060 ********************************************************************/
5062 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
5063 struct spoolss_DriverInfo6 *r,
5064 const struct spoolss_DriverInfo8 *driver,
5065 const char *servername)
5067 const char *cservername = canon_servername(servername);
5070 r->version = driver->version;
5072 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5073 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5074 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5075 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5077 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5078 driver->architecture,
5080 driver->driver_path,
5083 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5084 driver->architecture,
5089 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5090 driver->architecture,
5092 driver->config_file,
5095 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5096 driver->architecture,
5101 FILL_DRIVER_STRING(mem_ctx,
5102 driver->monitor_name,
5105 FILL_DRIVER_STRING(mem_ctx,
5106 driver->default_datatype,
5107 r->default_datatype);
5109 result = string_array_from_driver_info(mem_ctx,
5110 driver->dependent_files,
5111 &r->dependent_files,
5113 driver->architecture,
5115 if (!W_ERROR_IS_OK(result)) {
5119 result = string_array_from_driver_info(mem_ctx,
5120 driver->previous_names,
5123 if (!W_ERROR_IS_OK(result)) {
5127 r->driver_date = driver->driver_date;
5128 r->driver_version = driver->driver_version;
5130 FILL_DRIVER_STRING(mem_ctx,
5131 driver->manufacturer_name,
5132 r->manufacturer_name);
5133 FILL_DRIVER_STRING(mem_ctx,
5134 driver->manufacturer_url,
5135 r->manufacturer_url);
5136 FILL_DRIVER_STRING(mem_ctx,
5137 driver->hardware_id,
5139 FILL_DRIVER_STRING(mem_ctx,
5146 /********************************************************************
5147 * fill a spoolss_DriverInfo8 struct
5148 ********************************************************************/
5150 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
5151 struct spoolss_DriverInfo8 *r,
5152 const struct spoolss_DriverInfo8 *driver,
5153 const char *servername)
5155 const char *cservername = canon_servername(servername);
5158 r->version = driver->version;
5160 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5161 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5162 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5163 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5165 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5166 driver->architecture,
5168 driver->driver_path,
5171 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5172 driver->architecture,
5177 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5178 driver->architecture,
5180 driver->config_file,
5183 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5184 driver->architecture,
5189 FILL_DRIVER_STRING(mem_ctx,
5190 driver->monitor_name,
5193 FILL_DRIVER_STRING(mem_ctx,
5194 driver->default_datatype,
5195 r->default_datatype);
5197 result = string_array_from_driver_info(mem_ctx,
5198 driver->dependent_files,
5199 &r->dependent_files,
5201 driver->architecture,
5203 if (!W_ERROR_IS_OK(result)) {
5207 result = string_array_from_driver_info(mem_ctx,
5208 driver->previous_names,
5211 if (!W_ERROR_IS_OK(result)) {
5215 r->driver_date = driver->driver_date;
5216 r->driver_version = driver->driver_version;
5218 FILL_DRIVER_STRING(mem_ctx,
5219 driver->manufacturer_name,
5220 r->manufacturer_name);
5221 FILL_DRIVER_STRING(mem_ctx,
5222 driver->manufacturer_url,
5223 r->manufacturer_url);
5224 FILL_DRIVER_STRING(mem_ctx,
5225 driver->hardware_id,
5227 FILL_DRIVER_STRING(mem_ctx,
5231 FILL_DRIVER_STRING(mem_ctx,
5232 driver->print_processor,
5233 r->print_processor);
5234 FILL_DRIVER_STRING(mem_ctx,
5235 driver->vendor_setup,
5238 result = string_array_from_driver_info(mem_ctx,
5239 driver->color_profiles,
5242 if (!W_ERROR_IS_OK(result)) {
5246 FILL_DRIVER_STRING(mem_ctx,
5250 r->printer_driver_attributes = driver->printer_driver_attributes;
5252 result = string_array_from_driver_info(mem_ctx,
5253 driver->core_driver_dependencies,
5254 &r->core_driver_dependencies,
5256 if (!W_ERROR_IS_OK(result)) {
5260 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
5261 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
5266 #if 0 /* disabled until marshalling issues are resolved - gd */
5267 /********************************************************************
5268 ********************************************************************/
5270 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5271 struct spoolss_DriverFileInfo *r,
5272 const char *cservername,
5273 const char *file_name,
5274 enum spoolss_DriverFileType file_type,
5275 uint32_t file_version)
5277 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5278 cservername, file_name);
5279 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5280 r->file_type = file_type;
5281 r->file_version = file_version;
5286 /********************************************************************
5287 ********************************************************************/
5289 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5290 const struct spoolss_DriverInfo8 *driver,
5291 const char *cservername,
5292 struct spoolss_DriverFileInfo **info_p,
5295 struct spoolss_DriverFileInfo *info = NULL;
5303 if (strlen(driver->driver_path)) {
5304 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5305 struct spoolss_DriverFileInfo,
5307 W_ERROR_HAVE_NO_MEMORY(info);
5308 result = fill_spoolss_DriverFileInfo(info,
5311 driver->driver_path,
5312 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5314 W_ERROR_NOT_OK_RETURN(result);
5318 if (strlen(driver->config_file)) {
5319 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5320 struct spoolss_DriverFileInfo,
5322 W_ERROR_HAVE_NO_MEMORY(info);
5323 result = fill_spoolss_DriverFileInfo(info,
5326 driver->config_file,
5327 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5329 W_ERROR_NOT_OK_RETURN(result);
5333 if (strlen(driver->data_file)) {
5334 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5335 struct spoolss_DriverFileInfo,
5337 W_ERROR_HAVE_NO_MEMORY(info);
5338 result = fill_spoolss_DriverFileInfo(info,
5342 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5344 W_ERROR_NOT_OK_RETURN(result);
5348 if (strlen(driver->help_file)) {
5349 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5350 struct spoolss_DriverFileInfo,
5352 W_ERROR_HAVE_NO_MEMORY(info);
5353 result = fill_spoolss_DriverFileInfo(info,
5357 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5359 W_ERROR_NOT_OK_RETURN(result);
5363 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
5364 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5365 struct spoolss_DriverFileInfo,
5367 W_ERROR_HAVE_NO_MEMORY(info);
5368 result = fill_spoolss_DriverFileInfo(info,
5371 driver->dependent_files[i],
5372 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5374 W_ERROR_NOT_OK_RETURN(result);
5384 /********************************************************************
5385 * fill a spoolss_DriverInfo101 struct
5386 ********************************************************************/
5388 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5389 struct spoolss_DriverInfo101 *r,
5390 const struct spoolss_DriverInfo8 *driver,
5391 const char *servername)
5393 const char *cservername = canon_servername(servername);
5396 r->version = driver->version;
5398 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5399 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5400 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5401 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5403 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5407 if (!W_ERROR_IS_OK(result)) {
5411 FILL_DRIVER_STRING(mem_ctx,
5412 driver->monitor_name,
5415 FILL_DRIVER_STRING(mem_ctx,
5416 driver->default_datatype,
5417 r->default_datatype);
5419 result = string_array_from_driver_info(mem_ctx,
5420 driver->previous_names,
5423 if (!W_ERROR_IS_OK(result)) {
5427 r->driver_date = driver->driver_date;
5428 r->driver_version = driver->driver_version;
5430 FILL_DRIVER_STRING(mem_ctx,
5431 driver->manufacturer_name,
5432 r->manufacturer_name);
5433 FILL_DRIVER_STRING(mem_ctx,
5434 driver->manufacturer_url,
5435 r->manufacturer_url);
5436 FILL_DRIVER_STRING(mem_ctx,
5437 driver->hardware_id,
5439 FILL_DRIVER_STRING(mem_ctx,
5446 /********************************************************************
5447 ********************************************************************/
5449 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5450 const struct auth_serversupplied_info *session_info,
5451 struct messaging_context *msg_ctx,
5453 union spoolss_DriverInfo *r,
5455 const char *servername,
5456 const char *architecture,
5459 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5460 struct spoolss_DriverInfo8 *driver;
5464 return WERR_UNKNOWN_LEVEL;
5467 result = winreg_get_printer(mem_ctx,
5470 lp_const_servicename(snum),
5473 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5474 win_errstr(result)));
5476 if (!W_ERROR_IS_OK(result)) {
5477 return WERR_INVALID_PRINTER_NAME;
5480 result = winreg_get_driver(mem_ctx, session_info, msg_ctx,
5482 pinfo2->drivername, version, &driver);
5484 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5485 win_errstr(result)));
5487 if (!W_ERROR_IS_OK(result)) {
5489 * Is this a W2k client ?
5493 talloc_free(pinfo2);
5494 return WERR_UNKNOWN_PRINTER_DRIVER;
5497 /* Yes - try again with a WinNT driver. */
5499 result = winreg_get_driver(mem_ctx, session_info, msg_ctx,
5503 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5504 win_errstr(result)));
5505 if (!W_ERROR_IS_OK(result)) {
5506 talloc_free(pinfo2);
5507 return WERR_UNKNOWN_PRINTER_DRIVER;
5513 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5516 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5519 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5522 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5525 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5528 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5531 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5533 #if 0 /* disabled until marshalling issues are resolved - gd */
5535 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5539 result = WERR_UNKNOWN_LEVEL;
5543 talloc_free(pinfo2);
5544 talloc_free(driver);
5549 /****************************************************************
5550 _spoolss_GetPrinterDriver2
5551 ****************************************************************/
5553 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5554 struct spoolss_GetPrinterDriver2 *r)
5556 struct printer_handle *printer;
5561 /* that's an [in out] buffer */
5563 if (!r->in.buffer && (r->in.offered != 0)) {
5564 return WERR_INVALID_PARAM;
5567 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5569 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5570 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5571 return WERR_INVALID_PRINTER_NAME;
5575 *r->out.server_major_version = 0;
5576 *r->out.server_minor_version = 0;
5578 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5582 result = construct_printer_driver_info_level(p->mem_ctx,
5583 get_session_info_system(),
5585 r->in.level, r->out.info,
5586 snum, printer->servername,
5588 r->in.client_major_version);
5589 if (!W_ERROR_IS_OK(result)) {
5590 TALLOC_FREE(r->out.info);
5594 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5595 r->out.info, r->in.level);
5596 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5598 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5602 /****************************************************************
5603 _spoolss_StartPagePrinter
5604 ****************************************************************/
5606 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5607 struct spoolss_StartPagePrinter *r)
5609 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5612 DEBUG(3,("_spoolss_StartPagePrinter: "
5613 "Error in startpageprinter printer handle\n"));
5617 Printer->page_started = true;
5621 /****************************************************************
5622 _spoolss_EndPagePrinter
5623 ****************************************************************/
5625 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5626 struct spoolss_EndPagePrinter *r)
5630 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5633 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5634 OUR_HANDLE(r->in.handle)));
5638 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5641 Printer->page_started = false;
5642 print_job_endpage(p->msg_ctx, snum, Printer->jobid);
5647 /****************************************************************
5648 _spoolss_StartDocPrinter
5649 ****************************************************************/
5651 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5652 struct spoolss_StartDocPrinter *r)
5654 struct spoolss_DocumentInfo1 *info_1;
5656 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5660 DEBUG(2,("_spoolss_StartDocPrinter: "
5661 "Invalid handle (%s:%u:%u)\n",
5662 OUR_HANDLE(r->in.handle)));
5666 if (Printer->jobid) {
5667 DEBUG(2, ("_spoolss_StartDocPrinter: "
5668 "StartDocPrinter called twice! "
5669 "(existing jobid = %d)\n", Printer->jobid));
5670 return WERR_INVALID_HANDLE;
5673 if (r->in.level != 1) {
5674 return WERR_UNKNOWN_LEVEL;
5677 info_1 = r->in.info.info1;
5680 * a nice thing with NT is it doesn't listen to what you tell it.
5681 * when asked to send _only_ RAW datas, it tries to send datas
5684 * So I add checks like in NT Server ...
5687 if (info_1->datatype) {
5688 if (strcmp(info_1->datatype, "RAW") != 0) {
5690 return WERR_INVALID_DATATYPE;
5694 /* get the share number of the printer */
5695 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5699 werr = print_job_start(p->session_info,
5703 info_1->document_name,
5704 info_1->output_file,
5708 /* An error occured in print_job_start() so return an appropriate
5711 if (!W_ERROR_IS_OK(werr)) {
5715 Printer->document_started = true;
5716 *r->out.job_id = Printer->jobid;
5721 /****************************************************************
5722 _spoolss_EndDocPrinter
5723 ****************************************************************/
5725 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5726 struct spoolss_EndDocPrinter *r)
5728 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5733 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5734 OUR_HANDLE(r->in.handle)));
5738 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5742 Printer->document_started = false;
5743 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5744 if (!NT_STATUS_IS_OK(status)) {
5745 DEBUG(2, ("_spoolss_EndDocPrinter: "
5746 "print_job_end failed [%s]\n",
5747 nt_errstr(status)));
5751 return ntstatus_to_werror(status);
5754 /****************************************************************
5755 _spoolss_WritePrinter
5756 ****************************************************************/
5758 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5759 struct spoolss_WritePrinter *r)
5761 ssize_t buffer_written;
5763 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5766 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5767 OUR_HANDLE(r->in.handle)));
5768 *r->out.num_written = r->in._data_size;
5772 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5775 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5776 buffer_written = print_job_write(server_event_context(),p->msg_ctx,
5777 snum, Printer->jobid,
5778 (const char *)r->in.data.data,
5779 (size_t)r->in._data_size);
5780 if (buffer_written == (ssize_t)-1) {
5781 *r->out.num_written = 0;
5782 if (errno == ENOSPC)
5783 return WERR_NO_SPOOL_SPACE;
5785 return WERR_ACCESS_DENIED;
5788 *r->out.num_written = r->in._data_size;
5793 /********************************************************************
5794 * api_spoolss_getprinter
5795 * called from the spoolss dispatcher
5797 ********************************************************************/
5799 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5800 struct pipes_struct *p)
5802 const struct auth_serversupplied_info *session_info = p->session_info;
5804 WERROR errcode = WERR_BADFUNC;
5805 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5808 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5809 OUR_HANDLE(handle)));
5813 if (!get_printer_snum(p, handle, &snum, NULL))
5817 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5818 errcode = print_queue_pause(session_info, p->msg_ctx, snum);
5820 case SPOOLSS_PRINTER_CONTROL_RESUME:
5821 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5822 errcode = print_queue_resume(session_info, p->msg_ctx, snum);
5824 case SPOOLSS_PRINTER_CONTROL_PURGE:
5825 errcode = print_queue_purge(session_info, p->msg_ctx, snum);
5828 return WERR_UNKNOWN_LEVEL;
5835 /****************************************************************
5836 _spoolss_AbortPrinter
5837 * From MSDN: "Deletes printer's spool file if printer is configured
5839 ****************************************************************/
5841 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5842 struct spoolss_AbortPrinter *r)
5844 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5846 WERROR errcode = WERR_OK;
5849 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5850 OUR_HANDLE(r->in.handle)));
5854 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5857 if (!Printer->document_started) {
5858 return WERR_SPL_NO_STARTDOC;
5861 errcode = print_job_delete(p->session_info,
5869 /********************************************************************
5870 * called by spoolss_api_setprinter
5871 * when updating a printer description
5872 ********************************************************************/
5874 static WERROR update_printer_sec(struct policy_handle *handle,
5875 struct pipes_struct *p,
5876 struct sec_desc_buf *secdesc_ctr)
5878 struct spoolss_security_descriptor *new_secdesc = NULL;
5879 struct spoolss_security_descriptor *old_secdesc = NULL;
5880 const char *printer;
5884 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5886 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5887 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5888 OUR_HANDLE(handle)));
5890 result = WERR_BADFID;
5894 if (secdesc_ctr == NULL) {
5895 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5896 result = WERR_INVALID_PARAM;
5899 printer = lp_const_servicename(snum);
5901 /* Check the user has permissions to change the security
5902 descriptor. By experimentation with two NT machines, the user
5903 requires Full Access to the printer to change security
5906 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5907 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5908 result = WERR_ACCESS_DENIED;
5912 /* NT seems to like setting the security descriptor even though
5913 nothing may have actually changed. */
5914 result = winreg_get_printer_secdesc(p->mem_ctx,
5915 get_session_info_system(),
5919 if (!W_ERROR_IS_OK(result)) {
5920 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5921 result = WERR_BADFID;
5925 if (DEBUGLEVEL >= 10) {
5926 struct security_acl *the_acl;
5929 the_acl = old_secdesc->dacl;
5930 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5931 printer, the_acl->num_aces));
5933 for (i = 0; i < the_acl->num_aces; i++) {
5934 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5935 &the_acl->aces[i].trustee),
5936 the_acl->aces[i].access_mask));
5939 the_acl = secdesc_ctr->sd->dacl;
5942 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5943 printer, the_acl->num_aces));
5945 for (i = 0; i < the_acl->num_aces; i++) {
5946 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5947 &the_acl->aces[i].trustee),
5948 the_acl->aces[i].access_mask));
5951 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5955 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
5956 if (new_secdesc == NULL) {
5957 result = WERR_NOMEM;
5961 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
5966 result = winreg_set_printer_secdesc(p->mem_ctx,
5967 get_session_info_system(),
5976 /********************************************************************
5977 Canonicalize printer info from a client
5978 ********************************************************************/
5980 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
5981 struct spoolss_SetPrinterInfo2 *info2,
5984 fstring printername;
5987 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5988 "portname=%s drivername=%s comment=%s location=%s\n",
5989 info2->servername, info2->printername, info2->sharename,
5990 info2->portname, info2->drivername, info2->comment,
5993 /* we force some elements to "correct" values */
5994 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
5995 if (info2->servername == NULL) {
5998 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
5999 if (info2->sharename == NULL) {
6003 /* check to see if we allow printername != sharename */
6004 if (lp_force_printername(snum)) {
6005 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6006 global_myname(), info2->sharename);
6008 /* make sure printername is in \\server\printername format */
6009 fstrcpy(printername, info2->printername);
6011 if ( printername[0] == '\\' && printername[1] == '\\' ) {
6012 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
6016 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6017 global_myname(), p);
6019 if (info2->printername == NULL) {
6023 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
6024 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
6029 /****************************************************************************
6030 ****************************************************************************/
6032 static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const char *portname, const char *uri)
6034 char *cmd = lp_addport_cmd();
6035 char *command = NULL;
6037 bool is_print_op = false;
6040 return WERR_ACCESS_DENIED;
6043 command = talloc_asprintf(ctx,
6044 "%s \"%s\" \"%s\"", cmd, portname, uri );
6050 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6052 DEBUG(10,("Running [%s]\n", command));
6054 /********* BEGIN SePrintOperatorPrivilege **********/
6059 ret = smbrun(command, NULL);
6064 /********* END SePrintOperatorPrivilege **********/
6066 DEBUGADD(10,("returned [%d]\n", ret));
6068 TALLOC_FREE(command);
6071 return WERR_ACCESS_DENIED;
6077 /****************************************************************************
6078 ****************************************************************************/
6080 static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
6081 struct spoolss_SetPrinterInfo2 *info2,
6082 const char *remote_machine,
6083 struct messaging_context *msg_ctx)
6085 char *cmd = lp_addprinter_cmd();
6087 char *command = NULL;
6091 bool is_print_op = false;
6093 if (!remote_machine) {
6097 command = talloc_asprintf(ctx,
6098 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6099 cmd, info2->printername, info2->sharename,
6100 info2->portname, info2->drivername,
6101 info2->location, info2->comment, remote_machine);
6107 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6109 DEBUG(10,("Running [%s]\n", command));
6111 /********* BEGIN SePrintOperatorPrivilege **********/
6116 if ( (ret = smbrun(command, &fd)) == 0 ) {
6117 /* Tell everyone we updated smb.conf. */
6118 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6124 /********* END SePrintOperatorPrivilege **********/
6126 DEBUGADD(10,("returned [%d]\n", ret));
6128 TALLOC_FREE(command);
6136 /* reload our services immediately */
6138 reload_services(msg_ctx, -1, false);
6142 /* Get lines and convert them back to dos-codepage */
6143 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6144 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6147 /* Set the portname to what the script says the portname should be. */
6148 /* but don't require anything to be return from the script exit a good error code */
6151 /* Set the portname to what the script says the portname should be. */
6152 info2->portname = talloc_strdup(ctx, qlines[0]);
6153 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6156 TALLOC_FREE(qlines);
6160 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
6161 const struct auth_serversupplied_info *session_info,
6162 struct messaging_context *msg_ctx,
6164 struct spoolss_SetPrinterInfo2 *printer,
6165 struct spoolss_PrinterInfo2 *old_printer)
6167 bool force_update = (old_printer == NULL);
6168 const char *dnsdomname;
6169 const char *longname;
6170 const char *uncname;
6171 const char *spooling;
6173 WERROR result = WERR_OK;
6175 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
6176 push_reg_sz(mem_ctx, &buffer, printer->drivername);
6177 winreg_set_printer_dataex(mem_ctx,
6181 SPOOL_DSSPOOLER_KEY,
6182 SPOOL_REG_DRIVERNAME,
6187 if (!force_update) {
6188 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6189 printer->drivername));
6191 notify_printer_driver(server_event_context(), msg_ctx,
6192 snum, printer->drivername ?
6193 printer->drivername : "");
6197 if (force_update || !strequal(printer->comment, old_printer->comment)) {
6198 push_reg_sz(mem_ctx, &buffer, printer->comment);
6199 winreg_set_printer_dataex(mem_ctx,
6203 SPOOL_DSSPOOLER_KEY,
6204 SPOOL_REG_DESCRIPTION,
6209 if (!force_update) {
6210 notify_printer_comment(server_event_context(), msg_ctx,
6211 snum, printer->comment ?
6212 printer->comment : "");
6216 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
6217 push_reg_sz(mem_ctx, &buffer, printer->sharename);
6218 winreg_set_printer_dataex(mem_ctx,
6222 SPOOL_DSSPOOLER_KEY,
6223 SPOOL_REG_PRINTSHARENAME,
6228 if (!force_update) {
6229 notify_printer_sharename(server_event_context(),
6231 snum, printer->sharename ?
6232 printer->sharename : "");
6236 if (force_update || !strequal(printer->printername, old_printer->printername)) {
6239 p = strrchr(printer->printername, '\\' );
6243 p = printer->printername;
6246 push_reg_sz(mem_ctx, &buffer, p);
6247 winreg_set_printer_dataex(mem_ctx,
6251 SPOOL_DSSPOOLER_KEY,
6252 SPOOL_REG_PRINTERNAME,
6257 if (!force_update) {
6258 notify_printer_printername(server_event_context(),
6259 msg_ctx, snum, p ? p : "");
6263 if (force_update || !strequal(printer->portname, old_printer->portname)) {
6264 push_reg_sz(mem_ctx, &buffer, printer->portname);
6265 winreg_set_printer_dataex(mem_ctx,
6269 SPOOL_DSSPOOLER_KEY,
6275 if (!force_update) {
6276 notify_printer_port(server_event_context(),
6277 msg_ctx, snum, printer->portname ?
6278 printer->portname : "");
6282 if (force_update || !strequal(printer->location, old_printer->location)) {
6283 push_reg_sz(mem_ctx, &buffer, printer->location);
6284 winreg_set_printer_dataex(mem_ctx,
6288 SPOOL_DSSPOOLER_KEY,
6294 if (!force_update) {
6295 notify_printer_location(server_event_context(),
6298 printer->location : "");
6302 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
6303 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
6304 winreg_set_printer_dataex(mem_ctx,
6308 SPOOL_DSSPOOLER_KEY,
6309 SPOOL_REG_PRINTSEPARATORFILE,
6314 if (!force_update) {
6315 notify_printer_sepfile(server_event_context(),
6318 printer->sepfile : "");
6322 if (force_update || printer->starttime != old_printer->starttime) {
6323 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6324 SIVAL(buffer.data, 0, printer->starttime);
6325 winreg_set_printer_dataex(mem_ctx,
6329 SPOOL_DSSPOOLER_KEY,
6330 SPOOL_REG_PRINTSTARTTIME,
6336 if (force_update || printer->untiltime != old_printer->untiltime) {
6337 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6338 SIVAL(buffer.data, 0, printer->untiltime);
6339 winreg_set_printer_dataex(mem_ctx,
6343 SPOOL_DSSPOOLER_KEY,
6344 SPOOL_REG_PRINTENDTIME,
6350 if (force_update || printer->priority != old_printer->priority) {
6351 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6352 SIVAL(buffer.data, 0, printer->priority);
6353 winreg_set_printer_dataex(mem_ctx,
6357 SPOOL_DSSPOOLER_KEY,
6364 if (force_update || printer->attributes != old_printer->attributes) {
6365 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6366 SIVAL(buffer.data, 0, (printer->attributes &
6367 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
6368 winreg_set_printer_dataex(mem_ctx,
6372 SPOOL_DSSPOOLER_KEY,
6373 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
6378 switch (printer->attributes & 0x3) {
6380 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
6383 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
6386 spooling = SPOOL_REGVAL_PRINTDIRECT;
6389 spooling = "unknown";
6391 push_reg_sz(mem_ctx, &buffer, spooling);
6392 winreg_set_printer_dataex(mem_ctx,
6396 SPOOL_DSSPOOLER_KEY,
6397 SPOOL_REG_PRINTSPOOLING,
6403 push_reg_sz(mem_ctx, &buffer, global_myname());
6404 winreg_set_printer_dataex(mem_ctx,
6408 SPOOL_DSSPOOLER_KEY,
6409 SPOOL_REG_SHORTSERVERNAME,
6414 dnsdomname = get_mydnsfullname();
6415 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
6416 longname = talloc_strdup(mem_ctx, dnsdomname);
6418 longname = talloc_strdup(mem_ctx, global_myname());
6420 if (longname == NULL) {
6421 result = WERR_NOMEM;
6425 push_reg_sz(mem_ctx, &buffer, longname);
6426 winreg_set_printer_dataex(mem_ctx,
6430 SPOOL_DSSPOOLER_KEY,
6431 SPOOL_REG_SERVERNAME,
6436 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6437 global_myname(), printer->sharename);
6438 push_reg_sz(mem_ctx, &buffer, uncname);
6439 winreg_set_printer_dataex(mem_ctx,
6443 SPOOL_DSSPOOLER_KEY,
6453 /********************************************************************
6454 * Called by spoolss_api_setprinter
6455 * when updating a printer description.
6456 ********************************************************************/
6458 static WERROR update_printer(struct pipes_struct *p,
6459 struct policy_handle *handle,
6460 struct spoolss_SetPrinterInfoCtr *info_ctr,
6461 struct spoolss_DeviceMode *devmode)
6463 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6464 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6465 struct spoolss_PrinterInfo2 *old_printer;
6466 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6468 WERROR result = WERR_OK;
6469 TALLOC_CTX *tmp_ctx;
6471 DEBUG(8,("update_printer\n"));
6473 tmp_ctx = talloc_new(p->mem_ctx);
6474 if (tmp_ctx == NULL) {
6479 result = WERR_BADFID;
6483 if (!get_printer_snum(p, handle, &snum, NULL)) {
6484 result = WERR_BADFID;
6488 result = winreg_get_printer(tmp_ctx,
6489 get_session_info_system(),
6491 lp_const_servicename(snum),
6493 if (!W_ERROR_IS_OK(result)) {
6494 result = WERR_BADFID;
6498 /* Do sanity check on the requested changes for Samba */
6499 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6500 result = WERR_INVALID_PARAM;
6504 /* FIXME!!! If the driver has changed we really should verify that
6505 it is installed before doing much else --jerry */
6507 /* Check calling user has permission to update printer description */
6508 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6509 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6510 result = WERR_ACCESS_DENIED;
6514 /* Call addprinter hook */
6515 /* Check changes to see if this is really needed */
6517 if (*lp_addprinter_cmd() &&
6518 (!strequal(printer->drivername, old_printer->drivername) ||
6519 !strequal(printer->comment, old_printer->comment) ||
6520 !strequal(printer->portname, old_printer->portname) ||
6521 !strequal(printer->location, old_printer->location)) )
6523 /* add_printer_hook() will call reload_services() */
6524 if (!add_printer_hook(tmp_ctx, p->session_info->security_token,
6525 printer, p->client_id->addr,
6527 result = WERR_ACCESS_DENIED;
6532 update_dsspooler(tmp_ctx,
6533 get_session_info_system(),
6539 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6541 if (devmode == NULL) {
6542 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6544 result = winreg_update_printer(tmp_ctx,
6545 get_session_info_system(),
6554 talloc_free(tmp_ctx);
6559 /****************************************************************************
6560 ****************************************************************************/
6561 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6562 struct policy_handle *handle,
6563 struct spoolss_SetPrinterInfo7 *info7)
6566 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6569 struct printer_handle *Printer;
6571 if ( lp_security() != SEC_ADS ) {
6572 return WERR_UNKNOWN_LEVEL;
6575 Printer = find_printer_index_by_hnd(p, handle);
6577 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6582 if (!get_printer_snum(p, handle, &snum, NULL))
6585 result = winreg_get_printer(p->mem_ctx,
6586 get_session_info_system(),
6588 lp_servicename(snum),
6590 if (!W_ERROR_IS_OK(result)) {
6594 nt_printer_publish(pinfo2,
6595 get_session_info_system(),
6600 TALLOC_FREE(pinfo2);
6603 return WERR_UNKNOWN_LEVEL;
6607 /********************************************************************
6608 ********************************************************************/
6610 static WERROR update_printer_devmode(struct pipes_struct *p,
6611 struct policy_handle *handle,
6612 struct spoolss_DeviceMode *devmode)
6615 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6616 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6618 DEBUG(8,("update_printer_devmode\n"));
6624 if (!get_printer_snum(p, handle, &snum, NULL)) {
6628 /* Check calling user has permission to update printer description */
6629 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6630 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6631 return WERR_ACCESS_DENIED;
6634 return winreg_update_printer(p->mem_ctx,
6635 get_session_info_system(),
6637 lp_const_servicename(snum),
6645 /****************************************************************
6647 ****************************************************************/
6649 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6650 struct spoolss_SetPrinter *r)
6654 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6657 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6658 OUR_HANDLE(r->in.handle)));
6662 /* check the level */
6663 switch (r->in.info_ctr->level) {
6665 return control_printer(r->in.handle, r->in.command, p);
6667 result = update_printer(p, r->in.handle,
6669 r->in.devmode_ctr->devmode);
6670 if (!W_ERROR_IS_OK(result))
6672 if (r->in.secdesc_ctr->sd)
6673 result = update_printer_sec(r->in.handle, p,
6677 return update_printer_sec(r->in.handle, p,
6680 return publish_or_unpublish_printer(p, r->in.handle,
6681 r->in.info_ctr->info.info7);
6683 return update_printer_devmode(p, r->in.handle,
6684 r->in.devmode_ctr->devmode);
6686 return WERR_UNKNOWN_LEVEL;
6690 /****************************************************************
6691 _spoolss_FindClosePrinterNotify
6692 ****************************************************************/
6694 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6695 struct spoolss_FindClosePrinterNotify *r)
6697 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6700 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6701 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6705 if (Printer->notify.cli_chan != NULL &&
6706 Printer->notify.cli_chan->active_connections > 0) {
6709 if (Printer->printer_type == SPLHND_PRINTER) {
6710 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6715 srv_spoolss_replycloseprinter(snum, Printer);
6718 Printer->notify.flags=0;
6719 Printer->notify.options=0;
6720 Printer->notify.localmachine[0]='\0';
6721 Printer->notify.printerlocal=0;
6722 TALLOC_FREE(Printer->notify.option);
6727 /****************************************************************
6729 ****************************************************************/
6731 WERROR _spoolss_AddJob(struct pipes_struct *p,
6732 struct spoolss_AddJob *r)
6734 if (!r->in.buffer && (r->in.offered != 0)) {
6735 return WERR_INVALID_PARAM;
6738 /* this is what a NT server returns for AddJob. AddJob must fail on
6739 * non-local printers */
6741 if (r->in.level != 1) {
6742 return WERR_UNKNOWN_LEVEL;
6745 return WERR_INVALID_PARAM;
6748 /****************************************************************************
6750 ****************************************************************************/
6752 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6753 struct spoolss_JobInfo1 *r,
6754 const print_queue_struct *queue,
6755 int position, int snum,
6756 struct spoolss_PrinterInfo2 *pinfo2)
6760 t = gmtime(&queue->time);
6762 r->job_id = queue->job;
6764 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6765 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6766 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6767 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6768 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6769 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6770 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6771 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6772 r->data_type = talloc_strdup(mem_ctx, "RAW");
6773 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6774 r->text_status = talloc_strdup(mem_ctx, "");
6775 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6777 r->status = nt_printj_status(queue->status);
6778 r->priority = queue->priority;
6779 r->position = position;
6780 r->total_pages = queue->page_count;
6781 r->pages_printed = 0; /* ??? */
6783 init_systemtime(&r->submitted, t);
6788 /****************************************************************************
6790 ****************************************************************************/
6792 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6793 struct spoolss_JobInfo2 *r,
6794 const print_queue_struct *queue,
6795 int position, int snum,
6796 struct spoolss_PrinterInfo2 *pinfo2,
6797 struct spoolss_DeviceMode *devmode)
6801 t = gmtime(&queue->time);
6803 r->job_id = queue->job;
6805 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6806 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6807 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6808 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6809 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6810 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6811 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6812 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6813 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6814 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6815 r->data_type = talloc_strdup(mem_ctx, "RAW");
6816 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6817 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6818 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6819 r->parameters = talloc_strdup(mem_ctx, "");
6820 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6821 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6822 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6824 r->devmode = devmode;
6826 r->text_status = talloc_strdup(mem_ctx, "");
6827 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6831 r->status = nt_printj_status(queue->status);
6832 r->priority = queue->priority;
6833 r->position = position;
6836 r->total_pages = queue->page_count;
6837 r->size = queue->size;
6838 init_systemtime(&r->submitted, t);
6840 r->pages_printed = 0; /* ??? */
6845 /****************************************************************************
6847 ****************************************************************************/
6849 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6850 struct spoolss_JobInfo3 *r,
6851 const print_queue_struct *queue,
6852 const print_queue_struct *next_queue,
6853 int position, int snum,
6854 struct spoolss_PrinterInfo2 *pinfo2)
6856 r->job_id = queue->job;
6859 r->next_job_id = next_queue->job;
6866 /****************************************************************************
6867 Enumjobs at level 1.
6868 ****************************************************************************/
6870 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6871 const print_queue_struct *queue,
6872 uint32_t num_queues, int snum,
6873 struct spoolss_PrinterInfo2 *pinfo2,
6874 union spoolss_JobInfo **info_p,
6877 union spoolss_JobInfo *info;
6879 WERROR result = WERR_OK;
6881 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6882 W_ERROR_HAVE_NO_MEMORY(info);
6884 *count = num_queues;
6886 for (i=0; i<*count; i++) {
6887 result = fill_job_info1(info,
6893 if (!W_ERROR_IS_OK(result)) {
6899 if (!W_ERROR_IS_OK(result)) {
6910 /****************************************************************************
6911 Enumjobs at level 2.
6912 ****************************************************************************/
6914 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6915 const print_queue_struct *queue,
6916 uint32_t num_queues, int snum,
6917 struct spoolss_PrinterInfo2 *pinfo2,
6918 union spoolss_JobInfo **info_p,
6921 union spoolss_JobInfo *info;
6923 WERROR result = WERR_OK;
6925 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6926 W_ERROR_HAVE_NO_MEMORY(info);
6928 *count = num_queues;
6930 for (i=0; i<*count; i++) {
6931 struct spoolss_DeviceMode *devmode;
6933 result = spoolss_create_default_devmode(info,
6934 pinfo2->printername,
6936 if (!W_ERROR_IS_OK(result)) {
6937 DEBUG(3, ("Can't proceed w/o a devmode!"));
6941 result = fill_job_info2(info,
6948 if (!W_ERROR_IS_OK(result)) {
6954 if (!W_ERROR_IS_OK(result)) {
6965 /****************************************************************************
6966 Enumjobs at level 3.
6967 ****************************************************************************/
6969 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6970 const print_queue_struct *queue,
6971 uint32_t num_queues, int snum,
6972 struct spoolss_PrinterInfo2 *pinfo2,
6973 union spoolss_JobInfo **info_p,
6976 union spoolss_JobInfo *info;
6978 WERROR result = WERR_OK;
6980 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6981 W_ERROR_HAVE_NO_MEMORY(info);
6983 *count = num_queues;
6985 for (i=0; i<*count; i++) {
6986 const print_queue_struct *next_queue = NULL;
6989 next_queue = &queue[i+1];
6992 result = fill_job_info3(info,
6999 if (!W_ERROR_IS_OK(result)) {
7005 if (!W_ERROR_IS_OK(result)) {
7016 /****************************************************************
7018 ****************************************************************/
7020 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
7021 struct spoolss_EnumJobs *r)
7024 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
7026 print_status_struct prt_status;
7027 print_queue_struct *queue = NULL;
7030 /* that's an [in out] buffer */
7032 if (!r->in.buffer && (r->in.offered != 0)) {
7033 return WERR_INVALID_PARAM;
7036 DEBUG(4,("_spoolss_EnumJobs\n"));
7040 *r->out.info = NULL;
7042 /* lookup the printer snum and tdb entry */
7044 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7048 result = winreg_get_printer(p->mem_ctx,
7049 get_session_info_system(),
7051 lp_const_servicename(snum),
7053 if (!W_ERROR_IS_OK(result)) {
7057 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
7058 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7059 count, prt_status.status, prt_status.message));
7063 TALLOC_FREE(pinfo2);
7067 switch (r->in.level) {
7069 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
7070 pinfo2, r->out.info, r->out.count);
7073 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
7074 pinfo2, r->out.info, r->out.count);
7077 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
7078 pinfo2, r->out.info, r->out.count);
7081 result = WERR_UNKNOWN_LEVEL;
7086 TALLOC_FREE(pinfo2);
7088 if (!W_ERROR_IS_OK(result)) {
7092 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7094 *r->out.info, r->in.level,
7096 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7097 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7099 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7102 /****************************************************************
7103 _spoolss_ScheduleJob
7104 ****************************************************************/
7106 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
7107 struct spoolss_ScheduleJob *r)
7112 /****************************************************************
7113 ****************************************************************/
7115 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
7116 struct messaging_context *msg_ctx,
7117 const char *printer_name,
7119 struct spoolss_SetJobInfo1 *r)
7123 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
7127 if (strequal(old_doc_name, r->document_name)) {
7131 if (!print_job_set_name(server_event_context(), msg_ctx,
7132 printer_name, job_id, r->document_name)) {
7139 /****************************************************************
7141 ****************************************************************/
7143 WERROR _spoolss_SetJob(struct pipes_struct *p,
7144 struct spoolss_SetJob *r)
7146 const struct auth_serversupplied_info *session_info = p->session_info;
7148 WERROR errcode = WERR_BADFUNC;
7150 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7154 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
7155 return WERR_INVALID_PRINTER_NAME;
7158 switch (r->in.command) {
7159 case SPOOLSS_JOB_CONTROL_CANCEL:
7160 case SPOOLSS_JOB_CONTROL_DELETE:
7161 errcode = print_job_delete(session_info, p->msg_ctx,
7162 snum, r->in.job_id);
7163 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
7167 case SPOOLSS_JOB_CONTROL_PAUSE:
7168 if (print_job_pause(session_info, p->msg_ctx,
7169 snum, r->in.job_id, &errcode)) {
7173 case SPOOLSS_JOB_CONTROL_RESTART:
7174 case SPOOLSS_JOB_CONTROL_RESUME:
7175 if (print_job_resume(session_info, p->msg_ctx,
7176 snum, r->in.job_id, &errcode)) {
7184 return WERR_UNKNOWN_LEVEL;
7187 if (!W_ERROR_IS_OK(errcode)) {
7191 if (r->in.ctr == NULL) {
7195 switch (r->in.ctr->level) {
7197 errcode = spoolss_setjob_1(p->mem_ctx, p->msg_ctx,
7198 lp_const_servicename(snum),
7200 r->in.ctr->info.info1);
7206 return WERR_UNKNOWN_LEVEL;
7212 /****************************************************************************
7213 Enumerates all printer drivers by level and architecture.
7214 ****************************************************************************/
7216 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
7217 const struct auth_serversupplied_info *session_info,
7218 struct messaging_context *msg_ctx,
7219 const char *servername,
7220 const char *architecture,
7222 union spoolss_DriverInfo **info_p,
7227 struct spoolss_DriverInfo8 *driver;
7228 union spoolss_DriverInfo *info = NULL;
7230 WERROR result = WERR_OK;
7231 uint32_t num_drivers;
7232 const char **drivers;
7237 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7238 result = winreg_get_driver_list(mem_ctx, session_info, msg_ctx,
7239 architecture, version,
7240 &num_drivers, &drivers);
7241 if (!W_ERROR_IS_OK(result)) {
7244 DEBUG(4, ("we have:[%d] drivers in environment"
7245 " [%s] and version [%d]\n",
7246 num_drivers, architecture, version));
7248 if (num_drivers != 0) {
7249 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
7250 union spoolss_DriverInfo,
7251 count + num_drivers);
7253 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7254 "failed to enlarge driver info buffer!\n"));
7255 result = WERR_NOMEM;
7260 for (i = 0; i < num_drivers; i++) {
7261 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
7263 result = winreg_get_driver(mem_ctx, session_info,
7265 architecture, drivers[i],
7267 if (!W_ERROR_IS_OK(result)) {
7273 result = fill_printer_driver_info1(info, &info[count+i].info1,
7274 driver, servername);
7277 result = fill_printer_driver_info2(info, &info[count+i].info2,
7278 driver, servername);
7281 result = fill_printer_driver_info3(info, &info[count+i].info3,
7282 driver, servername);
7285 result = fill_printer_driver_info4(info, &info[count+i].info4,
7286 driver, servername);
7289 result = fill_printer_driver_info5(info, &info[count+i].info5,
7290 driver, servername);
7293 result = fill_printer_driver_info6(info, &info[count+i].info6,
7294 driver, servername);
7297 result = fill_printer_driver_info8(info, &info[count+i].info8,
7298 driver, servername);
7301 result = WERR_UNKNOWN_LEVEL;
7305 TALLOC_FREE(driver);
7307 if (!W_ERROR_IS_OK(result)) {
7312 count += num_drivers;
7313 TALLOC_FREE(drivers);
7317 TALLOC_FREE(drivers);
7319 if (!W_ERROR_IS_OK(result)) {
7330 /****************************************************************************
7331 Enumerates all printer drivers by level.
7332 ****************************************************************************/
7334 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
7335 const struct auth_serversupplied_info *session_info,
7336 struct messaging_context *msg_ctx,
7337 const char *servername,
7338 const char *architecture,
7340 union spoolss_DriverInfo **info_p,
7344 WERROR result = WERR_OK;
7346 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
7348 for (a=0; archi_table[a].long_archi != NULL; a++) {
7350 union spoolss_DriverInfo *info = NULL;
7353 result = enumprinterdrivers_level_by_architecture(mem_ctx,
7357 archi_table[a].long_archi,
7361 if (!W_ERROR_IS_OK(result)) {
7365 for (i=0; i < count; i++) {
7366 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
7367 info[i], info_p, count_p);
7374 return enumprinterdrivers_level_by_architecture(mem_ctx,
7384 /****************************************************************
7385 _spoolss_EnumPrinterDrivers
7386 ****************************************************************/
7388 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
7389 struct spoolss_EnumPrinterDrivers *r)
7391 const char *cservername;
7394 /* that's an [in out] buffer */
7396 if (!r->in.buffer && (r->in.offered != 0)) {
7397 return WERR_INVALID_PARAM;
7400 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7404 *r->out.info = NULL;
7406 cservername = canon_servername(r->in.server);
7408 if (!is_myname_or_ipaddr(cservername)) {
7409 return WERR_UNKNOWN_PRINTER_DRIVER;
7412 result = enumprinterdrivers_level(p->mem_ctx,
7413 get_session_info_system(),
7420 if (!W_ERROR_IS_OK(result)) {
7424 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7425 spoolss_EnumPrinterDrivers,
7426 *r->out.info, r->in.level,
7428 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7429 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7431 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7434 /****************************************************************
7436 ****************************************************************/
7438 WERROR _spoolss_EnumForms(struct pipes_struct *p,
7439 struct spoolss_EnumForms *r)
7445 *r->out.info = NULL;
7447 /* that's an [in out] buffer */
7449 if (!r->in.buffer && (r->in.offered != 0) ) {
7450 return WERR_INVALID_PARAM;
7453 DEBUG(4,("_spoolss_EnumForms\n"));
7454 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7455 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7457 switch (r->in.level) {
7459 result = winreg_printer_enumforms1(p->mem_ctx,
7460 get_session_info_system(),
7466 result = WERR_UNKNOWN_LEVEL;
7470 if (!W_ERROR_IS_OK(result)) {
7474 if (*r->out.count == 0) {
7475 return WERR_NO_MORE_ITEMS;
7478 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7480 *r->out.info, r->in.level,
7482 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7483 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7485 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7488 /****************************************************************
7490 ****************************************************************/
7492 WERROR _spoolss_GetForm(struct pipes_struct *p,
7493 struct spoolss_GetForm *r)
7497 /* that's an [in out] buffer */
7499 if (!r->in.buffer && (r->in.offered != 0)) {
7500 return WERR_INVALID_PARAM;
7503 DEBUG(4,("_spoolss_GetForm\n"));
7504 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7505 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7507 switch (r->in.level) {
7509 result = winreg_printer_getform1(p->mem_ctx,
7510 get_session_info_system(),
7513 &r->out.info->info1);
7516 result = WERR_UNKNOWN_LEVEL;
7520 if (!W_ERROR_IS_OK(result)) {
7521 TALLOC_FREE(r->out.info);
7525 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7526 r->out.info, r->in.level);
7527 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7529 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7532 /****************************************************************************
7533 ****************************************************************************/
7535 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7536 struct spoolss_PortInfo1 *r,
7539 r->port_name = talloc_strdup(mem_ctx, name);
7540 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7545 /****************************************************************************
7546 TODO: This probably needs distinguish between TCP/IP and Local ports
7548 ****************************************************************************/
7550 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7551 struct spoolss_PortInfo2 *r,
7554 r->port_name = talloc_strdup(mem_ctx, name);
7555 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7557 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7558 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7560 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7561 W_ERROR_HAVE_NO_MEMORY(r->description);
7563 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7570 /****************************************************************************
7571 wrapper around the enumer ports command
7572 ****************************************************************************/
7574 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7576 char *cmd = lp_enumports_cmd();
7577 char **qlines = NULL;
7578 char *command = NULL;
7586 /* if no hook then just fill in the default port */
7589 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7592 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7593 TALLOC_FREE(qlines);
7600 /* we have a valid enumport command */
7602 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7607 DEBUG(10,("Running [%s]\n", command));
7608 ret = smbrun(command, &fd);
7609 DEBUG(10,("Returned [%d]\n", ret));
7610 TALLOC_FREE(command);
7615 return WERR_ACCESS_DENIED;
7619 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7620 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7630 /****************************************************************************
7632 ****************************************************************************/
7634 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7635 union spoolss_PortInfo **info_p,
7638 union spoolss_PortInfo *info = NULL;
7640 WERROR result = WERR_OK;
7641 char **qlines = NULL;
7644 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7645 if (!W_ERROR_IS_OK(result)) {
7650 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7652 DEBUG(10,("Returning WERR_NOMEM\n"));
7653 result = WERR_NOMEM;
7657 for (i=0; i<numlines; i++) {
7658 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7659 result = fill_port_1(info, &info[i].info1, qlines[i]);
7660 if (!W_ERROR_IS_OK(result)) {
7665 TALLOC_FREE(qlines);
7668 if (!W_ERROR_IS_OK(result)) {
7670 TALLOC_FREE(qlines);
7682 /****************************************************************************
7684 ****************************************************************************/
7686 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7687 union spoolss_PortInfo **info_p,
7690 union spoolss_PortInfo *info = NULL;
7692 WERROR result = WERR_OK;
7693 char **qlines = NULL;
7696 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7697 if (!W_ERROR_IS_OK(result)) {
7702 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7704 DEBUG(10,("Returning WERR_NOMEM\n"));
7705 result = WERR_NOMEM;
7709 for (i=0; i<numlines; i++) {
7710 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7711 result = fill_port_2(info, &info[i].info2, qlines[i]);
7712 if (!W_ERROR_IS_OK(result)) {
7717 TALLOC_FREE(qlines);
7720 if (!W_ERROR_IS_OK(result)) {
7722 TALLOC_FREE(qlines);
7734 /****************************************************************
7736 ****************************************************************/
7738 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
7739 struct spoolss_EnumPorts *r)
7743 /* that's an [in out] buffer */
7745 if (!r->in.buffer && (r->in.offered != 0)) {
7746 return WERR_INVALID_PARAM;
7749 DEBUG(4,("_spoolss_EnumPorts\n"));
7753 *r->out.info = NULL;
7755 switch (r->in.level) {
7757 result = enumports_level_1(p->mem_ctx, r->out.info,
7761 result = enumports_level_2(p->mem_ctx, r->out.info,
7765 return WERR_UNKNOWN_LEVEL;
7768 if (!W_ERROR_IS_OK(result)) {
7772 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7774 *r->out.info, r->in.level,
7776 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7777 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7779 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7782 /****************************************************************************
7783 ****************************************************************************/
7785 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
7787 struct spoolss_SetPrinterInfoCtr *info_ctr,
7788 struct spoolss_DeviceMode *devmode,
7789 struct security_descriptor *secdesc,
7790 struct spoolss_UserLevelCtr *user_ctr,
7791 struct policy_handle *handle)
7793 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7794 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7796 WERROR err = WERR_OK;
7798 /* samba does not have a concept of local, non-shared printers yet, so
7799 * make sure we always setup sharename - gd */
7800 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7801 (info2->printername != NULL && info2->printername[0] != '\0')) {
7802 DEBUG(5, ("spoolss_addprinterex_level_2: "
7803 "no sharename has been set, setting printername %s as sharename\n",
7804 info2->printername));
7805 info2->sharename = info2->printername;
7808 /* check to see if the printer already exists */
7809 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7810 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7812 return WERR_PRINTER_ALREADY_EXISTS;
7815 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7816 if ((snum = print_queue_snum(info2->printername)) != -1) {
7817 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7818 info2->printername));
7819 return WERR_PRINTER_ALREADY_EXISTS;
7823 /* validate printer info struct */
7824 if (!info2->printername || strlen(info2->printername) == 0) {
7825 return WERR_INVALID_PRINTER_NAME;
7827 if (!info2->portname || strlen(info2->portname) == 0) {
7828 return WERR_UNKNOWN_PORT;
7830 if (!info2->drivername || strlen(info2->drivername) == 0) {
7831 return WERR_UNKNOWN_PRINTER_DRIVER;
7833 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7834 return WERR_UNKNOWN_PRINTPROCESSOR;
7837 /* FIXME!!! smbd should check to see if the driver is installed before
7838 trying to add a printer like this --jerry */
7840 if (*lp_addprinter_cmd() ) {
7841 if ( !add_printer_hook(p->mem_ctx, p->session_info->security_token,
7842 info2, p->client_id->addr,
7844 return WERR_ACCESS_DENIED;
7847 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7848 "smb.conf parameter \"addprinter command\" is defined. This"
7849 "parameter must exist for this call to succeed\n",
7850 info2->sharename ));
7853 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7854 return WERR_ACCESS_DENIED;
7857 /* you must be a printer admin to add a new printer */
7858 if (!print_access_check(p->session_info,
7861 PRINTER_ACCESS_ADMINISTER)) {
7862 return WERR_ACCESS_DENIED;
7866 * Do sanity check on the requested changes for Samba.
7869 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7870 return WERR_INVALID_PARAM;
7873 if (devmode == NULL) {
7874 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7877 update_dsspooler(p->mem_ctx,
7878 get_session_info_system(),
7884 err = winreg_update_printer(p->mem_ctx,
7885 get_session_info_system(),
7892 if (!W_ERROR_IS_OK(err)) {
7896 err = open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER);
7897 if (!W_ERROR_IS_OK(err)) {
7898 /* Handle open failed - remove addition. */
7899 ZERO_STRUCTP(handle);
7906 /****************************************************************
7907 _spoolss_AddPrinterEx
7908 ****************************************************************/
7910 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
7911 struct spoolss_AddPrinterEx *r)
7913 switch (r->in.info_ctr->level) {
7915 /* we don't handle yet */
7916 /* but I know what to do ... */
7917 return WERR_UNKNOWN_LEVEL;
7919 return spoolss_addprinterex_level_2(p, r->in.server,
7921 r->in.devmode_ctr->devmode,
7922 r->in.secdesc_ctr->sd,
7923 r->in.userlevel_ctr,
7926 return WERR_UNKNOWN_LEVEL;
7930 /****************************************************************
7932 ****************************************************************/
7934 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
7935 struct spoolss_AddPrinter *r)
7937 struct spoolss_AddPrinterEx a;
7938 struct spoolss_UserLevelCtr userlevel_ctr;
7940 ZERO_STRUCT(userlevel_ctr);
7942 userlevel_ctr.level = 1;
7944 a.in.server = r->in.server;
7945 a.in.info_ctr = r->in.info_ctr;
7946 a.in.devmode_ctr = r->in.devmode_ctr;
7947 a.in.secdesc_ctr = r->in.secdesc_ctr;
7948 a.in.userlevel_ctr = &userlevel_ctr;
7949 a.out.handle = r->out.handle;
7951 return _spoolss_AddPrinterEx(p, &a);
7954 /****************************************************************
7955 _spoolss_AddPrinterDriverEx
7956 ****************************************************************/
7958 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
7959 struct spoolss_AddPrinterDriverEx *r)
7961 WERROR err = WERR_OK;
7962 const char *driver_name = NULL;
7967 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7968 fn = "_spoolss_AddPrinterDriver";
7970 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7971 fn = "_spoolss_AddPrinterDriverEx";
7974 return WERR_INVALID_PARAM;
7978 * we only support the semantics of AddPrinterDriver()
7979 * i.e. only copy files that are newer than existing ones
7982 if (r->in.flags == 0) {
7983 return WERR_INVALID_PARAM;
7986 if (r->in.flags != APD_COPY_NEW_FILES) {
7987 return WERR_ACCESS_DENIED;
7991 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7992 /* Clever hack from Martin Zielinski <mz@seh.de>
7993 * to allow downgrade from level 8 (Vista).
7995 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7996 r->in.info_ctr->level));
7997 return WERR_UNKNOWN_LEVEL;
8000 DEBUG(5,("Cleaning driver's information\n"));
8001 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
8002 if (!W_ERROR_IS_OK(err))
8005 DEBUG(5,("Moving driver to final destination\n"));
8006 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
8011 err = winreg_add_driver(p->mem_ctx,
8012 get_session_info_system(),
8017 if (!W_ERROR_IS_OK(err)) {
8022 * I think this is where he DrvUpgradePrinter() hook would be
8023 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8024 * server. Right now, we just need to send ourselves a message
8025 * to update each printer bound to this driver. --jerry
8028 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
8029 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8037 /****************************************************************
8038 _spoolss_AddPrinterDriver
8039 ****************************************************************/
8041 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
8042 struct spoolss_AddPrinterDriver *r)
8044 struct spoolss_AddPrinterDriverEx a;
8046 switch (r->in.info_ctr->level) {
8053 return WERR_UNKNOWN_LEVEL;
8056 a.in.servername = r->in.servername;
8057 a.in.info_ctr = r->in.info_ctr;
8058 a.in.flags = APD_COPY_NEW_FILES;
8060 return _spoolss_AddPrinterDriverEx(p, &a);
8063 /****************************************************************************
8064 ****************************************************************************/
8066 struct _spoolss_paths {
8072 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
8074 static const struct _spoolss_paths spoolss_paths[]= {
8075 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
8076 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
8079 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
8080 const char *servername,
8081 const char *environment,
8085 const char *pservername = NULL;
8086 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
8087 const char *short_archi;
8091 /* environment may be empty */
8092 if (environment && strlen(environment)) {
8093 long_archi = environment;
8096 /* servername may be empty */
8097 if (servername && strlen(servername)) {
8098 pservername = canon_servername(servername);
8100 if (!is_myname_or_ipaddr(pservername)) {
8101 return WERR_INVALID_PARAM;
8105 if (!(short_archi = get_short_archi(long_archi))) {
8106 return WERR_INVALID_ENVIRONMENT;
8109 switch (component) {
8110 case SPOOLSS_PRTPROCS_PATH:
8111 case SPOOLSS_DRIVER_PATH:
8113 *path = talloc_asprintf(mem_ctx,
8116 spoolss_paths[component].share,
8119 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
8120 SPOOLSS_DEFAULT_SERVER_PATH,
8121 spoolss_paths[component].dir,
8126 return WERR_INVALID_PARAM;
8136 /****************************************************************************
8137 ****************************************************************************/
8139 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
8140 const char *servername,
8141 const char *environment,
8142 struct spoolss_DriverDirectoryInfo1 *r)
8147 werr = compose_spoolss_server_path(mem_ctx,
8150 SPOOLSS_DRIVER_PATH,
8152 if (!W_ERROR_IS_OK(werr)) {
8156 DEBUG(4,("printer driver directory: [%s]\n", path));
8158 r->directory_name = path;
8163 /****************************************************************
8164 _spoolss_GetPrinterDriverDirectory
8165 ****************************************************************/
8167 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
8168 struct spoolss_GetPrinterDriverDirectory *r)
8172 /* that's an [in out] buffer */
8174 if (!r->in.buffer && (r->in.offered != 0)) {
8175 return WERR_INVALID_PARAM;
8178 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8183 /* r->in.level is ignored */
8185 werror = getprinterdriverdir_level_1(p->mem_ctx,
8188 &r->out.info->info1);
8189 if (!W_ERROR_IS_OK(werror)) {
8190 TALLOC_FREE(r->out.info);
8194 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
8195 r->out.info, r->in.level);
8196 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8198 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8201 /****************************************************************
8202 _spoolss_EnumPrinterData
8203 ****************************************************************/
8205 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
8206 struct spoolss_EnumPrinterData *r)
8209 struct spoolss_EnumPrinterDataEx r2;
8211 struct spoolss_PrinterEnumValues *info, *val = NULL;
8214 r2.in.handle = r->in.handle;
8215 r2.in.key_name = "PrinterDriverData";
8217 r2.out.count = &count;
8218 r2.out.info = &info;
8219 r2.out.needed = &needed;
8221 result = _spoolss_EnumPrinterDataEx(p, &r2);
8222 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8223 r2.in.offered = needed;
8224 result = _spoolss_EnumPrinterDataEx(p, &r2);
8226 if (!W_ERROR_IS_OK(result)) {
8231 * The NT machine wants to know the biggest size of value and data
8233 * cf: MSDN EnumPrinterData remark section
8236 if (!r->in.value_offered && !r->in.data_offered) {
8237 uint32_t biggest_valuesize = 0;
8238 uint32_t biggest_datasize = 0;
8241 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8243 for (i=0; i<count; i++) {
8245 name_length = strlen(info[i].value_name);
8246 if (strlen(info[i].value_name) > biggest_valuesize) {
8247 biggest_valuesize = name_length;
8250 if (info[i].data_length > biggest_datasize) {
8251 biggest_datasize = info[i].data_length;
8254 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8258 /* the value is an UNICODE string but real_value_size is the length
8259 in bytes including the trailing 0 */
8261 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8262 *r->out.data_needed = biggest_datasize;
8264 DEBUG(6,("final values: [%d], [%d]\n",
8265 *r->out.value_needed, *r->out.data_needed));
8270 if (r->in.enum_index < count) {
8271 val = &info[r->in.enum_index];
8275 /* out_value should default to "" or else NT4 has
8276 problems unmarshalling the response */
8278 if (r->in.value_offered) {
8279 *r->out.value_needed = 1;
8280 r->out.value_name = talloc_strdup(r, "");
8281 if (!r->out.value_name) {
8285 r->out.value_name = NULL;
8286 *r->out.value_needed = 0;
8289 /* the data is counted in bytes */
8291 *r->out.data_needed = r->in.data_offered;
8293 result = WERR_NO_MORE_ITEMS;
8297 * - counted in bytes in the request
8298 * - counted in UNICODE chars in the max reply
8299 * - counted in bytes in the real size
8301 * take a pause *before* coding not *during* coding
8305 if (r->in.value_offered) {
8306 r->out.value_name = talloc_strdup(r, val->value_name);
8307 if (!r->out.value_name) {
8310 *r->out.value_needed = val->value_name_len;
8312 r->out.value_name = NULL;
8313 *r->out.value_needed = 0;
8318 *r->out.type = val->type;
8320 /* data - counted in bytes */
8323 * See the section "Dynamically Typed Query Parameters"
8327 if (r->out.data && val->data && val->data->data &&
8328 val->data_length && r->in.data_offered) {
8329 memcpy(r->out.data, val->data->data,
8330 MIN(val->data_length,r->in.data_offered));
8333 *r->out.data_needed = val->data_length;
8341 /****************************************************************
8342 _spoolss_SetPrinterData
8343 ****************************************************************/
8345 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
8346 struct spoolss_SetPrinterData *r)
8348 struct spoolss_SetPrinterDataEx r2;
8350 r2.in.handle = r->in.handle;
8351 r2.in.key_name = "PrinterDriverData";
8352 r2.in.value_name = r->in.value_name;
8353 r2.in.type = r->in.type;
8354 r2.in.data = r->in.data;
8355 r2.in.offered = r->in.offered;
8357 return _spoolss_SetPrinterDataEx(p, &r2);
8360 /****************************************************************
8361 _spoolss_ResetPrinter
8362 ****************************************************************/
8364 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
8365 struct spoolss_ResetPrinter *r)
8367 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8370 DEBUG(5,("_spoolss_ResetPrinter\n"));
8373 * All we do is to check to see if the handle and queue is valid.
8374 * This call really doesn't mean anything to us because we only
8375 * support RAW printing. --jerry
8379 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8380 OUR_HANDLE(r->in.handle)));
8384 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8388 /* blindly return success */
8392 /****************************************************************
8393 _spoolss_DeletePrinterData
8394 ****************************************************************/
8396 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
8397 struct spoolss_DeletePrinterData *r)
8399 struct spoolss_DeletePrinterDataEx r2;
8401 r2.in.handle = r->in.handle;
8402 r2.in.key_name = "PrinterDriverData";
8403 r2.in.value_name = r->in.value_name;
8405 return _spoolss_DeletePrinterDataEx(p, &r2);
8408 /****************************************************************
8410 ****************************************************************/
8412 WERROR _spoolss_AddForm(struct pipes_struct *p,
8413 struct spoolss_AddForm *r)
8415 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8417 WERROR status = WERR_OK;
8419 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8421 DEBUG(5,("_spoolss_AddForm\n"));
8424 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8425 OUR_HANDLE(r->in.handle)));
8429 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8430 and not a printer admin, then fail */
8432 if ((p->session_info->utok.uid != sec_initial_uid()) &&
8433 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
8434 !token_contains_name_in_list(uidtoname(p->session_info->utok.uid),
8435 p->session_info->info3->base.domain.string,
8437 p->session_info->security_token,
8438 lp_printer_admin(snum))) {
8439 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8440 return WERR_ACCESS_DENIED;
8443 switch (form->flags) {
8444 case SPOOLSS_FORM_USER:
8445 case SPOOLSS_FORM_BUILTIN:
8446 case SPOOLSS_FORM_PRINTER:
8449 return WERR_INVALID_PARAM;
8452 status = winreg_printer_addform1(p->mem_ctx,
8453 get_session_info_system(),
8456 if (!W_ERROR_IS_OK(status)) {
8461 * ChangeID must always be set if this is a printer
8463 if (Printer->printer_type == SPLHND_PRINTER) {
8464 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8468 status = winreg_printer_update_changeid(p->mem_ctx,
8469 get_session_info_system(),
8471 lp_const_servicename(snum));
8472 if (!W_ERROR_IS_OK(status)) {
8480 /****************************************************************
8482 ****************************************************************/
8484 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8485 struct spoolss_DeleteForm *r)
8487 const char *form_name = r->in.form_name;
8488 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8490 WERROR status = WERR_OK;
8492 DEBUG(5,("_spoolss_DeleteForm\n"));
8495 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8496 OUR_HANDLE(r->in.handle)));
8500 if ((p->session_info->utok.uid != sec_initial_uid()) &&
8501 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
8502 !token_contains_name_in_list(uidtoname(p->session_info->utok.uid),
8503 p->session_info->info3->base.domain.string,
8505 p->session_info->security_token,
8506 lp_printer_admin(snum))) {
8507 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8508 return WERR_ACCESS_DENIED;
8511 status = winreg_printer_deleteform1(p->mem_ctx,
8512 get_session_info_system(),
8515 if (!W_ERROR_IS_OK(status)) {
8520 * ChangeID must always be set if this is a printer
8522 if (Printer->printer_type == SPLHND_PRINTER) {
8523 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8527 status = winreg_printer_update_changeid(p->mem_ctx,
8528 get_session_info_system(),
8530 lp_const_servicename(snum));
8531 if (!W_ERROR_IS_OK(status)) {
8539 /****************************************************************
8541 ****************************************************************/
8543 WERROR _spoolss_SetForm(struct pipes_struct *p,
8544 struct spoolss_SetForm *r)
8546 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8547 const char *form_name = r->in.form_name;
8549 WERROR status = WERR_OK;
8551 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8553 DEBUG(5,("_spoolss_SetForm\n"));
8556 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8557 OUR_HANDLE(r->in.handle)));
8561 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8562 and not a printer admin, then fail */
8564 if ((p->session_info->utok.uid != sec_initial_uid()) &&
8565 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
8566 !token_contains_name_in_list(uidtoname(p->session_info->utok.uid),
8567 p->session_info->info3->base.domain.string,
8569 p->session_info->security_token,
8570 lp_printer_admin(snum))) {
8571 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8572 return WERR_ACCESS_DENIED;
8575 status = winreg_printer_setform1(p->mem_ctx,
8576 get_session_info_system(),
8580 if (!W_ERROR_IS_OK(status)) {
8585 * ChangeID must always be set if this is a printer
8587 if (Printer->printer_type == SPLHND_PRINTER) {
8588 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8592 status = winreg_printer_update_changeid(p->mem_ctx,
8593 get_session_info_system(),
8595 lp_const_servicename(snum));
8596 if (!W_ERROR_IS_OK(status)) {
8604 /****************************************************************************
8605 fill_print_processor1
8606 ****************************************************************************/
8608 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8609 struct spoolss_PrintProcessorInfo1 *r,
8610 const char *print_processor_name)
8612 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8613 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8618 /****************************************************************************
8619 enumprintprocessors level 1.
8620 ****************************************************************************/
8622 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8623 union spoolss_PrintProcessorInfo **info_p,
8626 union spoolss_PrintProcessorInfo *info;
8629 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8630 W_ERROR_HAVE_NO_MEMORY(info);
8634 result = fill_print_processor1(info, &info[0].info1, "winprint");
8635 if (!W_ERROR_IS_OK(result)) {
8640 if (!W_ERROR_IS_OK(result)) {
8651 /****************************************************************
8652 _spoolss_EnumPrintProcessors
8653 ****************************************************************/
8655 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8656 struct spoolss_EnumPrintProcessors *r)
8660 /* that's an [in out] buffer */
8662 if (!r->in.buffer && (r->in.offered != 0)) {
8663 return WERR_INVALID_PARAM;
8666 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8669 * Enumerate the print processors ...
8671 * Just reply with "winprint", to keep NT happy
8672 * and I can use my nice printer checker.
8677 *r->out.info = NULL;
8679 if (!get_short_archi(r->in.environment)) {
8680 return WERR_INVALID_ENVIRONMENT;
8683 switch (r->in.level) {
8685 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8689 return WERR_UNKNOWN_LEVEL;
8692 if (!W_ERROR_IS_OK(result)) {
8696 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8697 spoolss_EnumPrintProcessors,
8698 *r->out.info, r->in.level,
8700 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8701 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8703 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8706 /****************************************************************************
8707 fill_printprocdatatype1
8708 ****************************************************************************/
8710 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8711 struct spoolss_PrintProcDataTypesInfo1 *r,
8712 const char *name_array)
8714 r->name_array = talloc_strdup(mem_ctx, name_array);
8715 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8720 /****************************************************************************
8721 enumprintprocdatatypes level 1.
8722 ****************************************************************************/
8724 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8725 union spoolss_PrintProcDataTypesInfo **info_p,
8729 union spoolss_PrintProcDataTypesInfo *info;
8731 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8732 W_ERROR_HAVE_NO_MEMORY(info);
8736 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8737 if (!W_ERROR_IS_OK(result)) {
8742 if (!W_ERROR_IS_OK(result)) {
8753 /****************************************************************
8754 _spoolss_EnumPrintProcDataTypes
8755 ****************************************************************/
8757 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
8758 struct spoolss_EnumPrintProcDataTypes *r)
8762 /* that's an [in out] buffer */
8764 if (!r->in.buffer && (r->in.offered != 0)) {
8765 return WERR_INVALID_PARAM;
8768 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8772 *r->out.info = NULL;
8774 if (r->in.print_processor_name == NULL ||
8775 !strequal(r->in.print_processor_name, "winprint")) {
8776 return WERR_UNKNOWN_PRINTPROCESSOR;
8779 switch (r->in.level) {
8781 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8785 return WERR_UNKNOWN_LEVEL;
8788 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8789 spoolss_EnumPrintProcDataTypes,
8790 *r->out.info, r->in.level,
8792 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8793 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8795 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8798 /****************************************************************************
8800 ****************************************************************************/
8802 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8803 struct spoolss_MonitorInfo1 *r,
8804 const char *monitor_name)
8806 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8807 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8812 /****************************************************************************
8814 ****************************************************************************/
8816 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8817 struct spoolss_MonitorInfo2 *r,
8818 const char *monitor_name,
8819 const char *environment,
8820 const char *dll_name)
8822 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8823 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8824 r->environment = talloc_strdup(mem_ctx, environment);
8825 W_ERROR_HAVE_NO_MEMORY(r->environment);
8826 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8827 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8832 /****************************************************************************
8833 enumprintmonitors level 1.
8834 ****************************************************************************/
8836 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8837 union spoolss_MonitorInfo **info_p,
8840 union spoolss_MonitorInfo *info;
8841 WERROR result = WERR_OK;
8843 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8844 W_ERROR_HAVE_NO_MEMORY(info);
8848 result = fill_monitor_1(info, &info[0].info1,
8850 if (!W_ERROR_IS_OK(result)) {
8854 result = fill_monitor_1(info, &info[1].info1,
8856 if (!W_ERROR_IS_OK(result)) {
8861 if (!W_ERROR_IS_OK(result)) {
8872 /****************************************************************************
8873 enumprintmonitors level 2.
8874 ****************************************************************************/
8876 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8877 union spoolss_MonitorInfo **info_p,
8880 union spoolss_MonitorInfo *info;
8881 WERROR result = WERR_OK;
8883 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8884 W_ERROR_HAVE_NO_MEMORY(info);
8888 result = fill_monitor_2(info, &info[0].info2,
8890 "Windows NT X86", /* FIXME */
8892 if (!W_ERROR_IS_OK(result)) {
8896 result = fill_monitor_2(info, &info[1].info2,
8898 "Windows NT X86", /* FIXME */
8900 if (!W_ERROR_IS_OK(result)) {
8905 if (!W_ERROR_IS_OK(result)) {
8916 /****************************************************************
8917 _spoolss_EnumMonitors
8918 ****************************************************************/
8920 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
8921 struct spoolss_EnumMonitors *r)
8925 /* that's an [in out] buffer */
8927 if (!r->in.buffer && (r->in.offered != 0)) {
8928 return WERR_INVALID_PARAM;
8931 DEBUG(5,("_spoolss_EnumMonitors\n"));
8934 * Enumerate the print monitors ...
8936 * Just reply with "Local Port", to keep NT happy
8937 * and I can use my nice printer checker.
8942 *r->out.info = NULL;
8944 switch (r->in.level) {
8946 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8950 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8954 return WERR_UNKNOWN_LEVEL;
8957 if (!W_ERROR_IS_OK(result)) {
8961 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8962 spoolss_EnumMonitors,
8963 *r->out.info, r->in.level,
8965 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8966 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8968 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8971 /****************************************************************************
8972 ****************************************************************************/
8974 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8975 const print_queue_struct *queue,
8976 int count, int snum,
8977 struct spoolss_PrinterInfo2 *pinfo2,
8979 struct spoolss_JobInfo1 *r)
8984 for (i=0; i<count; i++) {
8985 if (queue[i].job == (int)jobid) {
8991 if (found == false) {
8992 /* NT treats not found as bad param... yet another bad choice */
8993 return WERR_INVALID_PARAM;
8996 return fill_job_info1(mem_ctx,
9004 /****************************************************************************
9005 ****************************************************************************/
9007 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
9008 const print_queue_struct *queue,
9009 int count, int snum,
9010 struct spoolss_PrinterInfo2 *pinfo2,
9012 struct spoolss_JobInfo2 *r)
9016 struct spoolss_DeviceMode *devmode;
9019 for (i=0; i<count; i++) {
9020 if (queue[i].job == (int)jobid) {
9026 if (found == false) {
9027 /* NT treats not found as bad param... yet another bad
9029 return WERR_INVALID_PARAM;
9033 * if the print job does not have a DEVMODE associated with it,
9034 * just use the one for the printer. A NULL devicemode is not
9035 * a failure condition
9038 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
9040 result = spoolss_create_default_devmode(mem_ctx,
9041 pinfo2->printername,
9043 if (!W_ERROR_IS_OK(result)) {
9044 DEBUG(3, ("Can't proceed w/o a devmode!"));
9049 return fill_job_info2(mem_ctx,
9058 /****************************************************************
9060 ****************************************************************/
9062 WERROR _spoolss_GetJob(struct pipes_struct *p,
9063 struct spoolss_GetJob *r)
9065 WERROR result = WERR_OK;
9066 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9069 print_queue_struct *queue = NULL;
9070 print_status_struct prt_status;
9072 /* that's an [in out] buffer */
9074 if (!r->in.buffer && (r->in.offered != 0)) {
9075 return WERR_INVALID_PARAM;
9078 DEBUG(5,("_spoolss_GetJob\n"));
9082 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9086 result = winreg_get_printer(p->mem_ctx,
9087 get_session_info_system(),
9089 lp_const_servicename(snum),
9091 if (!W_ERROR_IS_OK(result)) {
9095 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
9097 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9098 count, prt_status.status, prt_status.message));
9100 switch (r->in.level) {
9102 result = getjob_level_1(p->mem_ctx,
9103 queue, count, snum, pinfo2,
9104 r->in.job_id, &r->out.info->info1);
9107 result = getjob_level_2(p->mem_ctx,
9108 queue, count, snum, pinfo2,
9109 r->in.job_id, &r->out.info->info2);
9112 result = WERR_UNKNOWN_LEVEL;
9117 TALLOC_FREE(pinfo2);
9119 if (!W_ERROR_IS_OK(result)) {
9120 TALLOC_FREE(r->out.info);
9124 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
9126 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9128 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9131 /****************************************************************
9132 _spoolss_GetPrinterDataEx
9133 ****************************************************************/
9135 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
9136 struct spoolss_GetPrinterDataEx *r)
9139 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9140 const char *printer;
9142 WERROR result = WERR_OK;
9144 enum winreg_Type val_type;
9149 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9151 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9152 r->in.key_name, r->in.value_name));
9154 /* in case of problem, return some default values */
9157 *r->out.type = REG_NONE;
9160 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9161 OUR_HANDLE(r->in.handle)));
9162 result = WERR_BADFID;
9166 /* Is the handle to a printer or to the server? */
9168 if (Printer->printer_type == SPLHND_SERVER) {
9170 union spoolss_PrinterData data;
9172 result = getprinterdata_printer_server(p->mem_ctx,
9176 if (!W_ERROR_IS_OK(result)) {
9180 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
9181 *r->out.type, &data);
9182 if (!W_ERROR_IS_OK(result)) {
9186 *r->out.needed = blob.length;
9188 if (r->in.offered >= *r->out.needed) {
9189 memcpy(r->out.data, blob.data, blob.length);
9192 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9195 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9198 printer = lp_const_servicename(snum);
9200 /* check to see if the keyname is valid */
9201 if (!strlen(r->in.key_name)) {
9202 return WERR_INVALID_PARAM;
9205 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9206 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
9207 strequal(r->in.value_name, "ChangeId")) {
9208 *r->out.type = REG_DWORD;
9210 if (r->in.offered >= *r->out.needed) {
9211 uint32_t changeid = 0;
9213 result = winreg_printer_get_changeid(p->mem_ctx,
9214 get_session_info_system(),
9218 if (!W_ERROR_IS_OK(result)) {
9222 SIVAL(r->out.data, 0, changeid);
9228 result = winreg_get_printer_dataex(p->mem_ctx,
9229 get_session_info_system(),
9237 if (!W_ERROR_IS_OK(result)) {
9241 *r->out.needed = val_size;
9242 *r->out.type = val_type;
9244 if (r->in.offered >= *r->out.needed) {
9245 memcpy(r->out.data, val_data, val_size);
9249 /* retain type when returning WERR_MORE_DATA */
9250 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
9252 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9255 /****************************************************************
9256 _spoolss_SetPrinterDataEx
9257 ****************************************************************/
9259 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
9260 struct spoolss_SetPrinterDataEx *r)
9262 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9264 WERROR result = WERR_OK;
9265 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9268 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9270 /* From MSDN documentation of SetPrinterDataEx: pass request to
9271 SetPrinterData if key is "PrinterDriverData" */
9274 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9275 OUR_HANDLE(r->in.handle)));
9279 if (Printer->printer_type == SPLHND_SERVER) {
9280 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9281 "Not implemented for server handles yet\n"));
9282 return WERR_INVALID_PARAM;
9285 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9290 * Access check : NT returns "access denied" if you make a
9291 * SetPrinterData call without the necessary privildge.
9292 * we were originally returning OK if nothing changed
9293 * which made Win2k issue **a lot** of SetPrinterData
9294 * when connecting to a printer --jerry
9297 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9298 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9299 "change denied by handle access permissions\n"));
9300 return WERR_ACCESS_DENIED;
9303 result = winreg_get_printer(Printer,
9304 get_session_info_system(),
9306 lp_servicename(snum),
9308 if (!W_ERROR_IS_OK(result)) {
9312 /* check for OID in valuename */
9314 oid_string = strchr(r->in.value_name, ',');
9320 /* save the registry data */
9322 result = winreg_set_printer_dataex(p->mem_ctx,
9323 get_session_info_system(),
9332 if (W_ERROR_IS_OK(result)) {
9333 /* save the OID if one was specified */
9335 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9336 r->in.key_name, SPOOL_OID_KEY);
9338 result = WERR_NOMEM;
9343 * I'm not checking the status here on purpose. Don't know
9344 * if this is right, but I'm returning the status from the
9345 * previous set_printer_dataex() call. I have no idea if
9346 * this is right. --jerry
9348 winreg_set_printer_dataex(p->mem_ctx,
9349 get_session_info_system(),
9355 (uint8_t *) oid_string,
9356 strlen(oid_string) + 1);
9359 result = winreg_printer_update_changeid(p->mem_ctx,
9360 get_session_info_system(),
9362 lp_const_servicename(snum));
9367 talloc_free(pinfo2);
9371 /****************************************************************
9372 _spoolss_DeletePrinterDataEx
9373 ****************************************************************/
9375 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
9376 struct spoolss_DeletePrinterDataEx *r)
9378 const char *printer;
9380 WERROR status = WERR_OK;
9381 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9383 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9386 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9387 "Invalid handle (%s:%u:%u).\n",
9388 OUR_HANDLE(r->in.handle)));
9392 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9393 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9394 "printer properties change denied by handle\n"));
9395 return WERR_ACCESS_DENIED;
9398 if (!r->in.value_name || !r->in.key_name) {
9402 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9405 printer = lp_const_servicename(snum);
9407 status = winreg_delete_printer_dataex(p->mem_ctx,
9408 get_session_info_system(),
9413 if (W_ERROR_IS_OK(status)) {
9414 status = winreg_printer_update_changeid(p->mem_ctx,
9415 get_session_info_system(),
9423 /****************************************************************
9424 _spoolss_EnumPrinterKey
9425 ****************************************************************/
9427 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
9428 struct spoolss_EnumPrinterKey *r)
9431 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9433 WERROR result = WERR_BADFILE;
9434 const char **array = NULL;
9437 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9440 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9441 OUR_HANDLE(r->in.handle)));
9445 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9449 result = winreg_enum_printer_key(p->mem_ctx,
9450 get_session_info_system(),
9452 lp_const_servicename(snum),
9456 if (!W_ERROR_IS_OK(result)) {
9460 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9461 result = WERR_NOMEM;
9465 *r->out._ndr_size = r->in.offered / 2;
9466 *r->out.needed = blob.length;
9468 if (r->in.offered < *r->out.needed) {
9469 result = WERR_MORE_DATA;
9472 r->out.key_buffer->string_array = array;
9476 if (!W_ERROR_IS_OK(result)) {
9478 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9486 /****************************************************************
9487 _spoolss_DeletePrinterKey
9488 ****************************************************************/
9490 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9491 struct spoolss_DeletePrinterKey *r)
9493 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9496 const char *printer;
9498 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9501 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9502 OUR_HANDLE(r->in.handle)));
9506 /* if keyname == NULL, return error */
9507 if ( !r->in.key_name )
9508 return WERR_INVALID_PARAM;
9510 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9514 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9515 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9516 "printer properties change denied by handle\n"));
9517 return WERR_ACCESS_DENIED;
9520 printer = lp_const_servicename(snum);
9522 /* delete the key and all subkeys */
9523 status = winreg_delete_printer_key(p->mem_ctx,
9524 get_session_info_system(),
9528 if (W_ERROR_IS_OK(status)) {
9529 status = winreg_printer_update_changeid(p->mem_ctx,
9530 get_session_info_system(),
9538 /****************************************************************
9539 _spoolss_EnumPrinterDataEx
9540 ****************************************************************/
9542 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9543 struct spoolss_EnumPrinterDataEx *r)
9546 struct spoolss_PrinterEnumValues *info = NULL;
9547 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9551 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9555 *r->out.info = NULL;
9558 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9559 OUR_HANDLE(r->in.handle)));
9564 * first check for a keyname of NULL or "". Win2k seems to send
9565 * this a lot and we should send back WERR_INVALID_PARAM
9566 * no need to spend time looking up the printer in this case.
9570 if (!strlen(r->in.key_name)) {
9571 result = WERR_INVALID_PARAM;
9575 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9579 /* now look for a match on the key name */
9580 result = winreg_enum_printer_dataex(p->mem_ctx,
9581 get_session_info_system(),
9583 lp_const_servicename(snum),
9587 if (!W_ERROR_IS_OK(result)) {
9591 #if 0 /* FIXME - gd */
9592 /* housekeeping information in the reply */
9594 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9595 * the hand marshalled container size is a multiple
9596 * of 4 bytes for RPC alignment.
9600 needed += 4-(needed % 4);
9603 *r->out.count = count;
9604 *r->out.info = info;
9607 if (!W_ERROR_IS_OK(result)) {
9611 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9612 spoolss_EnumPrinterDataEx,
9615 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9616 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9618 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9621 /****************************************************************************
9622 ****************************************************************************/
9624 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9625 const char *servername,
9626 const char *environment,
9627 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9632 werr = compose_spoolss_server_path(mem_ctx,
9635 SPOOLSS_PRTPROCS_PATH,
9637 if (!W_ERROR_IS_OK(werr)) {
9641 DEBUG(4,("print processor directory: [%s]\n", path));
9643 r->directory_name = path;
9648 /****************************************************************
9649 _spoolss_GetPrintProcessorDirectory
9650 ****************************************************************/
9652 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
9653 struct spoolss_GetPrintProcessorDirectory *r)
9656 char *prnproc_share = NULL;
9657 bool prnproc_share_exists = false;
9660 /* that's an [in out] buffer */
9662 if (!r->in.buffer && (r->in.offered != 0)) {
9663 return WERR_INVALID_PARAM;
9666 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9671 /* r->in.level is ignored */
9673 /* We always should reply with a local print processor directory so that
9674 * users are not forced to have a [prnproc$] share on the Samba spoolss
9675 * server, if users decide to do so, lets announce it though - Guenther */
9677 snum = find_service(talloc_tos(), "prnproc$", &prnproc_share);
9678 if (!prnproc_share) {
9682 prnproc_share_exists = true;
9685 result = getprintprocessordirectory_level_1(p->mem_ctx,
9686 prnproc_share_exists ? r->in.server : NULL,
9688 &r->out.info->info1);
9689 if (!W_ERROR_IS_OK(result)) {
9690 TALLOC_FREE(r->out.info);
9694 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9695 r->out.info, r->in.level);
9696 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9698 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9701 /*******************************************************************
9702 ********************************************************************/
9704 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9705 const char *dllname)
9707 enum ndr_err_code ndr_err;
9708 struct spoolss_MonitorUi ui;
9710 ui.dll_name = dllname;
9712 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9713 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9714 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9715 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9717 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9720 /*******************************************************************
9721 Streams the monitor UI DLL name in UNICODE
9722 *******************************************************************/
9724 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9725 struct security_token *token, DATA_BLOB *in,
9726 DATA_BLOB *out, uint32_t *needed)
9728 const char *dllname = "tcpmonui.dll";
9730 *needed = (strlen(dllname)+1) * 2;
9732 if (out->length < *needed) {
9733 return WERR_INSUFFICIENT_BUFFER;
9736 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9743 /*******************************************************************
9744 ********************************************************************/
9746 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9747 struct spoolss_PortData1 *port1,
9748 const DATA_BLOB *buf)
9750 enum ndr_err_code ndr_err;
9751 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9752 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9753 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9754 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9756 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9759 /*******************************************************************
9760 ********************************************************************/
9762 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9763 struct spoolss_PortData2 *port2,
9764 const DATA_BLOB *buf)
9766 enum ndr_err_code ndr_err;
9767 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9768 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9769 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9770 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9772 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9775 /*******************************************************************
9776 Create a new TCP/IP port
9777 *******************************************************************/
9779 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9780 struct security_token *token, DATA_BLOB *in,
9781 DATA_BLOB *out, uint32_t *needed)
9783 struct spoolss_PortData1 port1;
9784 struct spoolss_PortData2 port2;
9785 char *device_uri = NULL;
9788 const char *portname;
9789 const char *hostaddress;
9791 uint32_t port_number;
9794 /* peek for spoolss_PortData version */
9796 if (!in || (in->length < (128 + 4))) {
9797 return WERR_GENERAL_FAILURE;
9800 version = IVAL(in->data, 128);
9806 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9810 portname = port1.portname;
9811 hostaddress = port1.hostaddress;
9812 queue = port1.queue;
9813 protocol = port1.protocol;
9814 port_number = port1.port_number;
9820 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9824 portname = port2.portname;
9825 hostaddress = port2.hostaddress;
9826 queue = port2.queue;
9827 protocol = port2.protocol;
9828 port_number = port2.port_number;
9832 DEBUG(1,("xcvtcp_addport: "
9833 "unknown version of port_data: %d\n", version));
9834 return WERR_UNKNOWN_PORT;
9837 /* create the device URI and call the add_port_hook() */
9840 case PROTOCOL_RAWTCP_TYPE:
9841 device_uri = talloc_asprintf(mem_ctx,
9842 "socket://%s:%d/", hostaddress,
9846 case PROTOCOL_LPR_TYPE:
9847 device_uri = talloc_asprintf(mem_ctx,
9848 "lpr://%s/%s", hostaddress, queue );
9852 return WERR_UNKNOWN_PORT;
9859 return add_port_hook(mem_ctx, token, portname, device_uri);
9862 /*******************************************************************
9863 *******************************************************************/
9865 struct xcv_api_table xcvtcp_cmds[] = {
9866 { "MonitorUI", xcvtcp_monitorui },
9867 { "AddPort", xcvtcp_addport},
9871 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9872 struct security_token *token, const char *command,
9879 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9881 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9882 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9883 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9886 return WERR_BADFUNC;
9889 /*******************************************************************
9890 *******************************************************************/
9891 #if 0 /* don't support management using the "Local Port" monitor */
9893 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9894 struct security_token *token, DATA_BLOB *in,
9895 DATA_BLOB *out, uint32_t *needed)
9897 const char *dllname = "localui.dll";
9899 *needed = (strlen(dllname)+1) * 2;
9901 if (out->length < *needed) {
9902 return WERR_INSUFFICIENT_BUFFER;
9905 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9912 /*******************************************************************
9913 *******************************************************************/
9915 struct xcv_api_table xcvlocal_cmds[] = {
9916 { "MonitorUI", xcvlocal_monitorui },
9920 struct xcv_api_table xcvlocal_cmds[] = {
9927 /*******************************************************************
9928 *******************************************************************/
9930 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9931 struct security_token *token, const char *command,
9932 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9937 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9939 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9940 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9941 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9943 return WERR_BADFUNC;
9946 /****************************************************************
9948 ****************************************************************/
9950 WERROR _spoolss_XcvData(struct pipes_struct *p,
9951 struct spoolss_XcvData *r)
9953 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9954 DATA_BLOB out_data = data_blob_null;
9958 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9959 OUR_HANDLE(r->in.handle)));
9963 /* Has to be a handle to the TCP/IP port monitor */
9965 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9966 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9970 /* requires administrative access to the server */
9972 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9973 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9974 return WERR_ACCESS_DENIED;
9977 /* Allocate the outgoing buffer */
9979 if (r->in.out_data_size) {
9980 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9981 if (out_data.data == NULL) {
9986 switch ( Printer->printer_type ) {
9987 case SPLHND_PORTMON_TCP:
9988 werror = process_xcvtcp_command(p->mem_ctx,
9989 p->session_info->security_token,
9990 r->in.function_name,
9991 &r->in.in_data, &out_data,
9994 case SPLHND_PORTMON_LOCAL:
9995 werror = process_xcvlocal_command(p->mem_ctx,
9996 p->session_info->security_token,
9997 r->in.function_name,
9998 &r->in.in_data, &out_data,
10002 werror = WERR_INVALID_PRINT_MONITOR;
10005 if (!W_ERROR_IS_OK(werror)) {
10009 *r->out.status_code = 0;
10011 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
10012 memcpy(r->out.out_data, out_data.data,
10013 MIN(r->in.out_data_size, out_data.length));
10019 /****************************************************************
10020 _spoolss_AddPrintProcessor
10021 ****************************************************************/
10023 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
10024 struct spoolss_AddPrintProcessor *r)
10026 /* for now, just indicate success and ignore the add. We'll
10027 automatically set the winprint processor for printer
10028 entries later. Used to debug the LexMark Optra S 1855 PCL
10034 /****************************************************************
10036 ****************************************************************/
10038 WERROR _spoolss_AddPort(struct pipes_struct *p,
10039 struct spoolss_AddPort *r)
10041 /* do what w2k3 does */
10043 return WERR_NOT_SUPPORTED;
10046 /****************************************************************
10047 _spoolss_GetPrinterDriver
10048 ****************************************************************/
10050 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
10051 struct spoolss_GetPrinterDriver *r)
10053 p->rng_fault_state = true;
10054 return WERR_NOT_SUPPORTED;
10057 /****************************************************************
10058 _spoolss_ReadPrinter
10059 ****************************************************************/
10061 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
10062 struct spoolss_ReadPrinter *r)
10064 p->rng_fault_state = true;
10065 return WERR_NOT_SUPPORTED;
10068 /****************************************************************
10069 _spoolss_WaitForPrinterChange
10070 ****************************************************************/
10072 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
10073 struct spoolss_WaitForPrinterChange *r)
10075 p->rng_fault_state = true;
10076 return WERR_NOT_SUPPORTED;
10079 /****************************************************************
10080 _spoolss_ConfigurePort
10081 ****************************************************************/
10083 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
10084 struct spoolss_ConfigurePort *r)
10086 p->rng_fault_state = true;
10087 return WERR_NOT_SUPPORTED;
10090 /****************************************************************
10091 _spoolss_DeletePort
10092 ****************************************************************/
10094 WERROR _spoolss_DeletePort(struct pipes_struct *p,
10095 struct spoolss_DeletePort *r)
10097 p->rng_fault_state = true;
10098 return WERR_NOT_SUPPORTED;
10101 /****************************************************************
10102 _spoolss_CreatePrinterIC
10103 ****************************************************************/
10105 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
10106 struct spoolss_CreatePrinterIC *r)
10108 p->rng_fault_state = true;
10109 return WERR_NOT_SUPPORTED;
10112 /****************************************************************
10113 _spoolss_PlayGDIScriptOnPrinterIC
10114 ****************************************************************/
10116 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
10117 struct spoolss_PlayGDIScriptOnPrinterIC *r)
10119 p->rng_fault_state = true;
10120 return WERR_NOT_SUPPORTED;
10123 /****************************************************************
10124 _spoolss_DeletePrinterIC
10125 ****************************************************************/
10127 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
10128 struct spoolss_DeletePrinterIC *r)
10130 p->rng_fault_state = true;
10131 return WERR_NOT_SUPPORTED;
10134 /****************************************************************
10135 _spoolss_AddPrinterConnection
10136 ****************************************************************/
10138 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
10139 struct spoolss_AddPrinterConnection *r)
10141 p->rng_fault_state = true;
10142 return WERR_NOT_SUPPORTED;
10145 /****************************************************************
10146 _spoolss_DeletePrinterConnection
10147 ****************************************************************/
10149 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
10150 struct spoolss_DeletePrinterConnection *r)
10152 p->rng_fault_state = true;
10153 return WERR_NOT_SUPPORTED;
10156 /****************************************************************
10157 _spoolss_PrinterMessageBox
10158 ****************************************************************/
10160 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
10161 struct spoolss_PrinterMessageBox *r)
10163 p->rng_fault_state = true;
10164 return WERR_NOT_SUPPORTED;
10167 /****************************************************************
10168 _spoolss_AddMonitor
10169 ****************************************************************/
10171 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
10172 struct spoolss_AddMonitor *r)
10174 p->rng_fault_state = true;
10175 return WERR_NOT_SUPPORTED;
10178 /****************************************************************
10179 _spoolss_DeleteMonitor
10180 ****************************************************************/
10182 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
10183 struct spoolss_DeleteMonitor *r)
10185 p->rng_fault_state = true;
10186 return WERR_NOT_SUPPORTED;
10189 /****************************************************************
10190 _spoolss_DeletePrintProcessor
10191 ****************************************************************/
10193 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
10194 struct spoolss_DeletePrintProcessor *r)
10196 p->rng_fault_state = true;
10197 return WERR_NOT_SUPPORTED;
10200 /****************************************************************
10201 _spoolss_AddPrintProvidor
10202 ****************************************************************/
10204 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
10205 struct spoolss_AddPrintProvidor *r)
10207 p->rng_fault_state = true;
10208 return WERR_NOT_SUPPORTED;
10211 /****************************************************************
10212 _spoolss_DeletePrintProvidor
10213 ****************************************************************/
10215 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
10216 struct spoolss_DeletePrintProvidor *r)
10218 p->rng_fault_state = true;
10219 return WERR_NOT_SUPPORTED;
10222 /****************************************************************
10223 _spoolss_FindFirstPrinterChangeNotification
10224 ****************************************************************/
10226 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
10227 struct spoolss_FindFirstPrinterChangeNotification *r)
10229 p->rng_fault_state = true;
10230 return WERR_NOT_SUPPORTED;
10233 /****************************************************************
10234 _spoolss_FindNextPrinterChangeNotification
10235 ****************************************************************/
10237 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
10238 struct spoolss_FindNextPrinterChangeNotification *r)
10240 p->rng_fault_state = true;
10241 return WERR_NOT_SUPPORTED;
10244 /****************************************************************
10245 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10246 ****************************************************************/
10248 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
10249 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10251 p->rng_fault_state = true;
10252 return WERR_NOT_SUPPORTED;
10255 /****************************************************************
10256 _spoolss_ReplyOpenPrinter
10257 ****************************************************************/
10259 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
10260 struct spoolss_ReplyOpenPrinter *r)
10262 p->rng_fault_state = true;
10263 return WERR_NOT_SUPPORTED;
10266 /****************************************************************
10267 _spoolss_RouterReplyPrinter
10268 ****************************************************************/
10270 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
10271 struct spoolss_RouterReplyPrinter *r)
10273 p->rng_fault_state = true;
10274 return WERR_NOT_SUPPORTED;
10277 /****************************************************************
10278 _spoolss_ReplyClosePrinter
10279 ****************************************************************/
10281 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
10282 struct spoolss_ReplyClosePrinter *r)
10284 p->rng_fault_state = true;
10285 return WERR_NOT_SUPPORTED;
10288 /****************************************************************
10290 ****************************************************************/
10292 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
10293 struct spoolss_AddPortEx *r)
10295 p->rng_fault_state = true;
10296 return WERR_NOT_SUPPORTED;
10299 /****************************************************************
10300 _spoolss_RouterFindFirstPrinterChangeNotification
10301 ****************************************************************/
10303 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
10304 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10306 p->rng_fault_state = true;
10307 return WERR_NOT_SUPPORTED;
10310 /****************************************************************
10311 _spoolss_SpoolerInit
10312 ****************************************************************/
10314 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
10315 struct spoolss_SpoolerInit *r)
10317 p->rng_fault_state = true;
10318 return WERR_NOT_SUPPORTED;
10321 /****************************************************************
10322 _spoolss_ResetPrinterEx
10323 ****************************************************************/
10325 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
10326 struct spoolss_ResetPrinterEx *r)
10328 p->rng_fault_state = true;
10329 return WERR_NOT_SUPPORTED;
10332 /****************************************************************
10333 _spoolss_RouterReplyPrinterEx
10334 ****************************************************************/
10336 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
10337 struct spoolss_RouterReplyPrinterEx *r)
10339 p->rng_fault_state = true;
10340 return WERR_NOT_SUPPORTED;
10343 /****************************************************************
10345 ****************************************************************/
10347 WERROR _spoolss_44(struct pipes_struct *p,
10348 struct spoolss_44 *r)
10350 p->rng_fault_state = true;
10351 return WERR_NOT_SUPPORTED;
10354 /****************************************************************
10356 ****************************************************************/
10358 WERROR _spoolss_SetPort(struct pipes_struct *p,
10359 struct spoolss_SetPort *r)
10361 p->rng_fault_state = true;
10362 return WERR_NOT_SUPPORTED;
10365 /****************************************************************
10367 ****************************************************************/
10369 WERROR _spoolss_4a(struct pipes_struct *p,
10370 struct spoolss_4a *r)
10372 p->rng_fault_state = true;
10373 return WERR_NOT_SUPPORTED;
10376 /****************************************************************
10378 ****************************************************************/
10380 WERROR _spoolss_4b(struct pipes_struct *p,
10381 struct spoolss_4b *r)
10383 p->rng_fault_state = true;
10384 return WERR_NOT_SUPPORTED;
10387 /****************************************************************
10389 ****************************************************************/
10391 WERROR _spoolss_4c(struct pipes_struct *p,
10392 struct spoolss_4c *r)
10394 p->rng_fault_state = true;
10395 return WERR_NOT_SUPPORTED;
10398 /****************************************************************
10400 ****************************************************************/
10402 WERROR _spoolss_53(struct pipes_struct *p,
10403 struct spoolss_53 *r)
10405 p->rng_fault_state = true;
10406 return WERR_NOT_SUPPORTED;
10409 /****************************************************************
10410 _spoolss_AddPerMachineConnection
10411 ****************************************************************/
10413 WERROR _spoolss_AddPerMachineConnection(struct pipes_struct *p,
10414 struct spoolss_AddPerMachineConnection *r)
10416 p->rng_fault_state = true;
10417 return WERR_NOT_SUPPORTED;
10420 /****************************************************************
10421 _spoolss_DeletePerMachineConnection
10422 ****************************************************************/
10424 WERROR _spoolss_DeletePerMachineConnection(struct pipes_struct *p,
10425 struct spoolss_DeletePerMachineConnection *r)
10427 p->rng_fault_state = true;
10428 return WERR_NOT_SUPPORTED;
10431 /****************************************************************
10432 _spoolss_EnumPerMachineConnections
10433 ****************************************************************/
10435 WERROR _spoolss_EnumPerMachineConnections(struct pipes_struct *p,
10436 struct spoolss_EnumPerMachineConnections *r)
10438 p->rng_fault_state = true;
10439 return WERR_NOT_SUPPORTED;
10442 /****************************************************************
10444 ****************************************************************/
10446 WERROR _spoolss_5a(struct pipes_struct *p,
10447 struct spoolss_5a *r)
10449 p->rng_fault_state = true;
10450 return WERR_NOT_SUPPORTED;
10453 /****************************************************************
10455 ****************************************************************/
10457 WERROR _spoolss_5b(struct pipes_struct *p,
10458 struct spoolss_5b *r)
10460 p->rng_fault_state = true;
10461 return WERR_NOT_SUPPORTED;
10464 /****************************************************************
10466 ****************************************************************/
10468 WERROR _spoolss_5c(struct pipes_struct *p,
10469 struct spoolss_5c *r)
10471 p->rng_fault_state = true;
10472 return WERR_NOT_SUPPORTED;
10475 /****************************************************************
10477 ****************************************************************/
10479 WERROR _spoolss_5d(struct pipes_struct *p,
10480 struct spoolss_5d *r)
10482 p->rng_fault_state = true;
10483 return WERR_NOT_SUPPORTED;
10486 /****************************************************************
10488 ****************************************************************/
10490 WERROR _spoolss_5e(struct pipes_struct *p,
10491 struct spoolss_5e *r)
10493 p->rng_fault_state = true;
10494 return WERR_NOT_SUPPORTED;
10497 /****************************************************************
10499 ****************************************************************/
10501 WERROR _spoolss_5f(struct pipes_struct *p,
10502 struct spoolss_5f *r)
10504 p->rng_fault_state = true;
10505 return WERR_NOT_SUPPORTED;
10508 /****************************************************************
10510 ****************************************************************/
10512 WERROR _spoolss_60(struct pipes_struct *p,
10513 struct spoolss_60 *r)
10515 p->rng_fault_state = true;
10516 return WERR_NOT_SUPPORTED;
10519 /****************************************************************
10521 ****************************************************************/
10523 WERROR _spoolss_61(struct pipes_struct *p,
10524 struct spoolss_61 *r)
10526 p->rng_fault_state = true;
10527 return WERR_NOT_SUPPORTED;
10530 /****************************************************************
10532 ****************************************************************/
10534 WERROR _spoolss_62(struct pipes_struct *p,
10535 struct spoolss_62 *r)
10537 p->rng_fault_state = true;
10538 return WERR_NOT_SUPPORTED;
10541 /****************************************************************
10543 ****************************************************************/
10545 WERROR _spoolss_63(struct pipes_struct *p,
10546 struct spoolss_63 *r)
10548 p->rng_fault_state = true;
10549 return WERR_NOT_SUPPORTED;
10552 /****************************************************************
10554 ****************************************************************/
10556 WERROR _spoolss_64(struct pipes_struct *p,
10557 struct spoolss_64 *r)
10559 p->rng_fault_state = true;
10560 return WERR_NOT_SUPPORTED;
10563 /****************************************************************
10565 ****************************************************************/
10567 WERROR _spoolss_65(struct pipes_struct *p,
10568 struct spoolss_65 *r)
10570 p->rng_fault_state = true;
10571 return WERR_NOT_SUPPORTED;
10574 /****************************************************************
10575 _spoolss_GetCorePrinterDrivers
10576 ****************************************************************/
10578 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10579 struct spoolss_GetCorePrinterDrivers *r)
10581 p->rng_fault_state = true;
10582 return WERR_NOT_SUPPORTED;
10585 /****************************************************************
10587 ****************************************************************/
10589 WERROR _spoolss_67(struct pipes_struct *p,
10590 struct spoolss_67 *r)
10592 p->rng_fault_state = true;
10593 return WERR_NOT_SUPPORTED;
10596 /****************************************************************
10597 _spoolss_GetPrinterDriverPackagePath
10598 ****************************************************************/
10600 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10601 struct spoolss_GetPrinterDriverPackagePath *r)
10603 p->rng_fault_state = true;
10604 return WERR_NOT_SUPPORTED;
10607 /****************************************************************
10609 ****************************************************************/
10611 WERROR _spoolss_69(struct pipes_struct *p,
10612 struct spoolss_69 *r)
10614 p->rng_fault_state = true;
10615 return WERR_NOT_SUPPORTED;
10618 /****************************************************************
10620 ****************************************************************/
10622 WERROR _spoolss_6a(struct pipes_struct *p,
10623 struct spoolss_6a *r)
10625 p->rng_fault_state = true;
10626 return WERR_NOT_SUPPORTED;
10629 /****************************************************************
10631 ****************************************************************/
10633 WERROR _spoolss_6b(struct pipes_struct *p,
10634 struct spoolss_6b *r)
10636 p->rng_fault_state = true;
10637 return WERR_NOT_SUPPORTED;
10640 /****************************************************************
10642 ****************************************************************/
10644 WERROR _spoolss_6c(struct pipes_struct *p,
10645 struct spoolss_6c *r)
10647 p->rng_fault_state = true;
10648 return WERR_NOT_SUPPORTED;
10651 /****************************************************************
10653 ****************************************************************/
10655 WERROR _spoolss_6d(struct pipes_struct *p,
10656 struct spoolss_6d *r)
10658 p->rng_fault_state = true;
10659 return WERR_NOT_SUPPORTED;