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/cli_spoolss.h"
35 #include "rpc_client/init_spoolss.h"
36 #include "librpc/gen_ndr/messaging.h"
37 #include "librpc/gen_ndr/ndr_security.h"
39 #include "registry/reg_objects.h"
40 #include "include/printing.h"
42 #include "../librpc/gen_ndr/netlogon.h"
45 /* macros stolen from s4 spoolss server */
46 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
47 ((info)?ndr_size_##fn(info, level, 0):0)
49 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
50 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
52 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
53 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
55 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
58 #define DBGC_CLASS DBGC_RPC_SRV
60 #ifndef MAX_OPEN_PRINTER_EXS
61 #define MAX_OPEN_PRINTER_EXS 50
64 struct notify_back_channel;
66 /* structure to store the printer handles */
67 /* and a reference to what it's pointing to */
68 /* and the notify info asked about */
69 /* that's the central struct */
70 struct printer_handle {
71 struct printer_handle *prev, *next;
72 bool document_started;
74 uint32 jobid; /* jobid in printing backend */
79 uint32 access_granted;
85 struct spoolss_NotifyOption *option;
86 struct policy_handle cli_hnd;
87 struct notify_back_channel *cli_chan;
89 /* are we in a FindNextPrinterChangeNotify() call? */
91 struct messaging_context *msg_ctx;
98 /* devmode sent in the OpenPrinter() call */
99 struct spoolss_DeviceMode *devmode;
101 /* TODO cache the printer info2 structure */
102 struct spoolss_PrinterInfo2 *info2;
106 static struct printer_handle *printers_list;
108 struct printer_session_counter {
109 struct printer_session_counter *next;
110 struct printer_session_counter *prev;
116 static struct printer_session_counter *counter_list;
118 struct notify_back_channel {
119 struct notify_back_channel *prev, *next;
121 /* associated client */
122 struct sockaddr_storage client_address;
124 /* print notify back-channel pipe handle*/
125 struct rpc_pipe_client *cli_pipe;
126 uint32_t active_connections;
129 static struct notify_back_channel *back_channels;
131 /* Map generic permissions to printer object specific permissions */
133 const struct standard_mapping printer_std_mapping = {
140 /* Map generic permissions to print server object specific permissions */
142 const struct standard_mapping printserver_std_mapping = {
149 /* API table for Xcv Monitor functions */
151 struct xcv_api_table {
153 WERROR(*fn) (TALLOC_CTX *mem_ctx, NT_USER_TOKEN *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
156 static void prune_printername_cache(void);
158 /********************************************************************
159 * Canonicalize servername.
160 ********************************************************************/
162 static const char *canon_servername(const char *servername)
164 const char *pservername = servername;
165 while (*pservername == '\\') {
171 /* translate between internal status numbers and NT status numbers */
172 static int nt_printj_status(int v)
178 return JOB_STATUS_PAUSED;
180 return JOB_STATUS_SPOOLING;
182 return JOB_STATUS_PRINTING;
184 return JOB_STATUS_ERROR;
186 return JOB_STATUS_DELETING;
188 return JOB_STATUS_OFFLINE;
190 return JOB_STATUS_PAPEROUT;
192 return JOB_STATUS_PRINTED;
194 return JOB_STATUS_DELETED;
196 return JOB_STATUS_BLOCKED_DEVQ;
197 case LPQ_USER_INTERVENTION:
198 return JOB_STATUS_USER_INTERVENTION;
203 static int nt_printq_status(int v)
207 return PRINTER_STATUS_PAUSED;
216 /***************************************************************************
217 Disconnect from the client
218 ****************************************************************************/
220 static void srv_spoolss_replycloseprinter(int snum,
221 struct printer_handle *prn_hnd)
227 * Tell the specific printing tdb we no longer want messages for this printer
228 * by deregistering our PID.
231 if (!print_notify_deregister_pid(snum)) {
232 DEBUG(0, ("Failed to register our pid for printer %s\n",
233 lp_const_servicename(snum)));
236 /* weird if the test succeeds !!! */
237 if (prn_hnd->notify.cli_chan == NULL ||
238 prn_hnd->notify.cli_chan->active_connections == 0) {
239 DEBUG(0, ("Trying to close unexisting backchannel!\n"));
240 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
241 TALLOC_FREE(prn_hnd->notify.cli_chan);
245 status = rpccli_spoolss_ReplyClosePrinter(
246 prn_hnd->notify.cli_chan->cli_pipe,
248 &prn_hnd->notify.cli_hnd,
250 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
251 DEBUG(0, ("reply_close_printer failed [%s].\n",
252 win_errstr(result)));
255 /* if it's the last connection, deconnect the IPC$ share */
256 if (prn_hnd->notify.cli_chan->active_connections == 1) {
258 cli_shutdown(rpc_pipe_np_smb_conn(prn_hnd->notify.cli_chan->cli_pipe));
259 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
260 TALLOC_FREE(prn_hnd->notify.cli_chan);
262 if (prn_hnd->notify.msg_ctx != NULL) {
263 messaging_deregister(prn_hnd->notify.msg_ctx,
264 MSG_PRINTER_NOTIFY2, NULL);
267 * Tell the serverid.tdb we're no longer
268 * interested in printer notify messages.
271 serverid_register_msg_flags(
272 messaging_server_id(prn_hnd->notify.msg_ctx),
273 false, FLAG_MSG_PRINT_NOTIFY);
277 if (prn_hnd->notify.cli_chan) {
278 prn_hnd->notify.cli_chan->active_connections--;
282 /****************************************************************************
283 Functions to free a printer entry datastruct.
284 ****************************************************************************/
286 static int printer_entry_destructor(struct printer_handle *Printer)
288 if (Printer->notify.cli_chan != NULL &&
289 Printer->notify.cli_chan->active_connections > 0) {
292 switch(Printer->printer_type) {
294 srv_spoolss_replycloseprinter(snum, Printer);
298 snum = print_queue_snum(Printer->sharename);
300 srv_spoolss_replycloseprinter(snum, Printer);
308 Printer->notify.flags=0;
309 Printer->notify.options=0;
310 Printer->notify.localmachine[0]='\0';
311 Printer->notify.printerlocal=0;
312 TALLOC_FREE(Printer->notify.option);
313 TALLOC_FREE(Printer->devmode);
315 /* Remove from the internal list. */
316 DLIST_REMOVE(printers_list, Printer);
320 /****************************************************************************
321 find printer index by handle
322 ****************************************************************************/
324 static struct printer_handle *find_printer_index_by_hnd(struct pipes_struct *p,
325 struct policy_handle *hnd)
327 struct printer_handle *find_printer = NULL;
329 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
330 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
337 /****************************************************************************
338 Close printer index by handle.
339 ****************************************************************************/
341 static bool close_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
343 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
346 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
351 close_policy_hnd(p, hnd);
356 /****************************************************************************
357 Delete a printer given a handle.
358 ****************************************************************************/
360 static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
361 const char *sharename,
362 struct messaging_context *msg_ctx)
364 char *cmd = lp_deleteprinter_cmd();
365 char *command = NULL;
367 SE_PRIV se_printop = SE_PRINT_OPERATOR;
368 bool is_print_op = false;
370 /* can't fail if we don't try */
375 command = talloc_asprintf(ctx,
382 is_print_op = user_has_privileges( token, &se_printop );
384 DEBUG(10,("Running [%s]\n", command));
386 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
391 if ( (ret = smbrun(command, NULL)) == 0 ) {
392 /* Tell everyone we updated smb.conf. */
393 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
399 /********** END SePrintOperatorPrivlege BLOCK **********/
401 DEBUGADD(10,("returned [%d]\n", ret));
403 TALLOC_FREE(command);
406 return WERR_BADFID; /* What to return here? */
408 /* go ahead and re-read the services immediately */
410 reload_services(msg_ctx, -1, false);
413 if ( lp_servicenumber( sharename ) > 0 )
414 return WERR_ACCESS_DENIED;
419 /****************************************************************************
420 Delete a printer given a handle.
421 ****************************************************************************/
423 static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
425 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
429 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
435 * It turns out that Windows allows delete printer on a handle
436 * opened by an admin user, then used on a pipe handle created
437 * by an anonymous user..... but they're working on security.... riiight !
441 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
442 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
443 return WERR_ACCESS_DENIED;
446 /* this does not need a become root since the access check has been
447 done on the handle already */
449 result = winreg_delete_printer_key(p->mem_ctx,
450 get_server_info_system(),
454 if (!W_ERROR_IS_OK(result)) {
455 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
459 result = delete_printer_hook(p->mem_ctx, p->server_info->ptok,
460 Printer->sharename, p->msg_ctx);
461 if (!W_ERROR_IS_OK(result)) {
464 prune_printername_cache();
468 /****************************************************************************
469 Return the snum of a printer corresponding to an handle.
470 ****************************************************************************/
472 static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
473 int *number, struct share_params **params)
475 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
478 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
483 switch (Printer->printer_type) {
485 DEBUG(4,("short name:%s\n", Printer->sharename));
486 *number = print_queue_snum(Printer->sharename);
487 return (*number != -1);
495 /****************************************************************************
496 Set printer handle type.
497 Check if it's \\server or \\server\printer
498 ****************************************************************************/
500 static bool set_printer_hnd_printertype(struct printer_handle *Printer, const char *handlename)
502 DEBUG(3,("Setting printer type=%s\n", handlename));
504 /* it's a print server */
505 if (handlename && *handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
506 DEBUGADD(4,("Printer is a print server\n"));
507 Printer->printer_type = SPLHND_SERVER;
509 /* it's a printer (set_printer_hnd_name() will handle port monitors */
511 DEBUGADD(4,("Printer is a printer\n"));
512 Printer->printer_type = SPLHND_PRINTER;
518 static void prune_printername_cache_fn(const char *key, const char *value,
519 time_t timeout, void *private_data)
524 static void prune_printername_cache(void)
526 gencache_iterate(prune_printername_cache_fn, NULL, "PRINTERNAME/*");
529 /****************************************************************************
530 Set printer handle name.. Accept names like \\server, \\server\printer,
531 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
532 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
533 XcvDataPort() interface.
534 ****************************************************************************/
536 static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
537 const struct auth_serversupplied_info *server_info,
538 struct messaging_context *msg_ctx,
539 struct printer_handle *Printer,
540 const char *handlename)
543 int n_services=lp_numservices();
545 const char *printername;
546 const char *servername = NULL;
549 struct spoolss_PrinterInfo2 *info2 = NULL;
553 * Hopefully nobody names his printers like this. Maybe \ or ,
554 * are illegal in printer names even?
556 const char printer_not_found[] = "Printer \\, !@#$%^&*( not found";
560 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
561 (unsigned long)strlen(handlename)));
563 aprinter = CONST_DISCARD(char *, handlename);
564 if ( *handlename == '\\' ) {
565 servername = canon_servername(handlename);
566 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
570 if (!is_myname_or_ipaddr(servername)) {
574 fstrcpy(Printer->servername, servername);
577 if (Printer->printer_type == SPLHND_SERVER) {
581 if (Printer->printer_type != SPLHND_PRINTER) {
585 DEBUGADD(5, ("searching for [%s]\n", aprinter));
587 /* check for the Port Monitor Interface */
588 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
589 Printer->printer_type = SPLHND_PORTMON_TCP;
590 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
593 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
594 Printer->printer_type = SPLHND_PORTMON_LOCAL;
595 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
600 * With hundreds of printers, the "for" loop iterating all
601 * shares can be quite expensive, as it is done on every
602 * OpenPrinter. The loop maps "aprinter" to "sname", the
603 * result of which we cache in gencache.
606 cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
608 if ((cache_key != NULL) && gencache_get(cache_key, &tmp, NULL)) {
610 found = (strcmp(tmp, printer_not_found) != 0);
612 DEBUG(4, ("Printer %s not found\n", aprinter));
620 /* Search all sharenames first as this is easier than pulling
621 the printer_info_2 off of disk. Don't use find_service() since
622 that calls out to map_username() */
624 /* do another loop to look for printernames */
625 for (snum = 0; !found && snum < n_services; snum++) {
626 const char *printer = lp_const_servicename(snum);
628 /* no point going on if this is not a printer */
629 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
633 /* ignore [printers] share */
634 if (strequal(printer, "printers")) {
638 fstrcpy(sname, printer);
639 if (strequal(aprinter, printer)) {
644 /* no point looking up the printer object if
645 we aren't allowing printername != sharename */
646 if (lp_force_printername(snum)) {
650 result = winreg_get_printer(mem_ctx,
656 if ( !W_ERROR_IS_OK(result) ) {
657 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
658 sname, win_errstr(result)));
662 printername = strrchr(info2->printername, '\\');
663 if (printername == NULL) {
664 printername = info2->printername;
669 if (strequal(printername, aprinter)) {
674 DEBUGADD(10, ("printername: %s\n", printername));
680 if (cache_key != NULL) {
681 gencache_set(cache_key, printer_not_found,
683 TALLOC_FREE(cache_key);
685 DEBUGADD(4,("Printer not found\n"));
689 if (cache_key != NULL) {
690 gencache_set(cache_key, sname, time(NULL)+300);
691 TALLOC_FREE(cache_key);
694 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
696 fstrcpy(Printer->sharename, sname);
701 /****************************************************************************
702 Find first available printer slot. creates a printer handle for you.
703 ****************************************************************************/
705 static bool open_printer_hnd(struct pipes_struct *p, struct policy_handle *hnd,
706 const char *name, uint32_t access_granted)
708 struct printer_handle *new_printer;
710 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
712 new_printer = talloc_zero(p->mem_ctx, struct printer_handle);
713 if (new_printer == NULL) {
716 talloc_set_destructor(new_printer, printer_entry_destructor);
718 /* This also steals the printer_handle on the policy_handle */
719 if (!create_policy_hnd(p, hnd, new_printer)) {
720 TALLOC_FREE(new_printer);
724 /* Add to the internal list. */
725 DLIST_ADD(printers_list, new_printer);
727 new_printer->notify.option=NULL;
729 if (!set_printer_hnd_printertype(new_printer, name)) {
730 close_printer_handle(p, hnd);
734 if (!set_printer_hnd_name(p->mem_ctx,
735 get_server_info_system(),
737 new_printer, name)) {
738 close_printer_handle(p, hnd);
742 new_printer->access_granted = access_granted;
744 DEBUG(5, ("%d printer handles active\n",
745 (int)num_pipe_handles(p)));
750 /***************************************************************************
751 check to see if the client motify handle is monitoring the notification
752 given by (notify_type, notify_field).
753 **************************************************************************/
755 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
756 uint16_t notify_field)
761 static bool is_monitoring_event(struct printer_handle *p, uint16_t notify_type,
762 uint16_t notify_field)
764 struct spoolss_NotifyOption *option = p->notify.option;
768 * Flags should always be zero when the change notify
769 * is registered by the client's spooler. A user Win32 app
770 * might use the flags though instead of the NOTIFY_OPTION_INFO
779 return is_monitoring_event_flags(
780 p->notify.flags, notify_type, notify_field);
782 for (i = 0; i < option->count; i++) {
784 /* Check match for notify_type */
786 if (option->types[i].type != notify_type)
789 /* Check match for field */
791 for (j = 0; j < option->types[i].count; j++) {
792 if (option->types[i].fields[j].field == notify_field) {
798 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
799 p->servername, p->sharename, notify_type, notify_field));
804 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
805 _data->data.integer[0] = _integer; \
806 _data->data.integer[1] = 0;
809 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
810 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
811 if (!_data->data.string.string) {\
812 _data->data.string.size = 0; \
814 _data->data.string.size = strlen_m_term(_p) * 2;
816 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
817 _data->data.devmode.devmode = _devmode;
819 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
820 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
821 if (!_data->data.sd.sd) { \
822 _data->data.sd.sd_size = 0; \
824 _data->data.sd.sd_size = \
825 ndr_size_security_descriptor(_data->data.sd.sd, 0);
827 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
832 struct spoolss_Time st;
836 if (!init_systemtime(&st, t)) {
840 p = talloc_array(mem_ctx, char, len);
846 * Systemtime must be linearized as a set of UINT16's.
847 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
850 SSVAL(p, 0, st.year);
851 SSVAL(p, 2, st.month);
852 SSVAL(p, 4, st.day_of_week);
854 SSVAL(p, 8, st.hour);
855 SSVAL(p, 10, st.minute);
856 SSVAL(p, 12, st.second);
857 SSVAL(p, 14, st.millisecond);
863 /* Convert a notification message to a struct spoolss_Notify */
865 static void notify_one_value(struct spoolss_notify_msg *msg,
866 struct spoolss_Notify *data,
869 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
872 static void notify_string(struct spoolss_notify_msg *msg,
873 struct spoolss_Notify *data,
876 /* The length of the message includes the trailing \0 */
878 data->data.string.size = msg->len * 2;
879 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
880 if (!data->data.string.string) {
881 data->data.string.size = 0;
886 static void notify_system_time(struct spoolss_notify_msg *msg,
887 struct spoolss_Notify *data,
890 data->data.string.string = NULL;
891 data->data.string.size = 0;
893 if (msg->len != sizeof(time_t)) {
894 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
899 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
900 &data->data.string.string,
901 &data->data.string.size);
904 struct notify2_message_table {
906 void (*fn)(struct spoolss_notify_msg *msg,
907 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
910 static struct notify2_message_table printer_notify_table[] = {
911 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
912 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
913 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
914 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
915 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
916 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
917 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
918 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
919 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
920 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
921 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
922 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
923 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
924 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
925 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
926 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
927 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
928 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
929 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
932 static struct notify2_message_table job_notify_table[] = {
933 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
934 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
935 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
936 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
937 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
938 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
939 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
940 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
941 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
942 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
943 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
944 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
945 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
946 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
947 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
948 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
949 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
950 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
951 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
952 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
953 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
954 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
955 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
956 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
960 /***********************************************************************
961 Allocate talloc context for container object
962 **********************************************************************/
964 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
969 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
974 /***********************************************************************
975 release all allocated memory and zero out structure
976 **********************************************************************/
978 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
984 talloc_destroy(ctr->ctx);
991 /***********************************************************************
992 **********************************************************************/
994 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1002 /***********************************************************************
1003 **********************************************************************/
1005 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1007 if ( !ctr || !ctr->msg_groups )
1010 if ( idx >= ctr->num_groups )
1013 return &ctr->msg_groups[idx];
1017 /***********************************************************************
1018 How many groups of change messages do we have ?
1019 **********************************************************************/
1021 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1026 return ctr->num_groups;
1029 /***********************************************************************
1030 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1031 **********************************************************************/
1033 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
1035 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
1036 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
1037 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
1043 /* loop over all groups looking for a matching printer name */
1045 for ( i=0; i<ctr->num_groups; i++ ) {
1046 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
1050 /* add a new group? */
1052 if ( i == ctr->num_groups ) {
1055 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
1056 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1059 ctr->msg_groups = groups;
1061 /* clear the new entry and set the printer name */
1063 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
1064 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
1067 /* add the change messages; 'i' is the correct index now regardless */
1069 msg_grp = &ctr->msg_groups[i];
1071 msg_grp->num_msgs++;
1073 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
1074 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
1077 msg_grp->msgs = msg_list;
1079 new_slot = msg_grp->num_msgs-1;
1080 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
1082 /* need to allocate own copy of data */
1084 if ( msg->len != 0 )
1085 msg_grp->msgs[new_slot].notify.data = (char *)
1086 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
1088 return ctr->num_groups;
1091 static void construct_info_data(struct spoolss_Notify *info_data,
1092 enum spoolss_NotifyType type,
1093 uint16_t field, int id);
1095 /***********************************************************************
1096 Send a change notication message on all handles which have a call
1098 **********************************************************************/
1100 static int build_notify2_messages(TALLOC_CTX *mem_ctx,
1101 struct printer_handle *prn_hnd,
1102 SPOOLSS_NOTIFY_MSG *messages,
1104 struct spoolss_Notify **_notifies,
1107 struct spoolss_Notify *notifies;
1108 SPOOLSS_NOTIFY_MSG *msg;
1113 notifies = talloc_zero_array(mem_ctx,
1114 struct spoolss_Notify, num_msgs);
1119 for (i = 0; i < num_msgs; i++) {
1123 /* Are we monitoring this event? */
1125 if (!is_monitoring_event(prn_hnd, msg->type, msg->field)) {
1129 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1130 "for printer [%s]\n",
1131 msg->type, msg->field, prn_hnd->sharename));
1134 * if the is a printer notification handle and not a job
1135 * notification type, then set the id to 0.
1136 * Otherwise just use what was specified in the message.
1138 * When registering change notification on a print server
1139 * handle we always need to send back the id (snum) matching
1140 * the printer for which the change took place.
1141 * For change notify registered on a printer handle,
1142 * this does not matter and the id should be 0.
1147 if ((msg->type == PRINTER_NOTIFY_TYPE) &&
1148 (prn_hnd->printer_type == SPLHND_PRINTER)) {
1154 /* Convert unix jobid to smb jobid */
1156 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1157 id = sysjob_to_jobid(msg->id);
1160 DEBUG(3, ("no such unix jobid %d\n",
1166 construct_info_data(¬ifies[count],
1167 msg->type, msg->field, id);
1170 case PRINTER_NOTIFY_TYPE:
1171 if (printer_notify_table[msg->field].fn) {
1172 printer_notify_table[msg->field].fn(msg,
1173 ¬ifies[count], mem_ctx);
1177 case JOB_NOTIFY_TYPE:
1178 if (job_notify_table[msg->field].fn) {
1179 job_notify_table[msg->field].fn(msg,
1180 ¬ifies[count], mem_ctx);
1185 DEBUG(5, ("Unknown notification type %d\n",
1193 *_notifies = notifies;
1199 static int send_notify2_printer(TALLOC_CTX *mem_ctx,
1200 struct printer_handle *prn_hnd,
1201 SPOOLSS_NOTIFY_MSG_GROUP *msg_group)
1203 struct spoolss_Notify *notifies;
1205 union spoolss_ReplyPrinterInfo info;
1206 struct spoolss_NotifyInfo info0;
1207 uint32_t reply_result;
1212 /* Is there notification on this handle? */
1213 if (prn_hnd->notify.cli_chan == NULL ||
1214 prn_hnd->notify.cli_chan->active_connections == 0) {
1218 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1219 prn_hnd->servername, prn_hnd->sharename));
1221 /* For this printer? Print servers always receive notifications. */
1222 if ((prn_hnd->printer_type == SPLHND_PRINTER) &&
1223 (!strequal(msg_group->printername, prn_hnd->sharename))) {
1227 DEBUG(10,("Our printer\n"));
1229 /* build the array of change notifications */
1230 ret = build_notify2_messages(mem_ctx, prn_hnd,
1232 msg_group->num_msgs,
1238 info0.version = 0x2;
1239 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1240 info0.count = count;
1241 info0.notifies = notifies;
1243 info.info0 = &info0;
1245 status = rpccli_spoolss_RouterReplyPrinterEx(
1246 prn_hnd->notify.cli_chan->cli_pipe,
1248 &prn_hnd->notify.cli_hnd,
1249 prn_hnd->notify.change, /* color */
1250 prn_hnd->notify.flags,
1252 0, /* reply_type, must be 0 */
1254 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1255 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1257 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1260 switch (reply_result) {
1263 case PRINTER_NOTIFY_INFO_DISCARDED:
1264 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1265 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1274 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1276 struct printer_handle *p;
1277 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
1278 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
1282 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1286 if (!msg_group->msgs) {
1287 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1291 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
1293 /* loop over all printers */
1295 for (p = printers_list; p; p = p->next) {
1296 ret = send_notify2_printer(mem_ctx, p, msg_group);
1303 DEBUG(8,("send_notify2_changes: Exit...\n"));
1307 /***********************************************************************
1308 **********************************************************************/
1310 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1313 uint32_t tv_sec, tv_usec;
1316 /* Unpack message */
1318 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1321 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1323 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1326 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1327 &msg->notify.value[0], &msg->notify.value[1]);
1329 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1330 &msg->len, &msg->notify.data);
1332 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1333 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1335 tv->tv_sec = tv_sec;
1336 tv->tv_usec = tv_usec;
1339 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1340 msg->notify.value[1]));
1342 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1347 /********************************************************************
1348 Receive a notify2 message list
1349 ********************************************************************/
1351 static void receive_notify2_message_list(struct messaging_context *msg,
1354 struct server_id server_id,
1357 size_t msg_count, i;
1358 char *buf = (char *)data->data;
1361 SPOOLSS_NOTIFY_MSG notify;
1362 SPOOLSS_NOTIFY_MSG_CTR messages;
1365 if (data->length < 4) {
1366 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1370 msg_count = IVAL(buf, 0);
1373 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1375 if (msg_count == 0) {
1376 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1380 /* initialize the container */
1382 ZERO_STRUCT( messages );
1383 notify_msg_ctr_init( &messages );
1386 * build message groups for each printer identified
1387 * in a change_notify msg. Remember that a PCN message
1388 * includes the handle returned for the srv_spoolss_replyopenprinter()
1389 * call. Therefore messages are grouped according to printer handle.
1392 for ( i=0; i<msg_count; i++ ) {
1393 struct timeval msg_tv;
1395 if (msg_ptr + 4 - buf > data->length) {
1396 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1400 msg_len = IVAL(msg_ptr,0);
1403 if (msg_ptr + msg_len - buf > data->length) {
1404 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1408 /* unpack messages */
1410 ZERO_STRUCT( notify );
1411 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1414 /* add to correct list in container */
1416 notify_msg_ctr_addmsg( &messages, ¬ify );
1418 /* free memory that might have been allocated by notify2_unpack_msg() */
1420 if ( notify.len != 0 )
1421 SAFE_FREE( notify.notify.data );
1424 /* process each group of messages */
1426 num_groups = notify_msg_ctr_numgroups( &messages );
1427 for ( i=0; i<num_groups; i++ )
1428 send_notify2_changes( &messages, i );
1433 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1434 (uint32_t)msg_count ));
1436 notify_msg_ctr_destroy( &messages );
1441 /********************************************************************
1442 Send a message to ourself about new driver being installed
1443 so we can upgrade the information for each printer bound to this
1445 ********************************************************************/
1447 static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
1448 struct messaging_context *msg_ctx)
1450 int len = strlen(drivername);
1455 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1458 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
1459 MSG_PRINTER_DRVUPGRADE,
1460 (uint8_t *)drivername, len+1);
1465 void srv_spoolss_cleanup(void)
1467 struct printer_session_counter *session_counter;
1469 for (session_counter = counter_list;
1470 session_counter != NULL;
1471 session_counter = counter_list) {
1472 DLIST_REMOVE(counter_list, session_counter);
1473 TALLOC_FREE(session_counter);
1477 /**********************************************************************
1478 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1479 over all printers, upgrading ones as necessary
1480 **********************************************************************/
1482 void do_drv_upgrade_printer(struct messaging_context *msg,
1485 struct server_id server_id,
1488 TALLOC_CTX *tmp_ctx;
1489 struct auth_serversupplied_info *server_info = NULL;
1490 struct spoolss_PrinterInfo2 *pinfo2;
1493 const char *drivername;
1495 int n_services = lp_numservices();
1498 tmp_ctx = talloc_new(NULL);
1499 if (!tmp_ctx) return;
1501 status = make_server_info_system(tmp_ctx, &server_info);
1502 if (!NT_STATUS_IS_OK(status)) {
1503 DEBUG(0, ("do_drv_upgrade_printer: "
1504 "Could not create system server_info\n"));
1508 len = MIN(data->length,sizeof(drivername)-1);
1509 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, len);
1511 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1515 DEBUG(10, ("do_drv_upgrade_printer: "
1516 "Got message for new driver [%s]\n", drivername));
1518 /* Iterate the printer list */
1520 for (snum = 0; snum < n_services; snum++) {
1521 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1525 result = winreg_get_printer(tmp_ctx, server_info, msg,
1527 lp_const_servicename(snum),
1530 if (!W_ERROR_IS_OK(result)) {
1534 if (!pinfo2->drivername) {
1538 if (strcmp(drivername, pinfo2->drivername) != 0) {
1542 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1544 /* all we care about currently is the change_id */
1545 result = winreg_printer_update_changeid(tmp_ctx,
1548 pinfo2->printername);
1550 if (!W_ERROR_IS_OK(result)) {
1551 DEBUG(3, ("do_drv_upgrade_printer: "
1552 "Failed to update changeid [%s]\n",
1553 win_errstr(result)));
1559 talloc_free(tmp_ctx);
1562 /********************************************************************
1563 Update the cache for all printq's with a registered client
1565 ********************************************************************/
1567 void update_monitored_printq_cache(struct messaging_context *msg_ctx)
1569 struct printer_handle *printer = printers_list;
1572 /* loop through all printers and update the cache where
1573 a client is connected */
1575 if ((printer->printer_type == SPLHND_PRINTER) &&
1576 ((printer->notify.cli_chan != NULL) &&
1577 (printer->notify.cli_chan->active_connections > 0))) {
1578 snum = print_queue_snum(printer->sharename);
1579 print_queue_status(msg_ctx, snum, NULL, NULL);
1582 printer = printer->next;
1588 /****************************************************************
1589 _spoolss_OpenPrinter
1590 ****************************************************************/
1592 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1593 struct spoolss_OpenPrinter *r)
1595 struct spoolss_OpenPrinterEx e;
1598 ZERO_STRUCT(e.in.userlevel);
1600 e.in.printername = r->in.printername;
1601 e.in.datatype = r->in.datatype;
1602 e.in.devmode_ctr = r->in.devmode_ctr;
1603 e.in.access_mask = r->in.access_mask;
1606 e.out.handle = r->out.handle;
1608 werr = _spoolss_OpenPrinterEx(p, &e);
1610 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1611 /* OpenPrinterEx returns this for a bad
1612 * printer name. We must return WERR_INVALID_PRINTER_NAME
1615 werr = WERR_INVALID_PRINTER_NAME;
1621 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1622 struct spoolss_DeviceMode *orig,
1623 struct spoolss_DeviceMode **dest)
1625 struct spoolss_DeviceMode *dm;
1627 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1632 /* copy all values, then duplicate strings and structs */
1635 dm->devicename = talloc_strdup(dm, orig->devicename);
1636 if (!dm->devicename) {
1639 dm->formname = talloc_strdup(dm, orig->formname);
1640 if (!dm->formname) {
1643 if (orig->driverextra_data.data) {
1644 dm->driverextra_data.data =
1645 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1646 orig->driverextra_data.length);
1647 if (!dm->driverextra_data.data) {
1656 /****************************************************************
1657 _spoolss_OpenPrinterEx
1658 ****************************************************************/
1660 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1661 struct spoolss_OpenPrinterEx *r)
1664 struct printer_handle *Printer=NULL;
1666 if (!r->in.printername) {
1667 return WERR_INVALID_PARAM;
1670 /* some sanity check because you can open a printer or a print server */
1671 /* aka: \\server\printer or \\server */
1673 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1675 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1676 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1677 "for printer %s\n", r->in.printername));
1678 ZERO_STRUCTP(r->out.handle);
1679 return WERR_INVALID_PARAM;
1682 Printer = find_printer_index_by_hnd(p, r->out.handle);
1684 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1685 "handle we created for printer %s\n", r->in.printername));
1686 close_printer_handle(p, r->out.handle);
1687 ZERO_STRUCTP(r->out.handle);
1688 return WERR_INVALID_PARAM;
1692 * First case: the user is opening the print server:
1694 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1695 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1697 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1698 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1699 * or if the user is listed in the smb.conf printer admin parameter.
1701 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1702 * client view printer folder, but does not show the MSAPW.
1704 * Note: this test needs code to check access rights here too. Jeremy
1705 * could you look at this?
1707 * Second case: the user is opening a printer:
1708 * NT doesn't let us connect to a printer if the connecting user
1709 * doesn't have print permission.
1711 * Third case: user is opening a Port Monitor
1712 * access checks same as opening a handle to the print server.
1715 switch (Printer->printer_type )
1718 case SPLHND_PORTMON_TCP:
1719 case SPLHND_PORTMON_LOCAL:
1720 /* Printserver handles use global struct... */
1724 /* Map standard access rights to object specific access rights */
1726 se_map_standard(&r->in.access_mask,
1727 &printserver_std_mapping);
1729 /* Deny any object specific bits that don't apply to print
1730 servers (i.e printer and job specific bits) */
1732 r->in.access_mask &= SEC_MASK_SPECIFIC;
1734 if (r->in.access_mask &
1735 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1736 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1737 close_printer_handle(p, r->out.handle);
1738 ZERO_STRUCTP(r->out.handle);
1739 return WERR_ACCESS_DENIED;
1742 /* Allow admin access */
1744 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1746 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1748 if (!lp_ms_add_printer_wizard()) {
1749 close_printer_handle(p, r->out.handle);
1750 ZERO_STRUCTP(r->out.handle);
1751 return WERR_ACCESS_DENIED;
1754 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1755 and not a printer admin, then fail */
1757 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1758 !user_has_privileges(p->server_info->ptok,
1760 !token_contains_name_in_list(
1761 uidtoname(p->server_info->utok.uid),
1762 p->server_info->info3->base.domain.string,
1764 p->server_info->ptok,
1765 lp_printer_admin(snum))) {
1766 close_printer_handle(p, r->out.handle);
1767 ZERO_STRUCTP(r->out.handle);
1768 return WERR_ACCESS_DENIED;
1771 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1775 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1778 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1779 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1781 /* We fall through to return WERR_OK */
1784 case SPLHND_PRINTER:
1785 /* NT doesn't let us connect to a printer if the connecting user
1786 doesn't have print permission. */
1788 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1789 close_printer_handle(p, r->out.handle);
1790 ZERO_STRUCTP(r->out.handle);
1794 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1795 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1798 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1800 /* map an empty access mask to the minimum access mask */
1801 if (r->in.access_mask == 0x0)
1802 r->in.access_mask = PRINTER_ACCESS_USE;
1805 * If we are not serving the printer driver for this printer,
1806 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1807 * will keep NT clients happy --jerry
1810 if (lp_use_client_driver(snum)
1811 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1813 r->in.access_mask = PRINTER_ACCESS_USE;
1816 /* check smb.conf parameters and the the sec_desc */
1818 if (!allow_access(lp_hostsdeny(snum), lp_hostsallow(snum),
1819 p->client_id->name, p->client_id->addr)) {
1820 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1821 ZERO_STRUCTP(r->out.handle);
1822 return WERR_ACCESS_DENIED;
1825 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1826 p->server_info->ptok, snum) ||
1827 !print_access_check(get_server_info_system(),
1830 r->in.access_mask)) {
1831 DEBUG(3, ("access DENIED for printer open\n"));
1832 close_printer_handle(p, r->out.handle);
1833 ZERO_STRUCTP(r->out.handle);
1834 return WERR_ACCESS_DENIED;
1837 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1838 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1839 close_printer_handle(p, r->out.handle);
1840 ZERO_STRUCTP(r->out.handle);
1841 return WERR_ACCESS_DENIED;
1844 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1845 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1847 r->in.access_mask = PRINTER_ACCESS_USE;
1849 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1850 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1852 winreg_create_printer(p->mem_ctx,
1853 get_server_info_system(),
1855 Printer->servername,
1856 lp_const_servicename(snum));
1861 /* sanity check to prevent programmer error */
1862 ZERO_STRUCTP(r->out.handle);
1866 Printer->access_granted = r->in.access_mask;
1869 * If the client sent a devmode in the OpenPrinter() call, then
1870 * save it here in case we get a job submission on this handle
1873 if ((Printer->printer_type != SPLHND_SERVER) &&
1874 r->in.devmode_ctr.devmode) {
1875 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1879 #if 0 /* JERRY -- I'm doubtful this is really effective */
1880 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1881 optimization in Windows 2000 clients --jerry */
1883 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1884 && (RA_WIN2K == get_remote_arch()) )
1886 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1887 sys_usleep( 500000 );
1894 /****************************************************************
1895 _spoolss_ClosePrinter
1896 ****************************************************************/
1898 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1899 struct spoolss_ClosePrinter *r)
1901 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1903 if (Printer && Printer->document_started) {
1904 struct spoolss_EndDocPrinter e;
1906 e.in.handle = r->in.handle;
1908 _spoolss_EndDocPrinter(p, &e);
1911 if (!close_printer_handle(p, r->in.handle))
1914 /* clear the returned printer handle. Observed behavior
1915 from Win2k server. Don't think this really matters.
1916 Previous code just copied the value of the closed
1919 ZERO_STRUCTP(r->out.handle);
1924 /****************************************************************
1925 _spoolss_DeletePrinter
1926 ****************************************************************/
1928 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1929 struct spoolss_DeletePrinter *r)
1931 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1935 if (Printer && Printer->document_started) {
1936 struct spoolss_EndDocPrinter e;
1938 e.in.handle = r->in.handle;
1940 _spoolss_EndDocPrinter(p, &e);
1943 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
1944 winreg_delete_printer_key(p->mem_ctx,
1945 get_server_info_system(),
1947 lp_const_servicename(snum),
1951 result = delete_printer_handle(p, r->in.handle);
1956 /*******************************************************************
1957 * static function to lookup the version id corresponding to an
1958 * long architecture string
1959 ******************************************************************/
1961 static const struct print_architecture_table_node archi_table[]= {
1963 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1964 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1965 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1966 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
1967 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
1968 {"Windows IA64", SPL_ARCH_IA64, 3 },
1969 {"Windows x64", SPL_ARCH_X64, 3 },
1973 static int get_version_id(const char *arch)
1977 for (i=0; archi_table[i].long_archi != NULL; i++)
1979 if (strcmp(arch, archi_table[i].long_archi) == 0)
1980 return (archi_table[i].version);
1986 /****************************************************************
1987 _spoolss_DeletePrinterDriver
1988 ****************************************************************/
1990 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
1991 struct spoolss_DeletePrinterDriver *r)
1994 struct spoolss_DriverInfo8 *info = NULL;
1995 struct spoolss_DriverInfo8 *info_win2k = NULL;
1998 SE_PRIV se_printop = SE_PRINT_OPERATOR;
2000 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2001 and not a printer admin, then fail */
2003 if ( (p->server_info->utok.uid != sec_initial_uid())
2004 && !user_has_privileges(p->server_info->ptok, &se_printop )
2005 && !token_contains_name_in_list(
2006 uidtoname(p->server_info->utok.uid),
2007 p->server_info->info3->base.domain.string,
2009 p->server_info->ptok,
2010 lp_printer_admin(-1)) )
2012 return WERR_ACCESS_DENIED;
2015 /* check that we have a valid driver name first */
2017 if ((version = get_version_id(r->in.architecture)) == -1)
2018 return WERR_INVALID_ENVIRONMENT;
2020 status = winreg_get_driver(p->mem_ctx,
2021 get_server_info_system(),
2023 r->in.architecture, r->in.driver,
2025 if (!W_ERROR_IS_OK(status)) {
2026 /* try for Win2k driver if "Windows NT x86" */
2028 if ( version == 2 ) {
2031 status = winreg_get_driver(p->mem_ctx,
2032 get_server_info_system(),
2037 if (!W_ERROR_IS_OK(status)) {
2038 status = WERR_UNKNOWN_PRINTER_DRIVER;
2042 /* otherwise it was a failure */
2044 status = WERR_UNKNOWN_PRINTER_DRIVER;
2050 if (printer_driver_in_use(p->mem_ctx,
2051 get_server_info_system(),
2054 status = WERR_PRINTER_DRIVER_IN_USE;
2059 status = winreg_get_driver(p->mem_ctx,
2060 get_server_info_system(),
2063 r->in.driver, 3, &info_win2k);
2064 if (W_ERROR_IS_OK(status)) {
2065 /* if we get to here, we now have 2 driver info structures to remove */
2066 /* remove the Win2k driver first*/
2068 status = winreg_del_driver(p->mem_ctx,
2069 get_server_info_system(),
2072 talloc_free(info_win2k);
2074 /* this should not have failed---if it did, report to client */
2075 if (!W_ERROR_IS_OK(status)) {
2081 status = winreg_del_driver(p->mem_ctx,
2082 get_server_info_system(),
2092 /****************************************************************
2093 _spoolss_DeletePrinterDriverEx
2094 ****************************************************************/
2096 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
2097 struct spoolss_DeletePrinterDriverEx *r)
2099 struct spoolss_DriverInfo8 *info = NULL;
2100 struct spoolss_DriverInfo8 *info_win2k = NULL;
2104 SE_PRIV se_printop = SE_PRINT_OPERATOR;
2106 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2107 and not a printer admin, then fail */
2109 if ( (p->server_info->utok.uid != sec_initial_uid())
2110 && !user_has_privileges(p->server_info->ptok, &se_printop )
2111 && !token_contains_name_in_list(
2112 uidtoname(p->server_info->utok.uid),
2113 p->server_info->info3->base.domain.string,
2115 p->server_info->ptok, lp_printer_admin(-1)) )
2117 return WERR_ACCESS_DENIED;
2120 /* check that we have a valid driver name first */
2121 if ((version = get_version_id(r->in.architecture)) == -1) {
2122 /* this is what NT returns */
2123 return WERR_INVALID_ENVIRONMENT;
2126 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2127 version = r->in.version;
2129 status = winreg_get_driver(p->mem_ctx,
2130 get_server_info_system(),
2136 if (!W_ERROR_IS_OK(status)) {
2137 status = WERR_UNKNOWN_PRINTER_DRIVER;
2140 * if the client asked for a specific version,
2141 * or this is something other than Windows NT x86,
2145 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2148 /* try for Win2k driver if "Windows NT x86" */
2151 status = winreg_get_driver(info,
2152 get_server_info_system(),
2157 if (!W_ERROR_IS_OK(status)) {
2158 status = WERR_UNKNOWN_PRINTER_DRIVER;
2163 if (printer_driver_in_use(info,
2164 get_server_info_system(),
2167 status = WERR_PRINTER_DRIVER_IN_USE;
2172 * we have a couple of cases to consider.
2173 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2174 * then the delete should fail if **any** files overlap with
2176 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2177 * non-overlapping files
2178 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2179 * is set, the do not delete any files
2180 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2183 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2185 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2188 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2189 printer_driver_files_in_use(info,
2190 get_server_info_system(),
2193 /* no idea of the correct error here */
2194 status = WERR_ACCESS_DENIED;
2199 /* also check for W32X86/3 if necessary; maybe we already have? */
2201 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2202 status = winreg_get_driver(info,
2203 get_server_info_system(),
2206 r->in.driver, 3, &info_win2k);
2207 if (W_ERROR_IS_OK(status)) {
2210 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2211 printer_driver_files_in_use(info,
2212 get_server_info_system(),
2215 /* no idea of the correct error here */
2216 talloc_free(info_win2k);
2217 status = WERR_ACCESS_DENIED;
2221 /* if we get to here, we now have 2 driver info structures to remove */
2222 /* remove the Win2k driver first*/
2224 status = winreg_del_driver(info,
2225 get_server_info_system(),
2230 /* this should not have failed---if it did, report to client */
2232 if (!W_ERROR_IS_OK(status)) {
2237 * now delete any associated files if delete_files is
2238 * true. Even if this part failes, we return succes
2239 * because the driver doesn not exist any more
2242 delete_driver_files(get_server_info_system(),
2248 status = winreg_del_driver(info,
2249 get_server_info_system(),
2253 if (!W_ERROR_IS_OK(status)) {
2258 * now delete any associated files if delete_files is
2259 * true. Even if this part failes, we return succes
2260 * because the driver doesn not exist any more
2263 delete_driver_files(get_server_info_system(), info);
2272 /********************************************************************
2273 GetPrinterData on a printer server Handle.
2274 ********************************************************************/
2276 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2278 enum winreg_Type *type,
2279 union spoolss_PrinterData *data)
2281 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2283 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2289 if (!StrCaseCmp(value, "BeepEnabled")) {
2295 if (!StrCaseCmp(value, "EventLog")) {
2297 /* formally was 0x1b */
2302 if (!StrCaseCmp(value, "NetPopup")) {
2308 if (!StrCaseCmp(value, "MajorVersion")) {
2311 /* Windows NT 4.0 seems to not allow uploading of drivers
2312 to a server that reports 0x3 as the MajorVersion.
2313 need to investigate more how Win2k gets around this .
2316 if (RA_WINNT == get_remote_arch()) {
2325 if (!StrCaseCmp(value, "MinorVersion")) {
2332 * uint32_t size = 0x114
2333 * uint32_t major = 5
2334 * uint32_t minor = [0|1]
2335 * uint32_t build = [2195|2600]
2336 * extra unicode string = e.g. "Service Pack 3"
2338 if (!StrCaseCmp(value, "OSVersion")) {
2340 enum ndr_err_code ndr_err;
2341 struct spoolss_OSVersion os;
2343 os.major = 5; /* Windows 2000 == 5.0 */
2345 os.build = 2195; /* build */
2346 os.extra_string = ""; /* leave extra string empty */
2348 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2349 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2350 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2351 return WERR_GENERAL_FAILURE;
2355 data->binary = blob;
2361 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2364 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2365 W_ERROR_HAVE_NO_MEMORY(data->string);
2370 if (!StrCaseCmp(value, "Architecture")) {
2372 data->string = talloc_strdup(mem_ctx,
2373 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2374 W_ERROR_HAVE_NO_MEMORY(data->string);
2379 if (!StrCaseCmp(value, "DsPresent")) {
2382 /* only show the publish check box if we are a
2383 member of a AD domain */
2385 if (lp_security() == SEC_ADS) {
2393 if (!StrCaseCmp(value, "DNSMachineName")) {
2394 const char *hostname = get_mydnsfullname();
2397 return WERR_BADFILE;
2401 data->string = talloc_strdup(mem_ctx, hostname);
2402 W_ERROR_HAVE_NO_MEMORY(data->string);
2409 return WERR_INVALID_PARAM;
2412 /****************************************************************
2413 _spoolss_GetPrinterData
2414 ****************************************************************/
2416 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2417 struct spoolss_GetPrinterData *r)
2419 struct spoolss_GetPrinterDataEx r2;
2421 r2.in.handle = r->in.handle;
2422 r2.in.key_name = "PrinterDriverData";
2423 r2.in.value_name = r->in.value_name;
2424 r2.in.offered = r->in.offered;
2425 r2.out.type = r->out.type;
2426 r2.out.data = r->out.data;
2427 r2.out.needed = r->out.needed;
2429 return _spoolss_GetPrinterDataEx(p, &r2);
2432 /*********************************************************
2433 Connect to the client machine.
2434 **********************************************************/
2436 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2437 struct sockaddr_storage *client_ss, const char *remote_machine)
2440 struct cli_state *the_cli;
2441 struct sockaddr_storage rm_addr;
2442 char addr[INET6_ADDRSTRLEN];
2444 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2445 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2447 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2448 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2451 print_sockaddr(addr, sizeof(addr), &rm_addr);
2453 rm_addr = *client_ss;
2454 print_sockaddr(addr, sizeof(addr), &rm_addr);
2455 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2459 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2460 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2465 /* setup the connection */
2466 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2467 &rm_addr, 0, "IPC$", "IPC",
2471 0, lp_client_signing(), NULL );
2473 if ( !NT_STATUS_IS_OK( ret ) ) {
2474 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2479 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2480 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2481 cli_shutdown(the_cli);
2486 * Ok - we have an anonymous connection to the IPC$ share.
2487 * Now start the NT Domain stuff :-).
2490 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2491 if (!NT_STATUS_IS_OK(ret)) {
2492 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2493 remote_machine, nt_errstr(ret)));
2494 cli_shutdown(the_cli);
2501 /***************************************************************************
2502 Connect to the client.
2503 ****************************************************************************/
2505 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2506 uint32_t localprinter,
2507 enum winreg_Type type,
2508 struct policy_handle *handle,
2509 struct notify_back_channel **_chan,
2510 struct sockaddr_storage *client_ss,
2511 struct messaging_context *msg_ctx)
2515 struct notify_back_channel *chan;
2517 for (chan = back_channels; chan; chan = chan->next) {
2518 if (memcmp(&chan->client_address, client_ss,
2519 sizeof(struct sockaddr_storage)) == 0) {
2525 * If it's the first connection, contact the client
2526 * and connect to the IPC$ share anonymously
2529 fstring unix_printer;
2531 /* the +2 is to strip the leading 2 backslashs */
2532 fstrcpy(unix_printer, printer + 2);
2534 chan = talloc_zero(back_channels, struct notify_back_channel);
2538 chan->client_address = *client_ss;
2540 if (!spoolss_connect_to_client(&chan->cli_pipe, client_ss, unix_printer)) {
2545 DLIST_ADD(back_channels, chan);
2547 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2548 receive_notify2_message_list);
2549 /* Tell the connections db we're now interested in printer
2550 * notify messages. */
2551 serverid_register_msg_flags(messaging_server_id(msg_ctx),
2552 true, FLAG_MSG_PRINT_NOTIFY);
2556 * Tell the specific printing tdb we want messages for this printer
2557 * by registering our PID.
2560 if (!print_notify_register_pid(snum)) {
2561 DEBUG(0, ("Failed to register our pid for printer %s\n",
2565 status = rpccli_spoolss_ReplyOpenPrinter(chan->cli_pipe, talloc_tos(),
2573 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
2574 DEBUG(5, ("Client RPC returned [%s]\n", win_errstr(result)));
2577 chan->active_connections++;
2580 return (W_ERROR_IS_OK(result));
2583 /****************************************************************
2584 ****************************************************************/
2586 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2587 const struct spoolss_NotifyOption *r)
2589 struct spoolss_NotifyOption *option;
2596 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2603 if (!option->count) {
2607 option->types = talloc_zero_array(option,
2608 struct spoolss_NotifyOptionType, option->count);
2609 if (!option->types) {
2610 talloc_free(option);
2614 for (i=0; i < option->count; i++) {
2615 option->types[i] = r->types[i];
2617 if (option->types[i].count) {
2618 option->types[i].fields = talloc_zero_array(option,
2619 union spoolss_Field, option->types[i].count);
2620 if (!option->types[i].fields) {
2621 talloc_free(option);
2624 for (k=0; k<option->types[i].count; k++) {
2625 option->types[i].fields[k] =
2626 r->types[i].fields[k];
2634 /****************************************************************
2635 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2637 * before replying OK: status=0 a rpc call is made to the workstation
2638 * asking ReplyOpenPrinter
2640 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2641 * called from api_spoolss_rffpcnex
2642 ****************************************************************/
2644 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2645 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2648 struct spoolss_NotifyOption *option = r->in.notify_options;
2649 struct sockaddr_storage client_ss;
2651 /* store the notify value in the printer struct */
2653 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2656 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2657 "Invalid handle (%s:%u:%u).\n",
2658 OUR_HANDLE(r->in.handle)));
2662 Printer->notify.flags = r->in.flags;
2663 Printer->notify.options = r->in.options;
2664 Printer->notify.printerlocal = r->in.printer_local;
2665 Printer->notify.msg_ctx = p->msg_ctx;
2667 TALLOC_FREE(Printer->notify.option);
2668 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2670 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2672 /* Connect to the client machine and send a ReplyOpenPrinter */
2674 if ( Printer->printer_type == SPLHND_SERVER)
2676 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2677 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2680 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2681 "client_address is %s\n", p->client_id->addr));
2683 if (!interpret_string_addr(&client_ss, p->client_id->addr,
2685 return WERR_SERVER_UNAVAILABLE;
2688 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2689 Printer->notify.printerlocal, REG_SZ,
2690 &Printer->notify.cli_hnd,
2691 &Printer->notify.cli_chan,
2692 &client_ss, p->msg_ctx)) {
2693 return WERR_SERVER_UNAVAILABLE;
2699 /*******************************************************************
2700 * fill a notify_info_data with the servername
2701 ********************************************************************/
2703 static void spoolss_notify_server_name(struct messaging_context *msg_ctx,
2705 struct spoolss_Notify *data,
2706 print_queue_struct *queue,
2707 struct spoolss_PrinterInfo2 *pinfo2,
2708 TALLOC_CTX *mem_ctx)
2710 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2713 /*******************************************************************
2714 * fill a notify_info_data with the printername (not including the servername).
2715 ********************************************************************/
2717 static void spoolss_notify_printer_name(struct messaging_context *msg_ctx,
2719 struct spoolss_Notify *data,
2720 print_queue_struct *queue,
2721 struct spoolss_PrinterInfo2 *pinfo2,
2722 TALLOC_CTX *mem_ctx)
2724 /* the notify name should not contain the \\server\ part */
2725 const char *p = strrchr(pinfo2->printername, '\\');
2728 p = pinfo2->printername;
2733 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2736 /*******************************************************************
2737 * fill a notify_info_data with the servicename
2738 ********************************************************************/
2740 static void spoolss_notify_share_name(struct messaging_context *msg_ctx,
2742 struct spoolss_Notify *data,
2743 print_queue_struct *queue,
2744 struct spoolss_PrinterInfo2 *pinfo2,
2745 TALLOC_CTX *mem_ctx)
2747 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2750 /*******************************************************************
2751 * fill a notify_info_data with the port name
2752 ********************************************************************/
2754 static void spoolss_notify_port_name(struct messaging_context *msg_ctx,
2756 struct spoolss_Notify *data,
2757 print_queue_struct *queue,
2758 struct spoolss_PrinterInfo2 *pinfo2,
2759 TALLOC_CTX *mem_ctx)
2761 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2764 /*******************************************************************
2765 * fill a notify_info_data with the printername
2766 * but it doesn't exist, have to see what to do
2767 ********************************************************************/
2769 static void spoolss_notify_driver_name(struct messaging_context *msg_ctx,
2771 struct spoolss_Notify *data,
2772 print_queue_struct *queue,
2773 struct spoolss_PrinterInfo2 *pinfo2,
2774 TALLOC_CTX *mem_ctx)
2776 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2779 /*******************************************************************
2780 * fill a notify_info_data with the comment
2781 ********************************************************************/
2783 static void spoolss_notify_comment(struct messaging_context *msg_ctx,
2785 struct spoolss_Notify *data,
2786 print_queue_struct *queue,
2787 struct spoolss_PrinterInfo2 *pinfo2,
2788 TALLOC_CTX *mem_ctx)
2792 if (*pinfo2->comment == '\0') {
2793 p = lp_comment(snum);
2795 p = pinfo2->comment;
2798 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2801 /*******************************************************************
2802 * fill a notify_info_data with the comment
2803 * location = "Room 1, floor 2, building 3"
2804 ********************************************************************/
2806 static void spoolss_notify_location(struct messaging_context *msg_ctx,
2808 struct spoolss_Notify *data,
2809 print_queue_struct *queue,
2810 struct spoolss_PrinterInfo2 *pinfo2,
2811 TALLOC_CTX *mem_ctx)
2813 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
2816 /*******************************************************************
2817 * fill a notify_info_data with the device mode
2818 * jfm:xxxx don't to it for know but that's a real problem !!!
2819 ********************************************************************/
2821 static void spoolss_notify_devmode(struct messaging_context *msg_ctx,
2823 struct spoolss_Notify *data,
2824 print_queue_struct *queue,
2825 struct spoolss_PrinterInfo2 *pinfo2,
2826 TALLOC_CTX *mem_ctx)
2828 /* for a dummy implementation we have to zero the fields */
2829 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2832 /*******************************************************************
2833 * fill a notify_info_data with the separator file name
2834 ********************************************************************/
2836 static void spoolss_notify_sepfile(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)
2843 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2846 /*******************************************************************
2847 * fill a notify_info_data with the print processor
2848 * jfm:xxxx return always winprint to indicate we don't do anything to it
2849 ********************************************************************/
2851 static void spoolss_notify_print_processor(struct messaging_context *msg_ctx,
2853 struct spoolss_Notify *data,
2854 print_queue_struct *queue,
2855 struct spoolss_PrinterInfo2 *pinfo2,
2856 TALLOC_CTX *mem_ctx)
2858 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2861 /*******************************************************************
2862 * fill a notify_info_data with the print processor options
2863 * jfm:xxxx send an empty string
2864 ********************************************************************/
2866 static void spoolss_notify_parameters(struct messaging_context *msg_ctx,
2868 struct spoolss_Notify *data,
2869 print_queue_struct *queue,
2870 struct spoolss_PrinterInfo2 *pinfo2,
2871 TALLOC_CTX *mem_ctx)
2873 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2876 /*******************************************************************
2877 * fill a notify_info_data with the data type
2878 * jfm:xxxx always send RAW as data type
2879 ********************************************************************/
2881 static void spoolss_notify_datatype(struct messaging_context *msg_ctx,
2883 struct spoolss_Notify *data,
2884 print_queue_struct *queue,
2885 struct spoolss_PrinterInfo2 *pinfo2,
2886 TALLOC_CTX *mem_ctx)
2888 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2891 /*******************************************************************
2892 * fill a notify_info_data with the security descriptor
2893 * jfm:xxxx send an null pointer to say no security desc
2894 * have to implement security before !
2895 ********************************************************************/
2897 static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
2899 struct spoolss_Notify *data,
2900 print_queue_struct *queue,
2901 struct spoolss_PrinterInfo2 *pinfo2,
2902 TALLOC_CTX *mem_ctx)
2904 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2907 /*******************************************************************
2908 * fill a notify_info_data with the attributes
2909 * jfm:xxxx a samba printer is always shared
2910 ********************************************************************/
2912 static void spoolss_notify_attributes(struct messaging_context *msg_ctx,
2914 struct spoolss_Notify *data,
2915 print_queue_struct *queue,
2916 struct spoolss_PrinterInfo2 *pinfo2,
2917 TALLOC_CTX *mem_ctx)
2919 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2922 /*******************************************************************
2923 * fill a notify_info_data with the priority
2924 ********************************************************************/
2926 static void spoolss_notify_priority(struct messaging_context *msg_ctx,
2928 struct spoolss_Notify *data,
2929 print_queue_struct *queue,
2930 struct spoolss_PrinterInfo2 *pinfo2,
2931 TALLOC_CTX *mem_ctx)
2933 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2936 /*******************************************************************
2937 * fill a notify_info_data with the default priority
2938 ********************************************************************/
2940 static void spoolss_notify_default_priority(struct messaging_context *msg_ctx,
2942 struct spoolss_Notify *data,
2943 print_queue_struct *queue,
2944 struct spoolss_PrinterInfo2 *pinfo2,
2945 TALLOC_CTX *mem_ctx)
2947 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
2950 /*******************************************************************
2951 * fill a notify_info_data with the start time
2952 ********************************************************************/
2954 static void spoolss_notify_start_time(struct messaging_context *msg_ctx,
2956 struct spoolss_Notify *data,
2957 print_queue_struct *queue,
2958 struct spoolss_PrinterInfo2 *pinfo2,
2959 TALLOC_CTX *mem_ctx)
2961 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
2964 /*******************************************************************
2965 * fill a notify_info_data with the until time
2966 ********************************************************************/
2968 static void spoolss_notify_until_time(struct messaging_context *msg_ctx,
2970 struct spoolss_Notify *data,
2971 print_queue_struct *queue,
2972 struct spoolss_PrinterInfo2 *pinfo2,
2973 TALLOC_CTX *mem_ctx)
2975 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
2978 /*******************************************************************
2979 * fill a notify_info_data with the status
2980 ********************************************************************/
2982 static void spoolss_notify_status(struct messaging_context *msg_ctx,
2984 struct spoolss_Notify *data,
2985 print_queue_struct *queue,
2986 struct spoolss_PrinterInfo2 *pinfo2,
2987 TALLOC_CTX *mem_ctx)
2989 print_status_struct status;
2991 print_queue_length(msg_ctx, snum, &status);
2992 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
2995 /*******************************************************************
2996 * fill a notify_info_data with the number of jobs queued
2997 ********************************************************************/
2999 static void spoolss_notify_cjobs(struct messaging_context *msg_ctx,
3001 struct spoolss_Notify *data,
3002 print_queue_struct *queue,
3003 struct spoolss_PrinterInfo2 *pinfo2,
3004 TALLOC_CTX *mem_ctx)
3006 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3007 data, print_queue_length(msg_ctx, snum, NULL));
3010 /*******************************************************************
3011 * fill a notify_info_data with the average ppm
3012 ********************************************************************/
3014 static void spoolss_notify_average_ppm(struct messaging_context *msg_ctx,
3016 struct spoolss_Notify *data,
3017 print_queue_struct *queue,
3018 struct spoolss_PrinterInfo2 *pinfo2,
3019 TALLOC_CTX *mem_ctx)
3021 /* always respond 8 pages per minutes */
3022 /* a little hard ! */
3023 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
3026 /*******************************************************************
3027 * fill a notify_info_data with username
3028 ********************************************************************/
3030 static void spoolss_notify_username(struct messaging_context *msg_ctx,
3032 struct spoolss_Notify *data,
3033 print_queue_struct *queue,
3034 struct spoolss_PrinterInfo2 *pinfo2,
3035 TALLOC_CTX *mem_ctx)
3037 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3040 /*******************************************************************
3041 * fill a notify_info_data with job status
3042 ********************************************************************/
3044 static void spoolss_notify_job_status(struct messaging_context *msg_ctx,
3046 struct spoolss_Notify *data,
3047 print_queue_struct *queue,
3048 struct spoolss_PrinterInfo2 *pinfo2,
3049 TALLOC_CTX *mem_ctx)
3051 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3054 /*******************************************************************
3055 * fill a notify_info_data with job name
3056 ********************************************************************/
3058 static void spoolss_notify_job_name(struct messaging_context *msg_ctx,
3060 struct spoolss_Notify *data,
3061 print_queue_struct *queue,
3062 struct spoolss_PrinterInfo2 *pinfo2,
3063 TALLOC_CTX *mem_ctx)
3065 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3068 /*******************************************************************
3069 * fill a notify_info_data with job status
3070 ********************************************************************/
3072 static void spoolss_notify_job_status_string(struct messaging_context *msg_ctx,
3074 struct spoolss_Notify *data,
3075 print_queue_struct *queue,
3076 struct spoolss_PrinterInfo2 *pinfo2,
3077 TALLOC_CTX *mem_ctx)
3080 * Now we're returning job status codes we just return a "" here. JRA.
3085 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3088 switch (queue->status) {
3093 p = ""; /* NT provides the paused string */
3102 #endif /* NO LONGER NEEDED. */
3104 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3107 /*******************************************************************
3108 * fill a notify_info_data with job time
3109 ********************************************************************/
3111 static void spoolss_notify_job_time(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_INTEGER(data, 0);
3121 /*******************************************************************
3122 * fill a notify_info_data with job size
3123 ********************************************************************/
3125 static void spoolss_notify_job_size(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)
3132 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3135 /*******************************************************************
3136 * fill a notify_info_data with page info
3137 ********************************************************************/
3138 static void spoolss_notify_total_pages(struct messaging_context *msg_ctx,
3140 struct spoolss_Notify *data,
3141 print_queue_struct *queue,
3142 struct spoolss_PrinterInfo2 *pinfo2,
3143 TALLOC_CTX *mem_ctx)
3145 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3148 /*******************************************************************
3149 * fill a notify_info_data with pages printed info.
3150 ********************************************************************/
3151 static void spoolss_notify_pages_printed(struct messaging_context *msg_ctx,
3153 struct spoolss_Notify *data,
3154 print_queue_struct *queue,
3155 struct spoolss_PrinterInfo2 *pinfo2,
3156 TALLOC_CTX *mem_ctx)
3158 /* Add code when back-end tracks this */
3159 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3162 /*******************************************************************
3163 Fill a notify_info_data with job position.
3164 ********************************************************************/
3166 static void spoolss_notify_job_position(struct messaging_context *msg_ctx,
3168 struct spoolss_Notify *data,
3169 print_queue_struct *queue,
3170 struct spoolss_PrinterInfo2 *pinfo2,
3171 TALLOC_CTX *mem_ctx)
3173 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3176 /*******************************************************************
3177 Fill a notify_info_data with submitted time.
3178 ********************************************************************/
3180 static void spoolss_notify_submitted_time(struct messaging_context *msg_ctx,
3182 struct spoolss_Notify *data,
3183 print_queue_struct *queue,
3184 struct spoolss_PrinterInfo2 *pinfo2,
3185 TALLOC_CTX *mem_ctx)
3187 data->data.string.string = NULL;
3188 data->data.string.size = 0;
3190 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3191 &data->data.string.string,
3192 &data->data.string.size);
3196 struct s_notify_info_data_table
3198 enum spoolss_NotifyType type;
3201 enum spoolss_NotifyTable variable_type;
3202 void (*fn) (struct messaging_context *msg_ctx,
3203 int snum, struct spoolss_Notify *data,
3204 print_queue_struct *queue,
3205 struct spoolss_PrinterInfo2 *pinfo2,
3206 TALLOC_CTX *mem_ctx);
3209 /* A table describing the various print notification constants and
3210 whether the notification data is a pointer to a variable sized
3211 buffer, a one value uint32_t or a two value uint32_t. */
3213 static const struct s_notify_info_data_table notify_info_data_table[] =
3215 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3216 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3217 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3218 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3219 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3220 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3221 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3222 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3223 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3224 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3225 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3226 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3227 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3228 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3229 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3230 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3231 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3232 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3233 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3234 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3235 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3236 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3237 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3238 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3239 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3240 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3241 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3242 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3243 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3244 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3245 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3246 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3247 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3248 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3249 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3250 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3251 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3252 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3253 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3254 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3255 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3256 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3257 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3258 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3259 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3260 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3261 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3262 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3263 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3266 /*******************************************************************
3267 Return the variable_type of info_data structure.
3268 ********************************************************************/
3270 static enum spoolss_NotifyTable variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3275 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3276 if ( (notify_info_data_table[i].type == type) &&
3277 (notify_info_data_table[i].field == field) ) {
3278 return notify_info_data_table[i].variable_type;
3282 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3284 return (enum spoolss_NotifyTable) 0;
3287 /****************************************************************************
3288 ****************************************************************************/
3290 static bool search_notify(enum spoolss_NotifyType type,
3296 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3297 if (notify_info_data_table[i].type == type &&
3298 notify_info_data_table[i].field == field &&
3299 notify_info_data_table[i].fn != NULL) {
3308 /****************************************************************************
3309 ****************************************************************************/
3311 static void construct_info_data(struct spoolss_Notify *info_data,
3312 enum spoolss_NotifyType type,
3313 uint16_t field, int id)
3315 info_data->type = type;
3316 info_data->field.field = field;
3317 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3318 info_data->job_id = id;
3321 /*******************************************************************
3323 * fill a notify_info struct with info asked
3325 ********************************************************************/
3327 static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
3328 struct printer_handle *print_hnd,
3329 struct spoolss_NotifyInfo *info,
3330 struct spoolss_PrinterInfo2 *pinfo2,
3332 const struct spoolss_NotifyOptionType *option_type,
3334 TALLOC_CTX *mem_ctx)
3337 enum spoolss_NotifyType type;
3340 struct spoolss_Notify *current_data;
3341 print_queue_struct *queue=NULL;
3343 type = option_type->type;
3345 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3346 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3347 option_type->count, lp_servicename(snum)));
3349 for(field_num=0; field_num < option_type->count; field_num++) {
3350 field = option_type->fields[field_num].field;
3352 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3354 if (!search_notify(type, field, &j) )
3357 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3358 struct spoolss_Notify,
3360 if (info->notifies == NULL) {
3361 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3365 current_data = &info->notifies[info->count];
3367 construct_info_data(current_data, type, field, id);
3369 DEBUG(10, ("construct_notify_printer_info: "
3370 "calling [%s] snum=%d printername=[%s])\n",
3371 notify_info_data_table[j].name, snum,
3372 pinfo2->printername));
3374 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3375 queue, pinfo2, mem_ctx);
3383 /*******************************************************************
3385 * fill a notify_info struct with info asked
3387 ********************************************************************/
3389 static bool construct_notify_jobs_info(struct messaging_context *msg_ctx,
3390 print_queue_struct *queue,
3391 struct spoolss_NotifyInfo *info,
3392 struct spoolss_PrinterInfo2 *pinfo2,
3394 const struct spoolss_NotifyOptionType *option_type,
3396 TALLOC_CTX *mem_ctx)
3399 enum spoolss_NotifyType type;
3401 struct spoolss_Notify *current_data;
3403 DEBUG(4,("construct_notify_jobs_info\n"));
3405 type = option_type->type;
3407 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3408 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3409 option_type->count));
3411 for(field_num=0; field_num<option_type->count; field_num++) {
3412 field = option_type->fields[field_num].field;
3414 if (!search_notify(type, field, &j) )
3417 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3418 struct spoolss_Notify,
3420 if (info->notifies == NULL) {
3421 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3425 current_data=&(info->notifies[info->count]);
3427 construct_info_data(current_data, type, field, id);
3428 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3429 queue, pinfo2, mem_ctx);
3437 * JFM: The enumeration is not that simple, it's even non obvious.
3439 * let's take an example: I want to monitor the PRINTER SERVER for
3440 * the printer's name and the number of jobs currently queued.
3441 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3442 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3444 * I have 3 printers on the back of my server.
3446 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3449 * 1 printer 1 name 1
3450 * 2 printer 1 cjob 1
3451 * 3 printer 2 name 2
3452 * 4 printer 2 cjob 2
3453 * 5 printer 3 name 3
3454 * 6 printer 3 name 3
3456 * that's the print server case, the printer case is even worse.
3459 /*******************************************************************
3461 * enumerate all printers on the printserver
3462 * fill a notify_info struct with info asked
3464 ********************************************************************/
3466 static WERROR printserver_notify_info(struct pipes_struct *p,
3467 struct policy_handle *hnd,
3468 struct spoolss_NotifyInfo *info,
3469 TALLOC_CTX *mem_ctx)
3472 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3473 int n_services=lp_numservices();
3475 struct spoolss_NotifyOption *option;
3476 struct spoolss_NotifyOptionType option_type;
3477 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3480 DEBUG(4,("printserver_notify_info\n"));
3485 option = Printer->notify.option;
3488 info->notifies = NULL;
3491 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3492 sending a ffpcn() request first */
3497 for (i=0; i<option->count; i++) {
3498 option_type = option->types[i];
3500 if (option_type.type != PRINTER_NOTIFY_TYPE)
3503 for (snum = 0; snum < n_services; snum++) {
3504 if (!lp_browseable(snum) ||
3505 !lp_snum_ok(snum) ||
3506 !lp_print_ok(snum)) {
3507 continue; /* skip */
3510 /* Maybe we should use the SYSTEM server_info here... */
3511 result = winreg_get_printer(mem_ctx,
3512 get_server_info_system(),
3514 Printer->servername,
3515 lp_servicename(snum),
3517 if (!W_ERROR_IS_OK(result)) {
3518 DEBUG(4, ("printserver_notify_info: "
3519 "Failed to get printer [%s]\n",
3520 lp_servicename(snum)));
3525 construct_notify_printer_info(p->msg_ctx,
3531 TALLOC_FREE(pinfo2);
3537 * Debugging information, don't delete.
3540 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3541 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3542 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3544 for (i=0; i<info->count; i++) {
3545 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3546 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3547 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3554 /*******************************************************************
3556 * fill a notify_info struct with info asked
3558 ********************************************************************/
3560 static WERROR printer_notify_info(struct pipes_struct *p,
3561 struct policy_handle *hnd,
3562 struct spoolss_NotifyInfo *info,
3563 TALLOC_CTX *mem_ctx)
3566 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3569 struct spoolss_NotifyOption *option;
3570 struct spoolss_NotifyOptionType option_type;
3572 print_queue_struct *queue=NULL;
3573 print_status_struct status;
3574 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3577 DEBUG(4,("printer_notify_info\n"));
3582 option = Printer->notify.option;
3586 info->notifies = NULL;
3589 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3590 sending a ffpcn() request first */
3595 get_printer_snum(p, hnd, &snum, NULL);
3597 /* Maybe we should use the SYSTEM server_info here... */
3598 result = winreg_get_printer(mem_ctx,
3599 get_server_info_system(),
3601 Printer->servername,
3602 lp_servicename(snum), &pinfo2);
3603 if (!W_ERROR_IS_OK(result)) {
3607 for (i=0; i<option->count; i++) {
3608 option_type = option->types[i];
3610 switch (option_type.type) {
3611 case PRINTER_NOTIFY_TYPE:
3612 if (construct_notify_printer_info(p->msg_ctx,
3621 case JOB_NOTIFY_TYPE:
3623 count = print_queue_status(p->msg_ctx, snum, &queue,
3626 for (j=0; j<count; j++) {
3627 construct_notify_jobs_info(p->msg_ctx,
3641 * Debugging information, don't delete.
3644 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3645 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3646 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3648 for (i=0; i<info->count; i++) {
3649 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3650 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3651 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3655 talloc_free(pinfo2);
3659 /****************************************************************
3660 _spoolss_RouterRefreshPrinterChangeNotify
3661 ****************************************************************/
3663 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3664 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3666 struct spoolss_NotifyInfo *info;
3668 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
3669 WERROR result = WERR_BADFID;
3671 /* we always have a spoolss_NotifyInfo struct */
3672 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3674 result = WERR_NOMEM;
3678 *r->out.info = info;
3681 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3682 "Invalid handle (%s:%u:%u).\n",
3683 OUR_HANDLE(r->in.handle)));
3687 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3690 * We are now using the change value, and
3691 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3692 * I don't have a global notification system, I'm sending back all the
3693 * informations even when _NOTHING_ has changed.
3696 /* We need to keep track of the change value to send back in
3697 RRPCN replies otherwise our updates are ignored. */
3699 Printer->notify.fnpcn = true;
3701 if (Printer->notify.cli_chan != NULL &&
3702 Printer->notify.cli_chan->active_connections > 0) {
3703 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3704 "Saving change value in request [%x]\n",
3706 Printer->notify.change = r->in.change_low;
3709 /* just ignore the spoolss_NotifyOption */
3711 switch (Printer->printer_type) {
3713 result = printserver_notify_info(p, r->in.handle,
3717 case SPLHND_PRINTER:
3718 result = printer_notify_info(p, r->in.handle,
3723 Printer->notify.fnpcn = false;
3729 /********************************************************************
3730 * construct_printer_info_0
3731 * fill a printer_info_0 struct
3732 ********************************************************************/
3734 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3735 const struct auth_serversupplied_info *server_info,
3736 struct messaging_context *msg_ctx,
3737 struct spoolss_PrinterInfo2 *info2,
3738 struct spoolss_PrinterInfo0 *r,
3742 struct printer_session_counter *session_counter;
3743 struct timeval setuptime;
3744 print_status_struct status;
3746 r->printername = talloc_strdup(mem_ctx, info2->printername);
3747 W_ERROR_HAVE_NO_MEMORY(r->printername);
3749 r->servername = talloc_strdup(mem_ctx, info2->servername);
3750 W_ERROR_HAVE_NO_MEMORY(r->servername);
3752 count = print_queue_length(msg_ctx, snum, &status);
3754 /* check if we already have a counter for this printer */
3755 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3756 if (session_counter->snum == snum)
3760 /* it's the first time, add it to the list */
3761 if (session_counter == NULL) {
3762 session_counter = talloc_zero(counter_list, struct printer_session_counter);
3763 W_ERROR_HAVE_NO_MEMORY(session_counter);
3764 session_counter->snum = snum;
3765 session_counter->counter = 0;
3766 DLIST_ADD(counter_list, session_counter);
3770 session_counter->counter++;
3776 get_startup_time(&setuptime);
3777 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3780 * the global_counter should be stored in a TDB as it's common to all the clients
3781 * and should be zeroed on samba startup
3783 r->global_counter = session_counter->counter;
3785 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3786 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3787 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3788 r->free_build = SPOOLSS_RELEASE_BUILD;
3790 r->max_spooling = 0;
3791 r->session_counter = session_counter->counter;
3792 r->num_error_out_of_paper = 0x0;
3793 r->num_error_not_ready = 0x0; /* number of print failure */
3795 r->number_of_processors = 0x1;
3796 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3797 r->high_part_total_bytes = 0x0;
3799 /* ChangeID in milliseconds*/
3800 winreg_printer_get_changeid(mem_ctx, server_info, msg_ctx,
3801 info2->sharename, &r->change_id);
3803 r->last_error = WERR_OK;
3804 r->status = nt_printq_status(status.status);
3805 r->enumerate_network_printers = 0x0;
3806 r->c_setprinter = 0x0;
3807 r->processor_architecture = PROCESSOR_ARCHITECTURE_INTEL;
3808 r->processor_level = 0x6; /* 6 ???*/
3817 /********************************************************************
3818 * construct_printer_info1
3819 * fill a spoolss_PrinterInfo1 struct
3820 ********************************************************************/
3822 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3823 const struct spoolss_PrinterInfo2 *info2,
3825 struct spoolss_PrinterInfo1 *r,
3830 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3834 W_ERROR_HAVE_NO_MEMORY(r->description);
3836 if (info2->comment == NULL || info2->comment[0] == '\0') {
3837 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3839 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3841 W_ERROR_HAVE_NO_MEMORY(r->comment);
3843 r->name = talloc_strdup(mem_ctx, info2->printername);
3844 W_ERROR_HAVE_NO_MEMORY(r->name);
3849 /********************************************************************
3850 * construct_printer_info2
3851 * fill a spoolss_PrinterInfo2 struct
3852 ********************************************************************/
3854 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3855 struct messaging_context *msg_ctx,
3856 const struct spoolss_PrinterInfo2 *info2,
3857 struct spoolss_PrinterInfo2 *r,
3861 print_status_struct status;
3863 count = print_queue_length(msg_ctx, snum, &status);
3865 r->servername = talloc_strdup(mem_ctx, info2->servername);
3866 W_ERROR_HAVE_NO_MEMORY(r->servername);
3867 r->printername = talloc_strdup(mem_ctx, info2->printername);
3868 W_ERROR_HAVE_NO_MEMORY(r->printername);
3869 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3870 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3871 r->portname = talloc_strdup(mem_ctx, info2->portname);
3872 W_ERROR_HAVE_NO_MEMORY(r->portname);
3873 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
3874 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3876 if (info2->comment[0] == '\0') {
3877 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3879 r->comment = talloc_strdup(mem_ctx, info2->comment);
3881 W_ERROR_HAVE_NO_MEMORY(r->comment);
3883 r->location = talloc_strdup(mem_ctx, info2->location);
3884 W_ERROR_HAVE_NO_MEMORY(r->location);
3885 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
3886 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3887 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
3888 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3889 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
3890 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3891 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
3892 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3894 r->attributes = info2->attributes;
3896 r->priority = info2->priority;
3897 r->defaultpriority = info2->defaultpriority;
3898 r->starttime = info2->starttime;
3899 r->untiltime = info2->untiltime;
3900 r->status = nt_printq_status(status.status);
3902 r->averageppm = info2->averageppm;
3904 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3906 DEBUG(8,("Returning NULL Devicemode!\n"));
3911 if (info2->secdesc != NULL) {
3912 /* don't use talloc_steal() here unless you do a deep steal of all
3913 the SEC_DESC members */
3915 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3921 /********************************************************************
3922 * construct_printer_info3
3923 * fill a spoolss_PrinterInfo3 struct
3924 ********************************************************************/
3926 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3927 const struct spoolss_PrinterInfo2 *info2,
3928 struct spoolss_PrinterInfo3 *r,
3931 /* These are the components of the SD we are returning. */
3933 if (info2->secdesc != NULL) {
3934 /* don't use talloc_steal() here unless you do a deep steal of all
3935 the SEC_DESC members */
3937 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3938 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3944 /********************************************************************
3945 * construct_printer_info4
3946 * fill a spoolss_PrinterInfo4 struct
3947 ********************************************************************/
3949 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
3950 const struct spoolss_PrinterInfo2 *info2,
3951 struct spoolss_PrinterInfo4 *r,
3954 r->printername = talloc_strdup(mem_ctx, info2->printername);
3955 W_ERROR_HAVE_NO_MEMORY(r->printername);
3956 r->servername = talloc_strdup(mem_ctx, info2->servername);
3957 W_ERROR_HAVE_NO_MEMORY(r->servername);
3959 r->attributes = info2->attributes;
3964 /********************************************************************
3965 * construct_printer_info5
3966 * fill a spoolss_PrinterInfo5 struct
3967 ********************************************************************/
3969 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
3970 const struct spoolss_PrinterInfo2 *info2,
3971 struct spoolss_PrinterInfo5 *r,
3974 r->printername = talloc_strdup(mem_ctx, info2->printername);
3975 W_ERROR_HAVE_NO_MEMORY(r->printername);
3976 r->portname = talloc_strdup(mem_ctx, info2->portname);
3977 W_ERROR_HAVE_NO_MEMORY(r->portname);
3979 r->attributes = info2->attributes;
3981 /* these two are not used by NT+ according to MSDN */
3982 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
3983 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
3988 /********************************************************************
3989 * construct_printer_info_6
3990 * fill a spoolss_PrinterInfo6 struct
3991 ********************************************************************/
3993 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
3994 struct messaging_context *msg_ctx,
3995 const struct spoolss_PrinterInfo2 *info2,
3996 struct spoolss_PrinterInfo6 *r,
4000 print_status_struct status;
4002 count = print_queue_length(msg_ctx, snum, &status);
4004 r->status = nt_printq_status(status.status);
4009 /********************************************************************
4010 * construct_printer_info7
4011 * fill a spoolss_PrinterInfo7 struct
4012 ********************************************************************/
4014 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4015 struct messaging_context *msg_ctx,
4016 struct printer_handle *print_hnd,
4017 struct spoolss_PrinterInfo7 *r,
4020 struct auth_serversupplied_info *server_info;
4024 status = make_server_info_system(mem_ctx, &server_info);
4025 if (!NT_STATUS_IS_OK(status)) {
4026 DEBUG(0, ("construct_printer_info7: "
4027 "Could not create system server_info\n"));
4031 if (is_printer_published(mem_ctx, server_info, msg_ctx,
4032 print_hnd->servername,
4033 lp_servicename(snum), &guid, NULL)) {
4034 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4035 r->action = DSPRINT_PUBLISH;
4037 r->guid = talloc_strdup(mem_ctx, "");
4038 r->action = DSPRINT_UNPUBLISH;
4040 W_ERROR_HAVE_NO_MEMORY(r->guid);
4042 TALLOC_FREE(server_info);
4046 /********************************************************************
4047 * construct_printer_info8
4048 * fill a spoolss_PrinterInfo8 struct
4049 ********************************************************************/
4051 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4052 const struct spoolss_PrinterInfo2 *info2,
4053 struct spoolss_DeviceModeInfo *r,
4056 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
4058 DEBUG(8,("Returning NULL Devicemode!\n"));
4065 /********************************************************************
4066 ********************************************************************/
4068 static bool snum_is_shared_printer(int snum)
4070 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4073 /********************************************************************
4074 Spoolss_enumprinters.
4075 ********************************************************************/
4077 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4078 const struct auth_serversupplied_info *server_info,
4079 struct messaging_context *msg_ctx,
4082 union spoolss_PrinterInfo **info_p,
4086 int n_services = lp_numservices();
4087 union spoolss_PrinterInfo *info = NULL;
4089 WERROR result = WERR_OK;
4094 for (snum = 0; snum < n_services; snum++) {
4096 const char *printer;
4097 struct spoolss_PrinterInfo2 *info2;
4099 if (!snum_is_shared_printer(snum)) {
4103 printer = lp_const_servicename(snum);
4105 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4108 result = winreg_create_printer(mem_ctx,
4113 if (!W_ERROR_IS_OK(result)) {
4117 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4118 union spoolss_PrinterInfo,
4121 result = WERR_NOMEM;
4125 result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
4126 NULL, printer, &info2);
4127 if (!W_ERROR_IS_OK(result)) {
4133 result = construct_printer_info0(info, server_info,
4135 &info[count].info0, snum);
4138 result = construct_printer_info1(info, info2, flags,
4139 &info[count].info1, snum);
4142 result = construct_printer_info2(info, msg_ctx, info2,
4143 &info[count].info2, snum);
4146 result = construct_printer_info4(info, info2,
4147 &info[count].info4, snum);
4150 result = construct_printer_info5(info, info2,
4151 &info[count].info5, snum);
4155 result = WERR_UNKNOWN_LEVEL;
4159 if (!W_ERROR_IS_OK(result)) {
4170 if (!W_ERROR_IS_OK(result)) {
4180 /********************************************************************
4181 * handle enumeration of printers at level 0
4182 ********************************************************************/
4184 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4185 const struct auth_serversupplied_info *server_info,
4186 struct messaging_context *msg_ctx,
4188 const char *servername,
4189 union spoolss_PrinterInfo **info,
4192 DEBUG(4,("enum_all_printers_info_0\n"));
4194 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4195 0, flags, info, count);
4199 /********************************************************************
4200 ********************************************************************/
4202 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4203 const struct auth_serversupplied_info *server_info,
4204 struct messaging_context *msg_ctx,
4206 union spoolss_PrinterInfo **info,
4209 DEBUG(4,("enum_all_printers_info_1\n"));
4211 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4212 1, flags, info, count);
4215 /********************************************************************
4216 enum_all_printers_info_1_local.
4217 *********************************************************************/
4219 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4220 const struct auth_serversupplied_info *server_info,
4221 struct messaging_context *msg_ctx,
4222 union spoolss_PrinterInfo **info,
4225 DEBUG(4,("enum_all_printers_info_1_local\n"));
4227 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4228 PRINTER_ENUM_ICON8, info, count);
4231 /********************************************************************
4232 enum_all_printers_info_1_name.
4233 *********************************************************************/
4235 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4236 const struct auth_serversupplied_info *server_info,
4237 struct messaging_context *msg_ctx,
4239 union spoolss_PrinterInfo **info,
4242 const char *s = name;
4244 DEBUG(4,("enum_all_printers_info_1_name\n"));
4246 if ((name[0] == '\\') && (name[1] == '\\')) {
4250 if (!is_myname_or_ipaddr(s)) {
4251 return WERR_INVALID_NAME;
4254 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4255 PRINTER_ENUM_ICON8, info, count);
4258 /********************************************************************
4259 enum_all_printers_info_1_network.
4260 *********************************************************************/
4262 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4263 const struct auth_serversupplied_info *server_info,
4264 struct messaging_context *msg_ctx,
4266 union spoolss_PrinterInfo **info,
4269 const char *s = name;
4271 DEBUG(4,("enum_all_printers_info_1_network\n"));
4273 /* If we respond to a enum_printers level 1 on our name with flags
4274 set to PRINTER_ENUM_REMOTE with a list of printers then these
4275 printers incorrectly appear in the APW browse list.
4276 Specifically the printers for the server appear at the workgroup
4277 level where all the other servers in the domain are
4278 listed. Windows responds to this call with a
4279 WERR_CAN_NOT_COMPLETE so we should do the same. */
4281 if (name[0] == '\\' && name[1] == '\\') {
4285 if (is_myname_or_ipaddr(s)) {
4286 return WERR_CAN_NOT_COMPLETE;
4289 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4290 PRINTER_ENUM_NAME, info, count);
4293 /********************************************************************
4294 * api_spoolss_enumprinters
4296 * called from api_spoolss_enumprinters (see this to understand)
4297 ********************************************************************/
4299 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4300 const struct auth_serversupplied_info *server_info,
4301 struct messaging_context *msg_ctx,
4302 union spoolss_PrinterInfo **info,
4305 DEBUG(4,("enum_all_printers_info_2\n"));
4307 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4311 /********************************************************************
4312 * handle enumeration of printers at level 1
4313 ********************************************************************/
4315 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4316 const struct auth_serversupplied_info *server_info,
4317 struct messaging_context *msg_ctx,
4320 union spoolss_PrinterInfo **info,
4323 /* Not all the flags are equals */
4325 if (flags & PRINTER_ENUM_LOCAL) {
4326 return enum_all_printers_info_1_local(mem_ctx, server_info,
4327 msg_ctx, info, count);
4330 if (flags & PRINTER_ENUM_NAME) {
4331 return enum_all_printers_info_1_name(mem_ctx, server_info,
4332 msg_ctx, name, info,
4336 if (flags & PRINTER_ENUM_NETWORK) {
4337 return enum_all_printers_info_1_network(mem_ctx, server_info,
4338 msg_ctx, name, info,
4342 return WERR_OK; /* NT4sp5 does that */
4345 /********************************************************************
4346 * handle enumeration of printers at level 2
4347 ********************************************************************/
4349 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4350 const struct auth_serversupplied_info *server_info,
4351 struct messaging_context *msg_ctx,
4353 const char *servername,
4354 union spoolss_PrinterInfo **info,
4357 if (flags & PRINTER_ENUM_LOCAL) {
4358 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4362 if (flags & PRINTER_ENUM_NAME) {
4363 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4364 return WERR_INVALID_NAME;
4367 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4371 if (flags & PRINTER_ENUM_REMOTE) {
4372 return WERR_UNKNOWN_LEVEL;
4378 /********************************************************************
4379 * handle enumeration of printers at level 4
4380 ********************************************************************/
4382 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4383 const struct auth_serversupplied_info *server_info,
4384 struct messaging_context *msg_ctx,
4386 const char *servername,
4387 union spoolss_PrinterInfo **info,
4390 DEBUG(4,("enum_all_printers_info_4\n"));
4392 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4393 4, flags, info, count);
4397 /********************************************************************
4398 * handle enumeration of printers at level 5
4399 ********************************************************************/
4401 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4402 const struct auth_serversupplied_info *server_info,
4403 struct messaging_context *msg_ctx,
4405 const char *servername,
4406 union spoolss_PrinterInfo **info,
4409 DEBUG(4,("enum_all_printers_info_5\n"));
4411 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4412 5, flags, info, count);
4415 /****************************************************************
4416 _spoolss_EnumPrinters
4417 ****************************************************************/
4419 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4420 struct spoolss_EnumPrinters *r)
4422 const struct auth_serversupplied_info *server_info = get_server_info_system();
4423 const char *name = NULL;
4426 /* that's an [in out] buffer */
4428 if (!r->in.buffer && (r->in.offered != 0)) {
4429 return WERR_INVALID_PARAM;
4432 DEBUG(4,("_spoolss_EnumPrinters\n"));
4436 *r->out.info = NULL;
4440 * flags==PRINTER_ENUM_NAME
4441 * if name=="" then enumerates all printers
4442 * if name!="" then enumerate the printer
4443 * flags==PRINTER_ENUM_REMOTE
4444 * name is NULL, enumerate printers
4445 * Level 2: name!="" enumerates printers, name can't be NULL
4446 * Level 3: doesn't exist
4447 * Level 4: does a local registry lookup
4448 * Level 5: same as Level 2
4452 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4453 W_ERROR_HAVE_NO_MEMORY(name);
4456 switch (r->in.level) {
4458 result = enumprinters_level0(p->mem_ctx, server_info,
4459 p->msg_ctx, r->in.flags, name,
4460 r->out.info, r->out.count);
4463 result = enumprinters_level1(p->mem_ctx, server_info,
4464 p->msg_ctx, r->in.flags, name,
4465 r->out.info, r->out.count);
4468 result = enumprinters_level2(p->mem_ctx, server_info,
4469 p->msg_ctx, r->in.flags, name,
4470 r->out.info, r->out.count);
4473 result = enumprinters_level4(p->mem_ctx, server_info,
4474 p->msg_ctx, r->in.flags, name,
4475 r->out.info, r->out.count);
4478 result = enumprinters_level5(p->mem_ctx, server_info,
4479 p->msg_ctx, r->in.flags, name,
4480 r->out.info, r->out.count);
4483 return WERR_UNKNOWN_LEVEL;
4486 if (!W_ERROR_IS_OK(result)) {
4490 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4491 spoolss_EnumPrinters,
4492 *r->out.info, r->in.level,
4494 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4495 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4497 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4500 /****************************************************************
4502 ****************************************************************/
4504 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4505 struct spoolss_GetPrinter *r)
4507 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
4508 struct spoolss_PrinterInfo2 *info2 = NULL;
4509 WERROR result = WERR_OK;
4510 const char *servername = NULL;
4513 /* that's an [in out] buffer */
4515 if (!r->in.buffer && (r->in.offered != 0)) {
4516 return WERR_INVALID_PARAM;
4521 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4525 if (Printer != NULL || Printer->servername != NULL) {
4526 servername = Printer->servername;
4529 result = winreg_get_printer(p->mem_ctx,
4530 get_server_info_system(),
4533 lp_const_servicename(snum),
4535 if (!W_ERROR_IS_OK(result)) {
4539 switch (r->in.level) {
4541 result = construct_printer_info0(p->mem_ctx,
4542 get_server_info_system(),
4545 &r->out.info->info0,
4549 result = construct_printer_info1(p->mem_ctx, info2,
4551 &r->out.info->info1, snum);
4554 result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
4555 &r->out.info->info2, snum);
4558 result = construct_printer_info3(p->mem_ctx, info2,
4559 &r->out.info->info3, snum);
4562 result = construct_printer_info4(p->mem_ctx, info2,
4563 &r->out.info->info4, snum);
4566 result = construct_printer_info5(p->mem_ctx, info2,
4567 &r->out.info->info5, snum);
4570 result = construct_printer_info6(p->mem_ctx, p->msg_ctx, info2,
4571 &r->out.info->info6, snum);
4574 result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
4576 &r->out.info->info7, snum);
4579 result = construct_printer_info8(p->mem_ctx, info2,
4580 &r->out.info->info8, snum);
4583 result = WERR_UNKNOWN_LEVEL;
4587 if (!W_ERROR_IS_OK(result)) {
4588 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4589 r->in.level, win_errstr(result)));
4590 TALLOC_FREE(r->out.info);
4594 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4595 r->out.info, r->in.level);
4596 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4598 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4601 /********************************************************************
4602 ********************************************************************/
4604 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4606 if (in && strlen(in)) { \
4607 out = talloc_strdup(mem_ctx, in); \
4609 out = talloc_strdup(mem_ctx, ""); \
4611 W_ERROR_HAVE_NO_MEMORY(out); \
4614 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4616 if (in && strlen(in)) { \
4617 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4619 out = talloc_strdup(mem_ctx, ""); \
4621 W_ERROR_HAVE_NO_MEMORY(out); \
4624 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4625 const char **string_array,
4626 const char ***presult,
4627 const char *cservername,
4631 int i, num_strings = 0;
4632 const char **array = NULL;
4634 if (string_array == NULL) {
4635 return WERR_INVALID_PARAMETER;;
4638 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4639 const char *str = NULL;
4641 if (cservername == NULL || arch == NULL) {
4642 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4644 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4647 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4654 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4655 &array, &num_strings);
4665 /********************************************************************
4666 * fill a spoolss_DriverInfo1 struct
4667 ********************************************************************/
4669 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4670 struct spoolss_DriverInfo1 *r,
4671 const struct spoolss_DriverInfo8 *driver,
4672 const char *servername)
4674 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4675 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4680 /********************************************************************
4681 * fill a spoolss_DriverInfo2 struct
4682 ********************************************************************/
4684 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4685 struct spoolss_DriverInfo2 *r,
4686 const struct spoolss_DriverInfo8 *driver,
4687 const char *servername)
4690 const char *cservername = canon_servername(servername);
4692 r->version = driver->version;
4694 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4695 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4696 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4697 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4699 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4700 driver->architecture,
4702 driver->driver_path,
4705 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4706 driver->architecture,
4711 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4712 driver->architecture,
4714 driver->config_file,
4720 /********************************************************************
4721 * fill a spoolss_DriverInfo3 struct
4722 ********************************************************************/
4724 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4725 struct spoolss_DriverInfo3 *r,
4726 const struct spoolss_DriverInfo8 *driver,
4727 const char *servername)
4729 const char *cservername = canon_servername(servername);
4731 r->version = driver->version;
4733 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4734 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4735 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4736 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4738 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4739 driver->architecture,
4741 driver->driver_path,
4744 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4745 driver->architecture,
4750 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4751 driver->architecture,
4753 driver->config_file,
4756 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4757 driver->architecture,
4762 FILL_DRIVER_STRING(mem_ctx,
4763 driver->monitor_name,
4766 FILL_DRIVER_STRING(mem_ctx,
4767 driver->default_datatype,
4768 r->default_datatype);
4770 return string_array_from_driver_info(mem_ctx,
4771 driver->dependent_files,
4772 &r->dependent_files,
4774 driver->architecture,
4778 /********************************************************************
4779 * fill a spoolss_DriverInfo4 struct
4780 ********************************************************************/
4782 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4783 struct spoolss_DriverInfo4 *r,
4784 const struct spoolss_DriverInfo8 *driver,
4785 const char *servername)
4787 const char *cservername = canon_servername(servername);
4790 r->version = driver->version;
4792 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4793 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4794 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4795 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4797 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4798 driver->architecture,
4800 driver->driver_path,
4803 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4804 driver->architecture,
4809 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4810 driver->architecture,
4812 driver->config_file,
4815 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4816 driver->architecture,
4821 result = string_array_from_driver_info(mem_ctx,
4822 driver->dependent_files,
4823 &r->dependent_files,
4825 driver->architecture,
4827 if (!W_ERROR_IS_OK(result)) {
4831 FILL_DRIVER_STRING(mem_ctx,
4832 driver->monitor_name,
4835 FILL_DRIVER_STRING(mem_ctx,
4836 driver->default_datatype,
4837 r->default_datatype);
4840 result = string_array_from_driver_info(mem_ctx,
4841 driver->previous_names,
4848 /********************************************************************
4849 * fill a spoolss_DriverInfo5 struct
4850 ********************************************************************/
4852 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4853 struct spoolss_DriverInfo5 *r,
4854 const struct spoolss_DriverInfo8 *driver,
4855 const char *servername)
4857 const char *cservername = canon_servername(servername);
4859 r->version = driver->version;
4861 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4862 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4863 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4864 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4866 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4867 driver->architecture,
4869 driver->driver_path,
4872 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4873 driver->architecture,
4878 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4879 driver->architecture,
4881 driver->config_file,
4884 r->driver_attributes = 0;
4885 r->config_version = 0;
4886 r->driver_version = 0;
4890 /********************************************************************
4891 * fill a spoolss_DriverInfo6 struct
4892 ********************************************************************/
4894 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4895 struct spoolss_DriverInfo6 *r,
4896 const struct spoolss_DriverInfo8 *driver,
4897 const char *servername)
4899 const char *cservername = canon_servername(servername);
4902 r->version = driver->version;
4904 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4905 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4906 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4907 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4909 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4910 driver->architecture,
4912 driver->driver_path,
4915 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4916 driver->architecture,
4921 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4922 driver->architecture,
4924 driver->config_file,
4927 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4928 driver->architecture,
4933 FILL_DRIVER_STRING(mem_ctx,
4934 driver->monitor_name,
4937 FILL_DRIVER_STRING(mem_ctx,
4938 driver->default_datatype,
4939 r->default_datatype);
4941 result = string_array_from_driver_info(mem_ctx,
4942 driver->dependent_files,
4943 &r->dependent_files,
4945 driver->architecture,
4947 if (!W_ERROR_IS_OK(result)) {
4951 result = string_array_from_driver_info(mem_ctx,
4952 driver->previous_names,
4955 if (!W_ERROR_IS_OK(result)) {
4959 r->driver_date = driver->driver_date;
4960 r->driver_version = driver->driver_version;
4962 FILL_DRIVER_STRING(mem_ctx,
4963 driver->manufacturer_name,
4964 r->manufacturer_name);
4965 FILL_DRIVER_STRING(mem_ctx,
4966 driver->manufacturer_url,
4967 r->manufacturer_url);
4968 FILL_DRIVER_STRING(mem_ctx,
4969 driver->hardware_id,
4971 FILL_DRIVER_STRING(mem_ctx,
4978 /********************************************************************
4979 * fill a spoolss_DriverInfo8 struct
4980 ********************************************************************/
4982 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
4983 struct spoolss_DriverInfo8 *r,
4984 const struct spoolss_DriverInfo8 *driver,
4985 const char *servername)
4987 const char *cservername = canon_servername(servername);
4990 r->version = driver->version;
4992 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4993 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4994 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4995 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4997 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4998 driver->architecture,
5000 driver->driver_path,
5003 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5004 driver->architecture,
5009 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5010 driver->architecture,
5012 driver->config_file,
5015 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5016 driver->architecture,
5021 FILL_DRIVER_STRING(mem_ctx,
5022 driver->monitor_name,
5025 FILL_DRIVER_STRING(mem_ctx,
5026 driver->default_datatype,
5027 r->default_datatype);
5029 result = string_array_from_driver_info(mem_ctx,
5030 driver->dependent_files,
5031 &r->dependent_files,
5033 driver->architecture,
5035 if (!W_ERROR_IS_OK(result)) {
5039 result = string_array_from_driver_info(mem_ctx,
5040 driver->previous_names,
5043 if (!W_ERROR_IS_OK(result)) {
5047 r->driver_date = driver->driver_date;
5048 r->driver_version = driver->driver_version;
5050 FILL_DRIVER_STRING(mem_ctx,
5051 driver->manufacturer_name,
5052 r->manufacturer_name);
5053 FILL_DRIVER_STRING(mem_ctx,
5054 driver->manufacturer_url,
5055 r->manufacturer_url);
5056 FILL_DRIVER_STRING(mem_ctx,
5057 driver->hardware_id,
5059 FILL_DRIVER_STRING(mem_ctx,
5063 FILL_DRIVER_STRING(mem_ctx,
5064 driver->print_processor,
5065 r->print_processor);
5066 FILL_DRIVER_STRING(mem_ctx,
5067 driver->vendor_setup,
5070 result = string_array_from_driver_info(mem_ctx,
5071 driver->color_profiles,
5074 if (!W_ERROR_IS_OK(result)) {
5078 FILL_DRIVER_STRING(mem_ctx,
5082 r->printer_driver_attributes = driver->printer_driver_attributes;
5084 result = string_array_from_driver_info(mem_ctx,
5085 driver->core_driver_dependencies,
5086 &r->core_driver_dependencies,
5088 if (!W_ERROR_IS_OK(result)) {
5092 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
5093 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
5098 #if 0 /* disabled until marshalling issues are resolved - gd */
5099 /********************************************************************
5100 ********************************************************************/
5102 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5103 struct spoolss_DriverFileInfo *r,
5104 const char *cservername,
5105 const char *file_name,
5106 enum spoolss_DriverFileType file_type,
5107 uint32_t file_version)
5109 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5110 cservername, file_name);
5111 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5112 r->file_type = file_type;
5113 r->file_version = file_version;
5118 /********************************************************************
5119 ********************************************************************/
5121 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5122 const struct spoolss_DriverInfo8 *driver,
5123 const char *cservername,
5124 struct spoolss_DriverFileInfo **info_p,
5127 struct spoolss_DriverFileInfo *info = NULL;
5135 if (strlen(driver->driver_path)) {
5136 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5137 struct spoolss_DriverFileInfo,
5139 W_ERROR_HAVE_NO_MEMORY(info);
5140 result = fill_spoolss_DriverFileInfo(info,
5143 driver->driver_path,
5144 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5146 W_ERROR_NOT_OK_RETURN(result);
5150 if (strlen(driver->config_file)) {
5151 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5152 struct spoolss_DriverFileInfo,
5154 W_ERROR_HAVE_NO_MEMORY(info);
5155 result = fill_spoolss_DriverFileInfo(info,
5158 driver->config_file,
5159 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5161 W_ERROR_NOT_OK_RETURN(result);
5165 if (strlen(driver->data_file)) {
5166 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5167 struct spoolss_DriverFileInfo,
5169 W_ERROR_HAVE_NO_MEMORY(info);
5170 result = fill_spoolss_DriverFileInfo(info,
5174 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5176 W_ERROR_NOT_OK_RETURN(result);
5180 if (strlen(driver->help_file)) {
5181 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5182 struct spoolss_DriverFileInfo,
5184 W_ERROR_HAVE_NO_MEMORY(info);
5185 result = fill_spoolss_DriverFileInfo(info,
5189 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5191 W_ERROR_NOT_OK_RETURN(result);
5195 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
5196 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5197 struct spoolss_DriverFileInfo,
5199 W_ERROR_HAVE_NO_MEMORY(info);
5200 result = fill_spoolss_DriverFileInfo(info,
5203 driver->dependent_files[i],
5204 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5206 W_ERROR_NOT_OK_RETURN(result);
5216 /********************************************************************
5217 * fill a spoolss_DriverInfo101 struct
5218 ********************************************************************/
5220 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5221 struct spoolss_DriverInfo101 *r,
5222 const struct spoolss_DriverInfo8 *driver,
5223 const char *servername)
5225 const char *cservername = canon_servername(servername);
5228 r->version = driver->version;
5230 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5231 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5232 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5233 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5235 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5239 if (!W_ERROR_IS_OK(result)) {
5243 FILL_DRIVER_STRING(mem_ctx,
5244 driver->monitor_name,
5247 FILL_DRIVER_STRING(mem_ctx,
5248 driver->default_datatype,
5249 r->default_datatype);
5251 result = string_array_from_driver_info(mem_ctx,
5252 driver->previous_names,
5255 if (!W_ERROR_IS_OK(result)) {
5259 r->driver_date = driver->driver_date;
5260 r->driver_version = driver->driver_version;
5262 FILL_DRIVER_STRING(mem_ctx,
5263 driver->manufacturer_name,
5264 r->manufacturer_name);
5265 FILL_DRIVER_STRING(mem_ctx,
5266 driver->manufacturer_url,
5267 r->manufacturer_url);
5268 FILL_DRIVER_STRING(mem_ctx,
5269 driver->hardware_id,
5271 FILL_DRIVER_STRING(mem_ctx,
5278 /********************************************************************
5279 ********************************************************************/
5281 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5282 const struct auth_serversupplied_info *server_info,
5283 struct messaging_context *msg_ctx,
5285 union spoolss_DriverInfo *r,
5287 const char *servername,
5288 const char *architecture,
5291 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5292 struct spoolss_DriverInfo8 *driver;
5295 result = winreg_get_printer(mem_ctx,
5299 lp_const_servicename(snum),
5302 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5303 win_errstr(result)));
5305 if (!W_ERROR_IS_OK(result)) {
5306 return WERR_INVALID_PRINTER_NAME;
5309 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5311 pinfo2->drivername, version, &driver);
5313 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5314 win_errstr(result)));
5316 if (!W_ERROR_IS_OK(result)) {
5318 * Is this a W2k client ?
5322 talloc_free(pinfo2);
5323 return WERR_UNKNOWN_PRINTER_DRIVER;
5326 /* Yes - try again with a WinNT driver. */
5328 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5332 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5333 win_errstr(result)));
5334 if (!W_ERROR_IS_OK(result)) {
5335 talloc_free(pinfo2);
5336 return WERR_UNKNOWN_PRINTER_DRIVER;
5342 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5345 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5348 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5351 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5354 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5357 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5360 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5362 #if 0 /* disabled until marshalling issues are resolved - gd */
5364 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5368 result = WERR_UNKNOWN_LEVEL;
5372 talloc_free(pinfo2);
5373 talloc_free(driver);
5378 /****************************************************************
5379 _spoolss_GetPrinterDriver2
5380 ****************************************************************/
5382 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5383 struct spoolss_GetPrinterDriver2 *r)
5385 struct printer_handle *printer;
5390 /* that's an [in out] buffer */
5392 if (!r->in.buffer && (r->in.offered != 0)) {
5393 return WERR_INVALID_PARAM;
5396 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5398 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5399 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5400 return WERR_INVALID_PRINTER_NAME;
5404 *r->out.server_major_version = 0;
5405 *r->out.server_minor_version = 0;
5407 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5411 result = construct_printer_driver_info_level(p->mem_ctx,
5412 get_server_info_system(),
5414 r->in.level, r->out.info,
5415 snum, printer->servername,
5417 r->in.client_major_version);
5418 if (!W_ERROR_IS_OK(result)) {
5419 TALLOC_FREE(r->out.info);
5423 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5424 r->out.info, r->in.level);
5425 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5427 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5431 /****************************************************************
5432 _spoolss_StartPagePrinter
5433 ****************************************************************/
5435 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5436 struct spoolss_StartPagePrinter *r)
5438 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5441 DEBUG(3,("_spoolss_StartPagePrinter: "
5442 "Error in startpageprinter printer handle\n"));
5446 Printer->page_started = true;
5450 /****************************************************************
5451 _spoolss_EndPagePrinter
5452 ****************************************************************/
5454 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5455 struct spoolss_EndPagePrinter *r)
5459 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5462 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5463 OUR_HANDLE(r->in.handle)));
5467 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5470 Printer->page_started = false;
5471 print_job_endpage(p->msg_ctx, snum, Printer->jobid);
5476 /****************************************************************
5477 _spoolss_StartDocPrinter
5478 ****************************************************************/
5480 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5481 struct spoolss_StartDocPrinter *r)
5483 struct spoolss_DocumentInfo1 *info_1;
5485 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5489 DEBUG(2,("_spoolss_StartDocPrinter: "
5490 "Invalid handle (%s:%u:%u)\n",
5491 OUR_HANDLE(r->in.handle)));
5495 if (Printer->jobid) {
5496 DEBUG(2, ("_spoolss_StartDocPrinter: "
5497 "StartDocPrinter called twice! "
5498 "(existing jobid = %d)\n", Printer->jobid));
5499 return WERR_INVALID_HANDLE;
5502 if (r->in.level != 1) {
5503 return WERR_UNKNOWN_LEVEL;
5506 info_1 = r->in.info.info1;
5509 * a nice thing with NT is it doesn't listen to what you tell it.
5510 * when asked to send _only_ RAW datas, it tries to send datas
5513 * So I add checks like in NT Server ...
5516 if (info_1->datatype) {
5517 if (strcmp(info_1->datatype, "RAW") != 0) {
5519 return WERR_INVALID_DATATYPE;
5523 /* get the share number of the printer */
5524 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5528 werr = print_job_start(get_server_info_system(),
5532 info_1->document_name,
5533 info_1->output_file,
5537 /* An error occured in print_job_start() so return an appropriate
5540 if (!W_ERROR_IS_OK(werr)) {
5544 Printer->document_started = true;
5545 *r->out.job_id = Printer->jobid;
5550 /****************************************************************
5551 _spoolss_EndDocPrinter
5552 ****************************************************************/
5554 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5555 struct spoolss_EndDocPrinter *r)
5557 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5562 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5563 OUR_HANDLE(r->in.handle)));
5567 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5571 Printer->document_started = false;
5572 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5573 if (!NT_STATUS_IS_OK(status)) {
5574 DEBUG(2, ("_spoolss_EndDocPrinter: "
5575 "print_job_end failed [%s]\n",
5576 nt_errstr(status)));
5580 return ntstatus_to_werror(status);
5583 /****************************************************************
5584 _spoolss_WritePrinter
5585 ****************************************************************/
5587 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5588 struct spoolss_WritePrinter *r)
5590 ssize_t buffer_written;
5592 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5595 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5596 OUR_HANDLE(r->in.handle)));
5597 *r->out.num_written = r->in._data_size;
5601 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5604 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5605 buffer_written = print_job_write(server_event_context(),p->msg_ctx,
5606 snum, Printer->jobid,
5607 (const char *)r->in.data.data,
5608 (size_t)r->in._data_size);
5609 if (buffer_written == (ssize_t)-1) {
5610 *r->out.num_written = 0;
5611 if (errno == ENOSPC)
5612 return WERR_NO_SPOOL_SPACE;
5614 return WERR_ACCESS_DENIED;
5617 *r->out.num_written = r->in._data_size;
5622 /********************************************************************
5623 * api_spoolss_getprinter
5624 * called from the spoolss dispatcher
5626 ********************************************************************/
5628 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5629 struct pipes_struct *p)
5631 const struct auth_serversupplied_info *server_info = get_server_info_system();
5633 WERROR errcode = WERR_BADFUNC;
5634 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5637 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5638 OUR_HANDLE(handle)));
5642 if (!get_printer_snum(p, handle, &snum, NULL))
5646 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5647 errcode = print_queue_pause(server_info, p->msg_ctx, snum);
5649 case SPOOLSS_PRINTER_CONTROL_RESUME:
5650 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5651 errcode = print_queue_resume(server_info, p->msg_ctx, snum);
5653 case SPOOLSS_PRINTER_CONTROL_PURGE:
5654 errcode = print_queue_purge(server_info, p->msg_ctx, snum);
5657 return WERR_UNKNOWN_LEVEL;
5664 /****************************************************************
5665 _spoolss_AbortPrinter
5666 * From MSDN: "Deletes printer's spool file if printer is configured
5668 ****************************************************************/
5670 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5671 struct spoolss_AbortPrinter *r)
5673 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5675 WERROR errcode = WERR_OK;
5678 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5679 OUR_HANDLE(r->in.handle)));
5683 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5686 if (!Printer->document_started) {
5687 return WERR_SPL_NO_STARTDOC;
5690 errcode = print_job_delete(get_server_info_system(),
5698 /********************************************************************
5699 * called by spoolss_api_setprinter
5700 * when updating a printer description
5701 ********************************************************************/
5703 static WERROR update_printer_sec(struct policy_handle *handle,
5704 struct pipes_struct *p,
5705 struct sec_desc_buf *secdesc_ctr)
5707 struct spoolss_security_descriptor *new_secdesc = NULL;
5708 struct spoolss_security_descriptor *old_secdesc = NULL;
5709 const char *printer;
5713 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5715 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5716 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5717 OUR_HANDLE(handle)));
5719 result = WERR_BADFID;
5723 if (secdesc_ctr == NULL) {
5724 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5725 result = WERR_INVALID_PARAM;
5728 printer = lp_const_servicename(snum);
5730 /* Check the user has permissions to change the security
5731 descriptor. By experimentation with two NT machines, the user
5732 requires Full Access to the printer to change security
5735 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5736 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5737 result = WERR_ACCESS_DENIED;
5741 /* NT seems to like setting the security descriptor even though
5742 nothing may have actually changed. */
5743 result = winreg_get_printer_secdesc(p->mem_ctx,
5744 get_server_info_system(),
5748 if (!W_ERROR_IS_OK(result)) {
5749 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5750 result = WERR_BADFID;
5754 if (DEBUGLEVEL >= 10) {
5755 struct security_acl *the_acl;
5758 the_acl = old_secdesc->dacl;
5759 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5760 printer, the_acl->num_aces));
5762 for (i = 0; i < the_acl->num_aces; i++) {
5763 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5764 &the_acl->aces[i].trustee),
5765 the_acl->aces[i].access_mask));
5768 the_acl = secdesc_ctr->sd->dacl;
5771 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5772 printer, the_acl->num_aces));
5774 for (i = 0; i < the_acl->num_aces; i++) {
5775 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5776 &the_acl->aces[i].trustee),
5777 the_acl->aces[i].access_mask));
5780 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5784 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
5785 if (new_secdesc == NULL) {
5786 result = WERR_NOMEM;
5790 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
5795 result = winreg_set_printer_secdesc(p->mem_ctx,
5796 get_server_info_system(),
5805 /********************************************************************
5806 Canonicalize printer info from a client
5807 ********************************************************************/
5809 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
5810 struct spoolss_SetPrinterInfo2 *info2,
5813 fstring printername;
5816 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5817 "portname=%s drivername=%s comment=%s location=%s\n",
5818 info2->servername, info2->printername, info2->sharename,
5819 info2->portname, info2->drivername, info2->comment,
5822 /* we force some elements to "correct" values */
5823 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
5824 if (info2->servername == NULL) {
5827 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
5828 if (info2->sharename == NULL) {
5832 /* check to see if we allow printername != sharename */
5833 if (lp_force_printername(snum)) {
5834 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5835 global_myname(), info2->sharename);
5837 /* make sure printername is in \\server\printername format */
5838 fstrcpy(printername, info2->printername);
5840 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5841 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5845 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5846 global_myname(), p);
5848 if (info2->printername == NULL) {
5852 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5853 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5858 /****************************************************************************
5859 ****************************************************************************/
5861 static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri)
5863 char *cmd = lp_addport_cmd();
5864 char *command = NULL;
5866 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5867 bool is_print_op = false;
5870 return WERR_ACCESS_DENIED;
5873 command = talloc_asprintf(ctx,
5874 "%s \"%s\" \"%s\"", cmd, portname, uri );
5880 is_print_op = user_has_privileges( token, &se_printop );
5882 DEBUG(10,("Running [%s]\n", command));
5884 /********* BEGIN SePrintOperatorPrivilege **********/
5889 ret = smbrun(command, NULL);
5894 /********* END SePrintOperatorPrivilege **********/
5896 DEBUGADD(10,("returned [%d]\n", ret));
5898 TALLOC_FREE(command);
5901 return WERR_ACCESS_DENIED;
5907 /****************************************************************************
5908 ****************************************************************************/
5910 static bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
5911 struct spoolss_SetPrinterInfo2 *info2,
5912 const char *remote_machine,
5913 struct messaging_context *msg_ctx)
5915 char *cmd = lp_addprinter_cmd();
5917 char *command = NULL;
5921 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5922 bool is_print_op = false;
5924 if (!remote_machine) {
5928 command = talloc_asprintf(ctx,
5929 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5930 cmd, info2->printername, info2->sharename,
5931 info2->portname, info2->drivername,
5932 info2->location, info2->comment, remote_machine);
5938 is_print_op = user_has_privileges( token, &se_printop );
5940 DEBUG(10,("Running [%s]\n", command));
5942 /********* BEGIN SePrintOperatorPrivilege **********/
5947 if ( (ret = smbrun(command, &fd)) == 0 ) {
5948 /* Tell everyone we updated smb.conf. */
5949 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5955 /********* END SePrintOperatorPrivilege **********/
5957 DEBUGADD(10,("returned [%d]\n", ret));
5959 TALLOC_FREE(command);
5967 /* reload our services immediately */
5969 reload_services(msg_ctx, -1, false);
5973 /* Get lines and convert them back to dos-codepage */
5974 qlines = fd_lines_load(fd, &numlines, 0, NULL);
5975 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
5978 /* Set the portname to what the script says the portname should be. */
5979 /* but don't require anything to be return from the script exit a good error code */
5982 /* Set the portname to what the script says the portname should be. */
5983 info2->portname = talloc_strdup(ctx, qlines[0]);
5984 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
5987 TALLOC_FREE(qlines);
5991 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
5992 const struct auth_serversupplied_info *server_info,
5993 struct messaging_context *msg_ctx,
5995 struct spoolss_SetPrinterInfo2 *printer,
5996 struct spoolss_PrinterInfo2 *old_printer)
5998 bool force_update = (old_printer == NULL);
5999 const char *dnsdomname;
6000 const char *longname;
6001 const char *uncname;
6002 const char *spooling;
6004 WERROR result = WERR_OK;
6006 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
6007 push_reg_sz(mem_ctx, &buffer, printer->drivername);
6008 winreg_set_printer_dataex(mem_ctx,
6012 SPOOL_DSSPOOLER_KEY,
6013 SPOOL_REG_DRIVERNAME,
6018 if (!force_update) {
6019 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6020 printer->drivername));
6022 notify_printer_driver(server_event_context(), msg_ctx,
6023 snum, printer->drivername);
6027 if (force_update || !strequal(printer->comment, old_printer->comment)) {
6028 push_reg_sz(mem_ctx, &buffer, printer->comment);
6029 winreg_set_printer_dataex(mem_ctx,
6033 SPOOL_DSSPOOLER_KEY,
6034 SPOOL_REG_DESCRIPTION,
6039 if (!force_update) {
6040 notify_printer_comment(server_event_context(), msg_ctx,
6041 snum, printer->comment);
6045 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
6046 push_reg_sz(mem_ctx, &buffer, printer->sharename);
6047 winreg_set_printer_dataex(mem_ctx,
6051 SPOOL_DSSPOOLER_KEY,
6052 SPOOL_REG_PRINTSHARENAME,
6057 if (!force_update) {
6058 notify_printer_sharename(server_event_context(),
6060 snum, printer->sharename);
6064 if (force_update || !strequal(printer->printername, old_printer->printername)) {
6067 p = strrchr(printer->printername, '\\' );
6071 p = printer->printername;
6074 push_reg_sz(mem_ctx, &buffer, p);
6075 winreg_set_printer_dataex(mem_ctx,
6079 SPOOL_DSSPOOLER_KEY,
6080 SPOOL_REG_PRINTERNAME,
6085 if (!force_update) {
6086 notify_printer_printername(server_event_context(),
6091 if (force_update || !strequal(printer->portname, old_printer->portname)) {
6092 push_reg_sz(mem_ctx, &buffer, printer->portname);
6093 winreg_set_printer_dataex(mem_ctx,
6097 SPOOL_DSSPOOLER_KEY,
6103 if (!force_update) {
6104 notify_printer_port(server_event_context(),
6105 msg_ctx, snum, printer->portname);
6109 if (force_update || !strequal(printer->location, old_printer->location)) {
6110 push_reg_sz(mem_ctx, &buffer, printer->location);
6111 winreg_set_printer_dataex(mem_ctx,
6115 SPOOL_DSSPOOLER_KEY,
6121 if (!force_update) {
6122 notify_printer_location(server_event_context(),
6128 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
6129 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
6130 winreg_set_printer_dataex(mem_ctx,
6134 SPOOL_DSSPOOLER_KEY,
6135 SPOOL_REG_PRINTSEPARATORFILE,
6140 if (!force_update) {
6141 notify_printer_location(server_event_context(),
6147 if (force_update || printer->starttime != old_printer->starttime) {
6148 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6149 SIVAL(buffer.data, 0, printer->starttime);
6150 winreg_set_printer_dataex(mem_ctx,
6154 SPOOL_DSSPOOLER_KEY,
6155 SPOOL_REG_PRINTSTARTTIME,
6161 if (force_update || printer->untiltime != old_printer->untiltime) {
6162 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6163 SIVAL(buffer.data, 0, printer->untiltime);
6164 winreg_set_printer_dataex(mem_ctx,
6168 SPOOL_DSSPOOLER_KEY,
6169 SPOOL_REG_PRINTENDTIME,
6175 if (force_update || printer->priority != old_printer->priority) {
6176 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6177 SIVAL(buffer.data, 0, printer->priority);
6178 winreg_set_printer_dataex(mem_ctx,
6182 SPOOL_DSSPOOLER_KEY,
6189 if (force_update || printer->attributes != old_printer->attributes) {
6190 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6191 SIVAL(buffer.data, 0, (printer->attributes &
6192 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
6193 winreg_set_printer_dataex(mem_ctx,
6197 SPOOL_DSSPOOLER_KEY,
6198 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
6203 switch (printer->attributes & 0x3) {
6205 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
6208 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
6211 spooling = SPOOL_REGVAL_PRINTDIRECT;
6214 spooling = "unknown";
6216 push_reg_sz(mem_ctx, &buffer, spooling);
6217 winreg_set_printer_dataex(mem_ctx,
6221 SPOOL_DSSPOOLER_KEY,
6222 SPOOL_REG_PRINTSPOOLING,
6228 push_reg_sz(mem_ctx, &buffer, global_myname());
6229 winreg_set_printer_dataex(mem_ctx,
6233 SPOOL_DSSPOOLER_KEY,
6234 SPOOL_REG_SHORTSERVERNAME,
6239 dnsdomname = get_mydnsfullname();
6240 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
6241 longname = talloc_strdup(mem_ctx, dnsdomname);
6243 longname = talloc_strdup(mem_ctx, global_myname());
6245 if (longname == NULL) {
6246 result = WERR_NOMEM;
6250 push_reg_sz(mem_ctx, &buffer, longname);
6251 winreg_set_printer_dataex(mem_ctx,
6255 SPOOL_DSSPOOLER_KEY,
6256 SPOOL_REG_SERVERNAME,
6261 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6262 global_myname(), printer->sharename);
6263 push_reg_sz(mem_ctx, &buffer, uncname);
6264 winreg_set_printer_dataex(mem_ctx,
6268 SPOOL_DSSPOOLER_KEY,
6278 /********************************************************************
6279 * Called by spoolss_api_setprinter
6280 * when updating a printer description.
6281 ********************************************************************/
6283 static WERROR update_printer(struct pipes_struct *p,
6284 struct policy_handle *handle,
6285 struct spoolss_SetPrinterInfoCtr *info_ctr,
6286 struct spoolss_DeviceMode *devmode)
6288 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6289 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6290 struct spoolss_PrinterInfo2 *old_printer;
6291 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6292 const char *servername = NULL;
6294 WERROR result = WERR_OK;
6295 TALLOC_CTX *tmp_ctx;
6297 DEBUG(8,("update_printer\n"));
6299 tmp_ctx = talloc_new(p->mem_ctx);
6300 if (tmp_ctx == NULL) {
6305 result = WERR_BADFID;
6309 if (!get_printer_snum(p, handle, &snum, NULL)) {
6310 result = WERR_BADFID;
6314 if (Printer != NULL || Printer->servername != NULL) {
6315 servername = Printer->servername;
6318 result = winreg_get_printer(tmp_ctx,
6319 get_server_info_system(),
6322 lp_const_servicename(snum),
6324 if (!W_ERROR_IS_OK(result)) {
6325 result = WERR_BADFID;
6329 /* Do sanity check on the requested changes for Samba */
6330 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6331 result = WERR_INVALID_PARAM;
6335 /* FIXME!!! If the driver has changed we really should verify that
6336 it is installed before doing much else --jerry */
6338 /* Check calling user has permission to update printer description */
6339 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6340 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6341 result = WERR_ACCESS_DENIED;
6345 /* Call addprinter hook */
6346 /* Check changes to see if this is really needed */
6348 if (*lp_addprinter_cmd() &&
6349 (!strequal(printer->drivername, old_printer->drivername) ||
6350 !strequal(printer->comment, old_printer->comment) ||
6351 !strequal(printer->portname, old_printer->portname) ||
6352 !strequal(printer->location, old_printer->location)) )
6354 /* add_printer_hook() will call reload_services() */
6355 if (!add_printer_hook(tmp_ctx, p->server_info->ptok,
6356 printer, p->client_id->addr,
6358 result = WERR_ACCESS_DENIED;
6363 update_dsspooler(tmp_ctx,
6364 get_server_info_system(),
6370 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6372 if (devmode == NULL) {
6373 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6375 result = winreg_update_printer(tmp_ctx,
6376 get_server_info_system(),
6385 talloc_free(tmp_ctx);
6390 /****************************************************************************
6391 ****************************************************************************/
6392 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6393 struct policy_handle *handle,
6394 struct spoolss_SetPrinterInfo7 *info7)
6397 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6400 struct printer_handle *Printer;
6402 if ( lp_security() != SEC_ADS ) {
6403 return WERR_UNKNOWN_LEVEL;
6406 Printer = find_printer_index_by_hnd(p, handle);
6408 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6413 if (!get_printer_snum(p, handle, &snum, NULL))
6416 result = winreg_get_printer(p->mem_ctx,
6417 get_server_info_system(),
6419 Printer->servername,
6420 lp_servicename(snum),
6422 if (!W_ERROR_IS_OK(result)) {
6426 nt_printer_publish(pinfo2,
6427 get_server_info_system(),
6432 TALLOC_FREE(pinfo2);
6435 return WERR_UNKNOWN_LEVEL;
6439 /********************************************************************
6440 ********************************************************************/
6442 static WERROR update_printer_devmode(struct pipes_struct *p,
6443 struct policy_handle *handle,
6444 struct spoolss_DeviceMode *devmode)
6447 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6448 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6450 DEBUG(8,("update_printer_devmode\n"));
6456 if (!get_printer_snum(p, handle, &snum, NULL)) {
6460 /* Check calling user has permission to update printer description */
6461 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6462 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6463 return WERR_ACCESS_DENIED;
6466 return winreg_update_printer(p->mem_ctx,
6467 get_server_info_system(),
6469 lp_const_servicename(snum),
6477 /****************************************************************
6479 ****************************************************************/
6481 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6482 struct spoolss_SetPrinter *r)
6486 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6489 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6490 OUR_HANDLE(r->in.handle)));
6494 /* check the level */
6495 switch (r->in.info_ctr->level) {
6497 return control_printer(r->in.handle, r->in.command, p);
6499 result = update_printer(p, r->in.handle,
6501 r->in.devmode_ctr->devmode);
6502 if (!W_ERROR_IS_OK(result))
6504 if (r->in.secdesc_ctr->sd)
6505 result = update_printer_sec(r->in.handle, p,
6509 return update_printer_sec(r->in.handle, p,
6512 return publish_or_unpublish_printer(p, r->in.handle,
6513 r->in.info_ctr->info.info7);
6515 return update_printer_devmode(p, r->in.handle,
6516 r->in.devmode_ctr->devmode);
6518 return WERR_UNKNOWN_LEVEL;
6522 /****************************************************************
6523 _spoolss_FindClosePrinterNotify
6524 ****************************************************************/
6526 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6527 struct spoolss_FindClosePrinterNotify *r)
6529 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6532 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6533 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6537 if (Printer->notify.cli_chan != NULL &&
6538 Printer->notify.cli_chan->active_connections > 0) {
6541 if (Printer->printer_type == SPLHND_PRINTER) {
6542 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6547 srv_spoolss_replycloseprinter(snum, Printer);
6550 Printer->notify.flags=0;
6551 Printer->notify.options=0;
6552 Printer->notify.localmachine[0]='\0';
6553 Printer->notify.printerlocal=0;
6554 TALLOC_FREE(Printer->notify.option);
6559 /****************************************************************
6561 ****************************************************************/
6563 WERROR _spoolss_AddJob(struct pipes_struct *p,
6564 struct spoolss_AddJob *r)
6566 if (!r->in.buffer && (r->in.offered != 0)) {
6567 return WERR_INVALID_PARAM;
6570 /* this is what a NT server returns for AddJob. AddJob must fail on
6571 * non-local printers */
6573 if (r->in.level != 1) {
6574 return WERR_UNKNOWN_LEVEL;
6577 return WERR_INVALID_PARAM;
6580 /****************************************************************************
6582 ****************************************************************************/
6584 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6585 struct spoolss_JobInfo1 *r,
6586 const print_queue_struct *queue,
6587 int position, int snum,
6588 struct spoolss_PrinterInfo2 *pinfo2)
6592 t = gmtime(&queue->time);
6594 r->job_id = queue->job;
6596 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6597 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6598 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6599 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6600 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6601 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6602 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6603 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6604 r->data_type = talloc_strdup(mem_ctx, "RAW");
6605 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6606 r->text_status = talloc_strdup(mem_ctx, "");
6607 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6609 r->status = nt_printj_status(queue->status);
6610 r->priority = queue->priority;
6611 r->position = position;
6612 r->total_pages = queue->page_count;
6613 r->pages_printed = 0; /* ??? */
6615 init_systemtime(&r->submitted, t);
6620 /****************************************************************************
6622 ****************************************************************************/
6624 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6625 struct spoolss_JobInfo2 *r,
6626 const print_queue_struct *queue,
6627 int position, int snum,
6628 struct spoolss_PrinterInfo2 *pinfo2,
6629 struct spoolss_DeviceMode *devmode)
6633 t = gmtime(&queue->time);
6635 r->job_id = queue->job;
6637 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6638 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6639 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6640 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6641 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6642 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6643 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6644 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6645 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6646 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6647 r->data_type = talloc_strdup(mem_ctx, "RAW");
6648 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6649 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6650 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6651 r->parameters = talloc_strdup(mem_ctx, "");
6652 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6653 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6654 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6656 r->devmode = devmode;
6658 r->text_status = talloc_strdup(mem_ctx, "");
6659 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6663 r->status = nt_printj_status(queue->status);
6664 r->priority = queue->priority;
6665 r->position = position;
6668 r->total_pages = queue->page_count;
6669 r->size = queue->size;
6670 init_systemtime(&r->submitted, t);
6672 r->pages_printed = 0; /* ??? */
6677 /****************************************************************************
6679 ****************************************************************************/
6681 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6682 struct spoolss_JobInfo3 *r,
6683 const print_queue_struct *queue,
6684 const print_queue_struct *next_queue,
6685 int position, int snum,
6686 struct spoolss_PrinterInfo2 *pinfo2)
6688 r->job_id = queue->job;
6691 r->next_job_id = next_queue->job;
6698 /****************************************************************************
6699 Enumjobs at level 1.
6700 ****************************************************************************/
6702 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6703 const print_queue_struct *queue,
6704 uint32_t num_queues, int snum,
6705 struct spoolss_PrinterInfo2 *pinfo2,
6706 union spoolss_JobInfo **info_p,
6709 union spoolss_JobInfo *info;
6711 WERROR result = WERR_OK;
6713 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6714 W_ERROR_HAVE_NO_MEMORY(info);
6716 *count = num_queues;
6718 for (i=0; i<*count; i++) {
6719 result = fill_job_info1(info,
6725 if (!W_ERROR_IS_OK(result)) {
6731 if (!W_ERROR_IS_OK(result)) {
6742 /****************************************************************************
6743 Enumjobs at level 2.
6744 ****************************************************************************/
6746 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6747 const print_queue_struct *queue,
6748 uint32_t num_queues, int snum,
6749 struct spoolss_PrinterInfo2 *pinfo2,
6750 union spoolss_JobInfo **info_p,
6753 union spoolss_JobInfo *info;
6755 WERROR result = WERR_OK;
6757 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6758 W_ERROR_HAVE_NO_MEMORY(info);
6760 *count = num_queues;
6762 for (i=0; i<*count; i++) {
6763 struct spoolss_DeviceMode *devmode;
6765 result = spoolss_create_default_devmode(info,
6766 pinfo2->printername,
6768 if (!W_ERROR_IS_OK(result)) {
6769 DEBUG(3, ("Can't proceed w/o a devmode!"));
6773 result = fill_job_info2(info,
6780 if (!W_ERROR_IS_OK(result)) {
6786 if (!W_ERROR_IS_OK(result)) {
6797 /****************************************************************************
6798 Enumjobs at level 3.
6799 ****************************************************************************/
6801 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6802 const print_queue_struct *queue,
6803 uint32_t num_queues, int snum,
6804 struct spoolss_PrinterInfo2 *pinfo2,
6805 union spoolss_JobInfo **info_p,
6808 union spoolss_JobInfo *info;
6810 WERROR result = WERR_OK;
6812 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6813 W_ERROR_HAVE_NO_MEMORY(info);
6815 *count = num_queues;
6817 for (i=0; i<*count; i++) {
6818 const print_queue_struct *next_queue = NULL;
6821 next_queue = &queue[i+1];
6824 result = fill_job_info3(info,
6831 if (!W_ERROR_IS_OK(result)) {
6837 if (!W_ERROR_IS_OK(result)) {
6848 /****************************************************************
6850 ****************************************************************/
6852 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
6853 struct spoolss_EnumJobs *r)
6856 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6858 print_status_struct prt_status;
6859 print_queue_struct *queue = NULL;
6862 /* that's an [in out] buffer */
6864 if (!r->in.buffer && (r->in.offered != 0)) {
6865 return WERR_INVALID_PARAM;
6868 DEBUG(4,("_spoolss_EnumJobs\n"));
6872 *r->out.info = NULL;
6874 /* lookup the printer snum and tdb entry */
6876 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6880 result = winreg_get_printer(p->mem_ctx,
6881 get_server_info_system(),
6884 lp_const_servicename(snum),
6886 if (!W_ERROR_IS_OK(result)) {
6890 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
6891 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6892 count, prt_status.status, prt_status.message));
6896 TALLOC_FREE(pinfo2);
6900 switch (r->in.level) {
6902 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6903 pinfo2, r->out.info, r->out.count);
6906 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6907 pinfo2, r->out.info, r->out.count);
6910 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
6911 pinfo2, r->out.info, r->out.count);
6914 result = WERR_UNKNOWN_LEVEL;
6919 TALLOC_FREE(pinfo2);
6921 if (!W_ERROR_IS_OK(result)) {
6925 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6927 *r->out.info, r->in.level,
6929 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6930 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6932 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6935 /****************************************************************
6936 _spoolss_ScheduleJob
6937 ****************************************************************/
6939 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
6940 struct spoolss_ScheduleJob *r)
6945 /****************************************************************
6946 ****************************************************************/
6948 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
6949 struct messaging_context *msg_ctx,
6950 const char *printer_name,
6952 struct spoolss_SetJobInfo1 *r)
6956 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
6960 if (strequal(old_doc_name, r->document_name)) {
6964 if (!print_job_set_name(server_event_context(), msg_ctx,
6965 printer_name, job_id, r->document_name)) {
6972 /****************************************************************
6974 ****************************************************************/
6976 WERROR _spoolss_SetJob(struct pipes_struct *p,
6977 struct spoolss_SetJob *r)
6979 const struct auth_serversupplied_info *server_info = get_server_info_system();
6981 WERROR errcode = WERR_BADFUNC;
6983 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6987 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6988 return WERR_INVALID_PRINTER_NAME;
6991 switch (r->in.command) {
6992 case SPOOLSS_JOB_CONTROL_CANCEL:
6993 case SPOOLSS_JOB_CONTROL_DELETE:
6994 errcode = print_job_delete(server_info, p->msg_ctx,
6995 snum, r->in.job_id);
6996 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
7000 case SPOOLSS_JOB_CONTROL_PAUSE:
7001 if (print_job_pause(server_info, p->msg_ctx,
7002 snum, r->in.job_id, &errcode)) {
7006 case SPOOLSS_JOB_CONTROL_RESTART:
7007 case SPOOLSS_JOB_CONTROL_RESUME:
7008 if (print_job_resume(server_info, p->msg_ctx,
7009 snum, r->in.job_id, &errcode)) {
7017 return WERR_UNKNOWN_LEVEL;
7020 if (!W_ERROR_IS_OK(errcode)) {
7024 if (r->in.ctr == NULL) {
7028 switch (r->in.ctr->level) {
7030 errcode = spoolss_setjob_1(p->mem_ctx, p->msg_ctx,
7031 lp_const_servicename(snum),
7033 r->in.ctr->info.info1);
7039 return WERR_UNKNOWN_LEVEL;
7045 /****************************************************************************
7046 Enumerates all printer drivers by level and architecture.
7047 ****************************************************************************/
7049 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
7050 const struct auth_serversupplied_info *server_info,
7051 struct messaging_context *msg_ctx,
7052 const char *servername,
7053 const char *architecture,
7055 union spoolss_DriverInfo **info_p,
7060 struct spoolss_DriverInfo8 *driver;
7061 union spoolss_DriverInfo *info = NULL;
7063 WERROR result = WERR_OK;
7064 uint32_t num_drivers;
7065 const char **drivers;
7070 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7071 result = winreg_get_driver_list(mem_ctx, server_info, msg_ctx,
7072 architecture, version,
7073 &num_drivers, &drivers);
7074 if (!W_ERROR_IS_OK(result)) {
7077 DEBUG(4, ("we have:[%d] drivers in environment"
7078 " [%s] and version [%d]\n",
7079 num_drivers, architecture, version));
7081 if (num_drivers != 0) {
7082 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
7083 union spoolss_DriverInfo,
7084 count + num_drivers);
7086 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7087 "failed to enlarge driver info buffer!\n"));
7088 result = WERR_NOMEM;
7093 for (i = 0; i < num_drivers; i++) {
7094 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
7096 result = winreg_get_driver(mem_ctx, server_info,
7098 architecture, drivers[i],
7100 if (!W_ERROR_IS_OK(result)) {
7106 result = fill_printer_driver_info1(info, &info[count+i].info1,
7107 driver, servername);
7110 result = fill_printer_driver_info2(info, &info[count+i].info2,
7111 driver, servername);
7114 result = fill_printer_driver_info3(info, &info[count+i].info3,
7115 driver, servername);
7118 result = fill_printer_driver_info4(info, &info[count+i].info4,
7119 driver, servername);
7122 result = fill_printer_driver_info5(info, &info[count+i].info5,
7123 driver, servername);
7126 result = fill_printer_driver_info6(info, &info[count+i].info6,
7127 driver, servername);
7130 result = fill_printer_driver_info8(info, &info[count+i].info8,
7131 driver, servername);
7134 result = WERR_UNKNOWN_LEVEL;
7138 TALLOC_FREE(driver);
7140 if (!W_ERROR_IS_OK(result)) {
7145 count += num_drivers;
7146 TALLOC_FREE(drivers);
7150 TALLOC_FREE(drivers);
7152 if (!W_ERROR_IS_OK(result)) {
7163 /****************************************************************************
7164 Enumerates all printer drivers by level.
7165 ****************************************************************************/
7167 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
7168 const struct auth_serversupplied_info *server_info,
7169 struct messaging_context *msg_ctx,
7170 const char *servername,
7171 const char *architecture,
7173 union spoolss_DriverInfo **info_p,
7177 WERROR result = WERR_OK;
7179 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
7181 for (a=0; archi_table[a].long_archi != NULL; a++) {
7183 union spoolss_DriverInfo *info = NULL;
7186 result = enumprinterdrivers_level_by_architecture(mem_ctx,
7190 archi_table[a].long_archi,
7194 if (!W_ERROR_IS_OK(result)) {
7198 for (i=0; i < count; i++) {
7199 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
7200 info[i], info_p, count_p);
7207 return enumprinterdrivers_level_by_architecture(mem_ctx,
7217 /****************************************************************
7218 _spoolss_EnumPrinterDrivers
7219 ****************************************************************/
7221 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
7222 struct spoolss_EnumPrinterDrivers *r)
7224 const char *cservername;
7227 /* that's an [in out] buffer */
7229 if (!r->in.buffer && (r->in.offered != 0)) {
7230 return WERR_INVALID_PARAM;
7233 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7237 *r->out.info = NULL;
7239 cservername = canon_servername(r->in.server);
7241 if (!is_myname_or_ipaddr(cservername)) {
7242 return WERR_UNKNOWN_PRINTER_DRIVER;
7245 result = enumprinterdrivers_level(p->mem_ctx,
7246 get_server_info_system(),
7253 if (!W_ERROR_IS_OK(result)) {
7257 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7258 spoolss_EnumPrinterDrivers,
7259 *r->out.info, r->in.level,
7261 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7262 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7264 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7267 /****************************************************************
7269 ****************************************************************/
7271 WERROR _spoolss_EnumForms(struct pipes_struct *p,
7272 struct spoolss_EnumForms *r)
7278 *r->out.info = NULL;
7280 /* that's an [in out] buffer */
7282 if (!r->in.buffer && (r->in.offered != 0) ) {
7283 return WERR_INVALID_PARAM;
7286 DEBUG(4,("_spoolss_EnumForms\n"));
7287 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7288 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7290 switch (r->in.level) {
7292 result = winreg_printer_enumforms1(p->mem_ctx,
7293 get_server_info_system(),
7299 result = WERR_UNKNOWN_LEVEL;
7303 if (!W_ERROR_IS_OK(result)) {
7307 if (*r->out.count == 0) {
7308 return WERR_NO_MORE_ITEMS;
7311 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7313 *r->out.info, r->in.level,
7315 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7316 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7318 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7321 /****************************************************************
7323 ****************************************************************/
7325 WERROR _spoolss_GetForm(struct pipes_struct *p,
7326 struct spoolss_GetForm *r)
7330 /* that's an [in out] buffer */
7332 if (!r->in.buffer && (r->in.offered != 0)) {
7333 return WERR_INVALID_PARAM;
7336 DEBUG(4,("_spoolss_GetForm\n"));
7337 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7338 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7340 switch (r->in.level) {
7342 result = winreg_printer_getform1(p->mem_ctx,
7343 get_server_info_system(),
7346 &r->out.info->info1);
7349 result = WERR_UNKNOWN_LEVEL;
7353 if (!W_ERROR_IS_OK(result)) {
7354 TALLOC_FREE(r->out.info);
7358 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7359 r->out.info, r->in.level);
7360 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7362 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7365 /****************************************************************************
7366 ****************************************************************************/
7368 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7369 struct spoolss_PortInfo1 *r,
7372 r->port_name = talloc_strdup(mem_ctx, name);
7373 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7378 /****************************************************************************
7379 TODO: This probably needs distinguish between TCP/IP and Local ports
7381 ****************************************************************************/
7383 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7384 struct spoolss_PortInfo2 *r,
7387 r->port_name = talloc_strdup(mem_ctx, name);
7388 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7390 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7391 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7393 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7394 W_ERROR_HAVE_NO_MEMORY(r->description);
7396 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7403 /****************************************************************************
7404 wrapper around the enumer ports command
7405 ****************************************************************************/
7407 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7409 char *cmd = lp_enumports_cmd();
7410 char **qlines = NULL;
7411 char *command = NULL;
7419 /* if no hook then just fill in the default port */
7422 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7425 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7426 TALLOC_FREE(qlines);
7433 /* we have a valid enumport command */
7435 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7440 DEBUG(10,("Running [%s]\n", command));
7441 ret = smbrun(command, &fd);
7442 DEBUG(10,("Returned [%d]\n", ret));
7443 TALLOC_FREE(command);
7448 return WERR_ACCESS_DENIED;
7452 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7453 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7463 /****************************************************************************
7465 ****************************************************************************/
7467 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7468 union spoolss_PortInfo **info_p,
7471 union spoolss_PortInfo *info = NULL;
7473 WERROR result = WERR_OK;
7474 char **qlines = NULL;
7477 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7478 if (!W_ERROR_IS_OK(result)) {
7483 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7485 DEBUG(10,("Returning WERR_NOMEM\n"));
7486 result = WERR_NOMEM;
7490 for (i=0; i<numlines; i++) {
7491 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7492 result = fill_port_1(info, &info[i].info1, qlines[i]);
7493 if (!W_ERROR_IS_OK(result)) {
7498 TALLOC_FREE(qlines);
7501 if (!W_ERROR_IS_OK(result)) {
7503 TALLOC_FREE(qlines);
7515 /****************************************************************************
7517 ****************************************************************************/
7519 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7520 union spoolss_PortInfo **info_p,
7523 union spoolss_PortInfo *info = NULL;
7525 WERROR result = WERR_OK;
7526 char **qlines = NULL;
7529 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7530 if (!W_ERROR_IS_OK(result)) {
7535 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7537 DEBUG(10,("Returning WERR_NOMEM\n"));
7538 result = WERR_NOMEM;
7542 for (i=0; i<numlines; i++) {
7543 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7544 result = fill_port_2(info, &info[i].info2, qlines[i]);
7545 if (!W_ERROR_IS_OK(result)) {
7550 TALLOC_FREE(qlines);
7553 if (!W_ERROR_IS_OK(result)) {
7555 TALLOC_FREE(qlines);
7567 /****************************************************************
7569 ****************************************************************/
7571 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
7572 struct spoolss_EnumPorts *r)
7576 /* that's an [in out] buffer */
7578 if (!r->in.buffer && (r->in.offered != 0)) {
7579 return WERR_INVALID_PARAM;
7582 DEBUG(4,("_spoolss_EnumPorts\n"));
7586 *r->out.info = NULL;
7588 switch (r->in.level) {
7590 result = enumports_level_1(p->mem_ctx, r->out.info,
7594 result = enumports_level_2(p->mem_ctx, r->out.info,
7598 return WERR_UNKNOWN_LEVEL;
7601 if (!W_ERROR_IS_OK(result)) {
7605 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7607 *r->out.info, r->in.level,
7609 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7610 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7612 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7615 /****************************************************************************
7616 ****************************************************************************/
7618 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
7620 struct spoolss_SetPrinterInfoCtr *info_ctr,
7621 struct spoolss_DeviceMode *devmode,
7622 struct security_descriptor *secdesc,
7623 struct spoolss_UserLevelCtr *user_ctr,
7624 struct policy_handle *handle)
7626 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7627 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7629 WERROR err = WERR_OK;
7631 /* samba does not have a concept of local, non-shared printers yet, so
7632 * make sure we always setup sharename - gd */
7633 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7634 (info2->printername != NULL && info2->printername[0] != '\0')) {
7635 DEBUG(5, ("spoolss_addprinterex_level_2: "
7636 "no sharename has been set, setting printername %s as sharename\n",
7637 info2->printername));
7638 info2->sharename = info2->printername;
7641 /* check to see if the printer already exists */
7642 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7643 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7645 return WERR_PRINTER_ALREADY_EXISTS;
7648 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7649 if ((snum = print_queue_snum(info2->printername)) != -1) {
7650 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7651 info2->printername));
7652 return WERR_PRINTER_ALREADY_EXISTS;
7656 /* validate printer info struct */
7657 if (!info2->printername || strlen(info2->printername) == 0) {
7658 return WERR_INVALID_PRINTER_NAME;
7660 if (!info2->portname || strlen(info2->portname) == 0) {
7661 return WERR_UNKNOWN_PORT;
7663 if (!info2->drivername || strlen(info2->drivername) == 0) {
7664 return WERR_UNKNOWN_PRINTER_DRIVER;
7666 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7667 return WERR_UNKNOWN_PRINTPROCESSOR;
7670 /* FIXME!!! smbd should check to see if the driver is installed before
7671 trying to add a printer like this --jerry */
7673 if (*lp_addprinter_cmd() ) {
7674 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7675 info2, p->client_id->addr,
7677 return WERR_ACCESS_DENIED;
7680 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7681 "smb.conf parameter \"addprinter command\" is defined. This"
7682 "parameter must exist for this call to succeed\n",
7683 info2->sharename ));
7686 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7687 return WERR_ACCESS_DENIED;
7690 /* you must be a printer admin to add a new printer */
7691 if (!print_access_check(get_server_info_system(),
7694 PRINTER_ACCESS_ADMINISTER)) {
7695 return WERR_ACCESS_DENIED;
7699 * Do sanity check on the requested changes for Samba.
7702 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7703 return WERR_INVALID_PARAM;
7706 if (devmode == NULL) {
7707 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7710 update_dsspooler(p->mem_ctx,
7711 get_server_info_system(),
7717 err = winreg_update_printer(p->mem_ctx,
7718 get_server_info_system(),
7725 if (!W_ERROR_IS_OK(err)) {
7729 if (!open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER)) {
7730 /* Handle open failed - remove addition. */
7731 ZERO_STRUCTP(handle);
7732 return WERR_ACCESS_DENIED;
7738 /****************************************************************
7739 _spoolss_AddPrinterEx
7740 ****************************************************************/
7742 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
7743 struct spoolss_AddPrinterEx *r)
7745 switch (r->in.info_ctr->level) {
7747 /* we don't handle yet */
7748 /* but I know what to do ... */
7749 return WERR_UNKNOWN_LEVEL;
7751 return spoolss_addprinterex_level_2(p, r->in.server,
7753 r->in.devmode_ctr->devmode,
7754 r->in.secdesc_ctr->sd,
7755 r->in.userlevel_ctr,
7758 return WERR_UNKNOWN_LEVEL;
7762 /****************************************************************
7764 ****************************************************************/
7766 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
7767 struct spoolss_AddPrinter *r)
7769 struct spoolss_AddPrinterEx a;
7770 struct spoolss_UserLevelCtr userlevel_ctr;
7772 ZERO_STRUCT(userlevel_ctr);
7774 userlevel_ctr.level = 1;
7776 a.in.server = r->in.server;
7777 a.in.info_ctr = r->in.info_ctr;
7778 a.in.devmode_ctr = r->in.devmode_ctr;
7779 a.in.secdesc_ctr = r->in.secdesc_ctr;
7780 a.in.userlevel_ctr = &userlevel_ctr;
7781 a.out.handle = r->out.handle;
7783 return _spoolss_AddPrinterEx(p, &a);
7786 /****************************************************************
7787 _spoolss_AddPrinterDriverEx
7788 ****************************************************************/
7790 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
7791 struct spoolss_AddPrinterDriverEx *r)
7793 WERROR err = WERR_OK;
7794 const char *driver_name = NULL;
7799 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7800 fn = "_spoolss_AddPrinterDriver";
7802 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7803 fn = "_spoolss_AddPrinterDriverEx";
7806 return WERR_INVALID_PARAM;
7810 * we only support the semantics of AddPrinterDriver()
7811 * i.e. only copy files that are newer than existing ones
7814 if (r->in.flags == 0) {
7815 return WERR_INVALID_PARAM;
7818 if (r->in.flags != APD_COPY_NEW_FILES) {
7819 return WERR_ACCESS_DENIED;
7823 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7824 /* Clever hack from Martin Zielinski <mz@seh.de>
7825 * to allow downgrade from level 8 (Vista).
7827 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7828 r->in.info_ctr->level));
7829 return WERR_UNKNOWN_LEVEL;
7832 DEBUG(5,("Cleaning driver's information\n"));
7833 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
7834 if (!W_ERROR_IS_OK(err))
7837 DEBUG(5,("Moving driver to final destination\n"));
7838 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7843 err = winreg_add_driver(p->mem_ctx,
7844 get_server_info_system(),
7849 if (!W_ERROR_IS_OK(err)) {
7854 * I think this is where he DrvUpgradePrinter() hook would be
7855 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7856 * server. Right now, we just need to send ourselves a message
7857 * to update each printer bound to this driver. --jerry
7860 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
7861 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7869 /****************************************************************
7870 _spoolss_AddPrinterDriver
7871 ****************************************************************/
7873 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
7874 struct spoolss_AddPrinterDriver *r)
7876 struct spoolss_AddPrinterDriverEx a;
7878 switch (r->in.info_ctr->level) {
7885 return WERR_UNKNOWN_LEVEL;
7888 a.in.servername = r->in.servername;
7889 a.in.info_ctr = r->in.info_ctr;
7890 a.in.flags = APD_COPY_NEW_FILES;
7892 return _spoolss_AddPrinterDriverEx(p, &a);
7895 /****************************************************************************
7896 ****************************************************************************/
7898 struct _spoolss_paths {
7904 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7906 static const struct _spoolss_paths spoolss_paths[]= {
7907 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7908 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7911 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7912 const char *servername,
7913 const char *environment,
7917 const char *pservername = NULL;
7918 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7919 const char *short_archi;
7923 /* environment may be empty */
7924 if (environment && strlen(environment)) {
7925 long_archi = environment;
7928 /* servername may be empty */
7929 if (servername && strlen(servername)) {
7930 pservername = canon_servername(servername);
7932 if (!is_myname_or_ipaddr(pservername)) {
7933 return WERR_INVALID_PARAM;
7937 if (!(short_archi = get_short_archi(long_archi))) {
7938 return WERR_INVALID_ENVIRONMENT;
7941 switch (component) {
7942 case SPOOLSS_PRTPROCS_PATH:
7943 case SPOOLSS_DRIVER_PATH:
7945 *path = talloc_asprintf(mem_ctx,
7948 spoolss_paths[component].share,
7951 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7952 SPOOLSS_DEFAULT_SERVER_PATH,
7953 spoolss_paths[component].dir,
7958 return WERR_INVALID_PARAM;
7968 /****************************************************************************
7969 ****************************************************************************/
7971 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7972 const char *servername,
7973 const char *environment,
7974 struct spoolss_DriverDirectoryInfo1 *r)
7979 werr = compose_spoolss_server_path(mem_ctx,
7982 SPOOLSS_DRIVER_PATH,
7984 if (!W_ERROR_IS_OK(werr)) {
7988 DEBUG(4,("printer driver directory: [%s]\n", path));
7990 r->directory_name = path;
7995 /****************************************************************
7996 _spoolss_GetPrinterDriverDirectory
7997 ****************************************************************/
7999 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
8000 struct spoolss_GetPrinterDriverDirectory *r)
8004 /* that's an [in out] buffer */
8006 if (!r->in.buffer && (r->in.offered != 0)) {
8007 return WERR_INVALID_PARAM;
8010 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8015 /* r->in.level is ignored */
8017 werror = getprinterdriverdir_level_1(p->mem_ctx,
8020 &r->out.info->info1);
8021 if (!W_ERROR_IS_OK(werror)) {
8022 TALLOC_FREE(r->out.info);
8026 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
8027 r->out.info, r->in.level);
8028 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8030 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8033 /****************************************************************
8034 _spoolss_EnumPrinterData
8035 ****************************************************************/
8037 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
8038 struct spoolss_EnumPrinterData *r)
8041 struct spoolss_EnumPrinterDataEx r2;
8043 struct spoolss_PrinterEnumValues *info, *val = NULL;
8046 r2.in.handle = r->in.handle;
8047 r2.in.key_name = "PrinterDriverData";
8049 r2.out.count = &count;
8050 r2.out.info = &info;
8051 r2.out.needed = &needed;
8053 result = _spoolss_EnumPrinterDataEx(p, &r2);
8054 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8055 r2.in.offered = needed;
8056 result = _spoolss_EnumPrinterDataEx(p, &r2);
8058 if (!W_ERROR_IS_OK(result)) {
8063 * The NT machine wants to know the biggest size of value and data
8065 * cf: MSDN EnumPrinterData remark section
8068 if (!r->in.value_offered && !r->in.data_offered) {
8069 uint32_t biggest_valuesize = 0;
8070 uint32_t biggest_datasize = 0;
8073 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8075 for (i=0; i<count; i++) {
8077 name_length = strlen(info[i].value_name);
8078 if (strlen(info[i].value_name) > biggest_valuesize) {
8079 biggest_valuesize = name_length;
8082 if (info[i].data_length > biggest_datasize) {
8083 biggest_datasize = info[i].data_length;
8086 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8090 /* the value is an UNICODE string but real_value_size is the length
8091 in bytes including the trailing 0 */
8093 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8094 *r->out.data_needed = biggest_datasize;
8096 DEBUG(6,("final values: [%d], [%d]\n",
8097 *r->out.value_needed, *r->out.data_needed));
8102 if (r->in.enum_index < count) {
8103 val = &info[r->in.enum_index];
8107 /* out_value should default to "" or else NT4 has
8108 problems unmarshalling the response */
8110 if (r->in.value_offered) {
8111 *r->out.value_needed = 1;
8112 r->out.value_name = talloc_strdup(r, "");
8113 if (!r->out.value_name) {
8117 r->out.value_name = NULL;
8118 *r->out.value_needed = 0;
8121 /* the data is counted in bytes */
8123 *r->out.data_needed = r->in.data_offered;
8125 result = WERR_NO_MORE_ITEMS;
8129 * - counted in bytes in the request
8130 * - counted in UNICODE chars in the max reply
8131 * - counted in bytes in the real size
8133 * take a pause *before* coding not *during* coding
8137 if (r->in.value_offered) {
8138 r->out.value_name = talloc_strdup(r, val->value_name);
8139 if (!r->out.value_name) {
8142 *r->out.value_needed = val->value_name_len;
8144 r->out.value_name = NULL;
8145 *r->out.value_needed = 0;
8150 *r->out.type = val->type;
8152 /* data - counted in bytes */
8155 * See the section "Dynamically Typed Query Parameters"
8159 if (r->out.data && val->data && val->data->data &&
8160 val->data_length && r->in.data_offered) {
8161 memcpy(r->out.data, val->data->data,
8162 MIN(val->data_length,r->in.data_offered));
8165 *r->out.data_needed = val->data_length;
8173 /****************************************************************
8174 _spoolss_SetPrinterData
8175 ****************************************************************/
8177 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
8178 struct spoolss_SetPrinterData *r)
8180 struct spoolss_SetPrinterDataEx r2;
8182 r2.in.handle = r->in.handle;
8183 r2.in.key_name = "PrinterDriverData";
8184 r2.in.value_name = r->in.value_name;
8185 r2.in.type = r->in.type;
8186 r2.in.data = r->in.data;
8187 r2.in.offered = r->in.offered;
8189 return _spoolss_SetPrinterDataEx(p, &r2);
8192 /****************************************************************
8193 _spoolss_ResetPrinter
8194 ****************************************************************/
8196 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
8197 struct spoolss_ResetPrinter *r)
8199 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8202 DEBUG(5,("_spoolss_ResetPrinter\n"));
8205 * All we do is to check to see if the handle and queue is valid.
8206 * This call really doesn't mean anything to us because we only
8207 * support RAW printing. --jerry
8211 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8212 OUR_HANDLE(r->in.handle)));
8216 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8220 /* blindly return success */
8224 /****************************************************************
8225 _spoolss_DeletePrinterData
8226 ****************************************************************/
8228 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
8229 struct spoolss_DeletePrinterData *r)
8231 struct spoolss_DeletePrinterDataEx r2;
8233 r2.in.handle = r->in.handle;
8234 r2.in.key_name = "PrinterDriverData";
8235 r2.in.value_name = r->in.value_name;
8237 return _spoolss_DeletePrinterDataEx(p, &r2);
8240 /****************************************************************
8242 ****************************************************************/
8244 WERROR _spoolss_AddForm(struct pipes_struct *p,
8245 struct spoolss_AddForm *r)
8247 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8249 WERROR status = WERR_OK;
8250 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8252 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8254 DEBUG(5,("_spoolss_AddForm\n"));
8257 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8258 OUR_HANDLE(r->in.handle)));
8262 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8263 and not a printer admin, then fail */
8265 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8266 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8267 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8268 p->server_info->info3->base.domain.string,
8270 p->server_info->ptok,
8271 lp_printer_admin(snum))) {
8272 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8273 return WERR_ACCESS_DENIED;
8276 switch (form->flags) {
8277 case SPOOLSS_FORM_USER:
8278 case SPOOLSS_FORM_BUILTIN:
8279 case SPOOLSS_FORM_PRINTER:
8282 return WERR_INVALID_PARAM;
8285 status = winreg_printer_addform1(p->mem_ctx,
8286 get_server_info_system(),
8289 if (!W_ERROR_IS_OK(status)) {
8294 * ChangeID must always be set if this is a printer
8296 if (Printer->printer_type == SPLHND_PRINTER) {
8297 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8301 status = winreg_printer_update_changeid(p->mem_ctx,
8302 get_server_info_system(),
8304 lp_const_servicename(snum));
8305 if (!W_ERROR_IS_OK(status)) {
8313 /****************************************************************
8315 ****************************************************************/
8317 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8318 struct spoolss_DeleteForm *r)
8320 const char *form_name = r->in.form_name;
8321 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8323 WERROR status = WERR_OK;
8324 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8326 DEBUG(5,("_spoolss_DeleteForm\n"));
8329 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8330 OUR_HANDLE(r->in.handle)));
8334 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8335 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8336 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8337 p->server_info->info3->base.domain.string,
8339 p->server_info->ptok,
8340 lp_printer_admin(snum))) {
8341 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8342 return WERR_ACCESS_DENIED;
8345 status = winreg_printer_deleteform1(p->mem_ctx,
8346 get_server_info_system(),
8349 if (!W_ERROR_IS_OK(status)) {
8354 * ChangeID must always be set if this is a printer
8356 if (Printer->printer_type == SPLHND_PRINTER) {
8357 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8361 status = winreg_printer_update_changeid(p->mem_ctx,
8362 get_server_info_system(),
8364 lp_const_servicename(snum));
8365 if (!W_ERROR_IS_OK(status)) {
8373 /****************************************************************
8375 ****************************************************************/
8377 WERROR _spoolss_SetForm(struct pipes_struct *p,
8378 struct spoolss_SetForm *r)
8380 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8381 const char *form_name = r->in.form_name;
8383 WERROR status = WERR_OK;
8384 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8386 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8388 DEBUG(5,("_spoolss_SetForm\n"));
8391 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8392 OUR_HANDLE(r->in.handle)));
8396 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8397 and not a printer admin, then fail */
8399 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8400 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8401 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8402 p->server_info->info3->base.domain.string,
8404 p->server_info->ptok,
8405 lp_printer_admin(snum))) {
8406 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8407 return WERR_ACCESS_DENIED;
8410 status = winreg_printer_setform1(p->mem_ctx,
8411 get_server_info_system(),
8415 if (!W_ERROR_IS_OK(status)) {
8420 * ChangeID must always be set if this is a printer
8422 if (Printer->printer_type == SPLHND_PRINTER) {
8423 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8427 status = winreg_printer_update_changeid(p->mem_ctx,
8428 get_server_info_system(),
8430 lp_const_servicename(snum));
8431 if (!W_ERROR_IS_OK(status)) {
8439 /****************************************************************************
8440 fill_print_processor1
8441 ****************************************************************************/
8443 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8444 struct spoolss_PrintProcessorInfo1 *r,
8445 const char *print_processor_name)
8447 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8448 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8453 /****************************************************************************
8454 enumprintprocessors level 1.
8455 ****************************************************************************/
8457 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8458 union spoolss_PrintProcessorInfo **info_p,
8461 union spoolss_PrintProcessorInfo *info;
8464 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8465 W_ERROR_HAVE_NO_MEMORY(info);
8469 result = fill_print_processor1(info, &info[0].info1, "winprint");
8470 if (!W_ERROR_IS_OK(result)) {
8475 if (!W_ERROR_IS_OK(result)) {
8486 /****************************************************************
8487 _spoolss_EnumPrintProcessors
8488 ****************************************************************/
8490 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8491 struct spoolss_EnumPrintProcessors *r)
8495 /* that's an [in out] buffer */
8497 if (!r->in.buffer && (r->in.offered != 0)) {
8498 return WERR_INVALID_PARAM;
8501 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8504 * Enumerate the print processors ...
8506 * Just reply with "winprint", to keep NT happy
8507 * and I can use my nice printer checker.
8512 *r->out.info = NULL;
8514 switch (r->in.level) {
8516 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8520 return WERR_UNKNOWN_LEVEL;
8523 if (!W_ERROR_IS_OK(result)) {
8527 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8528 spoolss_EnumPrintProcessors,
8529 *r->out.info, r->in.level,
8531 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8532 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8534 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8537 /****************************************************************************
8538 fill_printprocdatatype1
8539 ****************************************************************************/
8541 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8542 struct spoolss_PrintProcDataTypesInfo1 *r,
8543 const char *name_array)
8545 r->name_array = talloc_strdup(mem_ctx, name_array);
8546 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8551 /****************************************************************************
8552 enumprintprocdatatypes level 1.
8553 ****************************************************************************/
8555 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8556 union spoolss_PrintProcDataTypesInfo **info_p,
8560 union spoolss_PrintProcDataTypesInfo *info;
8562 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8563 W_ERROR_HAVE_NO_MEMORY(info);
8567 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8568 if (!W_ERROR_IS_OK(result)) {
8573 if (!W_ERROR_IS_OK(result)) {
8584 /****************************************************************
8585 _spoolss_EnumPrintProcDataTypes
8586 ****************************************************************/
8588 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
8589 struct spoolss_EnumPrintProcDataTypes *r)
8593 /* that's an [in out] buffer */
8595 if (!r->in.buffer && (r->in.offered != 0)) {
8596 return WERR_INVALID_PARAM;
8599 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8603 *r->out.info = NULL;
8605 switch (r->in.level) {
8607 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8611 return WERR_UNKNOWN_LEVEL;
8614 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8615 spoolss_EnumPrintProcDataTypes,
8616 *r->out.info, r->in.level,
8618 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8619 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8621 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8624 /****************************************************************************
8626 ****************************************************************************/
8628 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8629 struct spoolss_MonitorInfo1 *r,
8630 const char *monitor_name)
8632 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8633 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8638 /****************************************************************************
8640 ****************************************************************************/
8642 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8643 struct spoolss_MonitorInfo2 *r,
8644 const char *monitor_name,
8645 const char *environment,
8646 const char *dll_name)
8648 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8649 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8650 r->environment = talloc_strdup(mem_ctx, environment);
8651 W_ERROR_HAVE_NO_MEMORY(r->environment);
8652 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8653 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8658 /****************************************************************************
8659 enumprintmonitors level 1.
8660 ****************************************************************************/
8662 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8663 union spoolss_MonitorInfo **info_p,
8666 union spoolss_MonitorInfo *info;
8667 WERROR result = WERR_OK;
8669 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8670 W_ERROR_HAVE_NO_MEMORY(info);
8674 result = fill_monitor_1(info, &info[0].info1,
8676 if (!W_ERROR_IS_OK(result)) {
8680 result = fill_monitor_1(info, &info[1].info1,
8682 if (!W_ERROR_IS_OK(result)) {
8687 if (!W_ERROR_IS_OK(result)) {
8698 /****************************************************************************
8699 enumprintmonitors level 2.
8700 ****************************************************************************/
8702 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8703 union spoolss_MonitorInfo **info_p,
8706 union spoolss_MonitorInfo *info;
8707 WERROR result = WERR_OK;
8709 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8710 W_ERROR_HAVE_NO_MEMORY(info);
8714 result = fill_monitor_2(info, &info[0].info2,
8716 "Windows NT X86", /* FIXME */
8718 if (!W_ERROR_IS_OK(result)) {
8722 result = fill_monitor_2(info, &info[1].info2,
8724 "Windows NT X86", /* FIXME */
8726 if (!W_ERROR_IS_OK(result)) {
8731 if (!W_ERROR_IS_OK(result)) {
8742 /****************************************************************
8743 _spoolss_EnumMonitors
8744 ****************************************************************/
8746 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
8747 struct spoolss_EnumMonitors *r)
8751 /* that's an [in out] buffer */
8753 if (!r->in.buffer && (r->in.offered != 0)) {
8754 return WERR_INVALID_PARAM;
8757 DEBUG(5,("_spoolss_EnumMonitors\n"));
8760 * Enumerate the print monitors ...
8762 * Just reply with "Local Port", to keep NT happy
8763 * and I can use my nice printer checker.
8768 *r->out.info = NULL;
8770 switch (r->in.level) {
8772 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8776 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8780 return WERR_UNKNOWN_LEVEL;
8783 if (!W_ERROR_IS_OK(result)) {
8787 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8788 spoolss_EnumMonitors,
8789 *r->out.info, r->in.level,
8791 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8792 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8794 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8797 /****************************************************************************
8798 ****************************************************************************/
8800 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8801 const print_queue_struct *queue,
8802 int count, int snum,
8803 struct spoolss_PrinterInfo2 *pinfo2,
8805 struct spoolss_JobInfo1 *r)
8810 for (i=0; i<count; i++) {
8811 if (queue[i].job == (int)jobid) {
8817 if (found == false) {
8818 /* NT treats not found as bad param... yet another bad choice */
8819 return WERR_INVALID_PARAM;
8822 return fill_job_info1(mem_ctx,
8830 /****************************************************************************
8831 ****************************************************************************/
8833 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8834 const print_queue_struct *queue,
8835 int count, int snum,
8836 struct spoolss_PrinterInfo2 *pinfo2,
8838 struct spoolss_JobInfo2 *r)
8842 struct spoolss_DeviceMode *devmode;
8845 for (i=0; i<count; i++) {
8846 if (queue[i].job == (int)jobid) {
8852 if (found == false) {
8853 /* NT treats not found as bad param... yet another bad
8855 return WERR_INVALID_PARAM;
8859 * if the print job does not have a DEVMODE associated with it,
8860 * just use the one for the printer. A NULL devicemode is not
8861 * a failure condition
8864 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8866 result = spoolss_create_default_devmode(mem_ctx,
8867 pinfo2->printername,
8869 if (!W_ERROR_IS_OK(result)) {
8870 DEBUG(3, ("Can't proceed w/o a devmode!"));
8875 return fill_job_info2(mem_ctx,
8884 /****************************************************************
8886 ****************************************************************/
8888 WERROR _spoolss_GetJob(struct pipes_struct *p,
8889 struct spoolss_GetJob *r)
8891 WERROR result = WERR_OK;
8892 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8895 print_queue_struct *queue = NULL;
8896 print_status_struct prt_status;
8898 /* that's an [in out] buffer */
8900 if (!r->in.buffer && (r->in.offered != 0)) {
8901 return WERR_INVALID_PARAM;
8904 DEBUG(5,("_spoolss_GetJob\n"));
8908 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8912 result = winreg_get_printer(p->mem_ctx,
8913 get_server_info_system(),
8916 lp_const_servicename(snum),
8918 if (!W_ERROR_IS_OK(result)) {
8922 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
8924 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8925 count, prt_status.status, prt_status.message));
8927 switch (r->in.level) {
8929 result = getjob_level_1(p->mem_ctx,
8930 queue, count, snum, pinfo2,
8931 r->in.job_id, &r->out.info->info1);
8934 result = getjob_level_2(p->mem_ctx,
8935 queue, count, snum, pinfo2,
8936 r->in.job_id, &r->out.info->info2);
8939 result = WERR_UNKNOWN_LEVEL;
8944 TALLOC_FREE(pinfo2);
8946 if (!W_ERROR_IS_OK(result)) {
8947 TALLOC_FREE(r->out.info);
8951 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
8953 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8955 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8958 /****************************************************************
8959 _spoolss_GetPrinterDataEx
8960 ****************************************************************/
8962 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
8963 struct spoolss_GetPrinterDataEx *r)
8966 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8967 const char *printer;
8969 WERROR result = WERR_OK;
8971 enum winreg_Type val_type;
8976 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8978 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8979 r->in.key_name, r->in.value_name));
8981 /* in case of problem, return some default values */
8984 *r->out.type = REG_NONE;
8987 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8988 OUR_HANDLE(r->in.handle)));
8989 result = WERR_BADFID;
8993 /* Is the handle to a printer or to the server? */
8995 if (Printer->printer_type == SPLHND_SERVER) {
8997 union spoolss_PrinterData data;
8999 result = getprinterdata_printer_server(p->mem_ctx,
9003 if (!W_ERROR_IS_OK(result)) {
9007 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
9008 *r->out.type, &data);
9009 if (!W_ERROR_IS_OK(result)) {
9013 *r->out.needed = blob.length;
9015 if (r->in.offered >= *r->out.needed) {
9016 memcpy(r->out.data, blob.data, blob.length);
9019 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9022 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9025 printer = lp_const_servicename(snum);
9027 /* check to see if the keyname is valid */
9028 if (!strlen(r->in.key_name)) {
9029 return WERR_INVALID_PARAM;
9032 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9033 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
9034 strequal(r->in.value_name, "ChangeId")) {
9035 *r->out.type = REG_DWORD;
9037 if (r->in.offered >= *r->out.needed) {
9038 uint32_t changeid = 0;
9040 result = winreg_printer_get_changeid(p->mem_ctx,
9041 get_server_info_system(),
9045 if (!W_ERROR_IS_OK(result)) {
9049 SIVAL(r->out.data, 0, changeid);
9055 result = winreg_get_printer_dataex(p->mem_ctx,
9056 get_server_info_system(),
9064 if (!W_ERROR_IS_OK(result)) {
9068 *r->out.needed = val_size;
9069 *r->out.type = val_type;
9071 if (r->in.offered >= *r->out.needed) {
9072 memcpy(r->out.data, val_data, val_size);
9076 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
9077 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
9079 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9082 /****************************************************************
9083 _spoolss_SetPrinterDataEx
9084 ****************************************************************/
9086 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
9087 struct spoolss_SetPrinterDataEx *r)
9089 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9091 WERROR result = WERR_OK;
9092 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9095 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9097 /* From MSDN documentation of SetPrinterDataEx: pass request to
9098 SetPrinterData if key is "PrinterDriverData" */
9101 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9102 OUR_HANDLE(r->in.handle)));
9106 if (Printer->printer_type == SPLHND_SERVER) {
9107 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9108 "Not implemented for server handles yet\n"));
9109 return WERR_INVALID_PARAM;
9112 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9117 * Access check : NT returns "access denied" if you make a
9118 * SetPrinterData call without the necessary privildge.
9119 * we were originally returning OK if nothing changed
9120 * which made Win2k issue **a lot** of SetPrinterData
9121 * when connecting to a printer --jerry
9124 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9125 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9126 "change denied by handle access permissions\n"));
9127 return WERR_ACCESS_DENIED;
9130 result = winreg_get_printer(Printer,
9131 get_server_info_system(),
9133 Printer->servername,
9134 lp_servicename(snum),
9136 if (!W_ERROR_IS_OK(result)) {
9140 /* check for OID in valuename */
9142 oid_string = strchr(r->in.value_name, ',');
9148 /* save the registry data */
9150 result = winreg_set_printer_dataex(p->mem_ctx,
9151 get_server_info_system(),
9160 if (W_ERROR_IS_OK(result)) {
9161 /* save the OID if one was specified */
9163 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9164 r->in.key_name, SPOOL_OID_KEY);
9166 result = WERR_NOMEM;
9171 * I'm not checking the status here on purpose. Don't know
9172 * if this is right, but I'm returning the status from the
9173 * previous set_printer_dataex() call. I have no idea if
9174 * this is right. --jerry
9176 winreg_set_printer_dataex(p->mem_ctx,
9177 get_server_info_system(),
9183 (uint8_t *) oid_string,
9184 strlen(oid_string) + 1);
9187 result = winreg_printer_update_changeid(p->mem_ctx,
9188 get_server_info_system(),
9190 lp_const_servicename(snum));
9195 talloc_free(pinfo2);
9199 /****************************************************************
9200 _spoolss_DeletePrinterDataEx
9201 ****************************************************************/
9203 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
9204 struct spoolss_DeletePrinterDataEx *r)
9206 const char *printer;
9208 WERROR status = WERR_OK;
9209 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9211 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9214 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9215 "Invalid handle (%s:%u:%u).\n",
9216 OUR_HANDLE(r->in.handle)));
9220 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9221 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9222 "printer properties change denied by handle\n"));
9223 return WERR_ACCESS_DENIED;
9226 if (!r->in.value_name || !r->in.key_name) {
9230 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9233 printer = lp_const_servicename(snum);
9235 status = winreg_delete_printer_dataex(p->mem_ctx,
9236 get_server_info_system(),
9241 if (W_ERROR_IS_OK(status)) {
9242 status = winreg_printer_update_changeid(p->mem_ctx,
9243 get_server_info_system(),
9251 /****************************************************************
9252 _spoolss_EnumPrinterKey
9253 ****************************************************************/
9255 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
9256 struct spoolss_EnumPrinterKey *r)
9259 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9261 WERROR result = WERR_BADFILE;
9262 const char **array = NULL;
9265 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9268 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9269 OUR_HANDLE(r->in.handle)));
9273 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9277 result = winreg_enum_printer_key(p->mem_ctx,
9278 get_server_info_system(),
9280 lp_const_servicename(snum),
9284 if (!W_ERROR_IS_OK(result)) {
9288 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9289 result = WERR_NOMEM;
9293 *r->out._ndr_size = r->in.offered / 2;
9294 *r->out.needed = blob.length;
9296 if (r->in.offered < *r->out.needed) {
9297 result = WERR_MORE_DATA;
9300 r->out.key_buffer->string_array = array;
9304 if (!W_ERROR_IS_OK(result)) {
9306 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9314 /****************************************************************
9315 _spoolss_DeletePrinterKey
9316 ****************************************************************/
9318 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9319 struct spoolss_DeletePrinterKey *r)
9321 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9324 const char *printer;
9326 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9329 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9330 OUR_HANDLE(r->in.handle)));
9334 /* if keyname == NULL, return error */
9335 if ( !r->in.key_name )
9336 return WERR_INVALID_PARAM;
9338 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9342 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9343 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9344 "printer properties change denied by handle\n"));
9345 return WERR_ACCESS_DENIED;
9348 printer = lp_const_servicename(snum);
9350 /* delete the key and all subkeys */
9351 status = winreg_delete_printer_key(p->mem_ctx,
9352 get_server_info_system(),
9356 if (W_ERROR_IS_OK(status)) {
9357 status = winreg_printer_update_changeid(p->mem_ctx,
9358 get_server_info_system(),
9366 /****************************************************************
9367 _spoolss_EnumPrinterDataEx
9368 ****************************************************************/
9370 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9371 struct spoolss_EnumPrinterDataEx *r)
9374 struct spoolss_PrinterEnumValues *info = NULL;
9375 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9379 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9383 *r->out.info = NULL;
9386 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9387 OUR_HANDLE(r->in.handle)));
9392 * first check for a keyname of NULL or "". Win2k seems to send
9393 * this a lot and we should send back WERR_INVALID_PARAM
9394 * no need to spend time looking up the printer in this case.
9398 if (!strlen(r->in.key_name)) {
9399 result = WERR_INVALID_PARAM;
9403 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9407 /* now look for a match on the key name */
9408 result = winreg_enum_printer_dataex(p->mem_ctx,
9409 get_server_info_system(),
9411 lp_const_servicename(snum),
9415 if (!W_ERROR_IS_OK(result)) {
9419 #if 0 /* FIXME - gd */
9420 /* housekeeping information in the reply */
9422 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9423 * the hand marshalled container size is a multiple
9424 * of 4 bytes for RPC alignment.
9428 needed += 4-(needed % 4);
9431 *r->out.count = count;
9432 *r->out.info = info;
9435 if (!W_ERROR_IS_OK(result)) {
9439 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9440 spoolss_EnumPrinterDataEx,
9443 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9444 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9446 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9449 /****************************************************************************
9450 ****************************************************************************/
9452 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9453 const char *servername,
9454 const char *environment,
9455 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9460 werr = compose_spoolss_server_path(mem_ctx,
9463 SPOOLSS_PRTPROCS_PATH,
9465 if (!W_ERROR_IS_OK(werr)) {
9469 DEBUG(4,("print processor directory: [%s]\n", path));
9471 r->directory_name = path;
9476 /****************************************************************
9477 _spoolss_GetPrintProcessorDirectory
9478 ****************************************************************/
9480 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
9481 struct spoolss_GetPrintProcessorDirectory *r)
9485 /* that's an [in out] buffer */
9487 if (!r->in.buffer && (r->in.offered != 0)) {
9488 return WERR_INVALID_PARAM;
9491 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9496 /* r->in.level is ignored */
9498 /* We always should reply with a local print processor directory so that
9499 * users are not forced to have a [prnproc$] share on the Samba spoolss
9500 * server - Guenther */
9502 result = getprintprocessordirectory_level_1(p->mem_ctx,
9503 NULL, /* r->in.server */
9505 &r->out.info->info1);
9506 if (!W_ERROR_IS_OK(result)) {
9507 TALLOC_FREE(r->out.info);
9511 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9512 r->out.info, r->in.level);
9513 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9515 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9518 /*******************************************************************
9519 ********************************************************************/
9521 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9522 const char *dllname)
9524 enum ndr_err_code ndr_err;
9525 struct spoolss_MonitorUi ui;
9527 ui.dll_name = dllname;
9529 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9530 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9531 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9532 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9534 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9537 /*******************************************************************
9538 Streams the monitor UI DLL name in UNICODE
9539 *******************************************************************/
9541 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9542 NT_USER_TOKEN *token, DATA_BLOB *in,
9543 DATA_BLOB *out, uint32_t *needed)
9545 const char *dllname = "tcpmonui.dll";
9547 *needed = (strlen(dllname)+1) * 2;
9549 if (out->length < *needed) {
9550 return WERR_INSUFFICIENT_BUFFER;
9553 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9560 /*******************************************************************
9561 ********************************************************************/
9563 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9564 struct spoolss_PortData1 *port1,
9565 const DATA_BLOB *buf)
9567 enum ndr_err_code ndr_err;
9568 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9569 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9570 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9571 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9573 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9576 /*******************************************************************
9577 ********************************************************************/
9579 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9580 struct spoolss_PortData2 *port2,
9581 const DATA_BLOB *buf)
9583 enum ndr_err_code ndr_err;
9584 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9585 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9586 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9587 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9589 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9592 /*******************************************************************
9593 Create a new TCP/IP port
9594 *******************************************************************/
9596 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9597 NT_USER_TOKEN *token, DATA_BLOB *in,
9598 DATA_BLOB *out, uint32_t *needed)
9600 struct spoolss_PortData1 port1;
9601 struct spoolss_PortData2 port2;
9602 char *device_uri = NULL;
9605 const char *portname;
9606 const char *hostaddress;
9608 uint32_t port_number;
9611 /* peek for spoolss_PortData version */
9613 if (!in || (in->length < (128 + 4))) {
9614 return WERR_GENERAL_FAILURE;
9617 version = IVAL(in->data, 128);
9623 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9627 portname = port1.portname;
9628 hostaddress = port1.hostaddress;
9629 queue = port1.queue;
9630 protocol = port1.protocol;
9631 port_number = port1.port_number;
9637 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9641 portname = port2.portname;
9642 hostaddress = port2.hostaddress;
9643 queue = port2.queue;
9644 protocol = port2.protocol;
9645 port_number = port2.port_number;
9649 DEBUG(1,("xcvtcp_addport: "
9650 "unknown version of port_data: %d\n", version));
9651 return WERR_UNKNOWN_PORT;
9654 /* create the device URI and call the add_port_hook() */
9657 case PROTOCOL_RAWTCP_TYPE:
9658 device_uri = talloc_asprintf(mem_ctx,
9659 "socket://%s:%d/", hostaddress,
9663 case PROTOCOL_LPR_TYPE:
9664 device_uri = talloc_asprintf(mem_ctx,
9665 "lpr://%s/%s", hostaddress, queue );
9669 return WERR_UNKNOWN_PORT;
9676 return add_port_hook(mem_ctx, token, portname, device_uri);
9679 /*******************************************************************
9680 *******************************************************************/
9682 struct xcv_api_table xcvtcp_cmds[] = {
9683 { "MonitorUI", xcvtcp_monitorui },
9684 { "AddPort", xcvtcp_addport},
9688 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9689 NT_USER_TOKEN *token, const char *command,
9696 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9698 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9699 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9700 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9703 return WERR_BADFUNC;
9706 /*******************************************************************
9707 *******************************************************************/
9708 #if 0 /* don't support management using the "Local Port" monitor */
9710 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9711 NT_USER_TOKEN *token, DATA_BLOB *in,
9712 DATA_BLOB *out, uint32_t *needed)
9714 const char *dllname = "localui.dll";
9716 *needed = (strlen(dllname)+1) * 2;
9718 if (out->length < *needed) {
9719 return WERR_INSUFFICIENT_BUFFER;
9722 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9729 /*******************************************************************
9730 *******************************************************************/
9732 struct xcv_api_table xcvlocal_cmds[] = {
9733 { "MonitorUI", xcvlocal_monitorui },
9737 struct xcv_api_table xcvlocal_cmds[] = {
9744 /*******************************************************************
9745 *******************************************************************/
9747 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9748 NT_USER_TOKEN *token, const char *command,
9749 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9754 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9756 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9757 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9758 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9760 return WERR_BADFUNC;
9763 /****************************************************************
9765 ****************************************************************/
9767 WERROR _spoolss_XcvData(struct pipes_struct *p,
9768 struct spoolss_XcvData *r)
9770 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9771 DATA_BLOB out_data = data_blob_null;
9775 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9776 OUR_HANDLE(r->in.handle)));
9780 /* Has to be a handle to the TCP/IP port monitor */
9782 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9783 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9787 /* requires administrative access to the server */
9789 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9790 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9791 return WERR_ACCESS_DENIED;
9794 /* Allocate the outgoing buffer */
9796 if (r->in.out_data_size) {
9797 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9798 if (out_data.data == NULL) {
9803 switch ( Printer->printer_type ) {
9804 case SPLHND_PORTMON_TCP:
9805 werror = process_xcvtcp_command(p->mem_ctx,
9806 p->server_info->ptok,
9807 r->in.function_name,
9808 &r->in.in_data, &out_data,
9811 case SPLHND_PORTMON_LOCAL:
9812 werror = process_xcvlocal_command(p->mem_ctx,
9813 p->server_info->ptok,
9814 r->in.function_name,
9815 &r->in.in_data, &out_data,
9819 werror = WERR_INVALID_PRINT_MONITOR;
9822 if (!W_ERROR_IS_OK(werror)) {
9826 *r->out.status_code = 0;
9828 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9829 memcpy(r->out.out_data, out_data.data,
9830 MIN(r->in.out_data_size, out_data.length));
9836 /****************************************************************
9837 _spoolss_AddPrintProcessor
9838 ****************************************************************/
9840 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
9841 struct spoolss_AddPrintProcessor *r)
9843 /* for now, just indicate success and ignore the add. We'll
9844 automatically set the winprint processor for printer
9845 entries later. Used to debug the LexMark Optra S 1855 PCL
9851 /****************************************************************
9853 ****************************************************************/
9855 WERROR _spoolss_AddPort(struct pipes_struct *p,
9856 struct spoolss_AddPort *r)
9858 /* do what w2k3 does */
9860 return WERR_NOT_SUPPORTED;
9863 /****************************************************************
9864 _spoolss_GetPrinterDriver
9865 ****************************************************************/
9867 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
9868 struct spoolss_GetPrinterDriver *r)
9870 p->rng_fault_state = true;
9871 return WERR_NOT_SUPPORTED;
9874 /****************************************************************
9875 _spoolss_ReadPrinter
9876 ****************************************************************/
9878 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
9879 struct spoolss_ReadPrinter *r)
9881 p->rng_fault_state = true;
9882 return WERR_NOT_SUPPORTED;
9885 /****************************************************************
9886 _spoolss_WaitForPrinterChange
9887 ****************************************************************/
9889 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
9890 struct spoolss_WaitForPrinterChange *r)
9892 p->rng_fault_state = true;
9893 return WERR_NOT_SUPPORTED;
9896 /****************************************************************
9897 _spoolss_ConfigurePort
9898 ****************************************************************/
9900 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
9901 struct spoolss_ConfigurePort *r)
9903 p->rng_fault_state = true;
9904 return WERR_NOT_SUPPORTED;
9907 /****************************************************************
9909 ****************************************************************/
9911 WERROR _spoolss_DeletePort(struct pipes_struct *p,
9912 struct spoolss_DeletePort *r)
9914 p->rng_fault_state = true;
9915 return WERR_NOT_SUPPORTED;
9918 /****************************************************************
9919 _spoolss_CreatePrinterIC
9920 ****************************************************************/
9922 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
9923 struct spoolss_CreatePrinterIC *r)
9925 p->rng_fault_state = true;
9926 return WERR_NOT_SUPPORTED;
9929 /****************************************************************
9930 _spoolss_PlayGDIScriptOnPrinterIC
9931 ****************************************************************/
9933 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
9934 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9936 p->rng_fault_state = true;
9937 return WERR_NOT_SUPPORTED;
9940 /****************************************************************
9941 _spoolss_DeletePrinterIC
9942 ****************************************************************/
9944 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
9945 struct spoolss_DeletePrinterIC *r)
9947 p->rng_fault_state = true;
9948 return WERR_NOT_SUPPORTED;
9951 /****************************************************************
9952 _spoolss_AddPrinterConnection
9953 ****************************************************************/
9955 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
9956 struct spoolss_AddPrinterConnection *r)
9958 p->rng_fault_state = true;
9959 return WERR_NOT_SUPPORTED;
9962 /****************************************************************
9963 _spoolss_DeletePrinterConnection
9964 ****************************************************************/
9966 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
9967 struct spoolss_DeletePrinterConnection *r)
9969 p->rng_fault_state = true;
9970 return WERR_NOT_SUPPORTED;
9973 /****************************************************************
9974 _spoolss_PrinterMessageBox
9975 ****************************************************************/
9977 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
9978 struct spoolss_PrinterMessageBox *r)
9980 p->rng_fault_state = true;
9981 return WERR_NOT_SUPPORTED;
9984 /****************************************************************
9986 ****************************************************************/
9988 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
9989 struct spoolss_AddMonitor *r)
9991 p->rng_fault_state = true;
9992 return WERR_NOT_SUPPORTED;
9995 /****************************************************************
9996 _spoolss_DeleteMonitor
9997 ****************************************************************/
9999 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
10000 struct spoolss_DeleteMonitor *r)
10002 p->rng_fault_state = true;
10003 return WERR_NOT_SUPPORTED;
10006 /****************************************************************
10007 _spoolss_DeletePrintProcessor
10008 ****************************************************************/
10010 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
10011 struct spoolss_DeletePrintProcessor *r)
10013 p->rng_fault_state = true;
10014 return WERR_NOT_SUPPORTED;
10017 /****************************************************************
10018 _spoolss_AddPrintProvidor
10019 ****************************************************************/
10021 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
10022 struct spoolss_AddPrintProvidor *r)
10024 p->rng_fault_state = true;
10025 return WERR_NOT_SUPPORTED;
10028 /****************************************************************
10029 _spoolss_DeletePrintProvidor
10030 ****************************************************************/
10032 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
10033 struct spoolss_DeletePrintProvidor *r)
10035 p->rng_fault_state = true;
10036 return WERR_NOT_SUPPORTED;
10039 /****************************************************************
10040 _spoolss_FindFirstPrinterChangeNotification
10041 ****************************************************************/
10043 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
10044 struct spoolss_FindFirstPrinterChangeNotification *r)
10046 p->rng_fault_state = true;
10047 return WERR_NOT_SUPPORTED;
10050 /****************************************************************
10051 _spoolss_FindNextPrinterChangeNotification
10052 ****************************************************************/
10054 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
10055 struct spoolss_FindNextPrinterChangeNotification *r)
10057 p->rng_fault_state = true;
10058 return WERR_NOT_SUPPORTED;
10061 /****************************************************************
10062 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10063 ****************************************************************/
10065 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
10066 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10068 p->rng_fault_state = true;
10069 return WERR_NOT_SUPPORTED;
10072 /****************************************************************
10073 _spoolss_ReplyOpenPrinter
10074 ****************************************************************/
10076 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
10077 struct spoolss_ReplyOpenPrinter *r)
10079 p->rng_fault_state = true;
10080 return WERR_NOT_SUPPORTED;
10083 /****************************************************************
10084 _spoolss_RouterReplyPrinter
10085 ****************************************************************/
10087 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
10088 struct spoolss_RouterReplyPrinter *r)
10090 p->rng_fault_state = true;
10091 return WERR_NOT_SUPPORTED;
10094 /****************************************************************
10095 _spoolss_ReplyClosePrinter
10096 ****************************************************************/
10098 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
10099 struct spoolss_ReplyClosePrinter *r)
10101 p->rng_fault_state = true;
10102 return WERR_NOT_SUPPORTED;
10105 /****************************************************************
10107 ****************************************************************/
10109 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
10110 struct spoolss_AddPortEx *r)
10112 p->rng_fault_state = true;
10113 return WERR_NOT_SUPPORTED;
10116 /****************************************************************
10117 _spoolss_RouterFindFirstPrinterChangeNotification
10118 ****************************************************************/
10120 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
10121 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10123 p->rng_fault_state = true;
10124 return WERR_NOT_SUPPORTED;
10127 /****************************************************************
10128 _spoolss_SpoolerInit
10129 ****************************************************************/
10131 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
10132 struct spoolss_SpoolerInit *r)
10134 p->rng_fault_state = true;
10135 return WERR_NOT_SUPPORTED;
10138 /****************************************************************
10139 _spoolss_ResetPrinterEx
10140 ****************************************************************/
10142 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
10143 struct spoolss_ResetPrinterEx *r)
10145 p->rng_fault_state = true;
10146 return WERR_NOT_SUPPORTED;
10149 /****************************************************************
10150 _spoolss_RouterReplyPrinterEx
10151 ****************************************************************/
10153 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
10154 struct spoolss_RouterReplyPrinterEx *r)
10156 p->rng_fault_state = true;
10157 return WERR_NOT_SUPPORTED;
10160 /****************************************************************
10162 ****************************************************************/
10164 WERROR _spoolss_44(struct pipes_struct *p,
10165 struct spoolss_44 *r)
10167 p->rng_fault_state = true;
10168 return WERR_NOT_SUPPORTED;
10171 /****************************************************************
10173 ****************************************************************/
10175 WERROR _spoolss_47(struct pipes_struct *p,
10176 struct spoolss_47 *r)
10178 p->rng_fault_state = true;
10179 return WERR_NOT_SUPPORTED;
10182 /****************************************************************
10184 ****************************************************************/
10186 WERROR _spoolss_4a(struct pipes_struct *p,
10187 struct spoolss_4a *r)
10189 p->rng_fault_state = true;
10190 return WERR_NOT_SUPPORTED;
10193 /****************************************************************
10195 ****************************************************************/
10197 WERROR _spoolss_4b(struct pipes_struct *p,
10198 struct spoolss_4b *r)
10200 p->rng_fault_state = true;
10201 return WERR_NOT_SUPPORTED;
10204 /****************************************************************
10206 ****************************************************************/
10208 WERROR _spoolss_4c(struct pipes_struct *p,
10209 struct spoolss_4c *r)
10211 p->rng_fault_state = true;
10212 return WERR_NOT_SUPPORTED;
10215 /****************************************************************
10217 ****************************************************************/
10219 WERROR _spoolss_53(struct pipes_struct *p,
10220 struct spoolss_53 *r)
10222 p->rng_fault_state = true;
10223 return WERR_NOT_SUPPORTED;
10226 /****************************************************************
10228 ****************************************************************/
10230 WERROR _spoolss_55(struct pipes_struct *p,
10231 struct spoolss_55 *r)
10233 p->rng_fault_state = true;
10234 return WERR_NOT_SUPPORTED;
10237 /****************************************************************
10239 ****************************************************************/
10241 WERROR _spoolss_56(struct pipes_struct *p,
10242 struct spoolss_56 *r)
10244 p->rng_fault_state = true;
10245 return WERR_NOT_SUPPORTED;
10248 /****************************************************************
10250 ****************************************************************/
10252 WERROR _spoolss_57(struct pipes_struct *p,
10253 struct spoolss_57 *r)
10255 p->rng_fault_state = true;
10256 return WERR_NOT_SUPPORTED;
10259 /****************************************************************
10261 ****************************************************************/
10263 WERROR _spoolss_5a(struct pipes_struct *p,
10264 struct spoolss_5a *r)
10266 p->rng_fault_state = true;
10267 return WERR_NOT_SUPPORTED;
10270 /****************************************************************
10272 ****************************************************************/
10274 WERROR _spoolss_5b(struct pipes_struct *p,
10275 struct spoolss_5b *r)
10277 p->rng_fault_state = true;
10278 return WERR_NOT_SUPPORTED;
10281 /****************************************************************
10283 ****************************************************************/
10285 WERROR _spoolss_5c(struct pipes_struct *p,
10286 struct spoolss_5c *r)
10288 p->rng_fault_state = true;
10289 return WERR_NOT_SUPPORTED;
10292 /****************************************************************
10294 ****************************************************************/
10296 WERROR _spoolss_5d(struct pipes_struct *p,
10297 struct spoolss_5d *r)
10299 p->rng_fault_state = true;
10300 return WERR_NOT_SUPPORTED;
10303 /****************************************************************
10305 ****************************************************************/
10307 WERROR _spoolss_5e(struct pipes_struct *p,
10308 struct spoolss_5e *r)
10310 p->rng_fault_state = true;
10311 return WERR_NOT_SUPPORTED;
10314 /****************************************************************
10316 ****************************************************************/
10318 WERROR _spoolss_5f(struct pipes_struct *p,
10319 struct spoolss_5f *r)
10321 p->rng_fault_state = true;
10322 return WERR_NOT_SUPPORTED;
10325 /****************************************************************
10327 ****************************************************************/
10329 WERROR _spoolss_60(struct pipes_struct *p,
10330 struct spoolss_60 *r)
10332 p->rng_fault_state = true;
10333 return WERR_NOT_SUPPORTED;
10336 /****************************************************************
10338 ****************************************************************/
10340 WERROR _spoolss_61(struct pipes_struct *p,
10341 struct spoolss_61 *r)
10343 p->rng_fault_state = true;
10344 return WERR_NOT_SUPPORTED;
10347 /****************************************************************
10349 ****************************************************************/
10351 WERROR _spoolss_62(struct pipes_struct *p,
10352 struct spoolss_62 *r)
10354 p->rng_fault_state = true;
10355 return WERR_NOT_SUPPORTED;
10358 /****************************************************************
10360 ****************************************************************/
10362 WERROR _spoolss_63(struct pipes_struct *p,
10363 struct spoolss_63 *r)
10365 p->rng_fault_state = true;
10366 return WERR_NOT_SUPPORTED;
10369 /****************************************************************
10371 ****************************************************************/
10373 WERROR _spoolss_64(struct pipes_struct *p,
10374 struct spoolss_64 *r)
10376 p->rng_fault_state = true;
10377 return WERR_NOT_SUPPORTED;
10380 /****************************************************************
10382 ****************************************************************/
10384 WERROR _spoolss_65(struct pipes_struct *p,
10385 struct spoolss_65 *r)
10387 p->rng_fault_state = true;
10388 return WERR_NOT_SUPPORTED;
10391 /****************************************************************
10392 _spoolss_GetCorePrinterDrivers
10393 ****************************************************************/
10395 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10396 struct spoolss_GetCorePrinterDrivers *r)
10398 p->rng_fault_state = true;
10399 return WERR_NOT_SUPPORTED;
10402 /****************************************************************
10404 ****************************************************************/
10406 WERROR _spoolss_67(struct pipes_struct *p,
10407 struct spoolss_67 *r)
10409 p->rng_fault_state = true;
10410 return WERR_NOT_SUPPORTED;
10413 /****************************************************************
10414 _spoolss_GetPrinterDriverPackagePath
10415 ****************************************************************/
10417 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10418 struct spoolss_GetPrinterDriverPackagePath *r)
10420 p->rng_fault_state = true;
10421 return WERR_NOT_SUPPORTED;
10424 /****************************************************************
10426 ****************************************************************/
10428 WERROR _spoolss_69(struct pipes_struct *p,
10429 struct spoolss_69 *r)
10431 p->rng_fault_state = true;
10432 return WERR_NOT_SUPPORTED;
10435 /****************************************************************
10437 ****************************************************************/
10439 WERROR _spoolss_6a(struct pipes_struct *p,
10440 struct spoolss_6a *r)
10442 p->rng_fault_state = true;
10443 return WERR_NOT_SUPPORTED;
10446 /****************************************************************
10448 ****************************************************************/
10450 WERROR _spoolss_6b(struct pipes_struct *p,
10451 struct spoolss_6b *r)
10453 p->rng_fault_state = true;
10454 return WERR_NOT_SUPPORTED;
10457 /****************************************************************
10459 ****************************************************************/
10461 WERROR _spoolss_6c(struct pipes_struct *p,
10462 struct spoolss_6c *r)
10464 p->rng_fault_state = true;
10465 return WERR_NOT_SUPPORTED;
10468 /****************************************************************
10470 ****************************************************************/
10472 WERROR _spoolss_6d(struct pipes_struct *p,
10473 struct spoolss_6d *r)
10475 p->rng_fault_state = true;
10476 return WERR_NOT_SUPPORTED;