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(p->mem_ctx,
470 get_session_info_system(),
474 if (!W_ERROR_IS_OK(result)) {
475 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
479 result = delete_printer_hook(p->mem_ctx, p->session_info->security_token,
480 Printer->sharename, p->msg_ctx);
481 if (!W_ERROR_IS_OK(result)) {
484 prune_printername_cache();
488 /****************************************************************************
489 Return the snum of a printer corresponding to an handle.
490 ****************************************************************************/
492 static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
493 int *number, struct share_params **params)
495 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
498 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
503 switch (Printer->printer_type) {
505 DEBUG(4,("short name:%s\n", Printer->sharename));
506 *number = print_queue_snum(Printer->sharename);
507 return (*number != -1);
515 /****************************************************************************
516 Set printer handle type.
517 Check if it's \\server or \\server\printer
518 ****************************************************************************/
520 static bool set_printer_hnd_printertype(struct printer_handle *Printer, const char *handlename)
522 DEBUG(3,("Setting printer type=%s\n", handlename));
524 /* it's a print server */
525 if (handlename && *handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
526 DEBUGADD(4,("Printer is a print server\n"));
527 Printer->printer_type = SPLHND_SERVER;
529 /* it's a printer (set_printer_hnd_name() will handle port monitors */
531 DEBUGADD(4,("Printer is a printer\n"));
532 Printer->printer_type = SPLHND_PRINTER;
538 static void prune_printername_cache_fn(const char *key, const char *value,
539 time_t timeout, void *private_data)
544 static void prune_printername_cache(void)
546 gencache_iterate(prune_printername_cache_fn, NULL, "PRINTERNAME/*");
549 /****************************************************************************
550 Set printer handle name.. Accept names like \\server, \\server\printer,
551 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
552 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
553 XcvDataPort() interface.
554 ****************************************************************************/
556 static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
557 const struct auth_serversupplied_info *session_info,
558 struct messaging_context *msg_ctx,
559 struct printer_handle *Printer,
560 const char *handlename)
563 int n_services=lp_numservices();
565 const char *printername;
566 const char *servername = NULL;
569 struct spoolss_PrinterInfo2 *info2 = NULL;
574 * Hopefully nobody names his printers like this. Maybe \ or ,
575 * are illegal in printer names even?
577 const char printer_not_found[] = "Printer \\, !@#$%^&*( not found";
581 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
582 (unsigned long)strlen(handlename)));
584 aprinter = discard_const_p(char, handlename);
585 if ( *handlename == '\\' ) {
586 servername = canon_servername(handlename);
587 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
591 if (!is_myname_or_ipaddr(servername)) {
592 return WERR_INVALID_PRINTER_NAME;
594 Printer->servername = talloc_asprintf(Printer, "\\\\%s", servername);
595 if (Printer->servername == NULL) {
600 if (Printer->printer_type == SPLHND_SERVER) {
604 if (Printer->printer_type != SPLHND_PRINTER) {
605 return WERR_INVALID_HANDLE;
608 DEBUGADD(5, ("searching for [%s]\n", aprinter));
610 p = strchr(aprinter, ',');
617 if (strncmp(p, "DrvConvert", strlen("DrvConvert")) == 0) {
619 } else if (strncmp(p, "LocalOnly", strlen("LocalOnly")) == 0) {
625 DEBUGADD(5, ("stripped handlename: [%s]\n", aprinter));
628 /* check for the Port Monitor Interface */
629 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
630 Printer->printer_type = SPLHND_PORTMON_TCP;
631 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
634 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
635 Printer->printer_type = SPLHND_PORTMON_LOCAL;
636 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
641 * With hundreds of printers, the "for" loop iterating all
642 * shares can be quite expensive, as it is done on every
643 * OpenPrinter. The loop maps "aprinter" to "sname", the
644 * result of which we cache in gencache.
647 cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
649 if ((cache_key != NULL) && gencache_get(cache_key, &tmp, NULL)) {
651 found = (strcmp(tmp, printer_not_found) != 0);
653 DEBUG(4, ("Printer %s not found\n", aprinter));
655 return WERR_INVALID_PRINTER_NAME;
661 /* Search all sharenames first as this is easier than pulling
662 the printer_info_2 off of disk. Don't use find_service() since
663 that calls out to map_username() */
665 /* do another loop to look for printernames */
666 for (snum = 0; !found && snum < n_services; snum++) {
667 const char *printer = lp_const_servicename(snum);
669 /* no point going on if this is not a printer */
670 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
674 /* ignore [printers] share */
675 if (strequal(printer, "printers")) {
679 fstrcpy(sname, printer);
680 if (strequal(aprinter, printer)) {
685 /* no point looking up the printer object if
686 we aren't allowing printername != sharename */
687 if (lp_force_printername(snum)) {
691 result = winreg_get_printer(mem_ctx,
696 if ( !W_ERROR_IS_OK(result) ) {
697 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
698 sname, win_errstr(result)));
702 printername = strrchr(info2->printername, '\\');
703 if (printername == NULL) {
704 printername = info2->printername;
709 if (strequal(printername, aprinter)) {
714 DEBUGADD(10, ("printername: %s\n", printername));
720 if (cache_key != NULL) {
721 gencache_set(cache_key, printer_not_found,
723 TALLOC_FREE(cache_key);
725 DEBUGADD(4,("Printer not found\n"));
726 return WERR_INVALID_PRINTER_NAME;
729 if (cache_key != NULL) {
730 gencache_set(cache_key, sname, time(NULL)+300);
731 TALLOC_FREE(cache_key);
734 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
736 strlcpy(Printer->sharename, sname, sizeof(Printer->sharename));
741 /****************************************************************************
742 Find first available printer slot. creates a printer handle for you.
743 ****************************************************************************/
745 static WERROR open_printer_hnd(struct pipes_struct *p,
746 struct policy_handle *hnd,
748 uint32_t access_granted)
750 struct printer_handle *new_printer;
753 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
755 new_printer = talloc_zero(p->mem_ctx, struct printer_handle);
756 if (new_printer == NULL) {
759 talloc_set_destructor(new_printer, printer_entry_destructor);
761 /* This also steals the printer_handle on the policy_handle */
762 if (!create_policy_hnd(p, hnd, new_printer)) {
763 TALLOC_FREE(new_printer);
764 return WERR_INVALID_HANDLE;
767 /* Add to the internal list. */
768 DLIST_ADD(printers_list, new_printer);
770 new_printer->notify.option=NULL;
772 if (!set_printer_hnd_printertype(new_printer, name)) {
773 close_printer_handle(p, hnd);
774 return WERR_INVALID_HANDLE;
777 result = set_printer_hnd_name(p->mem_ctx,
778 get_session_info_system(),
781 if (!W_ERROR_IS_OK(result)) {
782 close_printer_handle(p, hnd);
786 new_printer->access_granted = access_granted;
788 DEBUG(5, ("%d printer handles active\n",
789 (int)num_pipe_handles(p)));
794 /***************************************************************************
795 check to see if the client motify handle is monitoring the notification
796 given by (notify_type, notify_field).
797 **************************************************************************/
799 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
800 uint16_t notify_field)
805 static bool is_monitoring_event(struct printer_handle *p, uint16_t notify_type,
806 uint16_t notify_field)
808 struct spoolss_NotifyOption *option = p->notify.option;
812 * Flags should always be zero when the change notify
813 * is registered by the client's spooler. A user Win32 app
814 * might use the flags though instead of the NOTIFY_OPTION_INFO
823 return is_monitoring_event_flags(
824 p->notify.flags, notify_type, notify_field);
826 for (i = 0; i < option->count; i++) {
828 /* Check match for notify_type */
830 if (option->types[i].type != notify_type)
833 /* Check match for field */
835 for (j = 0; j < option->types[i].count; j++) {
836 if (option->types[i].fields[j].field == notify_field) {
842 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
843 p->servername, p->sharename, notify_type, notify_field));
848 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
849 _data->data.integer[0] = _integer; \
850 _data->data.integer[1] = 0;
853 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
854 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
855 if (!_data->data.string.string) {\
856 _data->data.string.size = 0; \
858 _data->data.string.size = strlen_m_term(_p) * 2;
860 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
861 _data->data.devmode.devmode = _devmode;
863 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
864 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
865 if (!_data->data.sd.sd) { \
866 _data->data.sd.sd_size = 0; \
868 _data->data.sd.sd_size = \
869 ndr_size_security_descriptor(_data->data.sd.sd, 0);
871 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
876 struct spoolss_Time st;
880 if (!init_systemtime(&st, t)) {
884 p = talloc_array(mem_ctx, char, len);
890 * Systemtime must be linearized as a set of UINT16's.
891 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
894 SSVAL(p, 0, st.year);
895 SSVAL(p, 2, st.month);
896 SSVAL(p, 4, st.day_of_week);
898 SSVAL(p, 8, st.hour);
899 SSVAL(p, 10, st.minute);
900 SSVAL(p, 12, st.second);
901 SSVAL(p, 14, st.millisecond);
907 /* Convert a notification message to a struct spoolss_Notify */
909 static void notify_one_value(struct spoolss_notify_msg *msg,
910 struct spoolss_Notify *data,
913 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
916 static void notify_string(struct spoolss_notify_msg *msg,
917 struct spoolss_Notify *data,
920 /* The length of the message includes the trailing \0 */
922 data->data.string.size = msg->len * 2;
923 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
924 if (!data->data.string.string) {
925 data->data.string.size = 0;
930 static void notify_system_time(struct spoolss_notify_msg *msg,
931 struct spoolss_Notify *data,
934 data->data.string.string = NULL;
935 data->data.string.size = 0;
937 if (msg->len != sizeof(time_t)) {
938 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
943 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
944 &data->data.string.string,
945 &data->data.string.size);
948 struct notify2_message_table {
950 void (*fn)(struct spoolss_notify_msg *msg,
951 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
954 static struct notify2_message_table printer_notify_table[] = {
955 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
956 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
957 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
958 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
959 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
960 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
961 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
962 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
963 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
964 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
965 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
966 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
967 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
968 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
969 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
970 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
971 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
972 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
973 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
976 static struct notify2_message_table job_notify_table[] = {
977 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
978 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
979 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
980 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
981 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
982 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
983 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
984 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
985 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
986 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
987 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
988 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
989 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
990 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
991 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
992 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
993 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
994 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
995 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
996 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
997 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
998 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
999 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
1000 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
1004 /***********************************************************************
1005 Allocate talloc context for container object
1006 **********************************************************************/
1008 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1013 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
1018 /***********************************************************************
1019 release all allocated memory and zero out structure
1020 **********************************************************************/
1022 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1028 talloc_destroy(ctr->ctx);
1035 /***********************************************************************
1036 **********************************************************************/
1038 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1046 /***********************************************************************
1047 **********************************************************************/
1049 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1051 if ( !ctr || !ctr->msg_groups )
1054 if ( idx >= ctr->num_groups )
1057 return &ctr->msg_groups[idx];
1061 /***********************************************************************
1062 How many groups of change messages do we have ?
1063 **********************************************************************/
1065 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1070 return ctr->num_groups;
1073 /***********************************************************************
1074 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1075 **********************************************************************/
1077 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
1079 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
1080 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
1081 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
1087 /* loop over all groups looking for a matching printer name */
1089 for ( i=0; i<ctr->num_groups; i++ ) {
1090 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
1094 /* add a new group? */
1096 if ( i == ctr->num_groups ) {
1099 if ( !(groups = talloc_realloc( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
1100 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1103 ctr->msg_groups = groups;
1105 /* clear the new entry and set the printer name */
1107 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
1108 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
1111 /* add the change messages; 'i' is the correct index now regardless */
1113 msg_grp = &ctr->msg_groups[i];
1115 msg_grp->num_msgs++;
1117 if ( !(msg_list = talloc_realloc( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
1118 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
1121 msg_grp->msgs = msg_list;
1123 new_slot = msg_grp->num_msgs-1;
1124 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
1126 /* need to allocate own copy of data */
1128 if ( msg->len != 0 )
1129 msg_grp->msgs[new_slot].notify.data = (char *)
1130 talloc_memdup( ctr->ctx, msg->notify.data, msg->len );
1132 return ctr->num_groups;
1135 static void construct_info_data(struct spoolss_Notify *info_data,
1136 enum spoolss_NotifyType type,
1137 uint16_t field, int id);
1139 /***********************************************************************
1140 Send a change notication message on all handles which have a call
1142 **********************************************************************/
1144 static int build_notify2_messages(TALLOC_CTX *mem_ctx,
1145 struct printer_handle *prn_hnd,
1146 SPOOLSS_NOTIFY_MSG *messages,
1148 struct spoolss_Notify **_notifies,
1151 struct spoolss_Notify *notifies;
1152 SPOOLSS_NOTIFY_MSG *msg;
1157 notifies = talloc_zero_array(mem_ctx,
1158 struct spoolss_Notify, num_msgs);
1163 for (i = 0; i < num_msgs; i++) {
1167 /* Are we monitoring this event? */
1169 if (!is_monitoring_event(prn_hnd, msg->type, msg->field)) {
1173 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1174 "for printer [%s]\n",
1175 msg->type, msg->field, prn_hnd->sharename));
1178 * if the is a printer notification handle and not a job
1179 * notification type, then set the id to 0.
1180 * Otherwise just use what was specified in the message.
1182 * When registering change notification on a print server
1183 * handle we always need to send back the id (snum) matching
1184 * the printer for which the change took place.
1185 * For change notify registered on a printer handle,
1186 * this does not matter and the id should be 0.
1191 if ((msg->type == PRINTER_NOTIFY_TYPE) &&
1192 (prn_hnd->printer_type == SPLHND_PRINTER)) {
1198 /* Convert unix jobid to smb jobid */
1200 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1201 id = sysjob_to_jobid(msg->id);
1204 DEBUG(3, ("no such unix jobid %d\n",
1210 construct_info_data(¬ifies[count],
1211 msg->type, msg->field, id);
1214 case PRINTER_NOTIFY_TYPE:
1215 if (printer_notify_table[msg->field].fn) {
1216 printer_notify_table[msg->field].fn(msg,
1217 ¬ifies[count], mem_ctx);
1221 case JOB_NOTIFY_TYPE:
1222 if (job_notify_table[msg->field].fn) {
1223 job_notify_table[msg->field].fn(msg,
1224 ¬ifies[count], mem_ctx);
1229 DEBUG(5, ("Unknown notification type %d\n",
1237 *_notifies = notifies;
1243 static int send_notify2_printer(TALLOC_CTX *mem_ctx,
1244 struct printer_handle *prn_hnd,
1245 SPOOLSS_NOTIFY_MSG_GROUP *msg_group)
1247 struct spoolss_Notify *notifies;
1249 union spoolss_ReplyPrinterInfo info;
1250 struct spoolss_NotifyInfo info0;
1251 uint32_t reply_result;
1256 /* Is there notification on this handle? */
1257 if (prn_hnd->notify.cli_chan == NULL ||
1258 prn_hnd->notify.cli_chan->active_connections == 0) {
1262 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1263 prn_hnd->servername, prn_hnd->sharename));
1265 /* For this printer? Print servers always receive notifications. */
1266 if ((prn_hnd->printer_type == SPLHND_PRINTER) &&
1267 (!strequal(msg_group->printername, prn_hnd->sharename))) {
1271 DEBUG(10,("Our printer\n"));
1273 /* build the array of change notifications */
1274 ret = build_notify2_messages(mem_ctx, prn_hnd,
1276 msg_group->num_msgs,
1282 info0.version = 0x2;
1283 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1284 info0.count = count;
1285 info0.notifies = notifies;
1287 info.info0 = &info0;
1289 status = dcerpc_spoolss_RouterReplyPrinterEx(
1290 prn_hnd->notify.cli_chan->binding_handle,
1292 &prn_hnd->notify.cli_hnd,
1293 prn_hnd->notify.change, /* color */
1294 prn_hnd->notify.flags,
1296 0, /* reply_type, must be 0 */
1298 if (!NT_STATUS_IS_OK(status)) {
1299 DEBUG(1, ("dcerpc_spoolss_RouterReplyPrinterEx to client: %s "
1301 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1302 nt_errstr(status)));
1303 werr = ntstatus_to_werror(status);
1304 } else if (!W_ERROR_IS_OK(werr)) {
1305 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1307 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1310 switch (reply_result) {
1313 case PRINTER_NOTIFY_INFO_DISCARDED:
1314 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1315 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1324 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1326 struct printer_handle *p;
1327 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
1328 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
1332 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1336 if (!msg_group->msgs) {
1337 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1341 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
1343 /* loop over all printers */
1345 for (p = printers_list; p; p = p->next) {
1346 ret = send_notify2_printer(mem_ctx, p, msg_group);
1353 DEBUG(8,("send_notify2_changes: Exit...\n"));
1357 /***********************************************************************
1358 **********************************************************************/
1360 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1363 uint32_t tv_sec, tv_usec;
1366 /* Unpack message */
1368 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1371 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1373 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1376 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1377 &msg->notify.value[0], &msg->notify.value[1]);
1379 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1380 &msg->len, &msg->notify.data);
1382 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1383 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1385 tv->tv_sec = tv_sec;
1386 tv->tv_usec = tv_usec;
1389 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1390 msg->notify.value[1]));
1392 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1397 /********************************************************************
1398 Receive a notify2 message list
1399 ********************************************************************/
1401 static void receive_notify2_message_list(struct messaging_context *msg,
1404 struct server_id server_id,
1407 size_t msg_count, i;
1408 char *buf = (char *)data->data;
1411 SPOOLSS_NOTIFY_MSG notify;
1412 SPOOLSS_NOTIFY_MSG_CTR messages;
1415 if (data->length < 4) {
1416 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1420 msg_count = IVAL(buf, 0);
1423 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1425 if (msg_count == 0) {
1426 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1430 /* initialize the container */
1432 ZERO_STRUCT( messages );
1433 notify_msg_ctr_init( &messages );
1436 * build message groups for each printer identified
1437 * in a change_notify msg. Remember that a PCN message
1438 * includes the handle returned for the srv_spoolss_replyopenprinter()
1439 * call. Therefore messages are grouped according to printer handle.
1442 for ( i=0; i<msg_count; i++ ) {
1443 struct timeval msg_tv;
1445 if (msg_ptr + 4 - buf > data->length) {
1446 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1450 msg_len = IVAL(msg_ptr,0);
1453 if (msg_ptr + msg_len - buf > data->length) {
1454 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1458 /* unpack messages */
1460 ZERO_STRUCT( notify );
1461 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1464 /* add to correct list in container */
1466 notify_msg_ctr_addmsg( &messages, ¬ify );
1468 /* free memory that might have been allocated by notify2_unpack_msg() */
1470 if ( notify.len != 0 )
1471 SAFE_FREE( notify.notify.data );
1474 /* process each group of messages */
1476 num_groups = notify_msg_ctr_numgroups( &messages );
1477 for ( i=0; i<num_groups; i++ )
1478 send_notify2_changes( &messages, i );
1483 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1484 (uint32_t)msg_count ));
1486 notify_msg_ctr_destroy( &messages );
1491 /********************************************************************
1492 Send a message to ourself about new driver being installed
1493 so we can upgrade the information for each printer bound to this
1495 ********************************************************************/
1497 static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
1498 struct messaging_context *msg_ctx)
1500 int len = strlen(drivername);
1505 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1508 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
1509 MSG_PRINTER_DRVUPGRADE,
1510 (const uint8_t *)drivername, len+1);
1515 void srv_spoolss_cleanup(void)
1517 struct printer_session_counter *session_counter;
1519 for (session_counter = counter_list;
1520 session_counter != NULL;
1521 session_counter = counter_list) {
1522 DLIST_REMOVE(counter_list, session_counter);
1523 TALLOC_FREE(session_counter);
1527 /**********************************************************************
1528 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1529 over all printers, upgrading ones as necessary
1530 **********************************************************************/
1532 void do_drv_upgrade_printer(struct messaging_context *msg,
1535 struct server_id server_id,
1538 TALLOC_CTX *tmp_ctx;
1539 struct auth_serversupplied_info *session_info = NULL;
1540 struct spoolss_PrinterInfo2 *pinfo2;
1543 const char *drivername;
1545 int n_services = lp_numservices();
1547 tmp_ctx = talloc_new(NULL);
1548 if (!tmp_ctx) return;
1550 status = make_session_info_system(tmp_ctx, &session_info);
1551 if (!NT_STATUS_IS_OK(status)) {
1552 DEBUG(0, ("do_drv_upgrade_printer: "
1553 "Could not create system session_info\n"));
1557 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, data->length);
1559 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1563 DEBUG(10, ("do_drv_upgrade_printer: "
1564 "Got message for new driver [%s]\n", drivername));
1566 /* Iterate the printer list */
1568 for (snum = 0; snum < n_services; snum++) {
1569 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1573 /* ignore [printers] share */
1574 if (strequal(lp_const_servicename(snum), "printers")) {
1578 result = winreg_get_printer(tmp_ctx, session_info, msg,
1579 lp_const_servicename(snum),
1582 if (!W_ERROR_IS_OK(result)) {
1586 if (!pinfo2->drivername) {
1590 if (strcmp(drivername, pinfo2->drivername) != 0) {
1594 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1596 /* all we care about currently is the change_id */
1597 result = winreg_printer_update_changeid(tmp_ctx,
1600 pinfo2->printername);
1602 if (!W_ERROR_IS_OK(result)) {
1603 DEBUG(3, ("do_drv_upgrade_printer: "
1604 "Failed to update changeid [%s]\n",
1605 win_errstr(result)));
1611 talloc_free(tmp_ctx);
1614 /********************************************************************
1615 Update the cache for all printq's with a registered client
1617 ********************************************************************/
1619 void update_monitored_printq_cache(struct messaging_context *msg_ctx)
1621 struct printer_handle *printer = printers_list;
1624 /* loop through all printers and update the cache where
1625 a client is connected */
1627 if ((printer->printer_type == SPLHND_PRINTER) &&
1628 ((printer->notify.cli_chan != NULL) &&
1629 (printer->notify.cli_chan->active_connections > 0))) {
1630 snum = print_queue_snum(printer->sharename);
1631 print_queue_status(msg_ctx, snum, NULL, NULL);
1634 printer = printer->next;
1640 /****************************************************************
1641 _spoolss_OpenPrinter
1642 ****************************************************************/
1644 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1645 struct spoolss_OpenPrinter *r)
1647 struct spoolss_OpenPrinterEx e;
1650 ZERO_STRUCT(e.in.userlevel);
1652 e.in.printername = r->in.printername;
1653 e.in.datatype = r->in.datatype;
1654 e.in.devmode_ctr = r->in.devmode_ctr;
1655 e.in.access_mask = r->in.access_mask;
1658 e.out.handle = r->out.handle;
1660 werr = _spoolss_OpenPrinterEx(p, &e);
1662 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1663 /* OpenPrinterEx returns this for a bad
1664 * printer name. We must return WERR_INVALID_PRINTER_NAME
1667 werr = WERR_INVALID_PRINTER_NAME;
1673 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1674 struct spoolss_DeviceMode *orig,
1675 struct spoolss_DeviceMode **dest)
1677 struct spoolss_DeviceMode *dm;
1679 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1684 /* copy all values, then duplicate strings and structs */
1687 dm->devicename = talloc_strdup(dm, orig->devicename);
1688 if (!dm->devicename) {
1691 dm->formname = talloc_strdup(dm, orig->formname);
1692 if (!dm->formname) {
1695 if (orig->driverextra_data.data) {
1696 dm->driverextra_data.data =
1697 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1698 orig->driverextra_data.length);
1699 if (!dm->driverextra_data.data) {
1708 /****************************************************************
1709 _spoolss_OpenPrinterEx
1710 ****************************************************************/
1712 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1713 struct spoolss_OpenPrinterEx *r)
1718 struct printer_handle *Printer=NULL;
1722 if (!r->in.printername) {
1723 return WERR_INVALID_PARAM;
1726 if (r->in.level > 3) {
1727 return WERR_INVALID_PARAM;
1729 if ((r->in.level == 1 && !r->in.userlevel.level1) ||
1730 (r->in.level == 2 && !r->in.userlevel.level2) ||
1731 (r->in.level == 3 && !r->in.userlevel.level3)) {
1732 return WERR_INVALID_PARAM;
1735 /* some sanity check because you can open a printer or a print server */
1736 /* aka: \\server\printer or \\server */
1738 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1740 result = open_printer_hnd(p, r->out.handle, r->in.printername, 0);
1741 if (!W_ERROR_IS_OK(result)) {
1742 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1743 "for printer %s\n", r->in.printername));
1744 ZERO_STRUCTP(r->out.handle);
1748 Printer = find_printer_index_by_hnd(p, r->out.handle);
1750 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1751 "handle we created for printer %s\n", r->in.printername));
1752 close_printer_handle(p, r->out.handle);
1753 ZERO_STRUCTP(r->out.handle);
1754 return WERR_INVALID_PARAM;
1758 * First case: the user is opening the print server:
1760 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1761 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1763 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1764 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1765 * or if the user is listed in the smb.conf printer admin parameter.
1767 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1768 * client view printer folder, but does not show the MSAPW.
1770 * Note: this test needs code to check access rights here too. Jeremy
1771 * could you look at this?
1773 * Second case: the user is opening a printer:
1774 * NT doesn't let us connect to a printer if the connecting user
1775 * doesn't have print permission.
1777 * Third case: user is opening a Port Monitor
1778 * access checks same as opening a handle to the print server.
1781 switch (Printer->printer_type )
1784 case SPLHND_PORTMON_TCP:
1785 case SPLHND_PORTMON_LOCAL:
1786 /* Printserver handles use global struct... */
1790 /* Map standard access rights to object specific access rights */
1792 se_map_standard(&r->in.access_mask,
1793 &printserver_std_mapping);
1795 /* Deny any object specific bits that don't apply to print
1796 servers (i.e printer and job specific bits) */
1798 r->in.access_mask &= SEC_MASK_SPECIFIC;
1800 if (r->in.access_mask &
1801 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1802 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1803 close_printer_handle(p, r->out.handle);
1804 ZERO_STRUCTP(r->out.handle);
1805 return WERR_ACCESS_DENIED;
1808 /* Allow admin access */
1810 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1812 if (!lp_ms_add_printer_wizard()) {
1813 close_printer_handle(p, r->out.handle);
1814 ZERO_STRUCTP(r->out.handle);
1815 return WERR_ACCESS_DENIED;
1818 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1819 and not a printer admin, then fail */
1821 if ((p->session_info->utok.uid != sec_initial_uid()) &&
1822 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
1823 !nt_token_check_sid(&global_sid_Builtin_Print_Operators, p->session_info->security_token) &&
1824 !token_contains_name_in_list(
1825 uidtoname(p->session_info->utok.uid),
1826 p->session_info->info3->base.domain.string,
1828 p->session_info->security_token,
1829 lp_printer_admin(snum))) {
1830 close_printer_handle(p, r->out.handle);
1831 ZERO_STRUCTP(r->out.handle);
1832 DEBUG(3,("access DENIED as user is not root, "
1833 "has no printoperator privilege, "
1834 "not a member of the printoperator builtin group and "
1835 "is not in printer admin list"));
1836 return WERR_ACCESS_DENIED;
1839 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1843 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1846 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1847 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1849 /* We fall through to return WERR_OK */
1852 case SPLHND_PRINTER:
1853 /* NT doesn't let us connect to a printer if the connecting user
1854 doesn't have print permission. */
1856 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1857 close_printer_handle(p, r->out.handle);
1858 ZERO_STRUCTP(r->out.handle);
1862 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1863 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1866 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1868 /* map an empty access mask to the minimum access mask */
1869 if (r->in.access_mask == 0x0)
1870 r->in.access_mask = PRINTER_ACCESS_USE;
1873 * If we are not serving the printer driver for this printer,
1874 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1875 * will keep NT clients happy --jerry
1878 if (lp_use_client_driver(snum)
1879 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1881 r->in.access_mask = PRINTER_ACCESS_USE;
1884 /* check smb.conf parameters and the the sec_desc */
1885 raddr = tsocket_address_inet_addr_string(p->remote_address,
1887 if (raddr == NULL) {
1891 rc = get_remote_hostname(p->remote_address,
1897 if (strequal(rhost, "UNKNOWN")) {
1901 if (!allow_access(lp_hostsdeny(snum), lp_hostsallow(snum),
1903 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1904 ZERO_STRUCTP(r->out.handle);
1905 return WERR_ACCESS_DENIED;
1908 if (!user_ok_token(uidtoname(p->session_info->utok.uid), NULL,
1909 p->session_info->security_token, snum) ||
1910 !print_access_check(p->session_info,
1913 r->in.access_mask)) {
1914 DEBUG(3, ("access DENIED for printer open\n"));
1915 close_printer_handle(p, r->out.handle);
1916 ZERO_STRUCTP(r->out.handle);
1917 return WERR_ACCESS_DENIED;
1920 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1921 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1922 close_printer_handle(p, r->out.handle);
1923 ZERO_STRUCTP(r->out.handle);
1924 return WERR_ACCESS_DENIED;
1927 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1928 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1930 r->in.access_mask = PRINTER_ACCESS_USE;
1932 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1933 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1935 winreg_create_printer(p->mem_ctx,
1936 get_session_info_system(),
1938 lp_const_servicename(snum));
1943 /* sanity check to prevent programmer error */
1944 ZERO_STRUCTP(r->out.handle);
1948 Printer->access_granted = r->in.access_mask;
1951 * If the client sent a devmode in the OpenPrinter() call, then
1952 * save it here in case we get a job submission on this handle
1955 if ((Printer->printer_type != SPLHND_SERVER) &&
1956 r->in.devmode_ctr.devmode) {
1957 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1961 #if 0 /* JERRY -- I'm doubtful this is really effective */
1962 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1963 optimization in Windows 2000 clients --jerry */
1965 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1966 && (RA_WIN2K == get_remote_arch()) )
1968 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1969 sys_usleep( 500000 );
1976 /****************************************************************
1977 _spoolss_ClosePrinter
1978 ****************************************************************/
1980 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1981 struct spoolss_ClosePrinter *r)
1983 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1985 if (Printer && Printer->document_started) {
1986 struct spoolss_EndDocPrinter e;
1988 e.in.handle = r->in.handle;
1990 _spoolss_EndDocPrinter(p, &e);
1993 if (!close_printer_handle(p, r->in.handle))
1996 /* clear the returned printer handle. Observed behavior
1997 from Win2k server. Don't think this really matters.
1998 Previous code just copied the value of the closed
2001 ZERO_STRUCTP(r->out.handle);
2006 /****************************************************************
2007 _spoolss_DeletePrinter
2008 ****************************************************************/
2010 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
2011 struct spoolss_DeletePrinter *r)
2013 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2017 if (Printer && Printer->document_started) {
2018 struct spoolss_EndDocPrinter e;
2020 e.in.handle = r->in.handle;
2022 _spoolss_EndDocPrinter(p, &e);
2025 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
2026 winreg_delete_printer_key(p->mem_ctx,
2027 get_session_info_system(),
2029 lp_const_servicename(snum),
2033 result = delete_printer_handle(p, r->in.handle);
2038 /*******************************************************************
2039 * static function to lookup the version id corresponding to an
2040 * long architecture string
2041 ******************************************************************/
2043 static const struct print_architecture_table_node archi_table[]= {
2045 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
2046 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
2047 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
2048 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
2049 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
2050 {"Windows IA64", SPL_ARCH_IA64, 3 },
2051 {"Windows x64", SPL_ARCH_X64, 3 },
2055 static int get_version_id(const char *arch)
2059 for (i=0; archi_table[i].long_archi != NULL; i++)
2061 if (strcmp(arch, archi_table[i].long_archi) == 0)
2062 return (archi_table[i].version);
2068 /****************************************************************
2069 _spoolss_DeletePrinterDriver
2070 ****************************************************************/
2072 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
2073 struct spoolss_DeletePrinterDriver *r)
2076 struct spoolss_DriverInfo8 *info = NULL;
2077 struct spoolss_DriverInfo8 *info_win2k = NULL;
2081 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2082 and not a printer admin, then fail */
2084 if ( (p->session_info->utok.uid != sec_initial_uid())
2085 && !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR)
2086 && !token_contains_name_in_list(
2087 uidtoname(p->session_info->utok.uid),
2088 p->session_info->info3->base.domain.string,
2090 p->session_info->security_token,
2091 lp_printer_admin(-1)) )
2093 return WERR_ACCESS_DENIED;
2096 /* check that we have a valid driver name first */
2098 if ((version = get_version_id(r->in.architecture)) == -1)
2099 return WERR_INVALID_ENVIRONMENT;
2101 status = winreg_get_driver(p->mem_ctx,
2102 get_session_info_system(),
2104 r->in.architecture, r->in.driver,
2106 if (!W_ERROR_IS_OK(status)) {
2107 /* try for Win2k driver if "Windows NT x86" */
2109 if ( version == 2 ) {
2112 status = winreg_get_driver(p->mem_ctx,
2113 get_session_info_system(),
2118 if (!W_ERROR_IS_OK(status)) {
2119 status = WERR_UNKNOWN_PRINTER_DRIVER;
2123 /* otherwise it was a failure */
2125 status = WERR_UNKNOWN_PRINTER_DRIVER;
2131 if (printer_driver_in_use(p->mem_ctx,
2132 get_session_info_system(),
2135 status = WERR_PRINTER_DRIVER_IN_USE;
2140 status = winreg_get_driver(p->mem_ctx,
2141 get_session_info_system(),
2144 r->in.driver, 3, &info_win2k);
2145 if (W_ERROR_IS_OK(status)) {
2146 /* if we get to here, we now have 2 driver info structures to remove */
2147 /* remove the Win2k driver first*/
2149 status = winreg_del_driver(p->mem_ctx,
2150 get_session_info_system(),
2153 talloc_free(info_win2k);
2155 /* this should not have failed---if it did, report to client */
2156 if (!W_ERROR_IS_OK(status)) {
2162 status = winreg_del_driver(p->mem_ctx,
2163 get_session_info_system(),
2173 /****************************************************************
2174 _spoolss_DeletePrinterDriverEx
2175 ****************************************************************/
2177 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
2178 struct spoolss_DeletePrinterDriverEx *r)
2180 struct spoolss_DriverInfo8 *info = NULL;
2181 struct spoolss_DriverInfo8 *info_win2k = NULL;
2186 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2187 and not a printer admin, then fail */
2189 if ( (p->session_info->utok.uid != sec_initial_uid())
2190 && !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR)
2191 && !token_contains_name_in_list(
2192 uidtoname(p->session_info->utok.uid),
2193 p->session_info->info3->base.domain.string,
2195 p->session_info->security_token, lp_printer_admin(-1)) )
2197 return WERR_ACCESS_DENIED;
2200 /* check that we have a valid driver name first */
2201 if ((version = get_version_id(r->in.architecture)) == -1) {
2202 /* this is what NT returns */
2203 return WERR_INVALID_ENVIRONMENT;
2206 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2207 version = r->in.version;
2209 status = winreg_get_driver(p->mem_ctx,
2210 get_session_info_system(),
2216 if (!W_ERROR_IS_OK(status)) {
2217 status = WERR_UNKNOWN_PRINTER_DRIVER;
2220 * if the client asked for a specific version,
2221 * or this is something other than Windows NT x86,
2225 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2228 /* try for Win2k driver if "Windows NT x86" */
2231 status = winreg_get_driver(info,
2232 get_session_info_system(),
2237 if (!W_ERROR_IS_OK(status)) {
2238 status = WERR_UNKNOWN_PRINTER_DRIVER;
2243 if (printer_driver_in_use(info,
2244 get_session_info_system(),
2247 status = WERR_PRINTER_DRIVER_IN_USE;
2252 * we have a couple of cases to consider.
2253 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2254 * then the delete should fail if **any** files overlap with
2256 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2257 * non-overlapping files
2258 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2259 * is set, the do not delete any files
2260 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2263 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2265 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2268 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2269 printer_driver_files_in_use(info,
2270 get_session_info_system(),
2273 /* no idea of the correct error here */
2274 status = WERR_ACCESS_DENIED;
2279 /* also check for W32X86/3 if necessary; maybe we already have? */
2281 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2282 status = winreg_get_driver(info,
2283 get_session_info_system(),
2286 r->in.driver, 3, &info_win2k);
2287 if (W_ERROR_IS_OK(status)) {
2290 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2291 printer_driver_files_in_use(info,
2292 get_session_info_system(),
2295 /* no idea of the correct error here */
2296 talloc_free(info_win2k);
2297 status = WERR_ACCESS_DENIED;
2301 /* if we get to here, we now have 2 driver info structures to remove */
2302 /* remove the Win2k driver first*/
2304 status = winreg_del_driver(info,
2305 get_session_info_system(),
2310 /* this should not have failed---if it did, report to client */
2312 if (!W_ERROR_IS_OK(status)) {
2317 * now delete any associated files if delete_files is
2318 * true. Even if this part failes, we return succes
2319 * because the driver doesn not exist any more
2322 delete_driver_files(get_session_info_system(),
2328 status = winreg_del_driver(info,
2329 get_session_info_system(),
2333 if (!W_ERROR_IS_OK(status)) {
2338 * now delete any associated files if delete_files is
2339 * true. Even if this part failes, we return succes
2340 * because the driver doesn not exist any more
2343 delete_driver_files(get_session_info_system(), info);
2352 /********************************************************************
2353 GetPrinterData on a printer server Handle.
2354 ********************************************************************/
2356 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2358 enum winreg_Type *type,
2359 union spoolss_PrinterData *data)
2361 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2363 if (!strcasecmp_m(value, "W3SvcInstalled")) {
2369 if (!strcasecmp_m(value, "BeepEnabled")) {
2375 if (!strcasecmp_m(value, "EventLog")) {
2377 /* formally was 0x1b */
2382 if (!strcasecmp_m(value, "NetPopup")) {
2388 if (!strcasecmp_m(value, "MajorVersion")) {
2391 /* Windows NT 4.0 seems to not allow uploading of drivers
2392 to a server that reports 0x3 as the MajorVersion.
2393 need to investigate more how Win2k gets around this .
2396 if (RA_WINNT == get_remote_arch()) {
2405 if (!strcasecmp_m(value, "MinorVersion")) {
2412 * uint32_t size = 0x114
2413 * uint32_t major = 5
2414 * uint32_t minor = [0|1]
2415 * uint32_t build = [2195|2600]
2416 * extra unicode string = e.g. "Service Pack 3"
2418 if (!strcasecmp_m(value, "OSVersion")) {
2420 enum ndr_err_code ndr_err;
2421 struct spoolss_OSVersion os;
2423 os.major = 5; /* Windows 2000 == 5.0 */
2425 os.build = 2195; /* build */
2426 os.extra_string = ""; /* leave extra string empty */
2428 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2429 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2430 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2431 return WERR_GENERAL_FAILURE;
2435 data->binary = blob;
2441 if (!strcasecmp_m(value, "DefaultSpoolDirectory")) {
2444 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2445 W_ERROR_HAVE_NO_MEMORY(data->string);
2450 if (!strcasecmp_m(value, "Architecture")) {
2452 data->string = talloc_strdup(mem_ctx,
2453 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2454 W_ERROR_HAVE_NO_MEMORY(data->string);
2459 if (!strcasecmp_m(value, "DsPresent")) {
2462 /* only show the publish check box if we are a
2463 member of a AD domain */
2465 if (lp_security() == SEC_ADS) {
2473 if (!strcasecmp_m(value, "DNSMachineName")) {
2474 const char *hostname = get_mydnsfullname();
2477 return WERR_BADFILE;
2481 data->string = talloc_strdup(mem_ctx, hostname);
2482 W_ERROR_HAVE_NO_MEMORY(data->string);
2489 return WERR_INVALID_PARAM;
2492 /****************************************************************
2493 _spoolss_GetPrinterData
2494 ****************************************************************/
2496 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2497 struct spoolss_GetPrinterData *r)
2499 struct spoolss_GetPrinterDataEx r2;
2501 r2.in.handle = r->in.handle;
2502 r2.in.key_name = "PrinterDriverData";
2503 r2.in.value_name = r->in.value_name;
2504 r2.in.offered = r->in.offered;
2505 r2.out.type = r->out.type;
2506 r2.out.data = r->out.data;
2507 r2.out.needed = r->out.needed;
2509 return _spoolss_GetPrinterDataEx(p, &r2);
2512 /*********************************************************
2513 Connect to the client machine.
2514 **********************************************************/
2516 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2517 struct sockaddr_storage *client_ss, const char *remote_machine)
2520 struct cli_state *the_cli;
2521 struct sockaddr_storage rm_addr;
2522 char addr[INET6_ADDRSTRLEN];
2524 if ( is_zero_addr(client_ss) ) {
2525 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2527 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2528 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2531 print_sockaddr(addr, sizeof(addr), &rm_addr);
2533 rm_addr = *client_ss;
2534 print_sockaddr(addr, sizeof(addr), &rm_addr);
2535 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2539 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2540 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2545 /* setup the connection */
2546 ret = cli_full_connection( &the_cli, lp_netbios_name(), remote_machine,
2547 &rm_addr, 0, "IPC$", "IPC",
2551 0, lp_client_signing());
2553 if ( !NT_STATUS_IS_OK( ret ) ) {
2554 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2559 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2560 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2561 cli_shutdown(the_cli);
2566 * Ok - we have an anonymous connection to the IPC$ share.
2567 * Now start the NT Domain stuff :-).
2570 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2571 if (!NT_STATUS_IS_OK(ret)) {
2572 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2573 remote_machine, nt_errstr(ret)));
2574 cli_shutdown(the_cli);
2581 /***************************************************************************
2582 Connect to the client.
2583 ****************************************************************************/
2585 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2586 uint32_t localprinter,
2587 enum winreg_Type type,
2588 struct policy_handle *handle,
2589 struct notify_back_channel **_chan,
2590 struct sockaddr_storage *client_ss,
2591 struct messaging_context *msg_ctx)
2595 struct notify_back_channel *chan;
2597 for (chan = back_channels; chan; chan = chan->next) {
2598 if (memcmp(&chan->client_address, client_ss,
2599 sizeof(struct sockaddr_storage)) == 0) {
2605 * If it's the first connection, contact the client
2606 * and connect to the IPC$ share anonymously
2609 fstring unix_printer;
2611 /* the +2 is to strip the leading 2 backslashs */
2612 fstrcpy(unix_printer, printer + 2);
2614 chan = talloc_zero(back_channels, struct notify_back_channel);
2618 chan->client_address = *client_ss;
2620 if (!spoolss_connect_to_client(&chan->cli_pipe, client_ss, unix_printer)) {
2624 chan->binding_handle = chan->cli_pipe->binding_handle;
2626 DLIST_ADD(back_channels, chan);
2628 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2629 receive_notify2_message_list);
2630 /* Tell the connections db we're now interested in printer
2631 * notify messages. */
2632 serverid_register_msg_flags(messaging_server_id(msg_ctx),
2633 true, FLAG_MSG_PRINT_NOTIFY);
2637 * Tell the specific printing tdb we want messages for this printer
2638 * by registering our PID.
2641 if (!print_notify_register_pid(snum)) {
2642 DEBUG(0, ("Failed to register our pid for printer %s\n",
2646 status = dcerpc_spoolss_ReplyOpenPrinter(chan->binding_handle,
2655 if (!NT_STATUS_IS_OK(status)) {
2656 DEBUG(5, ("dcerpc_spoolss_ReplyOpenPrinter returned [%s]\n", nt_errstr(status)));
2657 result = ntstatus_to_werror(status);
2658 } else if (!W_ERROR_IS_OK(result)) {
2659 DEBUG(5, ("ReplyOpenPrinter returned [%s]\n", win_errstr(result)));
2662 chan->active_connections++;
2665 return (W_ERROR_IS_OK(result));
2668 /****************************************************************
2669 ****************************************************************/
2671 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2672 const struct spoolss_NotifyOption *r)
2674 struct spoolss_NotifyOption *option;
2681 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2688 if (!option->count) {
2692 option->types = talloc_zero_array(option,
2693 struct spoolss_NotifyOptionType, option->count);
2694 if (!option->types) {
2695 talloc_free(option);
2699 for (i=0; i < option->count; i++) {
2700 option->types[i] = r->types[i];
2702 if (option->types[i].count) {
2703 option->types[i].fields = talloc_zero_array(option,
2704 union spoolss_Field, option->types[i].count);
2705 if (!option->types[i].fields) {
2706 talloc_free(option);
2709 for (k=0; k<option->types[i].count; k++) {
2710 option->types[i].fields[k] =
2711 r->types[i].fields[k];
2719 /****************************************************************
2720 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2722 * before replying OK: status=0 a rpc call is made to the workstation
2723 * asking ReplyOpenPrinter
2725 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2726 * called from api_spoolss_rffpcnex
2727 ****************************************************************/
2729 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2730 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2733 struct spoolss_NotifyOption *option = r->in.notify_options;
2734 struct sockaddr_storage client_ss;
2735 socklen_t client_len;
2737 /* store the notify value in the printer struct */
2739 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2742 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2743 "Invalid handle (%s:%u:%u).\n",
2744 OUR_HANDLE(r->in.handle)));
2748 Printer->notify.flags = r->in.flags;
2749 Printer->notify.options = r->in.options;
2750 Printer->notify.printerlocal = r->in.printer_local;
2751 Printer->notify.msg_ctx = p->msg_ctx;
2753 TALLOC_FREE(Printer->notify.option);
2754 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2756 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2758 /* Connect to the client machine and send a ReplyOpenPrinter */
2760 if ( Printer->printer_type == SPLHND_SERVER)
2762 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2763 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2766 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2767 "remote_address is %s\n",
2768 tsocket_address_string(p->remote_address, p->mem_ctx)));
2770 if (!lp_print_notify_backchannel(snum)) {
2771 DEBUG(10, ("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2772 "backchannel disabled\n"));
2773 return WERR_SERVER_UNAVAILABLE;
2776 client_len = tsocket_address_bsd_sockaddr(p->remote_address,
2777 (struct sockaddr *) &client_ss,
2778 sizeof(struct sockaddr_storage));
2779 if (client_len < 0) {
2783 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2784 Printer->notify.printerlocal, REG_SZ,
2785 &Printer->notify.cli_hnd,
2786 &Printer->notify.cli_chan,
2787 &client_ss, p->msg_ctx)) {
2788 return WERR_SERVER_UNAVAILABLE;
2794 /*******************************************************************
2795 * fill a notify_info_data with the servername
2796 ********************************************************************/
2798 static void spoolss_notify_server_name(struct messaging_context *msg_ctx,
2800 struct spoolss_Notify *data,
2801 print_queue_struct *queue,
2802 struct spoolss_PrinterInfo2 *pinfo2,
2803 TALLOC_CTX *mem_ctx)
2805 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2808 /*******************************************************************
2809 * fill a notify_info_data with the printername (not including the servername).
2810 ********************************************************************/
2812 static void spoolss_notify_printer_name(struct messaging_context *msg_ctx,
2814 struct spoolss_Notify *data,
2815 print_queue_struct *queue,
2816 struct spoolss_PrinterInfo2 *pinfo2,
2817 TALLOC_CTX *mem_ctx)
2819 /* the notify name should not contain the \\server\ part */
2820 const char *p = strrchr(pinfo2->printername, '\\');
2823 p = pinfo2->printername;
2828 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2831 /*******************************************************************
2832 * fill a notify_info_data with the servicename
2833 ********************************************************************/
2835 static void spoolss_notify_share_name(struct messaging_context *msg_ctx,
2837 struct spoolss_Notify *data,
2838 print_queue_struct *queue,
2839 struct spoolss_PrinterInfo2 *pinfo2,
2840 TALLOC_CTX *mem_ctx)
2842 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2845 /*******************************************************************
2846 * fill a notify_info_data with the port name
2847 ********************************************************************/
2849 static void spoolss_notify_port_name(struct messaging_context *msg_ctx,
2851 struct spoolss_Notify *data,
2852 print_queue_struct *queue,
2853 struct spoolss_PrinterInfo2 *pinfo2,
2854 TALLOC_CTX *mem_ctx)
2856 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2859 /*******************************************************************
2860 * fill a notify_info_data with the printername
2861 * but it doesn't exist, have to see what to do
2862 ********************************************************************/
2864 static void spoolss_notify_driver_name(struct messaging_context *msg_ctx,
2866 struct spoolss_Notify *data,
2867 print_queue_struct *queue,
2868 struct spoolss_PrinterInfo2 *pinfo2,
2869 TALLOC_CTX *mem_ctx)
2871 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2874 /*******************************************************************
2875 * fill a notify_info_data with the comment
2876 ********************************************************************/
2878 static void spoolss_notify_comment(struct messaging_context *msg_ctx,
2880 struct spoolss_Notify *data,
2881 print_queue_struct *queue,
2882 struct spoolss_PrinterInfo2 *pinfo2,
2883 TALLOC_CTX *mem_ctx)
2887 if (*pinfo2->comment == '\0') {
2888 p = lp_comment(snum);
2890 p = pinfo2->comment;
2893 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2896 /*******************************************************************
2897 * fill a notify_info_data with the comment
2898 * location = "Room 1, floor 2, building 3"
2899 ********************************************************************/
2901 static void spoolss_notify_location(struct messaging_context *msg_ctx,
2903 struct spoolss_Notify *data,
2904 print_queue_struct *queue,
2905 struct spoolss_PrinterInfo2 *pinfo2,
2906 TALLOC_CTX *mem_ctx)
2908 const char *loc = pinfo2->location;
2911 status = printer_list_get_printer(mem_ctx,
2916 if (NT_STATUS_IS_OK(status)) {
2918 loc = pinfo2->location;
2922 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, loc);
2925 /*******************************************************************
2926 * fill a notify_info_data with the device mode
2927 * jfm:xxxx don't to it for know but that's a real problem !!!
2928 ********************************************************************/
2930 static void spoolss_notify_devmode(struct messaging_context *msg_ctx,
2932 struct spoolss_Notify *data,
2933 print_queue_struct *queue,
2934 struct spoolss_PrinterInfo2 *pinfo2,
2935 TALLOC_CTX *mem_ctx)
2937 /* for a dummy implementation we have to zero the fields */
2938 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2941 /*******************************************************************
2942 * fill a notify_info_data with the separator file name
2943 ********************************************************************/
2945 static void spoolss_notify_sepfile(struct messaging_context *msg_ctx,
2947 struct spoolss_Notify *data,
2948 print_queue_struct *queue,
2949 struct spoolss_PrinterInfo2 *pinfo2,
2950 TALLOC_CTX *mem_ctx)
2952 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2955 /*******************************************************************
2956 * fill a notify_info_data with the print processor
2957 * jfm:xxxx return always winprint to indicate we don't do anything to it
2958 ********************************************************************/
2960 static void spoolss_notify_print_processor(struct messaging_context *msg_ctx,
2962 struct spoolss_Notify *data,
2963 print_queue_struct *queue,
2964 struct spoolss_PrinterInfo2 *pinfo2,
2965 TALLOC_CTX *mem_ctx)
2967 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2970 /*******************************************************************
2971 * fill a notify_info_data with the print processor options
2972 * jfm:xxxx send an empty string
2973 ********************************************************************/
2975 static void spoolss_notify_parameters(struct messaging_context *msg_ctx,
2977 struct spoolss_Notify *data,
2978 print_queue_struct *queue,
2979 struct spoolss_PrinterInfo2 *pinfo2,
2980 TALLOC_CTX *mem_ctx)
2982 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2985 /*******************************************************************
2986 * fill a notify_info_data with the data type
2987 * jfm:xxxx always send RAW as data type
2988 ********************************************************************/
2990 static void spoolss_notify_datatype(struct messaging_context *msg_ctx,
2992 struct spoolss_Notify *data,
2993 print_queue_struct *queue,
2994 struct spoolss_PrinterInfo2 *pinfo2,
2995 TALLOC_CTX *mem_ctx)
2997 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
3000 /*******************************************************************
3001 * fill a notify_info_data with the security descriptor
3002 * jfm:xxxx send an null pointer to say no security desc
3003 * have to implement security before !
3004 ********************************************************************/
3006 static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
3008 struct spoolss_Notify *data,
3009 print_queue_struct *queue,
3010 struct spoolss_PrinterInfo2 *pinfo2,
3011 TALLOC_CTX *mem_ctx)
3013 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
3016 /*******************************************************************
3017 * fill a notify_info_data with the attributes
3018 * jfm:xxxx a samba printer is always shared
3019 ********************************************************************/
3021 static void spoolss_notify_attributes(struct messaging_context *msg_ctx,
3023 struct spoolss_Notify *data,
3024 print_queue_struct *queue,
3025 struct spoolss_PrinterInfo2 *pinfo2,
3026 TALLOC_CTX *mem_ctx)
3028 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
3031 /*******************************************************************
3032 * fill a notify_info_data with the priority
3033 ********************************************************************/
3035 static void spoolss_notify_priority(struct messaging_context *msg_ctx,
3037 struct spoolss_Notify *data,
3038 print_queue_struct *queue,
3039 struct spoolss_PrinterInfo2 *pinfo2,
3040 TALLOC_CTX *mem_ctx)
3042 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
3045 /*******************************************************************
3046 * fill a notify_info_data with the default priority
3047 ********************************************************************/
3049 static void spoolss_notify_default_priority(struct messaging_context *msg_ctx,
3051 struct spoolss_Notify *data,
3052 print_queue_struct *queue,
3053 struct spoolss_PrinterInfo2 *pinfo2,
3054 TALLOC_CTX *mem_ctx)
3056 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
3059 /*******************************************************************
3060 * fill a notify_info_data with the start time
3061 ********************************************************************/
3063 static void spoolss_notify_start_time(struct messaging_context *msg_ctx,
3065 struct spoolss_Notify *data,
3066 print_queue_struct *queue,
3067 struct spoolss_PrinterInfo2 *pinfo2,
3068 TALLOC_CTX *mem_ctx)
3070 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
3073 /*******************************************************************
3074 * fill a notify_info_data with the until time
3075 ********************************************************************/
3077 static void spoolss_notify_until_time(struct messaging_context *msg_ctx,
3079 struct spoolss_Notify *data,
3080 print_queue_struct *queue,
3081 struct spoolss_PrinterInfo2 *pinfo2,
3082 TALLOC_CTX *mem_ctx)
3084 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
3087 /*******************************************************************
3088 * fill a notify_info_data with the status
3089 ********************************************************************/
3091 static void spoolss_notify_status(struct messaging_context *msg_ctx,
3093 struct spoolss_Notify *data,
3094 print_queue_struct *queue,
3095 struct spoolss_PrinterInfo2 *pinfo2,
3096 TALLOC_CTX *mem_ctx)
3098 print_status_struct status;
3100 print_queue_length(msg_ctx, snum, &status);
3101 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3104 /*******************************************************************
3105 * fill a notify_info_data with the number of jobs queued
3106 ********************************************************************/
3108 static void spoolss_notify_cjobs(struct messaging_context *msg_ctx,
3110 struct spoolss_Notify *data,
3111 print_queue_struct *queue,
3112 struct spoolss_PrinterInfo2 *pinfo2,
3113 TALLOC_CTX *mem_ctx)
3115 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3116 data, print_queue_length(msg_ctx, snum, NULL));
3119 /*******************************************************************
3120 * fill a notify_info_data with the average ppm
3121 ********************************************************************/
3123 static void spoolss_notify_average_ppm(struct messaging_context *msg_ctx,
3125 struct spoolss_Notify *data,
3126 print_queue_struct *queue,
3127 struct spoolss_PrinterInfo2 *pinfo2,
3128 TALLOC_CTX *mem_ctx)
3130 /* always respond 8 pages per minutes */
3131 /* a little hard ! */
3132 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
3135 /*******************************************************************
3136 * fill a notify_info_data with username
3137 ********************************************************************/
3139 static void spoolss_notify_username(struct messaging_context *msg_ctx,
3141 struct spoolss_Notify *data,
3142 print_queue_struct *queue,
3143 struct spoolss_PrinterInfo2 *pinfo2,
3144 TALLOC_CTX *mem_ctx)
3146 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3149 /*******************************************************************
3150 * fill a notify_info_data with job status
3151 ********************************************************************/
3153 static void spoolss_notify_job_status(struct messaging_context *msg_ctx,
3155 struct spoolss_Notify *data,
3156 print_queue_struct *queue,
3157 struct spoolss_PrinterInfo2 *pinfo2,
3158 TALLOC_CTX *mem_ctx)
3160 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3163 /*******************************************************************
3164 * fill a notify_info_data with job name
3165 ********************************************************************/
3167 static void spoolss_notify_job_name(struct messaging_context *msg_ctx,
3169 struct spoolss_Notify *data,
3170 print_queue_struct *queue,
3171 struct spoolss_PrinterInfo2 *pinfo2,
3172 TALLOC_CTX *mem_ctx)
3174 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3177 /*******************************************************************
3178 * fill a notify_info_data with job status
3179 ********************************************************************/
3181 static void spoolss_notify_job_status_string(struct messaging_context *msg_ctx,
3183 struct spoolss_Notify *data,
3184 print_queue_struct *queue,
3185 struct spoolss_PrinterInfo2 *pinfo2,
3186 TALLOC_CTX *mem_ctx)
3189 * Now we're returning job status codes we just return a "" here. JRA.
3194 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3197 switch (queue->status) {
3202 p = ""; /* NT provides the paused string */
3211 #endif /* NO LONGER NEEDED. */
3213 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3216 /*******************************************************************
3217 * fill a notify_info_data with job time
3218 ********************************************************************/
3220 static void spoolss_notify_job_time(struct messaging_context *msg_ctx,
3222 struct spoolss_Notify *data,
3223 print_queue_struct *queue,
3224 struct spoolss_PrinterInfo2 *pinfo2,
3225 TALLOC_CTX *mem_ctx)
3227 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3230 /*******************************************************************
3231 * fill a notify_info_data with job size
3232 ********************************************************************/
3234 static void spoolss_notify_job_size(struct messaging_context *msg_ctx,
3236 struct spoolss_Notify *data,
3237 print_queue_struct *queue,
3238 struct spoolss_PrinterInfo2 *pinfo2,
3239 TALLOC_CTX *mem_ctx)
3241 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3244 /*******************************************************************
3245 * fill a notify_info_data with page info
3246 ********************************************************************/
3247 static void spoolss_notify_total_pages(struct messaging_context *msg_ctx,
3249 struct spoolss_Notify *data,
3250 print_queue_struct *queue,
3251 struct spoolss_PrinterInfo2 *pinfo2,
3252 TALLOC_CTX *mem_ctx)
3254 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3257 /*******************************************************************
3258 * fill a notify_info_data with pages printed info.
3259 ********************************************************************/
3260 static void spoolss_notify_pages_printed(struct messaging_context *msg_ctx,
3262 struct spoolss_Notify *data,
3263 print_queue_struct *queue,
3264 struct spoolss_PrinterInfo2 *pinfo2,
3265 TALLOC_CTX *mem_ctx)
3267 /* Add code when back-end tracks this */
3268 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3271 /*******************************************************************
3272 Fill a notify_info_data with job position.
3273 ********************************************************************/
3275 static void spoolss_notify_job_position(struct messaging_context *msg_ctx,
3277 struct spoolss_Notify *data,
3278 print_queue_struct *queue,
3279 struct spoolss_PrinterInfo2 *pinfo2,
3280 TALLOC_CTX *mem_ctx)
3282 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3285 /*******************************************************************
3286 Fill a notify_info_data with submitted time.
3287 ********************************************************************/
3289 static void spoolss_notify_submitted_time(struct messaging_context *msg_ctx,
3291 struct spoolss_Notify *data,
3292 print_queue_struct *queue,
3293 struct spoolss_PrinterInfo2 *pinfo2,
3294 TALLOC_CTX *mem_ctx)
3296 data->data.string.string = NULL;
3297 data->data.string.size = 0;
3299 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3300 &data->data.string.string,
3301 &data->data.string.size);
3305 struct s_notify_info_data_table
3307 enum spoolss_NotifyType type;
3310 enum spoolss_NotifyTable variable_type;
3311 void (*fn) (struct messaging_context *msg_ctx,
3312 int snum, struct spoolss_Notify *data,
3313 print_queue_struct *queue,
3314 struct spoolss_PrinterInfo2 *pinfo2,
3315 TALLOC_CTX *mem_ctx);
3318 /* A table describing the various print notification constants and
3319 whether the notification data is a pointer to a variable sized
3320 buffer, a one value uint32_t or a two value uint32_t. */
3322 static const struct s_notify_info_data_table notify_info_data_table[] =
3324 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3325 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3326 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3327 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3328 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3329 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3330 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3331 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3332 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3333 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3334 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3335 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3336 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3337 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3338 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3339 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3340 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3341 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3342 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3343 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3344 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3345 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3346 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3347 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3348 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3349 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3350 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3351 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3352 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3353 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3354 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3355 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3356 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3357 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3358 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3359 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3360 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3361 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3362 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3363 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3364 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3365 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3366 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3367 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3368 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3369 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3370 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3371 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3372 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3375 /*******************************************************************
3376 Return the variable_type of info_data structure.
3377 ********************************************************************/
3379 static enum spoolss_NotifyTable variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3384 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3385 if ( (notify_info_data_table[i].type == type) &&
3386 (notify_info_data_table[i].field == field) ) {
3387 return notify_info_data_table[i].variable_type;
3391 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3393 return (enum spoolss_NotifyTable) 0;
3396 /****************************************************************************
3397 ****************************************************************************/
3399 static bool search_notify(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 notify_info_data_table[i].fn != NULL) {
3417 /****************************************************************************
3418 ****************************************************************************/
3420 static void construct_info_data(struct spoolss_Notify *info_data,
3421 enum spoolss_NotifyType type,
3422 uint16_t field, int id)
3424 info_data->type = type;
3425 info_data->field.field = field;
3426 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3427 info_data->job_id = id;
3430 /*******************************************************************
3432 * fill a notify_info struct with info asked
3434 ********************************************************************/
3436 static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
3437 struct printer_handle *print_hnd,
3438 struct spoolss_NotifyInfo *info,
3439 struct spoolss_PrinterInfo2 *pinfo2,
3441 const struct spoolss_NotifyOptionType *option_type,
3443 TALLOC_CTX *mem_ctx)
3446 enum spoolss_NotifyType type;
3449 struct spoolss_Notify *current_data;
3451 type = option_type->type;
3453 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3454 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3455 option_type->count, lp_servicename(snum)));
3457 for(field_num=0; field_num < option_type->count; field_num++) {
3458 field = option_type->fields[field_num].field;
3460 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3462 if (!search_notify(type, field, &j) )
3465 info->notifies = talloc_realloc(info, info->notifies,
3466 struct spoolss_Notify,
3468 if (info->notifies == NULL) {
3469 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3473 current_data = &info->notifies[info->count];
3475 construct_info_data(current_data, type, field, id);
3477 DEBUG(10, ("construct_notify_printer_info: "
3478 "calling [%s] snum=%d printername=[%s])\n",
3479 notify_info_data_table[j].name, snum,
3480 pinfo2->printername));
3482 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3483 NULL, pinfo2, mem_ctx);
3491 /*******************************************************************
3493 * fill a notify_info struct with info asked
3495 ********************************************************************/
3497 static bool construct_notify_jobs_info(struct messaging_context *msg_ctx,
3498 print_queue_struct *queue,
3499 struct spoolss_NotifyInfo *info,
3500 struct spoolss_PrinterInfo2 *pinfo2,
3502 const struct spoolss_NotifyOptionType *option_type,
3504 TALLOC_CTX *mem_ctx)
3507 enum spoolss_NotifyType type;
3509 struct spoolss_Notify *current_data;
3511 DEBUG(4,("construct_notify_jobs_info\n"));
3513 type = option_type->type;
3515 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3516 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3517 option_type->count));
3519 for(field_num=0; field_num<option_type->count; field_num++) {
3520 field = option_type->fields[field_num].field;
3522 if (!search_notify(type, field, &j) )
3525 info->notifies = talloc_realloc(info, info->notifies,
3526 struct spoolss_Notify,
3528 if (info->notifies == NULL) {
3529 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3533 current_data=&(info->notifies[info->count]);
3535 construct_info_data(current_data, type, field, id);
3536 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3537 queue, pinfo2, mem_ctx);
3545 * JFM: The enumeration is not that simple, it's even non obvious.
3547 * let's take an example: I want to monitor the PRINTER SERVER for
3548 * the printer's name and the number of jobs currently queued.
3549 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3550 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3552 * I have 3 printers on the back of my server.
3554 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3557 * 1 printer 1 name 1
3558 * 2 printer 1 cjob 1
3559 * 3 printer 2 name 2
3560 * 4 printer 2 cjob 2
3561 * 5 printer 3 name 3
3562 * 6 printer 3 name 3
3564 * that's the print server case, the printer case is even worse.
3567 /*******************************************************************
3569 * enumerate all printers on the printserver
3570 * fill a notify_info struct with info asked
3572 ********************************************************************/
3574 static WERROR printserver_notify_info(struct pipes_struct *p,
3575 struct policy_handle *hnd,
3576 struct spoolss_NotifyInfo *info,
3577 TALLOC_CTX *mem_ctx)
3580 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3581 int n_services=lp_numservices();
3583 struct spoolss_NotifyOption *option;
3584 struct spoolss_NotifyOptionType option_type;
3585 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3588 DEBUG(4,("printserver_notify_info\n"));
3593 option = Printer->notify.option;
3596 info->notifies = NULL;
3599 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3600 sending a ffpcn() request first */
3605 for (i=0; i<option->count; i++) {
3606 option_type = option->types[i];
3608 if (option_type.type != PRINTER_NOTIFY_TYPE)
3611 for (snum = 0; snum < n_services; snum++) {
3612 if (!lp_browseable(snum) ||
3613 !lp_snum_ok(snum) ||
3614 !lp_print_ok(snum)) {
3615 continue; /* skip */
3618 /* Maybe we should use the SYSTEM session_info here... */
3619 result = winreg_get_printer(mem_ctx,
3620 get_session_info_system(),
3622 lp_servicename(snum),
3624 if (!W_ERROR_IS_OK(result)) {
3625 DEBUG(4, ("printserver_notify_info: "
3626 "Failed to get printer [%s]\n",
3627 lp_servicename(snum)));
3632 construct_notify_printer_info(p->msg_ctx,
3638 TALLOC_FREE(pinfo2);
3644 * Debugging information, don't delete.
3647 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3648 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3649 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3651 for (i=0; i<info->count; i++) {
3652 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3653 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3654 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3661 /*******************************************************************
3663 * fill a notify_info struct with info asked
3665 ********************************************************************/
3667 static WERROR printer_notify_info(struct pipes_struct *p,
3668 struct policy_handle *hnd,
3669 struct spoolss_NotifyInfo *info,
3670 TALLOC_CTX *mem_ctx)
3673 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3676 struct spoolss_NotifyOption *option;
3677 struct spoolss_NotifyOptionType option_type;
3679 print_queue_struct *queue=NULL;
3680 print_status_struct status;
3681 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3684 DEBUG(4,("printer_notify_info\n"));
3689 option = Printer->notify.option;
3693 info->notifies = NULL;
3696 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3697 sending a ffpcn() request first */
3702 if (!get_printer_snum(p, hnd, &snum, NULL)) {
3706 /* Maybe we should use the SYSTEM session_info here... */
3707 result = winreg_get_printer(mem_ctx,
3708 get_session_info_system(),
3710 lp_servicename(snum), &pinfo2);
3711 if (!W_ERROR_IS_OK(result)) {
3715 for (i=0; i<option->count; i++) {
3716 option_type = option->types[i];
3718 switch (option_type.type) {
3719 case PRINTER_NOTIFY_TYPE:
3720 if (construct_notify_printer_info(p->msg_ctx,
3729 case JOB_NOTIFY_TYPE:
3731 count = print_queue_status(p->msg_ctx, snum, &queue,
3734 for (j=0; j<count; j++) {
3735 construct_notify_jobs_info(p->msg_ctx,
3749 * Debugging information, don't delete.
3752 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3753 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3754 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3756 for (i=0; i<info->count; i++) {
3757 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3758 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3759 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3763 talloc_free(pinfo2);
3767 /****************************************************************
3768 _spoolss_RouterRefreshPrinterChangeNotify
3769 ****************************************************************/
3771 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3772 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3774 struct spoolss_NotifyInfo *info;
3776 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
3777 WERROR result = WERR_BADFID;
3779 /* we always have a spoolss_NotifyInfo struct */
3780 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3782 result = WERR_NOMEM;
3786 *r->out.info = info;
3789 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3790 "Invalid handle (%s:%u:%u).\n",
3791 OUR_HANDLE(r->in.handle)));
3795 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3798 * We are now using the change value, and
3799 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3800 * I don't have a global notification system, I'm sending back all the
3801 * information even when _NOTHING_ has changed.
3804 /* We need to keep track of the change value to send back in
3805 RRPCN replies otherwise our updates are ignored. */
3807 Printer->notify.fnpcn = true;
3809 if (Printer->notify.cli_chan != NULL &&
3810 Printer->notify.cli_chan->active_connections > 0) {
3811 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3812 "Saving change value in request [%x]\n",
3814 Printer->notify.change = r->in.change_low;
3817 /* just ignore the spoolss_NotifyOption */
3819 switch (Printer->printer_type) {
3821 result = printserver_notify_info(p, r->in.handle,
3825 case SPLHND_PRINTER:
3826 result = printer_notify_info(p, r->in.handle,
3831 Printer->notify.fnpcn = false;
3837 /********************************************************************
3838 ********************************************************************/
3840 static WERROR create_printername(TALLOC_CTX *mem_ctx,
3841 const char *servername,
3842 const char *printername,
3843 const char **printername_p)
3845 /* FIXME: add lp_force_printername() */
3847 if (servername == NULL) {
3848 *printername_p = talloc_strdup(mem_ctx, printername);
3849 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3853 if (servername[0] == '\\' && servername[1] == '\\') {
3857 *printername_p = talloc_asprintf(mem_ctx, "\\\\%s\\%s", servername, printername);
3858 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3863 /********************************************************************
3864 ********************************************************************/
3866 static void compose_devicemode_devicename(struct spoolss_DeviceMode *dm,
3867 const char *printername)
3873 dm->devicename = talloc_strndup(dm, printername,
3874 MIN(strlen(printername), 31));
3877 /********************************************************************
3878 * construct_printer_info_0
3879 * fill a printer_info_0 struct
3880 ********************************************************************/
3882 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3883 const struct auth_serversupplied_info *session_info,
3884 struct messaging_context *msg_ctx,
3885 struct spoolss_PrinterInfo2 *info2,
3886 const char *servername,
3887 struct spoolss_PrinterInfo0 *r,
3891 struct printer_session_counter *session_counter;
3892 struct timeval setuptime;
3893 print_status_struct status;
3896 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3897 if (!W_ERROR_IS_OK(result)) {
3902 r->servername = talloc_strdup(mem_ctx, servername);
3903 W_ERROR_HAVE_NO_MEMORY(r->servername);
3905 r->servername = NULL;
3908 count = print_queue_length(msg_ctx, snum, &status);
3910 /* check if we already have a counter for this printer */
3911 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3912 if (session_counter->snum == snum)
3916 /* it's the first time, add it to the list */
3917 if (session_counter == NULL) {
3918 session_counter = talloc_zero(counter_list, struct printer_session_counter);
3919 W_ERROR_HAVE_NO_MEMORY(session_counter);
3920 session_counter->snum = snum;
3921 session_counter->counter = 0;
3922 DLIST_ADD(counter_list, session_counter);
3926 session_counter->counter++;
3932 get_startup_time(&setuptime);
3933 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3936 * the global_counter should be stored in a TDB as it's common to all the clients
3937 * and should be zeroed on samba startup
3939 r->global_counter = session_counter->counter;
3941 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3942 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3943 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3944 r->free_build = SPOOLSS_RELEASE_BUILD;
3946 r->max_spooling = 0;
3947 r->session_counter = session_counter->counter;
3948 r->num_error_out_of_paper = 0x0;
3949 r->num_error_not_ready = 0x0; /* number of print failure */
3951 r->number_of_processors = 0x1;
3952 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3953 r->high_part_total_bytes = 0x0;
3955 /* ChangeID in milliseconds*/
3956 winreg_printer_get_changeid(mem_ctx, session_info, msg_ctx,
3957 info2->sharename, &r->change_id);
3959 r->last_error = WERR_OK;
3960 r->status = nt_printq_status(status.status);
3961 r->enumerate_network_printers = 0x0;
3962 r->c_setprinter = 0x0;
3963 r->processor_architecture = PROCESSOR_ARCHITECTURE_INTEL;
3964 r->processor_level = 0x6; /* 6 ???*/
3973 /********************************************************************
3974 * construct_printer_info1
3975 * fill a spoolss_PrinterInfo1 struct
3976 ********************************************************************/
3978 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3979 const struct spoolss_PrinterInfo2 *info2,
3981 const char *servername,
3982 struct spoolss_PrinterInfo1 *r,
3989 if (info2->comment == NULL || info2->comment[0] == '\0') {
3990 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3992 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3994 W_ERROR_HAVE_NO_MEMORY(r->comment);
3996 result = create_printername(mem_ctx, servername, info2->printername, &r->name);
3997 if (!W_ERROR_IS_OK(result)) {
4001 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
4005 W_ERROR_HAVE_NO_MEMORY(r->description);
4010 /********************************************************************
4011 * construct_printer_info2
4012 * fill a spoolss_PrinterInfo2 struct
4013 ********************************************************************/
4015 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
4016 struct messaging_context *msg_ctx,
4017 const struct spoolss_PrinterInfo2 *info2,
4018 const char *servername,
4019 struct spoolss_PrinterInfo2 *r,
4023 print_status_struct status;
4026 count = print_queue_length(msg_ctx, snum, &status);
4029 r->servername = talloc_strdup(mem_ctx, servername);
4030 W_ERROR_HAVE_NO_MEMORY(r->servername);
4032 r->servername = NULL;
4035 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4036 if (!W_ERROR_IS_OK(result)) {
4040 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
4041 W_ERROR_HAVE_NO_MEMORY(r->sharename);
4042 r->portname = talloc_strdup(mem_ctx, info2->portname);
4043 W_ERROR_HAVE_NO_MEMORY(r->portname);
4044 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
4045 W_ERROR_HAVE_NO_MEMORY(r->drivername);
4047 if (info2->comment[0] == '\0') {
4048 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
4050 r->comment = talloc_strdup(mem_ctx, info2->comment);
4052 W_ERROR_HAVE_NO_MEMORY(r->comment);
4054 r->location = talloc_strdup(mem_ctx, info2->location);
4055 if (info2->location[0] == '\0') {
4056 const char *loc = NULL;
4059 nt_status = printer_list_get_printer(mem_ctx,
4064 if (NT_STATUS_IS_OK(nt_status)) {
4066 r->location = talloc_strdup(mem_ctx, loc);
4070 W_ERROR_HAVE_NO_MEMORY(r->location);
4072 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
4073 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
4074 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
4075 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
4076 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
4077 W_ERROR_HAVE_NO_MEMORY(r->datatype);
4078 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
4079 W_ERROR_HAVE_NO_MEMORY(r->parameters);
4081 r->attributes = info2->attributes;
4083 r->priority = info2->priority;
4084 r->defaultpriority = info2->defaultpriority;
4085 r->starttime = info2->starttime;
4086 r->untiltime = info2->untiltime;
4087 r->status = nt_printq_status(status.status);
4089 r->averageppm = info2->averageppm;
4091 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
4093 DEBUG(8,("Returning NULL Devicemode!\n"));
4096 compose_devicemode_devicename(r->devmode, r->printername);
4100 if (info2->secdesc != NULL) {
4101 /* don't use talloc_steal() here unless you do a deep steal of all
4102 the SEC_DESC members */
4104 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4110 /********************************************************************
4111 * construct_printer_info3
4112 * fill a spoolss_PrinterInfo3 struct
4113 ********************************************************************/
4115 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
4116 const struct spoolss_PrinterInfo2 *info2,
4117 const char *servername,
4118 struct spoolss_PrinterInfo3 *r,
4121 /* These are the components of the SD we are returning. */
4123 if (info2->secdesc != NULL) {
4124 /* don't use talloc_steal() here unless you do a deep steal of all
4125 the SEC_DESC members */
4127 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4128 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
4134 /********************************************************************
4135 * construct_printer_info4
4136 * fill a spoolss_PrinterInfo4 struct
4137 ********************************************************************/
4139 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4140 const struct spoolss_PrinterInfo2 *info2,
4141 const char *servername,
4142 struct spoolss_PrinterInfo4 *r,
4147 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4148 if (!W_ERROR_IS_OK(result)) {
4153 r->servername = talloc_strdup(mem_ctx, servername);
4154 W_ERROR_HAVE_NO_MEMORY(r->servername);
4156 r->servername = NULL;
4159 r->attributes = info2->attributes;
4164 /********************************************************************
4165 * construct_printer_info5
4166 * fill a spoolss_PrinterInfo5 struct
4167 ********************************************************************/
4169 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4170 const struct spoolss_PrinterInfo2 *info2,
4171 const char *servername,
4172 struct spoolss_PrinterInfo5 *r,
4177 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4178 if (!W_ERROR_IS_OK(result)) {
4182 r->portname = talloc_strdup(mem_ctx, info2->portname);
4183 W_ERROR_HAVE_NO_MEMORY(r->portname);
4185 r->attributes = info2->attributes;
4187 /* these two are not used by NT+ according to MSDN */
4188 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4189 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4194 /********************************************************************
4195 * construct_printer_info_6
4196 * fill a spoolss_PrinterInfo6 struct
4197 ********************************************************************/
4199 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4200 struct messaging_context *msg_ctx,
4201 const struct spoolss_PrinterInfo2 *info2,
4202 const char *servername,
4203 struct spoolss_PrinterInfo6 *r,
4206 print_status_struct status;
4208 print_queue_length(msg_ctx, snum, &status);
4210 r->status = nt_printq_status(status.status);
4215 /********************************************************************
4216 * construct_printer_info7
4217 * fill a spoolss_PrinterInfo7 struct
4218 ********************************************************************/
4220 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4221 struct messaging_context *msg_ctx,
4222 const char *servername,
4223 struct spoolss_PrinterInfo7 *r,
4226 struct auth_serversupplied_info *session_info;
4230 status = make_session_info_system(mem_ctx, &session_info);
4231 if (!NT_STATUS_IS_OK(status)) {
4232 DEBUG(0, ("construct_printer_info7: "
4233 "Could not create system session_info\n"));
4237 if (is_printer_published(mem_ctx, session_info, msg_ctx,
4239 lp_servicename(snum), &guid, NULL)) {
4240 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4241 r->action = DSPRINT_PUBLISH;
4243 r->guid = talloc_strdup(mem_ctx, "");
4244 r->action = DSPRINT_UNPUBLISH;
4246 W_ERROR_HAVE_NO_MEMORY(r->guid);
4248 TALLOC_FREE(session_info);
4252 /********************************************************************
4253 * construct_printer_info8
4254 * fill a spoolss_PrinterInfo8 struct
4255 ********************************************************************/
4257 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4258 const struct spoolss_PrinterInfo2 *info2,
4259 const char *servername,
4260 struct spoolss_DeviceModeInfo *r,
4264 const char *printername;
4266 result = create_printername(mem_ctx, servername, info2->printername, &printername);
4267 if (!W_ERROR_IS_OK(result)) {
4271 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
4273 DEBUG(8,("Returning NULL Devicemode!\n"));
4276 compose_devicemode_devicename(r->devmode, printername);
4282 /********************************************************************
4283 ********************************************************************/
4285 static bool snum_is_shared_printer(int snum)
4287 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4290 /********************************************************************
4291 Spoolss_enumprinters.
4292 ********************************************************************/
4294 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4295 const struct auth_serversupplied_info *session_info,
4296 struct messaging_context *msg_ctx,
4297 const char *servername,
4300 union spoolss_PrinterInfo **info_p,
4304 int n_services = lp_numservices();
4305 union spoolss_PrinterInfo *info = NULL;
4307 WERROR result = WERR_OK;
4312 for (snum = 0; snum < n_services; snum++) {
4314 const char *printer;
4315 struct spoolss_PrinterInfo2 *info2;
4317 if (!snum_is_shared_printer(snum)) {
4321 printer = lp_const_servicename(snum);
4323 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4326 result = winreg_create_printer(mem_ctx,
4330 if (!W_ERROR_IS_OK(result)) {
4334 info = talloc_realloc(mem_ctx, info,
4335 union spoolss_PrinterInfo,
4338 result = WERR_NOMEM;
4342 result = winreg_get_printer(mem_ctx, session_info, msg_ctx,
4344 if (!W_ERROR_IS_OK(result)) {
4350 result = construct_printer_info0(info, session_info,
4353 &info[count].info0, snum);
4356 result = construct_printer_info1(info, info2, flags,
4358 &info[count].info1, snum);
4361 result = construct_printer_info2(info, msg_ctx, info2,
4363 &info[count].info2, snum);
4366 result = construct_printer_info4(info, info2,
4368 &info[count].info4, snum);
4371 result = construct_printer_info5(info, info2,
4373 &info[count].info5, snum);
4377 result = WERR_UNKNOWN_LEVEL;
4381 if (!W_ERROR_IS_OK(result)) {
4392 if (!W_ERROR_IS_OK(result)) {
4402 /********************************************************************
4403 * handle enumeration of printers at level 0
4404 ********************************************************************/
4406 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4407 const struct auth_serversupplied_info *session_info,
4408 struct messaging_context *msg_ctx,
4410 const char *servername,
4411 union spoolss_PrinterInfo **info,
4414 DEBUG(4,("enum_all_printers_info_0\n"));
4416 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4417 servername, 0, flags, info, count);
4421 /********************************************************************
4422 ********************************************************************/
4424 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4425 const struct auth_serversupplied_info *session_info,
4426 struct messaging_context *msg_ctx,
4427 const char *servername,
4429 union spoolss_PrinterInfo **info,
4432 DEBUG(4,("enum_all_printers_info_1\n"));
4434 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4435 servername, 1, flags, info, count);
4438 /********************************************************************
4439 enum_all_printers_info_1_local.
4440 *********************************************************************/
4442 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4443 const struct auth_serversupplied_info *session_info,
4444 struct messaging_context *msg_ctx,
4445 const char *servername,
4446 union spoolss_PrinterInfo **info,
4449 DEBUG(4,("enum_all_printers_info_1_local\n"));
4451 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4452 servername, PRINTER_ENUM_ICON8, info, count);
4455 /********************************************************************
4456 enum_all_printers_info_1_name.
4457 *********************************************************************/
4459 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4460 const struct auth_serversupplied_info *session_info,
4461 struct messaging_context *msg_ctx,
4462 const char *servername,
4463 union spoolss_PrinterInfo **info,
4466 const char *s = servername;
4468 DEBUG(4,("enum_all_printers_info_1_name\n"));
4470 if ((servername[0] == '\\') && (servername[1] == '\\')) {
4474 if (!is_myname_or_ipaddr(s)) {
4475 return WERR_INVALID_NAME;
4478 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4479 servername, PRINTER_ENUM_ICON8, info, count);
4482 /********************************************************************
4483 enum_all_printers_info_1_network.
4484 *********************************************************************/
4486 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4487 const struct auth_serversupplied_info *session_info,
4488 struct messaging_context *msg_ctx,
4489 const char *servername,
4490 union spoolss_PrinterInfo **info,
4493 const char *s = servername;
4495 DEBUG(4,("enum_all_printers_info_1_network\n"));
4497 /* If we respond to a enum_printers level 1 on our name with flags
4498 set to PRINTER_ENUM_REMOTE with a list of printers then these
4499 printers incorrectly appear in the APW browse list.
4500 Specifically the printers for the server appear at the workgroup
4501 level where all the other servers in the domain are
4502 listed. Windows responds to this call with a
4503 WERR_CAN_NOT_COMPLETE so we should do the same. */
4505 if (servername[0] == '\\' && servername[1] == '\\') {
4509 if (is_myname_or_ipaddr(s)) {
4510 return WERR_CAN_NOT_COMPLETE;
4513 return enum_all_printers_info_1(mem_ctx, session_info, msg_ctx,
4514 servername, PRINTER_ENUM_NAME, info, count);
4517 /********************************************************************
4518 * api_spoolss_enumprinters
4520 * called from api_spoolss_enumprinters (see this to understand)
4521 ********************************************************************/
4523 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4524 const struct auth_serversupplied_info *session_info,
4525 struct messaging_context *msg_ctx,
4526 const char *servername,
4527 union spoolss_PrinterInfo **info,
4530 DEBUG(4,("enum_all_printers_info_2\n"));
4532 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4533 servername, 2, 0, info, count);
4536 /********************************************************************
4537 * handle enumeration of printers at level 1
4538 ********************************************************************/
4540 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4541 const struct auth_serversupplied_info *session_info,
4542 struct messaging_context *msg_ctx,
4544 const char *servername,
4545 union spoolss_PrinterInfo **info,
4548 /* Not all the flags are equals */
4550 if (flags & PRINTER_ENUM_LOCAL) {
4551 return enum_all_printers_info_1_local(mem_ctx, session_info,
4552 msg_ctx, servername, info, count);
4555 if (flags & PRINTER_ENUM_NAME) {
4556 return enum_all_printers_info_1_name(mem_ctx, session_info,
4557 msg_ctx, servername, info,
4561 if (flags & PRINTER_ENUM_NETWORK) {
4562 return enum_all_printers_info_1_network(mem_ctx, session_info,
4563 msg_ctx, servername, info,
4567 return WERR_OK; /* NT4sp5 does that */
4570 /********************************************************************
4571 * handle enumeration of printers at level 2
4572 ********************************************************************/
4574 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4575 const struct auth_serversupplied_info *session_info,
4576 struct messaging_context *msg_ctx,
4578 const char *servername,
4579 union spoolss_PrinterInfo **info,
4582 if (flags & PRINTER_ENUM_LOCAL) {
4584 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4589 if (flags & PRINTER_ENUM_NAME) {
4590 if (servername && !is_myname_or_ipaddr(canon_servername(servername))) {
4591 return WERR_INVALID_NAME;
4594 return enum_all_printers_info_2(mem_ctx, session_info, msg_ctx,
4599 if (flags & PRINTER_ENUM_REMOTE) {
4600 return WERR_UNKNOWN_LEVEL;
4606 /********************************************************************
4607 * handle enumeration of printers at level 4
4608 ********************************************************************/
4610 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4611 const struct auth_serversupplied_info *session_info,
4612 struct messaging_context *msg_ctx,
4614 const char *servername,
4615 union spoolss_PrinterInfo **info,
4618 DEBUG(4,("enum_all_printers_info_4\n"));
4620 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4621 servername, 4, flags, info, count);
4625 /********************************************************************
4626 * handle enumeration of printers at level 5
4627 ********************************************************************/
4629 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4630 const struct auth_serversupplied_info *session_info,
4631 struct messaging_context *msg_ctx,
4633 const char *servername,
4634 union spoolss_PrinterInfo **info,
4637 DEBUG(4,("enum_all_printers_info_5\n"));
4639 return enum_all_printers_info_level(mem_ctx, session_info, msg_ctx,
4640 servername, 5, flags, info, count);
4643 /****************************************************************
4644 _spoolss_EnumPrinters
4645 ****************************************************************/
4647 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4648 struct spoolss_EnumPrinters *r)
4650 const struct auth_serversupplied_info *session_info = get_session_info_system();
4653 /* that's an [in out] buffer */
4655 if (!r->in.buffer && (r->in.offered != 0)) {
4656 return WERR_INVALID_PARAM;
4659 DEBUG(4,("_spoolss_EnumPrinters\n"));
4663 *r->out.info = NULL;
4667 * flags==PRINTER_ENUM_NAME
4668 * if name=="" then enumerates all printers
4669 * if name!="" then enumerate the printer
4670 * flags==PRINTER_ENUM_REMOTE
4671 * name is NULL, enumerate printers
4672 * Level 2: name!="" enumerates printers, name can't be NULL
4673 * Level 3: doesn't exist
4674 * Level 4: does a local registry lookup
4675 * Level 5: same as Level 2
4678 if (r->in.server && r->in.server[0] == '\0') {
4679 r->in.server = NULL;
4682 switch (r->in.level) {
4684 result = enumprinters_level0(p->mem_ctx, session_info,
4685 p->msg_ctx, r->in.flags,
4687 r->out.info, r->out.count);
4690 result = enumprinters_level1(p->mem_ctx, session_info,
4691 p->msg_ctx, r->in.flags,
4693 r->out.info, r->out.count);
4696 result = enumprinters_level2(p->mem_ctx, session_info,
4697 p->msg_ctx, r->in.flags,
4699 r->out.info, r->out.count);
4702 result = enumprinters_level4(p->mem_ctx, session_info,
4703 p->msg_ctx, r->in.flags,
4705 r->out.info, r->out.count);
4708 result = enumprinters_level5(p->mem_ctx, session_info,
4709 p->msg_ctx, r->in.flags,
4711 r->out.info, r->out.count);
4714 return WERR_UNKNOWN_LEVEL;
4717 if (!W_ERROR_IS_OK(result)) {
4721 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4722 spoolss_EnumPrinters,
4723 *r->out.info, r->in.level,
4725 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4726 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4728 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4731 /****************************************************************
4733 ****************************************************************/
4735 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4736 struct spoolss_GetPrinter *r)
4738 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
4739 struct spoolss_PrinterInfo2 *info2 = NULL;
4740 WERROR result = WERR_OK;
4743 /* that's an [in out] buffer */
4745 if (!r->in.buffer && (r->in.offered != 0)) {
4746 return WERR_INVALID_PARAM;
4751 if (Printer == NULL) {
4755 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4759 result = winreg_get_printer(p->mem_ctx,
4760 get_session_info_system(),
4762 lp_const_servicename(snum),
4764 if (!W_ERROR_IS_OK(result)) {
4768 switch (r->in.level) {
4770 result = construct_printer_info0(p->mem_ctx,
4771 get_session_info_system(),
4774 Printer->servername,
4775 &r->out.info->info0,
4779 result = construct_printer_info1(p->mem_ctx, info2,
4781 Printer->servername,
4782 &r->out.info->info1, snum);
4785 result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
4786 Printer->servername,
4787 &r->out.info->info2, snum);
4790 result = construct_printer_info3(p->mem_ctx, info2,
4791 Printer->servername,
4792 &r->out.info->info3, snum);
4795 result = construct_printer_info4(p->mem_ctx, info2,
4796 Printer->servername,
4797 &r->out.info->info4, snum);
4800 result = construct_printer_info5(p->mem_ctx, info2,
4801 Printer->servername,
4802 &r->out.info->info5, snum);
4805 result = construct_printer_info6(p->mem_ctx, p->msg_ctx, info2,
4806 Printer->servername,
4807 &r->out.info->info6, snum);
4810 result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
4811 Printer->servername,
4812 &r->out.info->info7, snum);
4815 result = construct_printer_info8(p->mem_ctx, info2,
4816 Printer->servername,
4817 &r->out.info->info8, snum);
4820 result = WERR_UNKNOWN_LEVEL;
4825 if (!W_ERROR_IS_OK(result)) {
4826 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4827 r->in.level, win_errstr(result)));
4828 TALLOC_FREE(r->out.info);
4832 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4833 r->out.info, r->in.level);
4834 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4836 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4839 /********************************************************************
4840 ********************************************************************/
4842 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4844 if (in && strlen(in)) { \
4845 out = talloc_strdup(mem_ctx, in); \
4847 out = talloc_strdup(mem_ctx, ""); \
4849 W_ERROR_HAVE_NO_MEMORY(out); \
4852 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4854 if (in && strlen(in)) { \
4855 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4857 out = talloc_strdup(mem_ctx, ""); \
4859 W_ERROR_HAVE_NO_MEMORY(out); \
4862 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4863 const char **string_array,
4864 const char ***presult,
4865 const char *cservername,
4869 int i, num_strings = 0;
4870 const char **array = NULL;
4872 if (string_array == NULL) {
4873 return WERR_INVALID_PARAMETER;
4876 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4877 const char *str = NULL;
4879 if (cservername == NULL || arch == NULL) {
4880 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4882 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4885 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4892 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4893 &array, &num_strings);
4903 /********************************************************************
4904 * fill a spoolss_DriverInfo1 struct
4905 ********************************************************************/
4907 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4908 struct spoolss_DriverInfo1 *r,
4909 const struct spoolss_DriverInfo8 *driver,
4910 const char *servername)
4912 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4913 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4918 /********************************************************************
4919 * fill a spoolss_DriverInfo2 struct
4920 ********************************************************************/
4922 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4923 struct spoolss_DriverInfo2 *r,
4924 const struct spoolss_DriverInfo8 *driver,
4925 const char *servername)
4928 const char *cservername = canon_servername(servername);
4930 r->version = driver->version;
4932 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4933 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4934 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4935 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4937 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4938 driver->architecture,
4940 driver->driver_path,
4943 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4944 driver->architecture,
4949 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4950 driver->architecture,
4952 driver->config_file,
4958 /********************************************************************
4959 * fill a spoolss_DriverInfo3 struct
4960 ********************************************************************/
4962 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4963 struct spoolss_DriverInfo3 *r,
4964 const struct spoolss_DriverInfo8 *driver,
4965 const char *servername)
4967 const char *cservername = canon_servername(servername);
4969 r->version = driver->version;
4971 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4972 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4973 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4974 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4976 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4977 driver->architecture,
4979 driver->driver_path,
4982 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4983 driver->architecture,
4988 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4989 driver->architecture,
4991 driver->config_file,
4994 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4995 driver->architecture,
5000 FILL_DRIVER_STRING(mem_ctx,
5001 driver->monitor_name,
5004 FILL_DRIVER_STRING(mem_ctx,
5005 driver->default_datatype,
5006 r->default_datatype);
5008 return string_array_from_driver_info(mem_ctx,
5009 driver->dependent_files,
5010 &r->dependent_files,
5012 driver->architecture,
5016 /********************************************************************
5017 * fill a spoolss_DriverInfo4 struct
5018 ********************************************************************/
5020 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
5021 struct spoolss_DriverInfo4 *r,
5022 const struct spoolss_DriverInfo8 *driver,
5023 const char *servername)
5025 const char *cservername = canon_servername(servername);
5028 r->version = driver->version;
5030 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5031 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5032 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5033 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5035 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5036 driver->architecture,
5038 driver->driver_path,
5041 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5042 driver->architecture,
5047 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5048 driver->architecture,
5050 driver->config_file,
5053 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5054 driver->architecture,
5059 result = string_array_from_driver_info(mem_ctx,
5060 driver->dependent_files,
5061 &r->dependent_files,
5063 driver->architecture,
5065 if (!W_ERROR_IS_OK(result)) {
5069 FILL_DRIVER_STRING(mem_ctx,
5070 driver->monitor_name,
5073 FILL_DRIVER_STRING(mem_ctx,
5074 driver->default_datatype,
5075 r->default_datatype);
5078 result = string_array_from_driver_info(mem_ctx,
5079 driver->previous_names,
5086 /********************************************************************
5087 * fill a spoolss_DriverInfo5 struct
5088 ********************************************************************/
5090 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
5091 struct spoolss_DriverInfo5 *r,
5092 const struct spoolss_DriverInfo8 *driver,
5093 const char *servername)
5095 const char *cservername = canon_servername(servername);
5097 r->version = driver->version;
5099 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5100 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5101 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5102 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5104 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5105 driver->architecture,
5107 driver->driver_path,
5110 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5111 driver->architecture,
5116 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5117 driver->architecture,
5119 driver->config_file,
5122 r->driver_attributes = 0;
5123 r->config_version = 0;
5124 r->driver_version = 0;
5128 /********************************************************************
5129 * fill a spoolss_DriverInfo6 struct
5130 ********************************************************************/
5132 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
5133 struct spoolss_DriverInfo6 *r,
5134 const struct spoolss_DriverInfo8 *driver,
5135 const char *servername)
5137 const char *cservername = canon_servername(servername);
5140 r->version = driver->version;
5142 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5143 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5144 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5145 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5147 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5148 driver->architecture,
5150 driver->driver_path,
5153 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5154 driver->architecture,
5159 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5160 driver->architecture,
5162 driver->config_file,
5165 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5166 driver->architecture,
5171 FILL_DRIVER_STRING(mem_ctx,
5172 driver->monitor_name,
5175 FILL_DRIVER_STRING(mem_ctx,
5176 driver->default_datatype,
5177 r->default_datatype);
5179 result = string_array_from_driver_info(mem_ctx,
5180 driver->dependent_files,
5181 &r->dependent_files,
5183 driver->architecture,
5185 if (!W_ERROR_IS_OK(result)) {
5189 result = string_array_from_driver_info(mem_ctx,
5190 driver->previous_names,
5193 if (!W_ERROR_IS_OK(result)) {
5197 r->driver_date = driver->driver_date;
5198 r->driver_version = driver->driver_version;
5200 FILL_DRIVER_STRING(mem_ctx,
5201 driver->manufacturer_name,
5202 r->manufacturer_name);
5203 FILL_DRIVER_STRING(mem_ctx,
5204 driver->manufacturer_url,
5205 r->manufacturer_url);
5206 FILL_DRIVER_STRING(mem_ctx,
5207 driver->hardware_id,
5209 FILL_DRIVER_STRING(mem_ctx,
5216 /********************************************************************
5217 * fill a spoolss_DriverInfo8 struct
5218 ********************************************************************/
5220 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
5221 struct spoolss_DriverInfo8 *r,
5222 const struct spoolss_DriverInfo8 *driver,
5223 const char *servername)
5225 const char *cservername = canon_servername(servername);
5228 r->version = driver->version;
5230 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5231 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5232 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5233 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5235 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5236 driver->architecture,
5238 driver->driver_path,
5241 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5242 driver->architecture,
5247 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5248 driver->architecture,
5250 driver->config_file,
5253 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5254 driver->architecture,
5259 FILL_DRIVER_STRING(mem_ctx,
5260 driver->monitor_name,
5263 FILL_DRIVER_STRING(mem_ctx,
5264 driver->default_datatype,
5265 r->default_datatype);
5267 result = string_array_from_driver_info(mem_ctx,
5268 driver->dependent_files,
5269 &r->dependent_files,
5271 driver->architecture,
5273 if (!W_ERROR_IS_OK(result)) {
5277 result = string_array_from_driver_info(mem_ctx,
5278 driver->previous_names,
5281 if (!W_ERROR_IS_OK(result)) {
5285 r->driver_date = driver->driver_date;
5286 r->driver_version = driver->driver_version;
5288 FILL_DRIVER_STRING(mem_ctx,
5289 driver->manufacturer_name,
5290 r->manufacturer_name);
5291 FILL_DRIVER_STRING(mem_ctx,
5292 driver->manufacturer_url,
5293 r->manufacturer_url);
5294 FILL_DRIVER_STRING(mem_ctx,
5295 driver->hardware_id,
5297 FILL_DRIVER_STRING(mem_ctx,
5301 FILL_DRIVER_STRING(mem_ctx,
5302 driver->print_processor,
5303 r->print_processor);
5304 FILL_DRIVER_STRING(mem_ctx,
5305 driver->vendor_setup,
5308 result = string_array_from_driver_info(mem_ctx,
5309 driver->color_profiles,
5312 if (!W_ERROR_IS_OK(result)) {
5316 FILL_DRIVER_STRING(mem_ctx,
5320 r->printer_driver_attributes = driver->printer_driver_attributes;
5322 result = string_array_from_driver_info(mem_ctx,
5323 driver->core_driver_dependencies,
5324 &r->core_driver_dependencies,
5326 if (!W_ERROR_IS_OK(result)) {
5330 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
5331 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
5336 #if 0 /* disabled until marshalling issues are resolved - gd */
5337 /********************************************************************
5338 ********************************************************************/
5340 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5341 struct spoolss_DriverFileInfo *r,
5342 const char *cservername,
5343 const char *file_name,
5344 enum spoolss_DriverFileType file_type,
5345 uint32_t file_version)
5347 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5348 cservername, file_name);
5349 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5350 r->file_type = file_type;
5351 r->file_version = file_version;
5356 /********************************************************************
5357 ********************************************************************/
5359 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5360 const struct spoolss_DriverInfo8 *driver,
5361 const char *cservername,
5362 struct spoolss_DriverFileInfo **info_p,
5365 struct spoolss_DriverFileInfo *info = NULL;
5373 if (strlen(driver->driver_path)) {
5374 info = talloc_realloc(mem_ctx, info,
5375 struct spoolss_DriverFileInfo,
5377 W_ERROR_HAVE_NO_MEMORY(info);
5378 result = fill_spoolss_DriverFileInfo(info,
5381 driver->driver_path,
5382 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5384 W_ERROR_NOT_OK_RETURN(result);
5388 if (strlen(driver->config_file)) {
5389 info = talloc_realloc(mem_ctx, info,
5390 struct spoolss_DriverFileInfo,
5392 W_ERROR_HAVE_NO_MEMORY(info);
5393 result = fill_spoolss_DriverFileInfo(info,
5396 driver->config_file,
5397 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5399 W_ERROR_NOT_OK_RETURN(result);
5403 if (strlen(driver->data_file)) {
5404 info = talloc_realloc(mem_ctx, info,
5405 struct spoolss_DriverFileInfo,
5407 W_ERROR_HAVE_NO_MEMORY(info);
5408 result = fill_spoolss_DriverFileInfo(info,
5412 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5414 W_ERROR_NOT_OK_RETURN(result);
5418 if (strlen(driver->help_file)) {
5419 info = talloc_realloc(mem_ctx, info,
5420 struct spoolss_DriverFileInfo,
5422 W_ERROR_HAVE_NO_MEMORY(info);
5423 result = fill_spoolss_DriverFileInfo(info,
5427 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5429 W_ERROR_NOT_OK_RETURN(result);
5433 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
5434 info = talloc_realloc(mem_ctx, info,
5435 struct spoolss_DriverFileInfo,
5437 W_ERROR_HAVE_NO_MEMORY(info);
5438 result = fill_spoolss_DriverFileInfo(info,
5441 driver->dependent_files[i],
5442 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5444 W_ERROR_NOT_OK_RETURN(result);
5454 /********************************************************************
5455 * fill a spoolss_DriverInfo101 struct
5456 ********************************************************************/
5458 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5459 struct spoolss_DriverInfo101 *r,
5460 const struct spoolss_DriverInfo8 *driver,
5461 const char *servername)
5463 const char *cservername = canon_servername(servername);
5466 r->version = driver->version;
5468 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5469 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5470 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5471 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5473 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5477 if (!W_ERROR_IS_OK(result)) {
5481 FILL_DRIVER_STRING(mem_ctx,
5482 driver->monitor_name,
5485 FILL_DRIVER_STRING(mem_ctx,
5486 driver->default_datatype,
5487 r->default_datatype);
5489 result = string_array_from_driver_info(mem_ctx,
5490 driver->previous_names,
5493 if (!W_ERROR_IS_OK(result)) {
5497 r->driver_date = driver->driver_date;
5498 r->driver_version = driver->driver_version;
5500 FILL_DRIVER_STRING(mem_ctx,
5501 driver->manufacturer_name,
5502 r->manufacturer_name);
5503 FILL_DRIVER_STRING(mem_ctx,
5504 driver->manufacturer_url,
5505 r->manufacturer_url);
5506 FILL_DRIVER_STRING(mem_ctx,
5507 driver->hardware_id,
5509 FILL_DRIVER_STRING(mem_ctx,
5516 /********************************************************************
5517 ********************************************************************/
5519 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5520 const struct auth_serversupplied_info *session_info,
5521 struct messaging_context *msg_ctx,
5523 union spoolss_DriverInfo *r,
5525 const char *servername,
5526 const char *architecture,
5529 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5530 struct spoolss_DriverInfo8 *driver;
5534 return WERR_UNKNOWN_LEVEL;
5537 result = winreg_get_printer(mem_ctx,
5540 lp_const_servicename(snum),
5543 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5544 win_errstr(result)));
5546 if (!W_ERROR_IS_OK(result)) {
5547 return WERR_INVALID_PRINTER_NAME;
5550 result = winreg_get_driver(mem_ctx, session_info, msg_ctx,
5552 pinfo2->drivername, version, &driver);
5554 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5555 win_errstr(result)));
5557 if (!W_ERROR_IS_OK(result)) {
5559 * Is this a W2k client ?
5563 talloc_free(pinfo2);
5564 return WERR_UNKNOWN_PRINTER_DRIVER;
5567 /* Yes - try again with a WinNT driver. */
5569 result = winreg_get_driver(mem_ctx, session_info, msg_ctx,
5573 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5574 win_errstr(result)));
5575 if (!W_ERROR_IS_OK(result)) {
5576 talloc_free(pinfo2);
5577 return WERR_UNKNOWN_PRINTER_DRIVER;
5583 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5586 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5589 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5592 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5595 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5598 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5601 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5603 #if 0 /* disabled until marshalling issues are resolved - gd */
5605 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5609 result = WERR_UNKNOWN_LEVEL;
5613 talloc_free(pinfo2);
5614 talloc_free(driver);
5619 /****************************************************************
5620 _spoolss_GetPrinterDriver2
5621 ****************************************************************/
5623 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5624 struct spoolss_GetPrinterDriver2 *r)
5626 struct printer_handle *printer;
5631 /* that's an [in out] buffer */
5633 if (!r->in.buffer && (r->in.offered != 0)) {
5634 return WERR_INVALID_PARAM;
5637 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5639 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5640 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5641 return WERR_INVALID_PRINTER_NAME;
5645 *r->out.server_major_version = 0;
5646 *r->out.server_minor_version = 0;
5648 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5652 result = construct_printer_driver_info_level(p->mem_ctx,
5653 get_session_info_system(),
5655 r->in.level, r->out.info,
5656 snum, printer->servername,
5658 r->in.client_major_version);
5659 if (!W_ERROR_IS_OK(result)) {
5660 TALLOC_FREE(r->out.info);
5664 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5665 r->out.info, r->in.level);
5666 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5668 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5672 /****************************************************************
5673 _spoolss_StartPagePrinter
5674 ****************************************************************/
5676 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5677 struct spoolss_StartPagePrinter *r)
5679 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5682 DEBUG(3,("_spoolss_StartPagePrinter: "
5683 "Error in startpageprinter printer handle\n"));
5687 Printer->page_started = true;
5691 /****************************************************************
5692 _spoolss_EndPagePrinter
5693 ****************************************************************/
5695 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5696 struct spoolss_EndPagePrinter *r)
5700 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5703 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5704 OUR_HANDLE(r->in.handle)));
5708 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5711 Printer->page_started = false;
5712 print_job_endpage(p->msg_ctx, snum, Printer->jobid);
5717 /****************************************************************
5718 _spoolss_StartDocPrinter
5719 ****************************************************************/
5721 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5722 struct spoolss_StartDocPrinter *r)
5724 struct spoolss_DocumentInfo1 *info_1;
5726 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5732 DEBUG(2,("_spoolss_StartDocPrinter: "
5733 "Invalid handle (%s:%u:%u)\n",
5734 OUR_HANDLE(r->in.handle)));
5738 if (Printer->jobid) {
5739 DEBUG(2, ("_spoolss_StartDocPrinter: "
5740 "StartDocPrinter called twice! "
5741 "(existing jobid = %d)\n", Printer->jobid));
5742 return WERR_INVALID_HANDLE;
5745 if (r->in.level != 1) {
5746 return WERR_UNKNOWN_LEVEL;
5749 info_1 = r->in.info.info1;
5752 * a nice thing with NT is it doesn't listen to what you tell it.
5753 * when asked to send _only_ RAW datas, it tries to send datas
5756 * So I add checks like in NT Server ...
5759 if (info_1->datatype) {
5760 if (strcmp(info_1->datatype, "RAW") != 0) {
5762 return WERR_INVALID_DATATYPE;
5766 /* get the share number of the printer */
5767 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5771 rc = get_remote_hostname(p->remote_address,
5777 if (strequal(rhost,"UNKNOWN")) {
5778 rhost = tsocket_address_inet_addr_string(p->remote_address,
5780 if (rhost == NULL) {
5785 werr = print_job_start(p->session_info,
5789 info_1->document_name,
5790 info_1->output_file,
5794 /* An error occured in print_job_start() so return an appropriate
5797 if (!W_ERROR_IS_OK(werr)) {
5801 Printer->document_started = true;
5802 *r->out.job_id = Printer->jobid;
5807 /****************************************************************
5808 _spoolss_EndDocPrinter
5809 ****************************************************************/
5811 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5812 struct spoolss_EndDocPrinter *r)
5814 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5819 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5820 OUR_HANDLE(r->in.handle)));
5824 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5828 Printer->document_started = false;
5829 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5830 if (!NT_STATUS_IS_OK(status)) {
5831 DEBUG(2, ("_spoolss_EndDocPrinter: "
5832 "print_job_end failed [%s]\n",
5833 nt_errstr(status)));
5837 return ntstatus_to_werror(status);
5840 /****************************************************************
5841 _spoolss_WritePrinter
5842 ****************************************************************/
5844 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5845 struct spoolss_WritePrinter *r)
5847 ssize_t buffer_written;
5849 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5852 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5853 OUR_HANDLE(r->in.handle)));
5854 *r->out.num_written = r->in._data_size;
5858 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5861 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5862 buffer_written = print_job_write(server_event_context(),p->msg_ctx,
5863 snum, Printer->jobid,
5864 (const char *)r->in.data.data,
5865 (size_t)r->in._data_size);
5866 if (buffer_written == (ssize_t)-1) {
5867 *r->out.num_written = 0;
5868 if (errno == ENOSPC)
5869 return WERR_NO_SPOOL_SPACE;
5871 return WERR_ACCESS_DENIED;
5874 *r->out.num_written = r->in._data_size;
5879 /********************************************************************
5880 * api_spoolss_getprinter
5881 * called from the spoolss dispatcher
5883 ********************************************************************/
5885 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5886 struct pipes_struct *p)
5888 const struct auth_serversupplied_info *session_info = p->session_info;
5890 WERROR errcode = WERR_BADFUNC;
5891 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5894 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5895 OUR_HANDLE(handle)));
5899 if (!get_printer_snum(p, handle, &snum, NULL))
5903 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5904 errcode = print_queue_pause(session_info, p->msg_ctx, snum);
5906 case SPOOLSS_PRINTER_CONTROL_RESUME:
5907 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5908 errcode = print_queue_resume(session_info, p->msg_ctx, snum);
5910 case SPOOLSS_PRINTER_CONTROL_PURGE:
5911 errcode = print_queue_purge(session_info, p->msg_ctx, snum);
5914 return WERR_UNKNOWN_LEVEL;
5921 /****************************************************************
5922 _spoolss_AbortPrinter
5923 * From MSDN: "Deletes printer's spool file if printer is configured
5925 ****************************************************************/
5927 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5928 struct spoolss_AbortPrinter *r)
5930 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5932 WERROR errcode = WERR_OK;
5935 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5936 OUR_HANDLE(r->in.handle)));
5940 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5943 if (!Printer->document_started) {
5944 return WERR_SPL_NO_STARTDOC;
5947 errcode = print_job_delete(p->session_info,
5955 /********************************************************************
5956 * called by spoolss_api_setprinter
5957 * when updating a printer description
5958 ********************************************************************/
5960 static WERROR update_printer_sec(struct policy_handle *handle,
5961 struct pipes_struct *p,
5962 struct sec_desc_buf *secdesc_ctr)
5964 struct spoolss_security_descriptor *new_secdesc = NULL;
5965 struct spoolss_security_descriptor *old_secdesc = NULL;
5966 const char *printer;
5970 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5972 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5973 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5974 OUR_HANDLE(handle)));
5976 result = WERR_BADFID;
5980 if (secdesc_ctr == NULL) {
5981 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5982 result = WERR_INVALID_PARAM;
5985 printer = lp_const_servicename(snum);
5987 /* Check the user has permissions to change the security
5988 descriptor. By experimentation with two NT machines, the user
5989 requires Full Access to the printer to change security
5992 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5993 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5994 result = WERR_ACCESS_DENIED;
5998 /* NT seems to like setting the security descriptor even though
5999 nothing may have actually changed. */
6000 result = winreg_get_printer_secdesc(p->mem_ctx,
6001 get_session_info_system(),
6005 if (!W_ERROR_IS_OK(result)) {
6006 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
6007 result = WERR_BADFID;
6011 if (DEBUGLEVEL >= 10) {
6012 struct security_acl *the_acl;
6015 the_acl = old_secdesc->dacl;
6016 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
6017 printer, the_acl->num_aces));
6019 for (i = 0; i < the_acl->num_aces; i++) {
6020 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6021 &the_acl->aces[i].trustee),
6022 the_acl->aces[i].access_mask));
6025 the_acl = secdesc_ctr->sd->dacl;
6028 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
6029 printer, the_acl->num_aces));
6031 for (i = 0; i < the_acl->num_aces; i++) {
6032 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6033 &the_acl->aces[i].trustee),
6034 the_acl->aces[i].access_mask));
6037 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
6041 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
6042 if (new_secdesc == NULL) {
6043 result = WERR_NOMEM;
6047 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
6052 result = winreg_set_printer_secdesc(p->mem_ctx,
6053 get_session_info_system(),
6062 /********************************************************************
6063 Canonicalize printer info from a client
6064 ********************************************************************/
6066 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
6067 struct spoolss_SetPrinterInfo2 *info2,
6070 fstring printername;
6073 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
6074 "portname=%s drivername=%s comment=%s location=%s\n",
6075 info2->servername, info2->printername, info2->sharename,
6076 info2->portname, info2->drivername, info2->comment,
6079 /* we force some elements to "correct" values */
6080 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", lp_netbios_name());
6081 if (info2->servername == NULL) {
6084 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
6085 if (info2->sharename == NULL) {
6089 /* check to see if we allow printername != sharename */
6090 if (lp_force_printername(snum)) {
6091 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6092 lp_netbios_name(), info2->sharename);
6094 /* make sure printername is in \\server\printername format */
6095 fstrcpy(printername, info2->printername);
6097 if ( printername[0] == '\\' && printername[1] == '\\' ) {
6098 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
6102 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6103 lp_netbios_name(), p);
6105 if (info2->printername == NULL) {
6109 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
6110 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
6115 /****************************************************************************
6116 ****************************************************************************/
6118 static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const char *portname, const char *uri)
6120 char *cmd = lp_addport_cmd();
6121 char *command = NULL;
6123 bool is_print_op = false;
6126 return WERR_ACCESS_DENIED;
6129 command = talloc_asprintf(ctx,
6130 "%s \"%s\" \"%s\"", cmd, portname, uri );
6136 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6138 DEBUG(10,("Running [%s]\n", command));
6140 /********* BEGIN SePrintOperatorPrivilege **********/
6145 ret = smbrun(command, NULL);
6150 /********* END SePrintOperatorPrivilege **********/
6152 DEBUGADD(10,("returned [%d]\n", ret));
6154 TALLOC_FREE(command);
6157 return WERR_ACCESS_DENIED;
6163 /****************************************************************************
6164 ****************************************************************************/
6166 static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
6167 struct spoolss_SetPrinterInfo2 *info2,
6168 const char *remote_machine,
6169 struct messaging_context *msg_ctx)
6171 char *cmd = lp_addprinter_cmd();
6173 char *command = NULL;
6177 bool is_print_op = false;
6179 if (!remote_machine) {
6183 command = talloc_asprintf(ctx,
6184 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6185 cmd, info2->printername, info2->sharename,
6186 info2->portname, info2->drivername,
6187 info2->location, info2->comment, remote_machine);
6193 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6195 DEBUG(10,("Running [%s]\n", command));
6197 /********* BEGIN SePrintOperatorPrivilege **********/
6202 if ( (ret = smbrun(command, &fd)) == 0 ) {
6203 /* Tell everyone we updated smb.conf. */
6204 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6210 /********* END SePrintOperatorPrivilege **********/
6212 DEBUGADD(10,("returned [%d]\n", ret));
6214 TALLOC_FREE(command);
6222 /* reload our services immediately */
6224 reload_services(msg_ctx, -1, false);
6228 /* Get lines and convert them back to dos-codepage */
6229 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6230 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6233 /* Set the portname to what the script says the portname should be. */
6234 /* but don't require anything to be return from the script exit a good error code */
6237 /* Set the portname to what the script says the portname should be. */
6238 info2->portname = talloc_strdup(ctx, qlines[0]);
6239 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6242 TALLOC_FREE(qlines);
6246 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
6247 const struct auth_serversupplied_info *session_info,
6248 struct messaging_context *msg_ctx,
6250 struct spoolss_SetPrinterInfo2 *printer,
6251 struct spoolss_PrinterInfo2 *old_printer)
6253 bool force_update = (old_printer == NULL);
6254 const char *dnsdomname;
6255 const char *longname;
6256 const char *uncname;
6257 const char *spooling;
6259 WERROR result = WERR_OK;
6261 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
6262 push_reg_sz(mem_ctx, &buffer, printer->drivername);
6263 winreg_set_printer_dataex(mem_ctx,
6267 SPOOL_DSSPOOLER_KEY,
6268 SPOOL_REG_DRIVERNAME,
6273 if (!force_update) {
6274 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6275 printer->drivername));
6277 notify_printer_driver(server_event_context(), msg_ctx,
6278 snum, printer->drivername ?
6279 printer->drivername : "");
6283 if (force_update || !strequal(printer->comment, old_printer->comment)) {
6284 push_reg_sz(mem_ctx, &buffer, printer->comment);
6285 winreg_set_printer_dataex(mem_ctx,
6289 SPOOL_DSSPOOLER_KEY,
6290 SPOOL_REG_DESCRIPTION,
6295 if (!force_update) {
6296 notify_printer_comment(server_event_context(), msg_ctx,
6297 snum, printer->comment ?
6298 printer->comment : "");
6302 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
6303 push_reg_sz(mem_ctx, &buffer, printer->sharename);
6304 winreg_set_printer_dataex(mem_ctx,
6308 SPOOL_DSSPOOLER_KEY,
6309 SPOOL_REG_PRINTSHARENAME,
6314 if (!force_update) {
6315 notify_printer_sharename(server_event_context(),
6317 snum, printer->sharename ?
6318 printer->sharename : "");
6322 if (force_update || !strequal(printer->printername, old_printer->printername)) {
6325 p = strrchr(printer->printername, '\\' );
6329 p = printer->printername;
6332 push_reg_sz(mem_ctx, &buffer, p);
6333 winreg_set_printer_dataex(mem_ctx,
6337 SPOOL_DSSPOOLER_KEY,
6338 SPOOL_REG_PRINTERNAME,
6343 if (!force_update) {
6344 notify_printer_printername(server_event_context(),
6345 msg_ctx, snum, p ? p : "");
6349 if (force_update || !strequal(printer->portname, old_printer->portname)) {
6350 push_reg_sz(mem_ctx, &buffer, printer->portname);
6351 winreg_set_printer_dataex(mem_ctx,
6355 SPOOL_DSSPOOLER_KEY,
6361 if (!force_update) {
6362 notify_printer_port(server_event_context(),
6363 msg_ctx, snum, printer->portname ?
6364 printer->portname : "");
6368 if (force_update || !strequal(printer->location, old_printer->location)) {
6369 push_reg_sz(mem_ctx, &buffer, printer->location);
6370 winreg_set_printer_dataex(mem_ctx,
6374 SPOOL_DSSPOOLER_KEY,
6380 if (!force_update) {
6381 notify_printer_location(server_event_context(),
6384 printer->location : "");
6388 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
6389 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
6390 winreg_set_printer_dataex(mem_ctx,
6394 SPOOL_DSSPOOLER_KEY,
6395 SPOOL_REG_PRINTSEPARATORFILE,
6400 if (!force_update) {
6401 notify_printer_sepfile(server_event_context(),
6404 printer->sepfile : "");
6408 if (force_update || printer->starttime != old_printer->starttime) {
6409 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6410 SIVAL(buffer.data, 0, printer->starttime);
6411 winreg_set_printer_dataex(mem_ctx,
6415 SPOOL_DSSPOOLER_KEY,
6416 SPOOL_REG_PRINTSTARTTIME,
6422 if (force_update || printer->untiltime != old_printer->untiltime) {
6423 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6424 SIVAL(buffer.data, 0, printer->untiltime);
6425 winreg_set_printer_dataex(mem_ctx,
6429 SPOOL_DSSPOOLER_KEY,
6430 SPOOL_REG_PRINTENDTIME,
6436 if (force_update || printer->priority != old_printer->priority) {
6437 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6438 SIVAL(buffer.data, 0, printer->priority);
6439 winreg_set_printer_dataex(mem_ctx,
6443 SPOOL_DSSPOOLER_KEY,
6450 if (force_update || printer->attributes != old_printer->attributes) {
6451 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6452 SIVAL(buffer.data, 0, (printer->attributes &
6453 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
6454 winreg_set_printer_dataex(mem_ctx,
6458 SPOOL_DSSPOOLER_KEY,
6459 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
6464 switch (printer->attributes & 0x3) {
6466 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
6469 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
6472 spooling = SPOOL_REGVAL_PRINTDIRECT;
6475 spooling = "unknown";
6477 push_reg_sz(mem_ctx, &buffer, spooling);
6478 winreg_set_printer_dataex(mem_ctx,
6482 SPOOL_DSSPOOLER_KEY,
6483 SPOOL_REG_PRINTSPOOLING,
6489 push_reg_sz(mem_ctx, &buffer, lp_netbios_name());
6490 winreg_set_printer_dataex(mem_ctx,
6494 SPOOL_DSSPOOLER_KEY,
6495 SPOOL_REG_SHORTSERVERNAME,
6500 dnsdomname = get_mydnsfullname();
6501 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
6502 longname = talloc_strdup(mem_ctx, dnsdomname);
6504 longname = talloc_strdup(mem_ctx, lp_netbios_name());
6506 if (longname == NULL) {
6507 result = WERR_NOMEM;
6511 push_reg_sz(mem_ctx, &buffer, longname);
6512 winreg_set_printer_dataex(mem_ctx,
6516 SPOOL_DSSPOOLER_KEY,
6517 SPOOL_REG_SERVERNAME,
6522 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6523 lp_netbios_name(), printer->sharename);
6524 push_reg_sz(mem_ctx, &buffer, uncname);
6525 winreg_set_printer_dataex(mem_ctx,
6529 SPOOL_DSSPOOLER_KEY,
6539 /********************************************************************
6540 * Called by spoolss_api_setprinter
6541 * when updating a printer description.
6542 ********************************************************************/
6544 static WERROR update_printer(struct pipes_struct *p,
6545 struct policy_handle *handle,
6546 struct spoolss_SetPrinterInfoCtr *info_ctr,
6547 struct spoolss_DeviceMode *devmode)
6549 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6550 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6551 struct spoolss_PrinterInfo2 *old_printer;
6552 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6554 WERROR result = WERR_OK;
6555 TALLOC_CTX *tmp_ctx;
6557 DEBUG(8,("update_printer\n"));
6559 tmp_ctx = talloc_new(p->mem_ctx);
6560 if (tmp_ctx == NULL) {
6565 result = WERR_BADFID;
6569 if (!get_printer_snum(p, handle, &snum, NULL)) {
6570 result = WERR_BADFID;
6574 result = winreg_get_printer(tmp_ctx,
6575 get_session_info_system(),
6577 lp_const_servicename(snum),
6579 if (!W_ERROR_IS_OK(result)) {
6580 result = WERR_BADFID;
6584 /* Do sanity check on the requested changes for Samba */
6585 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6586 result = WERR_INVALID_PARAM;
6590 /* FIXME!!! If the driver has changed we really should verify that
6591 it is installed before doing much else --jerry */
6593 /* Check calling user has permission to update printer description */
6594 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6595 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6596 result = WERR_ACCESS_DENIED;
6600 /* Call addprinter hook */
6601 /* Check changes to see if this is really needed */
6603 if (*lp_addprinter_cmd() &&
6604 (!strequal(printer->drivername, old_printer->drivername) ||
6605 !strequal(printer->comment, old_printer->comment) ||
6606 !strequal(printer->portname, old_printer->portname) ||
6607 !strequal(printer->location, old_printer->location)) )
6611 raddr = tsocket_address_inet_addr_string(p->remote_address,
6613 if (raddr == NULL) {
6617 /* add_printer_hook() will call reload_services() */
6618 if (!add_printer_hook(tmp_ctx, p->session_info->security_token,
6621 result = WERR_ACCESS_DENIED;
6626 update_dsspooler(tmp_ctx,
6627 get_session_info_system(),
6633 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6635 if (devmode == NULL) {
6636 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6638 result = winreg_update_printer(tmp_ctx,
6639 get_session_info_system(),
6648 talloc_free(tmp_ctx);
6653 /****************************************************************************
6654 ****************************************************************************/
6655 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6656 struct policy_handle *handle,
6657 struct spoolss_SetPrinterInfo7 *info7)
6660 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6663 struct printer_handle *Printer;
6665 if ( lp_security() != SEC_ADS ) {
6666 return WERR_UNKNOWN_LEVEL;
6669 Printer = find_printer_index_by_hnd(p, handle);
6671 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6676 if (!get_printer_snum(p, handle, &snum, NULL))
6679 result = winreg_get_printer(p->mem_ctx,
6680 get_session_info_system(),
6682 lp_servicename(snum),
6684 if (!W_ERROR_IS_OK(result)) {
6688 nt_printer_publish(pinfo2,
6689 get_session_info_system(),
6694 TALLOC_FREE(pinfo2);
6697 return WERR_UNKNOWN_LEVEL;
6701 /********************************************************************
6702 ********************************************************************/
6704 static WERROR update_printer_devmode(struct pipes_struct *p,
6705 struct policy_handle *handle,
6706 struct spoolss_DeviceMode *devmode)
6709 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6710 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6712 DEBUG(8,("update_printer_devmode\n"));
6718 if (!get_printer_snum(p, handle, &snum, NULL)) {
6722 /* Check calling user has permission to update printer description */
6723 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6724 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6725 return WERR_ACCESS_DENIED;
6728 return winreg_update_printer(p->mem_ctx,
6729 get_session_info_system(),
6731 lp_const_servicename(snum),
6739 /****************************************************************
6741 ****************************************************************/
6743 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6744 struct spoolss_SetPrinter *r)
6748 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6751 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6752 OUR_HANDLE(r->in.handle)));
6756 /* check the level */
6757 switch (r->in.info_ctr->level) {
6759 return control_printer(r->in.handle, r->in.command, p);
6761 result = update_printer(p, r->in.handle,
6763 r->in.devmode_ctr->devmode);
6764 if (!W_ERROR_IS_OK(result))
6766 if (r->in.secdesc_ctr->sd)
6767 result = update_printer_sec(r->in.handle, p,
6771 return update_printer_sec(r->in.handle, p,
6774 return publish_or_unpublish_printer(p, r->in.handle,
6775 r->in.info_ctr->info.info7);
6777 return update_printer_devmode(p, r->in.handle,
6778 r->in.devmode_ctr->devmode);
6780 return WERR_UNKNOWN_LEVEL;
6784 /****************************************************************
6785 _spoolss_FindClosePrinterNotify
6786 ****************************************************************/
6788 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6789 struct spoolss_FindClosePrinterNotify *r)
6791 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6794 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6795 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6799 if (Printer->notify.cli_chan != NULL &&
6800 Printer->notify.cli_chan->active_connections > 0) {
6803 if (Printer->printer_type == SPLHND_PRINTER) {
6804 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6809 srv_spoolss_replycloseprinter(snum, Printer);
6812 Printer->notify.flags=0;
6813 Printer->notify.options=0;
6814 Printer->notify.localmachine[0]='\0';
6815 Printer->notify.printerlocal=0;
6816 TALLOC_FREE(Printer->notify.option);
6821 /****************************************************************
6823 ****************************************************************/
6825 WERROR _spoolss_AddJob(struct pipes_struct *p,
6826 struct spoolss_AddJob *r)
6828 if (!r->in.buffer && (r->in.offered != 0)) {
6829 return WERR_INVALID_PARAM;
6832 /* this is what a NT server returns for AddJob. AddJob must fail on
6833 * non-local printers */
6835 if (r->in.level != 1) {
6836 return WERR_UNKNOWN_LEVEL;
6839 return WERR_INVALID_PARAM;
6842 /****************************************************************************
6844 ****************************************************************************/
6846 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6847 struct spoolss_JobInfo1 *r,
6848 const print_queue_struct *queue,
6849 int position, int snum,
6850 struct spoolss_PrinterInfo2 *pinfo2)
6854 t = gmtime(&queue->time);
6856 r->job_id = queue->job;
6858 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6859 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6860 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6861 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6862 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6863 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6864 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6865 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6866 r->data_type = talloc_strdup(mem_ctx, "RAW");
6867 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6868 r->text_status = talloc_strdup(mem_ctx, "");
6869 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6871 r->status = nt_printj_status(queue->status);
6872 r->priority = queue->priority;
6873 r->position = position;
6874 r->total_pages = queue->page_count;
6875 r->pages_printed = 0; /* ??? */
6877 init_systemtime(&r->submitted, t);
6882 /****************************************************************************
6884 ****************************************************************************/
6886 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6887 struct spoolss_JobInfo2 *r,
6888 const print_queue_struct *queue,
6889 int position, int snum,
6890 struct spoolss_PrinterInfo2 *pinfo2,
6891 struct spoolss_DeviceMode *devmode)
6895 t = gmtime(&queue->time);
6897 r->job_id = queue->job;
6899 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6900 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6901 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6902 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6903 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6904 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6905 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6906 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6907 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6908 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6909 r->data_type = talloc_strdup(mem_ctx, "RAW");
6910 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6911 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6912 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6913 r->parameters = talloc_strdup(mem_ctx, "");
6914 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6915 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6916 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6918 r->devmode = devmode;
6920 r->text_status = talloc_strdup(mem_ctx, "");
6921 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6925 r->status = nt_printj_status(queue->status);
6926 r->priority = queue->priority;
6927 r->position = position;
6930 r->total_pages = queue->page_count;
6931 r->size = queue->size;
6932 init_systemtime(&r->submitted, t);
6934 r->pages_printed = 0; /* ??? */
6939 /****************************************************************************
6941 ****************************************************************************/
6943 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6944 struct spoolss_JobInfo3 *r,
6945 const print_queue_struct *queue,
6946 const print_queue_struct *next_queue,
6947 int position, int snum,
6948 struct spoolss_PrinterInfo2 *pinfo2)
6950 r->job_id = queue->job;
6953 r->next_job_id = next_queue->job;
6960 /****************************************************************************
6961 Enumjobs at level 1.
6962 ****************************************************************************/
6964 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6965 const print_queue_struct *queue,
6966 uint32_t num_queues, int snum,
6967 struct spoolss_PrinterInfo2 *pinfo2,
6968 union spoolss_JobInfo **info_p,
6971 union spoolss_JobInfo *info;
6973 WERROR result = WERR_OK;
6975 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
6976 W_ERROR_HAVE_NO_MEMORY(info);
6978 *count = num_queues;
6980 for (i=0; i<*count; i++) {
6981 result = fill_job_info1(info,
6987 if (!W_ERROR_IS_OK(result)) {
6993 if (!W_ERROR_IS_OK(result)) {
7004 /****************************************************************************
7005 Enumjobs at level 2.
7006 ****************************************************************************/
7008 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
7009 const print_queue_struct *queue,
7010 uint32_t num_queues, int snum,
7011 struct spoolss_PrinterInfo2 *pinfo2,
7012 union spoolss_JobInfo **info_p,
7015 union spoolss_JobInfo *info;
7017 WERROR result = WERR_OK;
7019 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7020 W_ERROR_HAVE_NO_MEMORY(info);
7022 *count = num_queues;
7024 for (i=0; i<*count; i++) {
7025 struct spoolss_DeviceMode *devmode;
7027 result = spoolss_create_default_devmode(info,
7028 pinfo2->printername,
7030 if (!W_ERROR_IS_OK(result)) {
7031 DEBUG(3, ("Can't proceed w/o a devmode!"));
7035 result = fill_job_info2(info,
7042 if (!W_ERROR_IS_OK(result)) {
7048 if (!W_ERROR_IS_OK(result)) {
7059 /****************************************************************************
7060 Enumjobs at level 3.
7061 ****************************************************************************/
7063 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
7064 const print_queue_struct *queue,
7065 uint32_t num_queues, int snum,
7066 struct spoolss_PrinterInfo2 *pinfo2,
7067 union spoolss_JobInfo **info_p,
7070 union spoolss_JobInfo *info;
7072 WERROR result = WERR_OK;
7074 info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
7075 W_ERROR_HAVE_NO_MEMORY(info);
7077 *count = num_queues;
7079 for (i=0; i<*count; i++) {
7080 const print_queue_struct *next_queue = NULL;
7083 next_queue = &queue[i+1];
7086 result = fill_job_info3(info,
7093 if (!W_ERROR_IS_OK(result)) {
7099 if (!W_ERROR_IS_OK(result)) {
7110 /****************************************************************
7112 ****************************************************************/
7114 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
7115 struct spoolss_EnumJobs *r)
7118 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
7120 print_status_struct prt_status;
7121 print_queue_struct *queue = NULL;
7124 /* that's an [in out] buffer */
7126 if (!r->in.buffer && (r->in.offered != 0)) {
7127 return WERR_INVALID_PARAM;
7130 DEBUG(4,("_spoolss_EnumJobs\n"));
7134 *r->out.info = NULL;
7136 /* lookup the printer snum and tdb entry */
7138 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7142 result = winreg_get_printer(p->mem_ctx,
7143 get_session_info_system(),
7145 lp_const_servicename(snum),
7147 if (!W_ERROR_IS_OK(result)) {
7151 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
7152 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7153 count, prt_status.status, prt_status.message));
7157 TALLOC_FREE(pinfo2);
7161 switch (r->in.level) {
7163 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
7164 pinfo2, r->out.info, r->out.count);
7167 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
7168 pinfo2, r->out.info, r->out.count);
7171 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
7172 pinfo2, r->out.info, r->out.count);
7175 result = WERR_UNKNOWN_LEVEL;
7180 TALLOC_FREE(pinfo2);
7182 if (!W_ERROR_IS_OK(result)) {
7186 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7188 *r->out.info, r->in.level,
7190 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7191 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7193 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7196 /****************************************************************
7197 _spoolss_ScheduleJob
7198 ****************************************************************/
7200 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
7201 struct spoolss_ScheduleJob *r)
7206 /****************************************************************
7207 ****************************************************************/
7209 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
7210 struct messaging_context *msg_ctx,
7211 const char *printer_name,
7213 struct spoolss_SetJobInfo1 *r)
7217 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
7221 if (strequal(old_doc_name, r->document_name)) {
7225 if (!print_job_set_name(server_event_context(), msg_ctx,
7226 printer_name, job_id, r->document_name)) {
7233 /****************************************************************
7235 ****************************************************************/
7237 WERROR _spoolss_SetJob(struct pipes_struct *p,
7238 struct spoolss_SetJob *r)
7240 const struct auth_serversupplied_info *session_info = p->session_info;
7242 WERROR errcode = WERR_BADFUNC;
7244 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7248 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
7249 return WERR_INVALID_PRINTER_NAME;
7252 switch (r->in.command) {
7253 case SPOOLSS_JOB_CONTROL_CANCEL:
7254 case SPOOLSS_JOB_CONTROL_DELETE:
7255 errcode = print_job_delete(session_info, p->msg_ctx,
7256 snum, r->in.job_id);
7257 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
7261 case SPOOLSS_JOB_CONTROL_PAUSE:
7262 if (print_job_pause(session_info, p->msg_ctx,
7263 snum, r->in.job_id, &errcode)) {
7267 case SPOOLSS_JOB_CONTROL_RESTART:
7268 case SPOOLSS_JOB_CONTROL_RESUME:
7269 if (print_job_resume(session_info, p->msg_ctx,
7270 snum, r->in.job_id, &errcode)) {
7278 return WERR_UNKNOWN_LEVEL;
7281 if (!W_ERROR_IS_OK(errcode)) {
7285 if (r->in.ctr == NULL) {
7289 switch (r->in.ctr->level) {
7291 errcode = spoolss_setjob_1(p->mem_ctx, p->msg_ctx,
7292 lp_const_servicename(snum),
7294 r->in.ctr->info.info1);
7300 return WERR_UNKNOWN_LEVEL;
7306 /****************************************************************************
7307 Enumerates all printer drivers by level and architecture.
7308 ****************************************************************************/
7310 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
7311 const struct auth_serversupplied_info *session_info,
7312 struct messaging_context *msg_ctx,
7313 const char *servername,
7314 const char *architecture,
7316 union spoolss_DriverInfo **info_p,
7321 struct spoolss_DriverInfo8 *driver;
7322 union spoolss_DriverInfo *info = NULL;
7324 WERROR result = WERR_OK;
7325 uint32_t num_drivers;
7326 const char **drivers;
7331 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7332 result = winreg_get_driver_list(mem_ctx, session_info, msg_ctx,
7333 architecture, version,
7334 &num_drivers, &drivers);
7335 if (!W_ERROR_IS_OK(result)) {
7338 DEBUG(4, ("we have:[%d] drivers in environment"
7339 " [%s] and version [%d]\n",
7340 num_drivers, architecture, version));
7342 if (num_drivers != 0) {
7343 info = talloc_realloc(mem_ctx, info,
7344 union spoolss_DriverInfo,
7345 count + num_drivers);
7347 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7348 "failed to enlarge driver info buffer!\n"));
7349 result = WERR_NOMEM;
7354 for (i = 0; i < num_drivers; i++) {
7355 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
7357 result = winreg_get_driver(mem_ctx, session_info,
7359 architecture, drivers[i],
7361 if (!W_ERROR_IS_OK(result)) {
7367 result = fill_printer_driver_info1(info, &info[count+i].info1,
7368 driver, servername);
7371 result = fill_printer_driver_info2(info, &info[count+i].info2,
7372 driver, servername);
7375 result = fill_printer_driver_info3(info, &info[count+i].info3,
7376 driver, servername);
7379 result = fill_printer_driver_info4(info, &info[count+i].info4,
7380 driver, servername);
7383 result = fill_printer_driver_info5(info, &info[count+i].info5,
7384 driver, servername);
7387 result = fill_printer_driver_info6(info, &info[count+i].info6,
7388 driver, servername);
7391 result = fill_printer_driver_info8(info, &info[count+i].info8,
7392 driver, servername);
7395 result = WERR_UNKNOWN_LEVEL;
7399 TALLOC_FREE(driver);
7401 if (!W_ERROR_IS_OK(result)) {
7406 count += num_drivers;
7407 TALLOC_FREE(drivers);
7411 TALLOC_FREE(drivers);
7413 if (!W_ERROR_IS_OK(result)) {
7424 /****************************************************************************
7425 Enumerates all printer drivers by level.
7426 ****************************************************************************/
7428 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
7429 const struct auth_serversupplied_info *session_info,
7430 struct messaging_context *msg_ctx,
7431 const char *servername,
7432 const char *architecture,
7434 union spoolss_DriverInfo **info_p,
7438 WERROR result = WERR_OK;
7440 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
7442 for (a=0; archi_table[a].long_archi != NULL; a++) {
7444 union spoolss_DriverInfo *info = NULL;
7447 result = enumprinterdrivers_level_by_architecture(mem_ctx,
7451 archi_table[a].long_archi,
7455 if (!W_ERROR_IS_OK(result)) {
7459 for (i=0; i < count; i++) {
7460 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
7461 info[i], info_p, count_p);
7468 return enumprinterdrivers_level_by_architecture(mem_ctx,
7478 /****************************************************************
7479 _spoolss_EnumPrinterDrivers
7480 ****************************************************************/
7482 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
7483 struct spoolss_EnumPrinterDrivers *r)
7485 const char *cservername;
7488 /* that's an [in out] buffer */
7490 if (!r->in.buffer && (r->in.offered != 0)) {
7491 return WERR_INVALID_PARAM;
7494 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7498 *r->out.info = NULL;
7500 cservername = canon_servername(r->in.server);
7502 if (!is_myname_or_ipaddr(cservername)) {
7503 return WERR_UNKNOWN_PRINTER_DRIVER;
7506 result = enumprinterdrivers_level(p->mem_ctx,
7507 get_session_info_system(),
7514 if (!W_ERROR_IS_OK(result)) {
7518 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7519 spoolss_EnumPrinterDrivers,
7520 *r->out.info, r->in.level,
7522 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7523 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7525 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7528 /****************************************************************
7530 ****************************************************************/
7532 WERROR _spoolss_EnumForms(struct pipes_struct *p,
7533 struct spoolss_EnumForms *r)
7539 *r->out.info = NULL;
7541 /* that's an [in out] buffer */
7543 if (!r->in.buffer && (r->in.offered != 0) ) {
7544 return WERR_INVALID_PARAM;
7547 DEBUG(4,("_spoolss_EnumForms\n"));
7548 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7549 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7551 switch (r->in.level) {
7553 result = winreg_printer_enumforms1(p->mem_ctx,
7554 get_session_info_system(),
7560 result = WERR_UNKNOWN_LEVEL;
7564 if (!W_ERROR_IS_OK(result)) {
7568 if (*r->out.count == 0) {
7569 return WERR_NO_MORE_ITEMS;
7572 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7574 *r->out.info, r->in.level,
7576 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7577 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7579 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7582 /****************************************************************
7584 ****************************************************************/
7586 WERROR _spoolss_GetForm(struct pipes_struct *p,
7587 struct spoolss_GetForm *r)
7591 /* that's an [in out] buffer */
7593 if (!r->in.buffer && (r->in.offered != 0)) {
7594 return WERR_INVALID_PARAM;
7597 DEBUG(4,("_spoolss_GetForm\n"));
7598 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7599 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7601 switch (r->in.level) {
7603 result = winreg_printer_getform1(p->mem_ctx,
7604 get_session_info_system(),
7607 &r->out.info->info1);
7610 result = WERR_UNKNOWN_LEVEL;
7614 if (!W_ERROR_IS_OK(result)) {
7615 TALLOC_FREE(r->out.info);
7619 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7620 r->out.info, r->in.level);
7621 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7623 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7626 /****************************************************************************
7627 ****************************************************************************/
7629 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7630 struct spoolss_PortInfo1 *r,
7633 r->port_name = talloc_strdup(mem_ctx, name);
7634 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7639 /****************************************************************************
7640 TODO: This probably needs distinguish between TCP/IP and Local ports
7642 ****************************************************************************/
7644 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7645 struct spoolss_PortInfo2 *r,
7648 r->port_name = talloc_strdup(mem_ctx, name);
7649 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7651 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7652 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7654 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7655 W_ERROR_HAVE_NO_MEMORY(r->description);
7657 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7664 /****************************************************************************
7665 wrapper around the enumer ports command
7666 ****************************************************************************/
7668 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7670 char *cmd = lp_enumports_cmd();
7671 char **qlines = NULL;
7672 char *command = NULL;
7680 /* if no hook then just fill in the default port */
7683 if (!(qlines = talloc_array( NULL, char*, 2 ))) {
7686 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7687 TALLOC_FREE(qlines);
7694 /* we have a valid enumport command */
7696 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7701 DEBUG(10,("Running [%s]\n", command));
7702 ret = smbrun(command, &fd);
7703 DEBUG(10,("Returned [%d]\n", ret));
7704 TALLOC_FREE(command);
7709 return WERR_ACCESS_DENIED;
7713 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7714 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7724 /****************************************************************************
7726 ****************************************************************************/
7728 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7729 union spoolss_PortInfo **info_p,
7732 union spoolss_PortInfo *info = NULL;
7734 WERROR result = WERR_OK;
7735 char **qlines = NULL;
7738 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7739 if (!W_ERROR_IS_OK(result)) {
7744 info = talloc_array(mem_ctx, union spoolss_PortInfo, numlines);
7746 DEBUG(10,("Returning WERR_NOMEM\n"));
7747 result = WERR_NOMEM;
7751 for (i=0; i<numlines; i++) {
7752 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7753 result = fill_port_1(info, &info[i].info1, qlines[i]);
7754 if (!W_ERROR_IS_OK(result)) {
7759 TALLOC_FREE(qlines);
7762 if (!W_ERROR_IS_OK(result)) {
7764 TALLOC_FREE(qlines);
7776 /****************************************************************************
7778 ****************************************************************************/
7780 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7781 union spoolss_PortInfo **info_p,
7784 union spoolss_PortInfo *info = NULL;
7786 WERROR result = WERR_OK;
7787 char **qlines = NULL;
7790 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7791 if (!W_ERROR_IS_OK(result)) {
7796 info = talloc_array(mem_ctx, union spoolss_PortInfo, numlines);
7798 DEBUG(10,("Returning WERR_NOMEM\n"));
7799 result = WERR_NOMEM;
7803 for (i=0; i<numlines; i++) {
7804 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7805 result = fill_port_2(info, &info[i].info2, qlines[i]);
7806 if (!W_ERROR_IS_OK(result)) {
7811 TALLOC_FREE(qlines);
7814 if (!W_ERROR_IS_OK(result)) {
7816 TALLOC_FREE(qlines);
7828 /****************************************************************
7830 ****************************************************************/
7832 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
7833 struct spoolss_EnumPorts *r)
7837 /* that's an [in out] buffer */
7839 if (!r->in.buffer && (r->in.offered != 0)) {
7840 return WERR_INVALID_PARAM;
7843 DEBUG(4,("_spoolss_EnumPorts\n"));
7847 *r->out.info = NULL;
7849 switch (r->in.level) {
7851 result = enumports_level_1(p->mem_ctx, r->out.info,
7855 result = enumports_level_2(p->mem_ctx, r->out.info,
7859 return WERR_UNKNOWN_LEVEL;
7862 if (!W_ERROR_IS_OK(result)) {
7866 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7868 *r->out.info, r->in.level,
7870 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7871 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7873 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7876 /****************************************************************************
7877 ****************************************************************************/
7879 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
7881 struct spoolss_SetPrinterInfoCtr *info_ctr,
7882 struct spoolss_DeviceMode *devmode,
7883 struct security_descriptor *secdesc,
7884 struct spoolss_UserLevelCtr *user_ctr,
7885 struct policy_handle *handle)
7887 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7888 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7890 WERROR err = WERR_OK;
7892 /* samba does not have a concept of local, non-shared printers yet, so
7893 * make sure we always setup sharename - gd */
7894 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7895 (info2->printername != NULL && info2->printername[0] != '\0')) {
7896 DEBUG(5, ("spoolss_addprinterex_level_2: "
7897 "no sharename has been set, setting printername %s as sharename\n",
7898 info2->printername));
7899 info2->sharename = info2->printername;
7902 /* check to see if the printer already exists */
7903 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7904 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7906 return WERR_PRINTER_ALREADY_EXISTS;
7909 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7910 if ((snum = print_queue_snum(info2->printername)) != -1) {
7911 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7912 info2->printername));
7913 return WERR_PRINTER_ALREADY_EXISTS;
7917 /* validate printer info struct */
7918 if (!info2->printername || strlen(info2->printername) == 0) {
7919 return WERR_INVALID_PRINTER_NAME;
7921 if (!info2->portname || strlen(info2->portname) == 0) {
7922 return WERR_UNKNOWN_PORT;
7924 if (!info2->drivername || strlen(info2->drivername) == 0) {
7925 return WERR_UNKNOWN_PRINTER_DRIVER;
7927 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7928 return WERR_UNKNOWN_PRINTPROCESSOR;
7931 /* FIXME!!! smbd should check to see if the driver is installed before
7932 trying to add a printer like this --jerry */
7934 if (*lp_addprinter_cmd() ) {
7937 raddr = tsocket_address_inet_addr_string(p->remote_address,
7939 if (raddr == NULL) {
7943 if ( !add_printer_hook(p->mem_ctx, p->session_info->security_token,
7946 return WERR_ACCESS_DENIED;
7949 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no "
7950 "smb.conf parameter \"addprinter command\" is defined. This "
7951 "parameter must exist for this call to succeed\n",
7952 info2->sharename ));
7955 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7956 return WERR_ACCESS_DENIED;
7959 /* you must be a printer admin to add a new printer */
7960 if (!print_access_check(p->session_info,
7963 PRINTER_ACCESS_ADMINISTER)) {
7964 return WERR_ACCESS_DENIED;
7968 * Do sanity check on the requested changes for Samba.
7971 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7972 return WERR_INVALID_PARAM;
7975 if (devmode == NULL) {
7976 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7979 update_dsspooler(p->mem_ctx,
7980 get_session_info_system(),
7986 err = winreg_update_printer(p->mem_ctx,
7987 get_session_info_system(),
7994 if (!W_ERROR_IS_OK(err)) {
7998 err = open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER);
7999 if (!W_ERROR_IS_OK(err)) {
8000 /* Handle open failed - remove addition. */
8001 ZERO_STRUCTP(handle);
8008 /****************************************************************
8009 _spoolss_AddPrinterEx
8010 ****************************************************************/
8012 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
8013 struct spoolss_AddPrinterEx *r)
8015 switch (r->in.info_ctr->level) {
8017 /* we don't handle yet */
8018 /* but I know what to do ... */
8019 return WERR_UNKNOWN_LEVEL;
8021 return spoolss_addprinterex_level_2(p, r->in.server,
8023 r->in.devmode_ctr->devmode,
8024 r->in.secdesc_ctr->sd,
8025 r->in.userlevel_ctr,
8028 return WERR_UNKNOWN_LEVEL;
8032 /****************************************************************
8034 ****************************************************************/
8036 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
8037 struct spoolss_AddPrinter *r)
8039 struct spoolss_AddPrinterEx a;
8040 struct spoolss_UserLevelCtr userlevel_ctr;
8042 ZERO_STRUCT(userlevel_ctr);
8044 userlevel_ctr.level = 1;
8046 a.in.server = r->in.server;
8047 a.in.info_ctr = r->in.info_ctr;
8048 a.in.devmode_ctr = r->in.devmode_ctr;
8049 a.in.secdesc_ctr = r->in.secdesc_ctr;
8050 a.in.userlevel_ctr = &userlevel_ctr;
8051 a.out.handle = r->out.handle;
8053 return _spoolss_AddPrinterEx(p, &a);
8056 /****************************************************************
8057 _spoolss_AddPrinterDriverEx
8058 ****************************************************************/
8060 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
8061 struct spoolss_AddPrinterDriverEx *r)
8063 WERROR err = WERR_OK;
8064 const char *driver_name = NULL;
8069 case NDR_SPOOLSS_ADDPRINTERDRIVER:
8070 fn = "_spoolss_AddPrinterDriver";
8072 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
8073 fn = "_spoolss_AddPrinterDriverEx";
8076 return WERR_INVALID_PARAM;
8080 * we only support the semantics of AddPrinterDriver()
8081 * i.e. only copy files that are newer than existing ones
8084 if (r->in.flags == 0) {
8085 return WERR_INVALID_PARAM;
8088 if (r->in.flags != APD_COPY_NEW_FILES) {
8089 return WERR_ACCESS_DENIED;
8093 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
8094 /* Clever hack from Martin Zielinski <mz@seh.de>
8095 * to allow downgrade from level 8 (Vista).
8097 DEBUG(0,("%s: level %d not yet implemented\n", fn,
8098 r->in.info_ctr->level));
8099 return WERR_UNKNOWN_LEVEL;
8102 DEBUG(5,("Cleaning driver's information\n"));
8103 err = clean_up_driver_struct(p->mem_ctx, p->session_info, r->in.info_ctr);
8104 if (!W_ERROR_IS_OK(err))
8107 DEBUG(5,("Moving driver to final destination\n"));
8108 err = move_driver_to_download_area(p->session_info, r->in.info_ctr);
8109 if (!W_ERROR_IS_OK(err)) {
8113 err = winreg_add_driver(p->mem_ctx,
8114 get_session_info_system(),
8119 if (!W_ERROR_IS_OK(err)) {
8124 * I think this is where he DrvUpgradePrinter() hook would be
8125 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8126 * server. Right now, we just need to send ourselves a message
8127 * to update each printer bound to this driver. --jerry
8130 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
8131 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8139 /****************************************************************
8140 _spoolss_AddPrinterDriver
8141 ****************************************************************/
8143 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
8144 struct spoolss_AddPrinterDriver *r)
8146 struct spoolss_AddPrinterDriverEx a;
8148 switch (r->in.info_ctr->level) {
8155 return WERR_UNKNOWN_LEVEL;
8158 a.in.servername = r->in.servername;
8159 a.in.info_ctr = r->in.info_ctr;
8160 a.in.flags = APD_COPY_NEW_FILES;
8162 return _spoolss_AddPrinterDriverEx(p, &a);
8165 /****************************************************************************
8166 ****************************************************************************/
8168 struct _spoolss_paths {
8174 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
8176 static const struct _spoolss_paths spoolss_paths[]= {
8177 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
8178 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
8181 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
8182 const char *servername,
8183 const char *environment,
8187 const char *pservername = NULL;
8188 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
8189 const char *short_archi;
8193 /* environment may be empty */
8194 if (environment && strlen(environment)) {
8195 long_archi = environment;
8198 /* servername may be empty */
8199 if (servername && strlen(servername)) {
8200 pservername = canon_servername(servername);
8202 if (!is_myname_or_ipaddr(pservername)) {
8203 return WERR_INVALID_PARAM;
8207 if (!(short_archi = get_short_archi(long_archi))) {
8208 return WERR_INVALID_ENVIRONMENT;
8211 switch (component) {
8212 case SPOOLSS_PRTPROCS_PATH:
8213 case SPOOLSS_DRIVER_PATH:
8215 *path = talloc_asprintf(mem_ctx,
8218 spoolss_paths[component].share,
8221 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
8222 SPOOLSS_DEFAULT_SERVER_PATH,
8223 spoolss_paths[component].dir,
8228 return WERR_INVALID_PARAM;
8238 /****************************************************************************
8239 ****************************************************************************/
8241 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
8242 const char *servername,
8243 const char *environment,
8244 struct spoolss_DriverDirectoryInfo1 *r)
8249 werr = compose_spoolss_server_path(mem_ctx,
8252 SPOOLSS_DRIVER_PATH,
8254 if (!W_ERROR_IS_OK(werr)) {
8258 DEBUG(4,("printer driver directory: [%s]\n", path));
8260 r->directory_name = path;
8265 /****************************************************************
8266 _spoolss_GetPrinterDriverDirectory
8267 ****************************************************************/
8269 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
8270 struct spoolss_GetPrinterDriverDirectory *r)
8274 /* that's an [in out] buffer */
8276 if (!r->in.buffer && (r->in.offered != 0)) {
8277 return WERR_INVALID_PARAM;
8280 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8285 /* r->in.level is ignored */
8287 werror = getprinterdriverdir_level_1(p->mem_ctx,
8290 &r->out.info->info1);
8291 if (!W_ERROR_IS_OK(werror)) {
8292 TALLOC_FREE(r->out.info);
8296 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
8297 r->out.info, r->in.level);
8298 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8300 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8303 /****************************************************************
8304 _spoolss_EnumPrinterData
8305 ****************************************************************/
8307 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
8308 struct spoolss_EnumPrinterData *r)
8311 struct spoolss_EnumPrinterDataEx r2;
8313 struct spoolss_PrinterEnumValues *info, *val = NULL;
8316 r2.in.handle = r->in.handle;
8317 r2.in.key_name = "PrinterDriverData";
8319 r2.out.count = &count;
8320 r2.out.info = &info;
8321 r2.out.needed = &needed;
8323 result = _spoolss_EnumPrinterDataEx(p, &r2);
8324 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8325 r2.in.offered = needed;
8326 result = _spoolss_EnumPrinterDataEx(p, &r2);
8328 if (!W_ERROR_IS_OK(result)) {
8333 * The NT machine wants to know the biggest size of value and data
8335 * cf: MSDN EnumPrinterData remark section
8338 if (!r->in.value_offered && !r->in.data_offered) {
8339 uint32_t biggest_valuesize = 0;
8340 uint32_t biggest_datasize = 0;
8343 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8345 for (i=0; i<count; i++) {
8347 name_length = strlen(info[i].value_name);
8348 if (strlen(info[i].value_name) > biggest_valuesize) {
8349 biggest_valuesize = name_length;
8352 if (info[i].data_length > biggest_datasize) {
8353 biggest_datasize = info[i].data_length;
8356 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8360 /* the value is an UNICODE string but real_value_size is the length
8361 in bytes including the trailing 0 */
8363 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8364 *r->out.data_needed = biggest_datasize;
8366 DEBUG(6,("final values: [%d], [%d]\n",
8367 *r->out.value_needed, *r->out.data_needed));
8372 if (r->in.enum_index < count) {
8373 val = &info[r->in.enum_index];
8377 /* out_value should default to "" or else NT4 has
8378 problems unmarshalling the response */
8380 if (r->in.value_offered) {
8381 *r->out.value_needed = 1;
8382 r->out.value_name = talloc_strdup(r, "");
8383 if (!r->out.value_name) {
8387 r->out.value_name = NULL;
8388 *r->out.value_needed = 0;
8391 /* the data is counted in bytes */
8393 *r->out.data_needed = r->in.data_offered;
8395 result = WERR_NO_MORE_ITEMS;
8399 * - counted in bytes in the request
8400 * - counted in UNICODE chars in the max reply
8401 * - counted in bytes in the real size
8403 * take a pause *before* coding not *during* coding
8407 if (r->in.value_offered) {
8408 r->out.value_name = talloc_strdup(r, val->value_name);
8409 if (!r->out.value_name) {
8412 *r->out.value_needed = val->value_name_len;
8414 r->out.value_name = NULL;
8415 *r->out.value_needed = 0;
8420 *r->out.type = val->type;
8422 /* data - counted in bytes */
8425 * See the section "Dynamically Typed Query Parameters"
8429 if (r->out.data && val->data && val->data->data &&
8430 val->data_length && r->in.data_offered) {
8431 memcpy(r->out.data, val->data->data,
8432 MIN(val->data_length,r->in.data_offered));
8435 *r->out.data_needed = val->data_length;
8443 /****************************************************************
8444 _spoolss_SetPrinterData
8445 ****************************************************************/
8447 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
8448 struct spoolss_SetPrinterData *r)
8450 struct spoolss_SetPrinterDataEx r2;
8452 r2.in.handle = r->in.handle;
8453 r2.in.key_name = "PrinterDriverData";
8454 r2.in.value_name = r->in.value_name;
8455 r2.in.type = r->in.type;
8456 r2.in.data = r->in.data;
8457 r2.in.offered = r->in.offered;
8459 return _spoolss_SetPrinterDataEx(p, &r2);
8462 /****************************************************************
8463 _spoolss_ResetPrinter
8464 ****************************************************************/
8466 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
8467 struct spoolss_ResetPrinter *r)
8469 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8472 DEBUG(5,("_spoolss_ResetPrinter\n"));
8475 * All we do is to check to see if the handle and queue is valid.
8476 * This call really doesn't mean anything to us because we only
8477 * support RAW printing. --jerry
8481 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8482 OUR_HANDLE(r->in.handle)));
8486 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8490 /* blindly return success */
8494 /****************************************************************
8495 _spoolss_DeletePrinterData
8496 ****************************************************************/
8498 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
8499 struct spoolss_DeletePrinterData *r)
8501 struct spoolss_DeletePrinterDataEx r2;
8503 r2.in.handle = r->in.handle;
8504 r2.in.key_name = "PrinterDriverData";
8505 r2.in.value_name = r->in.value_name;
8507 return _spoolss_DeletePrinterDataEx(p, &r2);
8510 /****************************************************************
8512 ****************************************************************/
8514 WERROR _spoolss_AddForm(struct pipes_struct *p,
8515 struct spoolss_AddForm *r)
8517 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8519 WERROR status = WERR_OK;
8521 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8523 DEBUG(5,("_spoolss_AddForm\n"));
8526 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8527 OUR_HANDLE(r->in.handle)));
8531 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8532 and not a printer admin, then fail */
8534 if ((p->session_info->utok.uid != sec_initial_uid()) &&
8535 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
8536 !token_contains_name_in_list(uidtoname(p->session_info->utok.uid),
8537 p->session_info->info3->base.domain.string,
8539 p->session_info->security_token,
8540 lp_printer_admin(snum))) {
8541 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8542 return WERR_ACCESS_DENIED;
8545 switch (form->flags) {
8546 case SPOOLSS_FORM_USER:
8547 case SPOOLSS_FORM_BUILTIN:
8548 case SPOOLSS_FORM_PRINTER:
8551 return WERR_INVALID_PARAM;
8554 status = winreg_printer_addform1(p->mem_ctx,
8555 get_session_info_system(),
8558 if (!W_ERROR_IS_OK(status)) {
8563 * ChangeID must always be set if this is a printer
8565 if (Printer->printer_type == SPLHND_PRINTER) {
8566 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8570 status = winreg_printer_update_changeid(p->mem_ctx,
8571 get_session_info_system(),
8573 lp_const_servicename(snum));
8574 if (!W_ERROR_IS_OK(status)) {
8582 /****************************************************************
8584 ****************************************************************/
8586 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8587 struct spoolss_DeleteForm *r)
8589 const char *form_name = r->in.form_name;
8590 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8592 WERROR status = WERR_OK;
8594 DEBUG(5,("_spoolss_DeleteForm\n"));
8597 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8598 OUR_HANDLE(r->in.handle)));
8602 if ((p->session_info->utok.uid != sec_initial_uid()) &&
8603 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
8604 !token_contains_name_in_list(uidtoname(p->session_info->utok.uid),
8605 p->session_info->info3->base.domain.string,
8607 p->session_info->security_token,
8608 lp_printer_admin(snum))) {
8609 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8610 return WERR_ACCESS_DENIED;
8613 status = winreg_printer_deleteform1(p->mem_ctx,
8614 get_session_info_system(),
8617 if (!W_ERROR_IS_OK(status)) {
8622 * ChangeID must always be set if this is a printer
8624 if (Printer->printer_type == SPLHND_PRINTER) {
8625 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8629 status = winreg_printer_update_changeid(p->mem_ctx,
8630 get_session_info_system(),
8632 lp_const_servicename(snum));
8633 if (!W_ERROR_IS_OK(status)) {
8641 /****************************************************************
8643 ****************************************************************/
8645 WERROR _spoolss_SetForm(struct pipes_struct *p,
8646 struct spoolss_SetForm *r)
8648 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8649 const char *form_name = r->in.form_name;
8651 WERROR status = WERR_OK;
8653 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8655 DEBUG(5,("_spoolss_SetForm\n"));
8658 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8659 OUR_HANDLE(r->in.handle)));
8663 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8664 and not a printer admin, then fail */
8666 if ((p->session_info->utok.uid != sec_initial_uid()) &&
8667 !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
8668 !token_contains_name_in_list(uidtoname(p->session_info->utok.uid),
8669 p->session_info->info3->base.domain.string,
8671 p->session_info->security_token,
8672 lp_printer_admin(snum))) {
8673 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8674 return WERR_ACCESS_DENIED;
8677 status = winreg_printer_setform1(p->mem_ctx,
8678 get_session_info_system(),
8682 if (!W_ERROR_IS_OK(status)) {
8687 * ChangeID must always be set if this is a printer
8689 if (Printer->printer_type == SPLHND_PRINTER) {
8690 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8694 status = winreg_printer_update_changeid(p->mem_ctx,
8695 get_session_info_system(),
8697 lp_const_servicename(snum));
8698 if (!W_ERROR_IS_OK(status)) {
8706 /****************************************************************************
8707 fill_print_processor1
8708 ****************************************************************************/
8710 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8711 struct spoolss_PrintProcessorInfo1 *r,
8712 const char *print_processor_name)
8714 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8715 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8720 /****************************************************************************
8721 enumprintprocessors level 1.
8722 ****************************************************************************/
8724 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8725 union spoolss_PrintProcessorInfo **info_p,
8728 union spoolss_PrintProcessorInfo *info;
8731 info = talloc_array(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8732 W_ERROR_HAVE_NO_MEMORY(info);
8736 result = fill_print_processor1(info, &info[0].info1, "winprint");
8737 if (!W_ERROR_IS_OK(result)) {
8742 if (!W_ERROR_IS_OK(result)) {
8753 /****************************************************************
8754 _spoolss_EnumPrintProcessors
8755 ****************************************************************/
8757 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8758 struct spoolss_EnumPrintProcessors *r)
8762 /* that's an [in out] buffer */
8764 if (!r->in.buffer && (r->in.offered != 0)) {
8765 return WERR_INVALID_PARAM;
8768 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8771 * Enumerate the print processors ...
8773 * Just reply with "winprint", to keep NT happy
8774 * and I can use my nice printer checker.
8779 *r->out.info = NULL;
8781 if (!get_short_archi(r->in.environment)) {
8782 return WERR_INVALID_ENVIRONMENT;
8785 switch (r->in.level) {
8787 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8791 return WERR_UNKNOWN_LEVEL;
8794 if (!W_ERROR_IS_OK(result)) {
8798 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8799 spoolss_EnumPrintProcessors,
8800 *r->out.info, r->in.level,
8802 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8803 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8805 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8808 /****************************************************************************
8809 fill_printprocdatatype1
8810 ****************************************************************************/
8812 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8813 struct spoolss_PrintProcDataTypesInfo1 *r,
8814 const char *name_array)
8816 r->name_array = talloc_strdup(mem_ctx, name_array);
8817 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8822 /****************************************************************************
8823 enumprintprocdatatypes level 1.
8824 ****************************************************************************/
8826 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8827 union spoolss_PrintProcDataTypesInfo **info_p,
8831 union spoolss_PrintProcDataTypesInfo *info;
8833 info = talloc_array(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8834 W_ERROR_HAVE_NO_MEMORY(info);
8838 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8839 if (!W_ERROR_IS_OK(result)) {
8844 if (!W_ERROR_IS_OK(result)) {
8855 /****************************************************************
8856 _spoolss_EnumPrintProcDataTypes
8857 ****************************************************************/
8859 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
8860 struct spoolss_EnumPrintProcDataTypes *r)
8864 /* that's an [in out] buffer */
8866 if (!r->in.buffer && (r->in.offered != 0)) {
8867 return WERR_INVALID_PARAM;
8870 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8874 *r->out.info = NULL;
8876 if (r->in.print_processor_name == NULL ||
8877 !strequal(r->in.print_processor_name, "winprint")) {
8878 return WERR_UNKNOWN_PRINTPROCESSOR;
8881 switch (r->in.level) {
8883 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8887 return WERR_UNKNOWN_LEVEL;
8890 if (!W_ERROR_IS_OK(result)) {
8894 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8895 spoolss_EnumPrintProcDataTypes,
8896 *r->out.info, r->in.level,
8898 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8899 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8901 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8904 /****************************************************************************
8906 ****************************************************************************/
8908 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8909 struct spoolss_MonitorInfo1 *r,
8910 const char *monitor_name)
8912 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8913 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8918 /****************************************************************************
8920 ****************************************************************************/
8922 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8923 struct spoolss_MonitorInfo2 *r,
8924 const char *monitor_name,
8925 const char *environment,
8926 const char *dll_name)
8928 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8929 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8930 r->environment = talloc_strdup(mem_ctx, environment);
8931 W_ERROR_HAVE_NO_MEMORY(r->environment);
8932 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8933 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8938 /****************************************************************************
8939 enumprintmonitors level 1.
8940 ****************************************************************************/
8942 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8943 union spoolss_MonitorInfo **info_p,
8946 union spoolss_MonitorInfo *info;
8947 WERROR result = WERR_OK;
8949 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, 2);
8950 W_ERROR_HAVE_NO_MEMORY(info);
8954 result = fill_monitor_1(info, &info[0].info1,
8956 if (!W_ERROR_IS_OK(result)) {
8960 result = fill_monitor_1(info, &info[1].info1,
8962 if (!W_ERROR_IS_OK(result)) {
8967 if (!W_ERROR_IS_OK(result)) {
8978 /****************************************************************************
8979 enumprintmonitors level 2.
8980 ****************************************************************************/
8982 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8983 union spoolss_MonitorInfo **info_p,
8986 union spoolss_MonitorInfo *info;
8987 WERROR result = WERR_OK;
8989 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, 2);
8990 W_ERROR_HAVE_NO_MEMORY(info);
8994 result = fill_monitor_2(info, &info[0].info2,
8996 "Windows NT X86", /* FIXME */
8998 if (!W_ERROR_IS_OK(result)) {
9002 result = fill_monitor_2(info, &info[1].info2,
9004 "Windows NT X86", /* FIXME */
9006 if (!W_ERROR_IS_OK(result)) {
9011 if (!W_ERROR_IS_OK(result)) {
9022 /****************************************************************
9023 _spoolss_EnumMonitors
9024 ****************************************************************/
9026 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
9027 struct spoolss_EnumMonitors *r)
9031 /* that's an [in out] buffer */
9033 if (!r->in.buffer && (r->in.offered != 0)) {
9034 return WERR_INVALID_PARAM;
9037 DEBUG(5,("_spoolss_EnumMonitors\n"));
9040 * Enumerate the print monitors ...
9042 * Just reply with "Local Port", to keep NT happy
9043 * and I can use my nice printer checker.
9048 *r->out.info = NULL;
9050 switch (r->in.level) {
9052 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
9056 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
9060 return WERR_UNKNOWN_LEVEL;
9063 if (!W_ERROR_IS_OK(result)) {
9067 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9068 spoolss_EnumMonitors,
9069 *r->out.info, r->in.level,
9071 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9072 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9074 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9077 /****************************************************************************
9078 ****************************************************************************/
9080 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
9081 const print_queue_struct *queue,
9082 int count, int snum,
9083 struct spoolss_PrinterInfo2 *pinfo2,
9085 struct spoolss_JobInfo1 *r)
9090 for (i=0; i<count; i++) {
9091 if (queue[i].job == (int)jobid) {
9097 if (found == false) {
9098 /* NT treats not found as bad param... yet another bad choice */
9099 return WERR_INVALID_PARAM;
9102 return fill_job_info1(mem_ctx,
9110 /****************************************************************************
9111 ****************************************************************************/
9113 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
9114 const print_queue_struct *queue,
9115 int count, int snum,
9116 struct spoolss_PrinterInfo2 *pinfo2,
9118 struct spoolss_JobInfo2 *r)
9122 struct spoolss_DeviceMode *devmode;
9125 for (i=0; i<count; i++) {
9126 if (queue[i].job == (int)jobid) {
9132 if (found == false) {
9133 /* NT treats not found as bad param... yet another bad
9135 return WERR_INVALID_PARAM;
9139 * if the print job does not have a DEVMODE associated with it,
9140 * just use the one for the printer. A NULL devicemode is not
9141 * a failure condition
9144 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
9146 result = spoolss_create_default_devmode(mem_ctx,
9147 pinfo2->printername,
9149 if (!W_ERROR_IS_OK(result)) {
9150 DEBUG(3, ("Can't proceed w/o a devmode!"));
9155 return fill_job_info2(mem_ctx,
9164 /****************************************************************
9166 ****************************************************************/
9168 WERROR _spoolss_GetJob(struct pipes_struct *p,
9169 struct spoolss_GetJob *r)
9171 WERROR result = WERR_OK;
9172 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9175 print_queue_struct *queue = NULL;
9176 print_status_struct prt_status;
9178 /* that's an [in out] buffer */
9180 if (!r->in.buffer && (r->in.offered != 0)) {
9181 return WERR_INVALID_PARAM;
9184 DEBUG(5,("_spoolss_GetJob\n"));
9188 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9192 result = winreg_get_printer(p->mem_ctx,
9193 get_session_info_system(),
9195 lp_const_servicename(snum),
9197 if (!W_ERROR_IS_OK(result)) {
9201 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
9203 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9204 count, prt_status.status, prt_status.message));
9206 switch (r->in.level) {
9208 result = getjob_level_1(p->mem_ctx,
9209 queue, count, snum, pinfo2,
9210 r->in.job_id, &r->out.info->info1);
9213 result = getjob_level_2(p->mem_ctx,
9214 queue, count, snum, pinfo2,
9215 r->in.job_id, &r->out.info->info2);
9218 result = WERR_UNKNOWN_LEVEL;
9223 TALLOC_FREE(pinfo2);
9225 if (!W_ERROR_IS_OK(result)) {
9226 TALLOC_FREE(r->out.info);
9230 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
9232 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9234 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9237 /****************************************************************
9238 _spoolss_GetPrinterDataEx
9239 ****************************************************************/
9241 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
9242 struct spoolss_GetPrinterDataEx *r)
9245 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9246 const char *printer;
9248 WERROR result = WERR_OK;
9250 enum winreg_Type val_type = REG_NONE;
9251 uint8_t *val_data = NULL;
9252 uint32_t val_size = 0;
9255 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9257 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9258 r->in.key_name, r->in.value_name));
9260 /* in case of problem, return some default values */
9263 *r->out.type = REG_NONE;
9266 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9267 OUR_HANDLE(r->in.handle)));
9268 result = WERR_BADFID;
9272 /* Is the handle to a printer or to the server? */
9274 if (Printer->printer_type == SPLHND_SERVER) {
9276 union spoolss_PrinterData data;
9278 result = getprinterdata_printer_server(p->mem_ctx,
9282 if (!W_ERROR_IS_OK(result)) {
9286 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
9287 *r->out.type, &data);
9288 if (!W_ERROR_IS_OK(result)) {
9292 *r->out.needed = blob.length;
9294 if (r->in.offered >= *r->out.needed) {
9295 memcpy(r->out.data, blob.data, blob.length);
9298 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9301 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9304 printer = lp_const_servicename(snum);
9306 /* check to see if the keyname is valid */
9307 if (!strlen(r->in.key_name)) {
9308 return WERR_INVALID_PARAM;
9311 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9312 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
9313 strequal(r->in.value_name, "ChangeId")) {
9314 *r->out.type = REG_DWORD;
9316 if (r->in.offered >= *r->out.needed) {
9317 uint32_t changeid = 0;
9319 result = winreg_printer_get_changeid(p->mem_ctx,
9320 get_session_info_system(),
9324 if (!W_ERROR_IS_OK(result)) {
9328 SIVAL(r->out.data, 0, changeid);
9334 result = winreg_get_printer_dataex(p->mem_ctx,
9335 get_session_info_system(),
9343 if (!W_ERROR_IS_OK(result)) {
9347 *r->out.needed = val_size;
9348 *r->out.type = val_type;
9350 if (r->in.offered >= *r->out.needed) {
9351 memcpy(r->out.data, val_data, val_size);
9355 /* retain type when returning WERR_MORE_DATA */
9356 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
9358 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9361 /****************************************************************
9362 _spoolss_SetPrinterDataEx
9363 ****************************************************************/
9365 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
9366 struct spoolss_SetPrinterDataEx *r)
9368 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9370 WERROR result = WERR_OK;
9371 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9374 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9376 /* From MSDN documentation of SetPrinterDataEx: pass request to
9377 SetPrinterData if key is "PrinterDriverData" */
9380 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9381 OUR_HANDLE(r->in.handle)));
9385 if (Printer->printer_type == SPLHND_SERVER) {
9386 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9387 "Not implemented for server handles yet\n"));
9388 return WERR_INVALID_PARAM;
9391 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9396 * Access check : NT returns "access denied" if you make a
9397 * SetPrinterData call without the necessary privildge.
9398 * we were originally returning OK if nothing changed
9399 * which made Win2k issue **a lot** of SetPrinterData
9400 * when connecting to a printer --jerry
9403 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9404 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9405 "change denied by handle access permissions\n"));
9406 return WERR_ACCESS_DENIED;
9409 result = winreg_get_printer(Printer,
9410 get_session_info_system(),
9412 lp_servicename(snum),
9414 if (!W_ERROR_IS_OK(result)) {
9418 /* check for OID in valuename */
9420 oid_string = strchr(r->in.value_name, ',');
9426 /* save the registry data */
9428 result = winreg_set_printer_dataex(p->mem_ctx,
9429 get_session_info_system(),
9438 if (W_ERROR_IS_OK(result)) {
9439 /* save the OID if one was specified */
9441 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9442 r->in.key_name, SPOOL_OID_KEY);
9444 result = WERR_NOMEM;
9449 * I'm not checking the status here on purpose. Don't know
9450 * if this is right, but I'm returning the status from the
9451 * previous set_printer_dataex() call. I have no idea if
9452 * this is right. --jerry
9454 winreg_set_printer_dataex(p->mem_ctx,
9455 get_session_info_system(),
9461 (uint8_t *) oid_string,
9462 strlen(oid_string) + 1);
9465 result = winreg_printer_update_changeid(p->mem_ctx,
9466 get_session_info_system(),
9468 lp_const_servicename(snum));
9473 talloc_free(pinfo2);
9477 /****************************************************************
9478 _spoolss_DeletePrinterDataEx
9479 ****************************************************************/
9481 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
9482 struct spoolss_DeletePrinterDataEx *r)
9484 const char *printer;
9486 WERROR status = WERR_OK;
9487 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9489 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9492 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9493 "Invalid handle (%s:%u:%u).\n",
9494 OUR_HANDLE(r->in.handle)));
9498 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9499 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9500 "printer properties change denied by handle\n"));
9501 return WERR_ACCESS_DENIED;
9504 if (!r->in.value_name || !r->in.key_name) {
9508 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9511 printer = lp_const_servicename(snum);
9513 status = winreg_delete_printer_dataex(p->mem_ctx,
9514 get_session_info_system(),
9519 if (W_ERROR_IS_OK(status)) {
9520 status = winreg_printer_update_changeid(p->mem_ctx,
9521 get_session_info_system(),
9529 /****************************************************************
9530 _spoolss_EnumPrinterKey
9531 ****************************************************************/
9533 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
9534 struct spoolss_EnumPrinterKey *r)
9537 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9539 WERROR result = WERR_BADFILE;
9540 const char **array = NULL;
9543 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9546 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9547 OUR_HANDLE(r->in.handle)));
9551 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9555 result = winreg_enum_printer_key(p->mem_ctx,
9556 get_session_info_system(),
9558 lp_const_servicename(snum),
9562 if (!W_ERROR_IS_OK(result)) {
9566 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9567 result = WERR_NOMEM;
9571 *r->out._ndr_size = r->in.offered / 2;
9572 *r->out.needed = blob.length;
9574 if (r->in.offered < *r->out.needed) {
9575 result = WERR_MORE_DATA;
9578 r->out.key_buffer->string_array = array;
9582 if (!W_ERROR_IS_OK(result)) {
9584 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9592 /****************************************************************
9593 _spoolss_DeletePrinterKey
9594 ****************************************************************/
9596 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9597 struct spoolss_DeletePrinterKey *r)
9599 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9602 const char *printer;
9604 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9607 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9608 OUR_HANDLE(r->in.handle)));
9612 /* if keyname == NULL, return error */
9613 if ( !r->in.key_name )
9614 return WERR_INVALID_PARAM;
9616 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9620 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9621 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9622 "printer properties change denied by handle\n"));
9623 return WERR_ACCESS_DENIED;
9626 printer = lp_const_servicename(snum);
9628 /* delete the key and all subkeys */
9629 status = winreg_delete_printer_key(p->mem_ctx,
9630 get_session_info_system(),
9634 if (W_ERROR_IS_OK(status)) {
9635 status = winreg_printer_update_changeid(p->mem_ctx,
9636 get_session_info_system(),
9644 /****************************************************************
9645 _spoolss_EnumPrinterDataEx
9646 ****************************************************************/
9648 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9649 struct spoolss_EnumPrinterDataEx *r)
9652 struct spoolss_PrinterEnumValues *info = NULL;
9653 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9657 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9661 *r->out.info = NULL;
9664 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9665 OUR_HANDLE(r->in.handle)));
9670 * first check for a keyname of NULL or "". Win2k seems to send
9671 * this a lot and we should send back WERR_INVALID_PARAM
9672 * no need to spend time looking up the printer in this case.
9676 if (!strlen(r->in.key_name)) {
9677 result = WERR_INVALID_PARAM;
9681 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9685 /* now look for a match on the key name */
9686 result = winreg_enum_printer_dataex(p->mem_ctx,
9687 get_session_info_system(),
9689 lp_const_servicename(snum),
9693 if (!W_ERROR_IS_OK(result)) {
9697 #if 0 /* FIXME - gd */
9698 /* housekeeping information in the reply */
9700 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9701 * the hand marshalled container size is a multiple
9702 * of 4 bytes for RPC alignment.
9706 needed += 4-(needed % 4);
9709 *r->out.count = count;
9710 *r->out.info = info;
9713 if (!W_ERROR_IS_OK(result)) {
9717 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9718 spoolss_EnumPrinterDataEx,
9721 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9722 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9724 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9727 /****************************************************************************
9728 ****************************************************************************/
9730 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9731 const char *servername,
9732 const char *environment,
9733 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9738 werr = compose_spoolss_server_path(mem_ctx,
9741 SPOOLSS_PRTPROCS_PATH,
9743 if (!W_ERROR_IS_OK(werr)) {
9747 DEBUG(4,("print processor directory: [%s]\n", path));
9749 r->directory_name = path;
9754 /****************************************************************
9755 _spoolss_GetPrintProcessorDirectory
9756 ****************************************************************/
9758 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
9759 struct spoolss_GetPrintProcessorDirectory *r)
9762 char *prnproc_share = NULL;
9763 bool prnproc_share_exists = false;
9766 /* that's an [in out] buffer */
9768 if (!r->in.buffer && (r->in.offered != 0)) {
9769 return WERR_INVALID_PARAM;
9772 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9777 /* r->in.level is ignored */
9779 /* We always should reply with a local print processor directory so that
9780 * users are not forced to have a [prnproc$] share on the Samba spoolss
9781 * server, if users decide to do so, lets announce it though - Guenther */
9783 snum = find_service(talloc_tos(), "prnproc$", &prnproc_share);
9784 if (!prnproc_share) {
9788 prnproc_share_exists = true;
9791 result = getprintprocessordirectory_level_1(p->mem_ctx,
9792 prnproc_share_exists ? r->in.server : NULL,
9794 &r->out.info->info1);
9795 if (!W_ERROR_IS_OK(result)) {
9796 TALLOC_FREE(r->out.info);
9800 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9801 r->out.info, r->in.level);
9802 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9804 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9807 /*******************************************************************
9808 ********************************************************************/
9810 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9811 const char *dllname)
9813 enum ndr_err_code ndr_err;
9814 struct spoolss_MonitorUi ui;
9816 ui.dll_name = dllname;
9818 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9819 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9820 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9821 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9823 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9826 /*******************************************************************
9827 Streams the monitor UI DLL name in UNICODE
9828 *******************************************************************/
9830 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9831 struct security_token *token, DATA_BLOB *in,
9832 DATA_BLOB *out, uint32_t *needed)
9834 const char *dllname = "tcpmonui.dll";
9836 *needed = (strlen(dllname)+1) * 2;
9838 if (out->length < *needed) {
9839 return WERR_INSUFFICIENT_BUFFER;
9842 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9849 /*******************************************************************
9850 ********************************************************************/
9852 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9853 struct spoolss_PortData1 *port1,
9854 const DATA_BLOB *buf)
9856 enum ndr_err_code ndr_err;
9857 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9858 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9859 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9860 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9862 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9865 /*******************************************************************
9866 ********************************************************************/
9868 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9869 struct spoolss_PortData2 *port2,
9870 const DATA_BLOB *buf)
9872 enum ndr_err_code ndr_err;
9873 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9874 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9875 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9876 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9878 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9881 /*******************************************************************
9882 Create a new TCP/IP port
9883 *******************************************************************/
9885 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9886 struct security_token *token, DATA_BLOB *in,
9887 DATA_BLOB *out, uint32_t *needed)
9889 struct spoolss_PortData1 port1;
9890 struct spoolss_PortData2 port2;
9891 char *device_uri = NULL;
9894 const char *portname;
9895 const char *hostaddress;
9897 uint32_t port_number;
9900 /* peek for spoolss_PortData version */
9902 if (!in || (in->length < (128 + 4))) {
9903 return WERR_GENERAL_FAILURE;
9906 version = IVAL(in->data, 128);
9912 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9916 portname = port1.portname;
9917 hostaddress = port1.hostaddress;
9918 queue = port1.queue;
9919 protocol = port1.protocol;
9920 port_number = port1.port_number;
9926 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9930 portname = port2.portname;
9931 hostaddress = port2.hostaddress;
9932 queue = port2.queue;
9933 protocol = port2.protocol;
9934 port_number = port2.port_number;
9938 DEBUG(1,("xcvtcp_addport: "
9939 "unknown version of port_data: %d\n", version));
9940 return WERR_UNKNOWN_PORT;
9943 /* create the device URI and call the add_port_hook() */
9946 case PROTOCOL_RAWTCP_TYPE:
9947 device_uri = talloc_asprintf(mem_ctx,
9948 "socket://%s:%d/", hostaddress,
9952 case PROTOCOL_LPR_TYPE:
9953 device_uri = talloc_asprintf(mem_ctx,
9954 "lpr://%s/%s", hostaddress, queue );
9958 return WERR_UNKNOWN_PORT;
9965 return add_port_hook(mem_ctx, token, portname, device_uri);
9968 /*******************************************************************
9969 *******************************************************************/
9971 struct xcv_api_table xcvtcp_cmds[] = {
9972 { "MonitorUI", xcvtcp_monitorui },
9973 { "AddPort", xcvtcp_addport},
9977 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9978 struct security_token *token, const char *command,
9985 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9987 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9988 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9989 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9992 return WERR_BADFUNC;
9995 /*******************************************************************
9996 *******************************************************************/
9997 #if 0 /* don't support management using the "Local Port" monitor */
9999 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
10000 struct security_token *token, DATA_BLOB *in,
10001 DATA_BLOB *out, uint32_t *needed)
10003 const char *dllname = "localui.dll";
10005 *needed = (strlen(dllname)+1) * 2;
10007 if (out->length < *needed) {
10008 return WERR_INSUFFICIENT_BUFFER;
10011 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
10018 /*******************************************************************
10019 *******************************************************************/
10021 struct xcv_api_table xcvlocal_cmds[] = {
10022 { "MonitorUI", xcvlocal_monitorui },
10026 struct xcv_api_table xcvlocal_cmds[] = {
10033 /*******************************************************************
10034 *******************************************************************/
10036 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
10037 struct security_token *token, const char *command,
10038 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
10043 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
10045 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
10046 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
10047 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
10049 return WERR_BADFUNC;
10052 /****************************************************************
10054 ****************************************************************/
10056 WERROR _spoolss_XcvData(struct pipes_struct *p,
10057 struct spoolss_XcvData *r)
10059 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
10060 DATA_BLOB out_data = data_blob_null;
10064 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
10065 OUR_HANDLE(r->in.handle)));
10066 return WERR_BADFID;
10069 /* Has to be a handle to the TCP/IP port monitor */
10071 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
10072 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
10073 return WERR_BADFID;
10076 /* requires administrative access to the server */
10078 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
10079 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
10080 return WERR_ACCESS_DENIED;
10083 /* Allocate the outgoing buffer */
10085 if (r->in.out_data_size) {
10086 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
10087 if (out_data.data == NULL) {
10092 switch ( Printer->printer_type ) {
10093 case SPLHND_PORTMON_TCP:
10094 werror = process_xcvtcp_command(p->mem_ctx,
10095 p->session_info->security_token,
10096 r->in.function_name,
10097 &r->in.in_data, &out_data,
10100 case SPLHND_PORTMON_LOCAL:
10101 werror = process_xcvlocal_command(p->mem_ctx,
10102 p->session_info->security_token,
10103 r->in.function_name,
10104 &r->in.in_data, &out_data,
10108 werror = WERR_INVALID_PRINT_MONITOR;
10111 if (!W_ERROR_IS_OK(werror)) {
10115 *r->out.status_code = 0;
10117 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
10118 memcpy(r->out.out_data, out_data.data,
10119 MIN(r->in.out_data_size, out_data.length));
10125 /****************************************************************
10126 _spoolss_AddPrintProcessor
10127 ****************************************************************/
10129 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
10130 struct spoolss_AddPrintProcessor *r)
10132 /* for now, just indicate success and ignore the add. We'll
10133 automatically set the winprint processor for printer
10134 entries later. Used to debug the LexMark Optra S 1855 PCL
10140 /****************************************************************
10142 ****************************************************************/
10144 WERROR _spoolss_AddPort(struct pipes_struct *p,
10145 struct spoolss_AddPort *r)
10147 /* do what w2k3 does */
10149 return WERR_NOT_SUPPORTED;
10152 /****************************************************************
10153 _spoolss_GetPrinterDriver
10154 ****************************************************************/
10156 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
10157 struct spoolss_GetPrinterDriver *r)
10159 p->rng_fault_state = true;
10160 return WERR_NOT_SUPPORTED;
10163 /****************************************************************
10164 _spoolss_ReadPrinter
10165 ****************************************************************/
10167 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
10168 struct spoolss_ReadPrinter *r)
10170 p->rng_fault_state = true;
10171 return WERR_NOT_SUPPORTED;
10174 /****************************************************************
10175 _spoolss_WaitForPrinterChange
10176 ****************************************************************/
10178 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
10179 struct spoolss_WaitForPrinterChange *r)
10181 p->rng_fault_state = true;
10182 return WERR_NOT_SUPPORTED;
10185 /****************************************************************
10186 _spoolss_ConfigurePort
10187 ****************************************************************/
10189 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
10190 struct spoolss_ConfigurePort *r)
10192 p->rng_fault_state = true;
10193 return WERR_NOT_SUPPORTED;
10196 /****************************************************************
10197 _spoolss_DeletePort
10198 ****************************************************************/
10200 WERROR _spoolss_DeletePort(struct pipes_struct *p,
10201 struct spoolss_DeletePort *r)
10203 p->rng_fault_state = true;
10204 return WERR_NOT_SUPPORTED;
10207 /****************************************************************
10208 _spoolss_CreatePrinterIC
10209 ****************************************************************/
10211 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
10212 struct spoolss_CreatePrinterIC *r)
10214 p->rng_fault_state = true;
10215 return WERR_NOT_SUPPORTED;
10218 /****************************************************************
10219 _spoolss_PlayGDIScriptOnPrinterIC
10220 ****************************************************************/
10222 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
10223 struct spoolss_PlayGDIScriptOnPrinterIC *r)
10225 p->rng_fault_state = true;
10226 return WERR_NOT_SUPPORTED;
10229 /****************************************************************
10230 _spoolss_DeletePrinterIC
10231 ****************************************************************/
10233 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
10234 struct spoolss_DeletePrinterIC *r)
10236 p->rng_fault_state = true;
10237 return WERR_NOT_SUPPORTED;
10240 /****************************************************************
10241 _spoolss_AddPrinterConnection
10242 ****************************************************************/
10244 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
10245 struct spoolss_AddPrinterConnection *r)
10247 p->rng_fault_state = true;
10248 return WERR_NOT_SUPPORTED;
10251 /****************************************************************
10252 _spoolss_DeletePrinterConnection
10253 ****************************************************************/
10255 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
10256 struct spoolss_DeletePrinterConnection *r)
10258 p->rng_fault_state = true;
10259 return WERR_NOT_SUPPORTED;
10262 /****************************************************************
10263 _spoolss_PrinterMessageBox
10264 ****************************************************************/
10266 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
10267 struct spoolss_PrinterMessageBox *r)
10269 p->rng_fault_state = true;
10270 return WERR_NOT_SUPPORTED;
10273 /****************************************************************
10274 _spoolss_AddMonitor
10275 ****************************************************************/
10277 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
10278 struct spoolss_AddMonitor *r)
10280 p->rng_fault_state = true;
10281 return WERR_NOT_SUPPORTED;
10284 /****************************************************************
10285 _spoolss_DeleteMonitor
10286 ****************************************************************/
10288 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
10289 struct spoolss_DeleteMonitor *r)
10291 p->rng_fault_state = true;
10292 return WERR_NOT_SUPPORTED;
10295 /****************************************************************
10296 _spoolss_DeletePrintProcessor
10297 ****************************************************************/
10299 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
10300 struct spoolss_DeletePrintProcessor *r)
10302 p->rng_fault_state = true;
10303 return WERR_NOT_SUPPORTED;
10306 /****************************************************************
10307 _spoolss_AddPrintProvidor
10308 ****************************************************************/
10310 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
10311 struct spoolss_AddPrintProvidor *r)
10313 p->rng_fault_state = true;
10314 return WERR_NOT_SUPPORTED;
10317 /****************************************************************
10318 _spoolss_DeletePrintProvidor
10319 ****************************************************************/
10321 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
10322 struct spoolss_DeletePrintProvidor *r)
10324 p->rng_fault_state = true;
10325 return WERR_NOT_SUPPORTED;
10328 /****************************************************************
10329 _spoolss_FindFirstPrinterChangeNotification
10330 ****************************************************************/
10332 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
10333 struct spoolss_FindFirstPrinterChangeNotification *r)
10335 p->rng_fault_state = true;
10336 return WERR_NOT_SUPPORTED;
10339 /****************************************************************
10340 _spoolss_FindNextPrinterChangeNotification
10341 ****************************************************************/
10343 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
10344 struct spoolss_FindNextPrinterChangeNotification *r)
10346 p->rng_fault_state = true;
10347 return WERR_NOT_SUPPORTED;
10350 /****************************************************************
10351 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10352 ****************************************************************/
10354 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
10355 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10357 p->rng_fault_state = true;
10358 return WERR_NOT_SUPPORTED;
10361 /****************************************************************
10362 _spoolss_ReplyOpenPrinter
10363 ****************************************************************/
10365 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
10366 struct spoolss_ReplyOpenPrinter *r)
10368 p->rng_fault_state = true;
10369 return WERR_NOT_SUPPORTED;
10372 /****************************************************************
10373 _spoolss_RouterReplyPrinter
10374 ****************************************************************/
10376 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
10377 struct spoolss_RouterReplyPrinter *r)
10379 p->rng_fault_state = true;
10380 return WERR_NOT_SUPPORTED;
10383 /****************************************************************
10384 _spoolss_ReplyClosePrinter
10385 ****************************************************************/
10387 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
10388 struct spoolss_ReplyClosePrinter *r)
10390 p->rng_fault_state = true;
10391 return WERR_NOT_SUPPORTED;
10394 /****************************************************************
10396 ****************************************************************/
10398 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
10399 struct spoolss_AddPortEx *r)
10401 p->rng_fault_state = true;
10402 return WERR_NOT_SUPPORTED;
10405 /****************************************************************
10406 _spoolss_RouterFindFirstPrinterChangeNotification
10407 ****************************************************************/
10409 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
10410 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10412 p->rng_fault_state = true;
10413 return WERR_NOT_SUPPORTED;
10416 /****************************************************************
10417 _spoolss_SpoolerInit
10418 ****************************************************************/
10420 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
10421 struct spoolss_SpoolerInit *r)
10423 p->rng_fault_state = true;
10424 return WERR_NOT_SUPPORTED;
10427 /****************************************************************
10428 _spoolss_ResetPrinterEx
10429 ****************************************************************/
10431 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
10432 struct spoolss_ResetPrinterEx *r)
10434 p->rng_fault_state = true;
10435 return WERR_NOT_SUPPORTED;
10438 /****************************************************************
10439 _spoolss_RouterReplyPrinterEx
10440 ****************************************************************/
10442 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
10443 struct spoolss_RouterReplyPrinterEx *r)
10445 p->rng_fault_state = true;
10446 return WERR_NOT_SUPPORTED;
10449 /****************************************************************
10451 ****************************************************************/
10453 WERROR _spoolss_44(struct pipes_struct *p,
10454 struct spoolss_44 *r)
10456 p->rng_fault_state = true;
10457 return WERR_NOT_SUPPORTED;
10460 /****************************************************************
10462 ****************************************************************/
10464 WERROR _spoolss_SetPort(struct pipes_struct *p,
10465 struct spoolss_SetPort *r)
10467 p->rng_fault_state = true;
10468 return WERR_NOT_SUPPORTED;
10471 /****************************************************************
10473 ****************************************************************/
10475 WERROR _spoolss_4a(struct pipes_struct *p,
10476 struct spoolss_4a *r)
10478 p->rng_fault_state = true;
10479 return WERR_NOT_SUPPORTED;
10482 /****************************************************************
10484 ****************************************************************/
10486 WERROR _spoolss_4b(struct pipes_struct *p,
10487 struct spoolss_4b *r)
10489 p->rng_fault_state = true;
10490 return WERR_NOT_SUPPORTED;
10493 /****************************************************************
10495 ****************************************************************/
10497 WERROR _spoolss_4c(struct pipes_struct *p,
10498 struct spoolss_4c *r)
10500 p->rng_fault_state = true;
10501 return WERR_NOT_SUPPORTED;
10504 /****************************************************************
10506 ****************************************************************/
10508 WERROR _spoolss_53(struct pipes_struct *p,
10509 struct spoolss_53 *r)
10511 p->rng_fault_state = true;
10512 return WERR_NOT_SUPPORTED;
10515 /****************************************************************
10516 _spoolss_AddPerMachineConnection
10517 ****************************************************************/
10519 WERROR _spoolss_AddPerMachineConnection(struct pipes_struct *p,
10520 struct spoolss_AddPerMachineConnection *r)
10522 p->rng_fault_state = true;
10523 return WERR_NOT_SUPPORTED;
10526 /****************************************************************
10527 _spoolss_DeletePerMachineConnection
10528 ****************************************************************/
10530 WERROR _spoolss_DeletePerMachineConnection(struct pipes_struct *p,
10531 struct spoolss_DeletePerMachineConnection *r)
10533 p->rng_fault_state = true;
10534 return WERR_NOT_SUPPORTED;
10537 /****************************************************************
10538 _spoolss_EnumPerMachineConnections
10539 ****************************************************************/
10541 WERROR _spoolss_EnumPerMachineConnections(struct pipes_struct *p,
10542 struct spoolss_EnumPerMachineConnections *r)
10544 p->rng_fault_state = true;
10545 return WERR_NOT_SUPPORTED;
10548 /****************************************************************
10550 ****************************************************************/
10552 WERROR _spoolss_5a(struct pipes_struct *p,
10553 struct spoolss_5a *r)
10555 p->rng_fault_state = true;
10556 return WERR_NOT_SUPPORTED;
10559 /****************************************************************
10561 ****************************************************************/
10563 WERROR _spoolss_5b(struct pipes_struct *p,
10564 struct spoolss_5b *r)
10566 p->rng_fault_state = true;
10567 return WERR_NOT_SUPPORTED;
10570 /****************************************************************
10572 ****************************************************************/
10574 WERROR _spoolss_5c(struct pipes_struct *p,
10575 struct spoolss_5c *r)
10577 p->rng_fault_state = true;
10578 return WERR_NOT_SUPPORTED;
10581 /****************************************************************
10583 ****************************************************************/
10585 WERROR _spoolss_5d(struct pipes_struct *p,
10586 struct spoolss_5d *r)
10588 p->rng_fault_state = true;
10589 return WERR_NOT_SUPPORTED;
10592 /****************************************************************
10594 ****************************************************************/
10596 WERROR _spoolss_5e(struct pipes_struct *p,
10597 struct spoolss_5e *r)
10599 p->rng_fault_state = true;
10600 return WERR_NOT_SUPPORTED;
10603 /****************************************************************
10605 ****************************************************************/
10607 WERROR _spoolss_5f(struct pipes_struct *p,
10608 struct spoolss_5f *r)
10610 p->rng_fault_state = true;
10611 return WERR_NOT_SUPPORTED;
10614 /****************************************************************
10616 ****************************************************************/
10618 WERROR _spoolss_60(struct pipes_struct *p,
10619 struct spoolss_60 *r)
10621 p->rng_fault_state = true;
10622 return WERR_NOT_SUPPORTED;
10625 /****************************************************************
10627 ****************************************************************/
10629 WERROR _spoolss_61(struct pipes_struct *p,
10630 struct spoolss_61 *r)
10632 p->rng_fault_state = true;
10633 return WERR_NOT_SUPPORTED;
10636 /****************************************************************
10638 ****************************************************************/
10640 WERROR _spoolss_62(struct pipes_struct *p,
10641 struct spoolss_62 *r)
10643 p->rng_fault_state = true;
10644 return WERR_NOT_SUPPORTED;
10647 /****************************************************************
10649 ****************************************************************/
10651 WERROR _spoolss_63(struct pipes_struct *p,
10652 struct spoolss_63 *r)
10654 p->rng_fault_state = true;
10655 return WERR_NOT_SUPPORTED;
10658 /****************************************************************
10660 ****************************************************************/
10662 WERROR _spoolss_64(struct pipes_struct *p,
10663 struct spoolss_64 *r)
10665 p->rng_fault_state = true;
10666 return WERR_NOT_SUPPORTED;
10669 /****************************************************************
10671 ****************************************************************/
10673 WERROR _spoolss_65(struct pipes_struct *p,
10674 struct spoolss_65 *r)
10676 p->rng_fault_state = true;
10677 return WERR_NOT_SUPPORTED;
10680 /****************************************************************
10681 _spoolss_GetCorePrinterDrivers
10682 ****************************************************************/
10684 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10685 struct spoolss_GetCorePrinterDrivers *r)
10687 p->rng_fault_state = true;
10688 return WERR_NOT_SUPPORTED;
10691 /****************************************************************
10693 ****************************************************************/
10695 WERROR _spoolss_67(struct pipes_struct *p,
10696 struct spoolss_67 *r)
10698 p->rng_fault_state = true;
10699 return WERR_NOT_SUPPORTED;
10702 /****************************************************************
10703 _spoolss_GetPrinterDriverPackagePath
10704 ****************************************************************/
10706 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10707 struct spoolss_GetPrinterDriverPackagePath *r)
10709 p->rng_fault_state = true;
10710 return WERR_NOT_SUPPORTED;
10713 /****************************************************************
10715 ****************************************************************/
10717 WERROR _spoolss_69(struct pipes_struct *p,
10718 struct spoolss_69 *r)
10720 p->rng_fault_state = true;
10721 return WERR_NOT_SUPPORTED;
10724 /****************************************************************
10726 ****************************************************************/
10728 WERROR _spoolss_6a(struct pipes_struct *p,
10729 struct spoolss_6a *r)
10731 p->rng_fault_state = true;
10732 return WERR_NOT_SUPPORTED;
10735 /****************************************************************
10737 ****************************************************************/
10739 WERROR _spoolss_6b(struct pipes_struct *p,
10740 struct spoolss_6b *r)
10742 p->rng_fault_state = true;
10743 return WERR_NOT_SUPPORTED;
10746 /****************************************************************
10748 ****************************************************************/
10750 WERROR _spoolss_6c(struct pipes_struct *p,
10751 struct spoolss_6c *r)
10753 p->rng_fault_state = true;
10754 return WERR_NOT_SUPPORTED;
10757 /****************************************************************
10759 ****************************************************************/
10761 WERROR _spoolss_6d(struct pipes_struct *p,
10762 struct spoolss_6d *r)
10764 p->rng_fault_state = true;
10765 return WERR_NOT_SUPPORTED;