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. */
32 #include "nt_printing.h"
33 #include "srv_spoolss_util.h"
34 #include "../librpc/gen_ndr/srv_spoolss.h"
35 #include "../librpc/gen_ndr/ndr_spoolss_c.h"
36 #include "rpc_client/init_spoolss.h"
37 #include "rpc_client/cli_pipe.h"
38 #include "../libcli/security/security.h"
39 #include "librpc/gen_ndr/ndr_security.h"
41 #include "registry/reg_objects.h"
42 #include "include/printing.h"
44 #include "../librpc/gen_ndr/netlogon.h"
46 #include "printing/notify.h"
48 #include "../libcli/registry/util_reg.h"
49 #include "smbd/smbd.h"
50 #include "smbd/globals.h"
53 #include "rpc_server/spoolss/srv_spoolss_nt.h"
55 #include "libsmb/libsmb.h"
56 #include "printing/printer_list.h"
57 #include "../lib/tsocket/tsocket.h"
58 #include "rpc_client/cli_winreg_spoolss.h"
60 /* macros stolen from s4 spoolss server */
61 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
62 ((info)?ndr_size_##fn(info, level, 0):0)
64 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
65 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
67 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
68 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
70 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
73 #define DBGC_CLASS DBGC_RPC_SRV
75 #ifndef MAX_OPEN_PRINTER_EXS
76 #define MAX_OPEN_PRINTER_EXS 50
79 struct notify_back_channel;
81 /* structure to store the printer handles */
82 /* and a reference to what it's pointing to */
83 /* and the notify info asked about */
84 /* that's the central struct */
85 struct printer_handle {
86 struct printer_handle *prev, *next;
87 bool document_started;
89 uint32 jobid; /* jobid in printing backend */
91 const char *servername;
94 uint32 access_granted;
100 struct spoolss_NotifyOption *option;
101 struct policy_handle cli_hnd;
102 struct notify_back_channel *cli_chan;
104 /* are we in a FindNextPrinterChangeNotify() call? */
106 struct messaging_context *msg_ctx;
113 /* devmode sent in the OpenPrinter() call */
114 struct spoolss_DeviceMode *devmode;
116 /* TODO cache the printer info2 structure */
117 struct spoolss_PrinterInfo2 *info2;
121 static struct printer_handle *printers_list;
123 struct printer_session_counter {
124 struct printer_session_counter *next;
125 struct printer_session_counter *prev;
131 static struct printer_session_counter *counter_list;
133 struct notify_back_channel {
134 struct notify_back_channel *prev, *next;
136 /* associated client */
137 struct sockaddr_storage client_address;
139 /* print notify back-channel pipe handle*/
140 struct rpc_pipe_client *cli_pipe;
141 struct dcerpc_binding_handle *binding_handle;
142 uint32_t active_connections;
145 static struct notify_back_channel *back_channels;
147 /* Map generic permissions to printer object specific permissions */
149 const struct standard_mapping printer_std_mapping = {
156 /* Map generic permissions to print server object specific permissions */
158 const struct standard_mapping printserver_std_mapping = {
165 /* API table for Xcv Monitor functions */
167 struct xcv_api_table {
169 WERROR(*fn) (TALLOC_CTX *mem_ctx, struct security_token *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
172 static void prune_printername_cache(void);
174 /********************************************************************
175 * Canonicalize servername.
176 ********************************************************************/
178 static const char *canon_servername(const char *servername)
180 const char *pservername = servername;
181 while (*pservername == '\\') {
187 /* translate between internal status numbers and NT status numbers */
188 static int nt_printj_status(int v)
194 return JOB_STATUS_PAUSED;
196 return JOB_STATUS_SPOOLING;
198 return JOB_STATUS_PRINTING;
200 return JOB_STATUS_ERROR;
202 return JOB_STATUS_DELETING;
204 return JOB_STATUS_OFFLINE;
206 return JOB_STATUS_PAPEROUT;
208 return JOB_STATUS_PRINTED;
210 return JOB_STATUS_DELETED;
212 return JOB_STATUS_BLOCKED_DEVQ;
213 case LPQ_USER_INTERVENTION:
214 return JOB_STATUS_USER_INTERVENTION;
219 static int nt_printq_status(int v)
223 return PRINTER_STATUS_PAUSED;
232 /***************************************************************************
233 Disconnect from the client
234 ****************************************************************************/
236 static void srv_spoolss_replycloseprinter(int snum,
237 struct printer_handle *prn_hnd)
243 * Tell the specific printing tdb we no longer want messages for this printer
244 * by deregistering our PID.
247 if (!print_notify_deregister_pid(snum)) {
248 DEBUG(0, ("Failed to register our pid for printer %s\n",
249 lp_const_servicename(snum)));
252 /* weird if the test succeeds !!! */
253 if (prn_hnd->notify.cli_chan == NULL ||
254 prn_hnd->notify.cli_chan->active_connections == 0) {
255 DEBUG(0, ("Trying to close unexisting backchannel!\n"));
256 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
257 TALLOC_FREE(prn_hnd->notify.cli_chan);
261 status = dcerpc_spoolss_ReplyClosePrinter(
262 prn_hnd->notify.cli_chan->binding_handle,
264 &prn_hnd->notify.cli_hnd,
266 if (!NT_STATUS_IS_OK(status)) {
267 DEBUG(0, ("dcerpc_spoolss_ReplyClosePrinter failed [%s].\n",
269 result = ntstatus_to_werror(status);
270 } else if (!W_ERROR_IS_OK(result)) {
271 DEBUG(0, ("reply_close_printer failed [%s].\n",
272 win_errstr(result)));
275 /* if it's the last connection, deconnect the IPC$ share */
276 if (prn_hnd->notify.cli_chan->active_connections == 1) {
278 prn_hnd->notify.cli_chan->binding_handle = NULL;
279 cli_shutdown(rpc_pipe_np_smb_conn(prn_hnd->notify.cli_chan->cli_pipe));
280 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
281 TALLOC_FREE(prn_hnd->notify.cli_chan);
283 if (prn_hnd->notify.msg_ctx != NULL) {
284 messaging_deregister(prn_hnd->notify.msg_ctx,
285 MSG_PRINTER_NOTIFY2, NULL);
288 * Tell the serverid.tdb we're no longer
289 * interested in printer notify messages.
292 serverid_register_msg_flags(
293 messaging_server_id(prn_hnd->notify.msg_ctx),
294 false, FLAG_MSG_PRINT_NOTIFY);
298 if (prn_hnd->notify.cli_chan) {
299 prn_hnd->notify.cli_chan->active_connections--;
303 /****************************************************************************
304 Functions to free a printer entry datastruct.
305 ****************************************************************************/
307 static int printer_entry_destructor(struct printer_handle *Printer)
309 if (Printer->notify.cli_chan != NULL &&
310 Printer->notify.cli_chan->active_connections > 0) {
313 switch(Printer->printer_type) {
315 srv_spoolss_replycloseprinter(snum, Printer);
319 snum = print_queue_snum(Printer->sharename);
321 srv_spoolss_replycloseprinter(snum, Printer);
329 Printer->notify.flags=0;
330 Printer->notify.options=0;
331 Printer->notify.localmachine[0]='\0';
332 Printer->notify.printerlocal=0;
333 TALLOC_FREE(Printer->notify.option);
334 TALLOC_FREE(Printer->devmode);
336 /* Remove from the internal list. */
337 DLIST_REMOVE(printers_list, Printer);
341 /****************************************************************************
342 find printer index by handle
343 ****************************************************************************/
345 static struct printer_handle *find_printer_index_by_hnd(struct pipes_struct *p,
346 struct policy_handle *hnd)
348 struct printer_handle *find_printer = NULL;
350 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
351 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
358 /****************************************************************************
359 Close printer index by handle.
360 ****************************************************************************/
362 static bool close_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
364 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
367 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
372 close_policy_hnd(p, hnd);
377 /****************************************************************************
378 Delete a printer given a handle.
379 ****************************************************************************/
381 static WERROR delete_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
382 const char *sharename,
383 struct messaging_context *msg_ctx)
385 char *cmd = lp_deleteprinter_cmd();
386 char *command = NULL;
388 bool is_print_op = false;
390 /* can't fail if we don't try */
395 command = talloc_asprintf(ctx,
402 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
404 DEBUG(10,("Running [%s]\n", command));
406 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
411 if ( (ret = smbrun(command, NULL)) == 0 ) {
412 /* Tell everyone we updated smb.conf. */
413 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
419 /********** END SePrintOperatorPrivlege BLOCK **********/
421 DEBUGADD(10,("returned [%d]\n", ret));
423 TALLOC_FREE(command);
426 return WERR_BADFID; /* What to return here? */
428 /* go ahead and re-read the services immediately */
430 reload_services(msg_ctx, -1, false);
433 if ( lp_servicenumber( sharename ) >= 0 )
434 return WERR_ACCESS_DENIED;
439 /****************************************************************************
440 Delete a printer given a handle.
441 ****************************************************************************/
443 static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
445 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
449 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
455 * It turns out that Windows allows delete printer on a handle
456 * opened by an admin user, then used on a pipe handle created
457 * by an anonymous user..... but they're working on security.... riiight !
461 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
462 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
463 return WERR_ACCESS_DENIED;
466 /* this does not need a become root since the access check has been
467 done on the handle already */
469 result = winreg_delete_printer_key_internal(p->mem_ctx,
470 get_session_info_system(),
474 if (!W_ERROR_IS_OK(result)) {
475 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
479 result = delete_printer_hook(p->mem_ctx, p->session_info->security_token,
480 Printer->sharename, p->msg_ctx);
481 if (!W_ERROR_IS_OK(result)) {
484 prune_printername_cache();
488 /****************************************************************************
489 Return the snum of a printer corresponding to an handle.
490 ****************************************************************************/
492 static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
493 int *number, struct share_params **params)
495 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
498 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
503 switch (Printer->printer_type) {
505 DEBUG(4,("short name:%s\n", Printer->sharename));
506 *number = print_queue_snum(Printer->sharename);
507 return (*number != -1);
515 /****************************************************************************
516 Set printer handle type.
517 Check if it's \\server or \\server\printer
518 ****************************************************************************/
520 static bool set_printer_hnd_printertype(struct printer_handle *Printer, const char *handlename)
522 DEBUG(3,("Setting printer type=%s\n", handlename));
524 /* it's a print server */
525 if (handlename && *handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
526 DEBUGADD(4,("Printer is a print server\n"));
527 Printer->printer_type = SPLHND_SERVER;
529 /* it's a printer (set_printer_hnd_name() will handle port monitors */
531 DEBUGADD(4,("Printer is a printer\n"));
532 Printer->printer_type = SPLHND_PRINTER;
538 static void prune_printername_cache_fn(const char *key, const char *value,
539 time_t timeout, void *private_data)
544 static void prune_printername_cache(void)
546 gencache_iterate(prune_printername_cache_fn, NULL, "PRINTERNAME/*");
549 /****************************************************************************
550 Set printer handle name.. Accept names like \\server, \\server\printer,
551 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
552 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
553 XcvDataPort() interface.
554 ****************************************************************************/
556 static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
557 const struct auth_serversupplied_info *session_info,
558 struct messaging_context *msg_ctx,
559 struct printer_handle *Printer,
560 const char *handlename)
563 int n_services=lp_numservices();
565 const char *printername;
566 const char *servername = NULL;
569 struct spoolss_PrinterInfo2 *info2 = NULL;
574 * Hopefully nobody names his printers like this. Maybe \ or ,
575 * are illegal in printer names even?
577 const char printer_not_found[] = "Printer \\, !@#$%^&*( not found";
581 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
582 (unsigned long)strlen(handlename)));
584 aprinter = discard_const_p(char, handlename);
585 if ( *handlename == '\\' ) {
586 servername = canon_servername(handlename);
587 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
591 if (!is_myname_or_ipaddr(servername)) {
592 return WERR_INVALID_PRINTER_NAME;
594 Printer->servername = talloc_asprintf(Printer, "\\\\%s", servername);
595 if (Printer->servername == NULL) {
600 if (Printer->printer_type == SPLHND_SERVER) {
604 if (Printer->printer_type != SPLHND_PRINTER) {
605 return WERR_INVALID_HANDLE;
608 DEBUGADD(5, ("searching for [%s]\n", aprinter));
610 p = strchr(aprinter, ',');
617 if (strncmp(p, "DrvConvert", strlen("DrvConvert")) == 0) {
619 } else if (strncmp(p, "LocalOnly", strlen("LocalOnly")) == 0) {
625 DEBUGADD(5, ("stripped handlename: [%s]\n", aprinter));
628 /* check for the Port Monitor Interface */
629 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
630 Printer->printer_type = SPLHND_PORTMON_TCP;
631 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
634 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
635 Printer->printer_type = SPLHND_PORTMON_LOCAL;
636 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
641 * With hundreds of printers, the "for" loop iterating all
642 * shares can be quite expensive, as it is done on every
643 * OpenPrinter. The loop maps "aprinter" to "sname", the
644 * result of which we cache in gencache.
647 cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
649 if ((cache_key != NULL) && gencache_get(cache_key, &tmp, NULL)) {
651 found = (strcmp(tmp, printer_not_found) != 0);
653 DEBUG(4, ("Printer %s not found\n", aprinter));
655 return WERR_INVALID_PRINTER_NAME;
661 /* Search all sharenames first as this is easier than pulling
662 the printer_info_2 off of disk. Don't use find_service() since
663 that calls out to map_username() */
665 /* do another loop to look for printernames */
666 for (snum = 0; !found && snum < n_services; snum++) {
667 const char *printer = lp_const_servicename(snum);
669 /* no point going on if this is not a printer */
670 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
674 /* ignore [printers] share */
675 if (strequal(printer, "printers")) {
679 fstrcpy(sname, printer);
680 if (strequal(aprinter, printer)) {
685 /* no point looking up the printer object if
686 we aren't allowing printername != sharename */
687 if (lp_force_printername(snum)) {
691 result = winreg_get_printer_internal(mem_ctx,
696 if ( !W_ERROR_IS_OK(result) ) {
697 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
698 sname, win_errstr(result)));
702 printername = strrchr(info2->printername, '\\');
703 if (printername == NULL) {
704 printername = info2->printername;
709 if (strequal(printername, aprinter)) {
714 DEBUGADD(10, ("printername: %s\n", printername));
720 if (cache_key != NULL) {
721 gencache_set(cache_key, printer_not_found,
723 TALLOC_FREE(cache_key);
725 DEBUGADD(4,("Printer not found\n"));
726 return WERR_INVALID_PRINTER_NAME;
729 if (cache_key != NULL) {
730 gencache_set(cache_key, sname, time(NULL)+300);
731 TALLOC_FREE(cache_key);
734 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
736 strlcpy(Printer->sharename, sname, sizeof(Printer->sharename));
741 /****************************************************************************
742 Find first available printer slot. creates a printer handle for you.
743 ****************************************************************************/
745 static WERROR open_printer_hnd(struct pipes_struct *p,
746 struct policy_handle *hnd,
748 uint32_t access_granted)
750 struct printer_handle *new_printer;
753 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
755 new_printer = talloc_zero(p->mem_ctx, struct printer_handle);
756 if (new_printer == NULL) {
759 talloc_set_destructor(new_printer, printer_entry_destructor);
761 /* This also steals the printer_handle on the policy_handle */
762 if (!create_policy_hnd(p, hnd, new_printer)) {
763 TALLOC_FREE(new_printer);
764 return WERR_INVALID_HANDLE;
767 /* Add to the internal list. */
768 DLIST_ADD(printers_list, new_printer);
770 new_printer->notify.option=NULL;
772 if (!set_printer_hnd_printertype(new_printer, name)) {
773 close_printer_handle(p, hnd);
774 return WERR_INVALID_HANDLE;
777 result = set_printer_hnd_name(p->mem_ctx,
778 get_session_info_system(),
781 if (!W_ERROR_IS_OK(result)) {
782 close_printer_handle(p, hnd);
786 new_printer->access_granted = access_granted;
788 DEBUG(5, ("%d printer handles active\n",
789 (int)num_pipe_handles(p)));
794 /***************************************************************************
795 check to see if the client motify handle is monitoring the notification
796 given by (notify_type, notify_field).
797 **************************************************************************/
799 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
800 uint16_t notify_field)
805 static bool is_monitoring_event(struct printer_handle *p, uint16_t notify_type,
806 uint16_t notify_field)
808 struct spoolss_NotifyOption *option = p->notify.option;
812 * Flags should always be zero when the change notify
813 * is registered by the client's spooler. A user Win32 app
814 * might use the flags though instead of the NOTIFY_OPTION_INFO
823 return is_monitoring_event_flags(
824 p->notify.flags, notify_type, notify_field);
826 for (i = 0; i < option->count; i++) {
828 /* Check match for notify_type */
830 if (option->types[i].type != notify_type)
833 /* Check match for field */
835 for (j = 0; j < option->types[i].count; j++) {
836 if (option->types[i].fields[j].field == notify_field) {
842 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
843 p->servername, p->sharename, notify_type, notify_field));
848 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
849 _data->data.integer[0] = _integer; \
850 _data->data.integer[1] = 0;
853 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
854 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
855 if (!_data->data.string.string) {\
856 _data->data.string.size = 0; \
858 _data->data.string.size = strlen_m_term(_p) * 2;
860 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
861 _data->data.devmode.devmode = _devmode;
863 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
864 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
865 if (!_data->data.sd.sd) { \
866 _data->data.sd.sd_size = 0; \
868 _data->data.sd.sd_size = \
869 ndr_size_security_descriptor(_data->data.sd.sd, 0);
871 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
876 struct spoolss_Time st;
880 if (!init_systemtime(&st, t)) {
884 p = talloc_array(mem_ctx, char, len);
890 * Systemtime must be linearized as a set of UINT16's.
891 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
894 SSVAL(p, 0, st.year);
895 SSVAL(p, 2, st.month);
896 SSVAL(p, 4, st.day_of_week);
898 SSVAL(p, 8, st.hour);
899 SSVAL(p, 10, st.minute);
900 SSVAL(p, 12, st.second);
901 SSVAL(p, 14, st.millisecond);
907 /* Convert a notification message to a struct spoolss_Notify */
909 static void notify_one_value(struct spoolss_notify_msg *msg,
910 struct spoolss_Notify *data,
913 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
916 static void notify_string(struct spoolss_notify_msg *msg,
917 struct spoolss_Notify *data,
920 /* The length of the message includes the trailing \0 */
922 data->data.string.size = msg->len * 2;
923 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
924 if (!data->data.string.string) {
925 data->data.string.size = 0;
930 static void notify_system_time(struct spoolss_notify_msg *msg,
931 struct spoolss_Notify *data,
934 data->data.string.string = NULL;
935 data->data.string.size = 0;
937 if (msg->len != sizeof(time_t)) {
938 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
943 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
944 &data->data.string.string,
945 &data->data.string.size);
948 struct notify2_message_table {
950 void (*fn)(struct spoolss_notify_msg *msg,
951 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
954 static struct notify2_message_table printer_notify_table[] = {
955 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
956 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
957 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
958 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
959 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
960 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
961 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
962 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
963 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
964 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
965 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
966 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
967 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
968 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
969 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
970 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
971 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
972 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
973 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
976 static struct notify2_message_table job_notify_table[] = {
977 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
978 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
979 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
980 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
981 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
982 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
983 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
984 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
985 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
986 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
987 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
988 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
989 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
990 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
991 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
992 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
993 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
994 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
995 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
996 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
997 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
998 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
999 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
1000 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
1004 /***********************************************************************
1005 Allocate talloc context for container object
1006 **********************************************************************/
1008 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1013 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
1018 /***********************************************************************
1019 release all allocated memory and zero out structure
1020 **********************************************************************/
1022 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1028 talloc_destroy(ctr->ctx);
1035 /***********************************************************************
1036 **********************************************************************/
1038 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1046 /***********************************************************************
1047 **********************************************************************/
1049 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1051 if ( !ctr || !ctr->msg_groups )
1054 if ( idx >= ctr->num_groups )
1057 return &ctr->msg_groups[idx];
1061 /***********************************************************************
1062 How many groups of change messages do we have ?
1063 **********************************************************************/
1065 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1070 return ctr->num_groups;
1073 /***********************************************************************
1074 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1075 **********************************************************************/
1077 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
1079 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
1080 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
1081 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
1087 /* loop over all groups looking for a matching printer name */
1089 for ( i=0; i<ctr->num_groups; i++ ) {
1090 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
1094 /* add a new group? */
1096 if ( i == ctr->num_groups ) {
1099 if ( !(groups = talloc_realloc( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
1100 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1103 ctr->msg_groups = groups;
1105 /* clear the new entry and set the printer name */
1107 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
1108 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
1111 /* add the change messages; 'i' is the correct index now regardless */
1113 msg_grp = &ctr->msg_groups[i];
1115 msg_grp->num_msgs++;
1117 if ( !(msg_list = talloc_realloc( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
1118 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
1121 msg_grp->msgs = msg_list;
1123 new_slot = msg_grp->num_msgs-1;
1124 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
1126 /* need to allocate own copy of data */
1128 if ( msg->len != 0 )
1129 msg_grp->msgs[new_slot].notify.data = (char *)
1130 talloc_memdup( ctr->ctx, msg->notify.data, msg->len );
1132 return ctr->num_groups;
1135 static void construct_info_data(struct spoolss_Notify *info_data,
1136 enum spoolss_NotifyType type,
1137 uint16_t field, int id);
1139 /***********************************************************************
1140 Send a change notication message on all handles which have a call
1142 **********************************************************************/
1144 static int build_notify2_messages(TALLOC_CTX *mem_ctx,
1145 struct printer_handle *prn_hnd,
1146 SPOOLSS_NOTIFY_MSG *messages,
1148 struct spoolss_Notify **_notifies,
1151 struct spoolss_Notify *notifies;
1152 SPOOLSS_NOTIFY_MSG *msg;
1157 notifies = talloc_zero_array(mem_ctx,
1158 struct spoolss_Notify, num_msgs);
1163 for (i = 0; i < num_msgs; i++) {
1167 /* Are we monitoring this event? */
1169 if (!is_monitoring_event(prn_hnd, msg->type, msg->field)) {
1173 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1174 "for printer [%s]\n",
1175 msg->type, msg->field, prn_hnd->sharename));
1178 * if the is a printer notification handle and not a job
1179 * notification type, then set the id to 0.
1180 * Otherwise just use what was specified in the message.
1182 * When registering change notification on a print server
1183 * handle we always need to send back the id (snum) matching
1184 * the printer for which the change took place.
1185 * For change notify registered on a printer handle,
1186 * this does not matter and the id should be 0.
1191 if ((msg->type == PRINTER_NOTIFY_TYPE) &&
1192 (prn_hnd->printer_type == SPLHND_PRINTER)) {
1198 /* Convert unix jobid to smb jobid */
1200 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1201 id = sysjob_to_jobid(msg->id);
1204 DEBUG(3, ("no such unix jobid %d\n",
1210 construct_info_data(¬ifies[count],
1211 msg->type, msg->field, id);
1214 case PRINTER_NOTIFY_TYPE:
1215 if (printer_notify_table[msg->field].fn) {
1216 printer_notify_table[msg->field].fn(msg,
1217 ¬ifies[count], mem_ctx);
1221 case JOB_NOTIFY_TYPE:
1222 if (job_notify_table[msg->field].fn) {
1223 job_notify_table[msg->field].fn(msg,
1224 ¬ifies[count], mem_ctx);
1229 DEBUG(5, ("Unknown notification type %d\n",
1237 *_notifies = notifies;
1243 static int send_notify2_printer(TALLOC_CTX *mem_ctx,
1244 struct printer_handle *prn_hnd,
1245 SPOOLSS_NOTIFY_MSG_GROUP *msg_group)
1247 struct spoolss_Notify *notifies;
1249 union spoolss_ReplyPrinterInfo info;
1250 struct spoolss_NotifyInfo info0;
1251 uint32_t reply_result;
1256 /* Is there notification on this handle? */
1257 if (prn_hnd->notify.cli_chan == NULL ||
1258 prn_hnd->notify.cli_chan->active_connections == 0) {
1262 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1263 prn_hnd->servername, prn_hnd->sharename));
1265 /* For this printer? Print servers always receive notifications. */
1266 if ((prn_hnd->printer_type == SPLHND_PRINTER) &&
1267 (!strequal(msg_group->printername, prn_hnd->sharename))) {
1271 DEBUG(10,("Our printer\n"));
1273 /* build the array of change notifications */
1274 ret = build_notify2_messages(mem_ctx, prn_hnd,
1276 msg_group->num_msgs,
1282 info0.version = 0x2;
1283 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1284 info0.count = count;
1285 info0.notifies = notifies;
1287 info.info0 = &info0;
1289 status = dcerpc_spoolss_RouterReplyPrinterEx(
1290 prn_hnd->notify.cli_chan->binding_handle,
1292 &prn_hnd->notify.cli_hnd,
1293 prn_hnd->notify.change, /* color */
1294 prn_hnd->notify.flags,
1296 0, /* reply_type, must be 0 */
1298 if (!NT_STATUS_IS_OK(status)) {
1299 DEBUG(1, ("dcerpc_spoolss_RouterReplyPrinterEx to client: %s "
1301 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1302 nt_errstr(status)));
1303 werr = ntstatus_to_werror(status);
1304 } else if (!W_ERROR_IS_OK(werr)) {
1305 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1307 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1310 switch (reply_result) {
1313 case PRINTER_NOTIFY_INFO_DISCARDED:
1314 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1315 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1324 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1326 struct printer_handle *p;
1327 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
1328 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
1332 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1336 if (!msg_group->msgs) {
1337 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1341 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
1343 /* loop over all printers */
1345 for (p = printers_list; p; p = p->next) {
1346 ret = send_notify2_printer(mem_ctx, p, msg_group);
1353 DEBUG(8,("send_notify2_changes: Exit...\n"));
1357 /***********************************************************************
1358 **********************************************************************/
1360 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1363 uint32_t tv_sec, tv_usec;
1366 /* Unpack message */
1368 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1371 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1373 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1376 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1377 &msg->notify.value[0], &msg->notify.value[1]);
1379 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1380 &msg->len, &msg->notify.data);
1382 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1383 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1385 tv->tv_sec = tv_sec;
1386 tv->tv_usec = tv_usec;
1389 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1390 msg->notify.value[1]));
1392 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1397 /********************************************************************
1398 Receive a notify2 message list
1399 ********************************************************************/
1401 static void receive_notify2_message_list(struct messaging_context *msg,
1404 struct server_id server_id,
1407 size_t msg_count, i;
1408 char *buf = (char *)data->data;
1411 SPOOLSS_NOTIFY_MSG notify;
1412 SPOOLSS_NOTIFY_MSG_CTR messages;
1415 if (data->length < 4) {
1416 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1420 msg_count = IVAL(buf, 0);
1423 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1425 if (msg_count == 0) {
1426 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1430 /* initialize the container */
1432 ZERO_STRUCT( messages );
1433 notify_msg_ctr_init( &messages );
1436 * build message groups for each printer identified
1437 * in a change_notify msg. Remember that a PCN message
1438 * includes the handle returned for the srv_spoolss_replyopenprinter()
1439 * call. Therefore messages are grouped according to printer handle.
1442 for ( i=0; i<msg_count; i++ ) {
1443 struct timeval msg_tv;
1445 if (msg_ptr + 4 - buf > data->length) {
1446 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1450 msg_len = IVAL(msg_ptr,0);
1453 if (msg_ptr + msg_len - buf > data->length) {
1454 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1458 /* unpack messages */
1460 ZERO_STRUCT( notify );
1461 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1464 /* add to correct list in container */
1466 notify_msg_ctr_addmsg( &messages, ¬ify );
1468 /* free memory that might have been allocated by notify2_unpack_msg() */
1470 if ( notify.len != 0 )
1471 SAFE_FREE( notify.notify.data );
1474 /* process each group of messages */
1476 num_groups = notify_msg_ctr_numgroups( &messages );
1477 for ( i=0; i<num_groups; i++ )
1478 send_notify2_changes( &messages, i );
1483 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1484 (uint32_t)msg_count ));
1486 notify_msg_ctr_destroy( &messages );
1491 /********************************************************************
1492 Send a message to ourself about new driver being installed
1493 so we can upgrade the information for each printer bound to this
1495 ********************************************************************/
1497 static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
1498 struct messaging_context *msg_ctx)
1500 int len = strlen(drivername);
1505 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1508 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
1509 MSG_PRINTER_DRVUPGRADE,
1510 (const uint8_t *)drivername, len+1);
1515 void srv_spoolss_cleanup(void)
1517 struct printer_session_counter *session_counter;
1519 for (session_counter = counter_list;
1520 session_counter != NULL;
1521 session_counter = counter_list) {
1522 DLIST_REMOVE(counter_list, session_counter);
1523 TALLOC_FREE(session_counter);
1527 /**********************************************************************
1528 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1529 over all printers, upgrading ones as necessary
1530 **********************************************************************/
1532 void do_drv_upgrade_printer(struct messaging_context *msg,
1535 struct server_id server_id,
1538 TALLOC_CTX *tmp_ctx;
1539 struct auth_serversupplied_info *session_info = NULL;
1540 struct spoolss_PrinterInfo2 *pinfo2;
1543 const char *drivername;
1545 int n_services = lp_numservices();
1546 struct dcerpc_binding_handle *b = NULL;
1548 tmp_ctx = talloc_new(NULL);
1549 if (!tmp_ctx) return;
1551 status = make_session_info_system(tmp_ctx, &session_info);
1552 if (!NT_STATUS_IS_OK(status)) {
1553 DEBUG(0, ("do_drv_upgrade_printer: "
1554 "Could not create system session_info\n"));
1558 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, data->length);
1560 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1564 DEBUG(10, ("do_drv_upgrade_printer: "
1565 "Got message for new driver [%s]\n", drivername));
1567 /* Iterate the printer list */
1569 for (snum = 0; snum < n_services; snum++) {
1570 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1574 /* ignore [printers] share */
1575 if (strequal(lp_const_servicename(snum), "printers")) {
1580 result = winreg_printer_binding_handle(tmp_ctx,
1584 if (!W_ERROR_IS_OK(result)) {
1589 result = winreg_get_printer(tmp_ctx, b,
1590 lp_const_servicename(snum),
1593 if (!W_ERROR_IS_OK(result)) {
1597 if (!pinfo2->drivername) {
1601 if (strcmp(drivername, pinfo2->drivername) != 0) {
1605 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1607 /* all we care about currently is the change_id */
1608 result = winreg_printer_update_changeid(tmp_ctx, b,
1609 pinfo2->printername);
1611 if (!W_ERROR_IS_OK(result)) {
1612 DEBUG(3, ("do_drv_upgrade_printer: "
1613 "Failed to update changeid [%s]\n",
1614 win_errstr(result)));
1620 talloc_free(tmp_ctx);
1623 /********************************************************************
1624 Update the cache for all printq's with a registered client
1626 ********************************************************************/
1628 void update_monitored_printq_cache(struct messaging_context *msg_ctx)
1630 struct printer_handle *printer = printers_list;
1633 /* loop through all printers and update the cache where
1634 a client is connected */
1636 if ((printer->printer_type == SPLHND_PRINTER) &&
1637 ((printer->notify.cli_chan != NULL) &&
1638 (printer->notify.cli_chan->active_connections > 0))) {
1639 snum = print_queue_snum(printer->sharename);
1640 print_queue_status(msg_ctx, snum, NULL, NULL);
1643 printer = printer->next;
1649 /****************************************************************
1650 _spoolss_OpenPrinter
1651 ****************************************************************/
1653 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1654 struct spoolss_OpenPrinter *r)
1656 struct spoolss_OpenPrinterEx e;
1659 ZERO_STRUCT(e.in.userlevel);
1661 e.in.printername = r->in.printername;
1662 e.in.datatype = r->in.datatype;
1663 e.in.devmode_ctr = r->in.devmode_ctr;
1664 e.in.access_mask = r->in.access_mask;
1667 e.out.handle = r->out.handle;
1669 werr = _spoolss_OpenPrinterEx(p, &e);
1671 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1672 /* OpenPrinterEx returns this for a bad
1673 * printer name. We must return WERR_INVALID_PRINTER_NAME
1676 werr = WERR_INVALID_PRINTER_NAME;
1682 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1683 struct spoolss_DeviceMode *orig,
1684 struct spoolss_DeviceMode **dest)
1686 struct spoolss_DeviceMode *dm;
1688 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1693 /* copy all values, then duplicate strings and structs */
1696 dm->devicename = talloc_strdup(dm, orig->devicename);
1697 if (!dm->devicename) {
1700 dm->formname = talloc_strdup(dm, orig->formname);
1701 if (!dm->formname) {
1704 if (orig->driverextra_data.data) {
1705 dm->driverextra_data.data =
1706 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1707 orig->driverextra_data.length);
1708 if (!dm->driverextra_data.data) {
1717 /****************************************************************
1718 _spoolss_OpenPrinterEx
1719 ****************************************************************/
1721 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1722 struct spoolss_OpenPrinterEx *r)
1727 struct printer_handle *Printer=NULL;
1731 if (!r->in.printername) {
1732 return WERR_INVALID_PARAM;
1735 if (r->in.level > 3) {
1736 return WERR_INVALID_PARAM;
1738 if ((r->in.level == 1 && !r->in.userlevel.level1) ||
1739 (r->in.level == 2 && !r->in.userlevel.level2) ||
1740 (r->in.level == 3 && !r->in.userlevel.level3)) {
1741 return WERR_INVALID_PARAM;
1744 /* some sanity check because you can open a printer or a print server */
1745 /* aka: \\server\printer or \\server */
1747 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1749 result = open_printer_hnd(p, r->out.handle, r->in.printername, 0);
1750 if (!W_ERROR_IS_OK(result)) {
1751 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1752 "for printer %s\n", r->in.printername));
1753 ZERO_STRUCTP(r->out.handle);
1757 Printer = find_printer_index_by_hnd(p, r->out.handle);
1759 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1760 "handle we created for printer %s\n", r->in.printername));
1761 close_printer_handle(p, r->out.handle);
1762 ZERO_STRUCTP(r->out.handle);
1763 return WERR_INVALID_PARAM;
1767 * First case: the user is opening the print server:
1769 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1770 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1772 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1773 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1774 * or if the user is listed in the smb.conf printer admin parameter.
1776 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1777 * client view printer folder, but does not show the MSAPW.
1779 * Note: this test needs code to check access rights here too. Jeremy
1780 * could you look at this?
1782 * Second case: the user is opening a printer:
1783 * NT doesn't let us connect to a printer if the connecting user
1784 * doesn't have print permission.
1786 * Third case: user is opening a Port Monitor
1787 * access checks same as opening a handle to the print server.
1790 switch (Printer->printer_type )
1793 case SPLHND_PORTMON_TCP:
1794 case SPLHND_PORTMON_LOCAL:
1795 /* Printserver handles use global struct... */
1799 /* Map standard access rights to object specific access rights */
1801 se_map_standard(&r->in.access_mask,
1802 &printserver_std_mapping);
1804 /* Deny any object specific bits that don't apply to print
1805 servers (i.e printer and job specific bits) */
1807 r->in.access_mask &= SEC_MASK_SPECIFIC;
1809 if (r->in.access_mask &
1810 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1811 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1812 close_printer_handle(p, r->out.handle);
1813 ZERO_STRUCTP(r->out.handle);
1814 return WERR_ACCESS_DENIED;
1817 /* Allow admin access */
1819 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1821 if (!lp_ms_add_printer_wizard()) {
1822 close_printer_handle(p, r->out.handle);
1823 ZERO_STRUCTP(r->out.handle);
1824 return WERR_ACCESS_DENIED;
1827 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1828 and not a printer admin, then fail */
1830 if ((p->session_info->utok.uid != sec_initial_uid()) &&
1831 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
1832 !nt_token_check_sid(&global_sid_Builtin_Print_Operators, p->session_info->security_token) &&
1833 !token_contains_name_in_list(
1834 uidtoname(p->session_info->utok.uid),
1835 p->session_info->info3->base.domain.string,
1837 p->session_info->security_token,
1838 lp_printer_admin(snum))) {
1839 close_printer_handle(p, r->out.handle);
1840 ZERO_STRUCTP(r->out.handle);
1841 DEBUG(3,("access DENIED as user is not root, "
1842 "has no printoperator privilege, "
1843 "not a member of the printoperator builtin group and "
1844 "is not in printer admin list"));
1845 return WERR_ACCESS_DENIED;
1848 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1852 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1855 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1856 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1858 /* We fall through to return WERR_OK */
1861 case SPLHND_PRINTER:
1862 /* NT doesn't let us connect to a printer if the connecting user
1863 doesn't have print permission. */
1865 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1866 close_printer_handle(p, r->out.handle);
1867 ZERO_STRUCTP(r->out.handle);
1871 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1872 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1875 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1877 /* map an empty access mask to the minimum access mask */
1878 if (r->in.access_mask == 0x0)
1879 r->in.access_mask = PRINTER_ACCESS_USE;
1882 * If we are not serving the printer driver for this printer,
1883 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1884 * will keep NT clients happy --jerry
1887 if (lp_use_client_driver(snum)
1888 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1890 r->in.access_mask = PRINTER_ACCESS_USE;
1893 /* check smb.conf parameters and the the sec_desc */
1894 raddr = tsocket_address_inet_addr_string(p->remote_address,
1896 if (raddr == NULL) {
1900 rc = get_remote_hostname(p->remote_address,
1906 if (strequal(rhost, "UNKNOWN")) {
1910 if (!allow_access(lp_hostsdeny(snum), lp_hostsallow(snum),
1912 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1913 ZERO_STRUCTP(r->out.handle);
1914 return WERR_ACCESS_DENIED;
1917 if (!user_ok_token(uidtoname(p->session_info->utok.uid), NULL,
1918 p->session_info->security_token, snum) ||
1919 !print_access_check(p->session_info,
1922 r->in.access_mask)) {
1923 DEBUG(3, ("access DENIED for printer open\n"));
1924 close_printer_handle(p, r->out.handle);
1925 ZERO_STRUCTP(r->out.handle);
1926 return WERR_ACCESS_DENIED;
1929 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1930 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1931 close_printer_handle(p, r->out.handle);
1932 ZERO_STRUCTP(r->out.handle);
1933 return WERR_ACCESS_DENIED;
1936 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1937 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1939 r->in.access_mask = PRINTER_ACCESS_USE;
1941 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1942 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1944 winreg_create_printer_internal(p->mem_ctx,
1945 get_session_info_system(),
1947 lp_const_servicename(snum));
1952 /* sanity check to prevent programmer error */
1953 ZERO_STRUCTP(r->out.handle);
1957 Printer->access_granted = r->in.access_mask;
1960 * If the client sent a devmode in the OpenPrinter() call, then
1961 * save it here in case we get a job submission on this handle
1964 if ((Printer->printer_type != SPLHND_SERVER) &&
1965 r->in.devmode_ctr.devmode) {
1966 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1970 #if 0 /* JERRY -- I'm doubtful this is really effective */
1971 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1972 optimization in Windows 2000 clients --jerry */
1974 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1975 && (RA_WIN2K == get_remote_arch()) )
1977 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1978 sys_usleep( 500000 );
1985 /****************************************************************
1986 _spoolss_ClosePrinter
1987 ****************************************************************/
1989 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1990 struct spoolss_ClosePrinter *r)
1992 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1994 if (Printer && Printer->document_started) {
1995 struct spoolss_EndDocPrinter e;
1997 e.in.handle = r->in.handle;
1999 _spoolss_EndDocPrinter(p, &e);
2002 if (!close_printer_handle(p, r->in.handle))
2005 /* clear the returned printer handle. Observed behavior
2006 from Win2k server. Don't think this really matters.
2007 Previous code just copied the value of the closed
2010 ZERO_STRUCTP(r->out.handle);
2015 /****************************************************************
2016 _spoolss_DeletePrinter
2017 ****************************************************************/
2019 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
2020 struct spoolss_DeletePrinter *r)
2022 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2026 if (Printer && Printer->document_started) {
2027 struct spoolss_EndDocPrinter e;
2029 e.in.handle = r->in.handle;
2031 _spoolss_EndDocPrinter(p, &e);
2034 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
2035 winreg_delete_printer_key_internal(p->mem_ctx,
2036 get_session_info_system(),
2038 lp_const_servicename(snum),
2042 result = delete_printer_handle(p, r->in.handle);
2047 /*******************************************************************
2048 * static function to lookup the version id corresponding to an
2049 * long architecture string
2050 ******************************************************************/
2052 static const struct print_architecture_table_node archi_table[]= {
2054 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
2055 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
2056 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
2057 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
2058 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
2059 {"Windows IA64", SPL_ARCH_IA64, 3 },
2060 {"Windows x64", SPL_ARCH_X64, 3 },
2064 static int get_version_id(const char *arch)
2068 for (i=0; archi_table[i].long_archi != NULL; i++)
2070 if (strcmp(arch, archi_table[i].long_archi) == 0)
2071 return (archi_table[i].version);
2077 /****************************************************************
2078 _spoolss_DeletePrinterDriver
2079 ****************************************************************/
2081 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
2082 struct spoolss_DeletePrinterDriver *r)
2085 struct spoolss_DriverInfo8 *info = NULL;
2086 struct spoolss_DriverInfo8 *info_win2k = NULL;
2089 struct dcerpc_binding_handle *b;
2091 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2092 and not a printer admin, then fail */
2094 if ( (p->session_info->utok.uid != sec_initial_uid())
2095 && !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR)
2096 && !token_contains_name_in_list(
2097 uidtoname(p->session_info->utok.uid),
2098 p->session_info->info3->base.domain.string,
2100 p->session_info->security_token,
2101 lp_printer_admin(-1)) )
2103 return WERR_ACCESS_DENIED;
2106 /* check that we have a valid driver name first */
2108 if ((version = get_version_id(r->in.architecture)) == -1)
2109 return WERR_INVALID_ENVIRONMENT;
2111 status = winreg_printer_binding_handle(p->mem_ctx,
2112 get_session_info_system(),
2115 if (!W_ERROR_IS_OK(status)) {
2119 status = winreg_get_driver(p->mem_ctx, b,
2120 r->in.architecture, r->in.driver,
2122 if (!W_ERROR_IS_OK(status)) {
2123 /* try for Win2k driver if "Windows NT x86" */
2125 if ( version == 2 ) {
2128 status = winreg_get_driver(p->mem_ctx, b,
2132 if (!W_ERROR_IS_OK(status)) {
2133 status = WERR_UNKNOWN_PRINTER_DRIVER;
2137 /* otherwise it was a failure */
2139 status = WERR_UNKNOWN_PRINTER_DRIVER;
2145 if (printer_driver_in_use(p->mem_ctx,
2146 get_session_info_system(),
2149 status = WERR_PRINTER_DRIVER_IN_USE;
2154 status = winreg_get_driver(p->mem_ctx, b,
2156 r->in.driver, 3, &info_win2k);
2157 if (W_ERROR_IS_OK(status)) {
2158 /* if we get to here, we now have 2 driver info structures to remove */
2159 /* remove the Win2k driver first*/
2161 status = winreg_del_driver(p->mem_ctx, b,
2163 talloc_free(info_win2k);
2165 /* this should not have failed---if it did, report to client */
2166 if (!W_ERROR_IS_OK(status)) {
2172 status = winreg_del_driver(p->mem_ctx, b,
2181 /****************************************************************
2182 _spoolss_DeletePrinterDriverEx
2183 ****************************************************************/
2185 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
2186 struct spoolss_DeletePrinterDriverEx *r)
2188 struct spoolss_DriverInfo8 *info = NULL;
2189 struct spoolss_DriverInfo8 *info_win2k = NULL;
2193 struct dcerpc_binding_handle *b;
2195 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2196 and not a printer admin, then fail */
2198 if ( (p->session_info->utok.uid != sec_initial_uid())
2199 && !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR)
2200 && !token_contains_name_in_list(
2201 uidtoname(p->session_info->utok.uid),
2202 p->session_info->info3->base.domain.string,
2204 p->session_info->security_token, lp_printer_admin(-1)) )
2206 return WERR_ACCESS_DENIED;
2209 /* check that we have a valid driver name first */
2210 if ((version = get_version_id(r->in.architecture)) == -1) {
2211 /* this is what NT returns */
2212 return WERR_INVALID_ENVIRONMENT;
2215 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2216 version = r->in.version;
2218 status = winreg_printer_binding_handle(p->mem_ctx,
2219 get_session_info_system(),
2222 if (!W_ERROR_IS_OK(status)) {
2226 status = winreg_get_driver(p->mem_ctx, b,
2231 if (!W_ERROR_IS_OK(status)) {
2232 status = WERR_UNKNOWN_PRINTER_DRIVER;
2235 * if the client asked for a specific version,
2236 * or this is something other than Windows NT x86,
2240 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2243 /* try for Win2k driver if "Windows NT x86" */
2246 status = winreg_get_driver(info, b,
2250 if (!W_ERROR_IS_OK(status)) {
2251 status = WERR_UNKNOWN_PRINTER_DRIVER;
2256 if (printer_driver_in_use(info,
2257 get_session_info_system(),
2260 status = WERR_PRINTER_DRIVER_IN_USE;
2265 * we have a couple of cases to consider.
2266 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2267 * then the delete should fail if **any** files overlap with
2269 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2270 * non-overlapping files
2271 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2272 * is set, the do not delete any files
2273 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2276 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2278 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2281 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2282 printer_driver_files_in_use(info,
2283 get_session_info_system(),
2286 /* no idea of the correct error here */
2287 status = WERR_ACCESS_DENIED;
2292 /* also check for W32X86/3 if necessary; maybe we already have? */
2294 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2295 status = winreg_get_driver(info, b,
2297 r->in.driver, 3, &info_win2k);
2298 if (W_ERROR_IS_OK(status)) {
2301 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2302 printer_driver_files_in_use(info,
2303 get_session_info_system(),
2306 /* no idea of the correct error here */
2307 talloc_free(info_win2k);
2308 status = WERR_ACCESS_DENIED;
2312 /* if we get to here, we now have 2 driver info structures to remove */
2313 /* remove the Win2k driver first*/
2315 status = winreg_del_driver(info, b,
2319 /* this should not have failed---if it did, report to client */
2321 if (!W_ERROR_IS_OK(status)) {
2326 * now delete any associated files if delete_files is
2327 * true. Even if this part failes, we return succes
2328 * because the driver doesn not exist any more
2331 delete_driver_files(get_session_info_system(),
2337 status = winreg_del_driver(info, b,
2340 if (!W_ERROR_IS_OK(status)) {
2345 * now delete any associated files if delete_files is
2346 * true. Even if this part failes, we return succes
2347 * because the driver doesn not exist any more
2350 delete_driver_files(get_session_info_system(), info);
2359 /********************************************************************
2360 GetPrinterData on a printer server Handle.
2361 ********************************************************************/
2363 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2365 enum winreg_Type *type,
2366 union spoolss_PrinterData *data)
2368 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2370 if (!strcasecmp_m(value, "W3SvcInstalled")) {
2376 if (!strcasecmp_m(value, "BeepEnabled")) {
2382 if (!strcasecmp_m(value, "EventLog")) {
2384 /* formally was 0x1b */
2389 if (!strcasecmp_m(value, "NetPopup")) {
2395 if (!strcasecmp_m(value, "MajorVersion")) {
2398 /* Windows NT 4.0 seems to not allow uploading of drivers
2399 to a server that reports 0x3 as the MajorVersion.
2400 need to investigate more how Win2k gets around this .
2403 if (RA_WINNT == get_remote_arch()) {
2412 if (!strcasecmp_m(value, "MinorVersion")) {
2419 * uint32_t size = 0x114
2420 * uint32_t major = 5
2421 * uint32_t minor = [0|1]
2422 * uint32_t build = [2195|2600]
2423 * extra unicode string = e.g. "Service Pack 3"
2425 if (!strcasecmp_m(value, "OSVersion")) {
2427 enum ndr_err_code ndr_err;
2428 struct spoolss_OSVersion os;
2430 os.major = 5; /* Windows 2000 == 5.0 */
2432 os.build = 2195; /* build */
2433 os.extra_string = ""; /* leave extra string empty */
2435 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2436 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2437 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2438 return WERR_GENERAL_FAILURE;
2442 data->binary = blob;
2448 if (!strcasecmp_m(value, "DefaultSpoolDirectory")) {
2451 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2452 W_ERROR_HAVE_NO_MEMORY(data->string);
2457 if (!strcasecmp_m(value, "Architecture")) {
2459 data->string = talloc_strdup(mem_ctx,
2460 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2461 W_ERROR_HAVE_NO_MEMORY(data->string);
2466 if (!strcasecmp_m(value, "DsPresent")) {
2469 /* only show the publish check box if we are a
2470 member of a AD domain */
2472 if (lp_security() == SEC_ADS) {
2480 if (!strcasecmp_m(value, "DNSMachineName")) {
2481 const char *hostname = get_mydnsfullname();
2484 return WERR_BADFILE;
2488 data->string = talloc_strdup(mem_ctx, hostname);
2489 W_ERROR_HAVE_NO_MEMORY(data->string);
2496 return WERR_INVALID_PARAM;
2499 /****************************************************************
2500 _spoolss_GetPrinterData
2501 ****************************************************************/
2503 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2504 struct spoolss_GetPrinterData *r)
2506 struct spoolss_GetPrinterDataEx r2;
2508 r2.in.handle = r->in.handle;
2509 r2.in.key_name = "PrinterDriverData";
2510 r2.in.value_name = r->in.value_name;
2511 r2.in.offered = r->in.offered;
2512 r2.out.type = r->out.type;
2513 r2.out.data = r->out.data;
2514 r2.out.needed = r->out.needed;
2516 return _spoolss_GetPrinterDataEx(p, &r2);
2519 /*********************************************************
2520 Connect to the client machine.
2521 **********************************************************/
2523 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2524 struct sockaddr_storage *client_ss, const char *remote_machine)
2527 struct cli_state *the_cli;
2528 struct sockaddr_storage rm_addr;
2529 char addr[INET6_ADDRSTRLEN];
2531 if ( is_zero_addr(client_ss) ) {
2532 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2534 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2535 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2538 print_sockaddr(addr, sizeof(addr), &rm_addr);
2540 rm_addr = *client_ss;
2541 print_sockaddr(addr, sizeof(addr), &rm_addr);
2542 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2546 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2547 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2552 /* setup the connection */
2553 ret = cli_full_connection( &the_cli, lp_netbios_name(), remote_machine,
2554 &rm_addr, 0, "IPC$", "IPC",
2558 0, lp_client_signing());
2560 if ( !NT_STATUS_IS_OK( ret ) ) {
2561 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2566 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2567 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2568 cli_shutdown(the_cli);
2573 * Ok - we have an anonymous connection to the IPC$ share.
2574 * Now start the NT Domain stuff :-).
2577 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2578 if (!NT_STATUS_IS_OK(ret)) {
2579 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2580 remote_machine, nt_errstr(ret)));
2581 cli_shutdown(the_cli);
2588 /***************************************************************************
2589 Connect to the client.
2590 ****************************************************************************/
2592 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2593 uint32_t localprinter,
2594 enum winreg_Type type,
2595 struct policy_handle *handle,
2596 struct notify_back_channel **_chan,
2597 struct sockaddr_storage *client_ss,
2598 struct messaging_context *msg_ctx)
2602 struct notify_back_channel *chan;
2604 for (chan = back_channels; chan; chan = chan->next) {
2605 if (memcmp(&chan->client_address, client_ss,
2606 sizeof(struct sockaddr_storage)) == 0) {
2612 * If it's the first connection, contact the client
2613 * and connect to the IPC$ share anonymously
2616 fstring unix_printer;
2618 /* the +2 is to strip the leading 2 backslashs */
2619 fstrcpy(unix_printer, printer + 2);
2621 chan = talloc_zero(back_channels, struct notify_back_channel);
2625 chan->client_address = *client_ss;
2627 if (!spoolss_connect_to_client(&chan->cli_pipe, client_ss, unix_printer)) {
2631 chan->binding_handle = chan->cli_pipe->binding_handle;
2633 DLIST_ADD(back_channels, chan);
2635 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2636 receive_notify2_message_list);
2637 /* Tell the connections db we're now interested in printer
2638 * notify messages. */
2639 serverid_register_msg_flags(messaging_server_id(msg_ctx),
2640 true, FLAG_MSG_PRINT_NOTIFY);
2644 * Tell the specific printing tdb we want messages for this printer
2645 * by registering our PID.
2648 if (!print_notify_register_pid(snum)) {
2649 DEBUG(0, ("Failed to register our pid for printer %s\n",
2653 status = dcerpc_spoolss_ReplyOpenPrinter(chan->binding_handle,
2662 if (!NT_STATUS_IS_OK(status)) {
2663 DEBUG(5, ("dcerpc_spoolss_ReplyOpenPrinter returned [%s]\n", nt_errstr(status)));
2664 result = ntstatus_to_werror(status);
2665 } else if (!W_ERROR_IS_OK(result)) {
2666 DEBUG(5, ("ReplyOpenPrinter returned [%s]\n", win_errstr(result)));
2669 chan->active_connections++;
2672 return (W_ERROR_IS_OK(result));
2675 /****************************************************************
2676 ****************************************************************/
2678 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2679 const struct spoolss_NotifyOption *r)
2681 struct spoolss_NotifyOption *option;
2688 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2695 if (!option->count) {
2699 option->types = talloc_zero_array(option,
2700 struct spoolss_NotifyOptionType, option->count);
2701 if (!option->types) {
2702 talloc_free(option);
2706 for (i=0; i < option->count; i++) {
2707 option->types[i] = r->types[i];
2709 if (option->types[i].count) {
2710 option->types[i].fields = talloc_zero_array(option,
2711 union spoolss_Field, option->types[i].count);
2712 if (!option->types[i].fields) {
2713 talloc_free(option);
2716 for (k=0; k<option->types[i].count; k++) {
2717 option->types[i].fields[k] =
2718 r->types[i].fields[k];
2726 /****************************************************************
2727 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2729 * before replying OK: status=0 a rpc call is made to the workstation
2730 * asking ReplyOpenPrinter
2732 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2733 * called from api_spoolss_rffpcnex
2734 ****************************************************************/
2736 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2737 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2740 struct spoolss_NotifyOption *option = r->in.notify_options;
2741 struct sockaddr_storage client_ss;
2742 socklen_t client_len;
2744 /* store the notify value in the printer struct */
2746 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2749 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2750 "Invalid handle (%s:%u:%u).\n",
2751 OUR_HANDLE(r->in.handle)));
2755 Printer->notify.flags = r->in.flags;
2756 Printer->notify.options = r->in.options;
2757 Printer->notify.printerlocal = r->in.printer_local;
2758 Printer->notify.msg_ctx = p->msg_ctx;
2760 TALLOC_FREE(Printer->notify.option);
2761 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2763 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2765 /* Connect to the client machine and send a ReplyOpenPrinter */
2767 if ( Printer->printer_type == SPLHND_SERVER)
2769 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2770 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2773 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2774 "remote_address is %s\n",
2775 tsocket_address_string(p->remote_address, p->mem_ctx)));
2777 if (!lp_print_notify_backchannel(snum)) {
2778 DEBUG(10, ("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2779 "backchannel disabled\n"));
2780 return WERR_SERVER_UNAVAILABLE;
2783 client_len = tsocket_address_bsd_sockaddr(p->remote_address,
2784 (struct sockaddr *) &client_ss,
2785 sizeof(struct sockaddr_storage));
2786 if (client_len < 0) {
2790 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2791 Printer->notify.printerlocal, REG_SZ,
2792 &Printer->notify.cli_hnd,
2793 &Printer->notify.cli_chan,
2794 &client_ss, p->msg_ctx)) {
2795 return WERR_SERVER_UNAVAILABLE;
2801 /*******************************************************************
2802 * fill a notify_info_data with the servername
2803 ********************************************************************/
2805 static void spoolss_notify_server_name(struct messaging_context *msg_ctx,
2807 struct spoolss_Notify *data,
2808 print_queue_struct *queue,
2809 struct spoolss_PrinterInfo2 *pinfo2,
2810 TALLOC_CTX *mem_ctx)
2812 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2815 /*******************************************************************
2816 * fill a notify_info_data with the printername (not including the servername).
2817 ********************************************************************/
2819 static void spoolss_notify_printer_name(struct messaging_context *msg_ctx,
2821 struct spoolss_Notify *data,
2822 print_queue_struct *queue,
2823 struct spoolss_PrinterInfo2 *pinfo2,
2824 TALLOC_CTX *mem_ctx)
2826 /* the notify name should not contain the \\server\ part */
2827 const char *p = strrchr(pinfo2->printername, '\\');
2830 p = pinfo2->printername;
2835 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2838 /*******************************************************************
2839 * fill a notify_info_data with the servicename
2840 ********************************************************************/
2842 static void spoolss_notify_share_name(struct messaging_context *msg_ctx,
2844 struct spoolss_Notify *data,
2845 print_queue_struct *queue,
2846 struct spoolss_PrinterInfo2 *pinfo2,
2847 TALLOC_CTX *mem_ctx)
2849 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2852 /*******************************************************************
2853 * fill a notify_info_data with the port name
2854 ********************************************************************/
2856 static void spoolss_notify_port_name(struct messaging_context *msg_ctx,
2858 struct spoolss_Notify *data,
2859 print_queue_struct *queue,
2860 struct spoolss_PrinterInfo2 *pinfo2,
2861 TALLOC_CTX *mem_ctx)
2863 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2866 /*******************************************************************
2867 * fill a notify_info_data with the printername
2868 * but it doesn't exist, have to see what to do
2869 ********************************************************************/
2871 static void spoolss_notify_driver_name(struct messaging_context *msg_ctx,
2873 struct spoolss_Notify *data,
2874 print_queue_struct *queue,
2875 struct spoolss_PrinterInfo2 *pinfo2,
2876 TALLOC_CTX *mem_ctx)
2878 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2881 /*******************************************************************
2882 * fill a notify_info_data with the comment
2883 ********************************************************************/
2885 static void spoolss_notify_comment(struct messaging_context *msg_ctx,
2887 struct spoolss_Notify *data,
2888 print_queue_struct *queue,
2889 struct spoolss_PrinterInfo2 *pinfo2,
2890 TALLOC_CTX *mem_ctx)
2894 if (*pinfo2->comment == '\0') {
2895 p = lp_comment(snum);
2897 p = pinfo2->comment;
2900 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2903 /*******************************************************************
2904 * fill a notify_info_data with the comment
2905 * location = "Room 1, floor 2, building 3"
2906 ********************************************************************/
2908 static void spoolss_notify_location(struct messaging_context *msg_ctx,
2910 struct spoolss_Notify *data,
2911 print_queue_struct *queue,
2912 struct spoolss_PrinterInfo2 *pinfo2,
2913 TALLOC_CTX *mem_ctx)
2915 const char *loc = pinfo2->location;
2918 status = printer_list_get_printer(mem_ctx,
2923 if (NT_STATUS_IS_OK(status)) {
2925 loc = pinfo2->location;
2929 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, loc);
2932 /*******************************************************************
2933 * fill a notify_info_data with the device mode
2934 * jfm:xxxx don't to it for know but that's a real problem !!!
2935 ********************************************************************/
2937 static void spoolss_notify_devmode(struct messaging_context *msg_ctx,
2939 struct spoolss_Notify *data,
2940 print_queue_struct *queue,
2941 struct spoolss_PrinterInfo2 *pinfo2,
2942 TALLOC_CTX *mem_ctx)
2944 /* for a dummy implementation we have to zero the fields */
2945 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2948 /*******************************************************************
2949 * fill a notify_info_data with the separator file name
2950 ********************************************************************/
2952 static void spoolss_notify_sepfile(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_STRING(data, pinfo2->sepfile);
2962 /*******************************************************************
2963 * fill a notify_info_data with the print processor
2964 * jfm:xxxx return always winprint to indicate we don't do anything to it
2965 ********************************************************************/
2967 static void spoolss_notify_print_processor(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_STRING(data, pinfo2->printprocessor);
2977 /*******************************************************************
2978 * fill a notify_info_data with the print processor options
2979 * jfm:xxxx send an empty string
2980 ********************************************************************/
2982 static void spoolss_notify_parameters(struct messaging_context *msg_ctx,
2984 struct spoolss_Notify *data,
2985 print_queue_struct *queue,
2986 struct spoolss_PrinterInfo2 *pinfo2,
2987 TALLOC_CTX *mem_ctx)
2989 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2992 /*******************************************************************
2993 * fill a notify_info_data with the data type
2994 * jfm:xxxx always send RAW as data type
2995 ********************************************************************/
2997 static void spoolss_notify_datatype(struct messaging_context *msg_ctx,
2999 struct spoolss_Notify *data,
3000 print_queue_struct *queue,
3001 struct spoolss_PrinterInfo2 *pinfo2,
3002 TALLOC_CTX *mem_ctx)
3004 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
3007 /*******************************************************************
3008 * fill a notify_info_data with the security descriptor
3009 * jfm:xxxx send an null pointer to say no security desc
3010 * have to implement security before !
3011 ********************************************************************/
3013 static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
3015 struct spoolss_Notify *data,
3016 print_queue_struct *queue,
3017 struct spoolss_PrinterInfo2 *pinfo2,
3018 TALLOC_CTX *mem_ctx)
3020 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
3023 /*******************************************************************
3024 * fill a notify_info_data with the attributes
3025 * jfm:xxxx a samba printer is always shared
3026 ********************************************************************/
3028 static void spoolss_notify_attributes(struct messaging_context *msg_ctx,
3030 struct spoolss_Notify *data,
3031 print_queue_struct *queue,
3032 struct spoolss_PrinterInfo2 *pinfo2,
3033 TALLOC_CTX *mem_ctx)
3035 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
3038 /*******************************************************************
3039 * fill a notify_info_data with the priority
3040 ********************************************************************/
3042 static void spoolss_notify_priority(struct messaging_context *msg_ctx,
3044 struct spoolss_Notify *data,
3045 print_queue_struct *queue,
3046 struct spoolss_PrinterInfo2 *pinfo2,
3047 TALLOC_CTX *mem_ctx)
3049 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
3052 /*******************************************************************
3053 * fill a notify_info_data with the default priority
3054 ********************************************************************/
3056 static void spoolss_notify_default_priority(struct messaging_context *msg_ctx,
3058 struct spoolss_Notify *data,
3059 print_queue_struct *queue,
3060 struct spoolss_PrinterInfo2 *pinfo2,
3061 TALLOC_CTX *mem_ctx)
3063 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
3066 /*******************************************************************
3067 * fill a notify_info_data with the start time
3068 ********************************************************************/
3070 static void spoolss_notify_start_time(struct messaging_context *msg_ctx,
3072 struct spoolss_Notify *data,
3073 print_queue_struct *queue,
3074 struct spoolss_PrinterInfo2 *pinfo2,
3075 TALLOC_CTX *mem_ctx)
3077 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
3080 /*******************************************************************
3081 * fill a notify_info_data with the until time
3082 ********************************************************************/
3084 static void spoolss_notify_until_time(struct messaging_context *msg_ctx,
3086 struct spoolss_Notify *data,
3087 print_queue_struct *queue,
3088 struct spoolss_PrinterInfo2 *pinfo2,
3089 TALLOC_CTX *mem_ctx)
3091 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
3094 /*******************************************************************
3095 * fill a notify_info_data with the status
3096 ********************************************************************/
3098 static void spoolss_notify_status(struct messaging_context *msg_ctx,
3100 struct spoolss_Notify *data,
3101 print_queue_struct *queue,
3102 struct spoolss_PrinterInfo2 *pinfo2,
3103 TALLOC_CTX *mem_ctx)
3105 print_status_struct status;
3107 print_queue_length(msg_ctx, snum, &status);
3108 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3111 /*******************************************************************
3112 * fill a notify_info_data with the number of jobs queued
3113 ********************************************************************/
3115 static void spoolss_notify_cjobs(struct messaging_context *msg_ctx,
3117 struct spoolss_Notify *data,
3118 print_queue_struct *queue,
3119 struct spoolss_PrinterInfo2 *pinfo2,
3120 TALLOC_CTX *mem_ctx)
3122 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3123 data, print_queue_length(msg_ctx, snum, NULL));
3126 /*******************************************************************
3127 * fill a notify_info_data with the average ppm
3128 ********************************************************************/
3130 static void spoolss_notify_average_ppm(struct messaging_context *msg_ctx,
3132 struct spoolss_Notify *data,
3133 print_queue_struct *queue,
3134 struct spoolss_PrinterInfo2 *pinfo2,
3135 TALLOC_CTX *mem_ctx)
3137 /* always respond 8 pages per minutes */
3138 /* a little hard ! */
3139 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
3142 /*******************************************************************
3143 * fill a notify_info_data with username
3144 ********************************************************************/
3146 static void spoolss_notify_username(struct messaging_context *msg_ctx,
3148 struct spoolss_Notify *data,
3149 print_queue_struct *queue,
3150 struct spoolss_PrinterInfo2 *pinfo2,
3151 TALLOC_CTX *mem_ctx)
3153 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3156 /*******************************************************************
3157 * fill a notify_info_data with job status
3158 ********************************************************************/
3160 static void spoolss_notify_job_status(struct messaging_context *msg_ctx,
3162 struct spoolss_Notify *data,
3163 print_queue_struct *queue,
3164 struct spoolss_PrinterInfo2 *pinfo2,
3165 TALLOC_CTX *mem_ctx)
3167 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3170 /*******************************************************************
3171 * fill a notify_info_data with job name
3172 ********************************************************************/
3174 static void spoolss_notify_job_name(struct messaging_context *msg_ctx,
3176 struct spoolss_Notify *data,
3177 print_queue_struct *queue,
3178 struct spoolss_PrinterInfo2 *pinfo2,
3179 TALLOC_CTX *mem_ctx)
3181 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3184 /*******************************************************************
3185 * fill a notify_info_data with job status
3186 ********************************************************************/
3188 static void spoolss_notify_job_status_string(struct messaging_context *msg_ctx,
3190 struct spoolss_Notify *data,
3191 print_queue_struct *queue,
3192 struct spoolss_PrinterInfo2 *pinfo2,
3193 TALLOC_CTX *mem_ctx)
3196 * Now we're returning job status codes we just return a "" here. JRA.
3201 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3204 switch (queue->status) {
3209 p = ""; /* NT provides the paused string */
3218 #endif /* NO LONGER NEEDED. */
3220 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3223 /*******************************************************************
3224 * fill a notify_info_data with job time
3225 ********************************************************************/
3227 static void spoolss_notify_job_time(struct messaging_context *msg_ctx,
3229 struct spoolss_Notify *data,
3230 print_queue_struct *queue,
3231 struct spoolss_PrinterInfo2 *pinfo2,
3232 TALLOC_CTX *mem_ctx)
3234 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3237 /*******************************************************************
3238 * fill a notify_info_data with job size
3239 ********************************************************************/
3241 static void spoolss_notify_job_size(struct messaging_context *msg_ctx,
3243 struct spoolss_Notify *data,
3244 print_queue_struct *queue,
3245 struct spoolss_PrinterInfo2 *pinfo2,
3246 TALLOC_CTX *mem_ctx)
3248 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3251 /*******************************************************************
3252 * fill a notify_info_data with page info
3253 ********************************************************************/
3254 static void spoolss_notify_total_pages(struct messaging_context *msg_ctx,
3256 struct spoolss_Notify *data,
3257 print_queue_struct *queue,
3258 struct spoolss_PrinterInfo2 *pinfo2,
3259 TALLOC_CTX *mem_ctx)
3261 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3264 /*******************************************************************
3265 * fill a notify_info_data with pages printed info.
3266 ********************************************************************/
3267 static void spoolss_notify_pages_printed(struct messaging_context *msg_ctx,
3269 struct spoolss_Notify *data,
3270 print_queue_struct *queue,
3271 struct spoolss_PrinterInfo2 *pinfo2,
3272 TALLOC_CTX *mem_ctx)
3274 /* Add code when back-end tracks this */
3275 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3278 /*******************************************************************
3279 Fill a notify_info_data with job position.
3280 ********************************************************************/
3282 static void spoolss_notify_job_position(struct messaging_context *msg_ctx,
3284 struct spoolss_Notify *data,
3285 print_queue_struct *queue,
3286 struct spoolss_PrinterInfo2 *pinfo2,
3287 TALLOC_CTX *mem_ctx)
3289 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3292 /*******************************************************************
3293 Fill a notify_info_data with submitted time.
3294 ********************************************************************/
3296 static void spoolss_notify_submitted_time(struct messaging_context *msg_ctx,
3298 struct spoolss_Notify *data,
3299 print_queue_struct *queue,
3300 struct spoolss_PrinterInfo2 *pinfo2,
3301 TALLOC_CTX *mem_ctx)
3303 data->data.string.string = NULL;
3304 data->data.string.size = 0;
3306 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3307 &data->data.string.string,
3308 &data->data.string.size);
3312 struct s_notify_info_data_table
3314 enum spoolss_NotifyType type;
3317 enum spoolss_NotifyTable variable_type;
3318 void (*fn) (struct messaging_context *msg_ctx,
3319 int snum, struct spoolss_Notify *data,
3320 print_queue_struct *queue,
3321 struct spoolss_PrinterInfo2 *pinfo2,
3322 TALLOC_CTX *mem_ctx);
3325 /* A table describing the various print notification constants and
3326 whether the notification data is a pointer to a variable sized
3327 buffer, a one value uint32_t or a two value uint32_t. */
3329 static const struct s_notify_info_data_table notify_info_data_table[] =
3331 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3332 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3333 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3334 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3335 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3336 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3337 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3338 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3339 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3340 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3341 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3342 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3343 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3344 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3345 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3346 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3347 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3348 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3349 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3350 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3351 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3352 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3353 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3354 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3355 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3356 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3357 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3358 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3359 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3360 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3361 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3362 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3363 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3364 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3365 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3366 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3367 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3368 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3369 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3370 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3371 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3372 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3373 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3374 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3375 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3376 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3377 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3378 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3379 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3382 /*******************************************************************
3383 Return the variable_type of info_data structure.
3384 ********************************************************************/
3386 static enum spoolss_NotifyTable variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3391 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3392 if ( (notify_info_data_table[i].type == type) &&
3393 (notify_info_data_table[i].field == field) ) {
3394 return notify_info_data_table[i].variable_type;
3398 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3400 return (enum spoolss_NotifyTable) 0;
3403 /****************************************************************************
3404 ****************************************************************************/
3406 static bool search_notify(enum spoolss_NotifyType type,
3412 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3413 if (notify_info_data_table[i].type == type &&
3414 notify_info_data_table[i].field == field &&
3415 notify_info_data_table[i].fn != NULL) {
3424 /****************************************************************************
3425 ****************************************************************************/
3427 static void construct_info_data(struct spoolss_Notify *info_data,
3428 enum spoolss_NotifyType type,
3429 uint16_t field, int id)
3431 info_data->type = type;
3432 info_data->field.field = field;
3433 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3434 info_data->job_id = id;
3437 /*******************************************************************
3439 * fill a notify_info struct with info asked
3441 ********************************************************************/
3443 static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
3444 struct printer_handle *print_hnd,
3445 struct spoolss_NotifyInfo *info,
3446 struct spoolss_PrinterInfo2 *pinfo2,
3448 const struct spoolss_NotifyOptionType *option_type,
3450 TALLOC_CTX *mem_ctx)
3453 enum spoolss_NotifyType type;
3456 struct spoolss_Notify *current_data;
3458 type = option_type->type;
3460 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3461 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3462 option_type->count, lp_servicename(snum)));
3464 for(field_num=0; field_num < option_type->count; field_num++) {
3465 field = option_type->fields[field_num].field;
3467 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3469 if (!search_notify(type, field, &j) )
3472 info->notifies = talloc_realloc(info, info->notifies,
3473 struct spoolss_Notify,
3475 if (info->notifies == NULL) {
3476 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3480 current_data = &info->notifies[info->count];
3482 construct_info_data(current_data, type, field, id);
3484 DEBUG(10, ("construct_notify_printer_info: "
3485 "calling [%s] snum=%d printername=[%s])\n",
3486 notify_info_data_table[j].name, snum,
3487 pinfo2->printername));
3489 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3490 NULL, pinfo2, mem_ctx);
3498 /*******************************************************************
3500 * fill a notify_info struct with info asked
3502 ********************************************************************/
3504 static bool construct_notify_jobs_info(struct messaging_context *msg_ctx,
3505 print_queue_struct *queue,
3506 struct spoolss_NotifyInfo *info,
3507 struct spoolss_PrinterInfo2 *pinfo2,
3509 const struct spoolss_NotifyOptionType *option_type,
3511 TALLOC_CTX *mem_ctx)
3514 enum spoolss_NotifyType type;
3516 struct spoolss_Notify *current_data;
3518 DEBUG(4,("construct_notify_jobs_info\n"));
3520 type = option_type->type;
3522 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3523 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3524 option_type->count));
3526 for(field_num=0; field_num<option_type->count; field_num++) {
3527 field = option_type->fields[field_num].field;
3529 if (!search_notify(type, field, &j) )
3532 info->notifies = talloc_realloc(info, info->notifies,
3533 struct spoolss_Notify,
3535 if (info->notifies == NULL) {
3536 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3540 current_data=&(info->notifies[info->count]);
3542 construct_info_data(current_data, type, field, id);
3543 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3544 queue, pinfo2, mem_ctx);
3552 * JFM: The enumeration is not that simple, it's even non obvious.
3554 * let's take an example: I want to monitor the PRINTER SERVER for
3555 * the printer's name and the number of jobs currently queued.
3556 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3557 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3559 * I have 3 printers on the back of my server.
3561 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3564 * 1 printer 1 name 1
3565 * 2 printer 1 cjob 1
3566 * 3 printer 2 name 2
3567 * 4 printer 2 cjob 2
3568 * 5 printer 3 name 3
3569 * 6 printer 3 name 3
3571 * that's the print server case, the printer case is even worse.
3574 /*******************************************************************
3576 * enumerate all printers on the printserver
3577 * fill a notify_info struct with info asked
3579 ********************************************************************/
3581 static WERROR printserver_notify_info(struct pipes_struct *p,
3582 struct policy_handle *hnd,
3583 struct spoolss_NotifyInfo *info,
3584 TALLOC_CTX *mem_ctx)
3587 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3588 int n_services=lp_numservices();
3590 struct spoolss_NotifyOption *option;
3591 struct spoolss_NotifyOptionType option_type;
3592 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3595 DEBUG(4,("printserver_notify_info\n"));
3600 option = Printer->notify.option;
3603 info->notifies = NULL;
3606 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3607 sending a ffpcn() request first */
3612 for (i=0; i<option->count; i++) {
3613 option_type = option->types[i];
3615 if (option_type.type != PRINTER_NOTIFY_TYPE)
3618 for (snum = 0; snum < n_services; snum++) {
3619 if (!lp_browseable(snum) ||
3620 !lp_snum_ok(snum) ||
3621 !lp_print_ok(snum)) {
3622 continue; /* skip */
3625 /* Maybe we should use the SYSTEM session_info here... */
3626 result = winreg_get_printer_internal(mem_ctx,
3627 get_session_info_system(),
3629 lp_servicename(snum),
3631 if (!W_ERROR_IS_OK(result)) {
3632 DEBUG(4, ("printserver_notify_info: "
3633 "Failed to get printer [%s]\n",
3634 lp_servicename(snum)));
3639 construct_notify_printer_info(p->msg_ctx,
3645 TALLOC_FREE(pinfo2);
3651 * Debugging information, don't delete.
3654 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3655 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3656 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3658 for (i=0; i<info->count; i++) {
3659 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3660 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3661 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3668 /*******************************************************************
3670 * fill a notify_info struct with info asked
3672 ********************************************************************/
3674 static WERROR printer_notify_info(struct pipes_struct *p,
3675 struct policy_handle *hnd,
3676 struct spoolss_NotifyInfo *info,
3677 TALLOC_CTX *mem_ctx)
3680 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3683 struct spoolss_NotifyOption *option;
3684 struct spoolss_NotifyOptionType option_type;
3686 print_queue_struct *queue=NULL;
3687 print_status_struct status;
3688 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3691 DEBUG(4,("printer_notify_info\n"));
3696 option = Printer->notify.option;
3700 info->notifies = NULL;
3703 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3704 sending a ffpcn() request first */
3709 if (!get_printer_snum(p, hnd, &snum, NULL)) {
3713 /* Maybe we should use the SYSTEM session_info here... */
3714 result = winreg_get_printer_internal(mem_ctx,
3715 get_session_info_system(),
3717 lp_servicename(snum), &pinfo2);
3718 if (!W_ERROR_IS_OK(result)) {
3722 for (i=0; i<option->count; i++) {
3723 option_type = option->types[i];
3725 switch (option_type.type) {
3726 case PRINTER_NOTIFY_TYPE:
3727 if (construct_notify_printer_info(p->msg_ctx,
3736 case JOB_NOTIFY_TYPE:
3738 count = print_queue_status(p->msg_ctx, snum, &queue,
3741 for (j=0; j<count; j++) {
3742 construct_notify_jobs_info(p->msg_ctx,
3756 * Debugging information, don't delete.
3759 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3760 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3761 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3763 for (i=0; i<info->count; i++) {
3764 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3765 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3766 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3770 talloc_free(pinfo2);
3774 /****************************************************************
3775 _spoolss_RouterRefreshPrinterChangeNotify
3776 ****************************************************************/
3778 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3779 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3781 struct spoolss_NotifyInfo *info;
3783 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
3784 WERROR result = WERR_BADFID;
3786 /* we always have a spoolss_NotifyInfo struct */
3787 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3789 result = WERR_NOMEM;
3793 *r->out.info = info;
3796 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3797 "Invalid handle (%s:%u:%u).\n",
3798 OUR_HANDLE(r->in.handle)));
3802 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3805 * We are now using the change value, and
3806 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3807 * I don't have a global notification system, I'm sending back all the
3808 * information even when _NOTHING_ has changed.
3811 /* We need to keep track of the change value to send back in
3812 RRPCN replies otherwise our updates are ignored. */
3814 Printer->notify.fnpcn = true;
3816 if (Printer->notify.cli_chan != NULL &&
3817 Printer->notify.cli_chan->active_connections > 0) {
3818 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3819 "Saving change value in request [%x]\n",
3821 Printer->notify.change = r->in.change_low;
3824 /* just ignore the spoolss_NotifyOption */
3826 switch (Printer->printer_type) {
3828 result = printserver_notify_info(p, r->in.handle,
3832 case SPLHND_PRINTER:
3833 result = printer_notify_info(p, r->in.handle,
3838 Printer->notify.fnpcn = false;
3844 /********************************************************************
3845 ********************************************************************/
3847 static WERROR create_printername(TALLOC_CTX *mem_ctx,
3848 const char *servername,
3849 const char *printername,
3850 const char **printername_p)
3852 /* FIXME: add lp_force_printername() */
3854 if (servername == NULL) {
3855 *printername_p = talloc_strdup(mem_ctx, printername);
3856 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3860 if (servername[0] == '\\' && servername[1] == '\\') {
3864 *printername_p = talloc_asprintf(mem_ctx, "\\\\%s\\%s", servername, printername);
3865 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3870 /********************************************************************
3871 ********************************************************************/
3873 static void compose_devicemode_devicename(struct spoolss_DeviceMode *dm,
3874 const char *printername)
3880 dm->devicename = talloc_strndup(dm, printername,
3881 MIN(strlen(printername), 31));
3884 /********************************************************************
3885 * construct_printer_info_0
3886 * fill a printer_info_0 struct
3887 ********************************************************************/
3889 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3890 const struct auth_serversupplied_info *session_info,
3891 struct messaging_context *msg_ctx,
3892 struct spoolss_PrinterInfo2 *info2,
3893 const char *servername,
3894 struct spoolss_PrinterInfo0 *r,
3898 struct printer_session_counter *session_counter;
3899 struct timeval setuptime;
3900 print_status_struct status;
3903 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3904 if (!W_ERROR_IS_OK(result)) {
3909 r->servername = talloc_strdup(mem_ctx, servername);
3910 W_ERROR_HAVE_NO_MEMORY(r->servername);
3912 r->servername = NULL;
3915 count = print_queue_length(msg_ctx, snum, &status);
3917 /* check if we already have a counter for this printer */
3918 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3919 if (session_counter->snum == snum)
3923 /* it's the first time, add it to the list */
3924 if (session_counter == NULL) {
3925 session_counter = talloc_zero(counter_list, struct printer_session_counter);
3926 W_ERROR_HAVE_NO_MEMORY(session_counter);
3927 session_counter->snum = snum;
3928 session_counter->counter = 0;
3929 DLIST_ADD(counter_list, session_counter);
3933 session_counter->counter++;
3939 get_startup_time(&setuptime);
3940 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3943 * the global_counter should be stored in a TDB as it's common to all the clients
3944 * and should be zeroed on samba startup
3946 r->global_counter = session_counter->counter;
3948 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3949 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3950 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3951 r->free_build = SPOOLSS_RELEASE_BUILD;
3953 r->max_spooling = 0;
3954 r->session_counter = session_counter->counter;
3955 r->num_error_out_of_paper = 0x0;
3956 r->num_error_not_ready = 0x0; /* number of print failure */
3958 r->number_of_processors = 0x1;
3959 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3960 r->high_part_total_bytes = 0x0;
3962 /* ChangeID in milliseconds*/
3963 winreg_printer_get_changeid_internal(mem_ctx, session_info, msg_ctx,
3964 info2->sharename, &r->change_id);
3966 r->last_error = WERR_OK;
3967 r->status = nt_printq_status(status.status);
3968 r->enumerate_network_printers = 0x0;
3969 r->c_setprinter = 0x0;
3970 r->processor_architecture = PROCESSOR_ARCHITECTURE_INTEL;
3971 r->processor_level = 0x6; /* 6 ???*/
3980 /********************************************************************
3981 * construct_printer_info1
3982 * fill a spoolss_PrinterInfo1 struct
3983 ********************************************************************/
3985 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3986 const struct spoolss_PrinterInfo2 *info2,
3988 const char *servername,
3989 struct spoolss_PrinterInfo1 *r,
3996 if (info2->comment == NULL || info2->comment[0] == '\0') {
3997 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3999 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
4001 W_ERROR_HAVE_NO_MEMORY(r->comment);
4003 result = create_printername(mem_ctx, servername, info2->printername, &r->name);
4004 if (!W_ERROR_IS_OK(result)) {
4008 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
4012 W_ERROR_HAVE_NO_MEMORY(r->description);
4017 /********************************************************************
4018 * construct_printer_info2
4019 * fill a spoolss_PrinterInfo2 struct
4020 ********************************************************************/
4022 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
4023 struct messaging_context *msg_ctx,
4024 const struct spoolss_PrinterInfo2 *info2,
4025 const char *servername,
4026 struct spoolss_PrinterInfo2 *r,
4030 print_status_struct status;
4033 count = print_queue_length(msg_ctx, snum, &status);
4036 r->servername = talloc_strdup(mem_ctx, servername);
4037 W_ERROR_HAVE_NO_MEMORY(r->servername);
4039 r->servername = NULL;
4042 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4043 if (!W_ERROR_IS_OK(result)) {
4047 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
4048 W_ERROR_HAVE_NO_MEMORY(r->sharename);
4049 r->portname = talloc_strdup(mem_ctx, info2->portname);
4050 W_ERROR_HAVE_NO_MEMORY(r->portname);
4051 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
4052 W_ERROR_HAVE_NO_MEMORY(r->drivername);
4054 if (info2->comment[0] == '\0') {
4055 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
4057 r->comment = talloc_strdup(mem_ctx, info2->comment);
4059 W_ERROR_HAVE_NO_MEMORY(r->comment);
4061 r->location = talloc_strdup(mem_ctx, info2->location);
4062 if (info2->location[0] == '\0') {
4063 const char *loc = NULL;
4066 nt_status = printer_list_get_printer(mem_ctx,
4071 if (NT_STATUS_IS_OK(nt_status)) {
4073 r->location = talloc_strdup(mem_ctx, loc);
4077 W_ERROR_HAVE_NO_MEMORY(r->location);
4079 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
4080 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
4081 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
4082 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
4083 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
4084 W_ERROR_HAVE_NO_MEMORY(r->datatype);
4085 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
4086 W_ERROR_HAVE_NO_MEMORY(r->parameters);
4088 r->attributes = info2->attributes;
4090 r->priority = info2->priority;
4091 r->defaultpriority = info2->defaultpriority;
4092 r->starttime = info2->starttime;
4093 r->untiltime = info2->untiltime;
4094 r->status = nt_printq_status(status.status);
4096 r->averageppm = info2->averageppm;
4098 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
4100 DEBUG(8,("Returning NULL Devicemode!\n"));
4103 compose_devicemode_devicename(r->devmode, r->printername);
4107 if (info2->secdesc != NULL) {
4108 /* don't use talloc_steal() here unless you do a deep steal of all
4109 the SEC_DESC members */
4111 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4117 /********************************************************************
4118 * construct_printer_info3
4119 * fill a spoolss_PrinterInfo3 struct
4120 ********************************************************************/
4122 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
4123 const struct spoolss_PrinterInfo2 *info2,
4124 const char *servername,
4125 struct spoolss_PrinterInfo3 *r,
4128 /* These are the components of the SD we are returning. */
4130 if (info2->secdesc != NULL) {
4131 /* don't use talloc_steal() here unless you do a deep steal of all
4132 the SEC_DESC members */
4134 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4135 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
4141 /********************************************************************
4142 * construct_printer_info4
4143 * fill a spoolss_PrinterInfo4 struct
4144 ********************************************************************/
4146 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4147 const struct spoolss_PrinterInfo2 *info2,
4148 const char *servername,
4149 struct spoolss_PrinterInfo4 *r,
4154 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4155 if (!W_ERROR_IS_OK(result)) {
4160 r->servername = talloc_strdup(mem_ctx, servername);
4161 W_ERROR_HAVE_NO_MEMORY(r->servername);
4163 r->servername = NULL;
4166 r->attributes = info2->attributes;
4171 /********************************************************************
4172 * construct_printer_info5
4173 * fill a spoolss_PrinterInfo5 struct
4174 ********************************************************************/
4176 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4177 const struct spoolss_PrinterInfo2 *info2,
4178 const char *servername,
4179 struct spoolss_PrinterInfo5 *r,
4184 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4185 if (!W_ERROR_IS_OK(result)) {
4189 r->portname = talloc_strdup(mem_ctx, info2->portname);
4190 W_ERROR_HAVE_NO_MEMORY(r->portname);
4192 r->attributes = info2->attributes;
4194 /* these two are not used by NT+ according to MSDN */
4195 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4196 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4201 /********************************************************************
4202 * construct_printer_info_6
4203 * fill a spoolss_PrinterInfo6 struct
4204 ********************************************************************/
4206 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4207 struct messaging_context *msg_ctx,
4208 const struct spoolss_PrinterInfo2 *info2,
4209 const char *servername,
4210 struct spoolss_PrinterInfo6 *r,
4213 print_status_struct status;
4215 print_queue_length(msg_ctx, snum, &status);
4217 r->status = nt_printq_status(status.status);
4222 /********************************************************************
4223 * construct_printer_info7
4224 * fill a spoolss_PrinterInfo7 struct
4225 ********************************************************************/
4227 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4228 struct messaging_context *msg_ctx,
4229 const char *servername,
4230 struct spoolss_PrinterInfo7 *r,
4233 struct auth_serversupplied_info *session_info;
4237 status = make_session_info_system(mem_ctx, &session_info);
4238 if (!NT_STATUS_IS_OK(status)) {
4239 DEBUG(0, ("construct_printer_info7: "
4240 "Could not create system session_info\n"));
4244 if (is_printer_published(mem_ctx, session_info, msg_ctx,
4246 lp_servicename(snum), &guid, NULL)) {
4247 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4248 r->action = DSPRINT_PUBLISH;
4250 r->guid = talloc_strdup(mem_ctx, "");
4251 r->action = DSPRINT_UNPUBLISH;
4253 W_ERROR_HAVE_NO_MEMORY(r->guid);
4255 TALLOC_FREE(session_info);
4259 /********************************************************************
4260 * construct_printer_info8
4261 * fill a spoolss_PrinterInfo8 struct
4262 ********************************************************************/
4264 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4265 const struct spoolss_PrinterInfo2 *info2,
4266 const char *servername,
4267 struct spoolss_DeviceModeInfo *r,
4271 const char *printername;
4273 result = create_printername(mem_ctx, servername, info2->printername, &printername);
4274 if (!W_ERROR_IS_OK(result)) {
4278 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
4280 DEBUG(8,("Returning NULL Devicemode!\n"));
4283 compose_devicemode_devicename(r->devmode, printername);
4289 /********************************************************************
4290 ********************************************************************/
4292 static bool snum_is_shared_printer(int snum)
4294 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4297 /********************************************************************
4298 Spoolss_enumprinters.
4299 ********************************************************************/
4301 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4302 const struct auth_serversupplied_info *session_info,
4303 struct messaging_context *msg_ctx,
4304 const char *servername,
4307 union spoolss_PrinterInfo **info_p,
4311 int n_services = lp_numservices();
4312 union spoolss_PrinterInfo *info = NULL;
4314 WERROR result = WERR_OK;
4315 struct dcerpc_binding_handle *b = NULL;
4320 for (snum = 0; snum < n_services; snum++) {
4322 const char *printer;
4323 struct spoolss_PrinterInfo2 *info2;
4325 if (!snum_is_shared_printer(snum)) {
4329 printer = lp_const_servicename(snum);
4331 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4335 result = winreg_printer_binding_handle(mem_ctx,
4339 if (!W_ERROR_IS_OK(result)) {
4344 result = winreg_create_printer(mem_ctx, b,
4346 if (!W_ERROR_IS_OK(result)) {
4350 info = talloc_realloc(mem_ctx, info,
4351 union spoolss_PrinterInfo,
4354 result = WERR_NOMEM;
4358 result = winreg_get_printer(mem_ctx, b,
4360 if (!W_ERROR_IS_OK(result)) {
4366 result = construct_printer_info0(info, session_info,
4369 &info[count].info0, snum);
4372 result = construct_printer_info1(info, info2, flags,
4374 &info[count].info1, snum);
4377 result = construct_printer_info2(info, msg_ctx, info2,
4379 &info[count].info2, snum);
4382 result = construct_printer_info4(info, info2,
4384 &info[count].info4, snum);
4387 result = construct_printer_info5(info, info2,
4389 &info[count].info5, snum);
4393 result = WERR_UNKNOWN_LEVEL;
4397 if (!W_ERROR_IS_OK(result)) {
4408 if (!W_ERROR_IS_OK(result)) {
4418 /********************************************************************
4419 * handle enumeration of printers at level 0
4420 ********************************************************************/
4422 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4423 const struct auth_serversupplied_info *session_info,
4424 struct messaging_context *msg_ctx,
4426 const char *servername,
4427 union spoolss_PrinterInfo **info,
4430 DEBUG(4,("enum_all_printers_info_0\n"));
4432 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4433 servername, 0, flags, info, count);
4437 /********************************************************************
4438 ********************************************************************/
4440 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4441 const struct auth_serversupplied_info *session_info,
4442 struct messaging_context *msg_ctx,
4443 const char *servername,
4445 union spoolss_PrinterInfo **info,
4448 DEBUG(4,("enum_all_printers_info_1\n"));
4450 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4451 servername, 1, flags, info, count);
4454 /********************************************************************
4455 enum_all_printers_info_1_local.
4456 *********************************************************************/
4458 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4459 const struct auth_serversupplied_info *session_info,
4460 struct messaging_context *msg_ctx,
4461 const char *servername,
4462 union spoolss_PrinterInfo **info,
4465 DEBUG(4,("enum_all_printers_info_1_local\n"));
4467 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4468 servername, PRINTER_ENUM_ICON8, info, count);
4471 /********************************************************************
4472 enum_all_printers_info_1_name.
4473 *********************************************************************/
4475 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4476 const struct auth_serversupplied_info *session_info,
4477 struct messaging_context *msg_ctx,
4478 const char *servername,
4479 union spoolss_PrinterInfo **info,
4482 const char *s = servername;
4484 DEBUG(4,("enum_all_printers_info_1_name\n"));
4486 if ((servername[0] == '\\') && (servername[1] == '\\')) {
4490 if (!is_myname_or_ipaddr(s)) {
4491 return WERR_INVALID_NAME;
4494 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4495 servername, PRINTER_ENUM_ICON8, info, count);
4498 /********************************************************************
4499 enum_all_printers_info_1_network.
4500 *********************************************************************/
4502 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4503 const struct auth_serversupplied_info *session_info,
4504 struct messaging_context *msg_ctx,
4505 const char *servername,
4506 union spoolss_PrinterInfo **info,
4509 const char *s = servername;
4511 DEBUG(4,("enum_all_printers_info_1_network\n"));
4513 /* If we respond to a enum_printers level 1 on our name with flags
4514 set to PRINTER_ENUM_REMOTE with a list of printers then these
4515 printers incorrectly appear in the APW browse list.
4516 Specifically the printers for the server appear at the workgroup
4517 level where all the other servers in the domain are
4518 listed. Windows responds to this call with a
4519 WERR_CAN_NOT_COMPLETE so we should do the same. */
4521 if (servername[0] == '\\' && servername[1] == '\\') {
4525 if (is_myname_or_ipaddr(s)) {
4526 return WERR_CAN_NOT_COMPLETE;
4529 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4530 servername, PRINTER_ENUM_NAME, info, count);
4533 /********************************************************************
4534 * api_spoolss_enumprinters
4536 * called from api_spoolss_enumprinters (see this to understand)
4537 ********************************************************************/
4539 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4540 const struct auth_serversupplied_info *session_info,
4541 struct messaging_context *msg_ctx,
4542 const char *servername,
4543 union spoolss_PrinterInfo **info,
4546 DEBUG(4,("enum_all_printers_info_2\n"));
4548 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4549 servername, 2, 0, info, count);
4552 /********************************************************************
4553 * handle enumeration of printers at level 1
4554 ********************************************************************/
4556 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4557 const struct auth_serversupplied_info *session_info,
4558 struct messaging_context *msg_ctx,
4560 const char *servername,
4561 union spoolss_PrinterInfo **info,
4564 /* Not all the flags are equals */
4566 if (flags & PRINTER_ENUM_LOCAL) {
4567 return enum_all_printers_info_1_local(mem_ctx, session_info,
4568 msg_ctx, servername, info, count);
4571 if (flags & PRINTER_ENUM_NAME) {
4572 return enum_all_printers_info_1_name(mem_ctx, session_info,
4573 msg_ctx, servername, info,
4577 if (flags & PRINTER_ENUM_NETWORK) {
4578 return enum_all_printers_info_1_network(mem_ctx, session_info,
4579 msg_ctx, servername, info,
4583 return WERR_OK; /* NT4sp5 does that */
4586 /********************************************************************
4587 * handle enumeration of printers at level 2
4588 ********************************************************************/
4590 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4591 const struct auth_serversupplied_info *session_info,
4592 struct messaging_context *msg_ctx,
4594 const char *servername,
4595 union spoolss_PrinterInfo **info,
4598 if (flags & PRINTER_ENUM_LOCAL) {
4600 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4605 if (flags & PRINTER_ENUM_NAME) {
4606 if (servername && !is_myname_or_ipaddr(canon_servername(servername))) {
4607 return WERR_INVALID_NAME;
4610 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4615 if (flags & PRINTER_ENUM_REMOTE) {
4616 return WERR_UNKNOWN_LEVEL;
4622 /********************************************************************
4623 * handle enumeration of printers at level 4
4624 ********************************************************************/
4626 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4627 const struct auth_serversupplied_info *session_info,
4628 struct messaging_context *msg_ctx,
4630 const char *servername,
4631 union spoolss_PrinterInfo **info,
4634 DEBUG(4,("enum_all_printers_info_4\n"));
4636 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4637 servername, 4, flags, info, count);
4641 /********************************************************************
4642 * handle enumeration of printers at level 5
4643 ********************************************************************/
4645 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4646 const struct auth_serversupplied_info *session_info,
4647 struct messaging_context *msg_ctx,
4649 const char *servername,
4650 union spoolss_PrinterInfo **info,
4653 DEBUG(4,("enum_all_printers_info_5\n"));
4655 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4656 servername, 5, flags, info, count);
4659 /****************************************************************
4660 _spoolss_EnumPrinters
4661 ****************************************************************/
4663 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4664 struct spoolss_EnumPrinters *r)
4666 const struct auth_serversupplied_info *session_info = get_session_info_system();
4669 /* that's an [in out] buffer */
4671 if (!r->in.buffer && (r->in.offered != 0)) {
4672 return WERR_INVALID_PARAM;
4675 DEBUG(4,("_spoolss_EnumPrinters\n"));
4679 *r->out.info = NULL;
4683 * flags==PRINTER_ENUM_NAME
4684 * if name=="" then enumerates all printers
4685 * if name!="" then enumerate the printer
4686 * flags==PRINTER_ENUM_REMOTE
4687 * name is NULL, enumerate printers
4688 * Level 2: name!="" enumerates printers, name can't be NULL
4689 * Level 3: doesn't exist
4690 * Level 4: does a local registry lookup
4691 * Level 5: same as Level 2
4694 if (r->in.server && r->in.server[0] == '\0') {
4695 r->in.server = NULL;
4698 switch (r->in.level) {
4700 result = enumprinters_level0(p->mem_ctx, session_info,
4701 p->msg_ctx, r->in.flags,
4703 r->out.info, r->out.count);
4706 result = enumprinters_level1(p->mem_ctx, session_info,
4707 p->msg_ctx, r->in.flags,
4709 r->out.info, r->out.count);
4712 result = enumprinters_level2(p->mem_ctx, session_info,
4713 p->msg_ctx, r->in.flags,
4715 r->out.info, r->out.count);
4718 result = enumprinters_level4(p->mem_ctx, session_info,
4719 p->msg_ctx, r->in.flags,
4721 r->out.info, r->out.count);
4724 result = enumprinters_level5(p->mem_ctx, session_info,
4725 p->msg_ctx, r->in.flags,
4727 r->out.info, r->out.count);
4730 return WERR_UNKNOWN_LEVEL;
4733 if (!W_ERROR_IS_OK(result)) {
4737 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4738 spoolss_EnumPrinters,
4739 *r->out.info, r->in.level,
4741 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4742 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4744 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4747 /****************************************************************
4749 ****************************************************************/
4751 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4752 struct spoolss_GetPrinter *r)
4754 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
4755 struct spoolss_PrinterInfo2 *info2 = NULL;
4756 WERROR result = WERR_OK;
4759 /* that's an [in out] buffer */
4761 if (!r->in.buffer && (r->in.offered != 0)) {
4762 return WERR_INVALID_PARAM;
4767 if (Printer == NULL) {
4771 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4775 result = winreg_get_printer_internal(p->mem_ctx,
4776 get_session_info_system(),
4778 lp_const_servicename(snum),
4780 if (!W_ERROR_IS_OK(result)) {
4784 switch (r->in.level) {
4786 result = construct_printer_info0(p->mem_ctx,
4787 get_session_info_system(),
4790 Printer->servername,
4791 &r->out.info->info0,
4795 result = construct_printer_info1(p->mem_ctx, info2,
4797 Printer->servername,
4798 &r->out.info->info1, snum);
4801 result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
4802 Printer->servername,
4803 &r->out.info->info2, snum);
4806 result = construct_printer_info3(p->mem_ctx, info2,
4807 Printer->servername,
4808 &r->out.info->info3, snum);
4811 result = construct_printer_info4(p->mem_ctx, info2,
4812 Printer->servername,
4813 &r->out.info->info4, snum);
4816 result = construct_printer_info5(p->mem_ctx, info2,
4817 Printer->servername,
4818 &r->out.info->info5, snum);
4821 result = construct_printer_info6(p->mem_ctx, p->msg_ctx, info2,
4822 Printer->servername,
4823 &r->out.info->info6, snum);
4826 result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
4827 Printer->servername,
4828 &r->out.info->info7, snum);
4831 result = construct_printer_info8(p->mem_ctx, info2,
4832 Printer->servername,
4833 &r->out.info->info8, snum);
4836 result = WERR_UNKNOWN_LEVEL;
4841 if (!W_ERROR_IS_OK(result)) {
4842 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4843 r->in.level, win_errstr(result)));
4844 TALLOC_FREE(r->out.info);
4848 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4849 r->out.info, r->in.level);
4850 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4852 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4855 /********************************************************************
4856 ********************************************************************/
4858 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4860 if (in && strlen(in)) { \
4861 out = talloc_strdup(mem_ctx, in); \
4863 out = talloc_strdup(mem_ctx, ""); \
4865 W_ERROR_HAVE_NO_MEMORY(out); \
4868 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4870 if (in && strlen(in)) { \
4871 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4873 out = talloc_strdup(mem_ctx, ""); \
4875 W_ERROR_HAVE_NO_MEMORY(out); \
4878 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4879 const char **string_array,
4880 const char ***presult,
4881 const char *cservername,
4885 int i, num_strings = 0;
4886 const char **array = NULL;
4888 if (string_array == NULL) {
4889 return WERR_INVALID_PARAMETER;
4892 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4893 const char *str = NULL;
4895 if (cservername == NULL || arch == NULL) {
4896 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4898 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4901 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4908 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4909 &array, &num_strings);
4919 /********************************************************************
4920 * fill a spoolss_DriverInfo1 struct
4921 ********************************************************************/
4923 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4924 struct spoolss_DriverInfo1 *r,
4925 const struct spoolss_DriverInfo8 *driver,
4926 const char *servername)
4928 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4929 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4934 /********************************************************************
4935 * fill a spoolss_DriverInfo2 struct
4936 ********************************************************************/
4938 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4939 struct spoolss_DriverInfo2 *r,
4940 const struct spoolss_DriverInfo8 *driver,
4941 const char *servername)
4944 const char *cservername = canon_servername(servername);
4946 r->version = driver->version;
4948 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4949 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4950 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4951 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4953 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4954 driver->architecture,
4956 driver->driver_path,
4959 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4960 driver->architecture,
4965 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4966 driver->architecture,
4968 driver->config_file,
4974 /********************************************************************
4975 * fill a spoolss_DriverInfo3 struct
4976 ********************************************************************/
4978 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4979 struct spoolss_DriverInfo3 *r,
4980 const struct spoolss_DriverInfo8 *driver,
4981 const char *servername)
4983 const char *cservername = canon_servername(servername);
4985 r->version = driver->version;
4987 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4988 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4989 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4990 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4992 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4993 driver->architecture,
4995 driver->driver_path,
4998 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4999 driver->architecture,
5004 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5005 driver->architecture,
5007 driver->config_file,
5010 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5011 driver->architecture,
5016 FILL_DRIVER_STRING(mem_ctx,
5017 driver->monitor_name,
5020 FILL_DRIVER_STRING(mem_ctx,
5021 driver->default_datatype,
5022 r->default_datatype);
5024 return string_array_from_driver_info(mem_ctx,
5025 driver->dependent_files,
5026 &r->dependent_files,
5028 driver->architecture,
5032 /********************************************************************
5033 * fill a spoolss_DriverInfo4 struct
5034 ********************************************************************/
5036 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
5037 struct spoolss_DriverInfo4 *r,
5038 const struct spoolss_DriverInfo8 *driver,
5039 const char *servername)
5041 const char *cservername = canon_servername(servername);
5044 r->version = driver->version;
5046 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5047 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5048 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5049 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5051 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5052 driver->architecture,
5054 driver->driver_path,
5057 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5058 driver->architecture,
5063 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5064 driver->architecture,
5066 driver->config_file,
5069 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5070 driver->architecture,
5075 result = string_array_from_driver_info(mem_ctx,
5076 driver->dependent_files,
5077 &r->dependent_files,
5079 driver->architecture,
5081 if (!W_ERROR_IS_OK(result)) {
5085 FILL_DRIVER_STRING(mem_ctx,
5086 driver->monitor_name,
5089 FILL_DRIVER_STRING(mem_ctx,
5090 driver->default_datatype,
5091 r->default_datatype);
5094 result = string_array_from_driver_info(mem_ctx,
5095 driver->previous_names,
5102 /********************************************************************
5103 * fill a spoolss_DriverInfo5 struct
5104 ********************************************************************/
5106 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
5107 struct spoolss_DriverInfo5 *r,
5108 const struct spoolss_DriverInfo8 *driver,
5109 const char *servername)
5111 const char *cservername = canon_servername(servername);
5113 r->version = driver->version;
5115 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5116 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5117 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5118 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5120 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5121 driver->architecture,
5123 driver->driver_path,
5126 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5127 driver->architecture,
5132 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5133 driver->architecture,
5135 driver->config_file,
5138 r->driver_attributes = 0;
5139 r->config_version = 0;
5140 r->driver_version = 0;
5144 /********************************************************************
5145 * fill a spoolss_DriverInfo6 struct
5146 ********************************************************************/
5148 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
5149 struct spoolss_DriverInfo6 *r,
5150 const struct spoolss_DriverInfo8 *driver,
5151 const char *servername)
5153 const char *cservername = canon_servername(servername);
5156 r->version = driver->version;
5158 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5159 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5160 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5161 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5163 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5164 driver->architecture,
5166 driver->driver_path,
5169 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5170 driver->architecture,
5175 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5176 driver->architecture,
5178 driver->config_file,
5181 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5182 driver->architecture,
5187 FILL_DRIVER_STRING(mem_ctx,
5188 driver->monitor_name,
5191 FILL_DRIVER_STRING(mem_ctx,
5192 driver->default_datatype,
5193 r->default_datatype);
5195 result = string_array_from_driver_info(mem_ctx,
5196 driver->dependent_files,
5197 &r->dependent_files,
5199 driver->architecture,
5201 if (!W_ERROR_IS_OK(result)) {
5205 result = string_array_from_driver_info(mem_ctx,
5206 driver->previous_names,
5209 if (!W_ERROR_IS_OK(result)) {
5213 r->driver_date = driver->driver_date;
5214 r->driver_version = driver->driver_version;
5216 FILL_DRIVER_STRING(mem_ctx,
5217 driver->manufacturer_name,
5218 r->manufacturer_name);
5219 FILL_DRIVER_STRING(mem_ctx,
5220 driver->manufacturer_url,
5221 r->manufacturer_url);
5222 FILL_DRIVER_STRING(mem_ctx,
5223 driver->hardware_id,
5225 FILL_DRIVER_STRING(mem_ctx,
5232 /********************************************************************
5233 * fill a spoolss_DriverInfo8 struct
5234 ********************************************************************/
5236 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
5237 struct spoolss_DriverInfo8 *r,
5238 const struct spoolss_DriverInfo8 *driver,
5239 const char *servername)
5241 const char *cservername = canon_servername(servername);
5244 r->version = driver->version;
5246 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5247 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5248 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5249 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5251 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5252 driver->architecture,
5254 driver->driver_path,
5257 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5258 driver->architecture,
5263 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5264 driver->architecture,
5266 driver->config_file,
5269 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5270 driver->architecture,
5275 FILL_DRIVER_STRING(mem_ctx,
5276 driver->monitor_name,
5279 FILL_DRIVER_STRING(mem_ctx,
5280 driver->default_datatype,
5281 r->default_datatype);
5283 result = string_array_from_driver_info(mem_ctx,
5284 driver->dependent_files,
5285 &r->dependent_files,
5287 driver->architecture,
5289 if (!W_ERROR_IS_OK(result)) {
5293 result = string_array_from_driver_info(mem_ctx,
5294 driver->previous_names,
5297 if (!W_ERROR_IS_OK(result)) {
5301 r->driver_date = driver->driver_date;
5302 r->driver_version = driver->driver_version;
5304 FILL_DRIVER_STRING(mem_ctx,
5305 driver->manufacturer_name,
5306 r->manufacturer_name);
5307 FILL_DRIVER_STRING(mem_ctx,
5308 driver->manufacturer_url,
5309 r->manufacturer_url);
5310 FILL_DRIVER_STRING(mem_ctx,
5311 driver->hardware_id,
5313 FILL_DRIVER_STRING(mem_ctx,
5317 FILL_DRIVER_STRING(mem_ctx,
5318 driver->print_processor,
5319 r->print_processor);
5320 FILL_DRIVER_STRING(mem_ctx,
5321 driver->vendor_setup,
5324 result = string_array_from_driver_info(mem_ctx,
5325 driver->color_profiles,
5328 if (!W_ERROR_IS_OK(result)) {
5332 FILL_DRIVER_STRING(mem_ctx,
5336 r->printer_driver_attributes = driver->printer_driver_attributes;
5338 result = string_array_from_driver_info(mem_ctx,
5339 driver->core_driver_dependencies,
5340 &r->core_driver_dependencies,
5342 if (!W_ERROR_IS_OK(result)) {
5346 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
5347 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
5352 #if 0 /* disabled until marshalling issues are resolved - gd */
5353 /********************************************************************
5354 ********************************************************************/
5356 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5357 struct spoolss_DriverFileInfo *r,
5358 const char *cservername,
5359 const char *file_name,
5360 enum spoolss_DriverFileType file_type,
5361 uint32_t file_version)
5363 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5364 cservername, file_name);
5365 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5366 r->file_type = file_type;
5367 r->file_version = file_version;
5372 /********************************************************************
5373 ********************************************************************/
5375 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5376 const struct spoolss_DriverInfo8 *driver,
5377 const char *cservername,
5378 struct spoolss_DriverFileInfo **info_p,
5381 struct spoolss_DriverFileInfo *info = NULL;
5389 if (strlen(driver->driver_path)) {
5390 info = talloc_realloc(mem_ctx, info,
5391 struct spoolss_DriverFileInfo,
5393 W_ERROR_HAVE_NO_MEMORY(info);
5394 result = fill_spoolss_DriverFileInfo(info,
5397 driver->driver_path,
5398 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5400 W_ERROR_NOT_OK_RETURN(result);
5404 if (strlen(driver->config_file)) {
5405 info = talloc_realloc(mem_ctx, info,
5406 struct spoolss_DriverFileInfo,
5408 W_ERROR_HAVE_NO_MEMORY(info);
5409 result = fill_spoolss_DriverFileInfo(info,
5412 driver->config_file,
5413 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5415 W_ERROR_NOT_OK_RETURN(result);
5419 if (strlen(driver->data_file)) {
5420 info = talloc_realloc(mem_ctx, info,
5421 struct spoolss_DriverFileInfo,
5423 W_ERROR_HAVE_NO_MEMORY(info);
5424 result = fill_spoolss_DriverFileInfo(info,
5428 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5430 W_ERROR_NOT_OK_RETURN(result);
5434 if (strlen(driver->help_file)) {
5435 info = talloc_realloc(mem_ctx, info,
5436 struct spoolss_DriverFileInfo,
5438 W_ERROR_HAVE_NO_MEMORY(info);
5439 result = fill_spoolss_DriverFileInfo(info,
5443 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5445 W_ERROR_NOT_OK_RETURN(result);
5449 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
5450 info = talloc_realloc(mem_ctx, info,
5451 struct spoolss_DriverFileInfo,
5453 W_ERROR_HAVE_NO_MEMORY(info);
5454 result = fill_spoolss_DriverFileInfo(info,
5457 driver->dependent_files[i],
5458 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5460 W_ERROR_NOT_OK_RETURN(result);
5470 /********************************************************************
5471 * fill a spoolss_DriverInfo101 struct
5472 ********************************************************************/
5474 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5475 struct spoolss_DriverInfo101 *r,
5476 const struct spoolss_DriverInfo8 *driver,
5477 const char *servername)
5479 const char *cservername = canon_servername(servername);
5482 r->version = driver->version;
5484 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5485 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5486 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5487 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5489 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5493 if (!W_ERROR_IS_OK(result)) {
5497 FILL_DRIVER_STRING(mem_ctx,
5498 driver->monitor_name,
5501 FILL_DRIVER_STRING(mem_ctx,
5502 driver->default_datatype,
5503 r->default_datatype);
5505 result = string_array_from_driver_info(mem_ctx,
5506 driver->previous_names,
5509 if (!W_ERROR_IS_OK(result)) {
5513 r->driver_date = driver->driver_date;
5514 r->driver_version = driver->driver_version;
5516 FILL_DRIVER_STRING(mem_ctx,
5517 driver->manufacturer_name,
5518 r->manufacturer_name);
5519 FILL_DRIVER_STRING(mem_ctx,
5520 driver->manufacturer_url,
5521 r->manufacturer_url);
5522 FILL_DRIVER_STRING(mem_ctx,
5523 driver->hardware_id,
5525 FILL_DRIVER_STRING(mem_ctx,
5532 /********************************************************************
5533 ********************************************************************/
5535 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5536 const struct auth_serversupplied_info *session_info,
5537 struct messaging_context *msg_ctx,
5539 union spoolss_DriverInfo *r,
5541 const char *servername,
5542 const char *architecture,
5545 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5546 struct spoolss_DriverInfo8 *driver;
5548 struct dcerpc_binding_handle *b;
5551 return WERR_UNKNOWN_LEVEL;
5554 result = winreg_printer_binding_handle(mem_ctx,
5558 if (!W_ERROR_IS_OK(result)) {
5562 result = winreg_get_printer(mem_ctx, b,
5563 lp_const_servicename(snum),
5566 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5567 win_errstr(result)));
5569 if (!W_ERROR_IS_OK(result)) {
5570 return WERR_INVALID_PRINTER_NAME;
5573 result = winreg_get_driver(mem_ctx, b,
5575 pinfo2->drivername, version, &driver);
5577 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5578 win_errstr(result)));
5580 if (!W_ERROR_IS_OK(result)) {
5582 * Is this a W2k client ?
5586 talloc_free(pinfo2);
5587 return WERR_UNKNOWN_PRINTER_DRIVER;
5590 /* Yes - try again with a WinNT driver. */
5592 result = winreg_get_driver(mem_ctx, b,
5596 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5597 win_errstr(result)));
5598 if (!W_ERROR_IS_OK(result)) {
5599 talloc_free(pinfo2);
5600 return WERR_UNKNOWN_PRINTER_DRIVER;
5606 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5609 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5612 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5615 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5618 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5621 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5624 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5626 #if 0 /* disabled until marshalling issues are resolved - gd */
5628 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5632 result = WERR_UNKNOWN_LEVEL;
5636 talloc_free(pinfo2);
5637 talloc_free(driver);
5642 /****************************************************************
5643 _spoolss_GetPrinterDriver2
5644 ****************************************************************/
5646 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5647 struct spoolss_GetPrinterDriver2 *r)
5649 struct printer_handle *printer;
5654 /* that's an [in out] buffer */
5656 if (!r->in.buffer && (r->in.offered != 0)) {
5657 return WERR_INVALID_PARAM;
5660 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5662 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5663 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5664 return WERR_INVALID_PRINTER_NAME;
5668 *r->out.server_major_version = 0;
5669 *r->out.server_minor_version = 0;
5671 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5675 result = construct_printer_driver_info_level(p->mem_ctx,
5676 get_session_info_system(),
5678 r->in.level, r->out.info,
5679 snum, printer->servername,
5681 r->in.client_major_version);
5682 if (!W_ERROR_IS_OK(result)) {
5683 TALLOC_FREE(r->out.info);
5687 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5688 r->out.info, r->in.level);
5689 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5691 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5695 /****************************************************************
5696 _spoolss_StartPagePrinter
5697 ****************************************************************/
5699 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5700 struct spoolss_StartPagePrinter *r)
5702 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5705 DEBUG(3,("_spoolss_StartPagePrinter: "
5706 "Error in startpageprinter printer handle\n"));
5710 Printer->page_started = true;
5714 /****************************************************************
5715 _spoolss_EndPagePrinter
5716 ****************************************************************/
5718 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5719 struct spoolss_EndPagePrinter *r)
5723 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5726 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5727 OUR_HANDLE(r->in.handle)));
5731 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5734 Printer->page_started = false;
5735 print_job_endpage(p->msg_ctx, snum, Printer->jobid);
5740 /****************************************************************
5741 _spoolss_StartDocPrinter
5742 ****************************************************************/
5744 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5745 struct spoolss_StartDocPrinter *r)
5747 struct spoolss_DocumentInfo1 *info_1;
5749 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5755 DEBUG(2,("_spoolss_StartDocPrinter: "
5756 "Invalid handle (%s:%u:%u)\n",
5757 OUR_HANDLE(r->in.handle)));
5761 if (Printer->jobid) {
5762 DEBUG(2, ("_spoolss_StartDocPrinter: "
5763 "StartDocPrinter called twice! "
5764 "(existing jobid = %d)\n", Printer->jobid));
5765 return WERR_INVALID_HANDLE;
5768 if (r->in.level != 1) {
5769 return WERR_UNKNOWN_LEVEL;
5772 info_1 = r->in.info.info1;
5775 * a nice thing with NT is it doesn't listen to what you tell it.
5776 * when asked to send _only_ RAW datas, it tries to send datas
5779 * So I add checks like in NT Server ...
5782 if (info_1->datatype) {
5783 if (strcmp(info_1->datatype, "RAW") != 0) {
5785 return WERR_INVALID_DATATYPE;
5789 /* get the share number of the printer */
5790 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5794 rc = get_remote_hostname(p->remote_address,
5800 if (strequal(rhost,"UNKNOWN")) {
5801 rhost = tsocket_address_inet_addr_string(p->remote_address,
5803 if (rhost == NULL) {
5808 werr = print_job_start(p->session_info,
5812 info_1->document_name,
5813 info_1->output_file,
5817 /* An error occured in print_job_start() so return an appropriate
5820 if (!W_ERROR_IS_OK(werr)) {
5824 Printer->document_started = true;
5825 *r->out.job_id = Printer->jobid;
5830 /****************************************************************
5831 _spoolss_EndDocPrinter
5832 ****************************************************************/
5834 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5835 struct spoolss_EndDocPrinter *r)
5837 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5842 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5843 OUR_HANDLE(r->in.handle)));
5847 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5851 Printer->document_started = false;
5852 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5853 if (!NT_STATUS_IS_OK(status)) {
5854 DEBUG(2, ("_spoolss_EndDocPrinter: "
5855 "print_job_end failed [%s]\n",
5856 nt_errstr(status)));
5860 return ntstatus_to_werror(status);
5863 /****************************************************************
5864 _spoolss_WritePrinter
5865 ****************************************************************/
5867 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5868 struct spoolss_WritePrinter *r)
5870 ssize_t buffer_written;
5872 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5875 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5876 OUR_HANDLE(r->in.handle)));
5877 *r->out.num_written = r->in._data_size;
5881 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5884 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5885 buffer_written = print_job_write(server_event_context(),p->msg_ctx,
5886 snum, Printer->jobid,
5887 (const char *)r->in.data.data,
5888 (size_t)r->in._data_size);
5889 if (buffer_written == (ssize_t)-1) {
5890 *r->out.num_written = 0;
5891 if (errno == ENOSPC)
5892 return WERR_NO_SPOOL_SPACE;
5894 return WERR_ACCESS_DENIED;
5897 *r->out.num_written = r->in._data_size;
5902 /********************************************************************
5903 * api_spoolss_getprinter
5904 * called from the spoolss dispatcher
5906 ********************************************************************/
5908 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5909 struct pipes_struct *p)
5911 const struct auth_serversupplied_info *session_info = p->session_info;
5913 WERROR errcode = WERR_BADFUNC;
5914 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5917 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5918 OUR_HANDLE(handle)));
5922 if (!get_printer_snum(p, handle, &snum, NULL))
5926 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5927 errcode = print_queue_pause(session_info, p->msg_ctx, snum);
5929 case SPOOLSS_PRINTER_CONTROL_RESUME:
5930 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5931 errcode = print_queue_resume(session_info, p->msg_ctx, snum);
5933 case SPOOLSS_PRINTER_CONTROL_PURGE:
5934 errcode = print_queue_purge(session_info, p->msg_ctx, snum);
5937 return WERR_UNKNOWN_LEVEL;
5944 /****************************************************************
5945 _spoolss_AbortPrinter
5946 * From MSDN: "Deletes printer's spool file if printer is configured
5948 ****************************************************************/
5950 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5951 struct spoolss_AbortPrinter *r)
5953 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5955 WERROR errcode = WERR_OK;
5958 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5959 OUR_HANDLE(r->in.handle)));
5963 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5966 if (!Printer->document_started) {
5967 return WERR_SPL_NO_STARTDOC;
5970 errcode = print_job_delete(p->session_info,
5978 /********************************************************************
5979 * called by spoolss_api_setprinter
5980 * when updating a printer description
5981 ********************************************************************/
5983 static WERROR update_printer_sec(struct policy_handle *handle,
5984 struct pipes_struct *p,
5985 struct sec_desc_buf *secdesc_ctr)
5987 struct spoolss_security_descriptor *new_secdesc = NULL;
5988 struct spoolss_security_descriptor *old_secdesc = NULL;
5989 const char *printer;
5992 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5993 struct dcerpc_binding_handle *b;
5995 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5996 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5997 OUR_HANDLE(handle)));
5999 result = WERR_BADFID;
6003 if (secdesc_ctr == NULL) {
6004 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
6005 result = WERR_INVALID_PARAM;
6008 printer = lp_const_servicename(snum);
6010 /* Check the user has permissions to change the security
6011 descriptor. By experimentation with two NT machines, the user
6012 requires Full Access to the printer to change security
6015 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
6016 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
6017 result = WERR_ACCESS_DENIED;
6021 result = winreg_printer_binding_handle(p->mem_ctx,
6022 get_session_info_system(),
6025 if (!W_ERROR_IS_OK(result)) {
6029 /* NT seems to like setting the security descriptor even though
6030 nothing may have actually changed. */
6031 result = winreg_get_printer_secdesc(p->mem_ctx, b,
6034 if (!W_ERROR_IS_OK(result)) {
6035 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc_internal() failed\n"));
6036 result = WERR_BADFID;
6040 if (DEBUGLEVEL >= 10) {
6041 struct security_acl *the_acl;
6044 the_acl = old_secdesc->dacl;
6045 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
6046 printer, the_acl->num_aces));
6048 for (i = 0; i < the_acl->num_aces; i++) {
6049 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6050 &the_acl->aces[i].trustee),
6051 the_acl->aces[i].access_mask));
6054 the_acl = secdesc_ctr->sd->dacl;
6057 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
6058 printer, the_acl->num_aces));
6060 for (i = 0; i < the_acl->num_aces; i++) {
6061 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6062 &the_acl->aces[i].trustee),
6063 the_acl->aces[i].access_mask));
6066 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
6070 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
6071 if (new_secdesc == NULL) {
6072 result = WERR_NOMEM;
6076 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
6081 result = winreg_set_printer_secdesc(p->mem_ctx, b,
6089 /********************************************************************
6090 Canonicalize printer info from a client
6091 ********************************************************************/
6093 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
6094 struct spoolss_SetPrinterInfo2 *info2,
6097 fstring printername;
6100 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
6101 "portname=%s drivername=%s comment=%s location=%s\n",
6102 info2->servername, info2->printername, info2->sharename,
6103 info2->portname, info2->drivername, info2->comment,
6106 /* we force some elements to "correct" values */
6107 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", lp_netbios_name());
6108 if (info2->servername == NULL) {
6111 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
6112 if (info2->sharename == NULL) {
6116 /* check to see if we allow printername != sharename */
6117 if (lp_force_printername(snum)) {
6118 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6119 lp_netbios_name(), info2->sharename);
6121 /* make sure printername is in \\server\printername format */
6122 fstrcpy(printername, info2->printername);
6124 if ( printername[0] == '\\' && printername[1] == '\\' ) {
6125 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
6129 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6130 lp_netbios_name(), p);
6132 if (info2->printername == NULL) {
6136 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
6137 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
6142 /****************************************************************************
6143 ****************************************************************************/
6145 static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const char *portname, const char *uri)
6147 char *cmd = lp_addport_cmd();
6148 char *command = NULL;
6150 bool is_print_op = false;
6153 return WERR_ACCESS_DENIED;
6156 command = talloc_asprintf(ctx,
6157 "%s \"%s\" \"%s\"", cmd, portname, uri );
6163 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6165 DEBUG(10,("Running [%s]\n", command));
6167 /********* BEGIN SePrintOperatorPrivilege **********/
6172 ret = smbrun(command, NULL);
6177 /********* END SePrintOperatorPrivilege **********/
6179 DEBUGADD(10,("returned [%d]\n", ret));
6181 TALLOC_FREE(command);
6184 return WERR_ACCESS_DENIED;
6190 /****************************************************************************
6191 ****************************************************************************/
6193 static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
6194 struct spoolss_SetPrinterInfo2 *info2,
6195 const char *remote_machine,
6196 struct messaging_context *msg_ctx)
6198 char *cmd = lp_addprinter_cmd();
6200 char *command = NULL;
6204 bool is_print_op = false;
6206 if (!remote_machine) {
6210 command = talloc_asprintf(ctx,
6211 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6212 cmd, info2->printername, info2->sharename,
6213 info2->portname, info2->drivername,
6214 info2->location, info2->comment, remote_machine);
6220 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6222 DEBUG(10,("Running [%s]\n", command));
6224 /********* BEGIN SePrintOperatorPrivilege **********/
6229 if ( (ret = smbrun(command, &fd)) == 0 ) {
6230 /* Tell everyone we updated smb.conf. */
6231 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6237 /********* END SePrintOperatorPrivilege **********/
6239 DEBUGADD(10,("returned [%d]\n", ret));
6241 TALLOC_FREE(command);
6249 /* reload our services immediately */
6251 reload_services(msg_ctx, -1, false);
6255 /* Get lines and convert them back to dos-codepage */
6256 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6257 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6260 /* Set the portname to what the script says the portname should be. */
6261 /* but don't require anything to be return from the script exit a good error code */
6264 /* Set the portname to what the script says the portname should be. */
6265 info2->portname = talloc_strdup(ctx, qlines[0]);
6266 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6269 TALLOC_FREE(qlines);
6273 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
6274 const struct auth_serversupplied_info *session_info,
6275 struct messaging_context *msg_ctx,
6277 struct spoolss_SetPrinterInfo2 *printer,
6278 struct spoolss_PrinterInfo2 *old_printer)
6280 bool force_update = (old_printer == NULL);
6281 const char *dnsdomname;
6282 const char *longname;
6283 const char *uncname;
6284 const char *spooling;
6286 WERROR result = WERR_OK;
6287 struct dcerpc_binding_handle *b;
6289 result = winreg_printer_binding_handle(mem_ctx,
6293 if (!W_ERROR_IS_OK(result)) {
6297 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
6298 push_reg_sz(mem_ctx, &buffer, printer->drivername);
6299 winreg_set_printer_dataex(mem_ctx, b,
6301 SPOOL_DSSPOOLER_KEY,
6302 SPOOL_REG_DRIVERNAME,
6307 if (!force_update) {
6308 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6309 printer->drivername));
6311 notify_printer_driver(server_event_context(), msg_ctx,
6312 snum, printer->drivername ?
6313 printer->drivername : "");
6317 if (force_update || !strequal(printer->comment, old_printer->comment)) {
6318 push_reg_sz(mem_ctx, &buffer, printer->comment);
6319 winreg_set_printer_dataex(mem_ctx, b,
6321 SPOOL_DSSPOOLER_KEY,
6322 SPOOL_REG_DESCRIPTION,
6327 if (!force_update) {
6328 notify_printer_comment(server_event_context(), msg_ctx,
6329 snum, printer->comment ?
6330 printer->comment : "");
6334 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
6335 push_reg_sz(mem_ctx, &buffer, printer->sharename);
6336 winreg_set_printer_dataex(mem_ctx, b,
6338 SPOOL_DSSPOOLER_KEY,
6339 SPOOL_REG_PRINTSHARENAME,
6344 if (!force_update) {
6345 notify_printer_sharename(server_event_context(),
6347 snum, printer->sharename ?
6348 printer->sharename : "");
6352 if (force_update || !strequal(printer->printername, old_printer->printername)) {
6355 p = strrchr(printer->printername, '\\' );
6359 p = printer->printername;
6362 push_reg_sz(mem_ctx, &buffer, p);
6363 winreg_set_printer_dataex(mem_ctx, b,
6365 SPOOL_DSSPOOLER_KEY,
6366 SPOOL_REG_PRINTERNAME,
6371 if (!force_update) {
6372 notify_printer_printername(server_event_context(),
6373 msg_ctx, snum, p ? p : "");
6377 if (force_update || !strequal(printer->portname, old_printer->portname)) {
6378 push_reg_sz(mem_ctx, &buffer, printer->portname);
6379 winreg_set_printer_dataex(mem_ctx, b,
6381 SPOOL_DSSPOOLER_KEY,
6387 if (!force_update) {
6388 notify_printer_port(server_event_context(),
6389 msg_ctx, snum, printer->portname ?
6390 printer->portname : "");
6394 if (force_update || !strequal(printer->location, old_printer->location)) {
6395 push_reg_sz(mem_ctx, &buffer, printer->location);
6396 winreg_set_printer_dataex(mem_ctx, b,
6398 SPOOL_DSSPOOLER_KEY,
6404 if (!force_update) {
6405 notify_printer_location(server_event_context(),
6408 printer->location : "");
6412 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
6413 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
6414 winreg_set_printer_dataex(mem_ctx, b,
6416 SPOOL_DSSPOOLER_KEY,
6417 SPOOL_REG_PRINTSEPARATORFILE,
6422 if (!force_update) {
6423 notify_printer_sepfile(server_event_context(),
6426 printer->sepfile : "");
6430 if (force_update || printer->starttime != old_printer->starttime) {
6431 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6432 SIVAL(buffer.data, 0, printer->starttime);
6433 winreg_set_printer_dataex(mem_ctx, b,
6435 SPOOL_DSSPOOLER_KEY,
6436 SPOOL_REG_PRINTSTARTTIME,
6442 if (force_update || printer->untiltime != old_printer->untiltime) {
6443 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6444 SIVAL(buffer.data, 0, printer->untiltime);
6445 winreg_set_printer_dataex(mem_ctx, b,
6447 SPOOL_DSSPOOLER_KEY,
6448 SPOOL_REG_PRINTENDTIME,
6454 if (force_update || printer->priority != old_printer->priority) {
6455 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6456 SIVAL(buffer.data, 0, printer->priority);
6457 winreg_set_printer_dataex(mem_ctx, b,
6459 SPOOL_DSSPOOLER_KEY,
6466 if (force_update || printer->attributes != old_printer->attributes) {
6467 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6468 SIVAL(buffer.data, 0, (printer->attributes &
6469 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
6470 winreg_set_printer_dataex(mem_ctx, b,
6472 SPOOL_DSSPOOLER_KEY,
6473 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
6478 switch (printer->attributes & 0x3) {
6480 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
6483 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
6486 spooling = SPOOL_REGVAL_PRINTDIRECT;
6489 spooling = "unknown";
6491 push_reg_sz(mem_ctx, &buffer, spooling);
6492 winreg_set_printer_dataex(mem_ctx, b,
6494 SPOOL_DSSPOOLER_KEY,
6495 SPOOL_REG_PRINTSPOOLING,
6501 push_reg_sz(mem_ctx, &buffer, lp_netbios_name());
6502 winreg_set_printer_dataex(mem_ctx, b,
6504 SPOOL_DSSPOOLER_KEY,
6505 SPOOL_REG_SHORTSERVERNAME,
6510 dnsdomname = get_mydnsfullname();
6511 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
6512 longname = talloc_strdup(mem_ctx, dnsdomname);
6514 longname = talloc_strdup(mem_ctx, lp_netbios_name());
6516 if (longname == NULL) {
6517 result = WERR_NOMEM;
6521 push_reg_sz(mem_ctx, &buffer, longname);
6522 winreg_set_printer_dataex(mem_ctx, b,
6524 SPOOL_DSSPOOLER_KEY,
6525 SPOOL_REG_SERVERNAME,
6530 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6531 lp_netbios_name(), printer->sharename);
6532 push_reg_sz(mem_ctx, &buffer, uncname);
6533 winreg_set_printer_dataex(mem_ctx, b,
6535 SPOOL_DSSPOOLER_KEY,
6545 /********************************************************************
6546 * Called by spoolss_api_setprinter
6547 * when updating a printer description.
6548 ********************************************************************/
6550 static WERROR update_printer(struct pipes_struct *p,
6551 struct policy_handle *handle,
6552 struct spoolss_SetPrinterInfoCtr *info_ctr,
6553 struct spoolss_DeviceMode *devmode)
6555 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6556 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6557 struct spoolss_PrinterInfo2 *old_printer;
6558 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6560 WERROR result = WERR_OK;
6561 TALLOC_CTX *tmp_ctx;
6562 struct dcerpc_binding_handle *b;
6564 DEBUG(8,("update_printer\n"));
6566 tmp_ctx = talloc_new(p->mem_ctx);
6567 if (tmp_ctx == NULL) {
6572 result = WERR_BADFID;
6576 if (!get_printer_snum(p, handle, &snum, NULL)) {
6577 result = WERR_BADFID;
6581 result = winreg_printer_binding_handle(tmp_ctx,
6582 get_session_info_system(),
6585 if (!W_ERROR_IS_OK(result)) {
6589 result = winreg_get_printer(tmp_ctx, b,
6590 lp_const_servicename(snum),
6592 if (!W_ERROR_IS_OK(result)) {
6593 result = WERR_BADFID;
6597 /* Do sanity check on the requested changes for Samba */
6598 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6599 result = WERR_INVALID_PARAM;
6603 /* FIXME!!! If the driver has changed we really should verify that
6604 it is installed before doing much else --jerry */
6606 /* Check calling user has permission to update printer description */
6607 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6608 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6609 result = WERR_ACCESS_DENIED;
6613 /* Call addprinter hook */
6614 /* Check changes to see if this is really needed */
6616 if (*lp_addprinter_cmd() &&
6617 (!strequal(printer->drivername, old_printer->drivername) ||
6618 !strequal(printer->comment, old_printer->comment) ||
6619 !strequal(printer->portname, old_printer->portname) ||
6620 !strequal(printer->location, old_printer->location)) )
6624 raddr = tsocket_address_inet_addr_string(p->remote_address,
6626 if (raddr == NULL) {
6630 /* add_printer_hook() will call reload_services() */
6631 if (!add_printer_hook(tmp_ctx, p->session_info->security_token,
6634 result = WERR_ACCESS_DENIED;
6639 update_dsspooler(tmp_ctx,
6640 get_session_info_system(),
6646 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6648 if (devmode == NULL) {
6649 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6651 result = winreg_update_printer(tmp_ctx, b,
6659 talloc_free(tmp_ctx);
6664 /****************************************************************************
6665 ****************************************************************************/
6666 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6667 struct policy_handle *handle,
6668 struct spoolss_SetPrinterInfo7 *info7)
6671 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6674 struct printer_handle *Printer;
6676 if ( lp_security() != SEC_ADS ) {
6677 return WERR_UNKNOWN_LEVEL;
6680 Printer = find_printer_index_by_hnd(p, handle);
6682 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6687 if (!get_printer_snum(p, handle, &snum, NULL))
6690 result = winreg_get_printer_internal(p->mem_ctx,
6691 get_session_info_system(),
6693 lp_servicename(snum),
6695 if (!W_ERROR_IS_OK(result)) {
6699 nt_printer_publish(pinfo2,
6700 get_session_info_system(),
6705 TALLOC_FREE(pinfo2);
6708 return WERR_UNKNOWN_LEVEL;
6712 /********************************************************************
6713 ********************************************************************/
6715 static WERROR update_printer_devmode(struct pipes_struct *p,
6716 struct policy_handle *handle,
6717 struct spoolss_DeviceMode *devmode)
6720 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6721 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6723 DEBUG(8,("update_printer_devmode\n"));
6729 if (!get_printer_snum(p, handle, &snum, NULL)) {
6733 /* Check calling user has permission to update printer description */
6734 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6735 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6736 return WERR_ACCESS_DENIED;
6739 return winreg_update_printer_internal(p->mem_ctx,
6740 get_session_info_system(),
6742 lp_const_servicename(snum),
6750 /****************************************************************
6752 ****************************************************************/
6754 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6755 struct spoolss_SetPrinter *r)
6759 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6762 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6763 OUR_HANDLE(r->in.handle)));
6767 /* check the level */
6768 switch (r->in.info_ctr->level) {
6770 return control_printer(r->in.handle, r->in.command, p);
6772 result = update_printer(p, r->in.handle,
6774 r->in.devmode_ctr->devmode);
6775 if (!W_ERROR_IS_OK(result))
6777 if (r->in.secdesc_ctr->sd)
6778 result = update_printer_sec(r->in.handle, p,
6782 return update_printer_sec(r->in.handle, p,
6785 return publish_or_unpublish_printer(p, r->in.handle,
6786 r->in.info_ctr->info.info7);
6788 return update_printer_devmode(p, r->in.handle,
6789 r->in.devmode_ctr->devmode);
6791 return WERR_UNKNOWN_LEVEL;
6795 /****************************************************************
6796 _spoolss_FindClosePrinterNotify
6797 ****************************************************************/
6799 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6800 struct spoolss_FindClosePrinterNotify *r)
6802 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6805 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6806 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6810 if (Printer->notify.cli_chan != NULL &&
6811 Printer->notify.cli_chan->active_connections > 0) {
6814 if (Printer->printer_type == SPLHND_PRINTER) {
6815 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6820 srv_spoolss_replycloseprinter(snum, Printer);
6823 Printer->notify.flags=0;
6824 Printer->notify.options=0;
6825 Printer->notify.localmachine[0]='\0';
6826 Printer->notify.printerlocal=0;
6827 TALLOC_FREE(Printer->notify.option);
6832 /****************************************************************
6834 ****************************************************************/
6836 WERROR _spoolss_AddJob(struct pipes_struct *p,
6837 struct spoolss_AddJob *r)
6839 if (!r->in.buffer && (r->in.offered != 0)) {
6840 return WERR_INVALID_PARAM;
6843 /* this is what a NT server returns for AddJob. AddJob must fail on
6844 * non-local printers */
6846 if (r->in.level != 1) {
6847 return WERR_UNKNOWN_LEVEL;
6850 return WERR_INVALID_PARAM;
6853 /****************************************************************************
6855 ****************************************************************************/
6857 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6858 struct spoolss_JobInfo1 *r,
6859 const print_queue_struct *queue,
6860 int position, int snum,
6861 struct spoolss_PrinterInfo2 *pinfo2)
6865 t = gmtime(&queue->time);
6867 r->job_id = queue->job;
6869 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6870 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6871 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6872 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6873 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6874 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6875 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6876 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6877 r->data_type = talloc_strdup(mem_ctx, "RAW");
6878 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6879 r->text_status = talloc_strdup(mem_ctx, "");
6880 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6882 r->status = nt_printj_status(queue->status);
6883 r->priority = queue->priority;
6884 r->position = position;
6885 r->total_pages = queue->page_count;
6886 r->pages_printed = 0; /* ??? */
6888 init_systemtime(&r->submitted, t);
6893 /****************************************************************************
6895 ****************************************************************************/
6897 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6898 struct spoolss_JobInfo2 *r,
6899 const print_queue_struct *queue,
6900 int position, int snum,
6901 struct spoolss_PrinterInfo2 *pinfo2,
6902 struct spoolss_DeviceMode *devmode)
6906 t = gmtime(&queue->time);
6908 r->job_id = queue->job;
6910 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6911 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6912 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6913 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6914 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6915 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6916 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6917 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6918 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6919 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6920 r->data_type = talloc_strdup(mem_ctx, "RAW");
6921 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6922 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6923 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6924 r->parameters = talloc_strdup(mem_ctx, "");
6925 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6926 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6927 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6929 r->devmode = devmode;
6931 r->text_status = talloc_strdup(mem_ctx, "");
6932 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6936 r->status = nt_printj_status(queue->status);
6937 r->priority = queue->priority;
6938 r->position = position;
6941 r->total_pages = queue->page_count;
6942 r->size = queue->size;
6943 init_systemtime(&r->submitted, t);
6945 r->pages_printed = 0; /* ??? */
6950 /****************************************************************************
6952 ****************************************************************************/
6954 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6955 struct spoolss_JobInfo3 *r,
6956 const print_queue_struct *queue,
6957 const print_queue_struct *next_queue,
6958 int position, int snum,
6959 struct spoolss_PrinterInfo2 *pinfo2)
6961 r->job_id = queue->job;
6964 r->next_job_id = next_queue->job;
6971 /****************************************************************************
6972 Enumjobs at level 1.
6973 ****************************************************************************/
6975 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6976 const print_queue_struct *queue,
6977 uint32_t num_queues, int snum,
6978 struct spoolss_PrinterInfo2 *pinfo2,
6979 union spoolss_JobInfo **info_p,
6982 union spoolss_JobInfo *info;
6984 WERROR result = WERR_OK;
6986 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
6987 W_ERROR_HAVE_NO_MEMORY(info);
6989 *count = num_queues;
6991 for (i=0; i<*count; i++) {
6992 result = fill_job_info1(info,
6998 if (!W_ERROR_IS_OK(result)) {
7004 if (!W_ERROR_IS_OK(result)) {
7015 /****************************************************************************
7016 Enumjobs at level 2.
7017 ****************************************************************************/
7019 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
7020 const print_queue_struct *queue,
7021 uint32_t num_queues, int snum,
7022 struct spoolss_PrinterInfo2 *pinfo2,
7023 union spoolss_JobInfo **info_p,
7026 union spoolss_JobInfo *info;
7028 WERROR result = WERR_OK;
7030 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7031 W_ERROR_HAVE_NO_MEMORY(info);
7033 *count = num_queues;
7035 for (i=0; i<*count; i++) {
7036 struct spoolss_DeviceMode *devmode;
7038 result = spoolss_create_default_devmode(info,
7039 pinfo2->printername,
7041 if (!W_ERROR_IS_OK(result)) {
7042 DEBUG(3, ("Can't proceed w/o a devmode!"));
7046 result = fill_job_info2(info,
7053 if (!W_ERROR_IS_OK(result)) {
7059 if (!W_ERROR_IS_OK(result)) {
7070 /****************************************************************************
7071 Enumjobs at level 3.
7072 ****************************************************************************/
7074 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
7075 const print_queue_struct *queue,
7076 uint32_t num_queues, int snum,
7077 struct spoolss_PrinterInfo2 *pinfo2,
7078 union spoolss_JobInfo **info_p,
7081 union spoolss_JobInfo *info;
7083 WERROR result = WERR_OK;
7085 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7086 W_ERROR_HAVE_NO_MEMORY(info);
7088 *count = num_queues;
7090 for (i=0; i<*count; i++) {
7091 const print_queue_struct *next_queue = NULL;
7094 next_queue = &queue[i+1];
7097 result = fill_job_info3(info,
7104 if (!W_ERROR_IS_OK(result)) {
7110 if (!W_ERROR_IS_OK(result)) {
7121 /****************************************************************
7123 ****************************************************************/
7125 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
7126 struct spoolss_EnumJobs *r)
7129 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
7131 print_status_struct prt_status;
7132 print_queue_struct *queue = NULL;
7135 /* that's an [in out] buffer */
7137 if (!r->in.buffer && (r->in.offered != 0)) {
7138 return WERR_INVALID_PARAM;
7141 DEBUG(4,("_spoolss_EnumJobs\n"));
7145 *r->out.info = NULL;
7147 /* lookup the printer snum and tdb entry */
7149 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7153 result = winreg_get_printer_internal(p->mem_ctx,
7154 get_session_info_system(),
7156 lp_const_servicename(snum),
7158 if (!W_ERROR_IS_OK(result)) {
7162 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
7163 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7164 count, prt_status.status, prt_status.message));
7168 TALLOC_FREE(pinfo2);
7172 switch (r->in.level) {
7174 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
7175 pinfo2, r->out.info, r->out.count);
7178 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
7179 pinfo2, r->out.info, r->out.count);
7182 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
7183 pinfo2, r->out.info, r->out.count);
7186 result = WERR_UNKNOWN_LEVEL;
7191 TALLOC_FREE(pinfo2);
7193 if (!W_ERROR_IS_OK(result)) {
7197 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7199 *r->out.info, r->in.level,
7201 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7202 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7204 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7207 /****************************************************************
7208 _spoolss_ScheduleJob
7209 ****************************************************************/
7211 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
7212 struct spoolss_ScheduleJob *r)
7217 /****************************************************************
7218 ****************************************************************/
7220 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
7221 struct messaging_context *msg_ctx,
7222 const char *printer_name,
7224 struct spoolss_SetJobInfo1 *r)
7228 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
7232 if (strequal(old_doc_name, r->document_name)) {
7236 if (!print_job_set_name(server_event_context(), msg_ctx,
7237 printer_name, job_id, r->document_name)) {
7244 /****************************************************************
7246 ****************************************************************/
7248 WERROR _spoolss_SetJob(struct pipes_struct *p,
7249 struct spoolss_SetJob *r)
7251 const struct auth_serversupplied_info *session_info = p->session_info;
7253 WERROR errcode = WERR_BADFUNC;
7255 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7259 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
7260 return WERR_INVALID_PRINTER_NAME;
7263 switch (r->in.command) {
7264 case SPOOLSS_JOB_CONTROL_CANCEL:
7265 case SPOOLSS_JOB_CONTROL_DELETE:
7266 errcode = print_job_delete(session_info, p->msg_ctx,
7267 snum, r->in.job_id);
7268 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
7272 case SPOOLSS_JOB_CONTROL_PAUSE:
7273 if (print_job_pause(session_info, p->msg_ctx,
7274 snum, r->in.job_id, &errcode)) {
7278 case SPOOLSS_JOB_CONTROL_RESTART:
7279 case SPOOLSS_JOB_CONTROL_RESUME:
7280 if (print_job_resume(session_info, p->msg_ctx,
7281 snum, r->in.job_id, &errcode)) {
7289 return WERR_UNKNOWN_LEVEL;
7292 if (!W_ERROR_IS_OK(errcode)) {
7296 if (r->in.ctr == NULL) {
7300 switch (r->in.ctr->level) {
7302 errcode = spoolss_setjob_1(p->mem_ctx, p->msg_ctx,
7303 lp_const_servicename(snum),
7305 r->in.ctr->info.info1);
7311 return WERR_UNKNOWN_LEVEL;
7317 /****************************************************************************
7318 Enumerates all printer drivers by level and architecture.
7319 ****************************************************************************/
7321 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
7322 const struct auth_serversupplied_info *session_info,
7323 struct messaging_context *msg_ctx,
7324 const char *servername,
7325 const char *architecture,
7327 union spoolss_DriverInfo **info_p,
7332 struct spoolss_DriverInfo8 *driver;
7333 union spoolss_DriverInfo *info = NULL;
7335 WERROR result = WERR_OK;
7336 uint32_t num_drivers;
7337 const char **drivers;
7338 struct dcerpc_binding_handle *b;
7343 result = winreg_printer_binding_handle(mem_ctx,
7347 if (!W_ERROR_IS_OK(result)) {
7351 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7352 result = winreg_get_driver_list(mem_ctx, b,
7353 architecture, version,
7354 &num_drivers, &drivers);
7355 if (!W_ERROR_IS_OK(result)) {
7358 DEBUG(4, ("we have:[%d] drivers in environment"
7359 " [%s] and version [%d]\n",
7360 num_drivers, architecture, version));
7362 if (num_drivers != 0) {
7363 info = talloc_realloc(mem_ctx, info,
7364 union spoolss_DriverInfo,
7365 count + num_drivers);
7367 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7368 "failed to enlarge driver info buffer!\n"));
7369 result = WERR_NOMEM;
7374 for (i = 0; i < num_drivers; i++) {
7375 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
7377 result = winreg_get_driver(mem_ctx, b,
7378 architecture, drivers[i],
7380 if (!W_ERROR_IS_OK(result)) {
7386 result = fill_printer_driver_info1(info, &info[count+i].info1,
7387 driver, servername);
7390 result = fill_printer_driver_info2(info, &info[count+i].info2,
7391 driver, servername);
7394 result = fill_printer_driver_info3(info, &info[count+i].info3,
7395 driver, servername);
7398 result = fill_printer_driver_info4(info, &info[count+i].info4,
7399 driver, servername);
7402 result = fill_printer_driver_info5(info, &info[count+i].info5,
7403 driver, servername);
7406 result = fill_printer_driver_info6(info, &info[count+i].info6,
7407 driver, servername);
7410 result = fill_printer_driver_info8(info, &info[count+i].info8,
7411 driver, servername);
7414 result = WERR_UNKNOWN_LEVEL;
7418 TALLOC_FREE(driver);
7420 if (!W_ERROR_IS_OK(result)) {
7425 count += num_drivers;
7426 TALLOC_FREE(drivers);
7430 TALLOC_FREE(drivers);
7432 if (!W_ERROR_IS_OK(result)) {
7443 /****************************************************************************
7444 Enumerates all printer drivers by level.
7445 ****************************************************************************/
7447 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
7448 const struct auth_serversupplied_info *session_info,
7449 struct messaging_context *msg_ctx,
7450 const char *servername,
7451 const char *architecture,
7453 union spoolss_DriverInfo **info_p,
7457 WERROR result = WERR_OK;
7459 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
7461 for (a=0; archi_table[a].long_archi != NULL; a++) {
7463 union spoolss_DriverInfo *info = NULL;
7466 result = enumprinterdrivers_level_by_architecture(mem_ctx,
7470 archi_table[a].long_archi,
7474 if (!W_ERROR_IS_OK(result)) {
7478 for (i=0; i < count; i++) {
7479 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
7480 info[i], info_p, count_p);
7487 return enumprinterdrivers_level_by_architecture(mem_ctx,
7497 /****************************************************************
7498 _spoolss_EnumPrinterDrivers
7499 ****************************************************************/
7501 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
7502 struct spoolss_EnumPrinterDrivers *r)
7504 const char *cservername;
7507 /* that's an [in out] buffer */
7509 if (!r->in.buffer && (r->in.offered != 0)) {
7510 return WERR_INVALID_PARAM;
7513 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7517 *r->out.info = NULL;
7519 cservername = canon_servername(r->in.server);
7521 if (!is_myname_or_ipaddr(cservername)) {
7522 return WERR_UNKNOWN_PRINTER_DRIVER;
7525 result = enumprinterdrivers_level(p->mem_ctx,
7526 get_session_info_system(),
7533 if (!W_ERROR_IS_OK(result)) {
7537 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7538 spoolss_EnumPrinterDrivers,
7539 *r->out.info, r->in.level,
7541 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7542 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7544 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7547 /****************************************************************
7549 ****************************************************************/
7551 WERROR _spoolss_EnumForms(struct pipes_struct *p,
7552 struct spoolss_EnumForms *r)
7558 *r->out.info = NULL;
7560 /* that's an [in out] buffer */
7562 if (!r->in.buffer && (r->in.offered != 0) ) {
7563 return WERR_INVALID_PARAM;
7566 DEBUG(4,("_spoolss_EnumForms\n"));
7567 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7568 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7570 switch (r->in.level) {
7572 result = winreg_printer_enumforms1_internal(p->mem_ctx,
7573 get_session_info_system(),
7579 result = WERR_UNKNOWN_LEVEL;
7583 if (!W_ERROR_IS_OK(result)) {
7587 if (*r->out.count == 0) {
7588 return WERR_NO_MORE_ITEMS;
7591 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7593 *r->out.info, r->in.level,
7595 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7596 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7598 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7601 /****************************************************************
7603 ****************************************************************/
7605 WERROR _spoolss_GetForm(struct pipes_struct *p,
7606 struct spoolss_GetForm *r)
7610 /* that's an [in out] buffer */
7612 if (!r->in.buffer && (r->in.offered != 0)) {
7613 return WERR_INVALID_PARAM;
7616 DEBUG(4,("_spoolss_GetForm\n"));
7617 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7618 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7620 switch (r->in.level) {
7622 result = winreg_printer_getform1_internal(p->mem_ctx,
7623 get_session_info_system(),
7626 &r->out.info->info1);
7629 result = WERR_UNKNOWN_LEVEL;
7633 if (!W_ERROR_IS_OK(result)) {
7634 TALLOC_FREE(r->out.info);
7638 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7639 r->out.info, r->in.level);
7640 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7642 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7645 /****************************************************************************
7646 ****************************************************************************/
7648 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7649 struct spoolss_PortInfo1 *r,
7652 r->port_name = talloc_strdup(mem_ctx, name);
7653 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7658 /****************************************************************************
7659 TODO: This probably needs distinguish between TCP/IP and Local ports
7661 ****************************************************************************/
7663 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7664 struct spoolss_PortInfo2 *r,
7667 r->port_name = talloc_strdup(mem_ctx, name);
7668 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7670 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7671 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7673 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7674 W_ERROR_HAVE_NO_MEMORY(r->description);
7676 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7683 /****************************************************************************
7684 wrapper around the enumer ports command
7685 ****************************************************************************/
7687 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7689 char *cmd = lp_enumports_cmd();
7690 char **qlines = NULL;
7691 char *command = NULL;
7699 /* if no hook then just fill in the default port */
7702 if (!(qlines = talloc_array( NULL, char*, 2 ))) {
7705 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7706 TALLOC_FREE(qlines);
7713 /* we have a valid enumport command */
7715 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7720 DEBUG(10,("Running [%s]\n", command));
7721 ret = smbrun(command, &fd);
7722 DEBUG(10,("Returned [%d]\n", ret));
7723 TALLOC_FREE(command);
7728 return WERR_ACCESS_DENIED;
7732 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7733 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7743 /****************************************************************************
7745 ****************************************************************************/
7747 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7748 union spoolss_PortInfo **info_p,
7751 union spoolss_PortInfo *info = NULL;
7753 WERROR result = WERR_OK;
7754 char **qlines = NULL;
7757 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7758 if (!W_ERROR_IS_OK(result)) {
7763 info = talloc_array(mem_ctx, union spoolss_PortInfo, numlines);
7765 DEBUG(10,("Returning WERR_NOMEM\n"));
7766 result = WERR_NOMEM;
7770 for (i=0; i<numlines; i++) {
7771 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7772 result = fill_port_1(info, &info[i].info1, qlines[i]);
7773 if (!W_ERROR_IS_OK(result)) {
7778 TALLOC_FREE(qlines);
7781 if (!W_ERROR_IS_OK(result)) {
7783 TALLOC_FREE(qlines);
7795 /****************************************************************************
7797 ****************************************************************************/
7799 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7800 union spoolss_PortInfo **info_p,
7803 union spoolss_PortInfo *info = NULL;
7805 WERROR result = WERR_OK;
7806 char **qlines = NULL;
7809 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7810 if (!W_ERROR_IS_OK(result)) {
7815 info = talloc_array(mem_ctx, union spoolss_PortInfo, numlines);
7817 DEBUG(10,("Returning WERR_NOMEM\n"));
7818 result = WERR_NOMEM;
7822 for (i=0; i<numlines; i++) {
7823 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7824 result = fill_port_2(info, &info[i].info2, qlines[i]);
7825 if (!W_ERROR_IS_OK(result)) {
7830 TALLOC_FREE(qlines);
7833 if (!W_ERROR_IS_OK(result)) {
7835 TALLOC_FREE(qlines);
7847 /****************************************************************
7849 ****************************************************************/
7851 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
7852 struct spoolss_EnumPorts *r)
7856 /* that's an [in out] buffer */
7858 if (!r->in.buffer && (r->in.offered != 0)) {
7859 return WERR_INVALID_PARAM;
7862 DEBUG(4,("_spoolss_EnumPorts\n"));
7866 *r->out.info = NULL;
7868 switch (r->in.level) {
7870 result = enumports_level_1(p->mem_ctx, r->out.info,
7874 result = enumports_level_2(p->mem_ctx, r->out.info,
7878 return WERR_UNKNOWN_LEVEL;
7881 if (!W_ERROR_IS_OK(result)) {
7885 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7887 *r->out.info, r->in.level,
7889 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7890 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7892 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7895 /****************************************************************************
7896 ****************************************************************************/
7898 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
7900 struct spoolss_SetPrinterInfoCtr *info_ctr,
7901 struct spoolss_DeviceMode *devmode,
7902 struct security_descriptor *secdesc,
7903 struct spoolss_UserLevelCtr *user_ctr,
7904 struct policy_handle *handle)
7906 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7907 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7909 WERROR err = WERR_OK;
7911 /* samba does not have a concept of local, non-shared printers yet, so
7912 * make sure we always setup sharename - gd */
7913 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7914 (info2->printername != NULL && info2->printername[0] != '\0')) {
7915 DEBUG(5, ("spoolss_addprinterex_level_2: "
7916 "no sharename has been set, setting printername %s as sharename\n",
7917 info2->printername));
7918 info2->sharename = info2->printername;
7921 /* check to see if the printer already exists */
7922 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7923 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7925 return WERR_PRINTER_ALREADY_EXISTS;
7928 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7929 if ((snum = print_queue_snum(info2->printername)) != -1) {
7930 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7931 info2->printername));
7932 return WERR_PRINTER_ALREADY_EXISTS;
7936 /* validate printer info struct */
7937 if (!info2->printername || strlen(info2->printername) == 0) {
7938 return WERR_INVALID_PRINTER_NAME;
7940 if (!info2->portname || strlen(info2->portname) == 0) {
7941 return WERR_UNKNOWN_PORT;
7943 if (!info2->drivername || strlen(info2->drivername) == 0) {
7944 return WERR_UNKNOWN_PRINTER_DRIVER;
7946 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7947 return WERR_UNKNOWN_PRINTPROCESSOR;
7950 /* FIXME!!! smbd should check to see if the driver is installed before
7951 trying to add a printer like this --jerry */
7953 if (*lp_addprinter_cmd() ) {
7956 raddr = tsocket_address_inet_addr_string(p->remote_address,
7958 if (raddr == NULL) {
7962 if ( !add_printer_hook(p->mem_ctx, p->session_info->security_token,
7965 return WERR_ACCESS_DENIED;
7968 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no "
7969 "smb.conf parameter \"addprinter command\" is defined. This "
7970 "parameter must exist for this call to succeed\n",
7971 info2->sharename ));
7974 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7975 return WERR_ACCESS_DENIED;
7978 /* you must be a printer admin to add a new printer */
7979 if (!print_access_check(p->session_info,
7982 PRINTER_ACCESS_ADMINISTER)) {
7983 return WERR_ACCESS_DENIED;
7987 * Do sanity check on the requested changes for Samba.
7990 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7991 return WERR_INVALID_PARAM;
7994 if (devmode == NULL) {
7995 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7998 update_dsspooler(p->mem_ctx,
7999 get_session_info_system(),
8005 err = winreg_update_printer_internal(p->mem_ctx,
8006 get_session_info_system(),
8013 if (!W_ERROR_IS_OK(err)) {
8017 err = open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER);
8018 if (!W_ERROR_IS_OK(err)) {
8019 /* Handle open failed - remove addition. */
8020 ZERO_STRUCTP(handle);
8027 /****************************************************************
8028 _spoolss_AddPrinterEx
8029 ****************************************************************/
8031 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
8032 struct spoolss_AddPrinterEx *r)
8034 switch (r->in.info_ctr->level) {
8036 /* we don't handle yet */
8037 /* but I know what to do ... */
8038 return WERR_UNKNOWN_LEVEL;
8040 return spoolss_addprinterex_level_2(p, r->in.server,
8042 r->in.devmode_ctr->devmode,
8043 r->in.secdesc_ctr->sd,
8044 r->in.userlevel_ctr,
8047 return WERR_UNKNOWN_LEVEL;
8051 /****************************************************************
8053 ****************************************************************/
8055 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
8056 struct spoolss_AddPrinter *r)
8058 struct spoolss_AddPrinterEx a;
8059 struct spoolss_UserLevelCtr userlevel_ctr;
8061 ZERO_STRUCT(userlevel_ctr);
8063 userlevel_ctr.level = 1;
8065 a.in.server = r->in.server;
8066 a.in.info_ctr = r->in.info_ctr;
8067 a.in.devmode_ctr = r->in.devmode_ctr;
8068 a.in.secdesc_ctr = r->in.secdesc_ctr;
8069 a.in.userlevel_ctr = &userlevel_ctr;
8070 a.out.handle = r->out.handle;
8072 return _spoolss_AddPrinterEx(p, &a);
8075 /****************************************************************
8076 _spoolss_AddPrinterDriverEx
8077 ****************************************************************/
8079 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
8080 struct spoolss_AddPrinterDriverEx *r)
8082 WERROR err = WERR_OK;
8083 const char *driver_name = NULL;
8088 case NDR_SPOOLSS_ADDPRINTERDRIVER:
8089 fn = "_spoolss_AddPrinterDriver";
8091 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
8092 fn = "_spoolss_AddPrinterDriverEx";
8095 return WERR_INVALID_PARAM;
8099 * we only support the semantics of AddPrinterDriver()
8100 * i.e. only copy files that are newer than existing ones
8103 if (r->in.flags == 0) {
8104 return WERR_INVALID_PARAM;
8107 if (r->in.flags != APD_COPY_NEW_FILES) {
8108 return WERR_ACCESS_DENIED;
8112 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
8113 /* Clever hack from Martin Zielinski <mz@seh.de>
8114 * to allow downgrade from level 8 (Vista).
8116 DEBUG(0,("%s: level %d not yet implemented\n", fn,
8117 r->in.info_ctr->level));
8118 return WERR_UNKNOWN_LEVEL;
8121 DEBUG(5,("Cleaning driver's information\n"));
8122 err = clean_up_driver_struct(p->mem_ctx, p->session_info, r->in.info_ctr);
8123 if (!W_ERROR_IS_OK(err))
8126 DEBUG(5,("Moving driver to final destination\n"));
8127 err = move_driver_to_download_area(p->session_info, r->in.info_ctr);
8128 if (!W_ERROR_IS_OK(err)) {
8132 err = winreg_add_driver_internal(p->mem_ctx,
8133 get_session_info_system(),
8138 if (!W_ERROR_IS_OK(err)) {
8143 * I think this is where he DrvUpgradePrinter() hook would be
8144 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8145 * server. Right now, we just need to send ourselves a message
8146 * to update each printer bound to this driver. --jerry
8149 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
8150 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8158 /****************************************************************
8159 _spoolss_AddPrinterDriver
8160 ****************************************************************/
8162 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
8163 struct spoolss_AddPrinterDriver *r)
8165 struct spoolss_AddPrinterDriverEx a;
8167 switch (r->in.info_ctr->level) {
8174 return WERR_UNKNOWN_LEVEL;
8177 a.in.servername = r->in.servername;
8178 a.in.info_ctr = r->in.info_ctr;
8179 a.in.flags = APD_COPY_NEW_FILES;
8181 return _spoolss_AddPrinterDriverEx(p, &a);
8184 /****************************************************************************
8185 ****************************************************************************/
8187 struct _spoolss_paths {
8193 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
8195 static const struct _spoolss_paths spoolss_paths[]= {
8196 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
8197 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
8200 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
8201 const char *servername,
8202 const char *environment,
8206 const char *pservername = NULL;
8207 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
8208 const char *short_archi;
8212 /* environment may be empty */
8213 if (environment && strlen(environment)) {
8214 long_archi = environment;
8217 /* servername may be empty */
8218 if (servername && strlen(servername)) {
8219 pservername = canon_servername(servername);
8221 if (!is_myname_or_ipaddr(pservername)) {
8222 return WERR_INVALID_PARAM;
8226 if (!(short_archi = get_short_archi(long_archi))) {
8227 return WERR_INVALID_ENVIRONMENT;
8230 switch (component) {
8231 case SPOOLSS_PRTPROCS_PATH:
8232 case SPOOLSS_DRIVER_PATH:
8234 *path = talloc_asprintf(mem_ctx,
8237 spoolss_paths[component].share,
8240 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
8241 SPOOLSS_DEFAULT_SERVER_PATH,
8242 spoolss_paths[component].dir,
8247 return WERR_INVALID_PARAM;
8257 /****************************************************************************
8258 ****************************************************************************/
8260 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
8261 const char *servername,
8262 const char *environment,
8263 struct spoolss_DriverDirectoryInfo1 *r)
8268 werr = compose_spoolss_server_path(mem_ctx,
8271 SPOOLSS_DRIVER_PATH,
8273 if (!W_ERROR_IS_OK(werr)) {
8277 DEBUG(4,("printer driver directory: [%s]\n", path));
8279 r->directory_name = path;
8284 /****************************************************************
8285 _spoolss_GetPrinterDriverDirectory
8286 ****************************************************************/
8288 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
8289 struct spoolss_GetPrinterDriverDirectory *r)
8293 /* that's an [in out] buffer */
8295 if (!r->in.buffer && (r->in.offered != 0)) {
8296 return WERR_INVALID_PARAM;
8299 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8304 /* r->in.level is ignored */
8306 werror = getprinterdriverdir_level_1(p->mem_ctx,
8309 &r->out.info->info1);
8310 if (!W_ERROR_IS_OK(werror)) {
8311 TALLOC_FREE(r->out.info);
8315 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
8316 r->out.info, r->in.level);
8317 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8319 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8322 /****************************************************************
8323 _spoolss_EnumPrinterData
8324 ****************************************************************/
8326 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
8327 struct spoolss_EnumPrinterData *r)
8330 struct spoolss_EnumPrinterDataEx r2;
8332 struct spoolss_PrinterEnumValues *info, *val = NULL;
8335 r2.in.handle = r->in.handle;
8336 r2.in.key_name = "PrinterDriverData";
8338 r2.out.count = &count;
8339 r2.out.info = &info;
8340 r2.out.needed = &needed;
8342 result = _spoolss_EnumPrinterDataEx(p, &r2);
8343 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8344 r2.in.offered = needed;
8345 result = _spoolss_EnumPrinterDataEx(p, &r2);
8347 if (!W_ERROR_IS_OK(result)) {
8352 * The NT machine wants to know the biggest size of value and data
8354 * cf: MSDN EnumPrinterData remark section
8357 if (!r->in.value_offered && !r->in.data_offered) {
8358 uint32_t biggest_valuesize = 0;
8359 uint32_t biggest_datasize = 0;
8362 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8364 for (i=0; i<count; i++) {
8366 name_length = strlen(info[i].value_name);
8367 if (strlen(info[i].value_name) > biggest_valuesize) {
8368 biggest_valuesize = name_length;
8371 if (info[i].data_length > biggest_datasize) {
8372 biggest_datasize = info[i].data_length;
8375 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8379 /* the value is an UNICODE string but real_value_size is the length
8380 in bytes including the trailing 0 */
8382 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8383 *r->out.data_needed = biggest_datasize;
8385 DEBUG(6,("final values: [%d], [%d]\n",
8386 *r->out.value_needed, *r->out.data_needed));
8391 if (r->in.enum_index < count) {
8392 val = &info[r->in.enum_index];
8396 /* out_value should default to "" or else NT4 has
8397 problems unmarshalling the response */
8399 if (r->in.value_offered) {
8400 *r->out.value_needed = 1;
8401 r->out.value_name = talloc_strdup(r, "");
8402 if (!r->out.value_name) {
8406 r->out.value_name = NULL;
8407 *r->out.value_needed = 0;
8410 /* the data is counted in bytes */
8412 *r->out.data_needed = r->in.data_offered;
8414 result = WERR_NO_MORE_ITEMS;
8418 * - counted in bytes in the request
8419 * - counted in UNICODE chars in the max reply
8420 * - counted in bytes in the real size
8422 * take a pause *before* coding not *during* coding
8426 if (r->in.value_offered) {
8427 r->out.value_name = talloc_strdup(r, val->value_name);
8428 if (!r->out.value_name) {
8431 *r->out.value_needed = val->value_name_len;
8433 r->out.value_name = NULL;
8434 *r->out.value_needed = 0;
8439 *r->out.type = val->type;
8441 /* data - counted in bytes */
8444 * See the section "Dynamically Typed Query Parameters"
8448 if (r->out.data && val->data && val->data->data &&
8449 val->data_length && r->in.data_offered) {
8450 memcpy(r->out.data, val->data->data,
8451 MIN(val->data_length,r->in.data_offered));
8454 *r->out.data_needed = val->data_length;
8462 /****************************************************************
8463 _spoolss_SetPrinterData
8464 ****************************************************************/
8466 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
8467 struct spoolss_SetPrinterData *r)
8469 struct spoolss_SetPrinterDataEx r2;
8471 r2.in.handle = r->in.handle;
8472 r2.in.key_name = "PrinterDriverData";
8473 r2.in.value_name = r->in.value_name;
8474 r2.in.type = r->in.type;
8475 r2.in.data = r->in.data;
8476 r2.in.offered = r->in.offered;
8478 return _spoolss_SetPrinterDataEx(p, &r2);
8481 /****************************************************************
8482 _spoolss_ResetPrinter
8483 ****************************************************************/
8485 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
8486 struct spoolss_ResetPrinter *r)
8488 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8491 DEBUG(5,("_spoolss_ResetPrinter\n"));
8494 * All we do is to check to see if the handle and queue is valid.
8495 * This call really doesn't mean anything to us because we only
8496 * support RAW printing. --jerry
8500 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8501 OUR_HANDLE(r->in.handle)));
8505 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8509 /* blindly return success */
8513 /****************************************************************
8514 _spoolss_DeletePrinterData
8515 ****************************************************************/
8517 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
8518 struct spoolss_DeletePrinterData *r)
8520 struct spoolss_DeletePrinterDataEx r2;
8522 r2.in.handle = r->in.handle;
8523 r2.in.key_name = "PrinterDriverData";
8524 r2.in.value_name = r->in.value_name;
8526 return _spoolss_DeletePrinterDataEx(p, &r2);
8529 /****************************************************************
8531 ****************************************************************/
8533 WERROR _spoolss_AddForm(struct pipes_struct *p,
8534 struct spoolss_AddForm *r)
8536 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8538 WERROR status = WERR_OK;
8539 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8540 struct dcerpc_binding_handle *b;
8542 DEBUG(5,("_spoolss_AddForm\n"));
8545 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8546 OUR_HANDLE(r->in.handle)));
8550 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8551 and not a printer admin, then fail */
8553 if ((p->session_info->utok.uid != sec_initial_uid()) &&
8554 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
8555 !token_contains_name_in_list(uidtoname(p->session_info->utok.uid),
8556 p->session_info->info3->base.domain.string,
8558 p->session_info->security_token,
8559 lp_printer_admin(snum))) {
8560 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8561 return WERR_ACCESS_DENIED;
8564 switch (form->flags) {
8565 case SPOOLSS_FORM_USER:
8566 case SPOOLSS_FORM_BUILTIN:
8567 case SPOOLSS_FORM_PRINTER:
8570 return WERR_INVALID_PARAM;
8573 status = winreg_printer_binding_handle(p->mem_ctx,
8574 get_session_info_system(),
8577 if (!W_ERROR_IS_OK(status)) {
8581 status = winreg_printer_addform1(p->mem_ctx, b,
8583 if (!W_ERROR_IS_OK(status)) {
8588 * ChangeID must always be set if this is a printer
8590 if (Printer->printer_type == SPLHND_PRINTER) {
8591 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8595 status = winreg_printer_update_changeid(p->mem_ctx, b,
8596 lp_const_servicename(snum));
8597 if (!W_ERROR_IS_OK(status)) {
8605 /****************************************************************
8607 ****************************************************************/
8609 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8610 struct spoolss_DeleteForm *r)
8612 const char *form_name = r->in.form_name;
8613 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8615 WERROR status = WERR_OK;
8616 struct dcerpc_binding_handle *b;
8618 DEBUG(5,("_spoolss_DeleteForm\n"));
8621 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8622 OUR_HANDLE(r->in.handle)));
8626 if ((p->session_info->utok.uid != sec_initial_uid()) &&
8627 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
8628 !token_contains_name_in_list(uidtoname(p->session_info->utok.uid),
8629 p->session_info->info3->base.domain.string,
8631 p->session_info->security_token,
8632 lp_printer_admin(snum))) {
8633 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8634 return WERR_ACCESS_DENIED;
8637 status = winreg_printer_binding_handle(p->mem_ctx,
8638 get_session_info_system(),
8641 if (!W_ERROR_IS_OK(status)) {
8645 status = winreg_printer_deleteform1(p->mem_ctx, b,
8647 if (!W_ERROR_IS_OK(status)) {
8652 * ChangeID must always be set if this is a printer
8654 if (Printer->printer_type == SPLHND_PRINTER) {
8655 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8659 status = winreg_printer_update_changeid(p->mem_ctx, b,
8660 lp_const_servicename(snum));
8661 if (!W_ERROR_IS_OK(status)) {
8669 /****************************************************************
8671 ****************************************************************/
8673 WERROR _spoolss_SetForm(struct pipes_struct *p,
8674 struct spoolss_SetForm *r)
8676 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8677 const char *form_name = r->in.form_name;
8679 WERROR status = WERR_OK;
8680 struct dcerpc_binding_handle *b;
8682 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8684 DEBUG(5,("_spoolss_SetForm\n"));
8687 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8688 OUR_HANDLE(r->in.handle)));
8692 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8693 and not a printer admin, then fail */
8695 if ((p->session_info->utok.uid != sec_initial_uid()) &&
8696 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
8697 !token_contains_name_in_list(uidtoname(p->session_info->utok.uid),
8698 p->session_info->info3->base.domain.string,
8700 p->session_info->security_token,
8701 lp_printer_admin(snum))) {
8702 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8703 return WERR_ACCESS_DENIED;
8706 status = winreg_printer_binding_handle(p->mem_ctx,
8707 get_session_info_system(),
8710 if (!W_ERROR_IS_OK(status)) {
8714 status = winreg_printer_setform1(p->mem_ctx, b,
8717 if (!W_ERROR_IS_OK(status)) {
8722 * ChangeID must always be set if this is a printer
8724 if (Printer->printer_type == SPLHND_PRINTER) {
8725 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8729 status = winreg_printer_update_changeid(p->mem_ctx, b,
8730 lp_const_servicename(snum));
8731 if (!W_ERROR_IS_OK(status)) {
8739 /****************************************************************************
8740 fill_print_processor1
8741 ****************************************************************************/
8743 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8744 struct spoolss_PrintProcessorInfo1 *r,
8745 const char *print_processor_name)
8747 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8748 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8753 /****************************************************************************
8754 enumprintprocessors level 1.
8755 ****************************************************************************/
8757 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8758 union spoolss_PrintProcessorInfo **info_p,
8761 union spoolss_PrintProcessorInfo *info;
8764 info = talloc_array(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8765 W_ERROR_HAVE_NO_MEMORY(info);
8769 result = fill_print_processor1(info, &info[0].info1, "winprint");
8770 if (!W_ERROR_IS_OK(result)) {
8775 if (!W_ERROR_IS_OK(result)) {
8786 /****************************************************************
8787 _spoolss_EnumPrintProcessors
8788 ****************************************************************/
8790 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8791 struct spoolss_EnumPrintProcessors *r)
8795 /* that's an [in out] buffer */
8797 if (!r->in.buffer && (r->in.offered != 0)) {
8798 return WERR_INVALID_PARAM;
8801 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8804 * Enumerate the print processors ...
8806 * Just reply with "winprint", to keep NT happy
8807 * and I can use my nice printer checker.
8812 *r->out.info = NULL;
8814 if (!get_short_archi(r->in.environment)) {
8815 return WERR_INVALID_ENVIRONMENT;
8818 switch (r->in.level) {
8820 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8824 return WERR_UNKNOWN_LEVEL;
8827 if (!W_ERROR_IS_OK(result)) {
8831 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8832 spoolss_EnumPrintProcessors,
8833 *r->out.info, r->in.level,
8835 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8836 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8838 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8841 /****************************************************************************
8842 fill_printprocdatatype1
8843 ****************************************************************************/
8845 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8846 struct spoolss_PrintProcDataTypesInfo1 *r,
8847 const char *name_array)
8849 r->name_array = talloc_strdup(mem_ctx, name_array);
8850 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8855 /****************************************************************************
8856 enumprintprocdatatypes level 1.
8857 ****************************************************************************/
8859 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8860 union spoolss_PrintProcDataTypesInfo **info_p,
8864 union spoolss_PrintProcDataTypesInfo *info;
8866 info = talloc_array(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8867 W_ERROR_HAVE_NO_MEMORY(info);
8871 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8872 if (!W_ERROR_IS_OK(result)) {
8877 if (!W_ERROR_IS_OK(result)) {
8888 /****************************************************************
8889 _spoolss_EnumPrintProcDataTypes
8890 ****************************************************************/
8892 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
8893 struct spoolss_EnumPrintProcDataTypes *r)
8897 /* that's an [in out] buffer */
8899 if (!r->in.buffer && (r->in.offered != 0)) {
8900 return WERR_INVALID_PARAM;
8903 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8907 *r->out.info = NULL;
8909 if (r->in.print_processor_name == NULL ||
8910 !strequal(r->in.print_processor_name, "winprint")) {
8911 return WERR_UNKNOWN_PRINTPROCESSOR;
8914 switch (r->in.level) {
8916 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8920 return WERR_UNKNOWN_LEVEL;
8923 if (!W_ERROR_IS_OK(result)) {
8927 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8928 spoolss_EnumPrintProcDataTypes,
8929 *r->out.info, r->in.level,
8931 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8932 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8934 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8937 /****************************************************************************
8939 ****************************************************************************/
8941 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8942 struct spoolss_MonitorInfo1 *r,
8943 const char *monitor_name)
8945 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8946 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8951 /****************************************************************************
8953 ****************************************************************************/
8955 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8956 struct spoolss_MonitorInfo2 *r,
8957 const char *monitor_name,
8958 const char *environment,
8959 const char *dll_name)
8961 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8962 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8963 r->environment = talloc_strdup(mem_ctx, environment);
8964 W_ERROR_HAVE_NO_MEMORY(r->environment);
8965 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8966 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8971 /****************************************************************************
8972 enumprintmonitors level 1.
8973 ****************************************************************************/
8975 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8976 union spoolss_MonitorInfo **info_p,
8979 union spoolss_MonitorInfo *info;
8980 WERROR result = WERR_OK;
8982 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, 2);
8983 W_ERROR_HAVE_NO_MEMORY(info);
8987 result = fill_monitor_1(info, &info[0].info1,
8989 if (!W_ERROR_IS_OK(result)) {
8993 result = fill_monitor_1(info, &info[1].info1,
8995 if (!W_ERROR_IS_OK(result)) {
9000 if (!W_ERROR_IS_OK(result)) {
9011 /****************************************************************************
9012 enumprintmonitors level 2.
9013 ****************************************************************************/
9015 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
9016 union spoolss_MonitorInfo **info_p,
9019 union spoolss_MonitorInfo *info;
9020 WERROR result = WERR_OK;
9022 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, 2);
9023 W_ERROR_HAVE_NO_MEMORY(info);
9027 result = fill_monitor_2(info, &info[0].info2,
9029 "Windows NT X86", /* FIXME */
9031 if (!W_ERROR_IS_OK(result)) {
9035 result = fill_monitor_2(info, &info[1].info2,
9037 "Windows NT X86", /* FIXME */
9039 if (!W_ERROR_IS_OK(result)) {
9044 if (!W_ERROR_IS_OK(result)) {
9055 /****************************************************************
9056 _spoolss_EnumMonitors
9057 ****************************************************************/
9059 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
9060 struct spoolss_EnumMonitors *r)
9064 /* that's an [in out] buffer */
9066 if (!r->in.buffer && (r->in.offered != 0)) {
9067 return WERR_INVALID_PARAM;
9070 DEBUG(5,("_spoolss_EnumMonitors\n"));
9073 * Enumerate the print monitors ...
9075 * Just reply with "Local Port", to keep NT happy
9076 * and I can use my nice printer checker.
9081 *r->out.info = NULL;
9083 switch (r->in.level) {
9085 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
9089 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
9093 return WERR_UNKNOWN_LEVEL;
9096 if (!W_ERROR_IS_OK(result)) {
9100 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9101 spoolss_EnumMonitors,
9102 *r->out.info, r->in.level,
9104 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9105 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9107 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9110 /****************************************************************************
9111 ****************************************************************************/
9113 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
9114 const print_queue_struct *queue,
9115 int count, int snum,
9116 struct spoolss_PrinterInfo2 *pinfo2,
9118 struct spoolss_JobInfo1 *r)
9123 for (i=0; i<count; i++) {
9124 if (queue[i].job == (int)jobid) {
9130 if (found == false) {
9131 /* NT treats not found as bad param... yet another bad choice */
9132 return WERR_INVALID_PARAM;
9135 return fill_job_info1(mem_ctx,
9143 /****************************************************************************
9144 ****************************************************************************/
9146 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
9147 const print_queue_struct *queue,
9148 int count, int snum,
9149 struct spoolss_PrinterInfo2 *pinfo2,
9151 struct spoolss_JobInfo2 *r)
9155 struct spoolss_DeviceMode *devmode;
9158 for (i=0; i<count; i++) {
9159 if (queue[i].job == (int)jobid) {
9165 if (found == false) {
9166 /* NT treats not found as bad param... yet another bad
9168 return WERR_INVALID_PARAM;
9172 * if the print job does not have a DEVMODE associated with it,
9173 * just use the one for the printer. A NULL devicemode is not
9174 * a failure condition
9177 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
9179 result = spoolss_create_default_devmode(mem_ctx,
9180 pinfo2->printername,
9182 if (!W_ERROR_IS_OK(result)) {
9183 DEBUG(3, ("Can't proceed w/o a devmode!"));
9188 return fill_job_info2(mem_ctx,
9197 /****************************************************************
9199 ****************************************************************/
9201 WERROR _spoolss_GetJob(struct pipes_struct *p,
9202 struct spoolss_GetJob *r)
9204 WERROR result = WERR_OK;
9205 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9208 print_queue_struct *queue = NULL;
9209 print_status_struct prt_status;
9211 /* that's an [in out] buffer */
9213 if (!r->in.buffer && (r->in.offered != 0)) {
9214 return WERR_INVALID_PARAM;
9217 DEBUG(5,("_spoolss_GetJob\n"));
9221 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9225 result = winreg_get_printer_internal(p->mem_ctx,
9226 get_session_info_system(),
9228 lp_const_servicename(snum),
9230 if (!W_ERROR_IS_OK(result)) {
9234 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
9236 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9237 count, prt_status.status, prt_status.message));
9239 switch (r->in.level) {
9241 result = getjob_level_1(p->mem_ctx,
9242 queue, count, snum, pinfo2,
9243 r->in.job_id, &r->out.info->info1);
9246 result = getjob_level_2(p->mem_ctx,
9247 queue, count, snum, pinfo2,
9248 r->in.job_id, &r->out.info->info2);
9251 result = WERR_UNKNOWN_LEVEL;
9256 TALLOC_FREE(pinfo2);
9258 if (!W_ERROR_IS_OK(result)) {
9259 TALLOC_FREE(r->out.info);
9263 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
9265 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9267 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9270 /****************************************************************
9271 _spoolss_GetPrinterDataEx
9272 ****************************************************************/
9274 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
9275 struct spoolss_GetPrinterDataEx *r)
9278 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9279 const char *printer;
9281 WERROR result = WERR_OK;
9283 enum winreg_Type val_type = REG_NONE;
9284 uint8_t *val_data = NULL;
9285 uint32_t val_size = 0;
9286 struct dcerpc_binding_handle *b;
9288 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9290 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9291 r->in.key_name, r->in.value_name));
9293 /* in case of problem, return some default values */
9296 *r->out.type = REG_NONE;
9299 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9300 OUR_HANDLE(r->in.handle)));
9301 result = WERR_BADFID;
9305 /* Is the handle to a printer or to the server? */
9307 if (Printer->printer_type == SPLHND_SERVER) {
9309 union spoolss_PrinterData data;
9311 result = getprinterdata_printer_server(p->mem_ctx,
9315 if (!W_ERROR_IS_OK(result)) {
9319 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
9320 *r->out.type, &data);
9321 if (!W_ERROR_IS_OK(result)) {
9325 *r->out.needed = blob.length;
9327 if (r->in.offered >= *r->out.needed) {
9328 memcpy(r->out.data, blob.data, blob.length);
9331 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9334 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9337 printer = lp_const_servicename(snum);
9339 /* check to see if the keyname is valid */
9340 if (!strlen(r->in.key_name)) {
9341 return WERR_INVALID_PARAM;
9344 result = winreg_printer_binding_handle(p->mem_ctx,
9345 get_session_info_system(),
9348 if (!W_ERROR_IS_OK(result)) {
9352 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9353 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
9354 strequal(r->in.value_name, "ChangeId")) {
9355 *r->out.type = REG_DWORD;
9357 if (r->in.offered >= *r->out.needed) {
9358 uint32_t changeid = 0;
9360 result = winreg_printer_get_changeid(p->mem_ctx, b,
9363 if (!W_ERROR_IS_OK(result)) {
9367 SIVAL(r->out.data, 0, changeid);
9373 result = winreg_get_printer_dataex(p->mem_ctx, b,
9380 if (!W_ERROR_IS_OK(result)) {
9384 *r->out.needed = val_size;
9385 *r->out.type = val_type;
9387 if (r->in.offered >= *r->out.needed) {
9388 memcpy(r->out.data, val_data, val_size);
9392 /* retain type when returning WERR_MORE_DATA */
9393 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
9395 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9398 /****************************************************************
9399 _spoolss_SetPrinterDataEx
9400 ****************************************************************/
9402 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
9403 struct spoolss_SetPrinterDataEx *r)
9405 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9407 WERROR result = WERR_OK;
9408 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9410 struct dcerpc_binding_handle *b;
9412 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9414 /* From MSDN documentation of SetPrinterDataEx: pass request to
9415 SetPrinterData if key is "PrinterDriverData" */
9418 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9419 OUR_HANDLE(r->in.handle)));
9423 if (Printer->printer_type == SPLHND_SERVER) {
9424 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9425 "Not implemented for server handles yet\n"));
9426 return WERR_INVALID_PARAM;
9429 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9434 * Access check : NT returns "access denied" if you make a
9435 * SetPrinterData call without the necessary privildge.
9436 * we were originally returning OK if nothing changed
9437 * which made Win2k issue **a lot** of SetPrinterData
9438 * when connecting to a printer --jerry
9441 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9442 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9443 "change denied by handle access permissions\n"));
9444 return WERR_ACCESS_DENIED;
9447 result = winreg_printer_binding_handle(p->mem_ctx,
9448 get_session_info_system(),
9451 if (!W_ERROR_IS_OK(result)) {
9455 result = winreg_get_printer(Printer, b,
9456 lp_servicename(snum),
9458 if (!W_ERROR_IS_OK(result)) {
9462 /* check for OID in valuename */
9464 oid_string = strchr(r->in.value_name, ',');
9470 /* save the registry data */
9472 result = winreg_set_printer_dataex(p->mem_ctx, b,
9480 if (W_ERROR_IS_OK(result)) {
9481 /* save the OID if one was specified */
9483 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9484 r->in.key_name, SPOOL_OID_KEY);
9486 result = WERR_NOMEM;
9491 * I'm not checking the status here on purpose. Don't know
9492 * if this is right, but I'm returning the status from the
9493 * previous set_printer_dataex() call. I have no idea if
9494 * this is right. --jerry
9496 winreg_set_printer_dataex(p->mem_ctx, b,
9501 (uint8_t *) oid_string,
9502 strlen(oid_string) + 1);
9505 result = winreg_printer_update_changeid(p->mem_ctx, b,
9506 lp_const_servicename(snum));
9511 talloc_free(pinfo2);
9515 /****************************************************************
9516 _spoolss_DeletePrinterDataEx
9517 ****************************************************************/
9519 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
9520 struct spoolss_DeletePrinterDataEx *r)
9522 const char *printer;
9524 WERROR status = WERR_OK;
9525 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9527 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9530 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9531 "Invalid handle (%s:%u:%u).\n",
9532 OUR_HANDLE(r->in.handle)));
9536 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9537 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9538 "printer properties change denied by handle\n"));
9539 return WERR_ACCESS_DENIED;
9542 if (!r->in.value_name || !r->in.key_name) {
9546 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9549 printer = lp_const_servicename(snum);
9551 status = winreg_delete_printer_dataex_internal(p->mem_ctx,
9552 get_session_info_system(),
9557 if (W_ERROR_IS_OK(status)) {
9558 status = winreg_printer_update_changeid_internal(p->mem_ctx,
9559 get_session_info_system(),
9567 /****************************************************************
9568 _spoolss_EnumPrinterKey
9569 ****************************************************************/
9571 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
9572 struct spoolss_EnumPrinterKey *r)
9575 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9577 WERROR result = WERR_BADFILE;
9578 const char **array = NULL;
9581 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9584 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9585 OUR_HANDLE(r->in.handle)));
9589 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9593 result = winreg_enum_printer_key_internal(p->mem_ctx,
9594 get_session_info_system(),
9596 lp_const_servicename(snum),
9600 if (!W_ERROR_IS_OK(result)) {
9604 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9605 result = WERR_NOMEM;
9609 *r->out._ndr_size = r->in.offered / 2;
9610 *r->out.needed = blob.length;
9612 if (r->in.offered < *r->out.needed) {
9613 result = WERR_MORE_DATA;
9616 r->out.key_buffer->string_array = array;
9620 if (!W_ERROR_IS_OK(result)) {
9622 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9630 /****************************************************************
9631 _spoolss_DeletePrinterKey
9632 ****************************************************************/
9634 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9635 struct spoolss_DeletePrinterKey *r)
9637 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9640 const char *printer;
9641 struct dcerpc_binding_handle *b;
9643 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9646 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9647 OUR_HANDLE(r->in.handle)));
9651 /* if keyname == NULL, return error */
9652 if ( !r->in.key_name )
9653 return WERR_INVALID_PARAM;
9655 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9659 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9660 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9661 "printer properties change denied by handle\n"));
9662 return WERR_ACCESS_DENIED;
9665 printer = lp_const_servicename(snum);
9667 status = winreg_printer_binding_handle(p->mem_ctx,
9668 get_session_info_system(),
9671 if (!W_ERROR_IS_OK(status)) {
9675 /* delete the key and all subkeys */
9676 status = winreg_delete_printer_key(p->mem_ctx, b,
9679 if (W_ERROR_IS_OK(status)) {
9680 status = winreg_printer_update_changeid(p->mem_ctx, b,
9687 /****************************************************************
9688 _spoolss_EnumPrinterDataEx
9689 ****************************************************************/
9691 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9692 struct spoolss_EnumPrinterDataEx *r)
9695 struct spoolss_PrinterEnumValues *info = NULL;
9696 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9700 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9704 *r->out.info = NULL;
9707 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9708 OUR_HANDLE(r->in.handle)));
9713 * first check for a keyname of NULL or "". Win2k seems to send
9714 * this a lot and we should send back WERR_INVALID_PARAM
9715 * no need to spend time looking up the printer in this case.
9719 if (!strlen(r->in.key_name)) {
9720 result = WERR_INVALID_PARAM;
9724 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9728 /* now look for a match on the key name */
9729 result = winreg_enum_printer_dataex_internal(p->mem_ctx,
9730 get_session_info_system(),
9732 lp_const_servicename(snum),
9736 if (!W_ERROR_IS_OK(result)) {
9740 #if 0 /* FIXME - gd */
9741 /* housekeeping information in the reply */
9743 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9744 * the hand marshalled container size is a multiple
9745 * of 4 bytes for RPC alignment.
9749 needed += 4-(needed % 4);
9752 *r->out.count = count;
9753 *r->out.info = info;
9756 if (!W_ERROR_IS_OK(result)) {
9760 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9761 spoolss_EnumPrinterDataEx,
9764 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9765 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9767 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9770 /****************************************************************************
9771 ****************************************************************************/
9773 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9774 const char *servername,
9775 const char *environment,
9776 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9781 werr = compose_spoolss_server_path(mem_ctx,
9784 SPOOLSS_PRTPROCS_PATH,
9786 if (!W_ERROR_IS_OK(werr)) {
9790 DEBUG(4,("print processor directory: [%s]\n", path));
9792 r->directory_name = path;
9797 /****************************************************************
9798 _spoolss_GetPrintProcessorDirectory
9799 ****************************************************************/
9801 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
9802 struct spoolss_GetPrintProcessorDirectory *r)
9805 char *prnproc_share = NULL;
9806 bool prnproc_share_exists = false;
9809 /* that's an [in out] buffer */
9811 if (!r->in.buffer && (r->in.offered != 0)) {
9812 return WERR_INVALID_PARAM;
9815 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9820 /* r->in.level is ignored */
9822 /* We always should reply with a local print processor directory so that
9823 * users are not forced to have a [prnproc$] share on the Samba spoolss
9824 * server, if users decide to do so, lets announce it though - Guenther */
9826 snum = find_service(talloc_tos(), "prnproc$", &prnproc_share);
9827 if (!prnproc_share) {
9831 prnproc_share_exists = true;
9834 result = getprintprocessordirectory_level_1(p->mem_ctx,
9835 prnproc_share_exists ? r->in.server : NULL,
9837 &r->out.info->info1);
9838 if (!W_ERROR_IS_OK(result)) {
9839 TALLOC_FREE(r->out.info);
9843 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9844 r->out.info, r->in.level);
9845 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9847 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9850 /*******************************************************************
9851 ********************************************************************/
9853 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9854 const char *dllname)
9856 enum ndr_err_code ndr_err;
9857 struct spoolss_MonitorUi ui;
9859 ui.dll_name = dllname;
9861 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9862 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9863 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9864 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9866 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9869 /*******************************************************************
9870 Streams the monitor UI DLL name in UNICODE
9871 *******************************************************************/
9873 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9874 struct security_token *token, DATA_BLOB *in,
9875 DATA_BLOB *out, uint32_t *needed)
9877 const char *dllname = "tcpmonui.dll";
9879 *needed = (strlen(dllname)+1) * 2;
9881 if (out->length < *needed) {
9882 return WERR_INSUFFICIENT_BUFFER;
9885 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9892 /*******************************************************************
9893 ********************************************************************/
9895 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9896 struct spoolss_PortData1 *port1,
9897 const DATA_BLOB *buf)
9899 enum ndr_err_code ndr_err;
9900 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9901 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9902 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9903 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9905 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9908 /*******************************************************************
9909 ********************************************************************/
9911 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9912 struct spoolss_PortData2 *port2,
9913 const DATA_BLOB *buf)
9915 enum ndr_err_code ndr_err;
9916 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9917 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9918 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9919 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9921 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9924 /*******************************************************************
9925 Create a new TCP/IP port
9926 *******************************************************************/
9928 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9929 struct security_token *token, DATA_BLOB *in,
9930 DATA_BLOB *out, uint32_t *needed)
9932 struct spoolss_PortData1 port1;
9933 struct spoolss_PortData2 port2;
9934 char *device_uri = NULL;
9937 const char *portname;
9938 const char *hostaddress;
9940 uint32_t port_number;
9943 /* peek for spoolss_PortData version */
9945 if (!in || (in->length < (128 + 4))) {
9946 return WERR_GENERAL_FAILURE;
9949 version = IVAL(in->data, 128);
9955 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9959 portname = port1.portname;
9960 hostaddress = port1.hostaddress;
9961 queue = port1.queue;
9962 protocol = port1.protocol;
9963 port_number = port1.port_number;
9969 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9973 portname = port2.portname;
9974 hostaddress = port2.hostaddress;
9975 queue = port2.queue;
9976 protocol = port2.protocol;
9977 port_number = port2.port_number;
9981 DEBUG(1,("xcvtcp_addport: "
9982 "unknown version of port_data: %d\n", version));
9983 return WERR_UNKNOWN_PORT;
9986 /* create the device URI and call the add_port_hook() */
9989 case PROTOCOL_RAWTCP_TYPE:
9990 device_uri = talloc_asprintf(mem_ctx,
9991 "socket://%s:%d/", hostaddress,
9995 case PROTOCOL_LPR_TYPE:
9996 device_uri = talloc_asprintf(mem_ctx,
9997 "lpr://%s/%s", hostaddress, queue );
10001 return WERR_UNKNOWN_PORT;
10008 return add_port_hook(mem_ctx, token, portname, device_uri);
10011 /*******************************************************************
10012 *******************************************************************/
10014 struct xcv_api_table xcvtcp_cmds[] = {
10015 { "MonitorUI", xcvtcp_monitorui },
10016 { "AddPort", xcvtcp_addport},
10020 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
10021 struct security_token *token, const char *command,
10028 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
10030 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
10031 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
10032 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
10035 return WERR_BADFUNC;
10038 /*******************************************************************
10039 *******************************************************************/
10040 #if 0 /* don't support management using the "Local Port" monitor */
10042 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
10043 struct security_token *token, DATA_BLOB *in,
10044 DATA_BLOB *out, uint32_t *needed)
10046 const char *dllname = "localui.dll";
10048 *needed = (strlen(dllname)+1) * 2;
10050 if (out->length < *needed) {
10051 return WERR_INSUFFICIENT_BUFFER;
10054 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
10061 /*******************************************************************
10062 *******************************************************************/
10064 struct xcv_api_table xcvlocal_cmds[] = {
10065 { "MonitorUI", xcvlocal_monitorui },
10069 struct xcv_api_table xcvlocal_cmds[] = {
10076 /*******************************************************************
10077 *******************************************************************/
10079 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
10080 struct security_token *token, const char *command,
10081 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
10086 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
10088 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
10089 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
10090 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
10092 return WERR_BADFUNC;
10095 /****************************************************************
10097 ****************************************************************/
10099 WERROR _spoolss_XcvData(struct pipes_struct *p,
10100 struct spoolss_XcvData *r)
10102 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
10103 DATA_BLOB out_data = data_blob_null;
10107 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
10108 OUR_HANDLE(r->in.handle)));
10109 return WERR_BADFID;
10112 /* Has to be a handle to the TCP/IP port monitor */
10114 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
10115 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
10116 return WERR_BADFID;
10119 /* requires administrative access to the server */
10121 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
10122 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
10123 return WERR_ACCESS_DENIED;
10126 /* Allocate the outgoing buffer */
10128 if (r->in.out_data_size) {
10129 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
10130 if (out_data.data == NULL) {
10135 switch ( Printer->printer_type ) {
10136 case SPLHND_PORTMON_TCP:
10137 werror = process_xcvtcp_command(p->mem_ctx,
10138 p->session_info->security_token,
10139 r->in.function_name,
10140 &r->in.in_data, &out_data,
10143 case SPLHND_PORTMON_LOCAL:
10144 werror = process_xcvlocal_command(p->mem_ctx,
10145 p->session_info->security_token,
10146 r->in.function_name,
10147 &r->in.in_data, &out_data,
10151 werror = WERR_INVALID_PRINT_MONITOR;
10154 if (!W_ERROR_IS_OK(werror)) {
10158 *r->out.status_code = 0;
10160 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
10161 memcpy(r->out.out_data, out_data.data,
10162 MIN(r->in.out_data_size, out_data.length));
10168 /****************************************************************
10169 _spoolss_AddPrintProcessor
10170 ****************************************************************/
10172 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
10173 struct spoolss_AddPrintProcessor *r)
10175 /* for now, just indicate success and ignore the add. We'll
10176 automatically set the winprint processor for printer
10177 entries later. Used to debug the LexMark Optra S 1855 PCL
10183 /****************************************************************
10185 ****************************************************************/
10187 WERROR _spoolss_AddPort(struct pipes_struct *p,
10188 struct spoolss_AddPort *r)
10190 /* do what w2k3 does */
10192 return WERR_NOT_SUPPORTED;
10195 /****************************************************************
10196 _spoolss_GetPrinterDriver
10197 ****************************************************************/
10199 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
10200 struct spoolss_GetPrinterDriver *r)
10202 p->rng_fault_state = true;
10203 return WERR_NOT_SUPPORTED;
10206 /****************************************************************
10207 _spoolss_ReadPrinter
10208 ****************************************************************/
10210 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
10211 struct spoolss_ReadPrinter *r)
10213 p->rng_fault_state = true;
10214 return WERR_NOT_SUPPORTED;
10217 /****************************************************************
10218 _spoolss_WaitForPrinterChange
10219 ****************************************************************/
10221 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
10222 struct spoolss_WaitForPrinterChange *r)
10224 p->rng_fault_state = true;
10225 return WERR_NOT_SUPPORTED;
10228 /****************************************************************
10229 _spoolss_ConfigurePort
10230 ****************************************************************/
10232 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
10233 struct spoolss_ConfigurePort *r)
10235 p->rng_fault_state = true;
10236 return WERR_NOT_SUPPORTED;
10239 /****************************************************************
10240 _spoolss_DeletePort
10241 ****************************************************************/
10243 WERROR _spoolss_DeletePort(struct pipes_struct *p,
10244 struct spoolss_DeletePort *r)
10246 p->rng_fault_state = true;
10247 return WERR_NOT_SUPPORTED;
10250 /****************************************************************
10251 _spoolss_CreatePrinterIC
10252 ****************************************************************/
10254 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
10255 struct spoolss_CreatePrinterIC *r)
10257 p->rng_fault_state = true;
10258 return WERR_NOT_SUPPORTED;
10261 /****************************************************************
10262 _spoolss_PlayGDIScriptOnPrinterIC
10263 ****************************************************************/
10265 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
10266 struct spoolss_PlayGDIScriptOnPrinterIC *r)
10268 p->rng_fault_state = true;
10269 return WERR_NOT_SUPPORTED;
10272 /****************************************************************
10273 _spoolss_DeletePrinterIC
10274 ****************************************************************/
10276 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
10277 struct spoolss_DeletePrinterIC *r)
10279 p->rng_fault_state = true;
10280 return WERR_NOT_SUPPORTED;
10283 /****************************************************************
10284 _spoolss_AddPrinterConnection
10285 ****************************************************************/
10287 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
10288 struct spoolss_AddPrinterConnection *r)
10290 p->rng_fault_state = true;
10291 return WERR_NOT_SUPPORTED;
10294 /****************************************************************
10295 _spoolss_DeletePrinterConnection
10296 ****************************************************************/
10298 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
10299 struct spoolss_DeletePrinterConnection *r)
10301 p->rng_fault_state = true;
10302 return WERR_NOT_SUPPORTED;
10305 /****************************************************************
10306 _spoolss_PrinterMessageBox
10307 ****************************************************************/
10309 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
10310 struct spoolss_PrinterMessageBox *r)
10312 p->rng_fault_state = true;
10313 return WERR_NOT_SUPPORTED;
10316 /****************************************************************
10317 _spoolss_AddMonitor
10318 ****************************************************************/
10320 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
10321 struct spoolss_AddMonitor *r)
10323 p->rng_fault_state = true;
10324 return WERR_NOT_SUPPORTED;
10327 /****************************************************************
10328 _spoolss_DeleteMonitor
10329 ****************************************************************/
10331 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
10332 struct spoolss_DeleteMonitor *r)
10334 p->rng_fault_state = true;
10335 return WERR_NOT_SUPPORTED;
10338 /****************************************************************
10339 _spoolss_DeletePrintProcessor
10340 ****************************************************************/
10342 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
10343 struct spoolss_DeletePrintProcessor *r)
10345 p->rng_fault_state = true;
10346 return WERR_NOT_SUPPORTED;
10349 /****************************************************************
10350 _spoolss_AddPrintProvidor
10351 ****************************************************************/
10353 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
10354 struct spoolss_AddPrintProvidor *r)
10356 p->rng_fault_state = true;
10357 return WERR_NOT_SUPPORTED;
10360 /****************************************************************
10361 _spoolss_DeletePrintProvidor
10362 ****************************************************************/
10364 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
10365 struct spoolss_DeletePrintProvidor *r)
10367 p->rng_fault_state = true;
10368 return WERR_NOT_SUPPORTED;
10371 /****************************************************************
10372 _spoolss_FindFirstPrinterChangeNotification
10373 ****************************************************************/
10375 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
10376 struct spoolss_FindFirstPrinterChangeNotification *r)
10378 p->rng_fault_state = true;
10379 return WERR_NOT_SUPPORTED;
10382 /****************************************************************
10383 _spoolss_FindNextPrinterChangeNotification
10384 ****************************************************************/
10386 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
10387 struct spoolss_FindNextPrinterChangeNotification *r)
10389 p->rng_fault_state = true;
10390 return WERR_NOT_SUPPORTED;
10393 /****************************************************************
10394 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10395 ****************************************************************/
10397 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
10398 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10400 p->rng_fault_state = true;
10401 return WERR_NOT_SUPPORTED;
10404 /****************************************************************
10405 _spoolss_ReplyOpenPrinter
10406 ****************************************************************/
10408 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
10409 struct spoolss_ReplyOpenPrinter *r)
10411 p->rng_fault_state = true;
10412 return WERR_NOT_SUPPORTED;
10415 /****************************************************************
10416 _spoolss_RouterReplyPrinter
10417 ****************************************************************/
10419 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
10420 struct spoolss_RouterReplyPrinter *r)
10422 p->rng_fault_state = true;
10423 return WERR_NOT_SUPPORTED;
10426 /****************************************************************
10427 _spoolss_ReplyClosePrinter
10428 ****************************************************************/
10430 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
10431 struct spoolss_ReplyClosePrinter *r)
10433 p->rng_fault_state = true;
10434 return WERR_NOT_SUPPORTED;
10437 /****************************************************************
10439 ****************************************************************/
10441 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
10442 struct spoolss_AddPortEx *r)
10444 p->rng_fault_state = true;
10445 return WERR_NOT_SUPPORTED;
10448 /****************************************************************
10449 _spoolss_RouterFindFirstPrinterChangeNotification
10450 ****************************************************************/
10452 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
10453 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10455 p->rng_fault_state = true;
10456 return WERR_NOT_SUPPORTED;
10459 /****************************************************************
10460 _spoolss_SpoolerInit
10461 ****************************************************************/
10463 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
10464 struct spoolss_SpoolerInit *r)
10466 p->rng_fault_state = true;
10467 return WERR_NOT_SUPPORTED;
10470 /****************************************************************
10471 _spoolss_ResetPrinterEx
10472 ****************************************************************/
10474 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
10475 struct spoolss_ResetPrinterEx *r)
10477 p->rng_fault_state = true;
10478 return WERR_NOT_SUPPORTED;
10481 /****************************************************************
10482 _spoolss_RouterReplyPrinterEx
10483 ****************************************************************/
10485 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
10486 struct spoolss_RouterReplyPrinterEx *r)
10488 p->rng_fault_state = true;
10489 return WERR_NOT_SUPPORTED;
10492 /****************************************************************
10494 ****************************************************************/
10496 WERROR _spoolss_44(struct pipes_struct *p,
10497 struct spoolss_44 *r)
10499 p->rng_fault_state = true;
10500 return WERR_NOT_SUPPORTED;
10503 /****************************************************************
10505 ****************************************************************/
10507 WERROR _spoolss_SetPort(struct pipes_struct *p,
10508 struct spoolss_SetPort *r)
10510 p->rng_fault_state = true;
10511 return WERR_NOT_SUPPORTED;
10514 /****************************************************************
10516 ****************************************************************/
10518 WERROR _spoolss_4a(struct pipes_struct *p,
10519 struct spoolss_4a *r)
10521 p->rng_fault_state = true;
10522 return WERR_NOT_SUPPORTED;
10525 /****************************************************************
10527 ****************************************************************/
10529 WERROR _spoolss_4b(struct pipes_struct *p,
10530 struct spoolss_4b *r)
10532 p->rng_fault_state = true;
10533 return WERR_NOT_SUPPORTED;
10536 /****************************************************************
10538 ****************************************************************/
10540 WERROR _spoolss_4c(struct pipes_struct *p,
10541 struct spoolss_4c *r)
10543 p->rng_fault_state = true;
10544 return WERR_NOT_SUPPORTED;
10547 /****************************************************************
10549 ****************************************************************/
10551 WERROR _spoolss_53(struct pipes_struct *p,
10552 struct spoolss_53 *r)
10554 p->rng_fault_state = true;
10555 return WERR_NOT_SUPPORTED;
10558 /****************************************************************
10559 _spoolss_AddPerMachineConnection
10560 ****************************************************************/
10562 WERROR _spoolss_AddPerMachineConnection(struct pipes_struct *p,
10563 struct spoolss_AddPerMachineConnection *r)
10565 p->rng_fault_state = true;
10566 return WERR_NOT_SUPPORTED;
10569 /****************************************************************
10570 _spoolss_DeletePerMachineConnection
10571 ****************************************************************/
10573 WERROR _spoolss_DeletePerMachineConnection(struct pipes_struct *p,
10574 struct spoolss_DeletePerMachineConnection *r)
10576 p->rng_fault_state = true;
10577 return WERR_NOT_SUPPORTED;
10580 /****************************************************************
10581 _spoolss_EnumPerMachineConnections
10582 ****************************************************************/
10584 WERROR _spoolss_EnumPerMachineConnections(struct pipes_struct *p,
10585 struct spoolss_EnumPerMachineConnections *r)
10587 p->rng_fault_state = true;
10588 return WERR_NOT_SUPPORTED;
10591 /****************************************************************
10593 ****************************************************************/
10595 WERROR _spoolss_5a(struct pipes_struct *p,
10596 struct spoolss_5a *r)
10598 p->rng_fault_state = true;
10599 return WERR_NOT_SUPPORTED;
10602 /****************************************************************
10604 ****************************************************************/
10606 WERROR _spoolss_5b(struct pipes_struct *p,
10607 struct spoolss_5b *r)
10609 p->rng_fault_state = true;
10610 return WERR_NOT_SUPPORTED;
10613 /****************************************************************
10615 ****************************************************************/
10617 WERROR _spoolss_5c(struct pipes_struct *p,
10618 struct spoolss_5c *r)
10620 p->rng_fault_state = true;
10621 return WERR_NOT_SUPPORTED;
10624 /****************************************************************
10626 ****************************************************************/
10628 WERROR _spoolss_5d(struct pipes_struct *p,
10629 struct spoolss_5d *r)
10631 p->rng_fault_state = true;
10632 return WERR_NOT_SUPPORTED;
10635 /****************************************************************
10637 ****************************************************************/
10639 WERROR _spoolss_5e(struct pipes_struct *p,
10640 struct spoolss_5e *r)
10642 p->rng_fault_state = true;
10643 return WERR_NOT_SUPPORTED;
10646 /****************************************************************
10648 ****************************************************************/
10650 WERROR _spoolss_5f(struct pipes_struct *p,
10651 struct spoolss_5f *r)
10653 p->rng_fault_state = true;
10654 return WERR_NOT_SUPPORTED;
10657 /****************************************************************
10659 ****************************************************************/
10661 WERROR _spoolss_60(struct pipes_struct *p,
10662 struct spoolss_60 *r)
10664 p->rng_fault_state = true;
10665 return WERR_NOT_SUPPORTED;
10668 /****************************************************************
10670 ****************************************************************/
10672 WERROR _spoolss_61(struct pipes_struct *p,
10673 struct spoolss_61 *r)
10675 p->rng_fault_state = true;
10676 return WERR_NOT_SUPPORTED;
10679 /****************************************************************
10681 ****************************************************************/
10683 WERROR _spoolss_62(struct pipes_struct *p,
10684 struct spoolss_62 *r)
10686 p->rng_fault_state = true;
10687 return WERR_NOT_SUPPORTED;
10690 /****************************************************************
10692 ****************************************************************/
10694 WERROR _spoolss_63(struct pipes_struct *p,
10695 struct spoolss_63 *r)
10697 p->rng_fault_state = true;
10698 return WERR_NOT_SUPPORTED;
10701 /****************************************************************
10703 ****************************************************************/
10705 WERROR _spoolss_64(struct pipes_struct *p,
10706 struct spoolss_64 *r)
10708 p->rng_fault_state = true;
10709 return WERR_NOT_SUPPORTED;
10712 /****************************************************************
10714 ****************************************************************/
10716 WERROR _spoolss_65(struct pipes_struct *p,
10717 struct spoolss_65 *r)
10719 p->rng_fault_state = true;
10720 return WERR_NOT_SUPPORTED;
10723 /****************************************************************
10724 _spoolss_GetCorePrinterDrivers
10725 ****************************************************************/
10727 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10728 struct spoolss_GetCorePrinterDrivers *r)
10730 p->rng_fault_state = true;
10731 return WERR_NOT_SUPPORTED;
10734 /****************************************************************
10736 ****************************************************************/
10738 WERROR _spoolss_67(struct pipes_struct *p,
10739 struct spoolss_67 *r)
10741 p->rng_fault_state = true;
10742 return WERR_NOT_SUPPORTED;
10745 /****************************************************************
10746 _spoolss_GetPrinterDriverPackagePath
10747 ****************************************************************/
10749 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10750 struct spoolss_GetPrinterDriverPackagePath *r)
10752 p->rng_fault_state = true;
10753 return WERR_NOT_SUPPORTED;
10756 /****************************************************************
10758 ****************************************************************/
10760 WERROR _spoolss_69(struct pipes_struct *p,
10761 struct spoolss_69 *r)
10763 p->rng_fault_state = true;
10764 return WERR_NOT_SUPPORTED;
10767 /****************************************************************
10769 ****************************************************************/
10771 WERROR _spoolss_6a(struct pipes_struct *p,
10772 struct spoolss_6a *r)
10774 p->rng_fault_state = true;
10775 return WERR_NOT_SUPPORTED;
10778 /****************************************************************
10780 ****************************************************************/
10782 WERROR _spoolss_6b(struct pipes_struct *p,
10783 struct spoolss_6b *r)
10785 p->rng_fault_state = true;
10786 return WERR_NOT_SUPPORTED;
10789 /****************************************************************
10791 ****************************************************************/
10793 WERROR _spoolss_6c(struct pipes_struct *p,
10794 struct spoolss_6c *r)
10796 p->rng_fault_state = true;
10797 return WERR_NOT_SUPPORTED;
10800 /****************************************************************
10802 ****************************************************************/
10804 WERROR _spoolss_6d(struct pipes_struct *p,
10805 struct spoolss_6d *r)
10807 p->rng_fault_state = true;
10808 return WERR_NOT_SUPPORTED;