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_session_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_session_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->unix_token->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->unix_token->uid),
1835 p->session_info->info->domain_name,
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->unix_token->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;
2090 TALLOC_CTX *tmp_ctx = NULL;
2092 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2093 and not a printer admin, then fail */
2095 if ( (p->session_info->unix_token->uid != sec_initial_uid())
2096 && !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR)
2097 && !token_contains_name_in_list(
2098 uidtoname(p->session_info->unix_token->uid),
2099 p->session_info->info->domain_name,
2101 p->session_info->security_token,
2102 lp_printer_admin(-1)) )
2104 return WERR_ACCESS_DENIED;
2107 /* check that we have a valid driver name first */
2109 if ((version = get_version_id(r->in.architecture)) == -1) {
2110 return WERR_INVALID_ENVIRONMENT;
2113 tmp_ctx = talloc_new(p->mem_ctx);
2118 status = winreg_printer_binding_handle(tmp_ctx,
2119 get_session_info_system(),
2122 if (!W_ERROR_IS_OK(status)) {
2126 status = winreg_get_driver(tmp_ctx, b,
2127 r->in.architecture, r->in.driver,
2129 if (!W_ERROR_IS_OK(status)) {
2130 /* try for Win2k driver if "Windows NT x86" */
2132 if ( version == 2 ) {
2135 status = winreg_get_driver(tmp_ctx, b,
2139 if (!W_ERROR_IS_OK(status)) {
2140 status = WERR_UNKNOWN_PRINTER_DRIVER;
2144 /* otherwise it was a failure */
2146 status = WERR_UNKNOWN_PRINTER_DRIVER;
2152 if (printer_driver_in_use(tmp_ctx,
2153 get_session_info_system(),
2156 status = WERR_PRINTER_DRIVER_IN_USE;
2161 status = winreg_get_driver(tmp_ctx, b,
2163 r->in.driver, 3, &info_win2k);
2164 if (W_ERROR_IS_OK(status)) {
2165 /* if we get to here, we now have 2 driver info structures to remove */
2166 /* remove the Win2k driver first*/
2168 status = winreg_del_driver(tmp_ctx, b,
2170 talloc_free(info_win2k);
2172 /* this should not have failed---if it did, report to client */
2173 if (!W_ERROR_IS_OK(status)) {
2179 status = winreg_del_driver(tmp_ctx, b,
2183 talloc_free(tmp_ctx);
2188 /****************************************************************
2189 _spoolss_DeletePrinterDriverEx
2190 ****************************************************************/
2192 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
2193 struct spoolss_DeletePrinterDriverEx *r)
2195 struct spoolss_DriverInfo8 *info = NULL;
2196 struct spoolss_DriverInfo8 *info_win2k = NULL;
2200 struct dcerpc_binding_handle *b;
2201 TALLOC_CTX *tmp_ctx = NULL;
2203 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2204 and not a printer admin, then fail */
2206 if ( (p->session_info->unix_token->uid != sec_initial_uid())
2207 && !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR)
2208 && !token_contains_name_in_list(
2209 uidtoname(p->session_info->unix_token->uid),
2210 p->session_info->info->domain_name,
2212 p->session_info->security_token, lp_printer_admin(-1)) )
2214 return WERR_ACCESS_DENIED;
2217 /* check that we have a valid driver name first */
2218 if ((version = get_version_id(r->in.architecture)) == -1) {
2219 /* this is what NT returns */
2220 return WERR_INVALID_ENVIRONMENT;
2223 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) {
2224 version = r->in.version;
2227 tmp_ctx = talloc_new(p->mem_ctx);
2232 status = winreg_printer_binding_handle(tmp_ctx,
2233 get_session_info_system(),
2236 if (!W_ERROR_IS_OK(status)) {
2240 status = winreg_get_driver(tmp_ctx, b,
2245 if (!W_ERROR_IS_OK(status)) {
2246 status = WERR_UNKNOWN_PRINTER_DRIVER;
2249 * if the client asked for a specific version,
2250 * or this is something other than Windows NT x86,
2254 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2257 /* try for Win2k driver if "Windows NT x86" */
2260 status = winreg_get_driver(tmp_ctx, b,
2264 if (!W_ERROR_IS_OK(status)) {
2265 status = WERR_UNKNOWN_PRINTER_DRIVER;
2270 if (printer_driver_in_use(tmp_ctx,
2271 get_session_info_system(),
2274 status = WERR_PRINTER_DRIVER_IN_USE;
2279 * we have a couple of cases to consider.
2280 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2281 * then the delete should fail if **any** files overlap with
2283 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2284 * non-overlapping files
2285 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2286 * is set, the do not delete any files
2287 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2290 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2292 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2295 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2296 printer_driver_files_in_use(tmp_ctx,
2297 get_session_info_system(),
2300 /* no idea of the correct error here */
2301 status = WERR_ACCESS_DENIED;
2306 /* also check for W32X86/3 if necessary; maybe we already have? */
2308 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2309 status = winreg_get_driver(tmp_ctx, b,
2311 r->in.driver, 3, &info_win2k);
2312 if (W_ERROR_IS_OK(status)) {
2315 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2316 printer_driver_files_in_use(info,
2317 get_session_info_system(),
2320 /* no idea of the correct error here */
2321 talloc_free(info_win2k);
2322 status = WERR_ACCESS_DENIED;
2326 /* if we get to here, we now have 2 driver info structures to remove */
2327 /* remove the Win2k driver first*/
2329 status = winreg_del_driver(tmp_ctx, b,
2333 /* this should not have failed---if it did, report to client */
2335 if (!W_ERROR_IS_OK(status)) {
2340 * now delete any associated files if delete_files is
2341 * true. Even if this part failes, we return succes
2342 * because the driver doesn not exist any more
2345 delete_driver_files(get_session_info_system(),
2351 status = winreg_del_driver(tmp_ctx, b,
2354 if (!W_ERROR_IS_OK(status)) {
2359 * now delete any associated files if delete_files is
2360 * true. Even if this part failes, we return succes
2361 * because the driver doesn not exist any more
2364 delete_driver_files(get_session_info_system(), info);
2368 talloc_free(tmp_ctx);
2373 /********************************************************************
2374 GetPrinterData on a printer server Handle.
2375 ********************************************************************/
2377 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2379 enum winreg_Type *type,
2380 union spoolss_PrinterData *data)
2382 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2384 if (!strcasecmp_m(value, "W3SvcInstalled")) {
2390 if (!strcasecmp_m(value, "BeepEnabled")) {
2396 if (!strcasecmp_m(value, "EventLog")) {
2398 /* formally was 0x1b */
2403 if (!strcasecmp_m(value, "NetPopup")) {
2409 if (!strcasecmp_m(value, "MajorVersion")) {
2412 /* Windows NT 4.0 seems to not allow uploading of drivers
2413 to a server that reports 0x3 as the MajorVersion.
2414 need to investigate more how Win2k gets around this .
2417 if (RA_WINNT == get_remote_arch()) {
2426 if (!strcasecmp_m(value, "MinorVersion")) {
2433 * uint32_t size = 0x114
2434 * uint32_t major = 5
2435 * uint32_t minor = [0|1]
2436 * uint32_t build = [2195|2600]
2437 * extra unicode string = e.g. "Service Pack 3"
2439 if (!strcasecmp_m(value, "OSVersion")) {
2441 enum ndr_err_code ndr_err;
2442 struct spoolss_OSVersion os;
2444 os.major = 5; /* Windows 2000 == 5.0 */
2446 os.build = 2195; /* build */
2447 os.extra_string = ""; /* leave extra string empty */
2449 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2450 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2451 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2452 return WERR_GENERAL_FAILURE;
2456 data->binary = blob;
2462 if (!strcasecmp_m(value, "DefaultSpoolDirectory")) {
2465 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2466 W_ERROR_HAVE_NO_MEMORY(data->string);
2471 if (!strcasecmp_m(value, "Architecture")) {
2473 data->string = talloc_strdup(mem_ctx,
2474 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2475 W_ERROR_HAVE_NO_MEMORY(data->string);
2480 if (!strcasecmp_m(value, "DsPresent")) {
2483 /* only show the publish check box if we are a
2484 member of a AD domain */
2486 if (lp_security() == SEC_ADS) {
2494 if (!strcasecmp_m(value, "DNSMachineName")) {
2495 const char *hostname = get_mydnsfullname();
2498 return WERR_BADFILE;
2502 data->string = talloc_strdup(mem_ctx, hostname);
2503 W_ERROR_HAVE_NO_MEMORY(data->string);
2510 return WERR_INVALID_PARAM;
2513 /****************************************************************
2514 _spoolss_GetPrinterData
2515 ****************************************************************/
2517 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2518 struct spoolss_GetPrinterData *r)
2520 struct spoolss_GetPrinterDataEx r2;
2522 r2.in.handle = r->in.handle;
2523 r2.in.key_name = "PrinterDriverData";
2524 r2.in.value_name = r->in.value_name;
2525 r2.in.offered = r->in.offered;
2526 r2.out.type = r->out.type;
2527 r2.out.data = r->out.data;
2528 r2.out.needed = r->out.needed;
2530 return _spoolss_GetPrinterDataEx(p, &r2);
2533 /*********************************************************
2534 Connect to the client machine.
2535 **********************************************************/
2537 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2538 struct sockaddr_storage *client_ss, const char *remote_machine)
2541 struct cli_state *the_cli;
2542 struct sockaddr_storage rm_addr;
2543 char addr[INET6_ADDRSTRLEN];
2545 if ( is_zero_addr(client_ss) ) {
2546 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2548 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2549 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2552 print_sockaddr(addr, sizeof(addr), &rm_addr);
2554 rm_addr = *client_ss;
2555 print_sockaddr(addr, sizeof(addr), &rm_addr);
2556 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2560 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2561 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2566 /* setup the connection */
2567 ret = cli_full_connection( &the_cli, lp_netbios_name(), remote_machine,
2568 &rm_addr, 0, "IPC$", "IPC",
2572 0, lp_client_signing());
2574 if ( !NT_STATUS_IS_OK( ret ) ) {
2575 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2580 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2581 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2582 cli_shutdown(the_cli);
2587 * Ok - we have an anonymous connection to the IPC$ share.
2588 * Now start the NT Domain stuff :-).
2591 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2592 if (!NT_STATUS_IS_OK(ret)) {
2593 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2594 remote_machine, nt_errstr(ret)));
2595 cli_shutdown(the_cli);
2602 /***************************************************************************
2603 Connect to the client.
2604 ****************************************************************************/
2606 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2607 uint32_t localprinter,
2608 enum winreg_Type type,
2609 struct policy_handle *handle,
2610 struct notify_back_channel **_chan,
2611 struct sockaddr_storage *client_ss,
2612 struct messaging_context *msg_ctx)
2616 struct notify_back_channel *chan;
2618 for (chan = back_channels; chan; chan = chan->next) {
2619 if (memcmp(&chan->client_address, client_ss,
2620 sizeof(struct sockaddr_storage)) == 0) {
2626 * If it's the first connection, contact the client
2627 * and connect to the IPC$ share anonymously
2630 fstring unix_printer;
2632 /* the +2 is to strip the leading 2 backslashs */
2633 fstrcpy(unix_printer, printer + 2);
2635 chan = talloc_zero(back_channels, struct notify_back_channel);
2639 chan->client_address = *client_ss;
2641 if (!spoolss_connect_to_client(&chan->cli_pipe, client_ss, unix_printer)) {
2645 chan->binding_handle = chan->cli_pipe->binding_handle;
2647 DLIST_ADD(back_channels, chan);
2649 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2650 receive_notify2_message_list);
2651 /* Tell the connections db we're now interested in printer
2652 * notify messages. */
2653 serverid_register_msg_flags(messaging_server_id(msg_ctx),
2654 true, FLAG_MSG_PRINT_NOTIFY);
2658 * Tell the specific printing tdb we want messages for this printer
2659 * by registering our PID.
2662 if (!print_notify_register_pid(snum)) {
2663 DEBUG(0, ("Failed to register our pid for printer %s\n",
2667 status = dcerpc_spoolss_ReplyOpenPrinter(chan->binding_handle,
2676 if (!NT_STATUS_IS_OK(status)) {
2677 DEBUG(5, ("dcerpc_spoolss_ReplyOpenPrinter returned [%s]\n", nt_errstr(status)));
2678 result = ntstatus_to_werror(status);
2679 } else if (!W_ERROR_IS_OK(result)) {
2680 DEBUG(5, ("ReplyOpenPrinter returned [%s]\n", win_errstr(result)));
2683 chan->active_connections++;
2686 return (W_ERROR_IS_OK(result));
2689 /****************************************************************
2690 ****************************************************************/
2692 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2693 const struct spoolss_NotifyOption *r)
2695 struct spoolss_NotifyOption *option;
2702 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2709 if (!option->count) {
2713 option->types = talloc_zero_array(option,
2714 struct spoolss_NotifyOptionType, option->count);
2715 if (!option->types) {
2716 talloc_free(option);
2720 for (i=0; i < option->count; i++) {
2721 option->types[i] = r->types[i];
2723 if (option->types[i].count) {
2724 option->types[i].fields = talloc_zero_array(option,
2725 union spoolss_Field, option->types[i].count);
2726 if (!option->types[i].fields) {
2727 talloc_free(option);
2730 for (k=0; k<option->types[i].count; k++) {
2731 option->types[i].fields[k] =
2732 r->types[i].fields[k];
2740 /****************************************************************
2741 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2743 * before replying OK: status=0 a rpc call is made to the workstation
2744 * asking ReplyOpenPrinter
2746 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2747 * called from api_spoolss_rffpcnex
2748 ****************************************************************/
2750 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2751 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2754 struct spoolss_NotifyOption *option = r->in.notify_options;
2755 struct sockaddr_storage client_ss;
2756 socklen_t client_len;
2758 /* store the notify value in the printer struct */
2760 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2763 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2764 "Invalid handle (%s:%u:%u).\n",
2765 OUR_HANDLE(r->in.handle)));
2769 Printer->notify.flags = r->in.flags;
2770 Printer->notify.options = r->in.options;
2771 Printer->notify.printerlocal = r->in.printer_local;
2772 Printer->notify.msg_ctx = p->msg_ctx;
2774 TALLOC_FREE(Printer->notify.option);
2775 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2777 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2779 /* Connect to the client machine and send a ReplyOpenPrinter */
2781 if ( Printer->printer_type == SPLHND_SERVER)
2783 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2784 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2787 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2788 "remote_address is %s\n",
2789 tsocket_address_string(p->remote_address, p->mem_ctx)));
2791 if (!lp_print_notify_backchannel(snum)) {
2792 DEBUG(10, ("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2793 "backchannel disabled\n"));
2794 return WERR_SERVER_UNAVAILABLE;
2797 client_len = tsocket_address_bsd_sockaddr(p->remote_address,
2798 (struct sockaddr *) &client_ss,
2799 sizeof(struct sockaddr_storage));
2800 if (client_len < 0) {
2804 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2805 Printer->notify.printerlocal, REG_SZ,
2806 &Printer->notify.cli_hnd,
2807 &Printer->notify.cli_chan,
2808 &client_ss, p->msg_ctx)) {
2809 return WERR_SERVER_UNAVAILABLE;
2815 /*******************************************************************
2816 * fill a notify_info_data with the servername
2817 ********************************************************************/
2819 static void spoolss_notify_server_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 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2829 /*******************************************************************
2830 * fill a notify_info_data with the printername (not including the servername).
2831 ********************************************************************/
2833 static void spoolss_notify_printer_name(struct messaging_context *msg_ctx,
2835 struct spoolss_Notify *data,
2836 print_queue_struct *queue,
2837 struct spoolss_PrinterInfo2 *pinfo2,
2838 TALLOC_CTX *mem_ctx)
2840 /* the notify name should not contain the \\server\ part */
2841 const char *p = strrchr(pinfo2->printername, '\\');
2844 p = pinfo2->printername;
2849 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2852 /*******************************************************************
2853 * fill a notify_info_data with the servicename
2854 ********************************************************************/
2856 static void spoolss_notify_share_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, lp_servicename(snum));
2866 /*******************************************************************
2867 * fill a notify_info_data with the port name
2868 ********************************************************************/
2870 static void spoolss_notify_port_name(struct messaging_context *msg_ctx,
2872 struct spoolss_Notify *data,
2873 print_queue_struct *queue,
2874 struct spoolss_PrinterInfo2 *pinfo2,
2875 TALLOC_CTX *mem_ctx)
2877 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2880 /*******************************************************************
2881 * fill a notify_info_data with the printername
2882 * but it doesn't exist, have to see what to do
2883 ********************************************************************/
2885 static void spoolss_notify_driver_name(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)
2892 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2895 /*******************************************************************
2896 * fill a notify_info_data with the comment
2897 ********************************************************************/
2899 static void spoolss_notify_comment(struct messaging_context *msg_ctx,
2901 struct spoolss_Notify *data,
2902 print_queue_struct *queue,
2903 struct spoolss_PrinterInfo2 *pinfo2,
2904 TALLOC_CTX *mem_ctx)
2908 if (*pinfo2->comment == '\0') {
2909 p = lp_comment(snum);
2911 p = pinfo2->comment;
2914 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2917 /*******************************************************************
2918 * fill a notify_info_data with the comment
2919 * location = "Room 1, floor 2, building 3"
2920 ********************************************************************/
2922 static void spoolss_notify_location(struct messaging_context *msg_ctx,
2924 struct spoolss_Notify *data,
2925 print_queue_struct *queue,
2926 struct spoolss_PrinterInfo2 *pinfo2,
2927 TALLOC_CTX *mem_ctx)
2929 const char *loc = pinfo2->location;
2932 status = printer_list_get_printer(mem_ctx,
2937 if (NT_STATUS_IS_OK(status)) {
2939 loc = pinfo2->location;
2943 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, loc);
2946 /*******************************************************************
2947 * fill a notify_info_data with the device mode
2948 * jfm:xxxx don't to it for know but that's a real problem !!!
2949 ********************************************************************/
2951 static void spoolss_notify_devmode(struct messaging_context *msg_ctx,
2953 struct spoolss_Notify *data,
2954 print_queue_struct *queue,
2955 struct spoolss_PrinterInfo2 *pinfo2,
2956 TALLOC_CTX *mem_ctx)
2958 /* for a dummy implementation we have to zero the fields */
2959 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2962 /*******************************************************************
2963 * fill a notify_info_data with the separator file name
2964 ********************************************************************/
2966 static void spoolss_notify_sepfile(struct messaging_context *msg_ctx,
2968 struct spoolss_Notify *data,
2969 print_queue_struct *queue,
2970 struct spoolss_PrinterInfo2 *pinfo2,
2971 TALLOC_CTX *mem_ctx)
2973 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2976 /*******************************************************************
2977 * fill a notify_info_data with the print processor
2978 * jfm:xxxx return always winprint to indicate we don't do anything to it
2979 ********************************************************************/
2981 static void spoolss_notify_print_processor(struct messaging_context *msg_ctx,
2983 struct spoolss_Notify *data,
2984 print_queue_struct *queue,
2985 struct spoolss_PrinterInfo2 *pinfo2,
2986 TALLOC_CTX *mem_ctx)
2988 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2991 /*******************************************************************
2992 * fill a notify_info_data with the print processor options
2993 * jfm:xxxx send an empty string
2994 ********************************************************************/
2996 static void spoolss_notify_parameters(struct messaging_context *msg_ctx,
2998 struct spoolss_Notify *data,
2999 print_queue_struct *queue,
3000 struct spoolss_PrinterInfo2 *pinfo2,
3001 TALLOC_CTX *mem_ctx)
3003 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
3006 /*******************************************************************
3007 * fill a notify_info_data with the data type
3008 * jfm:xxxx always send RAW as data type
3009 ********************************************************************/
3011 static void spoolss_notify_datatype(struct messaging_context *msg_ctx,
3013 struct spoolss_Notify *data,
3014 print_queue_struct *queue,
3015 struct spoolss_PrinterInfo2 *pinfo2,
3016 TALLOC_CTX *mem_ctx)
3018 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
3021 /*******************************************************************
3022 * fill a notify_info_data with the security descriptor
3023 * jfm:xxxx send an null pointer to say no security desc
3024 * have to implement security before !
3025 ********************************************************************/
3027 static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
3029 struct spoolss_Notify *data,
3030 print_queue_struct *queue,
3031 struct spoolss_PrinterInfo2 *pinfo2,
3032 TALLOC_CTX *mem_ctx)
3034 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
3037 /*******************************************************************
3038 * fill a notify_info_data with the attributes
3039 * jfm:xxxx a samba printer is always shared
3040 ********************************************************************/
3042 static void spoolss_notify_attributes(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->attributes);
3052 /*******************************************************************
3053 * fill a notify_info_data with the priority
3054 ********************************************************************/
3056 static void spoolss_notify_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->priority);
3066 /*******************************************************************
3067 * fill a notify_info_data with the default priority
3068 ********************************************************************/
3070 static void spoolss_notify_default_priority(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->defaultpriority);
3080 /*******************************************************************
3081 * fill a notify_info_data with the start time
3082 ********************************************************************/
3084 static void spoolss_notify_start_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->starttime);
3094 /*******************************************************************
3095 * fill a notify_info_data with the until time
3096 ********************************************************************/
3098 static void spoolss_notify_until_time(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 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
3108 /*******************************************************************
3109 * fill a notify_info_data with the status
3110 ********************************************************************/
3112 static void spoolss_notify_status(struct messaging_context *msg_ctx,
3114 struct spoolss_Notify *data,
3115 print_queue_struct *queue,
3116 struct spoolss_PrinterInfo2 *pinfo2,
3117 TALLOC_CTX *mem_ctx)
3119 print_status_struct status;
3121 print_queue_length(msg_ctx, snum, &status);
3122 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3125 /*******************************************************************
3126 * fill a notify_info_data with the number of jobs queued
3127 ********************************************************************/
3129 static void spoolss_notify_cjobs(struct messaging_context *msg_ctx,
3131 struct spoolss_Notify *data,
3132 print_queue_struct *queue,
3133 struct spoolss_PrinterInfo2 *pinfo2,
3134 TALLOC_CTX *mem_ctx)
3136 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3137 data, print_queue_length(msg_ctx, snum, NULL));
3140 /*******************************************************************
3141 * fill a notify_info_data with the average ppm
3142 ********************************************************************/
3144 static void spoolss_notify_average_ppm(struct messaging_context *msg_ctx,
3146 struct spoolss_Notify *data,
3147 print_queue_struct *queue,
3148 struct spoolss_PrinterInfo2 *pinfo2,
3149 TALLOC_CTX *mem_ctx)
3151 /* always respond 8 pages per minutes */
3152 /* a little hard ! */
3153 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
3156 /*******************************************************************
3157 * fill a notify_info_data with username
3158 ********************************************************************/
3160 static void spoolss_notify_username(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_STRING(data, queue->fs_user);
3170 /*******************************************************************
3171 * fill a notify_info_data with job status
3172 ********************************************************************/
3174 static void spoolss_notify_job_status(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_INTEGER(data, nt_printj_status(queue->status));
3184 /*******************************************************************
3185 * fill a notify_info_data with job name
3186 ********************************************************************/
3188 static void spoolss_notify_job_name(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)
3195 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3198 /*******************************************************************
3199 * fill a notify_info_data with job status
3200 ********************************************************************/
3202 static void spoolss_notify_job_status_string(struct messaging_context *msg_ctx,
3204 struct spoolss_Notify *data,
3205 print_queue_struct *queue,
3206 struct spoolss_PrinterInfo2 *pinfo2,
3207 TALLOC_CTX *mem_ctx)
3210 * Now we're returning job status codes we just return a "" here. JRA.
3215 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3218 switch (queue->status) {
3223 p = ""; /* NT provides the paused string */
3232 #endif /* NO LONGER NEEDED. */
3234 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3237 /*******************************************************************
3238 * fill a notify_info_data with job time
3239 ********************************************************************/
3241 static void spoolss_notify_job_time(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, 0);
3251 /*******************************************************************
3252 * fill a notify_info_data with job size
3253 ********************************************************************/
3255 static void spoolss_notify_job_size(struct messaging_context *msg_ctx,
3257 struct spoolss_Notify *data,
3258 print_queue_struct *queue,
3259 struct spoolss_PrinterInfo2 *pinfo2,
3260 TALLOC_CTX *mem_ctx)
3262 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3265 /*******************************************************************
3266 * fill a notify_info_data with page info
3267 ********************************************************************/
3268 static void spoolss_notify_total_pages(struct messaging_context *msg_ctx,
3270 struct spoolss_Notify *data,
3271 print_queue_struct *queue,
3272 struct spoolss_PrinterInfo2 *pinfo2,
3273 TALLOC_CTX *mem_ctx)
3275 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3278 /*******************************************************************
3279 * fill a notify_info_data with pages printed info.
3280 ********************************************************************/
3281 static void spoolss_notify_pages_printed(struct messaging_context *msg_ctx,
3283 struct spoolss_Notify *data,
3284 print_queue_struct *queue,
3285 struct spoolss_PrinterInfo2 *pinfo2,
3286 TALLOC_CTX *mem_ctx)
3288 /* Add code when back-end tracks this */
3289 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3292 /*******************************************************************
3293 Fill a notify_info_data with job position.
3294 ********************************************************************/
3296 static void spoolss_notify_job_position(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 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3306 /*******************************************************************
3307 Fill a notify_info_data with submitted time.
3308 ********************************************************************/
3310 static void spoolss_notify_submitted_time(struct messaging_context *msg_ctx,
3312 struct spoolss_Notify *data,
3313 print_queue_struct *queue,
3314 struct spoolss_PrinterInfo2 *pinfo2,
3315 TALLOC_CTX *mem_ctx)
3317 data->data.string.string = NULL;
3318 data->data.string.size = 0;
3320 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3321 &data->data.string.string,
3322 &data->data.string.size);
3326 struct s_notify_info_data_table
3328 enum spoolss_NotifyType type;
3331 enum spoolss_NotifyTable variable_type;
3332 void (*fn) (struct messaging_context *msg_ctx,
3333 int snum, struct spoolss_Notify *data,
3334 print_queue_struct *queue,
3335 struct spoolss_PrinterInfo2 *pinfo2,
3336 TALLOC_CTX *mem_ctx);
3339 /* A table describing the various print notification constants and
3340 whether the notification data is a pointer to a variable sized
3341 buffer, a one value uint32_t or a two value uint32_t. */
3343 static const struct s_notify_info_data_table notify_info_data_table[] =
3345 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3346 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3347 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3348 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3349 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3350 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3351 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3352 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3353 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3354 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3355 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3356 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3357 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3358 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3359 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3360 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3361 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3362 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3363 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3364 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3365 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3366 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3367 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3368 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3369 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3370 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3371 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3372 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3373 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3374 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3375 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3376 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3377 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3378 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3379 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3380 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3381 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3382 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3383 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3384 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3385 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3386 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3387 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3388 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3389 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3390 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3391 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3392 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3393 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3396 /*******************************************************************
3397 Return the variable_type of info_data structure.
3398 ********************************************************************/
3400 static enum spoolss_NotifyTable variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3405 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3406 if ( (notify_info_data_table[i].type == type) &&
3407 (notify_info_data_table[i].field == field) ) {
3408 return notify_info_data_table[i].variable_type;
3412 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3414 return (enum spoolss_NotifyTable) 0;
3417 /****************************************************************************
3418 ****************************************************************************/
3420 static bool search_notify(enum spoolss_NotifyType type,
3426 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3427 if (notify_info_data_table[i].type == type &&
3428 notify_info_data_table[i].field == field &&
3429 notify_info_data_table[i].fn != NULL) {
3438 /****************************************************************************
3439 ****************************************************************************/
3441 static void construct_info_data(struct spoolss_Notify *info_data,
3442 enum spoolss_NotifyType type,
3443 uint16_t field, int id)
3445 info_data->type = type;
3446 info_data->field.field = field;
3447 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3448 info_data->job_id = id;
3451 /*******************************************************************
3453 * fill a notify_info struct with info asked
3455 ********************************************************************/
3457 static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
3458 struct printer_handle *print_hnd,
3459 struct spoolss_NotifyInfo *info,
3460 struct spoolss_PrinterInfo2 *pinfo2,
3462 const struct spoolss_NotifyOptionType *option_type,
3464 TALLOC_CTX *mem_ctx)
3467 enum spoolss_NotifyType type;
3470 struct spoolss_Notify *current_data;
3472 type = option_type->type;
3474 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3475 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3476 option_type->count, lp_servicename(snum)));
3478 for(field_num=0; field_num < option_type->count; field_num++) {
3479 field = option_type->fields[field_num].field;
3481 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3483 if (!search_notify(type, field, &j) )
3486 info->notifies = talloc_realloc(info, info->notifies,
3487 struct spoolss_Notify,
3489 if (info->notifies == NULL) {
3490 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3494 current_data = &info->notifies[info->count];
3496 construct_info_data(current_data, type, field, id);
3498 DEBUG(10, ("construct_notify_printer_info: "
3499 "calling [%s] snum=%d printername=[%s])\n",
3500 notify_info_data_table[j].name, snum,
3501 pinfo2->printername));
3503 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3504 NULL, pinfo2, mem_ctx);
3512 /*******************************************************************
3514 * fill a notify_info struct with info asked
3516 ********************************************************************/
3518 static bool construct_notify_jobs_info(struct messaging_context *msg_ctx,
3519 print_queue_struct *queue,
3520 struct spoolss_NotifyInfo *info,
3521 struct spoolss_PrinterInfo2 *pinfo2,
3523 const struct spoolss_NotifyOptionType *option_type,
3525 TALLOC_CTX *mem_ctx)
3528 enum spoolss_NotifyType type;
3530 struct spoolss_Notify *current_data;
3532 DEBUG(4,("construct_notify_jobs_info\n"));
3534 type = option_type->type;
3536 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3537 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3538 option_type->count));
3540 for(field_num=0; field_num<option_type->count; field_num++) {
3541 field = option_type->fields[field_num].field;
3543 if (!search_notify(type, field, &j) )
3546 info->notifies = talloc_realloc(info, info->notifies,
3547 struct spoolss_Notify,
3549 if (info->notifies == NULL) {
3550 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3554 current_data=&(info->notifies[info->count]);
3556 construct_info_data(current_data, type, field, id);
3557 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3558 queue, pinfo2, mem_ctx);
3566 * JFM: The enumeration is not that simple, it's even non obvious.
3568 * let's take an example: I want to monitor the PRINTER SERVER for
3569 * the printer's name and the number of jobs currently queued.
3570 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3571 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3573 * I have 3 printers on the back of my server.
3575 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3578 * 1 printer 1 name 1
3579 * 2 printer 1 cjob 1
3580 * 3 printer 2 name 2
3581 * 4 printer 2 cjob 2
3582 * 5 printer 3 name 3
3583 * 6 printer 3 name 3
3585 * that's the print server case, the printer case is even worse.
3588 /*******************************************************************
3590 * enumerate all printers on the printserver
3591 * fill a notify_info struct with info asked
3593 ********************************************************************/
3595 static WERROR printserver_notify_info(struct pipes_struct *p,
3596 struct policy_handle *hnd,
3597 struct spoolss_NotifyInfo *info,
3598 TALLOC_CTX *mem_ctx)
3601 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3602 int n_services=lp_numservices();
3604 struct spoolss_NotifyOption *option;
3605 struct spoolss_NotifyOptionType option_type;
3606 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3609 DEBUG(4,("printserver_notify_info\n"));
3614 option = Printer->notify.option;
3617 info->notifies = NULL;
3620 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3621 sending a ffpcn() request first */
3626 for (i=0; i<option->count; i++) {
3627 option_type = option->types[i];
3629 if (option_type.type != PRINTER_NOTIFY_TYPE)
3632 for (snum = 0; snum < n_services; snum++) {
3633 if (!lp_browseable(snum) ||
3634 !lp_snum_ok(snum) ||
3635 !lp_print_ok(snum)) {
3636 continue; /* skip */
3639 /* Maybe we should use the SYSTEM session_info here... */
3640 result = winreg_get_printer_internal(mem_ctx,
3641 get_session_info_system(),
3643 lp_servicename(snum),
3645 if (!W_ERROR_IS_OK(result)) {
3646 DEBUG(4, ("printserver_notify_info: "
3647 "Failed to get printer [%s]\n",
3648 lp_servicename(snum)));
3653 construct_notify_printer_info(p->msg_ctx,
3659 TALLOC_FREE(pinfo2);
3665 * Debugging information, don't delete.
3668 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3669 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3670 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3672 for (i=0; i<info->count; i++) {
3673 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3674 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3675 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3682 /*******************************************************************
3684 * fill a notify_info struct with info asked
3686 ********************************************************************/
3688 static WERROR printer_notify_info(struct pipes_struct *p,
3689 struct policy_handle *hnd,
3690 struct spoolss_NotifyInfo *info,
3691 TALLOC_CTX *mem_ctx)
3694 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3697 struct spoolss_NotifyOption *option;
3698 struct spoolss_NotifyOptionType option_type;
3700 print_queue_struct *queue=NULL;
3701 print_status_struct status;
3702 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3705 DEBUG(4,("printer_notify_info\n"));
3710 option = Printer->notify.option;
3714 info->notifies = NULL;
3717 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3718 sending a ffpcn() request first */
3723 if (!get_printer_snum(p, hnd, &snum, NULL)) {
3727 /* Maybe we should use the SYSTEM session_info here... */
3728 result = winreg_get_printer_internal(mem_ctx,
3729 get_session_info_system(),
3731 lp_servicename(snum), &pinfo2);
3732 if (!W_ERROR_IS_OK(result)) {
3736 for (i=0; i<option->count; i++) {
3737 option_type = option->types[i];
3739 switch (option_type.type) {
3740 case PRINTER_NOTIFY_TYPE:
3741 if (construct_notify_printer_info(p->msg_ctx,
3750 case JOB_NOTIFY_TYPE:
3752 count = print_queue_status(p->msg_ctx, snum, &queue,
3755 for (j=0; j<count; j++) {
3756 construct_notify_jobs_info(p->msg_ctx,
3770 * Debugging information, don't delete.
3773 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3774 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3775 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3777 for (i=0; i<info->count; i++) {
3778 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3779 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3780 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3784 talloc_free(pinfo2);
3788 /****************************************************************
3789 _spoolss_RouterRefreshPrinterChangeNotify
3790 ****************************************************************/
3792 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3793 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3795 struct spoolss_NotifyInfo *info;
3797 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
3798 WERROR result = WERR_BADFID;
3800 /* we always have a spoolss_NotifyInfo struct */
3801 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3803 result = WERR_NOMEM;
3807 *r->out.info = info;
3810 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3811 "Invalid handle (%s:%u:%u).\n",
3812 OUR_HANDLE(r->in.handle)));
3816 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3819 * We are now using the change value, and
3820 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3821 * I don't have a global notification system, I'm sending back all the
3822 * information even when _NOTHING_ has changed.
3825 /* We need to keep track of the change value to send back in
3826 RRPCN replies otherwise our updates are ignored. */
3828 Printer->notify.fnpcn = true;
3830 if (Printer->notify.cli_chan != NULL &&
3831 Printer->notify.cli_chan->active_connections > 0) {
3832 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3833 "Saving change value in request [%x]\n",
3835 Printer->notify.change = r->in.change_low;
3838 /* just ignore the spoolss_NotifyOption */
3840 switch (Printer->printer_type) {
3842 result = printserver_notify_info(p, r->in.handle,
3846 case SPLHND_PRINTER:
3847 result = printer_notify_info(p, r->in.handle,
3852 Printer->notify.fnpcn = false;
3858 /********************************************************************
3859 ********************************************************************/
3861 static WERROR create_printername(TALLOC_CTX *mem_ctx,
3862 const char *servername,
3863 const char *printername,
3864 const char **printername_p)
3866 /* FIXME: add lp_force_printername() */
3868 if (servername == NULL) {
3869 *printername_p = talloc_strdup(mem_ctx, printername);
3870 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3874 if (servername[0] == '\\' && servername[1] == '\\') {
3878 *printername_p = talloc_asprintf(mem_ctx, "\\\\%s\\%s", servername, printername);
3879 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3884 /********************************************************************
3885 ********************************************************************/
3887 static void compose_devicemode_devicename(struct spoolss_DeviceMode *dm,
3888 const char *printername)
3894 dm->devicename = talloc_strndup(dm, printername,
3895 MIN(strlen(printername), 31));
3898 /********************************************************************
3899 * construct_printer_info_0
3900 * fill a printer_info_0 struct
3901 ********************************************************************/
3903 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3904 const struct auth_session_info *session_info,
3905 struct messaging_context *msg_ctx,
3906 struct spoolss_PrinterInfo2 *info2,
3907 const char *servername,
3908 struct spoolss_PrinterInfo0 *r,
3912 struct printer_session_counter *session_counter;
3913 struct timeval setuptime;
3914 print_status_struct status;
3917 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3918 if (!W_ERROR_IS_OK(result)) {
3923 r->servername = talloc_strdup(mem_ctx, servername);
3924 W_ERROR_HAVE_NO_MEMORY(r->servername);
3926 r->servername = NULL;
3929 count = print_queue_length(msg_ctx, snum, &status);
3931 /* check if we already have a counter for this printer */
3932 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3933 if (session_counter->snum == snum)
3937 /* it's the first time, add it to the list */
3938 if (session_counter == NULL) {
3939 session_counter = talloc_zero(counter_list, struct printer_session_counter);
3940 W_ERROR_HAVE_NO_MEMORY(session_counter);
3941 session_counter->snum = snum;
3942 session_counter->counter = 0;
3943 DLIST_ADD(counter_list, session_counter);
3947 session_counter->counter++;
3953 get_startup_time(&setuptime);
3954 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3957 * the global_counter should be stored in a TDB as it's common to all the clients
3958 * and should be zeroed on samba startup
3960 r->global_counter = session_counter->counter;
3962 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3963 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3964 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3965 r->free_build = SPOOLSS_RELEASE_BUILD;
3967 r->max_spooling = 0;
3968 r->session_counter = session_counter->counter;
3969 r->num_error_out_of_paper = 0x0;
3970 r->num_error_not_ready = 0x0; /* number of print failure */
3972 r->number_of_processors = 0x1;
3973 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3974 r->high_part_total_bytes = 0x0;
3976 /* ChangeID in milliseconds*/
3977 winreg_printer_get_changeid_internal(mem_ctx, session_info, msg_ctx,
3978 info2->sharename, &r->change_id);
3980 r->last_error = WERR_OK;
3981 r->status = nt_printq_status(status.status);
3982 r->enumerate_network_printers = 0x0;
3983 r->c_setprinter = 0x0;
3984 r->processor_architecture = PROCESSOR_ARCHITECTURE_INTEL;
3985 r->processor_level = 0x6; /* 6 ???*/
3994 /********************************************************************
3995 * construct_printer_info1
3996 * fill a spoolss_PrinterInfo1 struct
3997 ********************************************************************/
3999 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
4000 const struct spoolss_PrinterInfo2 *info2,
4002 const char *servername,
4003 struct spoolss_PrinterInfo1 *r,
4010 if (info2->comment == NULL || info2->comment[0] == '\0') {
4011 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
4013 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
4015 W_ERROR_HAVE_NO_MEMORY(r->comment);
4017 result = create_printername(mem_ctx, servername, info2->printername, &r->name);
4018 if (!W_ERROR_IS_OK(result)) {
4022 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
4026 W_ERROR_HAVE_NO_MEMORY(r->description);
4031 /********************************************************************
4032 * construct_printer_info2
4033 * fill a spoolss_PrinterInfo2 struct
4034 ********************************************************************/
4036 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
4037 struct messaging_context *msg_ctx,
4038 const struct spoolss_PrinterInfo2 *info2,
4039 const char *servername,
4040 struct spoolss_PrinterInfo2 *r,
4044 print_status_struct status;
4047 count = print_queue_length(msg_ctx, snum, &status);
4050 r->servername = talloc_strdup(mem_ctx, servername);
4051 W_ERROR_HAVE_NO_MEMORY(r->servername);
4053 r->servername = NULL;
4056 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4057 if (!W_ERROR_IS_OK(result)) {
4061 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
4062 W_ERROR_HAVE_NO_MEMORY(r->sharename);
4063 r->portname = talloc_strdup(mem_ctx, info2->portname);
4064 W_ERROR_HAVE_NO_MEMORY(r->portname);
4065 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
4066 W_ERROR_HAVE_NO_MEMORY(r->drivername);
4068 if (info2->comment[0] == '\0') {
4069 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
4071 r->comment = talloc_strdup(mem_ctx, info2->comment);
4073 W_ERROR_HAVE_NO_MEMORY(r->comment);
4075 r->location = talloc_strdup(mem_ctx, info2->location);
4076 if (info2->location[0] == '\0') {
4077 const char *loc = NULL;
4080 nt_status = printer_list_get_printer(mem_ctx,
4085 if (NT_STATUS_IS_OK(nt_status)) {
4087 r->location = talloc_strdup(mem_ctx, loc);
4091 W_ERROR_HAVE_NO_MEMORY(r->location);
4093 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
4094 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
4095 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
4096 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
4097 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
4098 W_ERROR_HAVE_NO_MEMORY(r->datatype);
4099 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
4100 W_ERROR_HAVE_NO_MEMORY(r->parameters);
4102 r->attributes = info2->attributes;
4104 r->priority = info2->priority;
4105 r->defaultpriority = info2->defaultpriority;
4106 r->starttime = info2->starttime;
4107 r->untiltime = info2->untiltime;
4108 r->status = nt_printq_status(status.status);
4110 r->averageppm = info2->averageppm;
4112 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
4114 DEBUG(8,("Returning NULL Devicemode!\n"));
4117 compose_devicemode_devicename(r->devmode, r->printername);
4121 if (info2->secdesc != NULL) {
4122 /* don't use talloc_steal() here unless you do a deep steal of all
4123 the SEC_DESC members */
4125 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4131 /********************************************************************
4132 * construct_printer_info3
4133 * fill a spoolss_PrinterInfo3 struct
4134 ********************************************************************/
4136 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
4137 const struct spoolss_PrinterInfo2 *info2,
4138 const char *servername,
4139 struct spoolss_PrinterInfo3 *r,
4142 /* These are the components of the SD we are returning. */
4144 if (info2->secdesc != NULL) {
4145 /* don't use talloc_steal() here unless you do a deep steal of all
4146 the SEC_DESC members */
4148 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4149 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
4155 /********************************************************************
4156 * construct_printer_info4
4157 * fill a spoolss_PrinterInfo4 struct
4158 ********************************************************************/
4160 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4161 const struct spoolss_PrinterInfo2 *info2,
4162 const char *servername,
4163 struct spoolss_PrinterInfo4 *r,
4168 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4169 if (!W_ERROR_IS_OK(result)) {
4174 r->servername = talloc_strdup(mem_ctx, servername);
4175 W_ERROR_HAVE_NO_MEMORY(r->servername);
4177 r->servername = NULL;
4180 r->attributes = info2->attributes;
4185 /********************************************************************
4186 * construct_printer_info5
4187 * fill a spoolss_PrinterInfo5 struct
4188 ********************************************************************/
4190 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4191 const struct spoolss_PrinterInfo2 *info2,
4192 const char *servername,
4193 struct spoolss_PrinterInfo5 *r,
4198 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4199 if (!W_ERROR_IS_OK(result)) {
4203 r->portname = talloc_strdup(mem_ctx, info2->portname);
4204 W_ERROR_HAVE_NO_MEMORY(r->portname);
4206 r->attributes = info2->attributes;
4208 /* these two are not used by NT+ according to MSDN */
4209 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4210 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4215 /********************************************************************
4216 * construct_printer_info_6
4217 * fill a spoolss_PrinterInfo6 struct
4218 ********************************************************************/
4220 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4221 struct messaging_context *msg_ctx,
4222 const struct spoolss_PrinterInfo2 *info2,
4223 const char *servername,
4224 struct spoolss_PrinterInfo6 *r,
4227 print_status_struct status;
4229 print_queue_length(msg_ctx, snum, &status);
4231 r->status = nt_printq_status(status.status);
4236 /********************************************************************
4237 * construct_printer_info7
4238 * fill a spoolss_PrinterInfo7 struct
4239 ********************************************************************/
4241 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4242 struct messaging_context *msg_ctx,
4243 const char *servername,
4244 struct spoolss_PrinterInfo7 *r,
4247 struct auth_session_info *session_info;
4251 status = make_session_info_system(mem_ctx, &session_info);
4252 if (!NT_STATUS_IS_OK(status)) {
4253 DEBUG(0, ("construct_printer_info7: "
4254 "Could not create system session_info\n"));
4258 if (is_printer_published(mem_ctx, session_info, msg_ctx,
4260 lp_servicename(snum), &guid, NULL)) {
4261 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4262 r->action = DSPRINT_PUBLISH;
4264 r->guid = talloc_strdup(mem_ctx, "");
4265 r->action = DSPRINT_UNPUBLISH;
4267 W_ERROR_HAVE_NO_MEMORY(r->guid);
4269 TALLOC_FREE(session_info);
4273 /********************************************************************
4274 * construct_printer_info8
4275 * fill a spoolss_PrinterInfo8 struct
4276 ********************************************************************/
4278 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4279 const struct spoolss_PrinterInfo2 *info2,
4280 const char *servername,
4281 struct spoolss_DeviceModeInfo *r,
4285 const char *printername;
4287 result = create_printername(mem_ctx, servername, info2->printername, &printername);
4288 if (!W_ERROR_IS_OK(result)) {
4292 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
4294 DEBUG(8,("Returning NULL Devicemode!\n"));
4297 compose_devicemode_devicename(r->devmode, printername);
4303 /********************************************************************
4304 ********************************************************************/
4306 static bool snum_is_shared_printer(int snum)
4308 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4311 /********************************************************************
4312 Spoolss_enumprinters.
4313 ********************************************************************/
4315 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4316 const struct auth_session_info *session_info,
4317 struct messaging_context *msg_ctx,
4318 const char *servername,
4321 union spoolss_PrinterInfo **info_p,
4325 int n_services = lp_numservices();
4326 union spoolss_PrinterInfo *info = NULL;
4328 WERROR result = WERR_OK;
4329 struct dcerpc_binding_handle *b = NULL;
4330 TALLOC_CTX *tmp_ctx = NULL;
4332 tmp_ctx = talloc_new(mem_ctx);
4340 for (snum = 0; snum < n_services; snum++) {
4342 const char *printer;
4343 struct spoolss_PrinterInfo2 *info2;
4345 if (!snum_is_shared_printer(snum)) {
4349 printer = lp_const_servicename(snum);
4351 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4355 result = winreg_printer_binding_handle(tmp_ctx,
4359 if (!W_ERROR_IS_OK(result)) {
4364 result = winreg_create_printer(tmp_ctx, b,
4366 if (!W_ERROR_IS_OK(result)) {
4370 info = talloc_realloc(tmp_ctx, info,
4371 union spoolss_PrinterInfo,
4374 result = WERR_NOMEM;
4378 result = winreg_get_printer(tmp_ctx, b,
4380 if (!W_ERROR_IS_OK(result)) {
4386 result = construct_printer_info0(info, session_info,
4389 &info[count].info0, snum);
4392 result = construct_printer_info1(info, info2, flags,
4394 &info[count].info1, snum);
4397 result = construct_printer_info2(info, msg_ctx, info2,
4399 &info[count].info2, snum);
4402 result = construct_printer_info4(info, info2,
4404 &info[count].info4, snum);
4407 result = construct_printer_info5(info, info2,
4409 &info[count].info5, snum);
4413 result = WERR_UNKNOWN_LEVEL;
4417 if (!W_ERROR_IS_OK(result)) {
4425 if (W_ERROR_IS_OK(result)) {
4426 *info_p = talloc_move(mem_ctx, &info);
4430 talloc_free(tmp_ctx);
4435 /********************************************************************
4436 * handle enumeration of printers at level 0
4437 ********************************************************************/
4439 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4440 const struct auth_session_info *session_info,
4441 struct messaging_context *msg_ctx,
4443 const char *servername,
4444 union spoolss_PrinterInfo **info,
4447 DEBUG(4,("enum_all_printers_info_0\n"));
4449 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4450 servername, 0, flags, info, count);
4454 /********************************************************************
4455 ********************************************************************/
4457 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4458 const struct auth_session_info *session_info,
4459 struct messaging_context *msg_ctx,
4460 const char *servername,
4462 union spoolss_PrinterInfo **info,
4465 DEBUG(4,("enum_all_printers_info_1\n"));
4467 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4468 servername, 1, flags, info, count);
4471 /********************************************************************
4472 enum_all_printers_info_1_local.
4473 *********************************************************************/
4475 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4476 const struct auth_session_info *session_info,
4477 struct messaging_context *msg_ctx,
4478 const char *servername,
4479 union spoolss_PrinterInfo **info,
4482 DEBUG(4,("enum_all_printers_info_1_local\n"));
4484 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4485 servername, PRINTER_ENUM_ICON8, info, count);
4488 /********************************************************************
4489 enum_all_printers_info_1_name.
4490 *********************************************************************/
4492 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4493 const struct auth_session_info *session_info,
4494 struct messaging_context *msg_ctx,
4495 const char *servername,
4496 union spoolss_PrinterInfo **info,
4499 const char *s = servername;
4501 DEBUG(4,("enum_all_printers_info_1_name\n"));
4503 if ((servername[0] == '\\') && (servername[1] == '\\')) {
4507 if (!is_myname_or_ipaddr(s)) {
4508 return WERR_INVALID_NAME;
4511 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4512 servername, PRINTER_ENUM_ICON8, info, count);
4515 /********************************************************************
4516 enum_all_printers_info_1_network.
4517 *********************************************************************/
4519 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4520 const struct auth_session_info *session_info,
4521 struct messaging_context *msg_ctx,
4522 const char *servername,
4523 union spoolss_PrinterInfo **info,
4526 const char *s = servername;
4528 DEBUG(4,("enum_all_printers_info_1_network\n"));
4530 /* If we respond to a enum_printers level 1 on our name with flags
4531 set to PRINTER_ENUM_REMOTE with a list of printers then these
4532 printers incorrectly appear in the APW browse list.
4533 Specifically the printers for the server appear at the workgroup
4534 level where all the other servers in the domain are
4535 listed. Windows responds to this call with a
4536 WERR_CAN_NOT_COMPLETE so we should do the same. */
4538 if (servername[0] == '\\' && servername[1] == '\\') {
4542 if (is_myname_or_ipaddr(s)) {
4543 return WERR_CAN_NOT_COMPLETE;
4546 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4547 servername, PRINTER_ENUM_NAME, info, count);
4550 /********************************************************************
4551 * api_spoolss_enumprinters
4553 * called from api_spoolss_enumprinters (see this to understand)
4554 ********************************************************************/
4556 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4557 const struct auth_session_info *session_info,
4558 struct messaging_context *msg_ctx,
4559 const char *servername,
4560 union spoolss_PrinterInfo **info,
4563 DEBUG(4,("enum_all_printers_info_2\n"));
4565 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4566 servername, 2, 0, info, count);
4569 /********************************************************************
4570 * handle enumeration of printers at level 1
4571 ********************************************************************/
4573 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4574 const struct auth_session_info *session_info,
4575 struct messaging_context *msg_ctx,
4577 const char *servername,
4578 union spoolss_PrinterInfo **info,
4581 /* Not all the flags are equals */
4583 if (flags & PRINTER_ENUM_LOCAL) {
4584 return enum_all_printers_info_1_local(mem_ctx, session_info,
4585 msg_ctx, servername, info, count);
4588 if (flags & PRINTER_ENUM_NAME) {
4589 return enum_all_printers_info_1_name(mem_ctx, session_info,
4590 msg_ctx, servername, info,
4594 if (flags & PRINTER_ENUM_NETWORK) {
4595 return enum_all_printers_info_1_network(mem_ctx, session_info,
4596 msg_ctx, servername, info,
4600 return WERR_OK; /* NT4sp5 does that */
4603 /********************************************************************
4604 * handle enumeration of printers at level 2
4605 ********************************************************************/
4607 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4608 const struct auth_session_info *session_info,
4609 struct messaging_context *msg_ctx,
4611 const char *servername,
4612 union spoolss_PrinterInfo **info,
4615 if (flags & PRINTER_ENUM_LOCAL) {
4617 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4622 if (flags & PRINTER_ENUM_NAME) {
4623 if (servername && !is_myname_or_ipaddr(canon_servername(servername))) {
4624 return WERR_INVALID_NAME;
4627 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4632 if (flags & PRINTER_ENUM_REMOTE) {
4633 return WERR_UNKNOWN_LEVEL;
4639 /********************************************************************
4640 * handle enumeration of printers at level 4
4641 ********************************************************************/
4643 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4644 const struct auth_session_info *session_info,
4645 struct messaging_context *msg_ctx,
4647 const char *servername,
4648 union spoolss_PrinterInfo **info,
4651 DEBUG(4,("enum_all_printers_info_4\n"));
4653 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4654 servername, 4, flags, info, count);
4658 /********************************************************************
4659 * handle enumeration of printers at level 5
4660 ********************************************************************/
4662 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4663 const struct auth_session_info *session_info,
4664 struct messaging_context *msg_ctx,
4666 const char *servername,
4667 union spoolss_PrinterInfo **info,
4670 DEBUG(4,("enum_all_printers_info_5\n"));
4672 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4673 servername, 5, flags, info, count);
4676 /****************************************************************
4677 _spoolss_EnumPrinters
4678 ****************************************************************/
4680 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4681 struct spoolss_EnumPrinters *r)
4683 const struct auth_session_info *session_info = get_session_info_system();
4686 /* that's an [in out] buffer */
4688 if (!r->in.buffer && (r->in.offered != 0)) {
4689 return WERR_INVALID_PARAM;
4692 DEBUG(4,("_spoolss_EnumPrinters\n"));
4696 *r->out.info = NULL;
4700 * flags==PRINTER_ENUM_NAME
4701 * if name=="" then enumerates all printers
4702 * if name!="" then enumerate the printer
4703 * flags==PRINTER_ENUM_REMOTE
4704 * name is NULL, enumerate printers
4705 * Level 2: name!="" enumerates printers, name can't be NULL
4706 * Level 3: doesn't exist
4707 * Level 4: does a local registry lookup
4708 * Level 5: same as Level 2
4711 if (r->in.server && r->in.server[0] == '\0') {
4712 r->in.server = NULL;
4715 switch (r->in.level) {
4717 result = enumprinters_level0(p->mem_ctx, session_info,
4718 p->msg_ctx, r->in.flags,
4720 r->out.info, r->out.count);
4723 result = enumprinters_level1(p->mem_ctx, session_info,
4724 p->msg_ctx, r->in.flags,
4726 r->out.info, r->out.count);
4729 result = enumprinters_level2(p->mem_ctx, session_info,
4730 p->msg_ctx, r->in.flags,
4732 r->out.info, r->out.count);
4735 result = enumprinters_level4(p->mem_ctx, session_info,
4736 p->msg_ctx, r->in.flags,
4738 r->out.info, r->out.count);
4741 result = enumprinters_level5(p->mem_ctx, session_info,
4742 p->msg_ctx, r->in.flags,
4744 r->out.info, r->out.count);
4747 return WERR_UNKNOWN_LEVEL;
4750 if (!W_ERROR_IS_OK(result)) {
4754 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4755 spoolss_EnumPrinters,
4756 *r->out.info, r->in.level,
4758 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4759 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4761 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4764 /****************************************************************
4766 ****************************************************************/
4768 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4769 struct spoolss_GetPrinter *r)
4771 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
4772 struct spoolss_PrinterInfo2 *info2 = NULL;
4773 WERROR result = WERR_OK;
4776 /* that's an [in out] buffer */
4778 if (!r->in.buffer && (r->in.offered != 0)) {
4779 return WERR_INVALID_PARAM;
4784 if (Printer == NULL) {
4788 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4792 result = winreg_get_printer_internal(p->mem_ctx,
4793 get_session_info_system(),
4795 lp_const_servicename(snum),
4797 if (!W_ERROR_IS_OK(result)) {
4801 switch (r->in.level) {
4803 result = construct_printer_info0(p->mem_ctx,
4804 get_session_info_system(),
4807 Printer->servername,
4808 &r->out.info->info0,
4812 result = construct_printer_info1(p->mem_ctx, info2,
4814 Printer->servername,
4815 &r->out.info->info1, snum);
4818 result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
4819 Printer->servername,
4820 &r->out.info->info2, snum);
4823 result = construct_printer_info3(p->mem_ctx, info2,
4824 Printer->servername,
4825 &r->out.info->info3, snum);
4828 result = construct_printer_info4(p->mem_ctx, info2,
4829 Printer->servername,
4830 &r->out.info->info4, snum);
4833 result = construct_printer_info5(p->mem_ctx, info2,
4834 Printer->servername,
4835 &r->out.info->info5, snum);
4838 result = construct_printer_info6(p->mem_ctx, p->msg_ctx, info2,
4839 Printer->servername,
4840 &r->out.info->info6, snum);
4843 result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
4844 Printer->servername,
4845 &r->out.info->info7, snum);
4848 result = construct_printer_info8(p->mem_ctx, info2,
4849 Printer->servername,
4850 &r->out.info->info8, snum);
4853 result = WERR_UNKNOWN_LEVEL;
4858 if (!W_ERROR_IS_OK(result)) {
4859 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4860 r->in.level, win_errstr(result)));
4861 TALLOC_FREE(r->out.info);
4865 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4866 r->out.info, r->in.level);
4867 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4869 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4872 /********************************************************************
4873 ********************************************************************/
4875 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4877 if (in && strlen(in)) { \
4878 out = talloc_strdup(mem_ctx, in); \
4880 out = talloc_strdup(mem_ctx, ""); \
4882 W_ERROR_HAVE_NO_MEMORY(out); \
4885 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4887 if (in && strlen(in)) { \
4888 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4890 out = talloc_strdup(mem_ctx, ""); \
4892 W_ERROR_HAVE_NO_MEMORY(out); \
4895 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4896 const char **string_array,
4897 const char ***presult,
4898 const char *cservername,
4902 int i, num_strings = 0;
4903 const char **array = NULL;
4905 if (string_array == NULL) {
4906 return WERR_INVALID_PARAMETER;
4909 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4910 const char *str = NULL;
4912 if (cservername == NULL || arch == NULL) {
4913 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4915 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4918 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4925 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4926 &array, &num_strings);
4936 /********************************************************************
4937 * fill a spoolss_DriverInfo1 struct
4938 ********************************************************************/
4940 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4941 struct spoolss_DriverInfo1 *r,
4942 const struct spoolss_DriverInfo8 *driver,
4943 const char *servername)
4945 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4946 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4951 /********************************************************************
4952 * fill a spoolss_DriverInfo2 struct
4953 ********************************************************************/
4955 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4956 struct spoolss_DriverInfo2 *r,
4957 const struct spoolss_DriverInfo8 *driver,
4958 const char *servername)
4961 const char *cservername = canon_servername(servername);
4963 r->version = driver->version;
4965 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4966 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4967 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4968 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4970 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4971 driver->architecture,
4973 driver->driver_path,
4976 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4977 driver->architecture,
4982 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4983 driver->architecture,
4985 driver->config_file,
4991 /********************************************************************
4992 * fill a spoolss_DriverInfo3 struct
4993 ********************************************************************/
4995 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4996 struct spoolss_DriverInfo3 *r,
4997 const struct spoolss_DriverInfo8 *driver,
4998 const char *servername)
5000 const char *cservername = canon_servername(servername);
5002 r->version = driver->version;
5004 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5005 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5006 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5007 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5009 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5010 driver->architecture,
5012 driver->driver_path,
5015 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5016 driver->architecture,
5021 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5022 driver->architecture,
5024 driver->config_file,
5027 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5028 driver->architecture,
5033 FILL_DRIVER_STRING(mem_ctx,
5034 driver->monitor_name,
5037 FILL_DRIVER_STRING(mem_ctx,
5038 driver->default_datatype,
5039 r->default_datatype);
5041 return string_array_from_driver_info(mem_ctx,
5042 driver->dependent_files,
5043 &r->dependent_files,
5045 driver->architecture,
5049 /********************************************************************
5050 * fill a spoolss_DriverInfo4 struct
5051 ********************************************************************/
5053 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
5054 struct spoolss_DriverInfo4 *r,
5055 const struct spoolss_DriverInfo8 *driver,
5056 const char *servername)
5058 const char *cservername = canon_servername(servername);
5061 r->version = driver->version;
5063 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5064 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5065 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5066 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5068 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5069 driver->architecture,
5071 driver->driver_path,
5074 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5075 driver->architecture,
5080 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5081 driver->architecture,
5083 driver->config_file,
5086 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5087 driver->architecture,
5092 result = string_array_from_driver_info(mem_ctx,
5093 driver->dependent_files,
5094 &r->dependent_files,
5096 driver->architecture,
5098 if (!W_ERROR_IS_OK(result)) {
5102 FILL_DRIVER_STRING(mem_ctx,
5103 driver->monitor_name,
5106 FILL_DRIVER_STRING(mem_ctx,
5107 driver->default_datatype,
5108 r->default_datatype);
5111 result = string_array_from_driver_info(mem_ctx,
5112 driver->previous_names,
5119 /********************************************************************
5120 * fill a spoolss_DriverInfo5 struct
5121 ********************************************************************/
5123 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
5124 struct spoolss_DriverInfo5 *r,
5125 const struct spoolss_DriverInfo8 *driver,
5126 const char *servername)
5128 const char *cservername = canon_servername(servername);
5130 r->version = driver->version;
5132 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5133 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5134 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5135 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5137 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5138 driver->architecture,
5140 driver->driver_path,
5143 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5144 driver->architecture,
5149 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5150 driver->architecture,
5152 driver->config_file,
5155 r->driver_attributes = 0;
5156 r->config_version = 0;
5157 r->driver_version = 0;
5161 /********************************************************************
5162 * fill a spoolss_DriverInfo6 struct
5163 ********************************************************************/
5165 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
5166 struct spoolss_DriverInfo6 *r,
5167 const struct spoolss_DriverInfo8 *driver,
5168 const char *servername)
5170 const char *cservername = canon_servername(servername);
5173 r->version = driver->version;
5175 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5176 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5177 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5178 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5180 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5181 driver->architecture,
5183 driver->driver_path,
5186 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5187 driver->architecture,
5192 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5193 driver->architecture,
5195 driver->config_file,
5198 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5199 driver->architecture,
5204 FILL_DRIVER_STRING(mem_ctx,
5205 driver->monitor_name,
5208 FILL_DRIVER_STRING(mem_ctx,
5209 driver->default_datatype,
5210 r->default_datatype);
5212 result = string_array_from_driver_info(mem_ctx,
5213 driver->dependent_files,
5214 &r->dependent_files,
5216 driver->architecture,
5218 if (!W_ERROR_IS_OK(result)) {
5222 result = string_array_from_driver_info(mem_ctx,
5223 driver->previous_names,
5226 if (!W_ERROR_IS_OK(result)) {
5230 r->driver_date = driver->driver_date;
5231 r->driver_version = driver->driver_version;
5233 FILL_DRIVER_STRING(mem_ctx,
5234 driver->manufacturer_name,
5235 r->manufacturer_name);
5236 FILL_DRIVER_STRING(mem_ctx,
5237 driver->manufacturer_url,
5238 r->manufacturer_url);
5239 FILL_DRIVER_STRING(mem_ctx,
5240 driver->hardware_id,
5242 FILL_DRIVER_STRING(mem_ctx,
5249 /********************************************************************
5250 * fill a spoolss_DriverInfo8 struct
5251 ********************************************************************/
5253 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
5254 struct spoolss_DriverInfo8 *r,
5255 const struct spoolss_DriverInfo8 *driver,
5256 const char *servername)
5258 const char *cservername = canon_servername(servername);
5261 r->version = driver->version;
5263 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5264 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5265 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5266 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5268 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5269 driver->architecture,
5271 driver->driver_path,
5274 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5275 driver->architecture,
5280 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5281 driver->architecture,
5283 driver->config_file,
5286 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5287 driver->architecture,
5292 FILL_DRIVER_STRING(mem_ctx,
5293 driver->monitor_name,
5296 FILL_DRIVER_STRING(mem_ctx,
5297 driver->default_datatype,
5298 r->default_datatype);
5300 result = string_array_from_driver_info(mem_ctx,
5301 driver->dependent_files,
5302 &r->dependent_files,
5304 driver->architecture,
5306 if (!W_ERROR_IS_OK(result)) {
5310 result = string_array_from_driver_info(mem_ctx,
5311 driver->previous_names,
5314 if (!W_ERROR_IS_OK(result)) {
5318 r->driver_date = driver->driver_date;
5319 r->driver_version = driver->driver_version;
5321 FILL_DRIVER_STRING(mem_ctx,
5322 driver->manufacturer_name,
5323 r->manufacturer_name);
5324 FILL_DRIVER_STRING(mem_ctx,
5325 driver->manufacturer_url,
5326 r->manufacturer_url);
5327 FILL_DRIVER_STRING(mem_ctx,
5328 driver->hardware_id,
5330 FILL_DRIVER_STRING(mem_ctx,
5334 FILL_DRIVER_STRING(mem_ctx,
5335 driver->print_processor,
5336 r->print_processor);
5337 FILL_DRIVER_STRING(mem_ctx,
5338 driver->vendor_setup,
5341 result = string_array_from_driver_info(mem_ctx,
5342 driver->color_profiles,
5345 if (!W_ERROR_IS_OK(result)) {
5349 FILL_DRIVER_STRING(mem_ctx,
5353 r->printer_driver_attributes = driver->printer_driver_attributes;
5355 result = string_array_from_driver_info(mem_ctx,
5356 driver->core_driver_dependencies,
5357 &r->core_driver_dependencies,
5359 if (!W_ERROR_IS_OK(result)) {
5363 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
5364 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
5369 #if 0 /* disabled until marshalling issues are resolved - gd */
5370 /********************************************************************
5371 ********************************************************************/
5373 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5374 struct spoolss_DriverFileInfo *r,
5375 const char *cservername,
5376 const char *file_name,
5377 enum spoolss_DriverFileType file_type,
5378 uint32_t file_version)
5380 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5381 cservername, file_name);
5382 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5383 r->file_type = file_type;
5384 r->file_version = file_version;
5389 /********************************************************************
5390 ********************************************************************/
5392 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5393 const struct spoolss_DriverInfo8 *driver,
5394 const char *cservername,
5395 struct spoolss_DriverFileInfo **info_p,
5398 struct spoolss_DriverFileInfo *info = NULL;
5406 if (strlen(driver->driver_path)) {
5407 info = talloc_realloc(mem_ctx, info,
5408 struct spoolss_DriverFileInfo,
5410 W_ERROR_HAVE_NO_MEMORY(info);
5411 result = fill_spoolss_DriverFileInfo(info,
5414 driver->driver_path,
5415 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5417 W_ERROR_NOT_OK_RETURN(result);
5421 if (strlen(driver->config_file)) {
5422 info = talloc_realloc(mem_ctx, info,
5423 struct spoolss_DriverFileInfo,
5425 W_ERROR_HAVE_NO_MEMORY(info);
5426 result = fill_spoolss_DriverFileInfo(info,
5429 driver->config_file,
5430 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5432 W_ERROR_NOT_OK_RETURN(result);
5436 if (strlen(driver->data_file)) {
5437 info = talloc_realloc(mem_ctx, info,
5438 struct spoolss_DriverFileInfo,
5440 W_ERROR_HAVE_NO_MEMORY(info);
5441 result = fill_spoolss_DriverFileInfo(info,
5445 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5447 W_ERROR_NOT_OK_RETURN(result);
5451 if (strlen(driver->help_file)) {
5452 info = talloc_realloc(mem_ctx, info,
5453 struct spoolss_DriverFileInfo,
5455 W_ERROR_HAVE_NO_MEMORY(info);
5456 result = fill_spoolss_DriverFileInfo(info,
5460 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5462 W_ERROR_NOT_OK_RETURN(result);
5466 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
5467 info = talloc_realloc(mem_ctx, info,
5468 struct spoolss_DriverFileInfo,
5470 W_ERROR_HAVE_NO_MEMORY(info);
5471 result = fill_spoolss_DriverFileInfo(info,
5474 driver->dependent_files[i],
5475 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5477 W_ERROR_NOT_OK_RETURN(result);
5487 /********************************************************************
5488 * fill a spoolss_DriverInfo101 struct
5489 ********************************************************************/
5491 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5492 struct spoolss_DriverInfo101 *r,
5493 const struct spoolss_DriverInfo8 *driver,
5494 const char *servername)
5496 const char *cservername = canon_servername(servername);
5499 r->version = driver->version;
5501 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5502 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5503 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5504 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5506 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5510 if (!W_ERROR_IS_OK(result)) {
5514 FILL_DRIVER_STRING(mem_ctx,
5515 driver->monitor_name,
5518 FILL_DRIVER_STRING(mem_ctx,
5519 driver->default_datatype,
5520 r->default_datatype);
5522 result = string_array_from_driver_info(mem_ctx,
5523 driver->previous_names,
5526 if (!W_ERROR_IS_OK(result)) {
5530 r->driver_date = driver->driver_date;
5531 r->driver_version = driver->driver_version;
5533 FILL_DRIVER_STRING(mem_ctx,
5534 driver->manufacturer_name,
5535 r->manufacturer_name);
5536 FILL_DRIVER_STRING(mem_ctx,
5537 driver->manufacturer_url,
5538 r->manufacturer_url);
5539 FILL_DRIVER_STRING(mem_ctx,
5540 driver->hardware_id,
5542 FILL_DRIVER_STRING(mem_ctx,
5549 /********************************************************************
5550 ********************************************************************/
5552 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5553 const struct auth_session_info *session_info,
5554 struct messaging_context *msg_ctx,
5556 union spoolss_DriverInfo *r,
5558 const char *servername,
5559 const char *architecture,
5562 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5563 struct spoolss_DriverInfo8 *driver;
5565 struct dcerpc_binding_handle *b;
5566 TALLOC_CTX *tmp_ctx = NULL;
5569 return WERR_UNKNOWN_LEVEL;
5572 tmp_ctx = talloc_new(mem_ctx);
5577 result = winreg_printer_binding_handle(tmp_ctx,
5581 if (!W_ERROR_IS_OK(result)) {
5585 result = winreg_get_printer(tmp_ctx, b,
5586 lp_const_servicename(snum),
5589 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5590 win_errstr(result)));
5592 if (!W_ERROR_IS_OK(result)) {
5593 result = WERR_INVALID_PRINTER_NAME;
5597 result = winreg_get_driver(tmp_ctx, b,
5599 pinfo2->drivername, version, &driver);
5601 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5602 win_errstr(result)));
5604 if (!W_ERROR_IS_OK(result)) {
5606 * Is this a W2k client ?
5610 result = WERR_UNKNOWN_PRINTER_DRIVER;
5614 /* Yes - try again with a WinNT driver. */
5616 result = winreg_get_driver(tmp_ctx, b,
5620 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5621 win_errstr(result)));
5622 if (!W_ERROR_IS_OK(result)) {
5623 result = WERR_UNKNOWN_PRINTER_DRIVER;
5628 /* these are allocated on mem_ctx and not tmp_ctx because they are
5629 * the 'return value' and need to utlive this call */
5632 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5635 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5638 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5641 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5644 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5647 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5650 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5652 #if 0 /* disabled until marshalling issues are resolved - gd */
5654 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5658 result = WERR_UNKNOWN_LEVEL;
5663 talloc_free(tmp_ctx);
5667 /****************************************************************
5668 _spoolss_GetPrinterDriver2
5669 ****************************************************************/
5671 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5672 struct spoolss_GetPrinterDriver2 *r)
5674 struct printer_handle *printer;
5679 /* that's an [in out] buffer */
5681 if (!r->in.buffer && (r->in.offered != 0)) {
5682 return WERR_INVALID_PARAM;
5685 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5687 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5688 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5689 return WERR_INVALID_PRINTER_NAME;
5693 *r->out.server_major_version = 0;
5694 *r->out.server_minor_version = 0;
5696 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5700 result = construct_printer_driver_info_level(p->mem_ctx,
5701 get_session_info_system(),
5703 r->in.level, r->out.info,
5704 snum, printer->servername,
5706 r->in.client_major_version);
5707 if (!W_ERROR_IS_OK(result)) {
5708 TALLOC_FREE(r->out.info);
5712 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5713 r->out.info, r->in.level);
5714 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5716 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5720 /****************************************************************
5721 _spoolss_StartPagePrinter
5722 ****************************************************************/
5724 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5725 struct spoolss_StartPagePrinter *r)
5727 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5730 DEBUG(3,("_spoolss_StartPagePrinter: "
5731 "Error in startpageprinter printer handle\n"));
5735 Printer->page_started = true;
5739 /****************************************************************
5740 _spoolss_EndPagePrinter
5741 ****************************************************************/
5743 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5744 struct spoolss_EndPagePrinter *r)
5748 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5751 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5752 OUR_HANDLE(r->in.handle)));
5756 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5759 Printer->page_started = false;
5760 print_job_endpage(p->msg_ctx, snum, Printer->jobid);
5765 /****************************************************************
5766 _spoolss_StartDocPrinter
5767 ****************************************************************/
5769 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5770 struct spoolss_StartDocPrinter *r)
5772 struct spoolss_DocumentInfo1 *info_1;
5774 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5780 DEBUG(2,("_spoolss_StartDocPrinter: "
5781 "Invalid handle (%s:%u:%u)\n",
5782 OUR_HANDLE(r->in.handle)));
5786 if (Printer->jobid) {
5787 DEBUG(2, ("_spoolss_StartDocPrinter: "
5788 "StartDocPrinter called twice! "
5789 "(existing jobid = %d)\n", Printer->jobid));
5790 return WERR_INVALID_HANDLE;
5793 if (r->in.level != 1) {
5794 return WERR_UNKNOWN_LEVEL;
5797 info_1 = r->in.info.info1;
5800 * a nice thing with NT is it doesn't listen to what you tell it.
5801 * when asked to send _only_ RAW datas, it tries to send datas
5804 * So I add checks like in NT Server ...
5807 if (info_1->datatype) {
5808 if (strcmp(info_1->datatype, "RAW") != 0) {
5810 return WERR_INVALID_DATATYPE;
5814 /* get the share number of the printer */
5815 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5819 rc = get_remote_hostname(p->remote_address,
5825 if (strequal(rhost,"UNKNOWN")) {
5826 rhost = tsocket_address_inet_addr_string(p->remote_address,
5828 if (rhost == NULL) {
5833 werr = print_job_start(p->session_info,
5837 info_1->document_name,
5838 info_1->output_file,
5842 /* An error occured in print_job_start() so return an appropriate
5845 if (!W_ERROR_IS_OK(werr)) {
5849 Printer->document_started = true;
5850 *r->out.job_id = Printer->jobid;
5855 /****************************************************************
5856 _spoolss_EndDocPrinter
5857 ****************************************************************/
5859 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5860 struct spoolss_EndDocPrinter *r)
5862 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5867 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5868 OUR_HANDLE(r->in.handle)));
5872 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5876 Printer->document_started = false;
5877 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5878 if (!NT_STATUS_IS_OK(status)) {
5879 DEBUG(2, ("_spoolss_EndDocPrinter: "
5880 "print_job_end failed [%s]\n",
5881 nt_errstr(status)));
5885 return ntstatus_to_werror(status);
5888 /****************************************************************
5889 _spoolss_WritePrinter
5890 ****************************************************************/
5892 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5893 struct spoolss_WritePrinter *r)
5895 ssize_t buffer_written;
5897 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5900 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5901 OUR_HANDLE(r->in.handle)));
5902 *r->out.num_written = r->in._data_size;
5906 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5909 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5910 buffer_written = print_job_write(server_event_context(),p->msg_ctx,
5911 snum, Printer->jobid,
5912 (const char *)r->in.data.data,
5913 (size_t)r->in._data_size);
5914 if (buffer_written == (ssize_t)-1) {
5915 *r->out.num_written = 0;
5916 if (errno == ENOSPC)
5917 return WERR_NO_SPOOL_SPACE;
5919 return WERR_ACCESS_DENIED;
5922 *r->out.num_written = r->in._data_size;
5927 /********************************************************************
5928 * api_spoolss_getprinter
5929 * called from the spoolss dispatcher
5931 ********************************************************************/
5933 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5934 struct pipes_struct *p)
5936 const struct auth_session_info *session_info = p->session_info;
5938 WERROR errcode = WERR_BADFUNC;
5939 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5942 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5943 OUR_HANDLE(handle)));
5947 if (!get_printer_snum(p, handle, &snum, NULL))
5951 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5952 errcode = print_queue_pause(session_info, p->msg_ctx, snum);
5954 case SPOOLSS_PRINTER_CONTROL_RESUME:
5955 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5956 errcode = print_queue_resume(session_info, p->msg_ctx, snum);
5958 case SPOOLSS_PRINTER_CONTROL_PURGE:
5959 errcode = print_queue_purge(session_info, p->msg_ctx, snum);
5962 return WERR_UNKNOWN_LEVEL;
5969 /****************************************************************
5970 _spoolss_AbortPrinter
5971 * From MSDN: "Deletes printer's spool file if printer is configured
5973 ****************************************************************/
5975 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5976 struct spoolss_AbortPrinter *r)
5978 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5980 WERROR errcode = WERR_OK;
5983 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5984 OUR_HANDLE(r->in.handle)));
5988 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5991 if (!Printer->document_started) {
5992 return WERR_SPL_NO_STARTDOC;
5995 errcode = print_job_delete(p->session_info,
6003 /********************************************************************
6004 * called by spoolss_api_setprinter
6005 * when updating a printer description
6006 ********************************************************************/
6008 static WERROR update_printer_sec(struct policy_handle *handle,
6009 struct pipes_struct *p,
6010 struct sec_desc_buf *secdesc_ctr)
6012 struct spoolss_security_descriptor *new_secdesc = NULL;
6013 struct spoolss_security_descriptor *old_secdesc = NULL;
6014 const char *printer;
6017 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6018 struct dcerpc_binding_handle *b;
6019 TALLOC_CTX *tmp_ctx = NULL;
6021 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
6022 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
6023 OUR_HANDLE(handle)));
6025 result = WERR_BADFID;
6029 if (secdesc_ctr == NULL) {
6030 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
6031 result = WERR_INVALID_PARAM;
6034 printer = lp_const_servicename(snum);
6036 /* Check the user has permissions to change the security
6037 descriptor. By experimentation with two NT machines, the user
6038 requires Full Access to the printer to change security
6041 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
6042 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
6043 result = WERR_ACCESS_DENIED;
6047 tmp_ctx = talloc_new(p->mem_ctx);
6052 result = winreg_printer_binding_handle(tmp_ctx,
6053 get_session_info_system(),
6056 if (!W_ERROR_IS_OK(result)) {
6060 /* NT seems to like setting the security descriptor even though
6061 nothing may have actually changed. */
6062 result = winreg_get_printer_secdesc(tmp_ctx, b,
6065 if (!W_ERROR_IS_OK(result)) {
6066 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc_internal() failed\n"));
6067 result = WERR_BADFID;
6071 if (DEBUGLEVEL >= 10) {
6072 struct security_acl *the_acl;
6075 the_acl = old_secdesc->dacl;
6076 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
6077 printer, the_acl->num_aces));
6079 for (i = 0; i < the_acl->num_aces; i++) {
6080 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6081 &the_acl->aces[i].trustee),
6082 the_acl->aces[i].access_mask));
6085 the_acl = secdesc_ctr->sd->dacl;
6088 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
6089 printer, the_acl->num_aces));
6091 for (i = 0; i < the_acl->num_aces; i++) {
6092 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6093 &the_acl->aces[i].trustee),
6094 the_acl->aces[i].access_mask));
6097 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
6101 new_secdesc = sec_desc_merge(tmp_ctx, secdesc_ctr->sd, old_secdesc);
6102 if (new_secdesc == NULL) {
6103 result = WERR_NOMEM;
6107 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
6112 result = winreg_set_printer_secdesc(tmp_ctx, b,
6117 talloc_free(tmp_ctx);
6121 /********************************************************************
6122 Canonicalize printer info from a client
6123 ********************************************************************/
6125 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
6126 struct spoolss_SetPrinterInfo2 *info2,
6129 fstring printername;
6132 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
6133 "portname=%s drivername=%s comment=%s location=%s\n",
6134 info2->servername, info2->printername, info2->sharename,
6135 info2->portname, info2->drivername, info2->comment,
6138 /* we force some elements to "correct" values */
6139 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", lp_netbios_name());
6140 if (info2->servername == NULL) {
6143 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
6144 if (info2->sharename == NULL) {
6148 /* check to see if we allow printername != sharename */
6149 if (lp_force_printername(snum)) {
6150 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6151 lp_netbios_name(), info2->sharename);
6153 /* make sure printername is in \\server\printername format */
6154 fstrcpy(printername, info2->printername);
6156 if ( printername[0] == '\\' && printername[1] == '\\' ) {
6157 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
6161 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6162 lp_netbios_name(), p);
6164 if (info2->printername == NULL) {
6168 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
6169 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
6174 /****************************************************************************
6175 ****************************************************************************/
6177 static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const char *portname, const char *uri)
6179 char *cmd = lp_addport_cmd();
6180 char *command = NULL;
6182 bool is_print_op = false;
6185 return WERR_ACCESS_DENIED;
6188 command = talloc_asprintf(ctx,
6189 "%s \"%s\" \"%s\"", cmd, portname, uri );
6195 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6197 DEBUG(10,("Running [%s]\n", command));
6199 /********* BEGIN SePrintOperatorPrivilege **********/
6204 ret = smbrun(command, NULL);
6209 /********* END SePrintOperatorPrivilege **********/
6211 DEBUGADD(10,("returned [%d]\n", ret));
6213 TALLOC_FREE(command);
6216 return WERR_ACCESS_DENIED;
6222 /****************************************************************************
6223 ****************************************************************************/
6225 static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
6226 struct spoolss_SetPrinterInfo2 *info2,
6227 const char *remote_machine,
6228 struct messaging_context *msg_ctx)
6230 char *cmd = lp_addprinter_cmd();
6232 char *command = NULL;
6236 bool is_print_op = false;
6238 if (!remote_machine) {
6242 command = talloc_asprintf(ctx,
6243 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6244 cmd, info2->printername, info2->sharename,
6245 info2->portname, info2->drivername,
6246 info2->location, info2->comment, remote_machine);
6252 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6254 DEBUG(10,("Running [%s]\n", command));
6256 /********* BEGIN SePrintOperatorPrivilege **********/
6261 if ( (ret = smbrun(command, &fd)) == 0 ) {
6262 /* Tell everyone we updated smb.conf. */
6263 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6269 /********* END SePrintOperatorPrivilege **********/
6271 DEBUGADD(10,("returned [%d]\n", ret));
6273 TALLOC_FREE(command);
6281 /* reload our services immediately */
6283 reload_services(msg_ctx, -1, false);
6287 /* Get lines and convert them back to dos-codepage */
6288 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6289 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6292 /* Set the portname to what the script says the portname should be. */
6293 /* but don't require anything to be return from the script exit a good error code */
6296 /* Set the portname to what the script says the portname should be. */
6297 info2->portname = talloc_strdup(ctx, qlines[0]);
6298 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6301 TALLOC_FREE(qlines);
6305 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
6306 const struct auth_session_info *session_info,
6307 struct messaging_context *msg_ctx,
6309 struct spoolss_SetPrinterInfo2 *printer,
6310 struct spoolss_PrinterInfo2 *old_printer)
6312 bool force_update = (old_printer == NULL);
6313 const char *dnsdomname;
6314 const char *longname;
6315 const char *uncname;
6316 const char *spooling;
6318 WERROR result = WERR_OK;
6319 struct dcerpc_binding_handle *b;
6320 TALLOC_CTX *tmp_ctx;
6322 tmp_ctx = talloc_new(mem_ctx);
6327 result = winreg_printer_binding_handle(tmp_ctx,
6331 if (!W_ERROR_IS_OK(result)) {
6335 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
6336 push_reg_sz(tmp_ctx, &buffer, printer->drivername);
6337 winreg_set_printer_dataex(tmp_ctx, b,
6339 SPOOL_DSSPOOLER_KEY,
6340 SPOOL_REG_DRIVERNAME,
6345 if (!force_update) {
6346 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6347 printer->drivername));
6349 notify_printer_driver(server_event_context(), msg_ctx,
6350 snum, printer->drivername ?
6351 printer->drivername : "");
6355 if (force_update || !strequal(printer->comment, old_printer->comment)) {
6356 push_reg_sz(tmp_ctx, &buffer, printer->comment);
6357 winreg_set_printer_dataex(tmp_ctx, b,
6359 SPOOL_DSSPOOLER_KEY,
6360 SPOOL_REG_DESCRIPTION,
6365 if (!force_update) {
6366 notify_printer_comment(server_event_context(), msg_ctx,
6367 snum, printer->comment ?
6368 printer->comment : "");
6372 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
6373 push_reg_sz(tmp_ctx, &buffer, printer->sharename);
6374 winreg_set_printer_dataex(tmp_ctx, b,
6376 SPOOL_DSSPOOLER_KEY,
6377 SPOOL_REG_PRINTSHARENAME,
6382 if (!force_update) {
6383 notify_printer_sharename(server_event_context(),
6385 snum, printer->sharename ?
6386 printer->sharename : "");
6390 if (force_update || !strequal(printer->printername, old_printer->printername)) {
6393 p = strrchr(printer->printername, '\\' );
6397 p = printer->printername;
6400 push_reg_sz(tmp_ctx, &buffer, p);
6401 winreg_set_printer_dataex(tmp_ctx, b,
6403 SPOOL_DSSPOOLER_KEY,
6404 SPOOL_REG_PRINTERNAME,
6409 if (!force_update) {
6410 notify_printer_printername(server_event_context(),
6411 msg_ctx, snum, p ? p : "");
6415 if (force_update || !strequal(printer->portname, old_printer->portname)) {
6416 push_reg_sz(tmp_ctx, &buffer, printer->portname);
6417 winreg_set_printer_dataex(tmp_ctx, b,
6419 SPOOL_DSSPOOLER_KEY,
6425 if (!force_update) {
6426 notify_printer_port(server_event_context(),
6427 msg_ctx, snum, printer->portname ?
6428 printer->portname : "");
6432 if (force_update || !strequal(printer->location, old_printer->location)) {
6433 push_reg_sz(tmp_ctx, &buffer, printer->location);
6434 winreg_set_printer_dataex(tmp_ctx, b,
6436 SPOOL_DSSPOOLER_KEY,
6442 if (!force_update) {
6443 notify_printer_location(server_event_context(),
6446 printer->location : "");
6450 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
6451 push_reg_sz(tmp_ctx, &buffer, printer->sepfile);
6452 winreg_set_printer_dataex(tmp_ctx, b,
6454 SPOOL_DSSPOOLER_KEY,
6455 SPOOL_REG_PRINTSEPARATORFILE,
6460 if (!force_update) {
6461 notify_printer_sepfile(server_event_context(),
6464 printer->sepfile : "");
6468 if (force_update || printer->starttime != old_printer->starttime) {
6469 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6470 SIVAL(buffer.data, 0, printer->starttime);
6471 winreg_set_printer_dataex(tmp_ctx, b,
6473 SPOOL_DSSPOOLER_KEY,
6474 SPOOL_REG_PRINTSTARTTIME,
6480 if (force_update || printer->untiltime != old_printer->untiltime) {
6481 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6482 SIVAL(buffer.data, 0, printer->untiltime);
6483 winreg_set_printer_dataex(tmp_ctx, b,
6485 SPOOL_DSSPOOLER_KEY,
6486 SPOOL_REG_PRINTENDTIME,
6492 if (force_update || printer->priority != old_printer->priority) {
6493 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6494 SIVAL(buffer.data, 0, printer->priority);
6495 winreg_set_printer_dataex(tmp_ctx, b,
6497 SPOOL_DSSPOOLER_KEY,
6504 if (force_update || printer->attributes != old_printer->attributes) {
6505 buffer = data_blob_talloc(tmp_ctx, NULL, 4);
6506 SIVAL(buffer.data, 0, (printer->attributes &
6507 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
6508 winreg_set_printer_dataex(tmp_ctx, b,
6510 SPOOL_DSSPOOLER_KEY,
6511 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
6516 switch (printer->attributes & 0x3) {
6518 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
6521 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
6524 spooling = SPOOL_REGVAL_PRINTDIRECT;
6527 spooling = "unknown";
6529 push_reg_sz(tmp_ctx, &buffer, spooling);
6530 winreg_set_printer_dataex(tmp_ctx, b,
6532 SPOOL_DSSPOOLER_KEY,
6533 SPOOL_REG_PRINTSPOOLING,
6539 push_reg_sz(tmp_ctx, &buffer, lp_netbios_name());
6540 winreg_set_printer_dataex(tmp_ctx, b,
6542 SPOOL_DSSPOOLER_KEY,
6543 SPOOL_REG_SHORTSERVERNAME,
6548 dnsdomname = get_mydnsfullname();
6549 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
6550 longname = talloc_strdup(tmp_ctx, dnsdomname);
6552 longname = talloc_strdup(tmp_ctx, lp_netbios_name());
6554 if (longname == NULL) {
6555 result = WERR_NOMEM;
6559 push_reg_sz(tmp_ctx, &buffer, longname);
6560 winreg_set_printer_dataex(tmp_ctx, b,
6562 SPOOL_DSSPOOLER_KEY,
6563 SPOOL_REG_SERVERNAME,
6568 uncname = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
6569 lp_netbios_name(), printer->sharename);
6570 push_reg_sz(tmp_ctx, &buffer, uncname);
6571 winreg_set_printer_dataex(tmp_ctx, b,
6573 SPOOL_DSSPOOLER_KEY,
6580 talloc_free(tmp_ctx);
6584 /********************************************************************
6585 * Called by spoolss_api_setprinter
6586 * when updating a printer description.
6587 ********************************************************************/
6589 static WERROR update_printer(struct pipes_struct *p,
6590 struct policy_handle *handle,
6591 struct spoolss_SetPrinterInfoCtr *info_ctr,
6592 struct spoolss_DeviceMode *devmode)
6594 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6595 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6596 struct spoolss_PrinterInfo2 *old_printer;
6597 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6599 WERROR result = WERR_OK;
6600 TALLOC_CTX *tmp_ctx;
6601 struct dcerpc_binding_handle *b;
6603 DEBUG(8,("update_printer\n"));
6605 tmp_ctx = talloc_new(p->mem_ctx);
6606 if (tmp_ctx == NULL) {
6611 result = WERR_BADFID;
6615 if (!get_printer_snum(p, handle, &snum, NULL)) {
6616 result = WERR_BADFID;
6620 result = winreg_printer_binding_handle(tmp_ctx,
6621 get_session_info_system(),
6624 if (!W_ERROR_IS_OK(result)) {
6628 result = winreg_get_printer(tmp_ctx, b,
6629 lp_const_servicename(snum),
6631 if (!W_ERROR_IS_OK(result)) {
6632 result = WERR_BADFID;
6636 /* Do sanity check on the requested changes for Samba */
6637 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6638 result = WERR_INVALID_PARAM;
6642 /* FIXME!!! If the driver has changed we really should verify that
6643 it is installed before doing much else --jerry */
6645 /* Check calling user has permission to update printer description */
6646 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6647 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6648 result = WERR_ACCESS_DENIED;
6652 /* Call addprinter hook */
6653 /* Check changes to see if this is really needed */
6655 if (*lp_addprinter_cmd() &&
6656 (!strequal(printer->drivername, old_printer->drivername) ||
6657 !strequal(printer->comment, old_printer->comment) ||
6658 !strequal(printer->portname, old_printer->portname) ||
6659 !strequal(printer->location, old_printer->location)) )
6663 raddr = tsocket_address_inet_addr_string(p->remote_address,
6665 if (raddr == NULL) {
6669 /* add_printer_hook() will call reload_services() */
6670 if (!add_printer_hook(tmp_ctx, p->session_info->security_token,
6673 result = WERR_ACCESS_DENIED;
6678 update_dsspooler(tmp_ctx,
6679 get_session_info_system(),
6685 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6687 if (devmode == NULL) {
6688 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6690 result = winreg_update_printer(tmp_ctx, b,
6698 talloc_free(tmp_ctx);
6703 /****************************************************************************
6704 ****************************************************************************/
6705 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6706 struct policy_handle *handle,
6707 struct spoolss_SetPrinterInfo7 *info7)
6710 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6713 struct printer_handle *Printer;
6715 if ( lp_security() != SEC_ADS ) {
6716 return WERR_UNKNOWN_LEVEL;
6719 Printer = find_printer_index_by_hnd(p, handle);
6721 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6726 if (!get_printer_snum(p, handle, &snum, NULL))
6729 result = winreg_get_printer_internal(p->mem_ctx,
6730 get_session_info_system(),
6732 lp_servicename(snum),
6734 if (!W_ERROR_IS_OK(result)) {
6738 nt_printer_publish(pinfo2,
6739 get_session_info_system(),
6744 TALLOC_FREE(pinfo2);
6747 return WERR_UNKNOWN_LEVEL;
6751 /********************************************************************
6752 ********************************************************************/
6754 static WERROR update_printer_devmode(struct pipes_struct *p,
6755 struct policy_handle *handle,
6756 struct spoolss_DeviceMode *devmode)
6759 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6760 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6762 DEBUG(8,("update_printer_devmode\n"));
6768 if (!get_printer_snum(p, handle, &snum, NULL)) {
6772 /* Check calling user has permission to update printer description */
6773 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6774 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6775 return WERR_ACCESS_DENIED;
6778 return winreg_update_printer_internal(p->mem_ctx,
6779 get_session_info_system(),
6781 lp_const_servicename(snum),
6789 /****************************************************************
6791 ****************************************************************/
6793 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6794 struct spoolss_SetPrinter *r)
6798 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6801 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6802 OUR_HANDLE(r->in.handle)));
6806 /* check the level */
6807 switch (r->in.info_ctr->level) {
6809 return control_printer(r->in.handle, r->in.command, p);
6811 result = update_printer(p, r->in.handle,
6813 r->in.devmode_ctr->devmode);
6814 if (!W_ERROR_IS_OK(result))
6816 if (r->in.secdesc_ctr->sd)
6817 result = update_printer_sec(r->in.handle, p,
6821 return update_printer_sec(r->in.handle, p,
6824 return publish_or_unpublish_printer(p, r->in.handle,
6825 r->in.info_ctr->info.info7);
6827 return update_printer_devmode(p, r->in.handle,
6828 r->in.devmode_ctr->devmode);
6830 return WERR_UNKNOWN_LEVEL;
6834 /****************************************************************
6835 _spoolss_FindClosePrinterNotify
6836 ****************************************************************/
6838 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6839 struct spoolss_FindClosePrinterNotify *r)
6841 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6844 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6845 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6849 if (Printer->notify.cli_chan != NULL &&
6850 Printer->notify.cli_chan->active_connections > 0) {
6853 if (Printer->printer_type == SPLHND_PRINTER) {
6854 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6859 srv_spoolss_replycloseprinter(snum, Printer);
6862 Printer->notify.flags=0;
6863 Printer->notify.options=0;
6864 Printer->notify.localmachine[0]='\0';
6865 Printer->notify.printerlocal=0;
6866 TALLOC_FREE(Printer->notify.option);
6871 /****************************************************************
6873 ****************************************************************/
6875 WERROR _spoolss_AddJob(struct pipes_struct *p,
6876 struct spoolss_AddJob *r)
6878 if (!r->in.buffer && (r->in.offered != 0)) {
6879 return WERR_INVALID_PARAM;
6882 /* this is what a NT server returns for AddJob. AddJob must fail on
6883 * non-local printers */
6885 if (r->in.level != 1) {
6886 return WERR_UNKNOWN_LEVEL;
6889 return WERR_INVALID_PARAM;
6892 /****************************************************************************
6894 ****************************************************************************/
6896 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6897 struct spoolss_JobInfo1 *r,
6898 const print_queue_struct *queue,
6899 int position, int snum,
6900 struct spoolss_PrinterInfo2 *pinfo2)
6904 t = gmtime(&queue->time);
6906 r->job_id = queue->job;
6908 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6909 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6910 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6911 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6912 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6913 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6914 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6915 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6916 r->data_type = talloc_strdup(mem_ctx, "RAW");
6917 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6918 r->text_status = talloc_strdup(mem_ctx, "");
6919 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6921 r->status = nt_printj_status(queue->status);
6922 r->priority = queue->priority;
6923 r->position = position;
6924 r->total_pages = queue->page_count;
6925 r->pages_printed = 0; /* ??? */
6927 init_systemtime(&r->submitted, t);
6932 /****************************************************************************
6934 ****************************************************************************/
6936 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6937 struct spoolss_JobInfo2 *r,
6938 const print_queue_struct *queue,
6939 int position, int snum,
6940 struct spoolss_PrinterInfo2 *pinfo2,
6941 struct spoolss_DeviceMode *devmode)
6945 t = gmtime(&queue->time);
6947 r->job_id = queue->job;
6949 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6950 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6951 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6952 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6953 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6954 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6955 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6956 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6957 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6958 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6959 r->data_type = talloc_strdup(mem_ctx, "RAW");
6960 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6961 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6962 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6963 r->parameters = talloc_strdup(mem_ctx, "");
6964 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6965 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6966 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6968 r->devmode = devmode;
6970 r->text_status = talloc_strdup(mem_ctx, "");
6971 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6975 r->status = nt_printj_status(queue->status);
6976 r->priority = queue->priority;
6977 r->position = position;
6980 r->total_pages = queue->page_count;
6981 r->size = queue->size;
6982 init_systemtime(&r->submitted, t);
6984 r->pages_printed = 0; /* ??? */
6989 /****************************************************************************
6991 ****************************************************************************/
6993 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6994 struct spoolss_JobInfo3 *r,
6995 const print_queue_struct *queue,
6996 const print_queue_struct *next_queue,
6997 int position, int snum,
6998 struct spoolss_PrinterInfo2 *pinfo2)
7000 r->job_id = queue->job;
7003 r->next_job_id = next_queue->job;
7010 /****************************************************************************
7011 Enumjobs at level 1.
7012 ****************************************************************************/
7014 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
7015 const print_queue_struct *queue,
7016 uint32_t num_queues, int snum,
7017 struct spoolss_PrinterInfo2 *pinfo2,
7018 union spoolss_JobInfo **info_p,
7021 union spoolss_JobInfo *info;
7023 WERROR result = WERR_OK;
7025 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7026 W_ERROR_HAVE_NO_MEMORY(info);
7028 *count = num_queues;
7030 for (i=0; i<*count; i++) {
7031 result = fill_job_info1(info,
7037 if (!W_ERROR_IS_OK(result)) {
7043 if (!W_ERROR_IS_OK(result)) {
7054 /****************************************************************************
7055 Enumjobs at level 2.
7056 ****************************************************************************/
7058 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
7059 const print_queue_struct *queue,
7060 uint32_t num_queues, int snum,
7061 struct spoolss_PrinterInfo2 *pinfo2,
7062 union spoolss_JobInfo **info_p,
7065 union spoolss_JobInfo *info;
7067 WERROR result = WERR_OK;
7069 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7070 W_ERROR_HAVE_NO_MEMORY(info);
7072 *count = num_queues;
7074 for (i=0; i<*count; i++) {
7075 struct spoolss_DeviceMode *devmode;
7077 result = spoolss_create_default_devmode(info,
7078 pinfo2->printername,
7080 if (!W_ERROR_IS_OK(result)) {
7081 DEBUG(3, ("Can't proceed w/o a devmode!"));
7085 result = fill_job_info2(info,
7092 if (!W_ERROR_IS_OK(result)) {
7098 if (!W_ERROR_IS_OK(result)) {
7109 /****************************************************************************
7110 Enumjobs at level 3.
7111 ****************************************************************************/
7113 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
7114 const print_queue_struct *queue,
7115 uint32_t num_queues, int snum,
7116 struct spoolss_PrinterInfo2 *pinfo2,
7117 union spoolss_JobInfo **info_p,
7120 union spoolss_JobInfo *info;
7122 WERROR result = WERR_OK;
7124 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7125 W_ERROR_HAVE_NO_MEMORY(info);
7127 *count = num_queues;
7129 for (i=0; i<*count; i++) {
7130 const print_queue_struct *next_queue = NULL;
7133 next_queue = &queue[i+1];
7136 result = fill_job_info3(info,
7143 if (!W_ERROR_IS_OK(result)) {
7149 if (!W_ERROR_IS_OK(result)) {
7160 /****************************************************************
7162 ****************************************************************/
7164 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
7165 struct spoolss_EnumJobs *r)
7168 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
7170 print_status_struct prt_status;
7171 print_queue_struct *queue = NULL;
7174 /* that's an [in out] buffer */
7176 if (!r->in.buffer && (r->in.offered != 0)) {
7177 return WERR_INVALID_PARAM;
7180 DEBUG(4,("_spoolss_EnumJobs\n"));
7184 *r->out.info = NULL;
7186 /* lookup the printer snum and tdb entry */
7188 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7192 result = winreg_get_printer_internal(p->mem_ctx,
7193 get_session_info_system(),
7195 lp_const_servicename(snum),
7197 if (!W_ERROR_IS_OK(result)) {
7201 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
7202 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7203 count, prt_status.status, prt_status.message));
7207 TALLOC_FREE(pinfo2);
7211 switch (r->in.level) {
7213 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
7214 pinfo2, r->out.info, r->out.count);
7217 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
7218 pinfo2, r->out.info, r->out.count);
7221 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
7222 pinfo2, r->out.info, r->out.count);
7225 result = WERR_UNKNOWN_LEVEL;
7230 TALLOC_FREE(pinfo2);
7232 if (!W_ERROR_IS_OK(result)) {
7236 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7238 *r->out.info, r->in.level,
7240 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7241 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7243 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7246 /****************************************************************
7247 _spoolss_ScheduleJob
7248 ****************************************************************/
7250 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
7251 struct spoolss_ScheduleJob *r)
7256 /****************************************************************
7257 ****************************************************************/
7259 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
7260 struct messaging_context *msg_ctx,
7261 const char *printer_name,
7263 struct spoolss_SetJobInfo1 *r)
7267 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
7271 if (strequal(old_doc_name, r->document_name)) {
7275 if (!print_job_set_name(server_event_context(), msg_ctx,
7276 printer_name, job_id, r->document_name)) {
7283 /****************************************************************
7285 ****************************************************************/
7287 WERROR _spoolss_SetJob(struct pipes_struct *p,
7288 struct spoolss_SetJob *r)
7290 const struct auth_session_info *session_info = p->session_info;
7292 WERROR errcode = WERR_BADFUNC;
7294 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7298 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
7299 return WERR_INVALID_PRINTER_NAME;
7302 switch (r->in.command) {
7303 case SPOOLSS_JOB_CONTROL_CANCEL:
7304 case SPOOLSS_JOB_CONTROL_DELETE:
7305 errcode = print_job_delete(session_info, p->msg_ctx,
7306 snum, r->in.job_id);
7307 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
7311 case SPOOLSS_JOB_CONTROL_PAUSE:
7312 if (print_job_pause(session_info, p->msg_ctx,
7313 snum, r->in.job_id, &errcode)) {
7317 case SPOOLSS_JOB_CONTROL_RESTART:
7318 case SPOOLSS_JOB_CONTROL_RESUME:
7319 if (print_job_resume(session_info, p->msg_ctx,
7320 snum, r->in.job_id, &errcode)) {
7328 return WERR_UNKNOWN_LEVEL;
7331 if (!W_ERROR_IS_OK(errcode)) {
7335 if (r->in.ctr == NULL) {
7339 switch (r->in.ctr->level) {
7341 errcode = spoolss_setjob_1(p->mem_ctx, p->msg_ctx,
7342 lp_const_servicename(snum),
7344 r->in.ctr->info.info1);
7350 return WERR_UNKNOWN_LEVEL;
7356 /****************************************************************************
7357 Enumerates all printer drivers by level and architecture.
7358 ****************************************************************************/
7360 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
7361 const struct auth_session_info *session_info,
7362 struct messaging_context *msg_ctx,
7363 const char *servername,
7364 const char *architecture,
7366 union spoolss_DriverInfo **info_p,
7371 struct spoolss_DriverInfo8 *driver;
7372 union spoolss_DriverInfo *info = NULL;
7374 WERROR result = WERR_OK;
7375 uint32_t num_drivers;
7376 const char **drivers;
7377 struct dcerpc_binding_handle *b;
7378 TALLOC_CTX *tmp_ctx = NULL;
7383 tmp_ctx = talloc_new(mem_ctx);
7388 result = winreg_printer_binding_handle(tmp_ctx,
7392 if (!W_ERROR_IS_OK(result)) {
7396 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7397 result = winreg_get_driver_list(tmp_ctx, b,
7398 architecture, version,
7399 &num_drivers, &drivers);
7400 if (!W_ERROR_IS_OK(result)) {
7403 DEBUG(4, ("we have:[%d] drivers in environment"
7404 " [%s] and version [%d]\n",
7405 num_drivers, architecture, version));
7407 if (num_drivers != 0) {
7408 info = talloc_realloc(tmp_ctx, info,
7409 union spoolss_DriverInfo,
7410 count + num_drivers);
7412 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7413 "failed to enlarge driver info buffer!\n"));
7414 result = WERR_NOMEM;
7419 for (i = 0; i < num_drivers; i++) {
7420 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
7422 result = winreg_get_driver(tmp_ctx, b,
7423 architecture, drivers[i],
7425 if (!W_ERROR_IS_OK(result)) {
7431 result = fill_printer_driver_info1(info, &info[count+i].info1,
7432 driver, servername);
7435 result = fill_printer_driver_info2(info, &info[count+i].info2,
7436 driver, servername);
7439 result = fill_printer_driver_info3(info, &info[count+i].info3,
7440 driver, servername);
7443 result = fill_printer_driver_info4(info, &info[count+i].info4,
7444 driver, servername);
7447 result = fill_printer_driver_info5(info, &info[count+i].info5,
7448 driver, servername);
7451 result = fill_printer_driver_info6(info, &info[count+i].info6,
7452 driver, servername);
7455 result = fill_printer_driver_info8(info, &info[count+i].info8,
7456 driver, servername);
7459 result = WERR_UNKNOWN_LEVEL;
7463 TALLOC_FREE(driver);
7465 if (!W_ERROR_IS_OK(result)) {
7470 count += num_drivers;
7471 TALLOC_FREE(drivers);
7475 if (W_ERROR_IS_OK(result)) {
7476 *info_p = talloc_move(mem_ctx, &info);
7480 talloc_free(tmp_ctx);
7484 /****************************************************************************
7485 Enumerates all printer drivers by level.
7486 ****************************************************************************/
7488 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
7489 const struct auth_session_info *session_info,
7490 struct messaging_context *msg_ctx,
7491 const char *servername,
7492 const char *architecture,
7494 union spoolss_DriverInfo **info_p,
7498 WERROR result = WERR_OK;
7500 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
7502 for (a=0; archi_table[a].long_archi != NULL; a++) {
7504 union spoolss_DriverInfo *info = NULL;
7507 result = enumprinterdrivers_level_by_architecture(mem_ctx,
7511 archi_table[a].long_archi,
7515 if (!W_ERROR_IS_OK(result)) {
7519 for (i=0; i < count; i++) {
7520 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
7521 info[i], info_p, count_p);
7528 return enumprinterdrivers_level_by_architecture(mem_ctx,
7538 /****************************************************************
7539 _spoolss_EnumPrinterDrivers
7540 ****************************************************************/
7542 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
7543 struct spoolss_EnumPrinterDrivers *r)
7545 const char *cservername;
7548 /* that's an [in out] buffer */
7550 if (!r->in.buffer && (r->in.offered != 0)) {
7551 return WERR_INVALID_PARAM;
7554 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7558 *r->out.info = NULL;
7560 cservername = canon_servername(r->in.server);
7562 if (!is_myname_or_ipaddr(cservername)) {
7563 return WERR_UNKNOWN_PRINTER_DRIVER;
7566 result = enumprinterdrivers_level(p->mem_ctx,
7567 get_session_info_system(),
7574 if (!W_ERROR_IS_OK(result)) {
7578 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7579 spoolss_EnumPrinterDrivers,
7580 *r->out.info, r->in.level,
7582 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7583 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7585 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7588 /****************************************************************
7590 ****************************************************************/
7592 WERROR _spoolss_EnumForms(struct pipes_struct *p,
7593 struct spoolss_EnumForms *r)
7599 *r->out.info = NULL;
7601 /* that's an [in out] buffer */
7603 if (!r->in.buffer && (r->in.offered != 0) ) {
7604 return WERR_INVALID_PARAM;
7607 DEBUG(4,("_spoolss_EnumForms\n"));
7608 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7609 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7611 switch (r->in.level) {
7613 result = winreg_printer_enumforms1_internal(p->mem_ctx,
7614 get_session_info_system(),
7620 result = WERR_UNKNOWN_LEVEL;
7624 if (!W_ERROR_IS_OK(result)) {
7628 if (*r->out.count == 0) {
7629 return WERR_NO_MORE_ITEMS;
7632 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7634 *r->out.info, r->in.level,
7636 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7637 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7639 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7642 /****************************************************************
7644 ****************************************************************/
7646 WERROR _spoolss_GetForm(struct pipes_struct *p,
7647 struct spoolss_GetForm *r)
7651 /* that's an [in out] buffer */
7653 if (!r->in.buffer && (r->in.offered != 0)) {
7654 return WERR_INVALID_PARAM;
7657 DEBUG(4,("_spoolss_GetForm\n"));
7658 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7659 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7661 switch (r->in.level) {
7663 result = winreg_printer_getform1_internal(p->mem_ctx,
7664 get_session_info_system(),
7667 &r->out.info->info1);
7670 result = WERR_UNKNOWN_LEVEL;
7674 if (!W_ERROR_IS_OK(result)) {
7675 TALLOC_FREE(r->out.info);
7679 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7680 r->out.info, r->in.level);
7681 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7683 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7686 /****************************************************************************
7687 ****************************************************************************/
7689 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7690 struct spoolss_PortInfo1 *r,
7693 r->port_name = talloc_strdup(mem_ctx, name);
7694 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7699 /****************************************************************************
7700 TODO: This probably needs distinguish between TCP/IP and Local ports
7702 ****************************************************************************/
7704 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7705 struct spoolss_PortInfo2 *r,
7708 r->port_name = talloc_strdup(mem_ctx, name);
7709 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7711 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7712 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7714 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7715 W_ERROR_HAVE_NO_MEMORY(r->description);
7717 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7724 /****************************************************************************
7725 wrapper around the enumer ports command
7726 ****************************************************************************/
7728 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7730 char *cmd = lp_enumports_cmd();
7731 char **qlines = NULL;
7732 char *command = NULL;
7740 /* if no hook then just fill in the default port */
7743 if (!(qlines = talloc_array( NULL, char*, 2 ))) {
7746 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7747 TALLOC_FREE(qlines);
7754 /* we have a valid enumport command */
7756 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7761 DEBUG(10,("Running [%s]\n", command));
7762 ret = smbrun(command, &fd);
7763 DEBUG(10,("Returned [%d]\n", ret));
7764 TALLOC_FREE(command);
7769 return WERR_ACCESS_DENIED;
7773 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7774 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7784 /****************************************************************************
7786 ****************************************************************************/
7788 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7789 union spoolss_PortInfo **info_p,
7792 union spoolss_PortInfo *info = NULL;
7794 WERROR result = WERR_OK;
7795 char **qlines = NULL;
7798 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7799 if (!W_ERROR_IS_OK(result)) {
7804 info = talloc_array(mem_ctx, union spoolss_PortInfo, numlines);
7806 DEBUG(10,("Returning WERR_NOMEM\n"));
7807 result = WERR_NOMEM;
7811 for (i=0; i<numlines; i++) {
7812 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7813 result = fill_port_1(info, &info[i].info1, qlines[i]);
7814 if (!W_ERROR_IS_OK(result)) {
7819 TALLOC_FREE(qlines);
7822 if (!W_ERROR_IS_OK(result)) {
7824 TALLOC_FREE(qlines);
7836 /****************************************************************************
7838 ****************************************************************************/
7840 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7841 union spoolss_PortInfo **info_p,
7844 union spoolss_PortInfo *info = NULL;
7846 WERROR result = WERR_OK;
7847 char **qlines = NULL;
7850 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7851 if (!W_ERROR_IS_OK(result)) {
7856 info = talloc_array(mem_ctx, union spoolss_PortInfo, numlines);
7858 DEBUG(10,("Returning WERR_NOMEM\n"));
7859 result = WERR_NOMEM;
7863 for (i=0; i<numlines; i++) {
7864 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7865 result = fill_port_2(info, &info[i].info2, qlines[i]);
7866 if (!W_ERROR_IS_OK(result)) {
7871 TALLOC_FREE(qlines);
7874 if (!W_ERROR_IS_OK(result)) {
7876 TALLOC_FREE(qlines);
7888 /****************************************************************
7890 ****************************************************************/
7892 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
7893 struct spoolss_EnumPorts *r)
7897 /* that's an [in out] buffer */
7899 if (!r->in.buffer && (r->in.offered != 0)) {
7900 return WERR_INVALID_PARAM;
7903 DEBUG(4,("_spoolss_EnumPorts\n"));
7907 *r->out.info = NULL;
7909 switch (r->in.level) {
7911 result = enumports_level_1(p->mem_ctx, r->out.info,
7915 result = enumports_level_2(p->mem_ctx, r->out.info,
7919 return WERR_UNKNOWN_LEVEL;
7922 if (!W_ERROR_IS_OK(result)) {
7926 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7928 *r->out.info, r->in.level,
7930 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7931 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7933 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7936 /****************************************************************************
7937 ****************************************************************************/
7939 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
7941 struct spoolss_SetPrinterInfoCtr *info_ctr,
7942 struct spoolss_DeviceMode *devmode,
7943 struct security_descriptor *secdesc,
7944 struct spoolss_UserLevelCtr *user_ctr,
7945 struct policy_handle *handle)
7947 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7948 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7950 WERROR err = WERR_OK;
7952 /* samba does not have a concept of local, non-shared printers yet, so
7953 * make sure we always setup sharename - gd */
7954 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7955 (info2->printername != NULL && info2->printername[0] != '\0')) {
7956 DEBUG(5, ("spoolss_addprinterex_level_2: "
7957 "no sharename has been set, setting printername %s as sharename\n",
7958 info2->printername));
7959 info2->sharename = info2->printername;
7962 /* check to see if the printer already exists */
7963 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7964 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7966 return WERR_PRINTER_ALREADY_EXISTS;
7969 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7970 if ((snum = print_queue_snum(info2->printername)) != -1) {
7971 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7972 info2->printername));
7973 return WERR_PRINTER_ALREADY_EXISTS;
7977 /* validate printer info struct */
7978 if (!info2->printername || strlen(info2->printername) == 0) {
7979 return WERR_INVALID_PRINTER_NAME;
7981 if (!info2->portname || strlen(info2->portname) == 0) {
7982 return WERR_UNKNOWN_PORT;
7984 if (!info2->drivername || strlen(info2->drivername) == 0) {
7985 return WERR_UNKNOWN_PRINTER_DRIVER;
7987 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7988 return WERR_UNKNOWN_PRINTPROCESSOR;
7991 /* FIXME!!! smbd should check to see if the driver is installed before
7992 trying to add a printer like this --jerry */
7994 if (*lp_addprinter_cmd() ) {
7997 raddr = tsocket_address_inet_addr_string(p->remote_address,
7999 if (raddr == NULL) {
8003 if ( !add_printer_hook(p->mem_ctx, p->session_info->security_token,
8006 return WERR_ACCESS_DENIED;
8009 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no "
8010 "smb.conf parameter \"addprinter command\" is defined. This "
8011 "parameter must exist for this call to succeed\n",
8012 info2->sharename ));
8015 if ((snum = print_queue_snum(info2->sharename)) == -1) {
8016 return WERR_ACCESS_DENIED;
8019 /* you must be a printer admin to add a new printer */
8020 if (!print_access_check(p->session_info,
8023 PRINTER_ACCESS_ADMINISTER)) {
8024 return WERR_ACCESS_DENIED;
8028 * Do sanity check on the requested changes for Samba.
8031 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
8032 return WERR_INVALID_PARAM;
8035 if (devmode == NULL) {
8036 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
8039 update_dsspooler(p->mem_ctx,
8040 get_session_info_system(),
8046 err = winreg_update_printer_internal(p->mem_ctx,
8047 get_session_info_system(),
8054 if (!W_ERROR_IS_OK(err)) {
8058 err = open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER);
8059 if (!W_ERROR_IS_OK(err)) {
8060 /* Handle open failed - remove addition. */
8061 ZERO_STRUCTP(handle);
8068 /****************************************************************
8069 _spoolss_AddPrinterEx
8070 ****************************************************************/
8072 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
8073 struct spoolss_AddPrinterEx *r)
8075 switch (r->in.info_ctr->level) {
8077 /* we don't handle yet */
8078 /* but I know what to do ... */
8079 return WERR_UNKNOWN_LEVEL;
8081 return spoolss_addprinterex_level_2(p, r->in.server,
8083 r->in.devmode_ctr->devmode,
8084 r->in.secdesc_ctr->sd,
8085 r->in.userlevel_ctr,
8088 return WERR_UNKNOWN_LEVEL;
8092 /****************************************************************
8094 ****************************************************************/
8096 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
8097 struct spoolss_AddPrinter *r)
8099 struct spoolss_AddPrinterEx a;
8100 struct spoolss_UserLevelCtr userlevel_ctr;
8102 ZERO_STRUCT(userlevel_ctr);
8104 userlevel_ctr.level = 1;
8106 a.in.server = r->in.server;
8107 a.in.info_ctr = r->in.info_ctr;
8108 a.in.devmode_ctr = r->in.devmode_ctr;
8109 a.in.secdesc_ctr = r->in.secdesc_ctr;
8110 a.in.userlevel_ctr = &userlevel_ctr;
8111 a.out.handle = r->out.handle;
8113 return _spoolss_AddPrinterEx(p, &a);
8116 /****************************************************************
8117 _spoolss_AddPrinterDriverEx
8118 ****************************************************************/
8120 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
8121 struct spoolss_AddPrinterDriverEx *r)
8123 WERROR err = WERR_OK;
8124 const char *driver_name = NULL;
8129 case NDR_SPOOLSS_ADDPRINTERDRIVER:
8130 fn = "_spoolss_AddPrinterDriver";
8132 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
8133 fn = "_spoolss_AddPrinterDriverEx";
8136 return WERR_INVALID_PARAM;
8140 * we only support the semantics of AddPrinterDriver()
8141 * i.e. only copy files that are newer than existing ones
8144 if (r->in.flags == 0) {
8145 return WERR_INVALID_PARAM;
8148 if (r->in.flags != APD_COPY_NEW_FILES) {
8149 return WERR_ACCESS_DENIED;
8153 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
8154 /* Clever hack from Martin Zielinski <mz@seh.de>
8155 * to allow downgrade from level 8 (Vista).
8157 DEBUG(0,("%s: level %d not yet implemented\n", fn,
8158 r->in.info_ctr->level));
8159 return WERR_UNKNOWN_LEVEL;
8162 DEBUG(5,("Cleaning driver's information\n"));
8163 err = clean_up_driver_struct(p->mem_ctx, p->session_info, r->in.info_ctr);
8164 if (!W_ERROR_IS_OK(err))
8167 DEBUG(5,("Moving driver to final destination\n"));
8168 err = move_driver_to_download_area(p->session_info, r->in.info_ctr);
8169 if (!W_ERROR_IS_OK(err)) {
8173 err = winreg_add_driver_internal(p->mem_ctx,
8174 get_session_info_system(),
8179 if (!W_ERROR_IS_OK(err)) {
8184 * I think this is where he DrvUpgradePrinter() hook would be
8185 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8186 * server. Right now, we just need to send ourselves a message
8187 * to update each printer bound to this driver. --jerry
8190 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
8191 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8199 /****************************************************************
8200 _spoolss_AddPrinterDriver
8201 ****************************************************************/
8203 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
8204 struct spoolss_AddPrinterDriver *r)
8206 struct spoolss_AddPrinterDriverEx a;
8208 switch (r->in.info_ctr->level) {
8215 return WERR_UNKNOWN_LEVEL;
8218 a.in.servername = r->in.servername;
8219 a.in.info_ctr = r->in.info_ctr;
8220 a.in.flags = APD_COPY_NEW_FILES;
8222 return _spoolss_AddPrinterDriverEx(p, &a);
8225 /****************************************************************************
8226 ****************************************************************************/
8228 struct _spoolss_paths {
8234 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
8236 static const struct _spoolss_paths spoolss_paths[]= {
8237 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
8238 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
8241 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
8242 const char *servername,
8243 const char *environment,
8247 const char *pservername = NULL;
8248 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
8249 const char *short_archi;
8253 /* environment may be empty */
8254 if (environment && strlen(environment)) {
8255 long_archi = environment;
8258 /* servername may be empty */
8259 if (servername && strlen(servername)) {
8260 pservername = canon_servername(servername);
8262 if (!is_myname_or_ipaddr(pservername)) {
8263 return WERR_INVALID_PARAM;
8267 if (!(short_archi = get_short_archi(long_archi))) {
8268 return WERR_INVALID_ENVIRONMENT;
8271 switch (component) {
8272 case SPOOLSS_PRTPROCS_PATH:
8273 case SPOOLSS_DRIVER_PATH:
8275 *path = talloc_asprintf(mem_ctx,
8278 spoolss_paths[component].share,
8281 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
8282 SPOOLSS_DEFAULT_SERVER_PATH,
8283 spoolss_paths[component].dir,
8288 return WERR_INVALID_PARAM;
8298 /****************************************************************************
8299 ****************************************************************************/
8301 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
8302 const char *servername,
8303 const char *environment,
8304 struct spoolss_DriverDirectoryInfo1 *r)
8309 werr = compose_spoolss_server_path(mem_ctx,
8312 SPOOLSS_DRIVER_PATH,
8314 if (!W_ERROR_IS_OK(werr)) {
8318 DEBUG(4,("printer driver directory: [%s]\n", path));
8320 r->directory_name = path;
8325 /****************************************************************
8326 _spoolss_GetPrinterDriverDirectory
8327 ****************************************************************/
8329 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
8330 struct spoolss_GetPrinterDriverDirectory *r)
8334 /* that's an [in out] buffer */
8336 if (!r->in.buffer && (r->in.offered != 0)) {
8337 return WERR_INVALID_PARAM;
8340 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8345 /* r->in.level is ignored */
8347 werror = getprinterdriverdir_level_1(p->mem_ctx,
8350 &r->out.info->info1);
8351 if (!W_ERROR_IS_OK(werror)) {
8352 TALLOC_FREE(r->out.info);
8356 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
8357 r->out.info, r->in.level);
8358 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8360 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8363 /****************************************************************
8364 _spoolss_EnumPrinterData
8365 ****************************************************************/
8367 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
8368 struct spoolss_EnumPrinterData *r)
8371 struct spoolss_EnumPrinterDataEx r2;
8373 struct spoolss_PrinterEnumValues *info, *val = NULL;
8376 r2.in.handle = r->in.handle;
8377 r2.in.key_name = "PrinterDriverData";
8379 r2.out.count = &count;
8380 r2.out.info = &info;
8381 r2.out.needed = &needed;
8383 result = _spoolss_EnumPrinterDataEx(p, &r2);
8384 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8385 r2.in.offered = needed;
8386 result = _spoolss_EnumPrinterDataEx(p, &r2);
8388 if (!W_ERROR_IS_OK(result)) {
8393 * The NT machine wants to know the biggest size of value and data
8395 * cf: MSDN EnumPrinterData remark section
8398 if (!r->in.value_offered && !r->in.data_offered) {
8399 uint32_t biggest_valuesize = 0;
8400 uint32_t biggest_datasize = 0;
8403 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8405 for (i=0; i<count; i++) {
8407 name_length = strlen(info[i].value_name);
8408 if (strlen(info[i].value_name) > biggest_valuesize) {
8409 biggest_valuesize = name_length;
8412 if (info[i].data_length > biggest_datasize) {
8413 biggest_datasize = info[i].data_length;
8416 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8420 /* the value is an UNICODE string but real_value_size is the length
8421 in bytes including the trailing 0 */
8423 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8424 *r->out.data_needed = biggest_datasize;
8426 DEBUG(6,("final values: [%d], [%d]\n",
8427 *r->out.value_needed, *r->out.data_needed));
8432 if (r->in.enum_index < count) {
8433 val = &info[r->in.enum_index];
8437 /* out_value should default to "" or else NT4 has
8438 problems unmarshalling the response */
8440 if (r->in.value_offered) {
8441 *r->out.value_needed = 1;
8442 r->out.value_name = talloc_strdup(r, "");
8443 if (!r->out.value_name) {
8447 r->out.value_name = NULL;
8448 *r->out.value_needed = 0;
8451 /* the data is counted in bytes */
8453 *r->out.data_needed = r->in.data_offered;
8455 result = WERR_NO_MORE_ITEMS;
8459 * - counted in bytes in the request
8460 * - counted in UNICODE chars in the max reply
8461 * - counted in bytes in the real size
8463 * take a pause *before* coding not *during* coding
8467 if (r->in.value_offered) {
8468 r->out.value_name = talloc_strdup(r, val->value_name);
8469 if (!r->out.value_name) {
8472 *r->out.value_needed = val->value_name_len;
8474 r->out.value_name = NULL;
8475 *r->out.value_needed = 0;
8480 *r->out.type = val->type;
8482 /* data - counted in bytes */
8485 * See the section "Dynamically Typed Query Parameters"
8489 if (r->out.data && val->data && val->data->data &&
8490 val->data_length && r->in.data_offered) {
8491 memcpy(r->out.data, val->data->data,
8492 MIN(val->data_length,r->in.data_offered));
8495 *r->out.data_needed = val->data_length;
8503 /****************************************************************
8504 _spoolss_SetPrinterData
8505 ****************************************************************/
8507 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
8508 struct spoolss_SetPrinterData *r)
8510 struct spoolss_SetPrinterDataEx r2;
8512 r2.in.handle = r->in.handle;
8513 r2.in.key_name = "PrinterDriverData";
8514 r2.in.value_name = r->in.value_name;
8515 r2.in.type = r->in.type;
8516 r2.in.data = r->in.data;
8517 r2.in.offered = r->in.offered;
8519 return _spoolss_SetPrinterDataEx(p, &r2);
8522 /****************************************************************
8523 _spoolss_ResetPrinter
8524 ****************************************************************/
8526 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
8527 struct spoolss_ResetPrinter *r)
8529 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8532 DEBUG(5,("_spoolss_ResetPrinter\n"));
8535 * All we do is to check to see if the handle and queue is valid.
8536 * This call really doesn't mean anything to us because we only
8537 * support RAW printing. --jerry
8541 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8542 OUR_HANDLE(r->in.handle)));
8546 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8550 /* blindly return success */
8554 /****************************************************************
8555 _spoolss_DeletePrinterData
8556 ****************************************************************/
8558 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
8559 struct spoolss_DeletePrinterData *r)
8561 struct spoolss_DeletePrinterDataEx r2;
8563 r2.in.handle = r->in.handle;
8564 r2.in.key_name = "PrinterDriverData";
8565 r2.in.value_name = r->in.value_name;
8567 return _spoolss_DeletePrinterDataEx(p, &r2);
8570 /****************************************************************
8572 ****************************************************************/
8574 WERROR _spoolss_AddForm(struct pipes_struct *p,
8575 struct spoolss_AddForm *r)
8577 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8579 WERROR status = WERR_OK;
8580 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8581 struct dcerpc_binding_handle *b;
8582 TALLOC_CTX *tmp_ctx = NULL;
8584 DEBUG(5,("_spoolss_AddForm\n"));
8587 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8588 OUR_HANDLE(r->in.handle)));
8592 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8593 and not a printer admin, then fail */
8595 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
8596 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
8597 !token_contains_name_in_list(uidtoname(p->session_info->unix_token->uid),
8598 p->session_info->info->domain_name,
8600 p->session_info->security_token,
8601 lp_printer_admin(snum))) {
8602 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8603 return WERR_ACCESS_DENIED;
8606 switch (form->flags) {
8607 case SPOOLSS_FORM_USER:
8608 case SPOOLSS_FORM_BUILTIN:
8609 case SPOOLSS_FORM_PRINTER:
8612 return WERR_INVALID_PARAM;
8615 tmp_ctx = talloc_new(p->mem_ctx);
8620 status = winreg_printer_binding_handle(tmp_ctx,
8621 get_session_info_system(),
8624 if (!W_ERROR_IS_OK(status)) {
8628 status = winreg_printer_addform1(tmp_ctx, b, form);
8629 if (!W_ERROR_IS_OK(status)) {
8634 * ChangeID must always be set if this is a printer
8636 if (Printer->printer_type == SPLHND_PRINTER) {
8637 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8638 status = WERR_BADFID;
8642 status = winreg_printer_update_changeid(tmp_ctx, b,
8643 lp_const_servicename(snum));
8647 talloc_free(tmp_ctx);
8651 /****************************************************************
8653 ****************************************************************/
8655 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8656 struct spoolss_DeleteForm *r)
8658 const char *form_name = r->in.form_name;
8659 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8661 WERROR status = WERR_OK;
8662 struct dcerpc_binding_handle *b;
8663 TALLOC_CTX *tmp_ctx = NULL;
8665 DEBUG(5,("_spoolss_DeleteForm\n"));
8668 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8669 OUR_HANDLE(r->in.handle)));
8673 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
8674 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
8675 !token_contains_name_in_list(uidtoname(p->session_info->unix_token->uid),
8676 p->session_info->info->domain_name,
8678 p->session_info->security_token,
8679 lp_printer_admin(snum))) {
8680 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8681 return WERR_ACCESS_DENIED;
8684 tmp_ctx = talloc_new(p->mem_ctx);
8689 status = winreg_printer_binding_handle(tmp_ctx,
8690 get_session_info_system(),
8693 if (!W_ERROR_IS_OK(status)) {
8697 status = winreg_printer_deleteform1(tmp_ctx, b, form_name);
8698 if (!W_ERROR_IS_OK(status)) {
8703 * ChangeID must always be set if this is a printer
8705 if (Printer->printer_type == SPLHND_PRINTER) {
8706 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8707 status = WERR_BADFID;
8711 status = winreg_printer_update_changeid(tmp_ctx, b,
8712 lp_const_servicename(snum));
8716 talloc_free(tmp_ctx);
8720 /****************************************************************
8722 ****************************************************************/
8724 WERROR _spoolss_SetForm(struct pipes_struct *p,
8725 struct spoolss_SetForm *r)
8727 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8728 const char *form_name = r->in.form_name;
8730 WERROR status = WERR_OK;
8731 struct dcerpc_binding_handle *b;
8732 TALLOC_CTX *tmp_ctx = NULL;
8734 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8736 DEBUG(5,("_spoolss_SetForm\n"));
8739 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8740 OUR_HANDLE(r->in.handle)));
8744 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8745 and not a printer admin, then fail */
8747 if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
8748 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
8749 !token_contains_name_in_list(uidtoname(p->session_info->unix_token->uid),
8750 p->session_info->info->domain_name,
8752 p->session_info->security_token,
8753 lp_printer_admin(snum))) {
8754 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8755 return WERR_ACCESS_DENIED;
8758 tmp_ctx = talloc_new(p->mem_ctx);
8763 status = winreg_printer_binding_handle(tmp_ctx,
8764 get_session_info_system(),
8767 if (!W_ERROR_IS_OK(status)) {
8771 status = winreg_printer_setform1(tmp_ctx, b,
8774 if (!W_ERROR_IS_OK(status)) {
8779 * ChangeID must always be set if this is a printer
8781 if (Printer->printer_type == SPLHND_PRINTER) {
8782 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8783 status = WERR_BADFID;
8787 status = winreg_printer_update_changeid(tmp_ctx, b,
8788 lp_const_servicename(snum));
8792 talloc_free(tmp_ctx);
8796 /****************************************************************************
8797 fill_print_processor1
8798 ****************************************************************************/
8800 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8801 struct spoolss_PrintProcessorInfo1 *r,
8802 const char *print_processor_name)
8804 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8805 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8810 /****************************************************************************
8811 enumprintprocessors level 1.
8812 ****************************************************************************/
8814 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8815 union spoolss_PrintProcessorInfo **info_p,
8818 union spoolss_PrintProcessorInfo *info;
8821 info = talloc_array(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8822 W_ERROR_HAVE_NO_MEMORY(info);
8826 result = fill_print_processor1(info, &info[0].info1, "winprint");
8827 if (!W_ERROR_IS_OK(result)) {
8832 if (!W_ERROR_IS_OK(result)) {
8843 /****************************************************************
8844 _spoolss_EnumPrintProcessors
8845 ****************************************************************/
8847 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8848 struct spoolss_EnumPrintProcessors *r)
8852 /* that's an [in out] buffer */
8854 if (!r->in.buffer && (r->in.offered != 0)) {
8855 return WERR_INVALID_PARAM;
8858 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8861 * Enumerate the print processors ...
8863 * Just reply with "winprint", to keep NT happy
8864 * and I can use my nice printer checker.
8869 *r->out.info = NULL;
8871 if (!get_short_archi(r->in.environment)) {
8872 return WERR_INVALID_ENVIRONMENT;
8875 switch (r->in.level) {
8877 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8881 return WERR_UNKNOWN_LEVEL;
8884 if (!W_ERROR_IS_OK(result)) {
8888 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8889 spoolss_EnumPrintProcessors,
8890 *r->out.info, r->in.level,
8892 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8893 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8895 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8898 /****************************************************************************
8899 fill_printprocdatatype1
8900 ****************************************************************************/
8902 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8903 struct spoolss_PrintProcDataTypesInfo1 *r,
8904 const char *name_array)
8906 r->name_array = talloc_strdup(mem_ctx, name_array);
8907 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8912 /****************************************************************************
8913 enumprintprocdatatypes level 1.
8914 ****************************************************************************/
8916 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8917 union spoolss_PrintProcDataTypesInfo **info_p,
8921 union spoolss_PrintProcDataTypesInfo *info;
8923 info = talloc_array(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8924 W_ERROR_HAVE_NO_MEMORY(info);
8928 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8929 if (!W_ERROR_IS_OK(result)) {
8934 if (!W_ERROR_IS_OK(result)) {
8945 /****************************************************************
8946 _spoolss_EnumPrintProcDataTypes
8947 ****************************************************************/
8949 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
8950 struct spoolss_EnumPrintProcDataTypes *r)
8954 /* that's an [in out] buffer */
8956 if (!r->in.buffer && (r->in.offered != 0)) {
8957 return WERR_INVALID_PARAM;
8960 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8964 *r->out.info = NULL;
8966 if (r->in.print_processor_name == NULL ||
8967 !strequal(r->in.print_processor_name, "winprint")) {
8968 return WERR_UNKNOWN_PRINTPROCESSOR;
8971 switch (r->in.level) {
8973 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8977 return WERR_UNKNOWN_LEVEL;
8980 if (!W_ERROR_IS_OK(result)) {
8984 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8985 spoolss_EnumPrintProcDataTypes,
8986 *r->out.info, r->in.level,
8988 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8989 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8991 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8994 /****************************************************************************
8996 ****************************************************************************/
8998 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8999 struct spoolss_MonitorInfo1 *r,
9000 const char *monitor_name)
9002 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
9003 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
9008 /****************************************************************************
9010 ****************************************************************************/
9012 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
9013 struct spoolss_MonitorInfo2 *r,
9014 const char *monitor_name,
9015 const char *environment,
9016 const char *dll_name)
9018 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
9019 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
9020 r->environment = talloc_strdup(mem_ctx, environment);
9021 W_ERROR_HAVE_NO_MEMORY(r->environment);
9022 r->dll_name = talloc_strdup(mem_ctx, dll_name);
9023 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
9028 /****************************************************************************
9029 enumprintmonitors level 1.
9030 ****************************************************************************/
9032 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
9033 union spoolss_MonitorInfo **info_p,
9036 union spoolss_MonitorInfo *info;
9037 WERROR result = WERR_OK;
9039 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, 2);
9040 W_ERROR_HAVE_NO_MEMORY(info);
9044 result = fill_monitor_1(info, &info[0].info1,
9046 if (!W_ERROR_IS_OK(result)) {
9050 result = fill_monitor_1(info, &info[1].info1,
9052 if (!W_ERROR_IS_OK(result)) {
9057 if (!W_ERROR_IS_OK(result)) {
9068 /****************************************************************************
9069 enumprintmonitors level 2.
9070 ****************************************************************************/
9072 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
9073 union spoolss_MonitorInfo **info_p,
9076 union spoolss_MonitorInfo *info;
9077 WERROR result = WERR_OK;
9079 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, 2);
9080 W_ERROR_HAVE_NO_MEMORY(info);
9084 result = fill_monitor_2(info, &info[0].info2,
9086 "Windows NT X86", /* FIXME */
9088 if (!W_ERROR_IS_OK(result)) {
9092 result = fill_monitor_2(info, &info[1].info2,
9094 "Windows NT X86", /* FIXME */
9096 if (!W_ERROR_IS_OK(result)) {
9101 if (!W_ERROR_IS_OK(result)) {
9112 /****************************************************************
9113 _spoolss_EnumMonitors
9114 ****************************************************************/
9116 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
9117 struct spoolss_EnumMonitors *r)
9121 /* that's an [in out] buffer */
9123 if (!r->in.buffer && (r->in.offered != 0)) {
9124 return WERR_INVALID_PARAM;
9127 DEBUG(5,("_spoolss_EnumMonitors\n"));
9130 * Enumerate the print monitors ...
9132 * Just reply with "Local Port", to keep NT happy
9133 * and I can use my nice printer checker.
9138 *r->out.info = NULL;
9140 switch (r->in.level) {
9142 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
9146 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
9150 return WERR_UNKNOWN_LEVEL;
9153 if (!W_ERROR_IS_OK(result)) {
9157 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9158 spoolss_EnumMonitors,
9159 *r->out.info, r->in.level,
9161 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9162 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9164 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9167 /****************************************************************************
9168 ****************************************************************************/
9170 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
9171 const print_queue_struct *queue,
9172 int count, int snum,
9173 struct spoolss_PrinterInfo2 *pinfo2,
9175 struct spoolss_JobInfo1 *r)
9180 for (i=0; i<count; i++) {
9181 if (queue[i].job == (int)jobid) {
9187 if (found == false) {
9188 /* NT treats not found as bad param... yet another bad choice */
9189 return WERR_INVALID_PARAM;
9192 return fill_job_info1(mem_ctx,
9200 /****************************************************************************
9201 ****************************************************************************/
9203 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
9204 const print_queue_struct *queue,
9205 int count, int snum,
9206 struct spoolss_PrinterInfo2 *pinfo2,
9208 struct spoolss_JobInfo2 *r)
9212 struct spoolss_DeviceMode *devmode;
9215 for (i=0; i<count; i++) {
9216 if (queue[i].job == (int)jobid) {
9222 if (found == false) {
9223 /* NT treats not found as bad param... yet another bad
9225 return WERR_INVALID_PARAM;
9229 * if the print job does not have a DEVMODE associated with it,
9230 * just use the one for the printer. A NULL devicemode is not
9231 * a failure condition
9234 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
9236 result = spoolss_create_default_devmode(mem_ctx,
9237 pinfo2->printername,
9239 if (!W_ERROR_IS_OK(result)) {
9240 DEBUG(3, ("Can't proceed w/o a devmode!"));
9245 return fill_job_info2(mem_ctx,
9254 /****************************************************************
9256 ****************************************************************/
9258 WERROR _spoolss_GetJob(struct pipes_struct *p,
9259 struct spoolss_GetJob *r)
9261 WERROR result = WERR_OK;
9262 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9265 print_queue_struct *queue = NULL;
9266 print_status_struct prt_status;
9268 /* that's an [in out] buffer */
9270 if (!r->in.buffer && (r->in.offered != 0)) {
9271 return WERR_INVALID_PARAM;
9274 DEBUG(5,("_spoolss_GetJob\n"));
9278 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9282 result = winreg_get_printer_internal(p->mem_ctx,
9283 get_session_info_system(),
9285 lp_const_servicename(snum),
9287 if (!W_ERROR_IS_OK(result)) {
9291 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
9293 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9294 count, prt_status.status, prt_status.message));
9296 switch (r->in.level) {
9298 result = getjob_level_1(p->mem_ctx,
9299 queue, count, snum, pinfo2,
9300 r->in.job_id, &r->out.info->info1);
9303 result = getjob_level_2(p->mem_ctx,
9304 queue, count, snum, pinfo2,
9305 r->in.job_id, &r->out.info->info2);
9308 result = WERR_UNKNOWN_LEVEL;
9313 TALLOC_FREE(pinfo2);
9315 if (!W_ERROR_IS_OK(result)) {
9316 TALLOC_FREE(r->out.info);
9320 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
9322 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9324 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9327 /****************************************************************
9328 _spoolss_GetPrinterDataEx
9329 ****************************************************************/
9331 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
9332 struct spoolss_GetPrinterDataEx *r)
9335 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9336 const char *printer;
9338 WERROR result = WERR_OK;
9340 enum winreg_Type val_type = REG_NONE;
9341 uint8_t *val_data = NULL;
9342 uint32_t val_size = 0;
9343 struct dcerpc_binding_handle *b;
9344 TALLOC_CTX *tmp_ctx;
9346 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9348 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9349 r->in.key_name, r->in.value_name));
9351 /* in case of problem, return some default values */
9354 *r->out.type = REG_NONE;
9356 tmp_ctx = talloc_new(p->mem_ctx);
9362 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9363 OUR_HANDLE(r->in.handle)));
9364 result = WERR_BADFID;
9368 /* check to see if the keyname is valid */
9369 if (!strlen(r->in.key_name)) {
9370 result = WERR_INVALID_PARAM;
9374 /* Is the handle to a printer or to the server? */
9376 if (Printer->printer_type == SPLHND_SERVER) {
9378 union spoolss_PrinterData data;
9380 result = getprinterdata_printer_server(tmp_ctx,
9384 if (!W_ERROR_IS_OK(result)) {
9388 result = push_spoolss_PrinterData(tmp_ctx, &blob,
9389 *r->out.type, &data);
9390 if (!W_ERROR_IS_OK(result)) {
9394 *r->out.needed = blob.length;
9396 if (r->in.offered >= *r->out.needed) {
9397 memcpy(r->out.data, blob.data, blob.length);
9404 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9405 result = WERR_BADFID;
9408 printer = lp_const_servicename(snum);
9410 result = winreg_printer_binding_handle(tmp_ctx,
9411 get_session_info_system(),
9414 if (!W_ERROR_IS_OK(result)) {
9418 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9419 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
9420 strequal(r->in.value_name, "ChangeId")) {
9421 *r->out.type = REG_DWORD;
9423 if (r->in.offered >= *r->out.needed) {
9424 uint32_t changeid = 0;
9426 result = winreg_printer_get_changeid(tmp_ctx, b,
9429 if (!W_ERROR_IS_OK(result)) {
9433 SIVAL(r->out.data, 0, changeid);
9439 result = winreg_get_printer_dataex(tmp_ctx, b,
9446 if (!W_ERROR_IS_OK(result)) {
9450 *r->out.needed = val_size;
9451 *r->out.type = val_type;
9453 if (r->in.offered >= *r->out.needed) {
9454 memcpy(r->out.data, val_data, val_size);
9458 /* NOTE: do not replace type when returning WERR_MORE_DATA */
9460 if (W_ERROR_IS_OK(result)) {
9461 result = SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9464 talloc_free(tmp_ctx);
9468 /****************************************************************
9469 _spoolss_SetPrinterDataEx
9470 ****************************************************************/
9472 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
9473 struct spoolss_SetPrinterDataEx *r)
9475 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9477 WERROR result = WERR_OK;
9478 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9480 struct dcerpc_binding_handle *b;
9481 TALLOC_CTX *tmp_ctx;
9483 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9485 /* From MSDN documentation of SetPrinterDataEx: pass request to
9486 SetPrinterData if key is "PrinterDriverData" */
9489 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9490 OUR_HANDLE(r->in.handle)));
9494 if (Printer->printer_type == SPLHND_SERVER) {
9495 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9496 "Not implemented for server handles yet\n"));
9497 return WERR_INVALID_PARAM;
9500 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9505 * Access check : NT returns "access denied" if you make a
9506 * SetPrinterData call without the necessary privildge.
9507 * we were originally returning OK if nothing changed
9508 * which made Win2k issue **a lot** of SetPrinterData
9509 * when connecting to a printer --jerry
9512 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9513 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9514 "change denied by handle access permissions\n"));
9515 return WERR_ACCESS_DENIED;
9518 tmp_ctx = talloc_new(p->mem_ctx);
9523 result = winreg_printer_binding_handle(tmp_ctx,
9524 get_session_info_system(),
9527 if (!W_ERROR_IS_OK(result)) {
9531 result = winreg_get_printer(tmp_ctx, b,
9532 lp_servicename(snum),
9534 if (!W_ERROR_IS_OK(result)) {
9538 /* check for OID in valuename */
9540 oid_string = strchr(r->in.value_name, ',');
9546 /* save the registry data */
9548 result = winreg_set_printer_dataex(tmp_ctx, b,
9556 if (W_ERROR_IS_OK(result)) {
9557 /* save the OID if one was specified */
9559 char *str = talloc_asprintf(tmp_ctx, "%s\\%s",
9560 r->in.key_name, SPOOL_OID_KEY);
9562 result = WERR_NOMEM;
9567 * I'm not checking the status here on purpose. Don't know
9568 * if this is right, but I'm returning the status from the
9569 * previous set_printer_dataex() call. I have no idea if
9570 * this is right. --jerry
9572 winreg_set_printer_dataex(tmp_ctx, b,
9577 (uint8_t *) oid_string,
9578 strlen(oid_string) + 1);
9581 result = winreg_printer_update_changeid(tmp_ctx, b,
9582 lp_const_servicename(snum));
9587 talloc_free(tmp_ctx);
9591 /****************************************************************
9592 _spoolss_DeletePrinterDataEx
9593 ****************************************************************/
9595 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
9596 struct spoolss_DeletePrinterDataEx *r)
9598 const char *printer;
9600 WERROR status = WERR_OK;
9601 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9603 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9606 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9607 "Invalid handle (%s:%u:%u).\n",
9608 OUR_HANDLE(r->in.handle)));
9612 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9613 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9614 "printer properties change denied by handle\n"));
9615 return WERR_ACCESS_DENIED;
9618 if (!r->in.value_name || !r->in.key_name) {
9622 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9625 printer = lp_const_servicename(snum);
9627 status = winreg_delete_printer_dataex_internal(p->mem_ctx,
9628 get_session_info_system(),
9633 if (W_ERROR_IS_OK(status)) {
9634 status = winreg_printer_update_changeid_internal(p->mem_ctx,
9635 get_session_info_system(),
9643 /****************************************************************
9644 _spoolss_EnumPrinterKey
9645 ****************************************************************/
9647 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
9648 struct spoolss_EnumPrinterKey *r)
9651 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9653 WERROR result = WERR_BADFILE;
9654 const char **array = NULL;
9657 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9660 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9661 OUR_HANDLE(r->in.handle)));
9665 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9669 result = winreg_enum_printer_key_internal(p->mem_ctx,
9670 get_session_info_system(),
9672 lp_const_servicename(snum),
9676 if (!W_ERROR_IS_OK(result)) {
9680 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9681 result = WERR_NOMEM;
9685 *r->out._ndr_size = r->in.offered / 2;
9686 *r->out.needed = blob.length;
9688 if (r->in.offered < *r->out.needed) {
9689 result = WERR_MORE_DATA;
9692 r->out.key_buffer->string_array = array;
9696 if (!W_ERROR_IS_OK(result)) {
9698 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9706 /****************************************************************
9707 _spoolss_DeletePrinterKey
9708 ****************************************************************/
9710 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9711 struct spoolss_DeletePrinterKey *r)
9713 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9716 const char *printer;
9717 struct dcerpc_binding_handle *b;
9718 TALLOC_CTX *tmp_ctx;
9720 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9723 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9724 OUR_HANDLE(r->in.handle)));
9728 /* if keyname == NULL, return error */
9729 if ( !r->in.key_name )
9730 return WERR_INVALID_PARAM;
9732 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9736 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9737 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9738 "printer properties change denied by handle\n"));
9739 return WERR_ACCESS_DENIED;
9742 printer = lp_const_servicename(snum);
9744 tmp_ctx = talloc_new(p->mem_ctx);
9749 status = winreg_printer_binding_handle(tmp_ctx,
9750 get_session_info_system(),
9753 if (!W_ERROR_IS_OK(status)) {
9757 /* delete the key and all subkeys */
9758 status = winreg_delete_printer_key(tmp_ctx, b,
9761 if (W_ERROR_IS_OK(status)) {
9762 status = winreg_printer_update_changeid(tmp_ctx, b,
9767 talloc_free(tmp_ctx);
9771 /****************************************************************
9772 _spoolss_EnumPrinterDataEx
9773 ****************************************************************/
9775 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9776 struct spoolss_EnumPrinterDataEx *r)
9779 struct spoolss_PrinterEnumValues *info = NULL;
9780 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9784 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9788 *r->out.info = NULL;
9791 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9792 OUR_HANDLE(r->in.handle)));
9797 * first check for a keyname of NULL or "". Win2k seems to send
9798 * this a lot and we should send back WERR_INVALID_PARAM
9799 * no need to spend time looking up the printer in this case.
9803 if (!strlen(r->in.key_name)) {
9804 result = WERR_INVALID_PARAM;
9808 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9812 /* now look for a match on the key name */
9813 result = winreg_enum_printer_dataex_internal(p->mem_ctx,
9814 get_session_info_system(),
9816 lp_const_servicename(snum),
9820 if (!W_ERROR_IS_OK(result)) {
9824 #if 0 /* FIXME - gd */
9825 /* housekeeping information in the reply */
9827 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9828 * the hand marshalled container size is a multiple
9829 * of 4 bytes for RPC alignment.
9833 needed += 4-(needed % 4);
9836 *r->out.count = count;
9837 *r->out.info = info;
9840 if (!W_ERROR_IS_OK(result)) {
9844 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9845 spoolss_EnumPrinterDataEx,
9848 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9849 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9851 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9854 /****************************************************************************
9855 ****************************************************************************/
9857 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9858 const char *servername,
9859 const char *environment,
9860 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9865 werr = compose_spoolss_server_path(mem_ctx,
9868 SPOOLSS_PRTPROCS_PATH,
9870 if (!W_ERROR_IS_OK(werr)) {
9874 DEBUG(4,("print processor directory: [%s]\n", path));
9876 r->directory_name = path;
9881 /****************************************************************
9882 _spoolss_GetPrintProcessorDirectory
9883 ****************************************************************/
9885 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
9886 struct spoolss_GetPrintProcessorDirectory *r)
9889 char *prnproc_share = NULL;
9890 bool prnproc_share_exists = false;
9893 /* that's an [in out] buffer */
9895 if (!r->in.buffer && (r->in.offered != 0)) {
9896 return WERR_INVALID_PARAM;
9899 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9904 /* r->in.level is ignored */
9906 /* We always should reply with a local print processor directory so that
9907 * users are not forced to have a [prnproc$] share on the Samba spoolss
9908 * server, if users decide to do so, lets announce it though - Guenther */
9910 snum = find_service(talloc_tos(), "prnproc$", &prnproc_share);
9911 if (!prnproc_share) {
9915 prnproc_share_exists = true;
9918 result = getprintprocessordirectory_level_1(p->mem_ctx,
9919 prnproc_share_exists ? r->in.server : NULL,
9921 &r->out.info->info1);
9922 if (!W_ERROR_IS_OK(result)) {
9923 TALLOC_FREE(r->out.info);
9927 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9928 r->out.info, r->in.level);
9929 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9931 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9934 /*******************************************************************
9935 ********************************************************************/
9937 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9938 const char *dllname)
9940 enum ndr_err_code ndr_err;
9941 struct spoolss_MonitorUi ui;
9943 ui.dll_name = dllname;
9945 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9946 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9947 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9948 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9950 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9953 /*******************************************************************
9954 Streams the monitor UI DLL name in UNICODE
9955 *******************************************************************/
9957 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9958 struct security_token *token, DATA_BLOB *in,
9959 DATA_BLOB *out, uint32_t *needed)
9961 const char *dllname = "tcpmonui.dll";
9963 *needed = (strlen(dllname)+1) * 2;
9965 if (out->length < *needed) {
9966 return WERR_INSUFFICIENT_BUFFER;
9969 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9976 /*******************************************************************
9977 ********************************************************************/
9979 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9980 struct spoolss_PortData1 *port1,
9981 const DATA_BLOB *buf)
9983 enum ndr_err_code ndr_err;
9984 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9985 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9986 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9987 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9989 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9992 /*******************************************************************
9993 ********************************************************************/
9995 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9996 struct spoolss_PortData2 *port2,
9997 const DATA_BLOB *buf)
9999 enum ndr_err_code ndr_err;
10000 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
10001 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
10002 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10003 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
10005 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10008 /*******************************************************************
10009 Create a new TCP/IP port
10010 *******************************************************************/
10012 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
10013 struct security_token *token, DATA_BLOB *in,
10014 DATA_BLOB *out, uint32_t *needed)
10016 struct spoolss_PortData1 port1;
10017 struct spoolss_PortData2 port2;
10018 char *device_uri = NULL;
10021 const char *portname;
10022 const char *hostaddress;
10024 uint32_t port_number;
10027 /* peek for spoolss_PortData version */
10029 if (!in || (in->length < (128 + 4))) {
10030 return WERR_GENERAL_FAILURE;
10033 version = IVAL(in->data, 128);
10037 ZERO_STRUCT(port1);
10039 if (!pull_port_data_1(mem_ctx, &port1, in)) {
10043 portname = port1.portname;
10044 hostaddress = port1.hostaddress;
10045 queue = port1.queue;
10046 protocol = port1.protocol;
10047 port_number = port1.port_number;
10051 ZERO_STRUCT(port2);
10053 if (!pull_port_data_2(mem_ctx, &port2, in)) {
10057 portname = port2.portname;
10058 hostaddress = port2.hostaddress;
10059 queue = port2.queue;
10060 protocol = port2.protocol;
10061 port_number = port2.port_number;
10065 DEBUG(1,("xcvtcp_addport: "
10066 "unknown version of port_data: %d\n", version));
10067 return WERR_UNKNOWN_PORT;
10070 /* create the device URI and call the add_port_hook() */
10072 switch (protocol) {
10073 case PROTOCOL_RAWTCP_TYPE:
10074 device_uri = talloc_asprintf(mem_ctx,
10075 "socket://%s:%d/", hostaddress,
10079 case PROTOCOL_LPR_TYPE:
10080 device_uri = talloc_asprintf(mem_ctx,
10081 "lpr://%s/%s", hostaddress, queue );
10085 return WERR_UNKNOWN_PORT;
10092 return add_port_hook(mem_ctx, token, portname, device_uri);
10095 /*******************************************************************
10096 *******************************************************************/
10098 struct xcv_api_table xcvtcp_cmds[] = {
10099 { "MonitorUI", xcvtcp_monitorui },
10100 { "AddPort", xcvtcp_addport},
10104 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
10105 struct security_token *token, const char *command,
10112 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
10114 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
10115 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
10116 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
10119 return WERR_BADFUNC;
10122 /*******************************************************************
10123 *******************************************************************/
10124 #if 0 /* don't support management using the "Local Port" monitor */
10126 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
10127 struct security_token *token, DATA_BLOB *in,
10128 DATA_BLOB *out, uint32_t *needed)
10130 const char *dllname = "localui.dll";
10132 *needed = (strlen(dllname)+1) * 2;
10134 if (out->length < *needed) {
10135 return WERR_INSUFFICIENT_BUFFER;
10138 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
10145 /*******************************************************************
10146 *******************************************************************/
10148 struct xcv_api_table xcvlocal_cmds[] = {
10149 { "MonitorUI", xcvlocal_monitorui },
10153 struct xcv_api_table xcvlocal_cmds[] = {
10160 /*******************************************************************
10161 *******************************************************************/
10163 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
10164 struct security_token *token, const char *command,
10165 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
10170 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
10172 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
10173 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
10174 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
10176 return WERR_BADFUNC;
10179 /****************************************************************
10181 ****************************************************************/
10183 WERROR _spoolss_XcvData(struct pipes_struct *p,
10184 struct spoolss_XcvData *r)
10186 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
10187 DATA_BLOB out_data = data_blob_null;
10191 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
10192 OUR_HANDLE(r->in.handle)));
10193 return WERR_BADFID;
10196 /* Has to be a handle to the TCP/IP port monitor */
10198 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
10199 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
10200 return WERR_BADFID;
10203 /* requires administrative access to the server */
10205 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
10206 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
10207 return WERR_ACCESS_DENIED;
10210 /* Allocate the outgoing buffer */
10212 if (r->in.out_data_size) {
10213 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
10214 if (out_data.data == NULL) {
10219 switch ( Printer->printer_type ) {
10220 case SPLHND_PORTMON_TCP:
10221 werror = process_xcvtcp_command(p->mem_ctx,
10222 p->session_info->security_token,
10223 r->in.function_name,
10224 &r->in.in_data, &out_data,
10227 case SPLHND_PORTMON_LOCAL:
10228 werror = process_xcvlocal_command(p->mem_ctx,
10229 p->session_info->security_token,
10230 r->in.function_name,
10231 &r->in.in_data, &out_data,
10235 werror = WERR_INVALID_PRINT_MONITOR;
10238 if (!W_ERROR_IS_OK(werror)) {
10242 *r->out.status_code = 0;
10244 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
10245 memcpy(r->out.out_data, out_data.data,
10246 MIN(r->in.out_data_size, out_data.length));
10252 /****************************************************************
10253 _spoolss_AddPrintProcessor
10254 ****************************************************************/
10256 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
10257 struct spoolss_AddPrintProcessor *r)
10259 /* for now, just indicate success and ignore the add. We'll
10260 automatically set the winprint processor for printer
10261 entries later. Used to debug the LexMark Optra S 1855 PCL
10267 /****************************************************************
10269 ****************************************************************/
10271 WERROR _spoolss_AddPort(struct pipes_struct *p,
10272 struct spoolss_AddPort *r)
10274 /* do what w2k3 does */
10276 return WERR_NOT_SUPPORTED;
10279 /****************************************************************
10280 _spoolss_GetPrinterDriver
10281 ****************************************************************/
10283 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
10284 struct spoolss_GetPrinterDriver *r)
10286 p->rng_fault_state = true;
10287 return WERR_NOT_SUPPORTED;
10290 /****************************************************************
10291 _spoolss_ReadPrinter
10292 ****************************************************************/
10294 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
10295 struct spoolss_ReadPrinter *r)
10297 p->rng_fault_state = true;
10298 return WERR_NOT_SUPPORTED;
10301 /****************************************************************
10302 _spoolss_WaitForPrinterChange
10303 ****************************************************************/
10305 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
10306 struct spoolss_WaitForPrinterChange *r)
10308 p->rng_fault_state = true;
10309 return WERR_NOT_SUPPORTED;
10312 /****************************************************************
10313 _spoolss_ConfigurePort
10314 ****************************************************************/
10316 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
10317 struct spoolss_ConfigurePort *r)
10319 p->rng_fault_state = true;
10320 return WERR_NOT_SUPPORTED;
10323 /****************************************************************
10324 _spoolss_DeletePort
10325 ****************************************************************/
10327 WERROR _spoolss_DeletePort(struct pipes_struct *p,
10328 struct spoolss_DeletePort *r)
10330 p->rng_fault_state = true;
10331 return WERR_NOT_SUPPORTED;
10334 /****************************************************************
10335 _spoolss_CreatePrinterIC
10336 ****************************************************************/
10338 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
10339 struct spoolss_CreatePrinterIC *r)
10341 p->rng_fault_state = true;
10342 return WERR_NOT_SUPPORTED;
10345 /****************************************************************
10346 _spoolss_PlayGDIScriptOnPrinterIC
10347 ****************************************************************/
10349 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
10350 struct spoolss_PlayGDIScriptOnPrinterIC *r)
10352 p->rng_fault_state = true;
10353 return WERR_NOT_SUPPORTED;
10356 /****************************************************************
10357 _spoolss_DeletePrinterIC
10358 ****************************************************************/
10360 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
10361 struct spoolss_DeletePrinterIC *r)
10363 p->rng_fault_state = true;
10364 return WERR_NOT_SUPPORTED;
10367 /****************************************************************
10368 _spoolss_AddPrinterConnection
10369 ****************************************************************/
10371 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
10372 struct spoolss_AddPrinterConnection *r)
10374 p->rng_fault_state = true;
10375 return WERR_NOT_SUPPORTED;
10378 /****************************************************************
10379 _spoolss_DeletePrinterConnection
10380 ****************************************************************/
10382 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
10383 struct spoolss_DeletePrinterConnection *r)
10385 p->rng_fault_state = true;
10386 return WERR_NOT_SUPPORTED;
10389 /****************************************************************
10390 _spoolss_PrinterMessageBox
10391 ****************************************************************/
10393 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
10394 struct spoolss_PrinterMessageBox *r)
10396 p->rng_fault_state = true;
10397 return WERR_NOT_SUPPORTED;
10400 /****************************************************************
10401 _spoolss_AddMonitor
10402 ****************************************************************/
10404 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
10405 struct spoolss_AddMonitor *r)
10407 p->rng_fault_state = true;
10408 return WERR_NOT_SUPPORTED;
10411 /****************************************************************
10412 _spoolss_DeleteMonitor
10413 ****************************************************************/
10415 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
10416 struct spoolss_DeleteMonitor *r)
10418 p->rng_fault_state = true;
10419 return WERR_NOT_SUPPORTED;
10422 /****************************************************************
10423 _spoolss_DeletePrintProcessor
10424 ****************************************************************/
10426 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
10427 struct spoolss_DeletePrintProcessor *r)
10429 p->rng_fault_state = true;
10430 return WERR_NOT_SUPPORTED;
10433 /****************************************************************
10434 _spoolss_AddPrintProvidor
10435 ****************************************************************/
10437 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
10438 struct spoolss_AddPrintProvidor *r)
10440 p->rng_fault_state = true;
10441 return WERR_NOT_SUPPORTED;
10444 /****************************************************************
10445 _spoolss_DeletePrintProvidor
10446 ****************************************************************/
10448 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
10449 struct spoolss_DeletePrintProvidor *r)
10451 p->rng_fault_state = true;
10452 return WERR_NOT_SUPPORTED;
10455 /****************************************************************
10456 _spoolss_FindFirstPrinterChangeNotification
10457 ****************************************************************/
10459 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
10460 struct spoolss_FindFirstPrinterChangeNotification *r)
10462 p->rng_fault_state = true;
10463 return WERR_NOT_SUPPORTED;
10466 /****************************************************************
10467 _spoolss_FindNextPrinterChangeNotification
10468 ****************************************************************/
10470 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
10471 struct spoolss_FindNextPrinterChangeNotification *r)
10473 p->rng_fault_state = true;
10474 return WERR_NOT_SUPPORTED;
10477 /****************************************************************
10478 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10479 ****************************************************************/
10481 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
10482 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10484 p->rng_fault_state = true;
10485 return WERR_NOT_SUPPORTED;
10488 /****************************************************************
10489 _spoolss_ReplyOpenPrinter
10490 ****************************************************************/
10492 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
10493 struct spoolss_ReplyOpenPrinter *r)
10495 p->rng_fault_state = true;
10496 return WERR_NOT_SUPPORTED;
10499 /****************************************************************
10500 _spoolss_RouterReplyPrinter
10501 ****************************************************************/
10503 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
10504 struct spoolss_RouterReplyPrinter *r)
10506 p->rng_fault_state = true;
10507 return WERR_NOT_SUPPORTED;
10510 /****************************************************************
10511 _spoolss_ReplyClosePrinter
10512 ****************************************************************/
10514 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
10515 struct spoolss_ReplyClosePrinter *r)
10517 p->rng_fault_state = true;
10518 return WERR_NOT_SUPPORTED;
10521 /****************************************************************
10523 ****************************************************************/
10525 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
10526 struct spoolss_AddPortEx *r)
10528 p->rng_fault_state = true;
10529 return WERR_NOT_SUPPORTED;
10532 /****************************************************************
10533 _spoolss_RouterFindFirstPrinterChangeNotification
10534 ****************************************************************/
10536 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
10537 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10539 p->rng_fault_state = true;
10540 return WERR_NOT_SUPPORTED;
10543 /****************************************************************
10544 _spoolss_SpoolerInit
10545 ****************************************************************/
10547 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
10548 struct spoolss_SpoolerInit *r)
10550 p->rng_fault_state = true;
10551 return WERR_NOT_SUPPORTED;
10554 /****************************************************************
10555 _spoolss_ResetPrinterEx
10556 ****************************************************************/
10558 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
10559 struct spoolss_ResetPrinterEx *r)
10561 p->rng_fault_state = true;
10562 return WERR_NOT_SUPPORTED;
10565 /****************************************************************
10566 _spoolss_RouterReplyPrinterEx
10567 ****************************************************************/
10569 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
10570 struct spoolss_RouterReplyPrinterEx *r)
10572 p->rng_fault_state = true;
10573 return WERR_NOT_SUPPORTED;
10576 /****************************************************************
10578 ****************************************************************/
10580 WERROR _spoolss_44(struct pipes_struct *p,
10581 struct spoolss_44 *r)
10583 p->rng_fault_state = true;
10584 return WERR_NOT_SUPPORTED;
10587 /****************************************************************
10589 ****************************************************************/
10591 WERROR _spoolss_SetPort(struct pipes_struct *p,
10592 struct spoolss_SetPort *r)
10594 p->rng_fault_state = true;
10595 return WERR_NOT_SUPPORTED;
10598 /****************************************************************
10600 ****************************************************************/
10602 WERROR _spoolss_4a(struct pipes_struct *p,
10603 struct spoolss_4a *r)
10605 p->rng_fault_state = true;
10606 return WERR_NOT_SUPPORTED;
10609 /****************************************************************
10611 ****************************************************************/
10613 WERROR _spoolss_4b(struct pipes_struct *p,
10614 struct spoolss_4b *r)
10616 p->rng_fault_state = true;
10617 return WERR_NOT_SUPPORTED;
10620 /****************************************************************
10622 ****************************************************************/
10624 WERROR _spoolss_4c(struct pipes_struct *p,
10625 struct spoolss_4c *r)
10627 p->rng_fault_state = true;
10628 return WERR_NOT_SUPPORTED;
10631 /****************************************************************
10633 ****************************************************************/
10635 WERROR _spoolss_53(struct pipes_struct *p,
10636 struct spoolss_53 *r)
10638 p->rng_fault_state = true;
10639 return WERR_NOT_SUPPORTED;
10642 /****************************************************************
10643 _spoolss_AddPerMachineConnection
10644 ****************************************************************/
10646 WERROR _spoolss_AddPerMachineConnection(struct pipes_struct *p,
10647 struct spoolss_AddPerMachineConnection *r)
10649 p->rng_fault_state = true;
10650 return WERR_NOT_SUPPORTED;
10653 /****************************************************************
10654 _spoolss_DeletePerMachineConnection
10655 ****************************************************************/
10657 WERROR _spoolss_DeletePerMachineConnection(struct pipes_struct *p,
10658 struct spoolss_DeletePerMachineConnection *r)
10660 p->rng_fault_state = true;
10661 return WERR_NOT_SUPPORTED;
10664 /****************************************************************
10665 _spoolss_EnumPerMachineConnections
10666 ****************************************************************/
10668 WERROR _spoolss_EnumPerMachineConnections(struct pipes_struct *p,
10669 struct spoolss_EnumPerMachineConnections *r)
10671 p->rng_fault_state = true;
10672 return WERR_NOT_SUPPORTED;
10675 /****************************************************************
10677 ****************************************************************/
10679 WERROR _spoolss_5a(struct pipes_struct *p,
10680 struct spoolss_5a *r)
10682 p->rng_fault_state = true;
10683 return WERR_NOT_SUPPORTED;
10686 /****************************************************************
10688 ****************************************************************/
10690 WERROR _spoolss_5b(struct pipes_struct *p,
10691 struct spoolss_5b *r)
10693 p->rng_fault_state = true;
10694 return WERR_NOT_SUPPORTED;
10697 /****************************************************************
10699 ****************************************************************/
10701 WERROR _spoolss_5c(struct pipes_struct *p,
10702 struct spoolss_5c *r)
10704 p->rng_fault_state = true;
10705 return WERR_NOT_SUPPORTED;
10708 /****************************************************************
10710 ****************************************************************/
10712 WERROR _spoolss_5d(struct pipes_struct *p,
10713 struct spoolss_5d *r)
10715 p->rng_fault_state = true;
10716 return WERR_NOT_SUPPORTED;
10719 /****************************************************************
10721 ****************************************************************/
10723 WERROR _spoolss_5e(struct pipes_struct *p,
10724 struct spoolss_5e *r)
10726 p->rng_fault_state = true;
10727 return WERR_NOT_SUPPORTED;
10730 /****************************************************************
10732 ****************************************************************/
10734 WERROR _spoolss_5f(struct pipes_struct *p,
10735 struct spoolss_5f *r)
10737 p->rng_fault_state = true;
10738 return WERR_NOT_SUPPORTED;
10741 /****************************************************************
10743 ****************************************************************/
10745 WERROR _spoolss_60(struct pipes_struct *p,
10746 struct spoolss_60 *r)
10748 p->rng_fault_state = true;
10749 return WERR_NOT_SUPPORTED;
10752 /****************************************************************
10754 ****************************************************************/
10756 WERROR _spoolss_61(struct pipes_struct *p,
10757 struct spoolss_61 *r)
10759 p->rng_fault_state = true;
10760 return WERR_NOT_SUPPORTED;
10763 /****************************************************************
10765 ****************************************************************/
10767 WERROR _spoolss_62(struct pipes_struct *p,
10768 struct spoolss_62 *r)
10770 p->rng_fault_state = true;
10771 return WERR_NOT_SUPPORTED;
10774 /****************************************************************
10776 ****************************************************************/
10778 WERROR _spoolss_63(struct pipes_struct *p,
10779 struct spoolss_63 *r)
10781 p->rng_fault_state = true;
10782 return WERR_NOT_SUPPORTED;
10785 /****************************************************************
10787 ****************************************************************/
10789 WERROR _spoolss_64(struct pipes_struct *p,
10790 struct spoolss_64 *r)
10792 p->rng_fault_state = true;
10793 return WERR_NOT_SUPPORTED;
10796 /****************************************************************
10798 ****************************************************************/
10800 WERROR _spoolss_65(struct pipes_struct *p,
10801 struct spoolss_65 *r)
10803 p->rng_fault_state = true;
10804 return WERR_NOT_SUPPORTED;
10807 /****************************************************************
10808 _spoolss_GetCorePrinterDrivers
10809 ****************************************************************/
10811 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10812 struct spoolss_GetCorePrinterDrivers *r)
10814 p->rng_fault_state = true;
10815 return WERR_NOT_SUPPORTED;
10818 /****************************************************************
10820 ****************************************************************/
10822 WERROR _spoolss_67(struct pipes_struct *p,
10823 struct spoolss_67 *r)
10825 p->rng_fault_state = true;
10826 return WERR_NOT_SUPPORTED;
10829 /****************************************************************
10830 _spoolss_GetPrinterDriverPackagePath
10831 ****************************************************************/
10833 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10834 struct spoolss_GetPrinterDriverPackagePath *r)
10836 p->rng_fault_state = true;
10837 return WERR_NOT_SUPPORTED;
10840 /****************************************************************
10842 ****************************************************************/
10844 WERROR _spoolss_69(struct pipes_struct *p,
10845 struct spoolss_69 *r)
10847 p->rng_fault_state = true;
10848 return WERR_NOT_SUPPORTED;
10851 /****************************************************************
10853 ****************************************************************/
10855 WERROR _spoolss_6a(struct pipes_struct *p,
10856 struct spoolss_6a *r)
10858 p->rng_fault_state = true;
10859 return WERR_NOT_SUPPORTED;
10862 /****************************************************************
10864 ****************************************************************/
10866 WERROR _spoolss_6b(struct pipes_struct *p,
10867 struct spoolss_6b *r)
10869 p->rng_fault_state = true;
10870 return WERR_NOT_SUPPORTED;
10873 /****************************************************************
10875 ****************************************************************/
10877 WERROR _spoolss_6c(struct pipes_struct *p,
10878 struct spoolss_6c *r)
10880 p->rng_fault_state = true;
10881 return WERR_NOT_SUPPORTED;
10884 /****************************************************************
10886 ****************************************************************/
10888 WERROR _spoolss_6d(struct pipes_struct *p,
10889 struct spoolss_6d *r)
10891 p->rng_fault_state = true;
10892 return WERR_NOT_SUPPORTED;