2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Jeremy Allison 2001-2002,
8 * Copyright (C) Gerald Carter 2000-2004,
9 * Copyright (C) Tim Potter 2001-2002.
10 * Copyright (C) Guenther Deschner 2009-2010.
11 * Copyright (C) Andreas Schneider 2010.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
28 up, all the errors returned are DOS errors, not NT status codes. */
31 #include "nt_printing.h"
32 #include "srv_spoolss_util.h"
33 #include "../librpc/gen_ndr/srv_spoolss.h"
34 #include "../librpc/gen_ndr/ndr_spoolss_c.h"
35 #include "rpc_client/init_spoolss.h"
36 #include "librpc/gen_ndr/messaging.h"
37 #include "../libcli/security/security.h"
38 #include "librpc/gen_ndr/ndr_security.h"
40 #include "registry/reg_objects.h"
41 #include "include/printing.h"
43 #include "../librpc/gen_ndr/netlogon.h"
46 /* macros stolen from s4 spoolss server */
47 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
48 ((info)?ndr_size_##fn(info, level, 0):0)
50 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
51 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
53 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
54 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
56 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
59 #define DBGC_CLASS DBGC_RPC_SRV
61 #ifndef MAX_OPEN_PRINTER_EXS
62 #define MAX_OPEN_PRINTER_EXS 50
65 struct notify_back_channel;
67 /* structure to store the printer handles */
68 /* and a reference to what it's pointing to */
69 /* and the notify info asked about */
70 /* that's the central struct */
71 struct printer_handle {
72 struct printer_handle *prev, *next;
73 bool document_started;
75 uint32 jobid; /* jobid in printing backend */
77 const char *servername;
80 uint32 access_granted;
86 struct spoolss_NotifyOption *option;
87 struct policy_handle cli_hnd;
88 struct notify_back_channel *cli_chan;
90 /* are we in a FindNextPrinterChangeNotify() call? */
92 struct messaging_context *msg_ctx;
99 /* devmode sent in the OpenPrinter() call */
100 struct spoolss_DeviceMode *devmode;
102 /* TODO cache the printer info2 structure */
103 struct spoolss_PrinterInfo2 *info2;
107 static struct printer_handle *printers_list;
109 struct printer_session_counter {
110 struct printer_session_counter *next;
111 struct printer_session_counter *prev;
117 static struct printer_session_counter *counter_list;
119 struct notify_back_channel {
120 struct notify_back_channel *prev, *next;
122 /* associated client */
123 struct sockaddr_storage client_address;
125 /* print notify back-channel pipe handle*/
126 struct rpc_pipe_client *cli_pipe;
127 struct dcerpc_binding_handle *binding_handle;
128 uint32_t active_connections;
131 static struct notify_back_channel *back_channels;
133 /* Map generic permissions to printer object specific permissions */
135 const struct standard_mapping printer_std_mapping = {
142 /* Map generic permissions to print server object specific permissions */
144 const struct standard_mapping printserver_std_mapping = {
151 /* API table for Xcv Monitor functions */
153 struct xcv_api_table {
155 WERROR(*fn) (TALLOC_CTX *mem_ctx, struct security_token *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
158 static void prune_printername_cache(void);
160 /********************************************************************
161 * Canonicalize servername.
162 ********************************************************************/
164 static const char *canon_servername(const char *servername)
166 const char *pservername = servername;
167 while (*pservername == '\\') {
173 /* translate between internal status numbers and NT status numbers */
174 static int nt_printj_status(int v)
180 return JOB_STATUS_PAUSED;
182 return JOB_STATUS_SPOOLING;
184 return JOB_STATUS_PRINTING;
186 return JOB_STATUS_ERROR;
188 return JOB_STATUS_DELETING;
190 return JOB_STATUS_OFFLINE;
192 return JOB_STATUS_PAPEROUT;
194 return JOB_STATUS_PRINTED;
196 return JOB_STATUS_DELETED;
198 return JOB_STATUS_BLOCKED_DEVQ;
199 case LPQ_USER_INTERVENTION:
200 return JOB_STATUS_USER_INTERVENTION;
205 static int nt_printq_status(int v)
209 return PRINTER_STATUS_PAUSED;
218 /***************************************************************************
219 Disconnect from the client
220 ****************************************************************************/
222 static void srv_spoolss_replycloseprinter(int snum,
223 struct printer_handle *prn_hnd)
229 * Tell the specific printing tdb we no longer want messages for this printer
230 * by deregistering our PID.
233 if (!print_notify_deregister_pid(snum)) {
234 DEBUG(0, ("Failed to register our pid for printer %s\n",
235 lp_const_servicename(snum)));
238 /* weird if the test succeeds !!! */
239 if (prn_hnd->notify.cli_chan == NULL ||
240 prn_hnd->notify.cli_chan->active_connections == 0) {
241 DEBUG(0, ("Trying to close unexisting backchannel!\n"));
242 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
243 TALLOC_FREE(prn_hnd->notify.cli_chan);
247 status = dcerpc_spoolss_ReplyClosePrinter(
248 prn_hnd->notify.cli_chan->binding_handle,
250 &prn_hnd->notify.cli_hnd,
252 if (!NT_STATUS_IS_OK(status)) {
253 DEBUG(0, ("dcerpc_spoolss_ReplyClosePrinter failed [%s].\n",
255 result = ntstatus_to_werror(status);
256 } else if (!W_ERROR_IS_OK(result)) {
257 DEBUG(0, ("reply_close_printer failed [%s].\n",
258 win_errstr(result)));
261 /* if it's the last connection, deconnect the IPC$ share */
262 if (prn_hnd->notify.cli_chan->active_connections == 1) {
264 prn_hnd->notify.cli_chan->binding_handle = NULL;
265 cli_shutdown(rpc_pipe_np_smb_conn(prn_hnd->notify.cli_chan->cli_pipe));
266 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
267 TALLOC_FREE(prn_hnd->notify.cli_chan);
269 if (prn_hnd->notify.msg_ctx != NULL) {
270 messaging_deregister(prn_hnd->notify.msg_ctx,
271 MSG_PRINTER_NOTIFY2, NULL);
274 * Tell the serverid.tdb we're no longer
275 * interested in printer notify messages.
278 serverid_register_msg_flags(
279 messaging_server_id(prn_hnd->notify.msg_ctx),
280 false, FLAG_MSG_PRINT_NOTIFY);
284 if (prn_hnd->notify.cli_chan) {
285 prn_hnd->notify.cli_chan->active_connections--;
289 /****************************************************************************
290 Functions to free a printer entry datastruct.
291 ****************************************************************************/
293 static int printer_entry_destructor(struct printer_handle *Printer)
295 if (Printer->notify.cli_chan != NULL &&
296 Printer->notify.cli_chan->active_connections > 0) {
299 switch(Printer->printer_type) {
301 srv_spoolss_replycloseprinter(snum, Printer);
305 snum = print_queue_snum(Printer->sharename);
307 srv_spoolss_replycloseprinter(snum, Printer);
315 Printer->notify.flags=0;
316 Printer->notify.options=0;
317 Printer->notify.localmachine[0]='\0';
318 Printer->notify.printerlocal=0;
319 TALLOC_FREE(Printer->notify.option);
320 TALLOC_FREE(Printer->devmode);
322 /* Remove from the internal list. */
323 DLIST_REMOVE(printers_list, Printer);
327 /****************************************************************************
328 find printer index by handle
329 ****************************************************************************/
331 static struct printer_handle *find_printer_index_by_hnd(struct pipes_struct *p,
332 struct policy_handle *hnd)
334 struct printer_handle *find_printer = NULL;
336 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
337 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
344 /****************************************************************************
345 Close printer index by handle.
346 ****************************************************************************/
348 static bool close_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
350 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
353 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
358 close_policy_hnd(p, hnd);
363 /****************************************************************************
364 Delete a printer given a handle.
365 ****************************************************************************/
367 static WERROR delete_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
368 const char *sharename,
369 struct messaging_context *msg_ctx)
371 char *cmd = lp_deleteprinter_cmd();
372 char *command = NULL;
374 bool is_print_op = false;
376 /* can't fail if we don't try */
381 command = talloc_asprintf(ctx,
388 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
390 DEBUG(10,("Running [%s]\n", command));
392 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
397 if ( (ret = smbrun(command, NULL)) == 0 ) {
398 /* Tell everyone we updated smb.conf. */
399 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
405 /********** END SePrintOperatorPrivlege BLOCK **********/
407 DEBUGADD(10,("returned [%d]\n", ret));
409 TALLOC_FREE(command);
412 return WERR_BADFID; /* What to return here? */
414 /* go ahead and re-read the services immediately */
416 reload_services(msg_ctx, -1, false);
419 if ( lp_servicenumber( sharename ) >= 0 )
420 return WERR_ACCESS_DENIED;
425 /****************************************************************************
426 Delete a printer given a handle.
427 ****************************************************************************/
429 static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
431 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
435 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
441 * It turns out that Windows allows delete printer on a handle
442 * opened by an admin user, then used on a pipe handle created
443 * by an anonymous user..... but they're working on security.... riiight !
447 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
448 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
449 return WERR_ACCESS_DENIED;
452 /* this does not need a become root since the access check has been
453 done on the handle already */
455 result = winreg_delete_printer_key(p->mem_ctx,
456 get_server_info_system(),
460 if (!W_ERROR_IS_OK(result)) {
461 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
465 result = delete_printer_hook(p->mem_ctx, p->server_info->security_token,
466 Printer->sharename, p->msg_ctx);
467 if (!W_ERROR_IS_OK(result)) {
470 prune_printername_cache();
474 /****************************************************************************
475 Return the snum of a printer corresponding to an handle.
476 ****************************************************************************/
478 static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
479 int *number, struct share_params **params)
481 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
484 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
489 switch (Printer->printer_type) {
491 DEBUG(4,("short name:%s\n", Printer->sharename));
492 *number = print_queue_snum(Printer->sharename);
493 return (*number != -1);
501 /****************************************************************************
502 Set printer handle type.
503 Check if it's \\server or \\server\printer
504 ****************************************************************************/
506 static bool set_printer_hnd_printertype(struct printer_handle *Printer, const char *handlename)
508 DEBUG(3,("Setting printer type=%s\n", handlename));
510 /* it's a print server */
511 if (handlename && *handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
512 DEBUGADD(4,("Printer is a print server\n"));
513 Printer->printer_type = SPLHND_SERVER;
515 /* it's a printer (set_printer_hnd_name() will handle port monitors */
517 DEBUGADD(4,("Printer is a printer\n"));
518 Printer->printer_type = SPLHND_PRINTER;
524 static void prune_printername_cache_fn(const char *key, const char *value,
525 time_t timeout, void *private_data)
530 static void prune_printername_cache(void)
532 gencache_iterate(prune_printername_cache_fn, NULL, "PRINTERNAME/*");
535 /****************************************************************************
536 Set printer handle name.. Accept names like \\server, \\server\printer,
537 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
538 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
539 XcvDataPort() interface.
540 ****************************************************************************/
542 static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
543 const struct auth_serversupplied_info *server_info,
544 struct messaging_context *msg_ctx,
545 struct printer_handle *Printer,
546 const char *handlename)
549 int n_services=lp_numservices();
551 const char *printername;
552 const char *servername = NULL;
555 struct spoolss_PrinterInfo2 *info2 = NULL;
560 * Hopefully nobody names his printers like this. Maybe \ or ,
561 * are illegal in printer names even?
563 const char printer_not_found[] = "Printer \\, !@#$%^&*( not found";
567 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
568 (unsigned long)strlen(handlename)));
570 aprinter = CONST_DISCARD(char *, handlename);
571 if ( *handlename == '\\' ) {
572 servername = canon_servername(handlename);
573 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
577 if (!is_myname_or_ipaddr(servername)) {
578 return WERR_INVALID_PRINTER_NAME;
580 Printer->servername = talloc_asprintf(Printer, "\\\\%s", servername);
581 if (Printer->servername == NULL) {
586 if (Printer->printer_type == SPLHND_SERVER) {
590 if (Printer->printer_type != SPLHND_PRINTER) {
591 return WERR_INVALID_HANDLE;
594 DEBUGADD(5, ("searching for [%s]\n", aprinter));
596 p = strchr(aprinter, ',');
603 if (strncmp(p, "DrvConvert", strlen("DrvConvert")) == 0) {
605 } else if (strncmp(p, "LocalOnly", strlen("LocalOnly")) == 0) {
611 DEBUGADD(5, ("stripped handlename: [%s]\n", aprinter));
614 /* check for the Port Monitor Interface */
615 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
616 Printer->printer_type = SPLHND_PORTMON_TCP;
617 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
620 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
621 Printer->printer_type = SPLHND_PORTMON_LOCAL;
622 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
627 * With hundreds of printers, the "for" loop iterating all
628 * shares can be quite expensive, as it is done on every
629 * OpenPrinter. The loop maps "aprinter" to "sname", the
630 * result of which we cache in gencache.
633 cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
635 if ((cache_key != NULL) && gencache_get(cache_key, &tmp, NULL)) {
637 found = (strcmp(tmp, printer_not_found) != 0);
639 DEBUG(4, ("Printer %s not found\n", aprinter));
641 return WERR_INVALID_PRINTER_NAME;
647 /* Search all sharenames first as this is easier than pulling
648 the printer_info_2 off of disk. Don't use find_service() since
649 that calls out to map_username() */
651 /* do another loop to look for printernames */
652 for (snum = 0; !found && snum < n_services; snum++) {
653 const char *printer = lp_const_servicename(snum);
655 /* no point going on if this is not a printer */
656 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
660 /* ignore [printers] share */
661 if (strequal(printer, "printers")) {
665 fstrcpy(sname, printer);
666 if (strequal(aprinter, printer)) {
671 /* no point looking up the printer object if
672 we aren't allowing printername != sharename */
673 if (lp_force_printername(snum)) {
677 result = winreg_get_printer(mem_ctx,
682 if ( !W_ERROR_IS_OK(result) ) {
683 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
684 sname, win_errstr(result)));
688 printername = strrchr(info2->printername, '\\');
689 if (printername == NULL) {
690 printername = info2->printername;
695 if (strequal(printername, aprinter)) {
700 DEBUGADD(10, ("printername: %s\n", printername));
706 if (cache_key != NULL) {
707 gencache_set(cache_key, printer_not_found,
709 TALLOC_FREE(cache_key);
711 DEBUGADD(4,("Printer not found\n"));
712 return WERR_INVALID_PRINTER_NAME;
715 if (cache_key != NULL) {
716 gencache_set(cache_key, sname, time(NULL)+300);
717 TALLOC_FREE(cache_key);
720 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
722 fstrcpy(Printer->sharename, sname);
727 /****************************************************************************
728 Find first available printer slot. creates a printer handle for you.
729 ****************************************************************************/
731 static WERROR open_printer_hnd(struct pipes_struct *p,
732 struct policy_handle *hnd,
734 uint32_t access_granted)
736 struct printer_handle *new_printer;
739 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
741 new_printer = talloc_zero(p->mem_ctx, struct printer_handle);
742 if (new_printer == NULL) {
745 talloc_set_destructor(new_printer, printer_entry_destructor);
747 /* This also steals the printer_handle on the policy_handle */
748 if (!create_policy_hnd(p, hnd, new_printer)) {
749 TALLOC_FREE(new_printer);
750 return WERR_INVALID_HANDLE;
753 /* Add to the internal list. */
754 DLIST_ADD(printers_list, new_printer);
756 new_printer->notify.option=NULL;
758 if (!set_printer_hnd_printertype(new_printer, name)) {
759 close_printer_handle(p, hnd);
760 return WERR_INVALID_HANDLE;
763 result = set_printer_hnd_name(p->mem_ctx,
764 get_server_info_system(),
767 if (!W_ERROR_IS_OK(result)) {
768 close_printer_handle(p, hnd);
772 new_printer->access_granted = access_granted;
774 DEBUG(5, ("%d printer handles active\n",
775 (int)num_pipe_handles(p)));
780 /***************************************************************************
781 check to see if the client motify handle is monitoring the notification
782 given by (notify_type, notify_field).
783 **************************************************************************/
785 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
786 uint16_t notify_field)
791 static bool is_monitoring_event(struct printer_handle *p, uint16_t notify_type,
792 uint16_t notify_field)
794 struct spoolss_NotifyOption *option = p->notify.option;
798 * Flags should always be zero when the change notify
799 * is registered by the client's spooler. A user Win32 app
800 * might use the flags though instead of the NOTIFY_OPTION_INFO
809 return is_monitoring_event_flags(
810 p->notify.flags, notify_type, notify_field);
812 for (i = 0; i < option->count; i++) {
814 /* Check match for notify_type */
816 if (option->types[i].type != notify_type)
819 /* Check match for field */
821 for (j = 0; j < option->types[i].count; j++) {
822 if (option->types[i].fields[j].field == notify_field) {
828 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
829 p->servername, p->sharename, notify_type, notify_field));
834 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
835 _data->data.integer[0] = _integer; \
836 _data->data.integer[1] = 0;
839 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
840 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
841 if (!_data->data.string.string) {\
842 _data->data.string.size = 0; \
844 _data->data.string.size = strlen_m_term(_p) * 2;
846 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
847 _data->data.devmode.devmode = _devmode;
849 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
850 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
851 if (!_data->data.sd.sd) { \
852 _data->data.sd.sd_size = 0; \
854 _data->data.sd.sd_size = \
855 ndr_size_security_descriptor(_data->data.sd.sd, 0);
857 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
862 struct spoolss_Time st;
866 if (!init_systemtime(&st, t)) {
870 p = talloc_array(mem_ctx, char, len);
876 * Systemtime must be linearized as a set of UINT16's.
877 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
880 SSVAL(p, 0, st.year);
881 SSVAL(p, 2, st.month);
882 SSVAL(p, 4, st.day_of_week);
884 SSVAL(p, 8, st.hour);
885 SSVAL(p, 10, st.minute);
886 SSVAL(p, 12, st.second);
887 SSVAL(p, 14, st.millisecond);
893 /* Convert a notification message to a struct spoolss_Notify */
895 static void notify_one_value(struct spoolss_notify_msg *msg,
896 struct spoolss_Notify *data,
899 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
902 static void notify_string(struct spoolss_notify_msg *msg,
903 struct spoolss_Notify *data,
906 /* The length of the message includes the trailing \0 */
908 data->data.string.size = msg->len * 2;
909 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
910 if (!data->data.string.string) {
911 data->data.string.size = 0;
916 static void notify_system_time(struct spoolss_notify_msg *msg,
917 struct spoolss_Notify *data,
920 data->data.string.string = NULL;
921 data->data.string.size = 0;
923 if (msg->len != sizeof(time_t)) {
924 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
929 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
930 &data->data.string.string,
931 &data->data.string.size);
934 struct notify2_message_table {
936 void (*fn)(struct spoolss_notify_msg *msg,
937 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
940 static struct notify2_message_table printer_notify_table[] = {
941 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
942 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
943 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
944 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
945 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
946 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
947 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
948 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
949 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
950 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
951 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
952 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
953 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
954 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
955 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
956 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
957 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
958 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
959 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
962 static struct notify2_message_table job_notify_table[] = {
963 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
964 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
965 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
966 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
967 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
968 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
969 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
970 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
971 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
972 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
973 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
974 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
975 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
976 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
977 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
978 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
979 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
980 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
981 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
982 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
983 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
984 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
985 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
986 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
990 /***********************************************************************
991 Allocate talloc context for container object
992 **********************************************************************/
994 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
999 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
1004 /***********************************************************************
1005 release all allocated memory and zero out structure
1006 **********************************************************************/
1008 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1014 talloc_destroy(ctr->ctx);
1021 /***********************************************************************
1022 **********************************************************************/
1024 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1032 /***********************************************************************
1033 **********************************************************************/
1035 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1037 if ( !ctr || !ctr->msg_groups )
1040 if ( idx >= ctr->num_groups )
1043 return &ctr->msg_groups[idx];
1047 /***********************************************************************
1048 How many groups of change messages do we have ?
1049 **********************************************************************/
1051 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1056 return ctr->num_groups;
1059 /***********************************************************************
1060 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1061 **********************************************************************/
1063 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
1065 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
1066 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
1067 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
1073 /* loop over all groups looking for a matching printer name */
1075 for ( i=0; i<ctr->num_groups; i++ ) {
1076 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
1080 /* add a new group? */
1082 if ( i == ctr->num_groups ) {
1085 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
1086 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1089 ctr->msg_groups = groups;
1091 /* clear the new entry and set the printer name */
1093 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
1094 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
1097 /* add the change messages; 'i' is the correct index now regardless */
1099 msg_grp = &ctr->msg_groups[i];
1101 msg_grp->num_msgs++;
1103 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
1104 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
1107 msg_grp->msgs = msg_list;
1109 new_slot = msg_grp->num_msgs-1;
1110 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
1112 /* need to allocate own copy of data */
1114 if ( msg->len != 0 )
1115 msg_grp->msgs[new_slot].notify.data = (char *)
1116 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
1118 return ctr->num_groups;
1121 static void construct_info_data(struct spoolss_Notify *info_data,
1122 enum spoolss_NotifyType type,
1123 uint16_t field, int id);
1125 /***********************************************************************
1126 Send a change notication message on all handles which have a call
1128 **********************************************************************/
1130 static int build_notify2_messages(TALLOC_CTX *mem_ctx,
1131 struct printer_handle *prn_hnd,
1132 SPOOLSS_NOTIFY_MSG *messages,
1134 struct spoolss_Notify **_notifies,
1137 struct spoolss_Notify *notifies;
1138 SPOOLSS_NOTIFY_MSG *msg;
1143 notifies = talloc_zero_array(mem_ctx,
1144 struct spoolss_Notify, num_msgs);
1149 for (i = 0; i < num_msgs; i++) {
1153 /* Are we monitoring this event? */
1155 if (!is_monitoring_event(prn_hnd, msg->type, msg->field)) {
1159 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1160 "for printer [%s]\n",
1161 msg->type, msg->field, prn_hnd->sharename));
1164 * if the is a printer notification handle and not a job
1165 * notification type, then set the id to 0.
1166 * Otherwise just use what was specified in the message.
1168 * When registering change notification on a print server
1169 * handle we always need to send back the id (snum) matching
1170 * the printer for which the change took place.
1171 * For change notify registered on a printer handle,
1172 * this does not matter and the id should be 0.
1177 if ((msg->type == PRINTER_NOTIFY_TYPE) &&
1178 (prn_hnd->printer_type == SPLHND_PRINTER)) {
1184 /* Convert unix jobid to smb jobid */
1186 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1187 id = sysjob_to_jobid(msg->id);
1190 DEBUG(3, ("no such unix jobid %d\n",
1196 construct_info_data(¬ifies[count],
1197 msg->type, msg->field, id);
1200 case PRINTER_NOTIFY_TYPE:
1201 if (printer_notify_table[msg->field].fn) {
1202 printer_notify_table[msg->field].fn(msg,
1203 ¬ifies[count], mem_ctx);
1207 case JOB_NOTIFY_TYPE:
1208 if (job_notify_table[msg->field].fn) {
1209 job_notify_table[msg->field].fn(msg,
1210 ¬ifies[count], mem_ctx);
1215 DEBUG(5, ("Unknown notification type %d\n",
1223 *_notifies = notifies;
1229 static int send_notify2_printer(TALLOC_CTX *mem_ctx,
1230 struct printer_handle *prn_hnd,
1231 SPOOLSS_NOTIFY_MSG_GROUP *msg_group)
1233 struct spoolss_Notify *notifies;
1235 union spoolss_ReplyPrinterInfo info;
1236 struct spoolss_NotifyInfo info0;
1237 uint32_t reply_result;
1242 /* Is there notification on this handle? */
1243 if (prn_hnd->notify.cli_chan == NULL ||
1244 prn_hnd->notify.cli_chan->active_connections == 0) {
1248 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1249 prn_hnd->servername, prn_hnd->sharename));
1251 /* For this printer? Print servers always receive notifications. */
1252 if ((prn_hnd->printer_type == SPLHND_PRINTER) &&
1253 (!strequal(msg_group->printername, prn_hnd->sharename))) {
1257 DEBUG(10,("Our printer\n"));
1259 /* build the array of change notifications */
1260 ret = build_notify2_messages(mem_ctx, prn_hnd,
1262 msg_group->num_msgs,
1268 info0.version = 0x2;
1269 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1270 info0.count = count;
1271 info0.notifies = notifies;
1273 info.info0 = &info0;
1275 status = dcerpc_spoolss_RouterReplyPrinterEx(
1276 prn_hnd->notify.cli_chan->binding_handle,
1278 &prn_hnd->notify.cli_hnd,
1279 prn_hnd->notify.change, /* color */
1280 prn_hnd->notify.flags,
1282 0, /* reply_type, must be 0 */
1284 if (!NT_STATUS_IS_OK(status)) {
1285 DEBUG(1, ("dcerpc_spoolss_RouterReplyPrinterEx to client: %s "
1287 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1288 nt_errstr(status)));
1289 werr = ntstatus_to_werror(status);
1290 } else if (!W_ERROR_IS_OK(werr)) {
1291 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1293 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1296 switch (reply_result) {
1299 case PRINTER_NOTIFY_INFO_DISCARDED:
1300 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1301 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1310 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1312 struct printer_handle *p;
1313 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
1314 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
1318 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1322 if (!msg_group->msgs) {
1323 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1327 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
1329 /* loop over all printers */
1331 for (p = printers_list; p; p = p->next) {
1332 ret = send_notify2_printer(mem_ctx, p, msg_group);
1339 DEBUG(8,("send_notify2_changes: Exit...\n"));
1343 /***********************************************************************
1344 **********************************************************************/
1346 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1349 uint32_t tv_sec, tv_usec;
1352 /* Unpack message */
1354 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1357 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1359 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1362 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1363 &msg->notify.value[0], &msg->notify.value[1]);
1365 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1366 &msg->len, &msg->notify.data);
1368 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1369 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1371 tv->tv_sec = tv_sec;
1372 tv->tv_usec = tv_usec;
1375 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1376 msg->notify.value[1]));
1378 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1383 /********************************************************************
1384 Receive a notify2 message list
1385 ********************************************************************/
1387 static void receive_notify2_message_list(struct messaging_context *msg,
1390 struct server_id server_id,
1393 size_t msg_count, i;
1394 char *buf = (char *)data->data;
1397 SPOOLSS_NOTIFY_MSG notify;
1398 SPOOLSS_NOTIFY_MSG_CTR messages;
1401 if (data->length < 4) {
1402 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1406 msg_count = IVAL(buf, 0);
1409 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1411 if (msg_count == 0) {
1412 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1416 /* initialize the container */
1418 ZERO_STRUCT( messages );
1419 notify_msg_ctr_init( &messages );
1422 * build message groups for each printer identified
1423 * in a change_notify msg. Remember that a PCN message
1424 * includes the handle returned for the srv_spoolss_replyopenprinter()
1425 * call. Therefore messages are grouped according to printer handle.
1428 for ( i=0; i<msg_count; i++ ) {
1429 struct timeval msg_tv;
1431 if (msg_ptr + 4 - buf > data->length) {
1432 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1436 msg_len = IVAL(msg_ptr,0);
1439 if (msg_ptr + msg_len - buf > data->length) {
1440 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1444 /* unpack messages */
1446 ZERO_STRUCT( notify );
1447 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1450 /* add to correct list in container */
1452 notify_msg_ctr_addmsg( &messages, ¬ify );
1454 /* free memory that might have been allocated by notify2_unpack_msg() */
1456 if ( notify.len != 0 )
1457 SAFE_FREE( notify.notify.data );
1460 /* process each group of messages */
1462 num_groups = notify_msg_ctr_numgroups( &messages );
1463 for ( i=0; i<num_groups; i++ )
1464 send_notify2_changes( &messages, i );
1469 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1470 (uint32_t)msg_count ));
1472 notify_msg_ctr_destroy( &messages );
1477 /********************************************************************
1478 Send a message to ourself about new driver being installed
1479 so we can upgrade the information for each printer bound to this
1481 ********************************************************************/
1483 static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
1484 struct messaging_context *msg_ctx)
1486 int len = strlen(drivername);
1491 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1494 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
1495 MSG_PRINTER_DRVUPGRADE,
1496 (uint8_t *)drivername, len+1);
1501 void srv_spoolss_cleanup(void)
1503 struct printer_session_counter *session_counter;
1505 for (session_counter = counter_list;
1506 session_counter != NULL;
1507 session_counter = counter_list) {
1508 DLIST_REMOVE(counter_list, session_counter);
1509 TALLOC_FREE(session_counter);
1513 /**********************************************************************
1514 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1515 over all printers, upgrading ones as necessary
1516 **********************************************************************/
1518 void do_drv_upgrade_printer(struct messaging_context *msg,
1521 struct server_id server_id,
1524 TALLOC_CTX *tmp_ctx;
1525 struct auth_serversupplied_info *server_info = NULL;
1526 struct spoolss_PrinterInfo2 *pinfo2;
1529 const char *drivername;
1531 int n_services = lp_numservices();
1533 tmp_ctx = talloc_new(NULL);
1534 if (!tmp_ctx) return;
1536 status = make_server_info_system(tmp_ctx, &server_info);
1537 if (!NT_STATUS_IS_OK(status)) {
1538 DEBUG(0, ("do_drv_upgrade_printer: "
1539 "Could not create system server_info\n"));
1543 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, data->length);
1545 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1549 DEBUG(10, ("do_drv_upgrade_printer: "
1550 "Got message for new driver [%s]\n", drivername));
1552 /* Iterate the printer list */
1554 for (snum = 0; snum < n_services; snum++) {
1555 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1559 /* ignore [printers] share */
1560 if (strequal(lp_const_servicename(snum), "printers")) {
1564 result = winreg_get_printer(tmp_ctx, server_info, msg,
1565 lp_const_servicename(snum),
1568 if (!W_ERROR_IS_OK(result)) {
1572 if (!pinfo2->drivername) {
1576 if (strcmp(drivername, pinfo2->drivername) != 0) {
1580 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1582 /* all we care about currently is the change_id */
1583 result = winreg_printer_update_changeid(tmp_ctx,
1586 pinfo2->printername);
1588 if (!W_ERROR_IS_OK(result)) {
1589 DEBUG(3, ("do_drv_upgrade_printer: "
1590 "Failed to update changeid [%s]\n",
1591 win_errstr(result)));
1597 talloc_free(tmp_ctx);
1600 /********************************************************************
1601 Update the cache for all printq's with a registered client
1603 ********************************************************************/
1605 void update_monitored_printq_cache(struct messaging_context *msg_ctx)
1607 struct printer_handle *printer = printers_list;
1610 /* loop through all printers and update the cache where
1611 a client is connected */
1613 if ((printer->printer_type == SPLHND_PRINTER) &&
1614 ((printer->notify.cli_chan != NULL) &&
1615 (printer->notify.cli_chan->active_connections > 0))) {
1616 snum = print_queue_snum(printer->sharename);
1617 print_queue_status(msg_ctx, snum, NULL, NULL);
1620 printer = printer->next;
1626 /****************************************************************
1627 _spoolss_OpenPrinter
1628 ****************************************************************/
1630 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1631 struct spoolss_OpenPrinter *r)
1633 struct spoolss_OpenPrinterEx e;
1636 ZERO_STRUCT(e.in.userlevel);
1638 e.in.printername = r->in.printername;
1639 e.in.datatype = r->in.datatype;
1640 e.in.devmode_ctr = r->in.devmode_ctr;
1641 e.in.access_mask = r->in.access_mask;
1644 e.out.handle = r->out.handle;
1646 werr = _spoolss_OpenPrinterEx(p, &e);
1648 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1649 /* OpenPrinterEx returns this for a bad
1650 * printer name. We must return WERR_INVALID_PRINTER_NAME
1653 werr = WERR_INVALID_PRINTER_NAME;
1659 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1660 struct spoolss_DeviceMode *orig,
1661 struct spoolss_DeviceMode **dest)
1663 struct spoolss_DeviceMode *dm;
1665 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1670 /* copy all values, then duplicate strings and structs */
1673 dm->devicename = talloc_strdup(dm, orig->devicename);
1674 if (!dm->devicename) {
1677 dm->formname = talloc_strdup(dm, orig->formname);
1678 if (!dm->formname) {
1681 if (orig->driverextra_data.data) {
1682 dm->driverextra_data.data =
1683 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1684 orig->driverextra_data.length);
1685 if (!dm->driverextra_data.data) {
1694 /****************************************************************
1695 _spoolss_OpenPrinterEx
1696 ****************************************************************/
1698 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1699 struct spoolss_OpenPrinterEx *r)
1702 struct printer_handle *Printer=NULL;
1705 if (!r->in.printername) {
1706 return WERR_INVALID_PARAM;
1709 if (r->in.level < 0 || r->in.level > 3) {
1710 return WERR_INVALID_PARAM;
1712 if ((r->in.level == 1 && !r->in.userlevel.level1) ||
1713 (r->in.level == 2 && !r->in.userlevel.level2) ||
1714 (r->in.level == 3 && !r->in.userlevel.level3)) {
1715 return WERR_INVALID_PARAM;
1718 /* some sanity check because you can open a printer or a print server */
1719 /* aka: \\server\printer or \\server */
1721 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1723 result = open_printer_hnd(p, r->out.handle, r->in.printername, 0);
1724 if (!W_ERROR_IS_OK(result)) {
1725 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1726 "for printer %s\n", r->in.printername));
1727 ZERO_STRUCTP(r->out.handle);
1731 Printer = find_printer_index_by_hnd(p, r->out.handle);
1733 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1734 "handle we created for printer %s\n", r->in.printername));
1735 close_printer_handle(p, r->out.handle);
1736 ZERO_STRUCTP(r->out.handle);
1737 return WERR_INVALID_PARAM;
1741 * First case: the user is opening the print server:
1743 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1744 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1746 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1747 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1748 * or if the user is listed in the smb.conf printer admin parameter.
1750 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1751 * client view printer folder, but does not show the MSAPW.
1753 * Note: this test needs code to check access rights here too. Jeremy
1754 * could you look at this?
1756 * Second case: the user is opening a printer:
1757 * NT doesn't let us connect to a printer if the connecting user
1758 * doesn't have print permission.
1760 * Third case: user is opening a Port Monitor
1761 * access checks same as opening a handle to the print server.
1764 switch (Printer->printer_type )
1767 case SPLHND_PORTMON_TCP:
1768 case SPLHND_PORTMON_LOCAL:
1769 /* Printserver handles use global struct... */
1773 /* Map standard access rights to object specific access rights */
1775 se_map_standard(&r->in.access_mask,
1776 &printserver_std_mapping);
1778 /* Deny any object specific bits that don't apply to print
1779 servers (i.e printer and job specific bits) */
1781 r->in.access_mask &= SEC_MASK_SPECIFIC;
1783 if (r->in.access_mask &
1784 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1785 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1786 close_printer_handle(p, r->out.handle);
1787 ZERO_STRUCTP(r->out.handle);
1788 return WERR_ACCESS_DENIED;
1791 /* Allow admin access */
1793 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1795 if (!lp_ms_add_printer_wizard()) {
1796 close_printer_handle(p, r->out.handle);
1797 ZERO_STRUCTP(r->out.handle);
1798 return WERR_ACCESS_DENIED;
1801 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1802 and not a printer admin, then fail */
1804 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1805 !security_token_has_privilege(p->server_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
1806 !nt_token_check_sid(&global_sid_Builtin_Print_Operators, p->server_info->security_token) &&
1807 !token_contains_name_in_list(
1808 uidtoname(p->server_info->utok.uid),
1809 p->server_info->info3->base.domain.string,
1811 p->server_info->security_token,
1812 lp_printer_admin(snum))) {
1813 close_printer_handle(p, r->out.handle);
1814 ZERO_STRUCTP(r->out.handle);
1815 DEBUG(3,("access DENIED as user is not root, "
1816 "has no printoperator privilege, "
1817 "not a member of the printoperator builtin group and "
1818 "is not in printer admin list"));
1819 return WERR_ACCESS_DENIED;
1822 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1826 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1829 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1830 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1832 /* We fall through to return WERR_OK */
1835 case SPLHND_PRINTER:
1836 /* NT doesn't let us connect to a printer if the connecting user
1837 doesn't have print permission. */
1839 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1840 close_printer_handle(p, r->out.handle);
1841 ZERO_STRUCTP(r->out.handle);
1845 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1846 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1849 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1851 /* map an empty access mask to the minimum access mask */
1852 if (r->in.access_mask == 0x0)
1853 r->in.access_mask = PRINTER_ACCESS_USE;
1856 * If we are not serving the printer driver for this printer,
1857 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1858 * will keep NT clients happy --jerry
1861 if (lp_use_client_driver(snum)
1862 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1864 r->in.access_mask = PRINTER_ACCESS_USE;
1867 /* check smb.conf parameters and the the sec_desc */
1869 if (!allow_access(lp_hostsdeny(snum), lp_hostsallow(snum),
1870 p->client_id->name, p->client_id->addr)) {
1871 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1872 ZERO_STRUCTP(r->out.handle);
1873 return WERR_ACCESS_DENIED;
1876 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1877 p->server_info->security_token, snum) ||
1878 !print_access_check(p->server_info,
1881 r->in.access_mask)) {
1882 DEBUG(3, ("access DENIED for printer open\n"));
1883 close_printer_handle(p, r->out.handle);
1884 ZERO_STRUCTP(r->out.handle);
1885 return WERR_ACCESS_DENIED;
1888 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1889 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1890 close_printer_handle(p, r->out.handle);
1891 ZERO_STRUCTP(r->out.handle);
1892 return WERR_ACCESS_DENIED;
1895 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1896 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1898 r->in.access_mask = PRINTER_ACCESS_USE;
1900 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1901 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1903 winreg_create_printer(p->mem_ctx,
1904 get_server_info_system(),
1906 lp_const_servicename(snum));
1911 /* sanity check to prevent programmer error */
1912 ZERO_STRUCTP(r->out.handle);
1916 Printer->access_granted = r->in.access_mask;
1919 * If the client sent a devmode in the OpenPrinter() call, then
1920 * save it here in case we get a job submission on this handle
1923 if ((Printer->printer_type != SPLHND_SERVER) &&
1924 r->in.devmode_ctr.devmode) {
1925 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1929 #if 0 /* JERRY -- I'm doubtful this is really effective */
1930 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1931 optimization in Windows 2000 clients --jerry */
1933 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1934 && (RA_WIN2K == get_remote_arch()) )
1936 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1937 sys_usleep( 500000 );
1944 /****************************************************************
1945 _spoolss_ClosePrinter
1946 ****************************************************************/
1948 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1949 struct spoolss_ClosePrinter *r)
1951 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1953 if (Printer && Printer->document_started) {
1954 struct spoolss_EndDocPrinter e;
1956 e.in.handle = r->in.handle;
1958 _spoolss_EndDocPrinter(p, &e);
1961 if (!close_printer_handle(p, r->in.handle))
1964 /* clear the returned printer handle. Observed behavior
1965 from Win2k server. Don't think this really matters.
1966 Previous code just copied the value of the closed
1969 ZERO_STRUCTP(r->out.handle);
1974 /****************************************************************
1975 _spoolss_DeletePrinter
1976 ****************************************************************/
1978 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1979 struct spoolss_DeletePrinter *r)
1981 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 (get_printer_snum(p, r->in.handle, &snum, NULL)) {
1994 winreg_delete_printer_key(p->mem_ctx,
1995 get_server_info_system(),
1997 lp_const_servicename(snum),
2001 result = delete_printer_handle(p, r->in.handle);
2006 /*******************************************************************
2007 * static function to lookup the version id corresponding to an
2008 * long architecture string
2009 ******************************************************************/
2011 static const struct print_architecture_table_node archi_table[]= {
2013 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
2014 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
2015 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
2016 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
2017 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
2018 {"Windows IA64", SPL_ARCH_IA64, 3 },
2019 {"Windows x64", SPL_ARCH_X64, 3 },
2023 static int get_version_id(const char *arch)
2027 for (i=0; archi_table[i].long_archi != NULL; i++)
2029 if (strcmp(arch, archi_table[i].long_archi) == 0)
2030 return (archi_table[i].version);
2036 /****************************************************************
2037 _spoolss_DeletePrinterDriver
2038 ****************************************************************/
2040 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
2041 struct spoolss_DeletePrinterDriver *r)
2044 struct spoolss_DriverInfo8 *info = NULL;
2045 struct spoolss_DriverInfo8 *info_win2k = NULL;
2049 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2050 and not a printer admin, then fail */
2052 if ( (p->server_info->utok.uid != sec_initial_uid())
2053 && !security_token_has_privilege(p->server_info->security_token, SEC_PRIV_PRINT_OPERATOR)
2054 && !token_contains_name_in_list(
2055 uidtoname(p->server_info->utok.uid),
2056 p->server_info->info3->base.domain.string,
2058 p->server_info->security_token,
2059 lp_printer_admin(-1)) )
2061 return WERR_ACCESS_DENIED;
2064 /* check that we have a valid driver name first */
2066 if ((version = get_version_id(r->in.architecture)) == -1)
2067 return WERR_INVALID_ENVIRONMENT;
2069 status = winreg_get_driver(p->mem_ctx,
2070 get_server_info_system(),
2072 r->in.architecture, r->in.driver,
2074 if (!W_ERROR_IS_OK(status)) {
2075 /* try for Win2k driver if "Windows NT x86" */
2077 if ( version == 2 ) {
2080 status = winreg_get_driver(p->mem_ctx,
2081 get_server_info_system(),
2086 if (!W_ERROR_IS_OK(status)) {
2087 status = WERR_UNKNOWN_PRINTER_DRIVER;
2091 /* otherwise it was a failure */
2093 status = WERR_UNKNOWN_PRINTER_DRIVER;
2099 if (printer_driver_in_use(p->mem_ctx,
2100 get_server_info_system(),
2103 status = WERR_PRINTER_DRIVER_IN_USE;
2108 status = winreg_get_driver(p->mem_ctx,
2109 get_server_info_system(),
2112 r->in.driver, 3, &info_win2k);
2113 if (W_ERROR_IS_OK(status)) {
2114 /* if we get to here, we now have 2 driver info structures to remove */
2115 /* remove the Win2k driver first*/
2117 status = winreg_del_driver(p->mem_ctx,
2118 get_server_info_system(),
2121 talloc_free(info_win2k);
2123 /* this should not have failed---if it did, report to client */
2124 if (!W_ERROR_IS_OK(status)) {
2130 status = winreg_del_driver(p->mem_ctx,
2131 get_server_info_system(),
2141 /****************************************************************
2142 _spoolss_DeletePrinterDriverEx
2143 ****************************************************************/
2145 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
2146 struct spoolss_DeletePrinterDriverEx *r)
2148 struct spoolss_DriverInfo8 *info = NULL;
2149 struct spoolss_DriverInfo8 *info_win2k = NULL;
2154 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2155 and not a printer admin, then fail */
2157 if ( (p->server_info->utok.uid != sec_initial_uid())
2158 && !security_token_has_privilege(p->server_info->security_token, SEC_PRIV_PRINT_OPERATOR)
2159 && !token_contains_name_in_list(
2160 uidtoname(p->server_info->utok.uid),
2161 p->server_info->info3->base.domain.string,
2163 p->server_info->security_token, lp_printer_admin(-1)) )
2165 return WERR_ACCESS_DENIED;
2168 /* check that we have a valid driver name first */
2169 if ((version = get_version_id(r->in.architecture)) == -1) {
2170 /* this is what NT returns */
2171 return WERR_INVALID_ENVIRONMENT;
2174 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2175 version = r->in.version;
2177 status = winreg_get_driver(p->mem_ctx,
2178 get_server_info_system(),
2184 if (!W_ERROR_IS_OK(status)) {
2185 status = WERR_UNKNOWN_PRINTER_DRIVER;
2188 * if the client asked for a specific version,
2189 * or this is something other than Windows NT x86,
2193 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2196 /* try for Win2k driver if "Windows NT x86" */
2199 status = winreg_get_driver(info,
2200 get_server_info_system(),
2205 if (!W_ERROR_IS_OK(status)) {
2206 status = WERR_UNKNOWN_PRINTER_DRIVER;
2211 if (printer_driver_in_use(info,
2212 get_server_info_system(),
2215 status = WERR_PRINTER_DRIVER_IN_USE;
2220 * we have a couple of cases to consider.
2221 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2222 * then the delete should fail if **any** files overlap with
2224 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2225 * non-overlapping files
2226 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2227 * is set, the do not delete any files
2228 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2231 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2233 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2236 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2237 printer_driver_files_in_use(info,
2238 get_server_info_system(),
2241 /* no idea of the correct error here */
2242 status = WERR_ACCESS_DENIED;
2247 /* also check for W32X86/3 if necessary; maybe we already have? */
2249 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2250 status = winreg_get_driver(info,
2251 get_server_info_system(),
2254 r->in.driver, 3, &info_win2k);
2255 if (W_ERROR_IS_OK(status)) {
2258 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2259 printer_driver_files_in_use(info,
2260 get_server_info_system(),
2263 /* no idea of the correct error here */
2264 talloc_free(info_win2k);
2265 status = WERR_ACCESS_DENIED;
2269 /* if we get to here, we now have 2 driver info structures to remove */
2270 /* remove the Win2k driver first*/
2272 status = winreg_del_driver(info,
2273 get_server_info_system(),
2278 /* this should not have failed---if it did, report to client */
2280 if (!W_ERROR_IS_OK(status)) {
2285 * now delete any associated files if delete_files is
2286 * true. Even if this part failes, we return succes
2287 * because the driver doesn not exist any more
2290 delete_driver_files(get_server_info_system(),
2296 status = winreg_del_driver(info,
2297 get_server_info_system(),
2301 if (!W_ERROR_IS_OK(status)) {
2306 * now delete any associated files if delete_files is
2307 * true. Even if this part failes, we return succes
2308 * because the driver doesn not exist any more
2311 delete_driver_files(get_server_info_system(), info);
2320 /********************************************************************
2321 GetPrinterData on a printer server Handle.
2322 ********************************************************************/
2324 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2326 enum winreg_Type *type,
2327 union spoolss_PrinterData *data)
2329 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2331 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2337 if (!StrCaseCmp(value, "BeepEnabled")) {
2343 if (!StrCaseCmp(value, "EventLog")) {
2345 /* formally was 0x1b */
2350 if (!StrCaseCmp(value, "NetPopup")) {
2356 if (!StrCaseCmp(value, "MajorVersion")) {
2359 /* Windows NT 4.0 seems to not allow uploading of drivers
2360 to a server that reports 0x3 as the MajorVersion.
2361 need to investigate more how Win2k gets around this .
2364 if (RA_WINNT == get_remote_arch()) {
2373 if (!StrCaseCmp(value, "MinorVersion")) {
2380 * uint32_t size = 0x114
2381 * uint32_t major = 5
2382 * uint32_t minor = [0|1]
2383 * uint32_t build = [2195|2600]
2384 * extra unicode string = e.g. "Service Pack 3"
2386 if (!StrCaseCmp(value, "OSVersion")) {
2388 enum ndr_err_code ndr_err;
2389 struct spoolss_OSVersion os;
2391 os.major = 5; /* Windows 2000 == 5.0 */
2393 os.build = 2195; /* build */
2394 os.extra_string = ""; /* leave extra string empty */
2396 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2397 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2398 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2399 return WERR_GENERAL_FAILURE;
2403 data->binary = blob;
2409 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2412 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2413 W_ERROR_HAVE_NO_MEMORY(data->string);
2418 if (!StrCaseCmp(value, "Architecture")) {
2420 data->string = talloc_strdup(mem_ctx,
2421 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2422 W_ERROR_HAVE_NO_MEMORY(data->string);
2427 if (!StrCaseCmp(value, "DsPresent")) {
2430 /* only show the publish check box if we are a
2431 member of a AD domain */
2433 if (lp_security() == SEC_ADS) {
2441 if (!StrCaseCmp(value, "DNSMachineName")) {
2442 const char *hostname = get_mydnsfullname();
2445 return WERR_BADFILE;
2449 data->string = talloc_strdup(mem_ctx, hostname);
2450 W_ERROR_HAVE_NO_MEMORY(data->string);
2457 return WERR_INVALID_PARAM;
2460 /****************************************************************
2461 _spoolss_GetPrinterData
2462 ****************************************************************/
2464 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2465 struct spoolss_GetPrinterData *r)
2467 struct spoolss_GetPrinterDataEx r2;
2469 r2.in.handle = r->in.handle;
2470 r2.in.key_name = "PrinterDriverData";
2471 r2.in.value_name = r->in.value_name;
2472 r2.in.offered = r->in.offered;
2473 r2.out.type = r->out.type;
2474 r2.out.data = r->out.data;
2475 r2.out.needed = r->out.needed;
2477 return _spoolss_GetPrinterDataEx(p, &r2);
2480 /*********************************************************
2481 Connect to the client machine.
2482 **********************************************************/
2484 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2485 struct sockaddr_storage *client_ss, const char *remote_machine)
2488 struct cli_state *the_cli;
2489 struct sockaddr_storage rm_addr;
2490 char addr[INET6_ADDRSTRLEN];
2492 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2493 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2495 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2496 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2499 print_sockaddr(addr, sizeof(addr), &rm_addr);
2501 rm_addr = *client_ss;
2502 print_sockaddr(addr, sizeof(addr), &rm_addr);
2503 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2507 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2508 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2513 /* setup the connection */
2514 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2515 &rm_addr, 0, "IPC$", "IPC",
2519 0, lp_client_signing());
2521 if ( !NT_STATUS_IS_OK( ret ) ) {
2522 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2527 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2528 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2529 cli_shutdown(the_cli);
2534 * Ok - we have an anonymous connection to the IPC$ share.
2535 * Now start the NT Domain stuff :-).
2538 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2539 if (!NT_STATUS_IS_OK(ret)) {
2540 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2541 remote_machine, nt_errstr(ret)));
2542 cli_shutdown(the_cli);
2549 /***************************************************************************
2550 Connect to the client.
2551 ****************************************************************************/
2553 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2554 uint32_t localprinter,
2555 enum winreg_Type type,
2556 struct policy_handle *handle,
2557 struct notify_back_channel **_chan,
2558 struct sockaddr_storage *client_ss,
2559 struct messaging_context *msg_ctx)
2563 struct notify_back_channel *chan;
2565 for (chan = back_channels; chan; chan = chan->next) {
2566 if (memcmp(&chan->client_address, client_ss,
2567 sizeof(struct sockaddr_storage)) == 0) {
2573 * If it's the first connection, contact the client
2574 * and connect to the IPC$ share anonymously
2577 fstring unix_printer;
2579 /* the +2 is to strip the leading 2 backslashs */
2580 fstrcpy(unix_printer, printer + 2);
2582 chan = talloc_zero(back_channels, struct notify_back_channel);
2586 chan->client_address = *client_ss;
2588 if (!spoolss_connect_to_client(&chan->cli_pipe, client_ss, unix_printer)) {
2592 chan->binding_handle = chan->cli_pipe->binding_handle;
2594 DLIST_ADD(back_channels, chan);
2596 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2597 receive_notify2_message_list);
2598 /* Tell the connections db we're now interested in printer
2599 * notify messages. */
2600 serverid_register_msg_flags(messaging_server_id(msg_ctx),
2601 true, FLAG_MSG_PRINT_NOTIFY);
2605 * Tell the specific printing tdb we want messages for this printer
2606 * by registering our PID.
2609 if (!print_notify_register_pid(snum)) {
2610 DEBUG(0, ("Failed to register our pid for printer %s\n",
2614 status = dcerpc_spoolss_ReplyOpenPrinter(chan->binding_handle,
2623 if (!NT_STATUS_IS_OK(status)) {
2624 DEBUG(5, ("dcerpc_spoolss_ReplyOpenPrinter returned [%s]\n", nt_errstr(status)));
2625 result = ntstatus_to_werror(status);
2626 } else if (!W_ERROR_IS_OK(result)) {
2627 DEBUG(5, ("ReplyOpenPrinter returned [%s]\n", win_errstr(result)));
2630 chan->active_connections++;
2633 return (W_ERROR_IS_OK(result));
2636 /****************************************************************
2637 ****************************************************************/
2639 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2640 const struct spoolss_NotifyOption *r)
2642 struct spoolss_NotifyOption *option;
2649 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2656 if (!option->count) {
2660 option->types = talloc_zero_array(option,
2661 struct spoolss_NotifyOptionType, option->count);
2662 if (!option->types) {
2663 talloc_free(option);
2667 for (i=0; i < option->count; i++) {
2668 option->types[i] = r->types[i];
2670 if (option->types[i].count) {
2671 option->types[i].fields = talloc_zero_array(option,
2672 union spoolss_Field, option->types[i].count);
2673 if (!option->types[i].fields) {
2674 talloc_free(option);
2677 for (k=0; k<option->types[i].count; k++) {
2678 option->types[i].fields[k] =
2679 r->types[i].fields[k];
2687 /****************************************************************
2688 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2690 * before replying OK: status=0 a rpc call is made to the workstation
2691 * asking ReplyOpenPrinter
2693 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2694 * called from api_spoolss_rffpcnex
2695 ****************************************************************/
2697 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2698 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2701 struct spoolss_NotifyOption *option = r->in.notify_options;
2702 struct sockaddr_storage client_ss;
2704 /* store the notify value in the printer struct */
2706 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2709 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2710 "Invalid handle (%s:%u:%u).\n",
2711 OUR_HANDLE(r->in.handle)));
2715 Printer->notify.flags = r->in.flags;
2716 Printer->notify.options = r->in.options;
2717 Printer->notify.printerlocal = r->in.printer_local;
2718 Printer->notify.msg_ctx = p->msg_ctx;
2720 TALLOC_FREE(Printer->notify.option);
2721 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2723 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2725 /* Connect to the client machine and send a ReplyOpenPrinter */
2727 if ( Printer->printer_type == SPLHND_SERVER)
2729 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2730 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2733 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2734 "client_address is %s\n", p->client_id->addr));
2736 if (!interpret_string_addr(&client_ss, p->client_id->addr,
2738 return WERR_SERVER_UNAVAILABLE;
2741 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2742 Printer->notify.printerlocal, REG_SZ,
2743 &Printer->notify.cli_hnd,
2744 &Printer->notify.cli_chan,
2745 &client_ss, p->msg_ctx)) {
2746 return WERR_SERVER_UNAVAILABLE;
2752 /*******************************************************************
2753 * fill a notify_info_data with the servername
2754 ********************************************************************/
2756 static void spoolss_notify_server_name(struct messaging_context *msg_ctx,
2758 struct spoolss_Notify *data,
2759 print_queue_struct *queue,
2760 struct spoolss_PrinterInfo2 *pinfo2,
2761 TALLOC_CTX *mem_ctx)
2763 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2766 /*******************************************************************
2767 * fill a notify_info_data with the printername (not including the servername).
2768 ********************************************************************/
2770 static void spoolss_notify_printer_name(struct messaging_context *msg_ctx,
2772 struct spoolss_Notify *data,
2773 print_queue_struct *queue,
2774 struct spoolss_PrinterInfo2 *pinfo2,
2775 TALLOC_CTX *mem_ctx)
2777 /* the notify name should not contain the \\server\ part */
2778 const char *p = strrchr(pinfo2->printername, '\\');
2781 p = pinfo2->printername;
2786 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2789 /*******************************************************************
2790 * fill a notify_info_data with the servicename
2791 ********************************************************************/
2793 static void spoolss_notify_share_name(struct messaging_context *msg_ctx,
2795 struct spoolss_Notify *data,
2796 print_queue_struct *queue,
2797 struct spoolss_PrinterInfo2 *pinfo2,
2798 TALLOC_CTX *mem_ctx)
2800 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2803 /*******************************************************************
2804 * fill a notify_info_data with the port name
2805 ********************************************************************/
2807 static void spoolss_notify_port_name(struct messaging_context *msg_ctx,
2809 struct spoolss_Notify *data,
2810 print_queue_struct *queue,
2811 struct spoolss_PrinterInfo2 *pinfo2,
2812 TALLOC_CTX *mem_ctx)
2814 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2817 /*******************************************************************
2818 * fill a notify_info_data with the printername
2819 * but it doesn't exist, have to see what to do
2820 ********************************************************************/
2822 static void spoolss_notify_driver_name(struct messaging_context *msg_ctx,
2824 struct spoolss_Notify *data,
2825 print_queue_struct *queue,
2826 struct spoolss_PrinterInfo2 *pinfo2,
2827 TALLOC_CTX *mem_ctx)
2829 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2832 /*******************************************************************
2833 * fill a notify_info_data with the comment
2834 ********************************************************************/
2836 static void spoolss_notify_comment(struct messaging_context *msg_ctx,
2838 struct spoolss_Notify *data,
2839 print_queue_struct *queue,
2840 struct spoolss_PrinterInfo2 *pinfo2,
2841 TALLOC_CTX *mem_ctx)
2845 if (*pinfo2->comment == '\0') {
2846 p = lp_comment(snum);
2848 p = pinfo2->comment;
2851 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2854 /*******************************************************************
2855 * fill a notify_info_data with the comment
2856 * location = "Room 1, floor 2, building 3"
2857 ********************************************************************/
2859 static void spoolss_notify_location(struct messaging_context *msg_ctx,
2861 struct spoolss_Notify *data,
2862 print_queue_struct *queue,
2863 struct spoolss_PrinterInfo2 *pinfo2,
2864 TALLOC_CTX *mem_ctx)
2866 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
2869 /*******************************************************************
2870 * fill a notify_info_data with the device mode
2871 * jfm:xxxx don't to it for know but that's a real problem !!!
2872 ********************************************************************/
2874 static void spoolss_notify_devmode(struct messaging_context *msg_ctx,
2876 struct spoolss_Notify *data,
2877 print_queue_struct *queue,
2878 struct spoolss_PrinterInfo2 *pinfo2,
2879 TALLOC_CTX *mem_ctx)
2881 /* for a dummy implementation we have to zero the fields */
2882 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2885 /*******************************************************************
2886 * fill a notify_info_data with the separator file name
2887 ********************************************************************/
2889 static void spoolss_notify_sepfile(struct messaging_context *msg_ctx,
2891 struct spoolss_Notify *data,
2892 print_queue_struct *queue,
2893 struct spoolss_PrinterInfo2 *pinfo2,
2894 TALLOC_CTX *mem_ctx)
2896 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2899 /*******************************************************************
2900 * fill a notify_info_data with the print processor
2901 * jfm:xxxx return always winprint to indicate we don't do anything to it
2902 ********************************************************************/
2904 static void spoolss_notify_print_processor(struct messaging_context *msg_ctx,
2906 struct spoolss_Notify *data,
2907 print_queue_struct *queue,
2908 struct spoolss_PrinterInfo2 *pinfo2,
2909 TALLOC_CTX *mem_ctx)
2911 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2914 /*******************************************************************
2915 * fill a notify_info_data with the print processor options
2916 * jfm:xxxx send an empty string
2917 ********************************************************************/
2919 static void spoolss_notify_parameters(struct messaging_context *msg_ctx,
2921 struct spoolss_Notify *data,
2922 print_queue_struct *queue,
2923 struct spoolss_PrinterInfo2 *pinfo2,
2924 TALLOC_CTX *mem_ctx)
2926 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2929 /*******************************************************************
2930 * fill a notify_info_data with the data type
2931 * jfm:xxxx always send RAW as data type
2932 ********************************************************************/
2934 static void spoolss_notify_datatype(struct messaging_context *msg_ctx,
2936 struct spoolss_Notify *data,
2937 print_queue_struct *queue,
2938 struct spoolss_PrinterInfo2 *pinfo2,
2939 TALLOC_CTX *mem_ctx)
2941 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2944 /*******************************************************************
2945 * fill a notify_info_data with the security descriptor
2946 * jfm:xxxx send an null pointer to say no security desc
2947 * have to implement security before !
2948 ********************************************************************/
2950 static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
2952 struct spoolss_Notify *data,
2953 print_queue_struct *queue,
2954 struct spoolss_PrinterInfo2 *pinfo2,
2955 TALLOC_CTX *mem_ctx)
2957 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2960 /*******************************************************************
2961 * fill a notify_info_data with the attributes
2962 * jfm:xxxx a samba printer is always shared
2963 ********************************************************************/
2965 static void spoolss_notify_attributes(struct messaging_context *msg_ctx,
2967 struct spoolss_Notify *data,
2968 print_queue_struct *queue,
2969 struct spoolss_PrinterInfo2 *pinfo2,
2970 TALLOC_CTX *mem_ctx)
2972 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2975 /*******************************************************************
2976 * fill a notify_info_data with the priority
2977 ********************************************************************/
2979 static void spoolss_notify_priority(struct messaging_context *msg_ctx,
2981 struct spoolss_Notify *data,
2982 print_queue_struct *queue,
2983 struct spoolss_PrinterInfo2 *pinfo2,
2984 TALLOC_CTX *mem_ctx)
2986 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2989 /*******************************************************************
2990 * fill a notify_info_data with the default priority
2991 ********************************************************************/
2993 static void spoolss_notify_default_priority(struct messaging_context *msg_ctx,
2995 struct spoolss_Notify *data,
2996 print_queue_struct *queue,
2997 struct spoolss_PrinterInfo2 *pinfo2,
2998 TALLOC_CTX *mem_ctx)
3000 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
3003 /*******************************************************************
3004 * fill a notify_info_data with the start time
3005 ********************************************************************/
3007 static void spoolss_notify_start_time(struct messaging_context *msg_ctx,
3009 struct spoolss_Notify *data,
3010 print_queue_struct *queue,
3011 struct spoolss_PrinterInfo2 *pinfo2,
3012 TALLOC_CTX *mem_ctx)
3014 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
3017 /*******************************************************************
3018 * fill a notify_info_data with the until time
3019 ********************************************************************/
3021 static void spoolss_notify_until_time(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->untiltime);
3031 /*******************************************************************
3032 * fill a notify_info_data with the status
3033 ********************************************************************/
3035 static void spoolss_notify_status(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 print_status_struct status;
3044 print_queue_length(msg_ctx, snum, &status);
3045 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3048 /*******************************************************************
3049 * fill a notify_info_data with the number of jobs queued
3050 ********************************************************************/
3052 static void spoolss_notify_cjobs(struct messaging_context *msg_ctx,
3054 struct spoolss_Notify *data,
3055 print_queue_struct *queue,
3056 struct spoolss_PrinterInfo2 *pinfo2,
3057 TALLOC_CTX *mem_ctx)
3059 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3060 data, print_queue_length(msg_ctx, snum, NULL));
3063 /*******************************************************************
3064 * fill a notify_info_data with the average ppm
3065 ********************************************************************/
3067 static void spoolss_notify_average_ppm(struct messaging_context *msg_ctx,
3069 struct spoolss_Notify *data,
3070 print_queue_struct *queue,
3071 struct spoolss_PrinterInfo2 *pinfo2,
3072 TALLOC_CTX *mem_ctx)
3074 /* always respond 8 pages per minutes */
3075 /* a little hard ! */
3076 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
3079 /*******************************************************************
3080 * fill a notify_info_data with username
3081 ********************************************************************/
3083 static void spoolss_notify_username(struct messaging_context *msg_ctx,
3085 struct spoolss_Notify *data,
3086 print_queue_struct *queue,
3087 struct spoolss_PrinterInfo2 *pinfo2,
3088 TALLOC_CTX *mem_ctx)
3090 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3093 /*******************************************************************
3094 * fill a notify_info_data with job status
3095 ********************************************************************/
3097 static void spoolss_notify_job_status(struct messaging_context *msg_ctx,
3099 struct spoolss_Notify *data,
3100 print_queue_struct *queue,
3101 struct spoolss_PrinterInfo2 *pinfo2,
3102 TALLOC_CTX *mem_ctx)
3104 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3107 /*******************************************************************
3108 * fill a notify_info_data with job name
3109 ********************************************************************/
3111 static void spoolss_notify_job_name(struct messaging_context *msg_ctx,
3113 struct spoolss_Notify *data,
3114 print_queue_struct *queue,
3115 struct spoolss_PrinterInfo2 *pinfo2,
3116 TALLOC_CTX *mem_ctx)
3118 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3121 /*******************************************************************
3122 * fill a notify_info_data with job status
3123 ********************************************************************/
3125 static void spoolss_notify_job_status_string(struct messaging_context *msg_ctx,
3127 struct spoolss_Notify *data,
3128 print_queue_struct *queue,
3129 struct spoolss_PrinterInfo2 *pinfo2,
3130 TALLOC_CTX *mem_ctx)
3133 * Now we're returning job status codes we just return a "" here. JRA.
3138 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3141 switch (queue->status) {
3146 p = ""; /* NT provides the paused string */
3155 #endif /* NO LONGER NEEDED. */
3157 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3160 /*******************************************************************
3161 * fill a notify_info_data with job time
3162 ********************************************************************/
3164 static void spoolss_notify_job_time(struct messaging_context *msg_ctx,
3166 struct spoolss_Notify *data,
3167 print_queue_struct *queue,
3168 struct spoolss_PrinterInfo2 *pinfo2,
3169 TALLOC_CTX *mem_ctx)
3171 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3174 /*******************************************************************
3175 * fill a notify_info_data with job size
3176 ********************************************************************/
3178 static void spoolss_notify_job_size(struct messaging_context *msg_ctx,
3180 struct spoolss_Notify *data,
3181 print_queue_struct *queue,
3182 struct spoolss_PrinterInfo2 *pinfo2,
3183 TALLOC_CTX *mem_ctx)
3185 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3188 /*******************************************************************
3189 * fill a notify_info_data with page info
3190 ********************************************************************/
3191 static void spoolss_notify_total_pages(struct messaging_context *msg_ctx,
3193 struct spoolss_Notify *data,
3194 print_queue_struct *queue,
3195 struct spoolss_PrinterInfo2 *pinfo2,
3196 TALLOC_CTX *mem_ctx)
3198 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3201 /*******************************************************************
3202 * fill a notify_info_data with pages printed info.
3203 ********************************************************************/
3204 static void spoolss_notify_pages_printed(struct messaging_context *msg_ctx,
3206 struct spoolss_Notify *data,
3207 print_queue_struct *queue,
3208 struct spoolss_PrinterInfo2 *pinfo2,
3209 TALLOC_CTX *mem_ctx)
3211 /* Add code when back-end tracks this */
3212 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3215 /*******************************************************************
3216 Fill a notify_info_data with job position.
3217 ********************************************************************/
3219 static void spoolss_notify_job_position(struct messaging_context *msg_ctx,
3221 struct spoolss_Notify *data,
3222 print_queue_struct *queue,
3223 struct spoolss_PrinterInfo2 *pinfo2,
3224 TALLOC_CTX *mem_ctx)
3226 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3229 /*******************************************************************
3230 Fill a notify_info_data with submitted time.
3231 ********************************************************************/
3233 static void spoolss_notify_submitted_time(struct messaging_context *msg_ctx,
3235 struct spoolss_Notify *data,
3236 print_queue_struct *queue,
3237 struct spoolss_PrinterInfo2 *pinfo2,
3238 TALLOC_CTX *mem_ctx)
3240 data->data.string.string = NULL;
3241 data->data.string.size = 0;
3243 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3244 &data->data.string.string,
3245 &data->data.string.size);
3249 struct s_notify_info_data_table
3251 enum spoolss_NotifyType type;
3254 enum spoolss_NotifyTable variable_type;
3255 void (*fn) (struct messaging_context *msg_ctx,
3256 int snum, struct spoolss_Notify *data,
3257 print_queue_struct *queue,
3258 struct spoolss_PrinterInfo2 *pinfo2,
3259 TALLOC_CTX *mem_ctx);
3262 /* A table describing the various print notification constants and
3263 whether the notification data is a pointer to a variable sized
3264 buffer, a one value uint32_t or a two value uint32_t. */
3266 static const struct s_notify_info_data_table notify_info_data_table[] =
3268 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3269 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3270 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3271 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3272 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3273 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3274 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3275 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3276 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3277 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3278 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3279 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3280 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3281 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3282 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3283 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3284 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3285 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3286 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3287 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3288 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3289 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3290 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3291 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3292 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3293 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3294 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3295 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3296 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3297 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3298 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3299 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3300 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3301 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3302 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3303 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3304 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3305 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3306 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3307 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3308 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3309 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3310 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3311 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3312 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3313 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3314 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3315 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3316 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3319 /*******************************************************************
3320 Return the variable_type of info_data structure.
3321 ********************************************************************/
3323 static enum spoolss_NotifyTable variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3328 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3329 if ( (notify_info_data_table[i].type == type) &&
3330 (notify_info_data_table[i].field == field) ) {
3331 return notify_info_data_table[i].variable_type;
3335 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3337 return (enum spoolss_NotifyTable) 0;
3340 /****************************************************************************
3341 ****************************************************************************/
3343 static bool search_notify(enum spoolss_NotifyType type,
3349 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3350 if (notify_info_data_table[i].type == type &&
3351 notify_info_data_table[i].field == field &&
3352 notify_info_data_table[i].fn != NULL) {
3361 /****************************************************************************
3362 ****************************************************************************/
3364 static void construct_info_data(struct spoolss_Notify *info_data,
3365 enum spoolss_NotifyType type,
3366 uint16_t field, int id)
3368 info_data->type = type;
3369 info_data->field.field = field;
3370 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3371 info_data->job_id = id;
3374 /*******************************************************************
3376 * fill a notify_info struct with info asked
3378 ********************************************************************/
3380 static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
3381 struct printer_handle *print_hnd,
3382 struct spoolss_NotifyInfo *info,
3383 struct spoolss_PrinterInfo2 *pinfo2,
3385 const struct spoolss_NotifyOptionType *option_type,
3387 TALLOC_CTX *mem_ctx)
3390 enum spoolss_NotifyType type;
3393 struct spoolss_Notify *current_data;
3394 print_queue_struct *queue=NULL;
3396 type = option_type->type;
3398 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3399 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3400 option_type->count, lp_servicename(snum)));
3402 for(field_num=0; field_num < option_type->count; field_num++) {
3403 field = option_type->fields[field_num].field;
3405 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3407 if (!search_notify(type, field, &j) )
3410 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3411 struct spoolss_Notify,
3413 if (info->notifies == NULL) {
3414 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3418 current_data = &info->notifies[info->count];
3420 construct_info_data(current_data, type, field, id);
3422 DEBUG(10, ("construct_notify_printer_info: "
3423 "calling [%s] snum=%d printername=[%s])\n",
3424 notify_info_data_table[j].name, snum,
3425 pinfo2->printername));
3427 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3428 queue, pinfo2, mem_ctx);
3436 /*******************************************************************
3438 * fill a notify_info struct with info asked
3440 ********************************************************************/
3442 static bool construct_notify_jobs_info(struct messaging_context *msg_ctx,
3443 print_queue_struct *queue,
3444 struct spoolss_NotifyInfo *info,
3445 struct spoolss_PrinterInfo2 *pinfo2,
3447 const struct spoolss_NotifyOptionType *option_type,
3449 TALLOC_CTX *mem_ctx)
3452 enum spoolss_NotifyType type;
3454 struct spoolss_Notify *current_data;
3456 DEBUG(4,("construct_notify_jobs_info\n"));
3458 type = option_type->type;
3460 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3461 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3462 option_type->count));
3464 for(field_num=0; field_num<option_type->count; field_num++) {
3465 field = option_type->fields[field_num].field;
3467 if (!search_notify(type, field, &j) )
3470 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3471 struct spoolss_Notify,
3473 if (info->notifies == NULL) {
3474 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3478 current_data=&(info->notifies[info->count]);
3480 construct_info_data(current_data, type, field, id);
3481 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3482 queue, pinfo2, mem_ctx);
3490 * JFM: The enumeration is not that simple, it's even non obvious.
3492 * let's take an example: I want to monitor the PRINTER SERVER for
3493 * the printer's name and the number of jobs currently queued.
3494 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3495 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3497 * I have 3 printers on the back of my server.
3499 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3502 * 1 printer 1 name 1
3503 * 2 printer 1 cjob 1
3504 * 3 printer 2 name 2
3505 * 4 printer 2 cjob 2
3506 * 5 printer 3 name 3
3507 * 6 printer 3 name 3
3509 * that's the print server case, the printer case is even worse.
3512 /*******************************************************************
3514 * enumerate all printers on the printserver
3515 * fill a notify_info struct with info asked
3517 ********************************************************************/
3519 static WERROR printserver_notify_info(struct pipes_struct *p,
3520 struct policy_handle *hnd,
3521 struct spoolss_NotifyInfo *info,
3522 TALLOC_CTX *mem_ctx)
3525 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3526 int n_services=lp_numservices();
3528 struct spoolss_NotifyOption *option;
3529 struct spoolss_NotifyOptionType option_type;
3530 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3533 DEBUG(4,("printserver_notify_info\n"));
3538 option = Printer->notify.option;
3541 info->notifies = NULL;
3544 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3545 sending a ffpcn() request first */
3550 for (i=0; i<option->count; i++) {
3551 option_type = option->types[i];
3553 if (option_type.type != PRINTER_NOTIFY_TYPE)
3556 for (snum = 0; snum < n_services; snum++) {
3557 if (!lp_browseable(snum) ||
3558 !lp_snum_ok(snum) ||
3559 !lp_print_ok(snum)) {
3560 continue; /* skip */
3563 /* Maybe we should use the SYSTEM server_info here... */
3564 result = winreg_get_printer(mem_ctx,
3565 get_server_info_system(),
3567 lp_servicename(snum),
3569 if (!W_ERROR_IS_OK(result)) {
3570 DEBUG(4, ("printserver_notify_info: "
3571 "Failed to get printer [%s]\n",
3572 lp_servicename(snum)));
3577 construct_notify_printer_info(p->msg_ctx,
3583 TALLOC_FREE(pinfo2);
3589 * Debugging information, don't delete.
3592 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3593 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3594 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3596 for (i=0; i<info->count; i++) {
3597 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3598 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3599 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3606 /*******************************************************************
3608 * fill a notify_info struct with info asked
3610 ********************************************************************/
3612 static WERROR printer_notify_info(struct pipes_struct *p,
3613 struct policy_handle *hnd,
3614 struct spoolss_NotifyInfo *info,
3615 TALLOC_CTX *mem_ctx)
3618 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3621 struct spoolss_NotifyOption *option;
3622 struct spoolss_NotifyOptionType option_type;
3624 print_queue_struct *queue=NULL;
3625 print_status_struct status;
3626 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3629 DEBUG(4,("printer_notify_info\n"));
3634 option = Printer->notify.option;
3638 info->notifies = NULL;
3641 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3642 sending a ffpcn() request first */
3647 get_printer_snum(p, hnd, &snum, NULL);
3649 /* Maybe we should use the SYSTEM server_info here... */
3650 result = winreg_get_printer(mem_ctx,
3651 get_server_info_system(),
3653 lp_servicename(snum), &pinfo2);
3654 if (!W_ERROR_IS_OK(result)) {
3658 for (i=0; i<option->count; i++) {
3659 option_type = option->types[i];
3661 switch (option_type.type) {
3662 case PRINTER_NOTIFY_TYPE:
3663 if (construct_notify_printer_info(p->msg_ctx,
3672 case JOB_NOTIFY_TYPE:
3674 count = print_queue_status(p->msg_ctx, snum, &queue,
3677 for (j=0; j<count; j++) {
3678 construct_notify_jobs_info(p->msg_ctx,
3692 * Debugging information, don't delete.
3695 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3696 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3697 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3699 for (i=0; i<info->count; i++) {
3700 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3701 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3702 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3706 talloc_free(pinfo2);
3710 /****************************************************************
3711 _spoolss_RouterRefreshPrinterChangeNotify
3712 ****************************************************************/
3714 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3715 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3717 struct spoolss_NotifyInfo *info;
3719 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
3720 WERROR result = WERR_BADFID;
3722 /* we always have a spoolss_NotifyInfo struct */
3723 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3725 result = WERR_NOMEM;
3729 *r->out.info = info;
3732 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3733 "Invalid handle (%s:%u:%u).\n",
3734 OUR_HANDLE(r->in.handle)));
3738 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3741 * We are now using the change value, and
3742 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3743 * I don't have a global notification system, I'm sending back all the
3744 * informations even when _NOTHING_ has changed.
3747 /* We need to keep track of the change value to send back in
3748 RRPCN replies otherwise our updates are ignored. */
3750 Printer->notify.fnpcn = true;
3752 if (Printer->notify.cli_chan != NULL &&
3753 Printer->notify.cli_chan->active_connections > 0) {
3754 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3755 "Saving change value in request [%x]\n",
3757 Printer->notify.change = r->in.change_low;
3760 /* just ignore the spoolss_NotifyOption */
3762 switch (Printer->printer_type) {
3764 result = printserver_notify_info(p, r->in.handle,
3768 case SPLHND_PRINTER:
3769 result = printer_notify_info(p, r->in.handle,
3774 Printer->notify.fnpcn = false;
3780 /********************************************************************
3781 ********************************************************************/
3783 static WERROR create_printername(TALLOC_CTX *mem_ctx,
3784 const char *servername,
3785 const char *printername,
3786 const char **printername_p)
3788 /* FIXME: add lp_force_printername() */
3790 if (servername == NULL) {
3791 *printername_p = talloc_strdup(mem_ctx, printername);
3792 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3796 if (servername[0] == '\\' && servername[1] == '\\') {
3800 *printername_p = talloc_asprintf(mem_ctx, "\\\\%s\\%s", servername, printername);
3801 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3806 /********************************************************************
3807 ********************************************************************/
3809 static void compose_devicemode_devicename(struct spoolss_DeviceMode *dm,
3810 const char *printername)
3816 dm->devicename = talloc_strndup(dm, printername,
3817 MIN(strlen(printername), 31));
3820 /********************************************************************
3821 * construct_printer_info_0
3822 * fill a printer_info_0 struct
3823 ********************************************************************/
3825 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3826 const struct auth_serversupplied_info *server_info,
3827 struct messaging_context *msg_ctx,
3828 struct spoolss_PrinterInfo2 *info2,
3829 const char *servername,
3830 struct spoolss_PrinterInfo0 *r,
3834 struct printer_session_counter *session_counter;
3835 struct timeval setuptime;
3836 print_status_struct status;
3839 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3840 if (!W_ERROR_IS_OK(result)) {
3845 r->servername = talloc_strdup(mem_ctx, servername);
3846 W_ERROR_HAVE_NO_MEMORY(r->servername);
3848 r->servername = NULL;
3851 count = print_queue_length(msg_ctx, snum, &status);
3853 /* check if we already have a counter for this printer */
3854 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3855 if (session_counter->snum == snum)
3859 /* it's the first time, add it to the list */
3860 if (session_counter == NULL) {
3861 session_counter = talloc_zero(counter_list, struct printer_session_counter);
3862 W_ERROR_HAVE_NO_MEMORY(session_counter);
3863 session_counter->snum = snum;
3864 session_counter->counter = 0;
3865 DLIST_ADD(counter_list, session_counter);
3869 session_counter->counter++;
3875 get_startup_time(&setuptime);
3876 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3879 * the global_counter should be stored in a TDB as it's common to all the clients
3880 * and should be zeroed on samba startup
3882 r->global_counter = session_counter->counter;
3884 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3885 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3886 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3887 r->free_build = SPOOLSS_RELEASE_BUILD;
3889 r->max_spooling = 0;
3890 r->session_counter = session_counter->counter;
3891 r->num_error_out_of_paper = 0x0;
3892 r->num_error_not_ready = 0x0; /* number of print failure */
3894 r->number_of_processors = 0x1;
3895 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3896 r->high_part_total_bytes = 0x0;
3898 /* ChangeID in milliseconds*/
3899 winreg_printer_get_changeid(mem_ctx, server_info, msg_ctx,
3900 info2->sharename, &r->change_id);
3902 r->last_error = WERR_OK;
3903 r->status = nt_printq_status(status.status);
3904 r->enumerate_network_printers = 0x0;
3905 r->c_setprinter = 0x0;
3906 r->processor_architecture = PROCESSOR_ARCHITECTURE_INTEL;
3907 r->processor_level = 0x6; /* 6 ???*/
3916 /********************************************************************
3917 * construct_printer_info1
3918 * fill a spoolss_PrinterInfo1 struct
3919 ********************************************************************/
3921 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3922 const struct spoolss_PrinterInfo2 *info2,
3924 const char *servername,
3925 struct spoolss_PrinterInfo1 *r,
3932 if (info2->comment == NULL || info2->comment[0] == '\0') {
3933 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3935 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3937 W_ERROR_HAVE_NO_MEMORY(r->comment);
3939 result = create_printername(mem_ctx, servername, info2->printername, &r->name);
3940 if (!W_ERROR_IS_OK(result)) {
3944 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3948 W_ERROR_HAVE_NO_MEMORY(r->description);
3953 /********************************************************************
3954 * construct_printer_info2
3955 * fill a spoolss_PrinterInfo2 struct
3956 ********************************************************************/
3958 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3959 struct messaging_context *msg_ctx,
3960 const struct spoolss_PrinterInfo2 *info2,
3961 const char *servername,
3962 struct spoolss_PrinterInfo2 *r,
3966 print_status_struct status;
3969 count = print_queue_length(msg_ctx, snum, &status);
3972 r->servername = talloc_strdup(mem_ctx, servername);
3973 W_ERROR_HAVE_NO_MEMORY(r->servername);
3975 r->servername = NULL;
3978 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3979 if (!W_ERROR_IS_OK(result)) {
3983 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3984 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3985 r->portname = talloc_strdup(mem_ctx, info2->portname);
3986 W_ERROR_HAVE_NO_MEMORY(r->portname);
3987 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
3988 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3990 if (info2->comment[0] == '\0') {
3991 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3993 r->comment = talloc_strdup(mem_ctx, info2->comment);
3995 W_ERROR_HAVE_NO_MEMORY(r->comment);
3997 r->location = talloc_strdup(mem_ctx, info2->location);
3998 W_ERROR_HAVE_NO_MEMORY(r->location);
3999 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
4000 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
4001 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
4002 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
4003 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
4004 W_ERROR_HAVE_NO_MEMORY(r->datatype);
4005 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
4006 W_ERROR_HAVE_NO_MEMORY(r->parameters);
4008 r->attributes = info2->attributes;
4010 r->priority = info2->priority;
4011 r->defaultpriority = info2->defaultpriority;
4012 r->starttime = info2->starttime;
4013 r->untiltime = info2->untiltime;
4014 r->status = nt_printq_status(status.status);
4016 r->averageppm = info2->averageppm;
4018 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
4020 DEBUG(8,("Returning NULL Devicemode!\n"));
4023 compose_devicemode_devicename(r->devmode, r->printername);
4027 if (info2->secdesc != NULL) {
4028 /* don't use talloc_steal() here unless you do a deep steal of all
4029 the SEC_DESC members */
4031 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4037 /********************************************************************
4038 * construct_printer_info3
4039 * fill a spoolss_PrinterInfo3 struct
4040 ********************************************************************/
4042 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
4043 const struct spoolss_PrinterInfo2 *info2,
4044 const char *servername,
4045 struct spoolss_PrinterInfo3 *r,
4048 /* These are the components of the SD we are returning. */
4050 if (info2->secdesc != NULL) {
4051 /* don't use talloc_steal() here unless you do a deep steal of all
4052 the SEC_DESC members */
4054 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4055 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
4061 /********************************************************************
4062 * construct_printer_info4
4063 * fill a spoolss_PrinterInfo4 struct
4064 ********************************************************************/
4066 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4067 const struct spoolss_PrinterInfo2 *info2,
4068 const char *servername,
4069 struct spoolss_PrinterInfo4 *r,
4074 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4075 if (!W_ERROR_IS_OK(result)) {
4080 r->servername = talloc_strdup(mem_ctx, servername);
4081 W_ERROR_HAVE_NO_MEMORY(r->servername);
4083 r->servername = NULL;
4086 r->attributes = info2->attributes;
4091 /********************************************************************
4092 * construct_printer_info5
4093 * fill a spoolss_PrinterInfo5 struct
4094 ********************************************************************/
4096 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4097 const struct spoolss_PrinterInfo2 *info2,
4098 const char *servername,
4099 struct spoolss_PrinterInfo5 *r,
4104 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4105 if (!W_ERROR_IS_OK(result)) {
4109 r->portname = talloc_strdup(mem_ctx, info2->portname);
4110 W_ERROR_HAVE_NO_MEMORY(r->portname);
4112 r->attributes = info2->attributes;
4114 /* these two are not used by NT+ according to MSDN */
4115 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4116 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4121 /********************************************************************
4122 * construct_printer_info_6
4123 * fill a spoolss_PrinterInfo6 struct
4124 ********************************************************************/
4126 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4127 struct messaging_context *msg_ctx,
4128 const struct spoolss_PrinterInfo2 *info2,
4129 const char *servername,
4130 struct spoolss_PrinterInfo6 *r,
4134 print_status_struct status;
4136 count = print_queue_length(msg_ctx, snum, &status);
4138 r->status = nt_printq_status(status.status);
4143 /********************************************************************
4144 * construct_printer_info7
4145 * fill a spoolss_PrinterInfo7 struct
4146 ********************************************************************/
4148 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4149 struct messaging_context *msg_ctx,
4150 const char *servername,
4151 struct spoolss_PrinterInfo7 *r,
4154 struct auth_serversupplied_info *server_info;
4158 status = make_server_info_system(mem_ctx, &server_info);
4159 if (!NT_STATUS_IS_OK(status)) {
4160 DEBUG(0, ("construct_printer_info7: "
4161 "Could not create system server_info\n"));
4165 if (is_printer_published(mem_ctx, server_info, msg_ctx,
4167 lp_servicename(snum), &guid, NULL)) {
4168 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4169 r->action = DSPRINT_PUBLISH;
4171 r->guid = talloc_strdup(mem_ctx, "");
4172 r->action = DSPRINT_UNPUBLISH;
4174 W_ERROR_HAVE_NO_MEMORY(r->guid);
4176 TALLOC_FREE(server_info);
4180 /********************************************************************
4181 * construct_printer_info8
4182 * fill a spoolss_PrinterInfo8 struct
4183 ********************************************************************/
4185 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4186 const struct spoolss_PrinterInfo2 *info2,
4187 const char *servername,
4188 struct spoolss_DeviceModeInfo *r,
4192 const char *printername;
4194 result = create_printername(mem_ctx, servername, info2->printername, &printername);
4195 if (!W_ERROR_IS_OK(result)) {
4199 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
4201 DEBUG(8,("Returning NULL Devicemode!\n"));
4204 compose_devicemode_devicename(r->devmode, printername);
4210 /********************************************************************
4211 ********************************************************************/
4213 static bool snum_is_shared_printer(int snum)
4215 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4218 /********************************************************************
4219 Spoolss_enumprinters.
4220 ********************************************************************/
4222 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4223 const struct auth_serversupplied_info *server_info,
4224 struct messaging_context *msg_ctx,
4225 const char *servername,
4228 union spoolss_PrinterInfo **info_p,
4232 int n_services = lp_numservices();
4233 union spoolss_PrinterInfo *info = NULL;
4235 WERROR result = WERR_OK;
4240 for (snum = 0; snum < n_services; snum++) {
4242 const char *printer;
4243 struct spoolss_PrinterInfo2 *info2;
4245 if (!snum_is_shared_printer(snum)) {
4249 printer = lp_const_servicename(snum);
4251 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4254 result = winreg_create_printer(mem_ctx,
4258 if (!W_ERROR_IS_OK(result)) {
4262 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4263 union spoolss_PrinterInfo,
4266 result = WERR_NOMEM;
4270 result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
4272 if (!W_ERROR_IS_OK(result)) {
4278 result = construct_printer_info0(info, server_info,
4281 &info[count].info0, snum);
4284 result = construct_printer_info1(info, info2, flags,
4286 &info[count].info1, snum);
4289 result = construct_printer_info2(info, msg_ctx, info2,
4291 &info[count].info2, snum);
4294 result = construct_printer_info4(info, info2,
4296 &info[count].info4, snum);
4299 result = construct_printer_info5(info, info2,
4301 &info[count].info5, snum);
4305 result = WERR_UNKNOWN_LEVEL;
4309 if (!W_ERROR_IS_OK(result)) {
4320 if (!W_ERROR_IS_OK(result)) {
4330 /********************************************************************
4331 * handle enumeration of printers at level 0
4332 ********************************************************************/
4334 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4335 const struct auth_serversupplied_info *server_info,
4336 struct messaging_context *msg_ctx,
4338 const char *servername,
4339 union spoolss_PrinterInfo **info,
4342 DEBUG(4,("enum_all_printers_info_0\n"));
4344 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4345 servername, 0, flags, info, count);
4349 /********************************************************************
4350 ********************************************************************/
4352 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4353 const struct auth_serversupplied_info *server_info,
4354 struct messaging_context *msg_ctx,
4355 const char *servername,
4357 union spoolss_PrinterInfo **info,
4360 DEBUG(4,("enum_all_printers_info_1\n"));
4362 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4363 servername, 1, flags, info, count);
4366 /********************************************************************
4367 enum_all_printers_info_1_local.
4368 *********************************************************************/
4370 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4371 const struct auth_serversupplied_info *server_info,
4372 struct messaging_context *msg_ctx,
4373 const char *servername,
4374 union spoolss_PrinterInfo **info,
4377 DEBUG(4,("enum_all_printers_info_1_local\n"));
4379 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4380 servername, PRINTER_ENUM_ICON8, info, count);
4383 /********************************************************************
4384 enum_all_printers_info_1_name.
4385 *********************************************************************/
4387 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4388 const struct auth_serversupplied_info *server_info,
4389 struct messaging_context *msg_ctx,
4390 const char *servername,
4391 union spoolss_PrinterInfo **info,
4394 const char *s = servername;
4396 DEBUG(4,("enum_all_printers_info_1_name\n"));
4398 if ((servername[0] == '\\') && (servername[1] == '\\')) {
4402 if (!is_myname_or_ipaddr(s)) {
4403 return WERR_INVALID_NAME;
4406 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4407 servername, PRINTER_ENUM_ICON8, info, count);
4410 /********************************************************************
4411 enum_all_printers_info_1_network.
4412 *********************************************************************/
4414 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4415 const struct auth_serversupplied_info *server_info,
4416 struct messaging_context *msg_ctx,
4417 const char *servername,
4418 union spoolss_PrinterInfo **info,
4421 const char *s = servername;
4423 DEBUG(4,("enum_all_printers_info_1_network\n"));
4425 /* If we respond to a enum_printers level 1 on our name with flags
4426 set to PRINTER_ENUM_REMOTE with a list of printers then these
4427 printers incorrectly appear in the APW browse list.
4428 Specifically the printers for the server appear at the workgroup
4429 level where all the other servers in the domain are
4430 listed. Windows responds to this call with a
4431 WERR_CAN_NOT_COMPLETE so we should do the same. */
4433 if (servername[0] == '\\' && servername[1] == '\\') {
4437 if (is_myname_or_ipaddr(s)) {
4438 return WERR_CAN_NOT_COMPLETE;
4441 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4442 servername, PRINTER_ENUM_NAME, info, count);
4445 /********************************************************************
4446 * api_spoolss_enumprinters
4448 * called from api_spoolss_enumprinters (see this to understand)
4449 ********************************************************************/
4451 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4452 const struct auth_serversupplied_info *server_info,
4453 struct messaging_context *msg_ctx,
4454 const char *servername,
4455 union spoolss_PrinterInfo **info,
4458 DEBUG(4,("enum_all_printers_info_2\n"));
4460 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4461 servername, 2, 0, info, count);
4464 /********************************************************************
4465 * handle enumeration of printers at level 1
4466 ********************************************************************/
4468 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4469 const struct auth_serversupplied_info *server_info,
4470 struct messaging_context *msg_ctx,
4472 const char *servername,
4473 union spoolss_PrinterInfo **info,
4476 /* Not all the flags are equals */
4478 if (flags & PRINTER_ENUM_LOCAL) {
4479 return enum_all_printers_info_1_local(mem_ctx, server_info,
4480 msg_ctx, servername, info, count);
4483 if (flags & PRINTER_ENUM_NAME) {
4484 return enum_all_printers_info_1_name(mem_ctx, server_info,
4485 msg_ctx, servername, info,
4489 if (flags & PRINTER_ENUM_NETWORK) {
4490 return enum_all_printers_info_1_network(mem_ctx, server_info,
4491 msg_ctx, servername, info,
4495 return WERR_OK; /* NT4sp5 does that */
4498 /********************************************************************
4499 * handle enumeration of printers at level 2
4500 ********************************************************************/
4502 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4503 const struct auth_serversupplied_info *server_info,
4504 struct messaging_context *msg_ctx,
4506 const char *servername,
4507 union spoolss_PrinterInfo **info,
4510 if (flags & PRINTER_ENUM_LOCAL) {
4512 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4517 if (flags & PRINTER_ENUM_NAME) {
4518 if (servername && !is_myname_or_ipaddr(canon_servername(servername))) {
4519 return WERR_INVALID_NAME;
4522 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4527 if (flags & PRINTER_ENUM_REMOTE) {
4528 return WERR_UNKNOWN_LEVEL;
4534 /********************************************************************
4535 * handle enumeration of printers at level 4
4536 ********************************************************************/
4538 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4539 const struct auth_serversupplied_info *server_info,
4540 struct messaging_context *msg_ctx,
4542 const char *servername,
4543 union spoolss_PrinterInfo **info,
4546 DEBUG(4,("enum_all_printers_info_4\n"));
4548 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4549 servername, 4, flags, info, count);
4553 /********************************************************************
4554 * handle enumeration of printers at level 5
4555 ********************************************************************/
4557 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4558 const struct auth_serversupplied_info *server_info,
4559 struct messaging_context *msg_ctx,
4561 const char *servername,
4562 union spoolss_PrinterInfo **info,
4565 DEBUG(4,("enum_all_printers_info_5\n"));
4567 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4568 servername, 5, flags, info, count);
4571 /****************************************************************
4572 _spoolss_EnumPrinters
4573 ****************************************************************/
4575 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4576 struct spoolss_EnumPrinters *r)
4578 const struct auth_serversupplied_info *server_info = get_server_info_system();
4581 /* that's an [in out] buffer */
4583 if (!r->in.buffer && (r->in.offered != 0)) {
4584 return WERR_INVALID_PARAM;
4587 DEBUG(4,("_spoolss_EnumPrinters\n"));
4591 *r->out.info = NULL;
4595 * flags==PRINTER_ENUM_NAME
4596 * if name=="" then enumerates all printers
4597 * if name!="" then enumerate the printer
4598 * flags==PRINTER_ENUM_REMOTE
4599 * name is NULL, enumerate printers
4600 * Level 2: name!="" enumerates printers, name can't be NULL
4601 * Level 3: doesn't exist
4602 * Level 4: does a local registry lookup
4603 * Level 5: same as Level 2
4606 if (r->in.server && r->in.server[0] == '\0') {
4607 r->in.server = NULL;
4610 switch (r->in.level) {
4612 result = enumprinters_level0(p->mem_ctx, server_info,
4613 p->msg_ctx, r->in.flags,
4615 r->out.info, r->out.count);
4618 result = enumprinters_level1(p->mem_ctx, server_info,
4619 p->msg_ctx, r->in.flags,
4621 r->out.info, r->out.count);
4624 result = enumprinters_level2(p->mem_ctx, server_info,
4625 p->msg_ctx, r->in.flags,
4627 r->out.info, r->out.count);
4630 result = enumprinters_level4(p->mem_ctx, server_info,
4631 p->msg_ctx, r->in.flags,
4633 r->out.info, r->out.count);
4636 result = enumprinters_level5(p->mem_ctx, server_info,
4637 p->msg_ctx, r->in.flags,
4639 r->out.info, r->out.count);
4642 return WERR_UNKNOWN_LEVEL;
4645 if (!W_ERROR_IS_OK(result)) {
4649 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4650 spoolss_EnumPrinters,
4651 *r->out.info, r->in.level,
4653 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4654 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4656 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4659 /****************************************************************
4661 ****************************************************************/
4663 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4664 struct spoolss_GetPrinter *r)
4666 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
4667 struct spoolss_PrinterInfo2 *info2 = NULL;
4668 WERROR result = WERR_OK;
4671 /* that's an [in out] buffer */
4673 if (!r->in.buffer && (r->in.offered != 0)) {
4674 return WERR_INVALID_PARAM;
4679 if (Printer == NULL) {
4683 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4687 result = winreg_get_printer(p->mem_ctx,
4688 get_server_info_system(),
4690 lp_const_servicename(snum),
4692 if (!W_ERROR_IS_OK(result)) {
4696 switch (r->in.level) {
4698 result = construct_printer_info0(p->mem_ctx,
4699 get_server_info_system(),
4702 Printer->servername,
4703 &r->out.info->info0,
4707 result = construct_printer_info1(p->mem_ctx, info2,
4709 Printer->servername,
4710 &r->out.info->info1, snum);
4713 result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
4714 Printer->servername,
4715 &r->out.info->info2, snum);
4718 result = construct_printer_info3(p->mem_ctx, info2,
4719 Printer->servername,
4720 &r->out.info->info3, snum);
4723 result = construct_printer_info4(p->mem_ctx, info2,
4724 Printer->servername,
4725 &r->out.info->info4, snum);
4728 result = construct_printer_info5(p->mem_ctx, info2,
4729 Printer->servername,
4730 &r->out.info->info5, snum);
4733 result = construct_printer_info6(p->mem_ctx, p->msg_ctx, info2,
4734 Printer->servername,
4735 &r->out.info->info6, snum);
4738 result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
4739 Printer->servername,
4740 &r->out.info->info7, snum);
4743 result = construct_printer_info8(p->mem_ctx, info2,
4744 Printer->servername,
4745 &r->out.info->info8, snum);
4748 result = WERR_UNKNOWN_LEVEL;
4753 if (!W_ERROR_IS_OK(result)) {
4754 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4755 r->in.level, win_errstr(result)));
4756 TALLOC_FREE(r->out.info);
4760 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4761 r->out.info, r->in.level);
4762 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4764 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4767 /********************************************************************
4768 ********************************************************************/
4770 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4772 if (in && strlen(in)) { \
4773 out = talloc_strdup(mem_ctx, in); \
4775 out = talloc_strdup(mem_ctx, ""); \
4777 W_ERROR_HAVE_NO_MEMORY(out); \
4780 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4782 if (in && strlen(in)) { \
4783 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4785 out = talloc_strdup(mem_ctx, ""); \
4787 W_ERROR_HAVE_NO_MEMORY(out); \
4790 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4791 const char **string_array,
4792 const char ***presult,
4793 const char *cservername,
4797 int i, num_strings = 0;
4798 const char **array = NULL;
4800 if (string_array == NULL) {
4801 return WERR_INVALID_PARAMETER;
4804 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4805 const char *str = NULL;
4807 if (cservername == NULL || arch == NULL) {
4808 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4810 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4813 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4820 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4821 &array, &num_strings);
4831 /********************************************************************
4832 * fill a spoolss_DriverInfo1 struct
4833 ********************************************************************/
4835 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4836 struct spoolss_DriverInfo1 *r,
4837 const struct spoolss_DriverInfo8 *driver,
4838 const char *servername)
4840 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4841 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4846 /********************************************************************
4847 * fill a spoolss_DriverInfo2 struct
4848 ********************************************************************/
4850 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4851 struct spoolss_DriverInfo2 *r,
4852 const struct spoolss_DriverInfo8 *driver,
4853 const char *servername)
4856 const char *cservername = canon_servername(servername);
4858 r->version = driver->version;
4860 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4861 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4862 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4863 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4865 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4866 driver->architecture,
4868 driver->driver_path,
4871 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4872 driver->architecture,
4877 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4878 driver->architecture,
4880 driver->config_file,
4886 /********************************************************************
4887 * fill a spoolss_DriverInfo3 struct
4888 ********************************************************************/
4890 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4891 struct spoolss_DriverInfo3 *r,
4892 const struct spoolss_DriverInfo8 *driver,
4893 const char *servername)
4895 const char *cservername = canon_servername(servername);
4897 r->version = driver->version;
4899 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4900 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4901 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4902 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4904 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4905 driver->architecture,
4907 driver->driver_path,
4910 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4911 driver->architecture,
4916 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4917 driver->architecture,
4919 driver->config_file,
4922 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4923 driver->architecture,
4928 FILL_DRIVER_STRING(mem_ctx,
4929 driver->monitor_name,
4932 FILL_DRIVER_STRING(mem_ctx,
4933 driver->default_datatype,
4934 r->default_datatype);
4936 return string_array_from_driver_info(mem_ctx,
4937 driver->dependent_files,
4938 &r->dependent_files,
4940 driver->architecture,
4944 /********************************************************************
4945 * fill a spoolss_DriverInfo4 struct
4946 ********************************************************************/
4948 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4949 struct spoolss_DriverInfo4 *r,
4950 const struct spoolss_DriverInfo8 *driver,
4951 const char *servername)
4953 const char *cservername = canon_servername(servername);
4956 r->version = driver->version;
4958 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4959 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4960 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4961 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4963 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4964 driver->architecture,
4966 driver->driver_path,
4969 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4970 driver->architecture,
4975 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4976 driver->architecture,
4978 driver->config_file,
4981 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4982 driver->architecture,
4987 result = string_array_from_driver_info(mem_ctx,
4988 driver->dependent_files,
4989 &r->dependent_files,
4991 driver->architecture,
4993 if (!W_ERROR_IS_OK(result)) {
4997 FILL_DRIVER_STRING(mem_ctx,
4998 driver->monitor_name,
5001 FILL_DRIVER_STRING(mem_ctx,
5002 driver->default_datatype,
5003 r->default_datatype);
5006 result = string_array_from_driver_info(mem_ctx,
5007 driver->previous_names,
5014 /********************************************************************
5015 * fill a spoolss_DriverInfo5 struct
5016 ********************************************************************/
5018 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
5019 struct spoolss_DriverInfo5 *r,
5020 const struct spoolss_DriverInfo8 *driver,
5021 const char *servername)
5023 const char *cservername = canon_servername(servername);
5025 r->version = driver->version;
5027 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5028 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5029 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5030 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5032 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5033 driver->architecture,
5035 driver->driver_path,
5038 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5039 driver->architecture,
5044 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5045 driver->architecture,
5047 driver->config_file,
5050 r->driver_attributes = 0;
5051 r->config_version = 0;
5052 r->driver_version = 0;
5056 /********************************************************************
5057 * fill a spoolss_DriverInfo6 struct
5058 ********************************************************************/
5060 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
5061 struct spoolss_DriverInfo6 *r,
5062 const struct spoolss_DriverInfo8 *driver,
5063 const char *servername)
5065 const char *cservername = canon_servername(servername);
5068 r->version = driver->version;
5070 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5071 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5072 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5073 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5075 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5076 driver->architecture,
5078 driver->driver_path,
5081 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5082 driver->architecture,
5087 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5088 driver->architecture,
5090 driver->config_file,
5093 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5094 driver->architecture,
5099 FILL_DRIVER_STRING(mem_ctx,
5100 driver->monitor_name,
5103 FILL_DRIVER_STRING(mem_ctx,
5104 driver->default_datatype,
5105 r->default_datatype);
5107 result = string_array_from_driver_info(mem_ctx,
5108 driver->dependent_files,
5109 &r->dependent_files,
5111 driver->architecture,
5113 if (!W_ERROR_IS_OK(result)) {
5117 result = string_array_from_driver_info(mem_ctx,
5118 driver->previous_names,
5121 if (!W_ERROR_IS_OK(result)) {
5125 r->driver_date = driver->driver_date;
5126 r->driver_version = driver->driver_version;
5128 FILL_DRIVER_STRING(mem_ctx,
5129 driver->manufacturer_name,
5130 r->manufacturer_name);
5131 FILL_DRIVER_STRING(mem_ctx,
5132 driver->manufacturer_url,
5133 r->manufacturer_url);
5134 FILL_DRIVER_STRING(mem_ctx,
5135 driver->hardware_id,
5137 FILL_DRIVER_STRING(mem_ctx,
5144 /********************************************************************
5145 * fill a spoolss_DriverInfo8 struct
5146 ********************************************************************/
5148 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
5149 struct spoolss_DriverInfo8 *r,
5150 const struct spoolss_DriverInfo8 *driver,
5151 const char *servername)
5153 const char *cservername = canon_servername(servername);
5156 r->version = driver->version;
5158 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5159 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5160 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5161 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5163 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5164 driver->architecture,
5166 driver->driver_path,
5169 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5170 driver->architecture,
5175 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5176 driver->architecture,
5178 driver->config_file,
5181 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5182 driver->architecture,
5187 FILL_DRIVER_STRING(mem_ctx,
5188 driver->monitor_name,
5191 FILL_DRIVER_STRING(mem_ctx,
5192 driver->default_datatype,
5193 r->default_datatype);
5195 result = string_array_from_driver_info(mem_ctx,
5196 driver->dependent_files,
5197 &r->dependent_files,
5199 driver->architecture,
5201 if (!W_ERROR_IS_OK(result)) {
5205 result = string_array_from_driver_info(mem_ctx,
5206 driver->previous_names,
5209 if (!W_ERROR_IS_OK(result)) {
5213 r->driver_date = driver->driver_date;
5214 r->driver_version = driver->driver_version;
5216 FILL_DRIVER_STRING(mem_ctx,
5217 driver->manufacturer_name,
5218 r->manufacturer_name);
5219 FILL_DRIVER_STRING(mem_ctx,
5220 driver->manufacturer_url,
5221 r->manufacturer_url);
5222 FILL_DRIVER_STRING(mem_ctx,
5223 driver->hardware_id,
5225 FILL_DRIVER_STRING(mem_ctx,
5229 FILL_DRIVER_STRING(mem_ctx,
5230 driver->print_processor,
5231 r->print_processor);
5232 FILL_DRIVER_STRING(mem_ctx,
5233 driver->vendor_setup,
5236 result = string_array_from_driver_info(mem_ctx,
5237 driver->color_profiles,
5240 if (!W_ERROR_IS_OK(result)) {
5244 FILL_DRIVER_STRING(mem_ctx,
5248 r->printer_driver_attributes = driver->printer_driver_attributes;
5250 result = string_array_from_driver_info(mem_ctx,
5251 driver->core_driver_dependencies,
5252 &r->core_driver_dependencies,
5254 if (!W_ERROR_IS_OK(result)) {
5258 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
5259 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
5264 #if 0 /* disabled until marshalling issues are resolved - gd */
5265 /********************************************************************
5266 ********************************************************************/
5268 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5269 struct spoolss_DriverFileInfo *r,
5270 const char *cservername,
5271 const char *file_name,
5272 enum spoolss_DriverFileType file_type,
5273 uint32_t file_version)
5275 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5276 cservername, file_name);
5277 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5278 r->file_type = file_type;
5279 r->file_version = file_version;
5284 /********************************************************************
5285 ********************************************************************/
5287 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5288 const struct spoolss_DriverInfo8 *driver,
5289 const char *cservername,
5290 struct spoolss_DriverFileInfo **info_p,
5293 struct spoolss_DriverFileInfo *info = NULL;
5301 if (strlen(driver->driver_path)) {
5302 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5303 struct spoolss_DriverFileInfo,
5305 W_ERROR_HAVE_NO_MEMORY(info);
5306 result = fill_spoolss_DriverFileInfo(info,
5309 driver->driver_path,
5310 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5312 W_ERROR_NOT_OK_RETURN(result);
5316 if (strlen(driver->config_file)) {
5317 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5318 struct spoolss_DriverFileInfo,
5320 W_ERROR_HAVE_NO_MEMORY(info);
5321 result = fill_spoolss_DriverFileInfo(info,
5324 driver->config_file,
5325 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5327 W_ERROR_NOT_OK_RETURN(result);
5331 if (strlen(driver->data_file)) {
5332 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5333 struct spoolss_DriverFileInfo,
5335 W_ERROR_HAVE_NO_MEMORY(info);
5336 result = fill_spoolss_DriverFileInfo(info,
5340 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5342 W_ERROR_NOT_OK_RETURN(result);
5346 if (strlen(driver->help_file)) {
5347 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5348 struct spoolss_DriverFileInfo,
5350 W_ERROR_HAVE_NO_MEMORY(info);
5351 result = fill_spoolss_DriverFileInfo(info,
5355 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5357 W_ERROR_NOT_OK_RETURN(result);
5361 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
5362 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5363 struct spoolss_DriverFileInfo,
5365 W_ERROR_HAVE_NO_MEMORY(info);
5366 result = fill_spoolss_DriverFileInfo(info,
5369 driver->dependent_files[i],
5370 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5372 W_ERROR_NOT_OK_RETURN(result);
5382 /********************************************************************
5383 * fill a spoolss_DriverInfo101 struct
5384 ********************************************************************/
5386 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5387 struct spoolss_DriverInfo101 *r,
5388 const struct spoolss_DriverInfo8 *driver,
5389 const char *servername)
5391 const char *cservername = canon_servername(servername);
5394 r->version = driver->version;
5396 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5397 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5398 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5399 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5401 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5405 if (!W_ERROR_IS_OK(result)) {
5409 FILL_DRIVER_STRING(mem_ctx,
5410 driver->monitor_name,
5413 FILL_DRIVER_STRING(mem_ctx,
5414 driver->default_datatype,
5415 r->default_datatype);
5417 result = string_array_from_driver_info(mem_ctx,
5418 driver->previous_names,
5421 if (!W_ERROR_IS_OK(result)) {
5425 r->driver_date = driver->driver_date;
5426 r->driver_version = driver->driver_version;
5428 FILL_DRIVER_STRING(mem_ctx,
5429 driver->manufacturer_name,
5430 r->manufacturer_name);
5431 FILL_DRIVER_STRING(mem_ctx,
5432 driver->manufacturer_url,
5433 r->manufacturer_url);
5434 FILL_DRIVER_STRING(mem_ctx,
5435 driver->hardware_id,
5437 FILL_DRIVER_STRING(mem_ctx,
5444 /********************************************************************
5445 ********************************************************************/
5447 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5448 const struct auth_serversupplied_info *server_info,
5449 struct messaging_context *msg_ctx,
5451 union spoolss_DriverInfo *r,
5453 const char *servername,
5454 const char *architecture,
5457 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5458 struct spoolss_DriverInfo8 *driver;
5462 return WERR_UNKNOWN_LEVEL;
5465 result = winreg_get_printer(mem_ctx,
5468 lp_const_servicename(snum),
5471 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5472 win_errstr(result)));
5474 if (!W_ERROR_IS_OK(result)) {
5475 return WERR_INVALID_PRINTER_NAME;
5478 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5480 pinfo2->drivername, version, &driver);
5482 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5483 win_errstr(result)));
5485 if (!W_ERROR_IS_OK(result)) {
5487 * Is this a W2k client ?
5491 talloc_free(pinfo2);
5492 return WERR_UNKNOWN_PRINTER_DRIVER;
5495 /* Yes - try again with a WinNT driver. */
5497 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5501 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5502 win_errstr(result)));
5503 if (!W_ERROR_IS_OK(result)) {
5504 talloc_free(pinfo2);
5505 return WERR_UNKNOWN_PRINTER_DRIVER;
5511 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5514 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5517 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5520 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5523 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5526 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5529 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5531 #if 0 /* disabled until marshalling issues are resolved - gd */
5533 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5537 result = WERR_UNKNOWN_LEVEL;
5541 talloc_free(pinfo2);
5542 talloc_free(driver);
5547 /****************************************************************
5548 _spoolss_GetPrinterDriver2
5549 ****************************************************************/
5551 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5552 struct spoolss_GetPrinterDriver2 *r)
5554 struct printer_handle *printer;
5559 /* that's an [in out] buffer */
5561 if (!r->in.buffer && (r->in.offered != 0)) {
5562 return WERR_INVALID_PARAM;
5565 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5567 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5568 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5569 return WERR_INVALID_PRINTER_NAME;
5573 *r->out.server_major_version = 0;
5574 *r->out.server_minor_version = 0;
5576 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5580 result = construct_printer_driver_info_level(p->mem_ctx,
5581 get_server_info_system(),
5583 r->in.level, r->out.info,
5584 snum, printer->servername,
5586 r->in.client_major_version);
5587 if (!W_ERROR_IS_OK(result)) {
5588 TALLOC_FREE(r->out.info);
5592 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5593 r->out.info, r->in.level);
5594 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5596 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5600 /****************************************************************
5601 _spoolss_StartPagePrinter
5602 ****************************************************************/
5604 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5605 struct spoolss_StartPagePrinter *r)
5607 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5610 DEBUG(3,("_spoolss_StartPagePrinter: "
5611 "Error in startpageprinter printer handle\n"));
5615 Printer->page_started = true;
5619 /****************************************************************
5620 _spoolss_EndPagePrinter
5621 ****************************************************************/
5623 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5624 struct spoolss_EndPagePrinter *r)
5628 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5631 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5632 OUR_HANDLE(r->in.handle)));
5636 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5639 Printer->page_started = false;
5640 print_job_endpage(p->msg_ctx, snum, Printer->jobid);
5645 /****************************************************************
5646 _spoolss_StartDocPrinter
5647 ****************************************************************/
5649 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5650 struct spoolss_StartDocPrinter *r)
5652 struct spoolss_DocumentInfo1 *info_1;
5654 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5658 DEBUG(2,("_spoolss_StartDocPrinter: "
5659 "Invalid handle (%s:%u:%u)\n",
5660 OUR_HANDLE(r->in.handle)));
5664 if (Printer->jobid) {
5665 DEBUG(2, ("_spoolss_StartDocPrinter: "
5666 "StartDocPrinter called twice! "
5667 "(existing jobid = %d)\n", Printer->jobid));
5668 return WERR_INVALID_HANDLE;
5671 if (r->in.level != 1) {
5672 return WERR_UNKNOWN_LEVEL;
5675 info_1 = r->in.info.info1;
5678 * a nice thing with NT is it doesn't listen to what you tell it.
5679 * when asked to send _only_ RAW datas, it tries to send datas
5682 * So I add checks like in NT Server ...
5685 if (info_1->datatype) {
5686 if (strcmp(info_1->datatype, "RAW") != 0) {
5688 return WERR_INVALID_DATATYPE;
5692 /* get the share number of the printer */
5693 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5697 werr = print_job_start(p->server_info,
5701 info_1->document_name,
5702 info_1->output_file,
5706 /* An error occured in print_job_start() so return an appropriate
5709 if (!W_ERROR_IS_OK(werr)) {
5713 Printer->document_started = true;
5714 *r->out.job_id = Printer->jobid;
5719 /****************************************************************
5720 _spoolss_EndDocPrinter
5721 ****************************************************************/
5723 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5724 struct spoolss_EndDocPrinter *r)
5726 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5731 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5732 OUR_HANDLE(r->in.handle)));
5736 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5740 Printer->document_started = false;
5741 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5742 if (!NT_STATUS_IS_OK(status)) {
5743 DEBUG(2, ("_spoolss_EndDocPrinter: "
5744 "print_job_end failed [%s]\n",
5745 nt_errstr(status)));
5749 return ntstatus_to_werror(status);
5752 /****************************************************************
5753 _spoolss_WritePrinter
5754 ****************************************************************/
5756 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5757 struct spoolss_WritePrinter *r)
5759 ssize_t buffer_written;
5761 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5764 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5765 OUR_HANDLE(r->in.handle)));
5766 *r->out.num_written = r->in._data_size;
5770 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5773 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5774 buffer_written = print_job_write(server_event_context(),p->msg_ctx,
5775 snum, Printer->jobid,
5776 (const char *)r->in.data.data,
5777 (size_t)r->in._data_size);
5778 if (buffer_written == (ssize_t)-1) {
5779 *r->out.num_written = 0;
5780 if (errno == ENOSPC)
5781 return WERR_NO_SPOOL_SPACE;
5783 return WERR_ACCESS_DENIED;
5786 *r->out.num_written = r->in._data_size;
5791 /********************************************************************
5792 * api_spoolss_getprinter
5793 * called from the spoolss dispatcher
5795 ********************************************************************/
5797 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5798 struct pipes_struct *p)
5800 const struct auth_serversupplied_info *server_info = p->server_info;
5802 WERROR errcode = WERR_BADFUNC;
5803 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5806 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5807 OUR_HANDLE(handle)));
5811 if (!get_printer_snum(p, handle, &snum, NULL))
5815 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5816 errcode = print_queue_pause(server_info, p->msg_ctx, snum);
5818 case SPOOLSS_PRINTER_CONTROL_RESUME:
5819 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5820 errcode = print_queue_resume(server_info, p->msg_ctx, snum);
5822 case SPOOLSS_PRINTER_CONTROL_PURGE:
5823 errcode = print_queue_purge(server_info, p->msg_ctx, snum);
5826 return WERR_UNKNOWN_LEVEL;
5833 /****************************************************************
5834 _spoolss_AbortPrinter
5835 * From MSDN: "Deletes printer's spool file if printer is configured
5837 ****************************************************************/
5839 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5840 struct spoolss_AbortPrinter *r)
5842 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5844 WERROR errcode = WERR_OK;
5847 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5848 OUR_HANDLE(r->in.handle)));
5852 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5855 if (!Printer->document_started) {
5856 return WERR_SPL_NO_STARTDOC;
5859 errcode = print_job_delete(p->server_info,
5867 /********************************************************************
5868 * called by spoolss_api_setprinter
5869 * when updating a printer description
5870 ********************************************************************/
5872 static WERROR update_printer_sec(struct policy_handle *handle,
5873 struct pipes_struct *p,
5874 struct sec_desc_buf *secdesc_ctr)
5876 struct spoolss_security_descriptor *new_secdesc = NULL;
5877 struct spoolss_security_descriptor *old_secdesc = NULL;
5878 const char *printer;
5882 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5884 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5885 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5886 OUR_HANDLE(handle)));
5888 result = WERR_BADFID;
5892 if (secdesc_ctr == NULL) {
5893 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5894 result = WERR_INVALID_PARAM;
5897 printer = lp_const_servicename(snum);
5899 /* Check the user has permissions to change the security
5900 descriptor. By experimentation with two NT machines, the user
5901 requires Full Access to the printer to change security
5904 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5905 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5906 result = WERR_ACCESS_DENIED;
5910 /* NT seems to like setting the security descriptor even though
5911 nothing may have actually changed. */
5912 result = winreg_get_printer_secdesc(p->mem_ctx,
5913 get_server_info_system(),
5917 if (!W_ERROR_IS_OK(result)) {
5918 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5919 result = WERR_BADFID;
5923 if (DEBUGLEVEL >= 10) {
5924 struct security_acl *the_acl;
5927 the_acl = old_secdesc->dacl;
5928 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5929 printer, the_acl->num_aces));
5931 for (i = 0; i < the_acl->num_aces; i++) {
5932 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5933 &the_acl->aces[i].trustee),
5934 the_acl->aces[i].access_mask));
5937 the_acl = secdesc_ctr->sd->dacl;
5940 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5941 printer, the_acl->num_aces));
5943 for (i = 0; i < the_acl->num_aces; i++) {
5944 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5945 &the_acl->aces[i].trustee),
5946 the_acl->aces[i].access_mask));
5949 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5953 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
5954 if (new_secdesc == NULL) {
5955 result = WERR_NOMEM;
5959 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
5964 result = winreg_set_printer_secdesc(p->mem_ctx,
5965 get_server_info_system(),
5974 /********************************************************************
5975 Canonicalize printer info from a client
5976 ********************************************************************/
5978 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
5979 struct spoolss_SetPrinterInfo2 *info2,
5982 fstring printername;
5985 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5986 "portname=%s drivername=%s comment=%s location=%s\n",
5987 info2->servername, info2->printername, info2->sharename,
5988 info2->portname, info2->drivername, info2->comment,
5991 /* we force some elements to "correct" values */
5992 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
5993 if (info2->servername == NULL) {
5996 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
5997 if (info2->sharename == NULL) {
6001 /* check to see if we allow printername != sharename */
6002 if (lp_force_printername(snum)) {
6003 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6004 global_myname(), info2->sharename);
6006 /* make sure printername is in \\server\printername format */
6007 fstrcpy(printername, info2->printername);
6009 if ( printername[0] == '\\' && printername[1] == '\\' ) {
6010 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
6014 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6015 global_myname(), p);
6017 if (info2->printername == NULL) {
6021 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
6022 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
6027 /****************************************************************************
6028 ****************************************************************************/
6030 static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const char *portname, const char *uri)
6032 char *cmd = lp_addport_cmd();
6033 char *command = NULL;
6035 bool is_print_op = false;
6038 return WERR_ACCESS_DENIED;
6041 command = talloc_asprintf(ctx,
6042 "%s \"%s\" \"%s\"", cmd, portname, uri );
6048 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6050 DEBUG(10,("Running [%s]\n", command));
6052 /********* BEGIN SePrintOperatorPrivilege **********/
6057 ret = smbrun(command, NULL);
6062 /********* END SePrintOperatorPrivilege **********/
6064 DEBUGADD(10,("returned [%d]\n", ret));
6066 TALLOC_FREE(command);
6069 return WERR_ACCESS_DENIED;
6075 /****************************************************************************
6076 ****************************************************************************/
6078 static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
6079 struct spoolss_SetPrinterInfo2 *info2,
6080 const char *remote_machine,
6081 struct messaging_context *msg_ctx)
6083 char *cmd = lp_addprinter_cmd();
6085 char *command = NULL;
6089 bool is_print_op = false;
6091 if (!remote_machine) {
6095 command = talloc_asprintf(ctx,
6096 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6097 cmd, info2->printername, info2->sharename,
6098 info2->portname, info2->drivername,
6099 info2->location, info2->comment, remote_machine);
6105 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6107 DEBUG(10,("Running [%s]\n", command));
6109 /********* BEGIN SePrintOperatorPrivilege **********/
6114 if ( (ret = smbrun(command, &fd)) == 0 ) {
6115 /* Tell everyone we updated smb.conf. */
6116 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6122 /********* END SePrintOperatorPrivilege **********/
6124 DEBUGADD(10,("returned [%d]\n", ret));
6126 TALLOC_FREE(command);
6134 /* reload our services immediately */
6136 reload_services(msg_ctx, -1, false);
6140 /* Get lines and convert them back to dos-codepage */
6141 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6142 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6145 /* Set the portname to what the script says the portname should be. */
6146 /* but don't require anything to be return from the script exit a good error code */
6149 /* Set the portname to what the script says the portname should be. */
6150 info2->portname = talloc_strdup(ctx, qlines[0]);
6151 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6154 TALLOC_FREE(qlines);
6158 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
6159 const struct auth_serversupplied_info *server_info,
6160 struct messaging_context *msg_ctx,
6162 struct spoolss_SetPrinterInfo2 *printer,
6163 struct spoolss_PrinterInfo2 *old_printer)
6165 bool force_update = (old_printer == NULL);
6166 const char *dnsdomname;
6167 const char *longname;
6168 const char *uncname;
6169 const char *spooling;
6171 WERROR result = WERR_OK;
6173 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
6174 push_reg_sz(mem_ctx, &buffer, printer->drivername);
6175 winreg_set_printer_dataex(mem_ctx,
6179 SPOOL_DSSPOOLER_KEY,
6180 SPOOL_REG_DRIVERNAME,
6185 if (!force_update) {
6186 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6187 printer->drivername));
6189 notify_printer_driver(server_event_context(), msg_ctx,
6190 snum, printer->drivername ?
6191 printer->drivername : "");
6195 if (force_update || !strequal(printer->comment, old_printer->comment)) {
6196 push_reg_sz(mem_ctx, &buffer, printer->comment);
6197 winreg_set_printer_dataex(mem_ctx,
6201 SPOOL_DSSPOOLER_KEY,
6202 SPOOL_REG_DESCRIPTION,
6207 if (!force_update) {
6208 notify_printer_comment(server_event_context(), msg_ctx,
6209 snum, printer->comment ?
6210 printer->comment : "");
6214 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
6215 push_reg_sz(mem_ctx, &buffer, printer->sharename);
6216 winreg_set_printer_dataex(mem_ctx,
6220 SPOOL_DSSPOOLER_KEY,
6221 SPOOL_REG_PRINTSHARENAME,
6226 if (!force_update) {
6227 notify_printer_sharename(server_event_context(),
6229 snum, printer->sharename ?
6230 printer->sharename : "");
6234 if (force_update || !strequal(printer->printername, old_printer->printername)) {
6237 p = strrchr(printer->printername, '\\' );
6241 p = printer->printername;
6244 push_reg_sz(mem_ctx, &buffer, p);
6245 winreg_set_printer_dataex(mem_ctx,
6249 SPOOL_DSSPOOLER_KEY,
6250 SPOOL_REG_PRINTERNAME,
6255 if (!force_update) {
6256 notify_printer_printername(server_event_context(),
6257 msg_ctx, snum, p ? p : "");
6261 if (force_update || !strequal(printer->portname, old_printer->portname)) {
6262 push_reg_sz(mem_ctx, &buffer, printer->portname);
6263 winreg_set_printer_dataex(mem_ctx,
6267 SPOOL_DSSPOOLER_KEY,
6273 if (!force_update) {
6274 notify_printer_port(server_event_context(),
6275 msg_ctx, snum, printer->portname ?
6276 printer->portname : "");
6280 if (force_update || !strequal(printer->location, old_printer->location)) {
6281 push_reg_sz(mem_ctx, &buffer, printer->location);
6282 winreg_set_printer_dataex(mem_ctx,
6286 SPOOL_DSSPOOLER_KEY,
6292 if (!force_update) {
6293 notify_printer_location(server_event_context(),
6296 printer->location : "");
6300 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
6301 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
6302 winreg_set_printer_dataex(mem_ctx,
6306 SPOOL_DSSPOOLER_KEY,
6307 SPOOL_REG_PRINTSEPARATORFILE,
6312 if (!force_update) {
6313 notify_printer_sepfile(server_event_context(),
6316 printer->sepfile : "");
6320 if (force_update || printer->starttime != old_printer->starttime) {
6321 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6322 SIVAL(buffer.data, 0, printer->starttime);
6323 winreg_set_printer_dataex(mem_ctx,
6327 SPOOL_DSSPOOLER_KEY,
6328 SPOOL_REG_PRINTSTARTTIME,
6334 if (force_update || printer->untiltime != old_printer->untiltime) {
6335 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6336 SIVAL(buffer.data, 0, printer->untiltime);
6337 winreg_set_printer_dataex(mem_ctx,
6341 SPOOL_DSSPOOLER_KEY,
6342 SPOOL_REG_PRINTENDTIME,
6348 if (force_update || printer->priority != old_printer->priority) {
6349 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6350 SIVAL(buffer.data, 0, printer->priority);
6351 winreg_set_printer_dataex(mem_ctx,
6355 SPOOL_DSSPOOLER_KEY,
6362 if (force_update || printer->attributes != old_printer->attributes) {
6363 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6364 SIVAL(buffer.data, 0, (printer->attributes &
6365 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
6366 winreg_set_printer_dataex(mem_ctx,
6370 SPOOL_DSSPOOLER_KEY,
6371 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
6376 switch (printer->attributes & 0x3) {
6378 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
6381 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
6384 spooling = SPOOL_REGVAL_PRINTDIRECT;
6387 spooling = "unknown";
6389 push_reg_sz(mem_ctx, &buffer, spooling);
6390 winreg_set_printer_dataex(mem_ctx,
6394 SPOOL_DSSPOOLER_KEY,
6395 SPOOL_REG_PRINTSPOOLING,
6401 push_reg_sz(mem_ctx, &buffer, global_myname());
6402 winreg_set_printer_dataex(mem_ctx,
6406 SPOOL_DSSPOOLER_KEY,
6407 SPOOL_REG_SHORTSERVERNAME,
6412 dnsdomname = get_mydnsfullname();
6413 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
6414 longname = talloc_strdup(mem_ctx, dnsdomname);
6416 longname = talloc_strdup(mem_ctx, global_myname());
6418 if (longname == NULL) {
6419 result = WERR_NOMEM;
6423 push_reg_sz(mem_ctx, &buffer, longname);
6424 winreg_set_printer_dataex(mem_ctx,
6428 SPOOL_DSSPOOLER_KEY,
6429 SPOOL_REG_SERVERNAME,
6434 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6435 global_myname(), printer->sharename);
6436 push_reg_sz(mem_ctx, &buffer, uncname);
6437 winreg_set_printer_dataex(mem_ctx,
6441 SPOOL_DSSPOOLER_KEY,
6451 /********************************************************************
6452 * Called by spoolss_api_setprinter
6453 * when updating a printer description.
6454 ********************************************************************/
6456 static WERROR update_printer(struct pipes_struct *p,
6457 struct policy_handle *handle,
6458 struct spoolss_SetPrinterInfoCtr *info_ctr,
6459 struct spoolss_DeviceMode *devmode)
6461 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6462 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6463 struct spoolss_PrinterInfo2 *old_printer;
6464 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6466 WERROR result = WERR_OK;
6467 TALLOC_CTX *tmp_ctx;
6469 DEBUG(8,("update_printer\n"));
6471 tmp_ctx = talloc_new(p->mem_ctx);
6472 if (tmp_ctx == NULL) {
6477 result = WERR_BADFID;
6481 if (!get_printer_snum(p, handle, &snum, NULL)) {
6482 result = WERR_BADFID;
6486 result = winreg_get_printer(tmp_ctx,
6487 get_server_info_system(),
6489 lp_const_servicename(snum),
6491 if (!W_ERROR_IS_OK(result)) {
6492 result = WERR_BADFID;
6496 /* Do sanity check on the requested changes for Samba */
6497 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6498 result = WERR_INVALID_PARAM;
6502 /* FIXME!!! If the driver has changed we really should verify that
6503 it is installed before doing much else --jerry */
6505 /* Check calling user has permission to update printer description */
6506 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6507 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6508 result = WERR_ACCESS_DENIED;
6512 /* Call addprinter hook */
6513 /* Check changes to see if this is really needed */
6515 if (*lp_addprinter_cmd() &&
6516 (!strequal(printer->drivername, old_printer->drivername) ||
6517 !strequal(printer->comment, old_printer->comment) ||
6518 !strequal(printer->portname, old_printer->portname) ||
6519 !strequal(printer->location, old_printer->location)) )
6521 /* add_printer_hook() will call reload_services() */
6522 if (!add_printer_hook(tmp_ctx, p->server_info->security_token,
6523 printer, p->client_id->addr,
6525 result = WERR_ACCESS_DENIED;
6530 update_dsspooler(tmp_ctx,
6531 get_server_info_system(),
6537 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6539 if (devmode == NULL) {
6540 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6542 result = winreg_update_printer(tmp_ctx,
6543 get_server_info_system(),
6552 talloc_free(tmp_ctx);
6557 /****************************************************************************
6558 ****************************************************************************/
6559 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6560 struct policy_handle *handle,
6561 struct spoolss_SetPrinterInfo7 *info7)
6564 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6567 struct printer_handle *Printer;
6569 if ( lp_security() != SEC_ADS ) {
6570 return WERR_UNKNOWN_LEVEL;
6573 Printer = find_printer_index_by_hnd(p, handle);
6575 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6580 if (!get_printer_snum(p, handle, &snum, NULL))
6583 result = winreg_get_printer(p->mem_ctx,
6584 get_server_info_system(),
6586 lp_servicename(snum),
6588 if (!W_ERROR_IS_OK(result)) {
6592 nt_printer_publish(pinfo2,
6593 get_server_info_system(),
6598 TALLOC_FREE(pinfo2);
6601 return WERR_UNKNOWN_LEVEL;
6605 /********************************************************************
6606 ********************************************************************/
6608 static WERROR update_printer_devmode(struct pipes_struct *p,
6609 struct policy_handle *handle,
6610 struct spoolss_DeviceMode *devmode)
6613 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6614 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6616 DEBUG(8,("update_printer_devmode\n"));
6622 if (!get_printer_snum(p, handle, &snum, NULL)) {
6626 /* Check calling user has permission to update printer description */
6627 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6628 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6629 return WERR_ACCESS_DENIED;
6632 return winreg_update_printer(p->mem_ctx,
6633 get_server_info_system(),
6635 lp_const_servicename(snum),
6643 /****************************************************************
6645 ****************************************************************/
6647 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6648 struct spoolss_SetPrinter *r)
6652 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6655 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6656 OUR_HANDLE(r->in.handle)));
6660 /* check the level */
6661 switch (r->in.info_ctr->level) {
6663 return control_printer(r->in.handle, r->in.command, p);
6665 result = update_printer(p, r->in.handle,
6667 r->in.devmode_ctr->devmode);
6668 if (!W_ERROR_IS_OK(result))
6670 if (r->in.secdesc_ctr->sd)
6671 result = update_printer_sec(r->in.handle, p,
6675 return update_printer_sec(r->in.handle, p,
6678 return publish_or_unpublish_printer(p, r->in.handle,
6679 r->in.info_ctr->info.info7);
6681 return update_printer_devmode(p, r->in.handle,
6682 r->in.devmode_ctr->devmode);
6684 return WERR_UNKNOWN_LEVEL;
6688 /****************************************************************
6689 _spoolss_FindClosePrinterNotify
6690 ****************************************************************/
6692 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6693 struct spoolss_FindClosePrinterNotify *r)
6695 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6698 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6699 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6703 if (Printer->notify.cli_chan != NULL &&
6704 Printer->notify.cli_chan->active_connections > 0) {
6707 if (Printer->printer_type == SPLHND_PRINTER) {
6708 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6713 srv_spoolss_replycloseprinter(snum, Printer);
6716 Printer->notify.flags=0;
6717 Printer->notify.options=0;
6718 Printer->notify.localmachine[0]='\0';
6719 Printer->notify.printerlocal=0;
6720 TALLOC_FREE(Printer->notify.option);
6725 /****************************************************************
6727 ****************************************************************/
6729 WERROR _spoolss_AddJob(struct pipes_struct *p,
6730 struct spoolss_AddJob *r)
6732 if (!r->in.buffer && (r->in.offered != 0)) {
6733 return WERR_INVALID_PARAM;
6736 /* this is what a NT server returns for AddJob. AddJob must fail on
6737 * non-local printers */
6739 if (r->in.level != 1) {
6740 return WERR_UNKNOWN_LEVEL;
6743 return WERR_INVALID_PARAM;
6746 /****************************************************************************
6748 ****************************************************************************/
6750 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6751 struct spoolss_JobInfo1 *r,
6752 const print_queue_struct *queue,
6753 int position, int snum,
6754 struct spoolss_PrinterInfo2 *pinfo2)
6758 t = gmtime(&queue->time);
6760 r->job_id = queue->job;
6762 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6763 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6764 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6765 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6766 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6767 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6768 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6769 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6770 r->data_type = talloc_strdup(mem_ctx, "RAW");
6771 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6772 r->text_status = talloc_strdup(mem_ctx, "");
6773 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6775 r->status = nt_printj_status(queue->status);
6776 r->priority = queue->priority;
6777 r->position = position;
6778 r->total_pages = queue->page_count;
6779 r->pages_printed = 0; /* ??? */
6781 init_systemtime(&r->submitted, t);
6786 /****************************************************************************
6788 ****************************************************************************/
6790 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6791 struct spoolss_JobInfo2 *r,
6792 const print_queue_struct *queue,
6793 int position, int snum,
6794 struct spoolss_PrinterInfo2 *pinfo2,
6795 struct spoolss_DeviceMode *devmode)
6799 t = gmtime(&queue->time);
6801 r->job_id = queue->job;
6803 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6804 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6805 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6806 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6807 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6808 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6809 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6810 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6811 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6812 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6813 r->data_type = talloc_strdup(mem_ctx, "RAW");
6814 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6815 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6816 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6817 r->parameters = talloc_strdup(mem_ctx, "");
6818 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6819 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6820 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6822 r->devmode = devmode;
6824 r->text_status = talloc_strdup(mem_ctx, "");
6825 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6829 r->status = nt_printj_status(queue->status);
6830 r->priority = queue->priority;
6831 r->position = position;
6834 r->total_pages = queue->page_count;
6835 r->size = queue->size;
6836 init_systemtime(&r->submitted, t);
6838 r->pages_printed = 0; /* ??? */
6843 /****************************************************************************
6845 ****************************************************************************/
6847 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6848 struct spoolss_JobInfo3 *r,
6849 const print_queue_struct *queue,
6850 const print_queue_struct *next_queue,
6851 int position, int snum,
6852 struct spoolss_PrinterInfo2 *pinfo2)
6854 r->job_id = queue->job;
6857 r->next_job_id = next_queue->job;
6864 /****************************************************************************
6865 Enumjobs at level 1.
6866 ****************************************************************************/
6868 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6869 const print_queue_struct *queue,
6870 uint32_t num_queues, int snum,
6871 struct spoolss_PrinterInfo2 *pinfo2,
6872 union spoolss_JobInfo **info_p,
6875 union spoolss_JobInfo *info;
6877 WERROR result = WERR_OK;
6879 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6880 W_ERROR_HAVE_NO_MEMORY(info);
6882 *count = num_queues;
6884 for (i=0; i<*count; i++) {
6885 result = fill_job_info1(info,
6891 if (!W_ERROR_IS_OK(result)) {
6897 if (!W_ERROR_IS_OK(result)) {
6908 /****************************************************************************
6909 Enumjobs at level 2.
6910 ****************************************************************************/
6912 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6913 const print_queue_struct *queue,
6914 uint32_t num_queues, int snum,
6915 struct spoolss_PrinterInfo2 *pinfo2,
6916 union spoolss_JobInfo **info_p,
6919 union spoolss_JobInfo *info;
6921 WERROR result = WERR_OK;
6923 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6924 W_ERROR_HAVE_NO_MEMORY(info);
6926 *count = num_queues;
6928 for (i=0; i<*count; i++) {
6929 struct spoolss_DeviceMode *devmode;
6931 result = spoolss_create_default_devmode(info,
6932 pinfo2->printername,
6934 if (!W_ERROR_IS_OK(result)) {
6935 DEBUG(3, ("Can't proceed w/o a devmode!"));
6939 result = fill_job_info2(info,
6946 if (!W_ERROR_IS_OK(result)) {
6952 if (!W_ERROR_IS_OK(result)) {
6963 /****************************************************************************
6964 Enumjobs at level 3.
6965 ****************************************************************************/
6967 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6968 const print_queue_struct *queue,
6969 uint32_t num_queues, int snum,
6970 struct spoolss_PrinterInfo2 *pinfo2,
6971 union spoolss_JobInfo **info_p,
6974 union spoolss_JobInfo *info;
6976 WERROR result = WERR_OK;
6978 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6979 W_ERROR_HAVE_NO_MEMORY(info);
6981 *count = num_queues;
6983 for (i=0; i<*count; i++) {
6984 const print_queue_struct *next_queue = NULL;
6987 next_queue = &queue[i+1];
6990 result = fill_job_info3(info,
6997 if (!W_ERROR_IS_OK(result)) {
7003 if (!W_ERROR_IS_OK(result)) {
7014 /****************************************************************
7016 ****************************************************************/
7018 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
7019 struct spoolss_EnumJobs *r)
7022 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
7024 print_status_struct prt_status;
7025 print_queue_struct *queue = NULL;
7028 /* that's an [in out] buffer */
7030 if (!r->in.buffer && (r->in.offered != 0)) {
7031 return WERR_INVALID_PARAM;
7034 DEBUG(4,("_spoolss_EnumJobs\n"));
7038 *r->out.info = NULL;
7040 /* lookup the printer snum and tdb entry */
7042 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7046 result = winreg_get_printer(p->mem_ctx,
7047 get_server_info_system(),
7049 lp_const_servicename(snum),
7051 if (!W_ERROR_IS_OK(result)) {
7055 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
7056 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7057 count, prt_status.status, prt_status.message));
7061 TALLOC_FREE(pinfo2);
7065 switch (r->in.level) {
7067 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
7068 pinfo2, r->out.info, r->out.count);
7071 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
7072 pinfo2, r->out.info, r->out.count);
7075 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
7076 pinfo2, r->out.info, r->out.count);
7079 result = WERR_UNKNOWN_LEVEL;
7084 TALLOC_FREE(pinfo2);
7086 if (!W_ERROR_IS_OK(result)) {
7090 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7092 *r->out.info, r->in.level,
7094 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7095 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7097 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7100 /****************************************************************
7101 _spoolss_ScheduleJob
7102 ****************************************************************/
7104 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
7105 struct spoolss_ScheduleJob *r)
7110 /****************************************************************
7111 ****************************************************************/
7113 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
7114 struct messaging_context *msg_ctx,
7115 const char *printer_name,
7117 struct spoolss_SetJobInfo1 *r)
7121 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
7125 if (strequal(old_doc_name, r->document_name)) {
7129 if (!print_job_set_name(server_event_context(), msg_ctx,
7130 printer_name, job_id, r->document_name)) {
7137 /****************************************************************
7139 ****************************************************************/
7141 WERROR _spoolss_SetJob(struct pipes_struct *p,
7142 struct spoolss_SetJob *r)
7144 const struct auth_serversupplied_info *server_info = p->server_info;
7146 WERROR errcode = WERR_BADFUNC;
7148 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7152 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
7153 return WERR_INVALID_PRINTER_NAME;
7156 switch (r->in.command) {
7157 case SPOOLSS_JOB_CONTROL_CANCEL:
7158 case SPOOLSS_JOB_CONTROL_DELETE:
7159 errcode = print_job_delete(server_info, p->msg_ctx,
7160 snum, r->in.job_id);
7161 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
7165 case SPOOLSS_JOB_CONTROL_PAUSE:
7166 if (print_job_pause(server_info, p->msg_ctx,
7167 snum, r->in.job_id, &errcode)) {
7171 case SPOOLSS_JOB_CONTROL_RESTART:
7172 case SPOOLSS_JOB_CONTROL_RESUME:
7173 if (print_job_resume(server_info, p->msg_ctx,
7174 snum, r->in.job_id, &errcode)) {
7182 return WERR_UNKNOWN_LEVEL;
7185 if (!W_ERROR_IS_OK(errcode)) {
7189 if (r->in.ctr == NULL) {
7193 switch (r->in.ctr->level) {
7195 errcode = spoolss_setjob_1(p->mem_ctx, p->msg_ctx,
7196 lp_const_servicename(snum),
7198 r->in.ctr->info.info1);
7204 return WERR_UNKNOWN_LEVEL;
7210 /****************************************************************************
7211 Enumerates all printer drivers by level and architecture.
7212 ****************************************************************************/
7214 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
7215 const struct auth_serversupplied_info *server_info,
7216 struct messaging_context *msg_ctx,
7217 const char *servername,
7218 const char *architecture,
7220 union spoolss_DriverInfo **info_p,
7225 struct spoolss_DriverInfo8 *driver;
7226 union spoolss_DriverInfo *info = NULL;
7228 WERROR result = WERR_OK;
7229 uint32_t num_drivers;
7230 const char **drivers;
7235 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7236 result = winreg_get_driver_list(mem_ctx, server_info, msg_ctx,
7237 architecture, version,
7238 &num_drivers, &drivers);
7239 if (!W_ERROR_IS_OK(result)) {
7242 DEBUG(4, ("we have:[%d] drivers in environment"
7243 " [%s] and version [%d]\n",
7244 num_drivers, architecture, version));
7246 if (num_drivers != 0) {
7247 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
7248 union spoolss_DriverInfo,
7249 count + num_drivers);
7251 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7252 "failed to enlarge driver info buffer!\n"));
7253 result = WERR_NOMEM;
7258 for (i = 0; i < num_drivers; i++) {
7259 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
7261 result = winreg_get_driver(mem_ctx, server_info,
7263 architecture, drivers[i],
7265 if (!W_ERROR_IS_OK(result)) {
7271 result = fill_printer_driver_info1(info, &info[count+i].info1,
7272 driver, servername);
7275 result = fill_printer_driver_info2(info, &info[count+i].info2,
7276 driver, servername);
7279 result = fill_printer_driver_info3(info, &info[count+i].info3,
7280 driver, servername);
7283 result = fill_printer_driver_info4(info, &info[count+i].info4,
7284 driver, servername);
7287 result = fill_printer_driver_info5(info, &info[count+i].info5,
7288 driver, servername);
7291 result = fill_printer_driver_info6(info, &info[count+i].info6,
7292 driver, servername);
7295 result = fill_printer_driver_info8(info, &info[count+i].info8,
7296 driver, servername);
7299 result = WERR_UNKNOWN_LEVEL;
7303 TALLOC_FREE(driver);
7305 if (!W_ERROR_IS_OK(result)) {
7310 count += num_drivers;
7311 TALLOC_FREE(drivers);
7315 TALLOC_FREE(drivers);
7317 if (!W_ERROR_IS_OK(result)) {
7328 /****************************************************************************
7329 Enumerates all printer drivers by level.
7330 ****************************************************************************/
7332 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
7333 const struct auth_serversupplied_info *server_info,
7334 struct messaging_context *msg_ctx,
7335 const char *servername,
7336 const char *architecture,
7338 union spoolss_DriverInfo **info_p,
7342 WERROR result = WERR_OK;
7344 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
7346 for (a=0; archi_table[a].long_archi != NULL; a++) {
7348 union spoolss_DriverInfo *info = NULL;
7351 result = enumprinterdrivers_level_by_architecture(mem_ctx,
7355 archi_table[a].long_archi,
7359 if (!W_ERROR_IS_OK(result)) {
7363 for (i=0; i < count; i++) {
7364 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
7365 info[i], info_p, count_p);
7372 return enumprinterdrivers_level_by_architecture(mem_ctx,
7382 /****************************************************************
7383 _spoolss_EnumPrinterDrivers
7384 ****************************************************************/
7386 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
7387 struct spoolss_EnumPrinterDrivers *r)
7389 const char *cservername;
7392 /* that's an [in out] buffer */
7394 if (!r->in.buffer && (r->in.offered != 0)) {
7395 return WERR_INVALID_PARAM;
7398 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7402 *r->out.info = NULL;
7404 cservername = canon_servername(r->in.server);
7406 if (!is_myname_or_ipaddr(cservername)) {
7407 return WERR_UNKNOWN_PRINTER_DRIVER;
7410 result = enumprinterdrivers_level(p->mem_ctx,
7411 get_server_info_system(),
7418 if (!W_ERROR_IS_OK(result)) {
7422 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7423 spoolss_EnumPrinterDrivers,
7424 *r->out.info, r->in.level,
7426 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7427 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7429 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7432 /****************************************************************
7434 ****************************************************************/
7436 WERROR _spoolss_EnumForms(struct pipes_struct *p,
7437 struct spoolss_EnumForms *r)
7443 *r->out.info = NULL;
7445 /* that's an [in out] buffer */
7447 if (!r->in.buffer && (r->in.offered != 0) ) {
7448 return WERR_INVALID_PARAM;
7451 DEBUG(4,("_spoolss_EnumForms\n"));
7452 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7453 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7455 switch (r->in.level) {
7457 result = winreg_printer_enumforms1(p->mem_ctx,
7458 get_server_info_system(),
7464 result = WERR_UNKNOWN_LEVEL;
7468 if (!W_ERROR_IS_OK(result)) {
7472 if (*r->out.count == 0) {
7473 return WERR_NO_MORE_ITEMS;
7476 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7478 *r->out.info, r->in.level,
7480 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7481 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7483 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7486 /****************************************************************
7488 ****************************************************************/
7490 WERROR _spoolss_GetForm(struct pipes_struct *p,
7491 struct spoolss_GetForm *r)
7495 /* that's an [in out] buffer */
7497 if (!r->in.buffer && (r->in.offered != 0)) {
7498 return WERR_INVALID_PARAM;
7501 DEBUG(4,("_spoolss_GetForm\n"));
7502 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7503 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7505 switch (r->in.level) {
7507 result = winreg_printer_getform1(p->mem_ctx,
7508 get_server_info_system(),
7511 &r->out.info->info1);
7514 result = WERR_UNKNOWN_LEVEL;
7518 if (!W_ERROR_IS_OK(result)) {
7519 TALLOC_FREE(r->out.info);
7523 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7524 r->out.info, r->in.level);
7525 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7527 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7530 /****************************************************************************
7531 ****************************************************************************/
7533 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7534 struct spoolss_PortInfo1 *r,
7537 r->port_name = talloc_strdup(mem_ctx, name);
7538 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7543 /****************************************************************************
7544 TODO: This probably needs distinguish between TCP/IP and Local ports
7546 ****************************************************************************/
7548 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7549 struct spoolss_PortInfo2 *r,
7552 r->port_name = talloc_strdup(mem_ctx, name);
7553 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7555 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7556 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7558 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7559 W_ERROR_HAVE_NO_MEMORY(r->description);
7561 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7568 /****************************************************************************
7569 wrapper around the enumer ports command
7570 ****************************************************************************/
7572 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7574 char *cmd = lp_enumports_cmd();
7575 char **qlines = NULL;
7576 char *command = NULL;
7584 /* if no hook then just fill in the default port */
7587 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7590 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7591 TALLOC_FREE(qlines);
7598 /* we have a valid enumport command */
7600 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7605 DEBUG(10,("Running [%s]\n", command));
7606 ret = smbrun(command, &fd);
7607 DEBUG(10,("Returned [%d]\n", ret));
7608 TALLOC_FREE(command);
7613 return WERR_ACCESS_DENIED;
7617 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7618 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7628 /****************************************************************************
7630 ****************************************************************************/
7632 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7633 union spoolss_PortInfo **info_p,
7636 union spoolss_PortInfo *info = NULL;
7638 WERROR result = WERR_OK;
7639 char **qlines = NULL;
7642 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7643 if (!W_ERROR_IS_OK(result)) {
7648 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7650 DEBUG(10,("Returning WERR_NOMEM\n"));
7651 result = WERR_NOMEM;
7655 for (i=0; i<numlines; i++) {
7656 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7657 result = fill_port_1(info, &info[i].info1, qlines[i]);
7658 if (!W_ERROR_IS_OK(result)) {
7663 TALLOC_FREE(qlines);
7666 if (!W_ERROR_IS_OK(result)) {
7668 TALLOC_FREE(qlines);
7680 /****************************************************************************
7682 ****************************************************************************/
7684 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7685 union spoolss_PortInfo **info_p,
7688 union spoolss_PortInfo *info = NULL;
7690 WERROR result = WERR_OK;
7691 char **qlines = NULL;
7694 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7695 if (!W_ERROR_IS_OK(result)) {
7700 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7702 DEBUG(10,("Returning WERR_NOMEM\n"));
7703 result = WERR_NOMEM;
7707 for (i=0; i<numlines; i++) {
7708 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7709 result = fill_port_2(info, &info[i].info2, qlines[i]);
7710 if (!W_ERROR_IS_OK(result)) {
7715 TALLOC_FREE(qlines);
7718 if (!W_ERROR_IS_OK(result)) {
7720 TALLOC_FREE(qlines);
7732 /****************************************************************
7734 ****************************************************************/
7736 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
7737 struct spoolss_EnumPorts *r)
7741 /* that's an [in out] buffer */
7743 if (!r->in.buffer && (r->in.offered != 0)) {
7744 return WERR_INVALID_PARAM;
7747 DEBUG(4,("_spoolss_EnumPorts\n"));
7751 *r->out.info = NULL;
7753 switch (r->in.level) {
7755 result = enumports_level_1(p->mem_ctx, r->out.info,
7759 result = enumports_level_2(p->mem_ctx, r->out.info,
7763 return WERR_UNKNOWN_LEVEL;
7766 if (!W_ERROR_IS_OK(result)) {
7770 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7772 *r->out.info, r->in.level,
7774 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7775 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7777 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7780 /****************************************************************************
7781 ****************************************************************************/
7783 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
7785 struct spoolss_SetPrinterInfoCtr *info_ctr,
7786 struct spoolss_DeviceMode *devmode,
7787 struct security_descriptor *secdesc,
7788 struct spoolss_UserLevelCtr *user_ctr,
7789 struct policy_handle *handle)
7791 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7792 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7794 WERROR err = WERR_OK;
7796 /* samba does not have a concept of local, non-shared printers yet, so
7797 * make sure we always setup sharename - gd */
7798 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7799 (info2->printername != NULL && info2->printername[0] != '\0')) {
7800 DEBUG(5, ("spoolss_addprinterex_level_2: "
7801 "no sharename has been set, setting printername %s as sharename\n",
7802 info2->printername));
7803 info2->sharename = info2->printername;
7806 /* check to see if the printer already exists */
7807 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7808 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7810 return WERR_PRINTER_ALREADY_EXISTS;
7813 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7814 if ((snum = print_queue_snum(info2->printername)) != -1) {
7815 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7816 info2->printername));
7817 return WERR_PRINTER_ALREADY_EXISTS;
7821 /* validate printer info struct */
7822 if (!info2->printername || strlen(info2->printername) == 0) {
7823 return WERR_INVALID_PRINTER_NAME;
7825 if (!info2->portname || strlen(info2->portname) == 0) {
7826 return WERR_UNKNOWN_PORT;
7828 if (!info2->drivername || strlen(info2->drivername) == 0) {
7829 return WERR_UNKNOWN_PRINTER_DRIVER;
7831 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7832 return WERR_UNKNOWN_PRINTPROCESSOR;
7835 /* FIXME!!! smbd should check to see if the driver is installed before
7836 trying to add a printer like this --jerry */
7838 if (*lp_addprinter_cmd() ) {
7839 if ( !add_printer_hook(p->mem_ctx, p->server_info->security_token,
7840 info2, p->client_id->addr,
7842 return WERR_ACCESS_DENIED;
7845 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7846 "smb.conf parameter \"addprinter command\" is defined. This"
7847 "parameter must exist for this call to succeed\n",
7848 info2->sharename ));
7851 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7852 return WERR_ACCESS_DENIED;
7855 /* you must be a printer admin to add a new printer */
7856 if (!print_access_check(p->server_info,
7859 PRINTER_ACCESS_ADMINISTER)) {
7860 return WERR_ACCESS_DENIED;
7864 * Do sanity check on the requested changes for Samba.
7867 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7868 return WERR_INVALID_PARAM;
7871 if (devmode == NULL) {
7872 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7875 update_dsspooler(p->mem_ctx,
7876 get_server_info_system(),
7882 err = winreg_update_printer(p->mem_ctx,
7883 get_server_info_system(),
7890 if (!W_ERROR_IS_OK(err)) {
7894 err = open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER);
7895 if (!W_ERROR_IS_OK(err)) {
7896 /* Handle open failed - remove addition. */
7897 ZERO_STRUCTP(handle);
7904 /****************************************************************
7905 _spoolss_AddPrinterEx
7906 ****************************************************************/
7908 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
7909 struct spoolss_AddPrinterEx *r)
7911 switch (r->in.info_ctr->level) {
7913 /* we don't handle yet */
7914 /* but I know what to do ... */
7915 return WERR_UNKNOWN_LEVEL;
7917 return spoolss_addprinterex_level_2(p, r->in.server,
7919 r->in.devmode_ctr->devmode,
7920 r->in.secdesc_ctr->sd,
7921 r->in.userlevel_ctr,
7924 return WERR_UNKNOWN_LEVEL;
7928 /****************************************************************
7930 ****************************************************************/
7932 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
7933 struct spoolss_AddPrinter *r)
7935 struct spoolss_AddPrinterEx a;
7936 struct spoolss_UserLevelCtr userlevel_ctr;
7938 ZERO_STRUCT(userlevel_ctr);
7940 userlevel_ctr.level = 1;
7942 a.in.server = r->in.server;
7943 a.in.info_ctr = r->in.info_ctr;
7944 a.in.devmode_ctr = r->in.devmode_ctr;
7945 a.in.secdesc_ctr = r->in.secdesc_ctr;
7946 a.in.userlevel_ctr = &userlevel_ctr;
7947 a.out.handle = r->out.handle;
7949 return _spoolss_AddPrinterEx(p, &a);
7952 /****************************************************************
7953 _spoolss_AddPrinterDriverEx
7954 ****************************************************************/
7956 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
7957 struct spoolss_AddPrinterDriverEx *r)
7959 WERROR err = WERR_OK;
7960 const char *driver_name = NULL;
7965 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7966 fn = "_spoolss_AddPrinterDriver";
7968 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7969 fn = "_spoolss_AddPrinterDriverEx";
7972 return WERR_INVALID_PARAM;
7976 * we only support the semantics of AddPrinterDriver()
7977 * i.e. only copy files that are newer than existing ones
7980 if (r->in.flags == 0) {
7981 return WERR_INVALID_PARAM;
7984 if (r->in.flags != APD_COPY_NEW_FILES) {
7985 return WERR_ACCESS_DENIED;
7989 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7990 /* Clever hack from Martin Zielinski <mz@seh.de>
7991 * to allow downgrade from level 8 (Vista).
7993 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7994 r->in.info_ctr->level));
7995 return WERR_UNKNOWN_LEVEL;
7998 DEBUG(5,("Cleaning driver's information\n"));
7999 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
8000 if (!W_ERROR_IS_OK(err))
8003 DEBUG(5,("Moving driver to final destination\n"));
8004 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
8009 err = winreg_add_driver(p->mem_ctx,
8010 get_server_info_system(),
8015 if (!W_ERROR_IS_OK(err)) {
8020 * I think this is where he DrvUpgradePrinter() hook would be
8021 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8022 * server. Right now, we just need to send ourselves a message
8023 * to update each printer bound to this driver. --jerry
8026 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
8027 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8035 /****************************************************************
8036 _spoolss_AddPrinterDriver
8037 ****************************************************************/
8039 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
8040 struct spoolss_AddPrinterDriver *r)
8042 struct spoolss_AddPrinterDriverEx a;
8044 switch (r->in.info_ctr->level) {
8051 return WERR_UNKNOWN_LEVEL;
8054 a.in.servername = r->in.servername;
8055 a.in.info_ctr = r->in.info_ctr;
8056 a.in.flags = APD_COPY_NEW_FILES;
8058 return _spoolss_AddPrinterDriverEx(p, &a);
8061 /****************************************************************************
8062 ****************************************************************************/
8064 struct _spoolss_paths {
8070 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
8072 static const struct _spoolss_paths spoolss_paths[]= {
8073 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
8074 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
8077 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
8078 const char *servername,
8079 const char *environment,
8083 const char *pservername = NULL;
8084 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
8085 const char *short_archi;
8089 /* environment may be empty */
8090 if (environment && strlen(environment)) {
8091 long_archi = environment;
8094 /* servername may be empty */
8095 if (servername && strlen(servername)) {
8096 pservername = canon_servername(servername);
8098 if (!is_myname_or_ipaddr(pservername)) {
8099 return WERR_INVALID_PARAM;
8103 if (!(short_archi = get_short_archi(long_archi))) {
8104 return WERR_INVALID_ENVIRONMENT;
8107 switch (component) {
8108 case SPOOLSS_PRTPROCS_PATH:
8109 case SPOOLSS_DRIVER_PATH:
8111 *path = talloc_asprintf(mem_ctx,
8114 spoolss_paths[component].share,
8117 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
8118 SPOOLSS_DEFAULT_SERVER_PATH,
8119 spoolss_paths[component].dir,
8124 return WERR_INVALID_PARAM;
8134 /****************************************************************************
8135 ****************************************************************************/
8137 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
8138 const char *servername,
8139 const char *environment,
8140 struct spoolss_DriverDirectoryInfo1 *r)
8145 werr = compose_spoolss_server_path(mem_ctx,
8148 SPOOLSS_DRIVER_PATH,
8150 if (!W_ERROR_IS_OK(werr)) {
8154 DEBUG(4,("printer driver directory: [%s]\n", path));
8156 r->directory_name = path;
8161 /****************************************************************
8162 _spoolss_GetPrinterDriverDirectory
8163 ****************************************************************/
8165 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
8166 struct spoolss_GetPrinterDriverDirectory *r)
8170 /* that's an [in out] buffer */
8172 if (!r->in.buffer && (r->in.offered != 0)) {
8173 return WERR_INVALID_PARAM;
8176 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8181 /* r->in.level is ignored */
8183 werror = getprinterdriverdir_level_1(p->mem_ctx,
8186 &r->out.info->info1);
8187 if (!W_ERROR_IS_OK(werror)) {
8188 TALLOC_FREE(r->out.info);
8192 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
8193 r->out.info, r->in.level);
8194 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8196 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8199 /****************************************************************
8200 _spoolss_EnumPrinterData
8201 ****************************************************************/
8203 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
8204 struct spoolss_EnumPrinterData *r)
8207 struct spoolss_EnumPrinterDataEx r2;
8209 struct spoolss_PrinterEnumValues *info, *val = NULL;
8212 r2.in.handle = r->in.handle;
8213 r2.in.key_name = "PrinterDriverData";
8215 r2.out.count = &count;
8216 r2.out.info = &info;
8217 r2.out.needed = &needed;
8219 result = _spoolss_EnumPrinterDataEx(p, &r2);
8220 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8221 r2.in.offered = needed;
8222 result = _spoolss_EnumPrinterDataEx(p, &r2);
8224 if (!W_ERROR_IS_OK(result)) {
8229 * The NT machine wants to know the biggest size of value and data
8231 * cf: MSDN EnumPrinterData remark section
8234 if (!r->in.value_offered && !r->in.data_offered) {
8235 uint32_t biggest_valuesize = 0;
8236 uint32_t biggest_datasize = 0;
8239 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8241 for (i=0; i<count; i++) {
8243 name_length = strlen(info[i].value_name);
8244 if (strlen(info[i].value_name) > biggest_valuesize) {
8245 biggest_valuesize = name_length;
8248 if (info[i].data_length > biggest_datasize) {
8249 biggest_datasize = info[i].data_length;
8252 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8256 /* the value is an UNICODE string but real_value_size is the length
8257 in bytes including the trailing 0 */
8259 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8260 *r->out.data_needed = biggest_datasize;
8262 DEBUG(6,("final values: [%d], [%d]\n",
8263 *r->out.value_needed, *r->out.data_needed));
8268 if (r->in.enum_index < count) {
8269 val = &info[r->in.enum_index];
8273 /* out_value should default to "" or else NT4 has
8274 problems unmarshalling the response */
8276 if (r->in.value_offered) {
8277 *r->out.value_needed = 1;
8278 r->out.value_name = talloc_strdup(r, "");
8279 if (!r->out.value_name) {
8283 r->out.value_name = NULL;
8284 *r->out.value_needed = 0;
8287 /* the data is counted in bytes */
8289 *r->out.data_needed = r->in.data_offered;
8291 result = WERR_NO_MORE_ITEMS;
8295 * - counted in bytes in the request
8296 * - counted in UNICODE chars in the max reply
8297 * - counted in bytes in the real size
8299 * take a pause *before* coding not *during* coding
8303 if (r->in.value_offered) {
8304 r->out.value_name = talloc_strdup(r, val->value_name);
8305 if (!r->out.value_name) {
8308 *r->out.value_needed = val->value_name_len;
8310 r->out.value_name = NULL;
8311 *r->out.value_needed = 0;
8316 *r->out.type = val->type;
8318 /* data - counted in bytes */
8321 * See the section "Dynamically Typed Query Parameters"
8325 if (r->out.data && val->data && val->data->data &&
8326 val->data_length && r->in.data_offered) {
8327 memcpy(r->out.data, val->data->data,
8328 MIN(val->data_length,r->in.data_offered));
8331 *r->out.data_needed = val->data_length;
8339 /****************************************************************
8340 _spoolss_SetPrinterData
8341 ****************************************************************/
8343 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
8344 struct spoolss_SetPrinterData *r)
8346 struct spoolss_SetPrinterDataEx r2;
8348 r2.in.handle = r->in.handle;
8349 r2.in.key_name = "PrinterDriverData";
8350 r2.in.value_name = r->in.value_name;
8351 r2.in.type = r->in.type;
8352 r2.in.data = r->in.data;
8353 r2.in.offered = r->in.offered;
8355 return _spoolss_SetPrinterDataEx(p, &r2);
8358 /****************************************************************
8359 _spoolss_ResetPrinter
8360 ****************************************************************/
8362 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
8363 struct spoolss_ResetPrinter *r)
8365 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8368 DEBUG(5,("_spoolss_ResetPrinter\n"));
8371 * All we do is to check to see if the handle and queue is valid.
8372 * This call really doesn't mean anything to us because we only
8373 * support RAW printing. --jerry
8377 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8378 OUR_HANDLE(r->in.handle)));
8382 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8386 /* blindly return success */
8390 /****************************************************************
8391 _spoolss_DeletePrinterData
8392 ****************************************************************/
8394 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
8395 struct spoolss_DeletePrinterData *r)
8397 struct spoolss_DeletePrinterDataEx r2;
8399 r2.in.handle = r->in.handle;
8400 r2.in.key_name = "PrinterDriverData";
8401 r2.in.value_name = r->in.value_name;
8403 return _spoolss_DeletePrinterDataEx(p, &r2);
8406 /****************************************************************
8408 ****************************************************************/
8410 WERROR _spoolss_AddForm(struct pipes_struct *p,
8411 struct spoolss_AddForm *r)
8413 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8415 WERROR status = WERR_OK;
8417 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8419 DEBUG(5,("_spoolss_AddForm\n"));
8422 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8423 OUR_HANDLE(r->in.handle)));
8427 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8428 and not a printer admin, then fail */
8430 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8431 !security_token_has_privilege(p->server_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
8432 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8433 p->server_info->info3->base.domain.string,
8435 p->server_info->security_token,
8436 lp_printer_admin(snum))) {
8437 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8438 return WERR_ACCESS_DENIED;
8441 switch (form->flags) {
8442 case SPOOLSS_FORM_USER:
8443 case SPOOLSS_FORM_BUILTIN:
8444 case SPOOLSS_FORM_PRINTER:
8447 return WERR_INVALID_PARAM;
8450 status = winreg_printer_addform1(p->mem_ctx,
8451 get_server_info_system(),
8454 if (!W_ERROR_IS_OK(status)) {
8459 * ChangeID must always be set if this is a printer
8461 if (Printer->printer_type == SPLHND_PRINTER) {
8462 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8466 status = winreg_printer_update_changeid(p->mem_ctx,
8467 get_server_info_system(),
8469 lp_const_servicename(snum));
8470 if (!W_ERROR_IS_OK(status)) {
8478 /****************************************************************
8480 ****************************************************************/
8482 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8483 struct spoolss_DeleteForm *r)
8485 const char *form_name = r->in.form_name;
8486 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8488 WERROR status = WERR_OK;
8490 DEBUG(5,("_spoolss_DeleteForm\n"));
8493 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8494 OUR_HANDLE(r->in.handle)));
8498 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8499 !security_token_has_privilege(p->server_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
8500 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8501 p->server_info->info3->base.domain.string,
8503 p->server_info->security_token,
8504 lp_printer_admin(snum))) {
8505 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8506 return WERR_ACCESS_DENIED;
8509 status = winreg_printer_deleteform1(p->mem_ctx,
8510 get_server_info_system(),
8513 if (!W_ERROR_IS_OK(status)) {
8518 * ChangeID must always be set if this is a printer
8520 if (Printer->printer_type == SPLHND_PRINTER) {
8521 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8525 status = winreg_printer_update_changeid(p->mem_ctx,
8526 get_server_info_system(),
8528 lp_const_servicename(snum));
8529 if (!W_ERROR_IS_OK(status)) {
8537 /****************************************************************
8539 ****************************************************************/
8541 WERROR _spoolss_SetForm(struct pipes_struct *p,
8542 struct spoolss_SetForm *r)
8544 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8545 const char *form_name = r->in.form_name;
8547 WERROR status = WERR_OK;
8549 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8551 DEBUG(5,("_spoolss_SetForm\n"));
8554 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8555 OUR_HANDLE(r->in.handle)));
8559 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8560 and not a printer admin, then fail */
8562 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8563 !security_token_has_privilege(p->server_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
8564 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8565 p->server_info->info3->base.domain.string,
8567 p->server_info->security_token,
8568 lp_printer_admin(snum))) {
8569 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8570 return WERR_ACCESS_DENIED;
8573 status = winreg_printer_setform1(p->mem_ctx,
8574 get_server_info_system(),
8578 if (!W_ERROR_IS_OK(status)) {
8583 * ChangeID must always be set if this is a printer
8585 if (Printer->printer_type == SPLHND_PRINTER) {
8586 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8590 status = winreg_printer_update_changeid(p->mem_ctx,
8591 get_server_info_system(),
8593 lp_const_servicename(snum));
8594 if (!W_ERROR_IS_OK(status)) {
8602 /****************************************************************************
8603 fill_print_processor1
8604 ****************************************************************************/
8606 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8607 struct spoolss_PrintProcessorInfo1 *r,
8608 const char *print_processor_name)
8610 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8611 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8616 /****************************************************************************
8617 enumprintprocessors level 1.
8618 ****************************************************************************/
8620 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8621 union spoolss_PrintProcessorInfo **info_p,
8624 union spoolss_PrintProcessorInfo *info;
8627 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8628 W_ERROR_HAVE_NO_MEMORY(info);
8632 result = fill_print_processor1(info, &info[0].info1, "winprint");
8633 if (!W_ERROR_IS_OK(result)) {
8638 if (!W_ERROR_IS_OK(result)) {
8649 /****************************************************************
8650 _spoolss_EnumPrintProcessors
8651 ****************************************************************/
8653 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8654 struct spoolss_EnumPrintProcessors *r)
8658 /* that's an [in out] buffer */
8660 if (!r->in.buffer && (r->in.offered != 0)) {
8661 return WERR_INVALID_PARAM;
8664 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8667 * Enumerate the print processors ...
8669 * Just reply with "winprint", to keep NT happy
8670 * and I can use my nice printer checker.
8675 *r->out.info = NULL;
8677 if (!get_short_archi(r->in.environment)) {
8678 return WERR_INVALID_ENVIRONMENT;
8681 switch (r->in.level) {
8683 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8687 return WERR_UNKNOWN_LEVEL;
8690 if (!W_ERROR_IS_OK(result)) {
8694 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8695 spoolss_EnumPrintProcessors,
8696 *r->out.info, r->in.level,
8698 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8699 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8701 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8704 /****************************************************************************
8705 fill_printprocdatatype1
8706 ****************************************************************************/
8708 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8709 struct spoolss_PrintProcDataTypesInfo1 *r,
8710 const char *name_array)
8712 r->name_array = talloc_strdup(mem_ctx, name_array);
8713 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8718 /****************************************************************************
8719 enumprintprocdatatypes level 1.
8720 ****************************************************************************/
8722 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8723 union spoolss_PrintProcDataTypesInfo **info_p,
8727 union spoolss_PrintProcDataTypesInfo *info;
8729 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8730 W_ERROR_HAVE_NO_MEMORY(info);
8734 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8735 if (!W_ERROR_IS_OK(result)) {
8740 if (!W_ERROR_IS_OK(result)) {
8751 /****************************************************************
8752 _spoolss_EnumPrintProcDataTypes
8753 ****************************************************************/
8755 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
8756 struct spoolss_EnumPrintProcDataTypes *r)
8760 /* that's an [in out] buffer */
8762 if (!r->in.buffer && (r->in.offered != 0)) {
8763 return WERR_INVALID_PARAM;
8766 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8770 *r->out.info = NULL;
8772 if (r->in.print_processor_name == NULL ||
8773 !strequal(r->in.print_processor_name, "winprint")) {
8774 return WERR_UNKNOWN_PRINTPROCESSOR;
8777 switch (r->in.level) {
8779 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8783 return WERR_UNKNOWN_LEVEL;
8786 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8787 spoolss_EnumPrintProcDataTypes,
8788 *r->out.info, r->in.level,
8790 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8791 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8793 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8796 /****************************************************************************
8798 ****************************************************************************/
8800 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8801 struct spoolss_MonitorInfo1 *r,
8802 const char *monitor_name)
8804 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8805 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8810 /****************************************************************************
8812 ****************************************************************************/
8814 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8815 struct spoolss_MonitorInfo2 *r,
8816 const char *monitor_name,
8817 const char *environment,
8818 const char *dll_name)
8820 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8821 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8822 r->environment = talloc_strdup(mem_ctx, environment);
8823 W_ERROR_HAVE_NO_MEMORY(r->environment);
8824 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8825 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8830 /****************************************************************************
8831 enumprintmonitors level 1.
8832 ****************************************************************************/
8834 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8835 union spoolss_MonitorInfo **info_p,
8838 union spoolss_MonitorInfo *info;
8839 WERROR result = WERR_OK;
8841 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8842 W_ERROR_HAVE_NO_MEMORY(info);
8846 result = fill_monitor_1(info, &info[0].info1,
8848 if (!W_ERROR_IS_OK(result)) {
8852 result = fill_monitor_1(info, &info[1].info1,
8854 if (!W_ERROR_IS_OK(result)) {
8859 if (!W_ERROR_IS_OK(result)) {
8870 /****************************************************************************
8871 enumprintmonitors level 2.
8872 ****************************************************************************/
8874 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8875 union spoolss_MonitorInfo **info_p,
8878 union spoolss_MonitorInfo *info;
8879 WERROR result = WERR_OK;
8881 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8882 W_ERROR_HAVE_NO_MEMORY(info);
8886 result = fill_monitor_2(info, &info[0].info2,
8888 "Windows NT X86", /* FIXME */
8890 if (!W_ERROR_IS_OK(result)) {
8894 result = fill_monitor_2(info, &info[1].info2,
8896 "Windows NT X86", /* FIXME */
8898 if (!W_ERROR_IS_OK(result)) {
8903 if (!W_ERROR_IS_OK(result)) {
8914 /****************************************************************
8915 _spoolss_EnumMonitors
8916 ****************************************************************/
8918 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
8919 struct spoolss_EnumMonitors *r)
8923 /* that's an [in out] buffer */
8925 if (!r->in.buffer && (r->in.offered != 0)) {
8926 return WERR_INVALID_PARAM;
8929 DEBUG(5,("_spoolss_EnumMonitors\n"));
8932 * Enumerate the print monitors ...
8934 * Just reply with "Local Port", to keep NT happy
8935 * and I can use my nice printer checker.
8940 *r->out.info = NULL;
8942 switch (r->in.level) {
8944 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8948 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8952 return WERR_UNKNOWN_LEVEL;
8955 if (!W_ERROR_IS_OK(result)) {
8959 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8960 spoolss_EnumMonitors,
8961 *r->out.info, r->in.level,
8963 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8964 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8966 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8969 /****************************************************************************
8970 ****************************************************************************/
8972 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8973 const print_queue_struct *queue,
8974 int count, int snum,
8975 struct spoolss_PrinterInfo2 *pinfo2,
8977 struct spoolss_JobInfo1 *r)
8982 for (i=0; i<count; i++) {
8983 if (queue[i].job == (int)jobid) {
8989 if (found == false) {
8990 /* NT treats not found as bad param... yet another bad choice */
8991 return WERR_INVALID_PARAM;
8994 return fill_job_info1(mem_ctx,
9002 /****************************************************************************
9003 ****************************************************************************/
9005 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
9006 const print_queue_struct *queue,
9007 int count, int snum,
9008 struct spoolss_PrinterInfo2 *pinfo2,
9010 struct spoolss_JobInfo2 *r)
9014 struct spoolss_DeviceMode *devmode;
9017 for (i=0; i<count; i++) {
9018 if (queue[i].job == (int)jobid) {
9024 if (found == false) {
9025 /* NT treats not found as bad param... yet another bad
9027 return WERR_INVALID_PARAM;
9031 * if the print job does not have a DEVMODE associated with it,
9032 * just use the one for the printer. A NULL devicemode is not
9033 * a failure condition
9036 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
9038 result = spoolss_create_default_devmode(mem_ctx,
9039 pinfo2->printername,
9041 if (!W_ERROR_IS_OK(result)) {
9042 DEBUG(3, ("Can't proceed w/o a devmode!"));
9047 return fill_job_info2(mem_ctx,
9056 /****************************************************************
9058 ****************************************************************/
9060 WERROR _spoolss_GetJob(struct pipes_struct *p,
9061 struct spoolss_GetJob *r)
9063 WERROR result = WERR_OK;
9064 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9067 print_queue_struct *queue = NULL;
9068 print_status_struct prt_status;
9070 /* that's an [in out] buffer */
9072 if (!r->in.buffer && (r->in.offered != 0)) {
9073 return WERR_INVALID_PARAM;
9076 DEBUG(5,("_spoolss_GetJob\n"));
9080 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9084 result = winreg_get_printer(p->mem_ctx,
9085 get_server_info_system(),
9087 lp_const_servicename(snum),
9089 if (!W_ERROR_IS_OK(result)) {
9093 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
9095 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9096 count, prt_status.status, prt_status.message));
9098 switch (r->in.level) {
9100 result = getjob_level_1(p->mem_ctx,
9101 queue, count, snum, pinfo2,
9102 r->in.job_id, &r->out.info->info1);
9105 result = getjob_level_2(p->mem_ctx,
9106 queue, count, snum, pinfo2,
9107 r->in.job_id, &r->out.info->info2);
9110 result = WERR_UNKNOWN_LEVEL;
9115 TALLOC_FREE(pinfo2);
9117 if (!W_ERROR_IS_OK(result)) {
9118 TALLOC_FREE(r->out.info);
9122 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
9124 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9126 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9129 /****************************************************************
9130 _spoolss_GetPrinterDataEx
9131 ****************************************************************/
9133 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
9134 struct spoolss_GetPrinterDataEx *r)
9137 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9138 const char *printer;
9140 WERROR result = WERR_OK;
9142 enum winreg_Type val_type;
9147 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9149 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9150 r->in.key_name, r->in.value_name));
9152 /* in case of problem, return some default values */
9155 *r->out.type = REG_NONE;
9158 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9159 OUR_HANDLE(r->in.handle)));
9160 result = WERR_BADFID;
9164 /* Is the handle to a printer or to the server? */
9166 if (Printer->printer_type == SPLHND_SERVER) {
9168 union spoolss_PrinterData data;
9170 result = getprinterdata_printer_server(p->mem_ctx,
9174 if (!W_ERROR_IS_OK(result)) {
9178 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
9179 *r->out.type, &data);
9180 if (!W_ERROR_IS_OK(result)) {
9184 *r->out.needed = blob.length;
9186 if (r->in.offered >= *r->out.needed) {
9187 memcpy(r->out.data, blob.data, blob.length);
9190 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9193 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9196 printer = lp_const_servicename(snum);
9198 /* check to see if the keyname is valid */
9199 if (!strlen(r->in.key_name)) {
9200 return WERR_INVALID_PARAM;
9203 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9204 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
9205 strequal(r->in.value_name, "ChangeId")) {
9206 *r->out.type = REG_DWORD;
9208 if (r->in.offered >= *r->out.needed) {
9209 uint32_t changeid = 0;
9211 result = winreg_printer_get_changeid(p->mem_ctx,
9212 get_server_info_system(),
9216 if (!W_ERROR_IS_OK(result)) {
9220 SIVAL(r->out.data, 0, changeid);
9226 result = winreg_get_printer_dataex(p->mem_ctx,
9227 get_server_info_system(),
9235 if (!W_ERROR_IS_OK(result)) {
9239 *r->out.needed = val_size;
9240 *r->out.type = val_type;
9242 if (r->in.offered >= *r->out.needed) {
9243 memcpy(r->out.data, val_data, val_size);
9247 /* retain type when returning WERR_MORE_DATA */
9248 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
9250 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9253 /****************************************************************
9254 _spoolss_SetPrinterDataEx
9255 ****************************************************************/
9257 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
9258 struct spoolss_SetPrinterDataEx *r)
9260 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9262 WERROR result = WERR_OK;
9263 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9266 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9268 /* From MSDN documentation of SetPrinterDataEx: pass request to
9269 SetPrinterData if key is "PrinterDriverData" */
9272 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9273 OUR_HANDLE(r->in.handle)));
9277 if (Printer->printer_type == SPLHND_SERVER) {
9278 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9279 "Not implemented for server handles yet\n"));
9280 return WERR_INVALID_PARAM;
9283 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9288 * Access check : NT returns "access denied" if you make a
9289 * SetPrinterData call without the necessary privildge.
9290 * we were originally returning OK if nothing changed
9291 * which made Win2k issue **a lot** of SetPrinterData
9292 * when connecting to a printer --jerry
9295 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9296 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9297 "change denied by handle access permissions\n"));
9298 return WERR_ACCESS_DENIED;
9301 result = winreg_get_printer(Printer,
9302 get_server_info_system(),
9304 lp_servicename(snum),
9306 if (!W_ERROR_IS_OK(result)) {
9310 /* check for OID in valuename */
9312 oid_string = strchr(r->in.value_name, ',');
9318 /* save the registry data */
9320 result = winreg_set_printer_dataex(p->mem_ctx,
9321 get_server_info_system(),
9330 if (W_ERROR_IS_OK(result)) {
9331 /* save the OID if one was specified */
9333 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9334 r->in.key_name, SPOOL_OID_KEY);
9336 result = WERR_NOMEM;
9341 * I'm not checking the status here on purpose. Don't know
9342 * if this is right, but I'm returning the status from the
9343 * previous set_printer_dataex() call. I have no idea if
9344 * this is right. --jerry
9346 winreg_set_printer_dataex(p->mem_ctx,
9347 get_server_info_system(),
9353 (uint8_t *) oid_string,
9354 strlen(oid_string) + 1);
9357 result = winreg_printer_update_changeid(p->mem_ctx,
9358 get_server_info_system(),
9360 lp_const_servicename(snum));
9365 talloc_free(pinfo2);
9369 /****************************************************************
9370 _spoolss_DeletePrinterDataEx
9371 ****************************************************************/
9373 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
9374 struct spoolss_DeletePrinterDataEx *r)
9376 const char *printer;
9378 WERROR status = WERR_OK;
9379 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9381 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9384 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9385 "Invalid handle (%s:%u:%u).\n",
9386 OUR_HANDLE(r->in.handle)));
9390 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9391 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9392 "printer properties change denied by handle\n"));
9393 return WERR_ACCESS_DENIED;
9396 if (!r->in.value_name || !r->in.key_name) {
9400 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9403 printer = lp_const_servicename(snum);
9405 status = winreg_delete_printer_dataex(p->mem_ctx,
9406 get_server_info_system(),
9411 if (W_ERROR_IS_OK(status)) {
9412 status = winreg_printer_update_changeid(p->mem_ctx,
9413 get_server_info_system(),
9421 /****************************************************************
9422 _spoolss_EnumPrinterKey
9423 ****************************************************************/
9425 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
9426 struct spoolss_EnumPrinterKey *r)
9429 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9431 WERROR result = WERR_BADFILE;
9432 const char **array = NULL;
9435 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9438 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9439 OUR_HANDLE(r->in.handle)));
9443 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9447 result = winreg_enum_printer_key(p->mem_ctx,
9448 get_server_info_system(),
9450 lp_const_servicename(snum),
9454 if (!W_ERROR_IS_OK(result)) {
9458 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9459 result = WERR_NOMEM;
9463 *r->out._ndr_size = r->in.offered / 2;
9464 *r->out.needed = blob.length;
9466 if (r->in.offered < *r->out.needed) {
9467 result = WERR_MORE_DATA;
9470 r->out.key_buffer->string_array = array;
9474 if (!W_ERROR_IS_OK(result)) {
9476 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9484 /****************************************************************
9485 _spoolss_DeletePrinterKey
9486 ****************************************************************/
9488 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9489 struct spoolss_DeletePrinterKey *r)
9491 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9494 const char *printer;
9496 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9499 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9500 OUR_HANDLE(r->in.handle)));
9504 /* if keyname == NULL, return error */
9505 if ( !r->in.key_name )
9506 return WERR_INVALID_PARAM;
9508 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9512 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9513 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9514 "printer properties change denied by handle\n"));
9515 return WERR_ACCESS_DENIED;
9518 printer = lp_const_servicename(snum);
9520 /* delete the key and all subkeys */
9521 status = winreg_delete_printer_key(p->mem_ctx,
9522 get_server_info_system(),
9526 if (W_ERROR_IS_OK(status)) {
9527 status = winreg_printer_update_changeid(p->mem_ctx,
9528 get_server_info_system(),
9536 /****************************************************************
9537 _spoolss_EnumPrinterDataEx
9538 ****************************************************************/
9540 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9541 struct spoolss_EnumPrinterDataEx *r)
9544 struct spoolss_PrinterEnumValues *info = NULL;
9545 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9549 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9553 *r->out.info = NULL;
9556 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9557 OUR_HANDLE(r->in.handle)));
9562 * first check for a keyname of NULL or "". Win2k seems to send
9563 * this a lot and we should send back WERR_INVALID_PARAM
9564 * no need to spend time looking up the printer in this case.
9568 if (!strlen(r->in.key_name)) {
9569 result = WERR_INVALID_PARAM;
9573 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9577 /* now look for a match on the key name */
9578 result = winreg_enum_printer_dataex(p->mem_ctx,
9579 get_server_info_system(),
9581 lp_const_servicename(snum),
9585 if (!W_ERROR_IS_OK(result)) {
9589 #if 0 /* FIXME - gd */
9590 /* housekeeping information in the reply */
9592 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9593 * the hand marshalled container size is a multiple
9594 * of 4 bytes for RPC alignment.
9598 needed += 4-(needed % 4);
9601 *r->out.count = count;
9602 *r->out.info = info;
9605 if (!W_ERROR_IS_OK(result)) {
9609 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9610 spoolss_EnumPrinterDataEx,
9613 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9614 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9616 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9619 /****************************************************************************
9620 ****************************************************************************/
9622 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9623 const char *servername,
9624 const char *environment,
9625 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9630 werr = compose_spoolss_server_path(mem_ctx,
9633 SPOOLSS_PRTPROCS_PATH,
9635 if (!W_ERROR_IS_OK(werr)) {
9639 DEBUG(4,("print processor directory: [%s]\n", path));
9641 r->directory_name = path;
9646 /****************************************************************
9647 _spoolss_GetPrintProcessorDirectory
9648 ****************************************************************/
9650 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
9651 struct spoolss_GetPrintProcessorDirectory *r)
9654 char *prnproc_share = NULL;
9655 bool prnproc_share_exists = false;
9658 /* that's an [in out] buffer */
9660 if (!r->in.buffer && (r->in.offered != 0)) {
9661 return WERR_INVALID_PARAM;
9664 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9669 /* r->in.level is ignored */
9671 /* We always should reply with a local print processor directory so that
9672 * users are not forced to have a [prnproc$] share on the Samba spoolss
9673 * server, if users decide to do so, lets announce it though - Guenther */
9675 snum = find_service(talloc_tos(), "prnproc$", &prnproc_share);
9676 if (!prnproc_share) {
9680 prnproc_share_exists = true;
9683 result = getprintprocessordirectory_level_1(p->mem_ctx,
9684 prnproc_share_exists ? r->in.server : NULL,
9686 &r->out.info->info1);
9687 if (!W_ERROR_IS_OK(result)) {
9688 TALLOC_FREE(r->out.info);
9692 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9693 r->out.info, r->in.level);
9694 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9696 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9699 /*******************************************************************
9700 ********************************************************************/
9702 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9703 const char *dllname)
9705 enum ndr_err_code ndr_err;
9706 struct spoolss_MonitorUi ui;
9708 ui.dll_name = dllname;
9710 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9711 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9712 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9713 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9715 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9718 /*******************************************************************
9719 Streams the monitor UI DLL name in UNICODE
9720 *******************************************************************/
9722 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9723 struct security_token *token, DATA_BLOB *in,
9724 DATA_BLOB *out, uint32_t *needed)
9726 const char *dllname = "tcpmonui.dll";
9728 *needed = (strlen(dllname)+1) * 2;
9730 if (out->length < *needed) {
9731 return WERR_INSUFFICIENT_BUFFER;
9734 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9741 /*******************************************************************
9742 ********************************************************************/
9744 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9745 struct spoolss_PortData1 *port1,
9746 const DATA_BLOB *buf)
9748 enum ndr_err_code ndr_err;
9749 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9750 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9751 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9752 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9754 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9757 /*******************************************************************
9758 ********************************************************************/
9760 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9761 struct spoolss_PortData2 *port2,
9762 const DATA_BLOB *buf)
9764 enum ndr_err_code ndr_err;
9765 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9766 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9767 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9768 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9770 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9773 /*******************************************************************
9774 Create a new TCP/IP port
9775 *******************************************************************/
9777 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9778 struct security_token *token, DATA_BLOB *in,
9779 DATA_BLOB *out, uint32_t *needed)
9781 struct spoolss_PortData1 port1;
9782 struct spoolss_PortData2 port2;
9783 char *device_uri = NULL;
9786 const char *portname;
9787 const char *hostaddress;
9789 uint32_t port_number;
9792 /* peek for spoolss_PortData version */
9794 if (!in || (in->length < (128 + 4))) {
9795 return WERR_GENERAL_FAILURE;
9798 version = IVAL(in->data, 128);
9804 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9808 portname = port1.portname;
9809 hostaddress = port1.hostaddress;
9810 queue = port1.queue;
9811 protocol = port1.protocol;
9812 port_number = port1.port_number;
9818 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9822 portname = port2.portname;
9823 hostaddress = port2.hostaddress;
9824 queue = port2.queue;
9825 protocol = port2.protocol;
9826 port_number = port2.port_number;
9830 DEBUG(1,("xcvtcp_addport: "
9831 "unknown version of port_data: %d\n", version));
9832 return WERR_UNKNOWN_PORT;
9835 /* create the device URI and call the add_port_hook() */
9838 case PROTOCOL_RAWTCP_TYPE:
9839 device_uri = talloc_asprintf(mem_ctx,
9840 "socket://%s:%d/", hostaddress,
9844 case PROTOCOL_LPR_TYPE:
9845 device_uri = talloc_asprintf(mem_ctx,
9846 "lpr://%s/%s", hostaddress, queue );
9850 return WERR_UNKNOWN_PORT;
9857 return add_port_hook(mem_ctx, token, portname, device_uri);
9860 /*******************************************************************
9861 *******************************************************************/
9863 struct xcv_api_table xcvtcp_cmds[] = {
9864 { "MonitorUI", xcvtcp_monitorui },
9865 { "AddPort", xcvtcp_addport},
9869 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9870 struct security_token *token, const char *command,
9877 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9879 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9880 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9881 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9884 return WERR_BADFUNC;
9887 /*******************************************************************
9888 *******************************************************************/
9889 #if 0 /* don't support management using the "Local Port" monitor */
9891 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9892 struct security_token *token, DATA_BLOB *in,
9893 DATA_BLOB *out, uint32_t *needed)
9895 const char *dllname = "localui.dll";
9897 *needed = (strlen(dllname)+1) * 2;
9899 if (out->length < *needed) {
9900 return WERR_INSUFFICIENT_BUFFER;
9903 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9910 /*******************************************************************
9911 *******************************************************************/
9913 struct xcv_api_table xcvlocal_cmds[] = {
9914 { "MonitorUI", xcvlocal_monitorui },
9918 struct xcv_api_table xcvlocal_cmds[] = {
9925 /*******************************************************************
9926 *******************************************************************/
9928 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9929 struct security_token *token, const char *command,
9930 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9935 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9937 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9938 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9939 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9941 return WERR_BADFUNC;
9944 /****************************************************************
9946 ****************************************************************/
9948 WERROR _spoolss_XcvData(struct pipes_struct *p,
9949 struct spoolss_XcvData *r)
9951 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9952 DATA_BLOB out_data = data_blob_null;
9956 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9957 OUR_HANDLE(r->in.handle)));
9961 /* Has to be a handle to the TCP/IP port monitor */
9963 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9964 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9968 /* requires administrative access to the server */
9970 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9971 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9972 return WERR_ACCESS_DENIED;
9975 /* Allocate the outgoing buffer */
9977 if (r->in.out_data_size) {
9978 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9979 if (out_data.data == NULL) {
9984 switch ( Printer->printer_type ) {
9985 case SPLHND_PORTMON_TCP:
9986 werror = process_xcvtcp_command(p->mem_ctx,
9987 p->server_info->security_token,
9988 r->in.function_name,
9989 &r->in.in_data, &out_data,
9992 case SPLHND_PORTMON_LOCAL:
9993 werror = process_xcvlocal_command(p->mem_ctx,
9994 p->server_info->security_token,
9995 r->in.function_name,
9996 &r->in.in_data, &out_data,
10000 werror = WERR_INVALID_PRINT_MONITOR;
10003 if (!W_ERROR_IS_OK(werror)) {
10007 *r->out.status_code = 0;
10009 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
10010 memcpy(r->out.out_data, out_data.data,
10011 MIN(r->in.out_data_size, out_data.length));
10017 /****************************************************************
10018 _spoolss_AddPrintProcessor
10019 ****************************************************************/
10021 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
10022 struct spoolss_AddPrintProcessor *r)
10024 /* for now, just indicate success and ignore the add. We'll
10025 automatically set the winprint processor for printer
10026 entries later. Used to debug the LexMark Optra S 1855 PCL
10032 /****************************************************************
10034 ****************************************************************/
10036 WERROR _spoolss_AddPort(struct pipes_struct *p,
10037 struct spoolss_AddPort *r)
10039 /* do what w2k3 does */
10041 return WERR_NOT_SUPPORTED;
10044 /****************************************************************
10045 _spoolss_GetPrinterDriver
10046 ****************************************************************/
10048 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
10049 struct spoolss_GetPrinterDriver *r)
10051 p->rng_fault_state = true;
10052 return WERR_NOT_SUPPORTED;
10055 /****************************************************************
10056 _spoolss_ReadPrinter
10057 ****************************************************************/
10059 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
10060 struct spoolss_ReadPrinter *r)
10062 p->rng_fault_state = true;
10063 return WERR_NOT_SUPPORTED;
10066 /****************************************************************
10067 _spoolss_WaitForPrinterChange
10068 ****************************************************************/
10070 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
10071 struct spoolss_WaitForPrinterChange *r)
10073 p->rng_fault_state = true;
10074 return WERR_NOT_SUPPORTED;
10077 /****************************************************************
10078 _spoolss_ConfigurePort
10079 ****************************************************************/
10081 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
10082 struct spoolss_ConfigurePort *r)
10084 p->rng_fault_state = true;
10085 return WERR_NOT_SUPPORTED;
10088 /****************************************************************
10089 _spoolss_DeletePort
10090 ****************************************************************/
10092 WERROR _spoolss_DeletePort(struct pipes_struct *p,
10093 struct spoolss_DeletePort *r)
10095 p->rng_fault_state = true;
10096 return WERR_NOT_SUPPORTED;
10099 /****************************************************************
10100 _spoolss_CreatePrinterIC
10101 ****************************************************************/
10103 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
10104 struct spoolss_CreatePrinterIC *r)
10106 p->rng_fault_state = true;
10107 return WERR_NOT_SUPPORTED;
10110 /****************************************************************
10111 _spoolss_PlayGDIScriptOnPrinterIC
10112 ****************************************************************/
10114 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
10115 struct spoolss_PlayGDIScriptOnPrinterIC *r)
10117 p->rng_fault_state = true;
10118 return WERR_NOT_SUPPORTED;
10121 /****************************************************************
10122 _spoolss_DeletePrinterIC
10123 ****************************************************************/
10125 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
10126 struct spoolss_DeletePrinterIC *r)
10128 p->rng_fault_state = true;
10129 return WERR_NOT_SUPPORTED;
10132 /****************************************************************
10133 _spoolss_AddPrinterConnection
10134 ****************************************************************/
10136 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
10137 struct spoolss_AddPrinterConnection *r)
10139 p->rng_fault_state = true;
10140 return WERR_NOT_SUPPORTED;
10143 /****************************************************************
10144 _spoolss_DeletePrinterConnection
10145 ****************************************************************/
10147 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
10148 struct spoolss_DeletePrinterConnection *r)
10150 p->rng_fault_state = true;
10151 return WERR_NOT_SUPPORTED;
10154 /****************************************************************
10155 _spoolss_PrinterMessageBox
10156 ****************************************************************/
10158 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
10159 struct spoolss_PrinterMessageBox *r)
10161 p->rng_fault_state = true;
10162 return WERR_NOT_SUPPORTED;
10165 /****************************************************************
10166 _spoolss_AddMonitor
10167 ****************************************************************/
10169 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
10170 struct spoolss_AddMonitor *r)
10172 p->rng_fault_state = true;
10173 return WERR_NOT_SUPPORTED;
10176 /****************************************************************
10177 _spoolss_DeleteMonitor
10178 ****************************************************************/
10180 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
10181 struct spoolss_DeleteMonitor *r)
10183 p->rng_fault_state = true;
10184 return WERR_NOT_SUPPORTED;
10187 /****************************************************************
10188 _spoolss_DeletePrintProcessor
10189 ****************************************************************/
10191 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
10192 struct spoolss_DeletePrintProcessor *r)
10194 p->rng_fault_state = true;
10195 return WERR_NOT_SUPPORTED;
10198 /****************************************************************
10199 _spoolss_AddPrintProvidor
10200 ****************************************************************/
10202 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
10203 struct spoolss_AddPrintProvidor *r)
10205 p->rng_fault_state = true;
10206 return WERR_NOT_SUPPORTED;
10209 /****************************************************************
10210 _spoolss_DeletePrintProvidor
10211 ****************************************************************/
10213 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
10214 struct spoolss_DeletePrintProvidor *r)
10216 p->rng_fault_state = true;
10217 return WERR_NOT_SUPPORTED;
10220 /****************************************************************
10221 _spoolss_FindFirstPrinterChangeNotification
10222 ****************************************************************/
10224 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
10225 struct spoolss_FindFirstPrinterChangeNotification *r)
10227 p->rng_fault_state = true;
10228 return WERR_NOT_SUPPORTED;
10231 /****************************************************************
10232 _spoolss_FindNextPrinterChangeNotification
10233 ****************************************************************/
10235 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
10236 struct spoolss_FindNextPrinterChangeNotification *r)
10238 p->rng_fault_state = true;
10239 return WERR_NOT_SUPPORTED;
10242 /****************************************************************
10243 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10244 ****************************************************************/
10246 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
10247 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10249 p->rng_fault_state = true;
10250 return WERR_NOT_SUPPORTED;
10253 /****************************************************************
10254 _spoolss_ReplyOpenPrinter
10255 ****************************************************************/
10257 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
10258 struct spoolss_ReplyOpenPrinter *r)
10260 p->rng_fault_state = true;
10261 return WERR_NOT_SUPPORTED;
10264 /****************************************************************
10265 _spoolss_RouterReplyPrinter
10266 ****************************************************************/
10268 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
10269 struct spoolss_RouterReplyPrinter *r)
10271 p->rng_fault_state = true;
10272 return WERR_NOT_SUPPORTED;
10275 /****************************************************************
10276 _spoolss_ReplyClosePrinter
10277 ****************************************************************/
10279 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
10280 struct spoolss_ReplyClosePrinter *r)
10282 p->rng_fault_state = true;
10283 return WERR_NOT_SUPPORTED;
10286 /****************************************************************
10288 ****************************************************************/
10290 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
10291 struct spoolss_AddPortEx *r)
10293 p->rng_fault_state = true;
10294 return WERR_NOT_SUPPORTED;
10297 /****************************************************************
10298 _spoolss_RouterFindFirstPrinterChangeNotification
10299 ****************************************************************/
10301 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
10302 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10304 p->rng_fault_state = true;
10305 return WERR_NOT_SUPPORTED;
10308 /****************************************************************
10309 _spoolss_SpoolerInit
10310 ****************************************************************/
10312 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
10313 struct spoolss_SpoolerInit *r)
10315 p->rng_fault_state = true;
10316 return WERR_NOT_SUPPORTED;
10319 /****************************************************************
10320 _spoolss_ResetPrinterEx
10321 ****************************************************************/
10323 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
10324 struct spoolss_ResetPrinterEx *r)
10326 p->rng_fault_state = true;
10327 return WERR_NOT_SUPPORTED;
10330 /****************************************************************
10331 _spoolss_RouterReplyPrinterEx
10332 ****************************************************************/
10334 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
10335 struct spoolss_RouterReplyPrinterEx *r)
10337 p->rng_fault_state = true;
10338 return WERR_NOT_SUPPORTED;
10341 /****************************************************************
10343 ****************************************************************/
10345 WERROR _spoolss_44(struct pipes_struct *p,
10346 struct spoolss_44 *r)
10348 p->rng_fault_state = true;
10349 return WERR_NOT_SUPPORTED;
10352 /****************************************************************
10354 ****************************************************************/
10356 WERROR _spoolss_SetPort(struct pipes_struct *p,
10357 struct spoolss_SetPort *r)
10359 p->rng_fault_state = true;
10360 return WERR_NOT_SUPPORTED;
10363 /****************************************************************
10365 ****************************************************************/
10367 WERROR _spoolss_4a(struct pipes_struct *p,
10368 struct spoolss_4a *r)
10370 p->rng_fault_state = true;
10371 return WERR_NOT_SUPPORTED;
10374 /****************************************************************
10376 ****************************************************************/
10378 WERROR _spoolss_4b(struct pipes_struct *p,
10379 struct spoolss_4b *r)
10381 p->rng_fault_state = true;
10382 return WERR_NOT_SUPPORTED;
10385 /****************************************************************
10387 ****************************************************************/
10389 WERROR _spoolss_4c(struct pipes_struct *p,
10390 struct spoolss_4c *r)
10392 p->rng_fault_state = true;
10393 return WERR_NOT_SUPPORTED;
10396 /****************************************************************
10398 ****************************************************************/
10400 WERROR _spoolss_53(struct pipes_struct *p,
10401 struct spoolss_53 *r)
10403 p->rng_fault_state = true;
10404 return WERR_NOT_SUPPORTED;
10407 /****************************************************************
10408 _spoolss_AddPerMachineConnection
10409 ****************************************************************/
10411 WERROR _spoolss_AddPerMachineConnection(struct pipes_struct *p,
10412 struct spoolss_AddPerMachineConnection *r)
10414 p->rng_fault_state = true;
10415 return WERR_NOT_SUPPORTED;
10418 /****************************************************************
10419 _spoolss_DeletePerMachineConnection
10420 ****************************************************************/
10422 WERROR _spoolss_DeletePerMachineConnection(struct pipes_struct *p,
10423 struct spoolss_DeletePerMachineConnection *r)
10425 p->rng_fault_state = true;
10426 return WERR_NOT_SUPPORTED;
10429 /****************************************************************
10430 _spoolss_EnumPerMachineConnections
10431 ****************************************************************/
10433 WERROR _spoolss_EnumPerMachineConnections(struct pipes_struct *p,
10434 struct spoolss_EnumPerMachineConnections *r)
10436 p->rng_fault_state = true;
10437 return WERR_NOT_SUPPORTED;
10440 /****************************************************************
10442 ****************************************************************/
10444 WERROR _spoolss_5a(struct pipes_struct *p,
10445 struct spoolss_5a *r)
10447 p->rng_fault_state = true;
10448 return WERR_NOT_SUPPORTED;
10451 /****************************************************************
10453 ****************************************************************/
10455 WERROR _spoolss_5b(struct pipes_struct *p,
10456 struct spoolss_5b *r)
10458 p->rng_fault_state = true;
10459 return WERR_NOT_SUPPORTED;
10462 /****************************************************************
10464 ****************************************************************/
10466 WERROR _spoolss_5c(struct pipes_struct *p,
10467 struct spoolss_5c *r)
10469 p->rng_fault_state = true;
10470 return WERR_NOT_SUPPORTED;
10473 /****************************************************************
10475 ****************************************************************/
10477 WERROR _spoolss_5d(struct pipes_struct *p,
10478 struct spoolss_5d *r)
10480 p->rng_fault_state = true;
10481 return WERR_NOT_SUPPORTED;
10484 /****************************************************************
10486 ****************************************************************/
10488 WERROR _spoolss_5e(struct pipes_struct *p,
10489 struct spoolss_5e *r)
10491 p->rng_fault_state = true;
10492 return WERR_NOT_SUPPORTED;
10495 /****************************************************************
10497 ****************************************************************/
10499 WERROR _spoolss_5f(struct pipes_struct *p,
10500 struct spoolss_5f *r)
10502 p->rng_fault_state = true;
10503 return WERR_NOT_SUPPORTED;
10506 /****************************************************************
10508 ****************************************************************/
10510 WERROR _spoolss_60(struct pipes_struct *p,
10511 struct spoolss_60 *r)
10513 p->rng_fault_state = true;
10514 return WERR_NOT_SUPPORTED;
10517 /****************************************************************
10519 ****************************************************************/
10521 WERROR _spoolss_61(struct pipes_struct *p,
10522 struct spoolss_61 *r)
10524 p->rng_fault_state = true;
10525 return WERR_NOT_SUPPORTED;
10528 /****************************************************************
10530 ****************************************************************/
10532 WERROR _spoolss_62(struct pipes_struct *p,
10533 struct spoolss_62 *r)
10535 p->rng_fault_state = true;
10536 return WERR_NOT_SUPPORTED;
10539 /****************************************************************
10541 ****************************************************************/
10543 WERROR _spoolss_63(struct pipes_struct *p,
10544 struct spoolss_63 *r)
10546 p->rng_fault_state = true;
10547 return WERR_NOT_SUPPORTED;
10550 /****************************************************************
10552 ****************************************************************/
10554 WERROR _spoolss_64(struct pipes_struct *p,
10555 struct spoolss_64 *r)
10557 p->rng_fault_state = true;
10558 return WERR_NOT_SUPPORTED;
10561 /****************************************************************
10563 ****************************************************************/
10565 WERROR _spoolss_65(struct pipes_struct *p,
10566 struct spoolss_65 *r)
10568 p->rng_fault_state = true;
10569 return WERR_NOT_SUPPORTED;
10572 /****************************************************************
10573 _spoolss_GetCorePrinterDrivers
10574 ****************************************************************/
10576 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10577 struct spoolss_GetCorePrinterDrivers *r)
10579 p->rng_fault_state = true;
10580 return WERR_NOT_SUPPORTED;
10583 /****************************************************************
10585 ****************************************************************/
10587 WERROR _spoolss_67(struct pipes_struct *p,
10588 struct spoolss_67 *r)
10590 p->rng_fault_state = true;
10591 return WERR_NOT_SUPPORTED;
10594 /****************************************************************
10595 _spoolss_GetPrinterDriverPackagePath
10596 ****************************************************************/
10598 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10599 struct spoolss_GetPrinterDriverPackagePath *r)
10601 p->rng_fault_state = true;
10602 return WERR_NOT_SUPPORTED;
10605 /****************************************************************
10607 ****************************************************************/
10609 WERROR _spoolss_69(struct pipes_struct *p,
10610 struct spoolss_69 *r)
10612 p->rng_fault_state = true;
10613 return WERR_NOT_SUPPORTED;
10616 /****************************************************************
10618 ****************************************************************/
10620 WERROR _spoolss_6a(struct pipes_struct *p,
10621 struct spoolss_6a *r)
10623 p->rng_fault_state = true;
10624 return WERR_NOT_SUPPORTED;
10627 /****************************************************************
10629 ****************************************************************/
10631 WERROR _spoolss_6b(struct pipes_struct *p,
10632 struct spoolss_6b *r)
10634 p->rng_fault_state = true;
10635 return WERR_NOT_SUPPORTED;
10638 /****************************************************************
10640 ****************************************************************/
10642 WERROR _spoolss_6c(struct pipes_struct *p,
10643 struct spoolss_6c *r)
10645 p->rng_fault_state = true;
10646 return WERR_NOT_SUPPORTED;
10649 /****************************************************************
10651 ****************************************************************/
10653 WERROR _spoolss_6d(struct pipes_struct *p,
10654 struct spoolss_6d *r)
10656 p->rng_fault_state = true;
10657 return WERR_NOT_SUPPORTED;