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 uint64_t 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 uint64_t 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 uint64_t 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 uint64_t 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;
4588 if (!W_ERROR_IS_OK(result)) {
4589 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4590 r->in.level, win_errstr(result)));
4591 TALLOC_FREE(r->out.info);
4595 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4596 r->out.info, r->in.level);
4597 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4599 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4602 /********************************************************************
4603 ********************************************************************/
4605 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4607 if (in && strlen(in)) { \
4608 out = talloc_strdup(mem_ctx, in); \
4610 out = talloc_strdup(mem_ctx, ""); \
4612 W_ERROR_HAVE_NO_MEMORY(out); \
4615 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4617 if (in && strlen(in)) { \
4618 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4620 out = talloc_strdup(mem_ctx, ""); \
4622 W_ERROR_HAVE_NO_MEMORY(out); \
4625 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4626 const char **string_array,
4627 const char ***presult,
4628 const char *cservername,
4632 int i, num_strings = 0;
4633 const char **array = NULL;
4635 if (string_array == NULL) {
4636 return WERR_INVALID_PARAMETER;;
4639 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4640 const char *str = NULL;
4642 if (cservername == NULL || arch == NULL) {
4643 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4645 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4648 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4655 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4656 &array, &num_strings);
4666 /********************************************************************
4667 * fill a spoolss_DriverInfo1 struct
4668 ********************************************************************/
4670 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4671 struct spoolss_DriverInfo1 *r,
4672 const struct spoolss_DriverInfo8 *driver,
4673 const char *servername)
4675 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4676 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4681 /********************************************************************
4682 * fill a spoolss_DriverInfo2 struct
4683 ********************************************************************/
4685 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4686 struct spoolss_DriverInfo2 *r,
4687 const struct spoolss_DriverInfo8 *driver,
4688 const char *servername)
4691 const char *cservername = canon_servername(servername);
4693 r->version = driver->version;
4695 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4696 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4697 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4698 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4700 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4701 driver->architecture,
4703 driver->driver_path,
4706 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4707 driver->architecture,
4712 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4713 driver->architecture,
4715 driver->config_file,
4721 /********************************************************************
4722 * fill a spoolss_DriverInfo3 struct
4723 ********************************************************************/
4725 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4726 struct spoolss_DriverInfo3 *r,
4727 const struct spoolss_DriverInfo8 *driver,
4728 const char *servername)
4730 const char *cservername = canon_servername(servername);
4732 r->version = driver->version;
4734 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4735 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4736 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4737 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4739 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4740 driver->architecture,
4742 driver->driver_path,
4745 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4746 driver->architecture,
4751 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4752 driver->architecture,
4754 driver->config_file,
4757 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4758 driver->architecture,
4763 FILL_DRIVER_STRING(mem_ctx,
4764 driver->monitor_name,
4767 FILL_DRIVER_STRING(mem_ctx,
4768 driver->default_datatype,
4769 r->default_datatype);
4771 return string_array_from_driver_info(mem_ctx,
4772 driver->dependent_files,
4773 &r->dependent_files,
4775 driver->architecture,
4779 /********************************************************************
4780 * fill a spoolss_DriverInfo4 struct
4781 ********************************************************************/
4783 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4784 struct spoolss_DriverInfo4 *r,
4785 const struct spoolss_DriverInfo8 *driver,
4786 const char *servername)
4788 const char *cservername = canon_servername(servername);
4791 r->version = driver->version;
4793 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4794 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4795 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4796 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4798 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4799 driver->architecture,
4801 driver->driver_path,
4804 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4805 driver->architecture,
4810 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4811 driver->architecture,
4813 driver->config_file,
4816 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4817 driver->architecture,
4822 result = string_array_from_driver_info(mem_ctx,
4823 driver->dependent_files,
4824 &r->dependent_files,
4826 driver->architecture,
4828 if (!W_ERROR_IS_OK(result)) {
4832 FILL_DRIVER_STRING(mem_ctx,
4833 driver->monitor_name,
4836 FILL_DRIVER_STRING(mem_ctx,
4837 driver->default_datatype,
4838 r->default_datatype);
4841 result = string_array_from_driver_info(mem_ctx,
4842 driver->previous_names,
4849 /********************************************************************
4850 * fill a spoolss_DriverInfo5 struct
4851 ********************************************************************/
4853 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4854 struct spoolss_DriverInfo5 *r,
4855 const struct spoolss_DriverInfo8 *driver,
4856 const char *servername)
4858 const char *cservername = canon_servername(servername);
4860 r->version = driver->version;
4862 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4863 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4864 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4865 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4867 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4868 driver->architecture,
4870 driver->driver_path,
4873 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4874 driver->architecture,
4879 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4880 driver->architecture,
4882 driver->config_file,
4885 r->driver_attributes = 0;
4886 r->config_version = 0;
4887 r->driver_version = 0;
4891 /********************************************************************
4892 * fill a spoolss_DriverInfo6 struct
4893 ********************************************************************/
4895 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4896 struct spoolss_DriverInfo6 *r,
4897 const struct spoolss_DriverInfo8 *driver,
4898 const char *servername)
4900 const char *cservername = canon_servername(servername);
4903 r->version = driver->version;
4905 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4906 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4907 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4908 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4910 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4911 driver->architecture,
4913 driver->driver_path,
4916 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4917 driver->architecture,
4922 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4923 driver->architecture,
4925 driver->config_file,
4928 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4929 driver->architecture,
4934 FILL_DRIVER_STRING(mem_ctx,
4935 driver->monitor_name,
4938 FILL_DRIVER_STRING(mem_ctx,
4939 driver->default_datatype,
4940 r->default_datatype);
4942 result = string_array_from_driver_info(mem_ctx,
4943 driver->dependent_files,
4944 &r->dependent_files,
4946 driver->architecture,
4948 if (!W_ERROR_IS_OK(result)) {
4952 result = string_array_from_driver_info(mem_ctx,
4953 driver->previous_names,
4956 if (!W_ERROR_IS_OK(result)) {
4960 r->driver_date = driver->driver_date;
4961 r->driver_version = driver->driver_version;
4963 FILL_DRIVER_STRING(mem_ctx,
4964 driver->manufacturer_name,
4965 r->manufacturer_name);
4966 FILL_DRIVER_STRING(mem_ctx,
4967 driver->manufacturer_url,
4968 r->manufacturer_url);
4969 FILL_DRIVER_STRING(mem_ctx,
4970 driver->hardware_id,
4972 FILL_DRIVER_STRING(mem_ctx,
4979 /********************************************************************
4980 * fill a spoolss_DriverInfo8 struct
4981 ********************************************************************/
4983 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
4984 struct spoolss_DriverInfo8 *r,
4985 const struct spoolss_DriverInfo8 *driver,
4986 const char *servername)
4988 const char *cservername = canon_servername(servername);
4991 r->version = driver->version;
4993 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4994 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4995 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4996 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4998 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4999 driver->architecture,
5001 driver->driver_path,
5004 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5005 driver->architecture,
5010 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5011 driver->architecture,
5013 driver->config_file,
5016 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5017 driver->architecture,
5022 FILL_DRIVER_STRING(mem_ctx,
5023 driver->monitor_name,
5026 FILL_DRIVER_STRING(mem_ctx,
5027 driver->default_datatype,
5028 r->default_datatype);
5030 result = string_array_from_driver_info(mem_ctx,
5031 driver->dependent_files,
5032 &r->dependent_files,
5034 driver->architecture,
5036 if (!W_ERROR_IS_OK(result)) {
5040 result = string_array_from_driver_info(mem_ctx,
5041 driver->previous_names,
5044 if (!W_ERROR_IS_OK(result)) {
5048 r->driver_date = driver->driver_date;
5049 r->driver_version = driver->driver_version;
5051 FILL_DRIVER_STRING(mem_ctx,
5052 driver->manufacturer_name,
5053 r->manufacturer_name);
5054 FILL_DRIVER_STRING(mem_ctx,
5055 driver->manufacturer_url,
5056 r->manufacturer_url);
5057 FILL_DRIVER_STRING(mem_ctx,
5058 driver->hardware_id,
5060 FILL_DRIVER_STRING(mem_ctx,
5064 FILL_DRIVER_STRING(mem_ctx,
5065 driver->print_processor,
5066 r->print_processor);
5067 FILL_DRIVER_STRING(mem_ctx,
5068 driver->vendor_setup,
5071 result = string_array_from_driver_info(mem_ctx,
5072 driver->color_profiles,
5075 if (!W_ERROR_IS_OK(result)) {
5079 FILL_DRIVER_STRING(mem_ctx,
5083 r->printer_driver_attributes = driver->printer_driver_attributes;
5085 result = string_array_from_driver_info(mem_ctx,
5086 driver->core_driver_dependencies,
5087 &r->core_driver_dependencies,
5089 if (!W_ERROR_IS_OK(result)) {
5093 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
5094 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
5099 #if 0 /* disabled until marshalling issues are resolved - gd */
5100 /********************************************************************
5101 ********************************************************************/
5103 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5104 struct spoolss_DriverFileInfo *r,
5105 const char *cservername,
5106 const char *file_name,
5107 enum spoolss_DriverFileType file_type,
5108 uint32_t file_version)
5110 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5111 cservername, file_name);
5112 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5113 r->file_type = file_type;
5114 r->file_version = file_version;
5119 /********************************************************************
5120 ********************************************************************/
5122 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5123 const struct spoolss_DriverInfo8 *driver,
5124 const char *cservername,
5125 struct spoolss_DriverFileInfo **info_p,
5128 struct spoolss_DriverFileInfo *info = NULL;
5136 if (strlen(driver->driver_path)) {
5137 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5138 struct spoolss_DriverFileInfo,
5140 W_ERROR_HAVE_NO_MEMORY(info);
5141 result = fill_spoolss_DriverFileInfo(info,
5144 driver->driver_path,
5145 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5147 W_ERROR_NOT_OK_RETURN(result);
5151 if (strlen(driver->config_file)) {
5152 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5153 struct spoolss_DriverFileInfo,
5155 W_ERROR_HAVE_NO_MEMORY(info);
5156 result = fill_spoolss_DriverFileInfo(info,
5159 driver->config_file,
5160 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5162 W_ERROR_NOT_OK_RETURN(result);
5166 if (strlen(driver->data_file)) {
5167 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5168 struct spoolss_DriverFileInfo,
5170 W_ERROR_HAVE_NO_MEMORY(info);
5171 result = fill_spoolss_DriverFileInfo(info,
5175 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5177 W_ERROR_NOT_OK_RETURN(result);
5181 if (strlen(driver->help_file)) {
5182 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5183 struct spoolss_DriverFileInfo,
5185 W_ERROR_HAVE_NO_MEMORY(info);
5186 result = fill_spoolss_DriverFileInfo(info,
5190 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5192 W_ERROR_NOT_OK_RETURN(result);
5196 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
5197 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5198 struct spoolss_DriverFileInfo,
5200 W_ERROR_HAVE_NO_MEMORY(info);
5201 result = fill_spoolss_DriverFileInfo(info,
5204 driver->dependent_files[i],
5205 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5207 W_ERROR_NOT_OK_RETURN(result);
5217 /********************************************************************
5218 * fill a spoolss_DriverInfo101 struct
5219 ********************************************************************/
5221 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5222 struct spoolss_DriverInfo101 *r,
5223 const struct spoolss_DriverInfo8 *driver,
5224 const char *servername)
5226 const char *cservername = canon_servername(servername);
5229 r->version = driver->version;
5231 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5232 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5233 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5234 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5236 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5240 if (!W_ERROR_IS_OK(result)) {
5244 FILL_DRIVER_STRING(mem_ctx,
5245 driver->monitor_name,
5248 FILL_DRIVER_STRING(mem_ctx,
5249 driver->default_datatype,
5250 r->default_datatype);
5252 result = string_array_from_driver_info(mem_ctx,
5253 driver->previous_names,
5256 if (!W_ERROR_IS_OK(result)) {
5260 r->driver_date = driver->driver_date;
5261 r->driver_version = driver->driver_version;
5263 FILL_DRIVER_STRING(mem_ctx,
5264 driver->manufacturer_name,
5265 r->manufacturer_name);
5266 FILL_DRIVER_STRING(mem_ctx,
5267 driver->manufacturer_url,
5268 r->manufacturer_url);
5269 FILL_DRIVER_STRING(mem_ctx,
5270 driver->hardware_id,
5272 FILL_DRIVER_STRING(mem_ctx,
5279 /********************************************************************
5280 ********************************************************************/
5282 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5283 const struct auth_serversupplied_info *server_info,
5284 struct messaging_context *msg_ctx,
5286 union spoolss_DriverInfo *r,
5288 const char *servername,
5289 const char *architecture,
5292 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5293 struct spoolss_DriverInfo8 *driver;
5296 result = winreg_get_printer(mem_ctx,
5300 lp_const_servicename(snum),
5303 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5304 win_errstr(result)));
5306 if (!W_ERROR_IS_OK(result)) {
5307 return WERR_INVALID_PRINTER_NAME;
5310 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5312 pinfo2->drivername, version, &driver);
5314 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5315 win_errstr(result)));
5317 if (!W_ERROR_IS_OK(result)) {
5319 * Is this a W2k client ?
5323 talloc_free(pinfo2);
5324 return WERR_UNKNOWN_PRINTER_DRIVER;
5327 /* Yes - try again with a WinNT driver. */
5329 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5333 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5334 win_errstr(result)));
5335 if (!W_ERROR_IS_OK(result)) {
5336 talloc_free(pinfo2);
5337 return WERR_UNKNOWN_PRINTER_DRIVER;
5343 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5346 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5349 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5352 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5355 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5358 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5361 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5363 #if 0 /* disabled until marshalling issues are resolved - gd */
5365 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5369 result = WERR_UNKNOWN_LEVEL;
5373 talloc_free(pinfo2);
5374 talloc_free(driver);
5379 /****************************************************************
5380 _spoolss_GetPrinterDriver2
5381 ****************************************************************/
5383 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5384 struct spoolss_GetPrinterDriver2 *r)
5386 struct printer_handle *printer;
5391 /* that's an [in out] buffer */
5393 if (!r->in.buffer && (r->in.offered != 0)) {
5394 return WERR_INVALID_PARAM;
5397 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5399 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5400 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5401 return WERR_INVALID_PRINTER_NAME;
5405 *r->out.server_major_version = 0;
5406 *r->out.server_minor_version = 0;
5408 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5412 result = construct_printer_driver_info_level(p->mem_ctx,
5413 get_server_info_system(),
5415 r->in.level, r->out.info,
5416 snum, printer->servername,
5418 r->in.client_major_version);
5419 if (!W_ERROR_IS_OK(result)) {
5420 TALLOC_FREE(r->out.info);
5424 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5425 r->out.info, r->in.level);
5426 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5428 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5432 /****************************************************************
5433 _spoolss_StartPagePrinter
5434 ****************************************************************/
5436 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5437 struct spoolss_StartPagePrinter *r)
5439 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5442 DEBUG(3,("_spoolss_StartPagePrinter: "
5443 "Error in startpageprinter printer handle\n"));
5447 Printer->page_started = true;
5451 /****************************************************************
5452 _spoolss_EndPagePrinter
5453 ****************************************************************/
5455 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5456 struct spoolss_EndPagePrinter *r)
5460 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5463 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5464 OUR_HANDLE(r->in.handle)));
5468 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5471 Printer->page_started = false;
5472 print_job_endpage(p->msg_ctx, snum, Printer->jobid);
5477 /****************************************************************
5478 _spoolss_StartDocPrinter
5479 ****************************************************************/
5481 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5482 struct spoolss_StartDocPrinter *r)
5484 struct spoolss_DocumentInfo1 *info_1;
5486 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5490 DEBUG(2,("_spoolss_StartDocPrinter: "
5491 "Invalid handle (%s:%u:%u)\n",
5492 OUR_HANDLE(r->in.handle)));
5496 if (Printer->jobid) {
5497 DEBUG(2, ("_spoolss_StartDocPrinter: "
5498 "StartDocPrinter called twice! "
5499 "(existing jobid = %d)\n", Printer->jobid));
5500 return WERR_INVALID_HANDLE;
5503 if (r->in.level != 1) {
5504 return WERR_UNKNOWN_LEVEL;
5507 info_1 = r->in.info.info1;
5510 * a nice thing with NT is it doesn't listen to what you tell it.
5511 * when asked to send _only_ RAW datas, it tries to send datas
5514 * So I add checks like in NT Server ...
5517 if (info_1->datatype) {
5518 if (strcmp(info_1->datatype, "RAW") != 0) {
5520 return WERR_INVALID_DATATYPE;
5524 /* get the share number of the printer */
5525 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5529 werr = print_job_start(get_server_info_system(),
5533 info_1->document_name,
5534 info_1->output_file,
5538 /* An error occured in print_job_start() so return an appropriate
5541 if (!W_ERROR_IS_OK(werr)) {
5545 Printer->document_started = true;
5546 *r->out.job_id = Printer->jobid;
5551 /****************************************************************
5552 _spoolss_EndDocPrinter
5553 ****************************************************************/
5555 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5556 struct spoolss_EndDocPrinter *r)
5558 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5563 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5564 OUR_HANDLE(r->in.handle)));
5568 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5572 Printer->document_started = false;
5573 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5574 if (!NT_STATUS_IS_OK(status)) {
5575 DEBUG(2, ("_spoolss_EndDocPrinter: "
5576 "print_job_end failed [%s]\n",
5577 nt_errstr(status)));
5581 return ntstatus_to_werror(status);
5584 /****************************************************************
5585 _spoolss_WritePrinter
5586 ****************************************************************/
5588 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5589 struct spoolss_WritePrinter *r)
5591 ssize_t buffer_written;
5593 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5596 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5597 OUR_HANDLE(r->in.handle)));
5598 *r->out.num_written = r->in._data_size;
5602 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5605 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5606 buffer_written = print_job_write(server_event_context(),p->msg_ctx,
5607 snum, Printer->jobid,
5608 (const char *)r->in.data.data,
5609 (size_t)r->in._data_size);
5610 if (buffer_written == (ssize_t)-1) {
5611 *r->out.num_written = 0;
5612 if (errno == ENOSPC)
5613 return WERR_NO_SPOOL_SPACE;
5615 return WERR_ACCESS_DENIED;
5618 *r->out.num_written = r->in._data_size;
5623 /********************************************************************
5624 * api_spoolss_getprinter
5625 * called from the spoolss dispatcher
5627 ********************************************************************/
5629 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5630 struct pipes_struct *p)
5632 const struct auth_serversupplied_info *server_info = get_server_info_system();
5634 WERROR errcode = WERR_BADFUNC;
5635 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5638 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5639 OUR_HANDLE(handle)));
5643 if (!get_printer_snum(p, handle, &snum, NULL))
5647 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5648 errcode = print_queue_pause(server_info, p->msg_ctx, snum);
5650 case SPOOLSS_PRINTER_CONTROL_RESUME:
5651 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5652 errcode = print_queue_resume(server_info, p->msg_ctx, snum);
5654 case SPOOLSS_PRINTER_CONTROL_PURGE:
5655 errcode = print_queue_purge(server_info, p->msg_ctx, snum);
5658 return WERR_UNKNOWN_LEVEL;
5665 /****************************************************************
5666 _spoolss_AbortPrinter
5667 * From MSDN: "Deletes printer's spool file if printer is configured
5669 ****************************************************************/
5671 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5672 struct spoolss_AbortPrinter *r)
5674 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5676 WERROR errcode = WERR_OK;
5679 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5680 OUR_HANDLE(r->in.handle)));
5684 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5687 if (!Printer->document_started) {
5688 return WERR_SPL_NO_STARTDOC;
5691 errcode = print_job_delete(get_server_info_system(),
5699 /********************************************************************
5700 * called by spoolss_api_setprinter
5701 * when updating a printer description
5702 ********************************************************************/
5704 static WERROR update_printer_sec(struct policy_handle *handle,
5705 struct pipes_struct *p,
5706 struct sec_desc_buf *secdesc_ctr)
5708 struct spoolss_security_descriptor *new_secdesc = NULL;
5709 struct spoolss_security_descriptor *old_secdesc = NULL;
5710 const char *printer;
5714 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5716 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5717 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5718 OUR_HANDLE(handle)));
5720 result = WERR_BADFID;
5724 if (secdesc_ctr == NULL) {
5725 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5726 result = WERR_INVALID_PARAM;
5729 printer = lp_const_servicename(snum);
5731 /* Check the user has permissions to change the security
5732 descriptor. By experimentation with two NT machines, the user
5733 requires Full Access to the printer to change security
5736 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5737 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5738 result = WERR_ACCESS_DENIED;
5742 /* NT seems to like setting the security descriptor even though
5743 nothing may have actually changed. */
5744 result = winreg_get_printer_secdesc(p->mem_ctx,
5745 get_server_info_system(),
5749 if (!W_ERROR_IS_OK(result)) {
5750 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5751 result = WERR_BADFID;
5755 if (DEBUGLEVEL >= 10) {
5756 struct security_acl *the_acl;
5759 the_acl = old_secdesc->dacl;
5760 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5761 printer, the_acl->num_aces));
5763 for (i = 0; i < the_acl->num_aces; i++) {
5764 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5765 &the_acl->aces[i].trustee),
5766 the_acl->aces[i].access_mask));
5769 the_acl = secdesc_ctr->sd->dacl;
5772 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5773 printer, the_acl->num_aces));
5775 for (i = 0; i < the_acl->num_aces; i++) {
5776 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5777 &the_acl->aces[i].trustee),
5778 the_acl->aces[i].access_mask));
5781 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5785 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
5786 if (new_secdesc == NULL) {
5787 result = WERR_NOMEM;
5791 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
5796 result = winreg_set_printer_secdesc(p->mem_ctx,
5797 get_server_info_system(),
5806 /********************************************************************
5807 Canonicalize printer info from a client
5808 ********************************************************************/
5810 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
5811 struct spoolss_SetPrinterInfo2 *info2,
5814 fstring printername;
5817 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5818 "portname=%s drivername=%s comment=%s location=%s\n",
5819 info2->servername, info2->printername, info2->sharename,
5820 info2->portname, info2->drivername, info2->comment,
5823 /* we force some elements to "correct" values */
5824 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
5825 if (info2->servername == NULL) {
5828 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
5829 if (info2->sharename == NULL) {
5833 /* check to see if we allow printername != sharename */
5834 if (lp_force_printername(snum)) {
5835 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5836 global_myname(), info2->sharename);
5838 /* make sure printername is in \\server\printername format */
5839 fstrcpy(printername, info2->printername);
5841 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5842 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5846 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5847 global_myname(), p);
5849 if (info2->printername == NULL) {
5853 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5854 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5859 /****************************************************************************
5860 ****************************************************************************/
5862 static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri)
5864 char *cmd = lp_addport_cmd();
5865 char *command = NULL;
5867 uint64_t se_printop = SE_PRINT_OPERATOR;
5868 bool is_print_op = false;
5871 return WERR_ACCESS_DENIED;
5874 command = talloc_asprintf(ctx,
5875 "%s \"%s\" \"%s\"", cmd, portname, uri );
5881 is_print_op = user_has_privileges( token, &se_printop );
5883 DEBUG(10,("Running [%s]\n", command));
5885 /********* BEGIN SePrintOperatorPrivilege **********/
5890 ret = smbrun(command, NULL);
5895 /********* END SePrintOperatorPrivilege **********/
5897 DEBUGADD(10,("returned [%d]\n", ret));
5899 TALLOC_FREE(command);
5902 return WERR_ACCESS_DENIED;
5908 /****************************************************************************
5909 ****************************************************************************/
5911 static bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
5912 struct spoolss_SetPrinterInfo2 *info2,
5913 const char *remote_machine,
5914 struct messaging_context *msg_ctx)
5916 char *cmd = lp_addprinter_cmd();
5918 char *command = NULL;
5922 uint64_t se_printop = SE_PRINT_OPERATOR;
5923 bool is_print_op = false;
5925 if (!remote_machine) {
5929 command = talloc_asprintf(ctx,
5930 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5931 cmd, info2->printername, info2->sharename,
5932 info2->portname, info2->drivername,
5933 info2->location, info2->comment, remote_machine);
5939 is_print_op = user_has_privileges( token, &se_printop );
5941 DEBUG(10,("Running [%s]\n", command));
5943 /********* BEGIN SePrintOperatorPrivilege **********/
5948 if ( (ret = smbrun(command, &fd)) == 0 ) {
5949 /* Tell everyone we updated smb.conf. */
5950 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5956 /********* END SePrintOperatorPrivilege **********/
5958 DEBUGADD(10,("returned [%d]\n", ret));
5960 TALLOC_FREE(command);
5968 /* reload our services immediately */
5970 reload_services(msg_ctx, -1, false);
5974 /* Get lines and convert them back to dos-codepage */
5975 qlines = fd_lines_load(fd, &numlines, 0, NULL);
5976 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
5979 /* Set the portname to what the script says the portname should be. */
5980 /* but don't require anything to be return from the script exit a good error code */
5983 /* Set the portname to what the script says the portname should be. */
5984 info2->portname = talloc_strdup(ctx, qlines[0]);
5985 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
5988 TALLOC_FREE(qlines);
5992 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
5993 const struct auth_serversupplied_info *server_info,
5994 struct messaging_context *msg_ctx,
5996 struct spoolss_SetPrinterInfo2 *printer,
5997 struct spoolss_PrinterInfo2 *old_printer)
5999 bool force_update = (old_printer == NULL);
6000 const char *dnsdomname;
6001 const char *longname;
6002 const char *uncname;
6003 const char *spooling;
6005 WERROR result = WERR_OK;
6007 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
6008 push_reg_sz(mem_ctx, &buffer, printer->drivername);
6009 winreg_set_printer_dataex(mem_ctx,
6013 SPOOL_DSSPOOLER_KEY,
6014 SPOOL_REG_DRIVERNAME,
6019 if (!force_update) {
6020 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6021 printer->drivername));
6023 notify_printer_driver(server_event_context(), msg_ctx,
6024 snum, printer->drivername);
6028 if (force_update || !strequal(printer->comment, old_printer->comment)) {
6029 push_reg_sz(mem_ctx, &buffer, printer->comment);
6030 winreg_set_printer_dataex(mem_ctx,
6034 SPOOL_DSSPOOLER_KEY,
6035 SPOOL_REG_DESCRIPTION,
6040 if (!force_update) {
6041 notify_printer_comment(server_event_context(), msg_ctx,
6042 snum, printer->comment);
6046 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
6047 push_reg_sz(mem_ctx, &buffer, printer->sharename);
6048 winreg_set_printer_dataex(mem_ctx,
6052 SPOOL_DSSPOOLER_KEY,
6053 SPOOL_REG_PRINTSHARENAME,
6058 if (!force_update) {
6059 notify_printer_sharename(server_event_context(),
6061 snum, printer->sharename);
6065 if (force_update || !strequal(printer->printername, old_printer->printername)) {
6068 p = strrchr(printer->printername, '\\' );
6072 p = printer->printername;
6075 push_reg_sz(mem_ctx, &buffer, p);
6076 winreg_set_printer_dataex(mem_ctx,
6080 SPOOL_DSSPOOLER_KEY,
6081 SPOOL_REG_PRINTERNAME,
6086 if (!force_update) {
6087 notify_printer_printername(server_event_context(),
6092 if (force_update || !strequal(printer->portname, old_printer->portname)) {
6093 push_reg_sz(mem_ctx, &buffer, printer->portname);
6094 winreg_set_printer_dataex(mem_ctx,
6098 SPOOL_DSSPOOLER_KEY,
6104 if (!force_update) {
6105 notify_printer_port(server_event_context(),
6106 msg_ctx, snum, printer->portname);
6110 if (force_update || !strequal(printer->location, old_printer->location)) {
6111 push_reg_sz(mem_ctx, &buffer, printer->location);
6112 winreg_set_printer_dataex(mem_ctx,
6116 SPOOL_DSSPOOLER_KEY,
6122 if (!force_update) {
6123 notify_printer_location(server_event_context(),
6129 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
6130 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
6131 winreg_set_printer_dataex(mem_ctx,
6135 SPOOL_DSSPOOLER_KEY,
6136 SPOOL_REG_PRINTSEPARATORFILE,
6141 if (!force_update) {
6142 notify_printer_location(server_event_context(),
6148 if (force_update || printer->starttime != old_printer->starttime) {
6149 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6150 SIVAL(buffer.data, 0, printer->starttime);
6151 winreg_set_printer_dataex(mem_ctx,
6155 SPOOL_DSSPOOLER_KEY,
6156 SPOOL_REG_PRINTSTARTTIME,
6162 if (force_update || printer->untiltime != old_printer->untiltime) {
6163 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6164 SIVAL(buffer.data, 0, printer->untiltime);
6165 winreg_set_printer_dataex(mem_ctx,
6169 SPOOL_DSSPOOLER_KEY,
6170 SPOOL_REG_PRINTENDTIME,
6176 if (force_update || printer->priority != old_printer->priority) {
6177 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6178 SIVAL(buffer.data, 0, printer->priority);
6179 winreg_set_printer_dataex(mem_ctx,
6183 SPOOL_DSSPOOLER_KEY,
6190 if (force_update || printer->attributes != old_printer->attributes) {
6191 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6192 SIVAL(buffer.data, 0, (printer->attributes &
6193 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
6194 winreg_set_printer_dataex(mem_ctx,
6198 SPOOL_DSSPOOLER_KEY,
6199 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
6204 switch (printer->attributes & 0x3) {
6206 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
6209 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
6212 spooling = SPOOL_REGVAL_PRINTDIRECT;
6215 spooling = "unknown";
6217 push_reg_sz(mem_ctx, &buffer, spooling);
6218 winreg_set_printer_dataex(mem_ctx,
6222 SPOOL_DSSPOOLER_KEY,
6223 SPOOL_REG_PRINTSPOOLING,
6229 push_reg_sz(mem_ctx, &buffer, global_myname());
6230 winreg_set_printer_dataex(mem_ctx,
6234 SPOOL_DSSPOOLER_KEY,
6235 SPOOL_REG_SHORTSERVERNAME,
6240 dnsdomname = get_mydnsfullname();
6241 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
6242 longname = talloc_strdup(mem_ctx, dnsdomname);
6244 longname = talloc_strdup(mem_ctx, global_myname());
6246 if (longname == NULL) {
6247 result = WERR_NOMEM;
6251 push_reg_sz(mem_ctx, &buffer, longname);
6252 winreg_set_printer_dataex(mem_ctx,
6256 SPOOL_DSSPOOLER_KEY,
6257 SPOOL_REG_SERVERNAME,
6262 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6263 global_myname(), printer->sharename);
6264 push_reg_sz(mem_ctx, &buffer, uncname);
6265 winreg_set_printer_dataex(mem_ctx,
6269 SPOOL_DSSPOOLER_KEY,
6279 /********************************************************************
6280 * Called by spoolss_api_setprinter
6281 * when updating a printer description.
6282 ********************************************************************/
6284 static WERROR update_printer(struct pipes_struct *p,
6285 struct policy_handle *handle,
6286 struct spoolss_SetPrinterInfoCtr *info_ctr,
6287 struct spoolss_DeviceMode *devmode)
6289 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6290 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6291 struct spoolss_PrinterInfo2 *old_printer;
6292 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6293 const char *servername = NULL;
6295 WERROR result = WERR_OK;
6296 TALLOC_CTX *tmp_ctx;
6298 DEBUG(8,("update_printer\n"));
6300 tmp_ctx = talloc_new(p->mem_ctx);
6301 if (tmp_ctx == NULL) {
6306 result = WERR_BADFID;
6310 if (!get_printer_snum(p, handle, &snum, NULL)) {
6311 result = WERR_BADFID;
6315 if (Printer != NULL || Printer->servername != NULL) {
6316 servername = Printer->servername;
6319 result = winreg_get_printer(tmp_ctx,
6320 get_server_info_system(),
6323 lp_const_servicename(snum),
6325 if (!W_ERROR_IS_OK(result)) {
6326 result = WERR_BADFID;
6330 /* Do sanity check on the requested changes for Samba */
6331 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6332 result = WERR_INVALID_PARAM;
6336 /* FIXME!!! If the driver has changed we really should verify that
6337 it is installed before doing much else --jerry */
6339 /* Check calling user has permission to update printer description */
6340 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6341 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6342 result = WERR_ACCESS_DENIED;
6346 /* Call addprinter hook */
6347 /* Check changes to see if this is really needed */
6349 if (*lp_addprinter_cmd() &&
6350 (!strequal(printer->drivername, old_printer->drivername) ||
6351 !strequal(printer->comment, old_printer->comment) ||
6352 !strequal(printer->portname, old_printer->portname) ||
6353 !strequal(printer->location, old_printer->location)) )
6355 /* add_printer_hook() will call reload_services() */
6356 if (!add_printer_hook(tmp_ctx, p->server_info->ptok,
6357 printer, p->client_id->addr,
6359 result = WERR_ACCESS_DENIED;
6364 update_dsspooler(tmp_ctx,
6365 get_server_info_system(),
6371 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6373 if (devmode == NULL) {
6374 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6376 result = winreg_update_printer(tmp_ctx,
6377 get_server_info_system(),
6386 talloc_free(tmp_ctx);
6391 /****************************************************************************
6392 ****************************************************************************/
6393 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6394 struct policy_handle *handle,
6395 struct spoolss_SetPrinterInfo7 *info7)
6398 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6401 struct printer_handle *Printer;
6403 if ( lp_security() != SEC_ADS ) {
6404 return WERR_UNKNOWN_LEVEL;
6407 Printer = find_printer_index_by_hnd(p, handle);
6409 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6414 if (!get_printer_snum(p, handle, &snum, NULL))
6417 result = winreg_get_printer(p->mem_ctx,
6418 get_server_info_system(),
6420 Printer->servername,
6421 lp_servicename(snum),
6423 if (!W_ERROR_IS_OK(result)) {
6427 nt_printer_publish(pinfo2,
6428 get_server_info_system(),
6433 TALLOC_FREE(pinfo2);
6436 return WERR_UNKNOWN_LEVEL;
6440 /********************************************************************
6441 ********************************************************************/
6443 static WERROR update_printer_devmode(struct pipes_struct *p,
6444 struct policy_handle *handle,
6445 struct spoolss_DeviceMode *devmode)
6448 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6449 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6451 DEBUG(8,("update_printer_devmode\n"));
6457 if (!get_printer_snum(p, handle, &snum, NULL)) {
6461 /* Check calling user has permission to update printer description */
6462 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6463 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6464 return WERR_ACCESS_DENIED;
6467 return winreg_update_printer(p->mem_ctx,
6468 get_server_info_system(),
6470 lp_const_servicename(snum),
6478 /****************************************************************
6480 ****************************************************************/
6482 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6483 struct spoolss_SetPrinter *r)
6487 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6490 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6491 OUR_HANDLE(r->in.handle)));
6495 /* check the level */
6496 switch (r->in.info_ctr->level) {
6498 return control_printer(r->in.handle, r->in.command, p);
6500 result = update_printer(p, r->in.handle,
6502 r->in.devmode_ctr->devmode);
6503 if (!W_ERROR_IS_OK(result))
6505 if (r->in.secdesc_ctr->sd)
6506 result = update_printer_sec(r->in.handle, p,
6510 return update_printer_sec(r->in.handle, p,
6513 return publish_or_unpublish_printer(p, r->in.handle,
6514 r->in.info_ctr->info.info7);
6516 return update_printer_devmode(p, r->in.handle,
6517 r->in.devmode_ctr->devmode);
6519 return WERR_UNKNOWN_LEVEL;
6523 /****************************************************************
6524 _spoolss_FindClosePrinterNotify
6525 ****************************************************************/
6527 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6528 struct spoolss_FindClosePrinterNotify *r)
6530 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6533 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6534 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6538 if (Printer->notify.cli_chan != NULL &&
6539 Printer->notify.cli_chan->active_connections > 0) {
6542 if (Printer->printer_type == SPLHND_PRINTER) {
6543 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6548 srv_spoolss_replycloseprinter(snum, Printer);
6551 Printer->notify.flags=0;
6552 Printer->notify.options=0;
6553 Printer->notify.localmachine[0]='\0';
6554 Printer->notify.printerlocal=0;
6555 TALLOC_FREE(Printer->notify.option);
6560 /****************************************************************
6562 ****************************************************************/
6564 WERROR _spoolss_AddJob(struct pipes_struct *p,
6565 struct spoolss_AddJob *r)
6567 if (!r->in.buffer && (r->in.offered != 0)) {
6568 return WERR_INVALID_PARAM;
6571 /* this is what a NT server returns for AddJob. AddJob must fail on
6572 * non-local printers */
6574 if (r->in.level != 1) {
6575 return WERR_UNKNOWN_LEVEL;
6578 return WERR_INVALID_PARAM;
6581 /****************************************************************************
6583 ****************************************************************************/
6585 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6586 struct spoolss_JobInfo1 *r,
6587 const print_queue_struct *queue,
6588 int position, int snum,
6589 struct spoolss_PrinterInfo2 *pinfo2)
6593 t = gmtime(&queue->time);
6595 r->job_id = queue->job;
6597 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6598 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6599 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6600 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6601 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6602 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6603 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6604 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6605 r->data_type = talloc_strdup(mem_ctx, "RAW");
6606 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6607 r->text_status = talloc_strdup(mem_ctx, "");
6608 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6610 r->status = nt_printj_status(queue->status);
6611 r->priority = queue->priority;
6612 r->position = position;
6613 r->total_pages = queue->page_count;
6614 r->pages_printed = 0; /* ??? */
6616 init_systemtime(&r->submitted, t);
6621 /****************************************************************************
6623 ****************************************************************************/
6625 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6626 struct spoolss_JobInfo2 *r,
6627 const print_queue_struct *queue,
6628 int position, int snum,
6629 struct spoolss_PrinterInfo2 *pinfo2,
6630 struct spoolss_DeviceMode *devmode)
6634 t = gmtime(&queue->time);
6636 r->job_id = queue->job;
6638 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6639 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6640 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6641 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6642 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6643 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6644 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6645 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6646 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6647 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6648 r->data_type = talloc_strdup(mem_ctx, "RAW");
6649 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6650 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6651 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6652 r->parameters = talloc_strdup(mem_ctx, "");
6653 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6654 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6655 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6657 r->devmode = devmode;
6659 r->text_status = talloc_strdup(mem_ctx, "");
6660 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6664 r->status = nt_printj_status(queue->status);
6665 r->priority = queue->priority;
6666 r->position = position;
6669 r->total_pages = queue->page_count;
6670 r->size = queue->size;
6671 init_systemtime(&r->submitted, t);
6673 r->pages_printed = 0; /* ??? */
6678 /****************************************************************************
6680 ****************************************************************************/
6682 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6683 struct spoolss_JobInfo3 *r,
6684 const print_queue_struct *queue,
6685 const print_queue_struct *next_queue,
6686 int position, int snum,
6687 struct spoolss_PrinterInfo2 *pinfo2)
6689 r->job_id = queue->job;
6692 r->next_job_id = next_queue->job;
6699 /****************************************************************************
6700 Enumjobs at level 1.
6701 ****************************************************************************/
6703 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6704 const print_queue_struct *queue,
6705 uint32_t num_queues, int snum,
6706 struct spoolss_PrinterInfo2 *pinfo2,
6707 union spoolss_JobInfo **info_p,
6710 union spoolss_JobInfo *info;
6712 WERROR result = WERR_OK;
6714 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6715 W_ERROR_HAVE_NO_MEMORY(info);
6717 *count = num_queues;
6719 for (i=0; i<*count; i++) {
6720 result = fill_job_info1(info,
6726 if (!W_ERROR_IS_OK(result)) {
6732 if (!W_ERROR_IS_OK(result)) {
6743 /****************************************************************************
6744 Enumjobs at level 2.
6745 ****************************************************************************/
6747 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6748 const print_queue_struct *queue,
6749 uint32_t num_queues, int snum,
6750 struct spoolss_PrinterInfo2 *pinfo2,
6751 union spoolss_JobInfo **info_p,
6754 union spoolss_JobInfo *info;
6756 WERROR result = WERR_OK;
6758 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6759 W_ERROR_HAVE_NO_MEMORY(info);
6761 *count = num_queues;
6763 for (i=0; i<*count; i++) {
6764 struct spoolss_DeviceMode *devmode;
6766 result = spoolss_create_default_devmode(info,
6767 pinfo2->printername,
6769 if (!W_ERROR_IS_OK(result)) {
6770 DEBUG(3, ("Can't proceed w/o a devmode!"));
6774 result = fill_job_info2(info,
6781 if (!W_ERROR_IS_OK(result)) {
6787 if (!W_ERROR_IS_OK(result)) {
6798 /****************************************************************************
6799 Enumjobs at level 3.
6800 ****************************************************************************/
6802 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6803 const print_queue_struct *queue,
6804 uint32_t num_queues, int snum,
6805 struct spoolss_PrinterInfo2 *pinfo2,
6806 union spoolss_JobInfo **info_p,
6809 union spoolss_JobInfo *info;
6811 WERROR result = WERR_OK;
6813 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6814 W_ERROR_HAVE_NO_MEMORY(info);
6816 *count = num_queues;
6818 for (i=0; i<*count; i++) {
6819 const print_queue_struct *next_queue = NULL;
6822 next_queue = &queue[i+1];
6825 result = fill_job_info3(info,
6832 if (!W_ERROR_IS_OK(result)) {
6838 if (!W_ERROR_IS_OK(result)) {
6849 /****************************************************************
6851 ****************************************************************/
6853 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
6854 struct spoolss_EnumJobs *r)
6857 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6859 print_status_struct prt_status;
6860 print_queue_struct *queue = NULL;
6863 /* that's an [in out] buffer */
6865 if (!r->in.buffer && (r->in.offered != 0)) {
6866 return WERR_INVALID_PARAM;
6869 DEBUG(4,("_spoolss_EnumJobs\n"));
6873 *r->out.info = NULL;
6875 /* lookup the printer snum and tdb entry */
6877 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6881 result = winreg_get_printer(p->mem_ctx,
6882 get_server_info_system(),
6885 lp_const_servicename(snum),
6887 if (!W_ERROR_IS_OK(result)) {
6891 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
6892 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6893 count, prt_status.status, prt_status.message));
6897 TALLOC_FREE(pinfo2);
6901 switch (r->in.level) {
6903 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6904 pinfo2, r->out.info, r->out.count);
6907 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6908 pinfo2, r->out.info, r->out.count);
6911 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
6912 pinfo2, r->out.info, r->out.count);
6915 result = WERR_UNKNOWN_LEVEL;
6920 TALLOC_FREE(pinfo2);
6922 if (!W_ERROR_IS_OK(result)) {
6926 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6928 *r->out.info, r->in.level,
6930 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6931 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6933 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6936 /****************************************************************
6937 _spoolss_ScheduleJob
6938 ****************************************************************/
6940 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
6941 struct spoolss_ScheduleJob *r)
6946 /****************************************************************
6947 ****************************************************************/
6949 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
6950 struct messaging_context *msg_ctx,
6951 const char *printer_name,
6953 struct spoolss_SetJobInfo1 *r)
6957 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
6961 if (strequal(old_doc_name, r->document_name)) {
6965 if (!print_job_set_name(server_event_context(), msg_ctx,
6966 printer_name, job_id, r->document_name)) {
6973 /****************************************************************
6975 ****************************************************************/
6977 WERROR _spoolss_SetJob(struct pipes_struct *p,
6978 struct spoolss_SetJob *r)
6980 const struct auth_serversupplied_info *server_info = get_server_info_system();
6982 WERROR errcode = WERR_BADFUNC;
6984 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6988 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6989 return WERR_INVALID_PRINTER_NAME;
6992 switch (r->in.command) {
6993 case SPOOLSS_JOB_CONTROL_CANCEL:
6994 case SPOOLSS_JOB_CONTROL_DELETE:
6995 errcode = print_job_delete(server_info, p->msg_ctx,
6996 snum, r->in.job_id);
6997 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
7001 case SPOOLSS_JOB_CONTROL_PAUSE:
7002 if (print_job_pause(server_info, p->msg_ctx,
7003 snum, r->in.job_id, &errcode)) {
7007 case SPOOLSS_JOB_CONTROL_RESTART:
7008 case SPOOLSS_JOB_CONTROL_RESUME:
7009 if (print_job_resume(server_info, p->msg_ctx,
7010 snum, r->in.job_id, &errcode)) {
7018 return WERR_UNKNOWN_LEVEL;
7021 if (!W_ERROR_IS_OK(errcode)) {
7025 if (r->in.ctr == NULL) {
7029 switch (r->in.ctr->level) {
7031 errcode = spoolss_setjob_1(p->mem_ctx, p->msg_ctx,
7032 lp_const_servicename(snum),
7034 r->in.ctr->info.info1);
7040 return WERR_UNKNOWN_LEVEL;
7046 /****************************************************************************
7047 Enumerates all printer drivers by level and architecture.
7048 ****************************************************************************/
7050 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
7051 const struct auth_serversupplied_info *server_info,
7052 struct messaging_context *msg_ctx,
7053 const char *servername,
7054 const char *architecture,
7056 union spoolss_DriverInfo **info_p,
7061 struct spoolss_DriverInfo8 *driver;
7062 union spoolss_DriverInfo *info = NULL;
7064 WERROR result = WERR_OK;
7065 uint32_t num_drivers;
7066 const char **drivers;
7071 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7072 result = winreg_get_driver_list(mem_ctx, server_info, msg_ctx,
7073 architecture, version,
7074 &num_drivers, &drivers);
7075 if (!W_ERROR_IS_OK(result)) {
7078 DEBUG(4, ("we have:[%d] drivers in environment"
7079 " [%s] and version [%d]\n",
7080 num_drivers, architecture, version));
7082 if (num_drivers != 0) {
7083 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
7084 union spoolss_DriverInfo,
7085 count + num_drivers);
7087 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7088 "failed to enlarge driver info buffer!\n"));
7089 result = WERR_NOMEM;
7094 for (i = 0; i < num_drivers; i++) {
7095 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
7097 result = winreg_get_driver(mem_ctx, server_info,
7099 architecture, drivers[i],
7101 if (!W_ERROR_IS_OK(result)) {
7107 result = fill_printer_driver_info1(info, &info[count+i].info1,
7108 driver, servername);
7111 result = fill_printer_driver_info2(info, &info[count+i].info2,
7112 driver, servername);
7115 result = fill_printer_driver_info3(info, &info[count+i].info3,
7116 driver, servername);
7119 result = fill_printer_driver_info4(info, &info[count+i].info4,
7120 driver, servername);
7123 result = fill_printer_driver_info5(info, &info[count+i].info5,
7124 driver, servername);
7127 result = fill_printer_driver_info6(info, &info[count+i].info6,
7128 driver, servername);
7131 result = fill_printer_driver_info8(info, &info[count+i].info8,
7132 driver, servername);
7135 result = WERR_UNKNOWN_LEVEL;
7139 TALLOC_FREE(driver);
7141 if (!W_ERROR_IS_OK(result)) {
7146 count += num_drivers;
7147 TALLOC_FREE(drivers);
7151 TALLOC_FREE(drivers);
7153 if (!W_ERROR_IS_OK(result)) {
7164 /****************************************************************************
7165 Enumerates all printer drivers by level.
7166 ****************************************************************************/
7168 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
7169 const struct auth_serversupplied_info *server_info,
7170 struct messaging_context *msg_ctx,
7171 const char *servername,
7172 const char *architecture,
7174 union spoolss_DriverInfo **info_p,
7178 WERROR result = WERR_OK;
7180 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
7182 for (a=0; archi_table[a].long_archi != NULL; a++) {
7184 union spoolss_DriverInfo *info = NULL;
7187 result = enumprinterdrivers_level_by_architecture(mem_ctx,
7191 archi_table[a].long_archi,
7195 if (!W_ERROR_IS_OK(result)) {
7199 for (i=0; i < count; i++) {
7200 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
7201 info[i], info_p, count_p);
7208 return enumprinterdrivers_level_by_architecture(mem_ctx,
7218 /****************************************************************
7219 _spoolss_EnumPrinterDrivers
7220 ****************************************************************/
7222 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
7223 struct spoolss_EnumPrinterDrivers *r)
7225 const char *cservername;
7228 /* that's an [in out] buffer */
7230 if (!r->in.buffer && (r->in.offered != 0)) {
7231 return WERR_INVALID_PARAM;
7234 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7238 *r->out.info = NULL;
7240 cservername = canon_servername(r->in.server);
7242 if (!is_myname_or_ipaddr(cservername)) {
7243 return WERR_UNKNOWN_PRINTER_DRIVER;
7246 result = enumprinterdrivers_level(p->mem_ctx,
7247 get_server_info_system(),
7254 if (!W_ERROR_IS_OK(result)) {
7258 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7259 spoolss_EnumPrinterDrivers,
7260 *r->out.info, r->in.level,
7262 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7263 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7265 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7268 /****************************************************************
7270 ****************************************************************/
7272 WERROR _spoolss_EnumForms(struct pipes_struct *p,
7273 struct spoolss_EnumForms *r)
7279 *r->out.info = NULL;
7281 /* that's an [in out] buffer */
7283 if (!r->in.buffer && (r->in.offered != 0) ) {
7284 return WERR_INVALID_PARAM;
7287 DEBUG(4,("_spoolss_EnumForms\n"));
7288 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7289 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7291 switch (r->in.level) {
7293 result = winreg_printer_enumforms1(p->mem_ctx,
7294 get_server_info_system(),
7300 result = WERR_UNKNOWN_LEVEL;
7304 if (!W_ERROR_IS_OK(result)) {
7308 if (*r->out.count == 0) {
7309 return WERR_NO_MORE_ITEMS;
7312 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7314 *r->out.info, r->in.level,
7316 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7317 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7319 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7322 /****************************************************************
7324 ****************************************************************/
7326 WERROR _spoolss_GetForm(struct pipes_struct *p,
7327 struct spoolss_GetForm *r)
7331 /* that's an [in out] buffer */
7333 if (!r->in.buffer && (r->in.offered != 0)) {
7334 return WERR_INVALID_PARAM;
7337 DEBUG(4,("_spoolss_GetForm\n"));
7338 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7339 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7341 switch (r->in.level) {
7343 result = winreg_printer_getform1(p->mem_ctx,
7344 get_server_info_system(),
7347 &r->out.info->info1);
7350 result = WERR_UNKNOWN_LEVEL;
7354 if (!W_ERROR_IS_OK(result)) {
7355 TALLOC_FREE(r->out.info);
7359 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7360 r->out.info, r->in.level);
7361 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7363 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7366 /****************************************************************************
7367 ****************************************************************************/
7369 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7370 struct spoolss_PortInfo1 *r,
7373 r->port_name = talloc_strdup(mem_ctx, name);
7374 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7379 /****************************************************************************
7380 TODO: This probably needs distinguish between TCP/IP and Local ports
7382 ****************************************************************************/
7384 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7385 struct spoolss_PortInfo2 *r,
7388 r->port_name = talloc_strdup(mem_ctx, name);
7389 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7391 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7392 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7394 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7395 W_ERROR_HAVE_NO_MEMORY(r->description);
7397 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7404 /****************************************************************************
7405 wrapper around the enumer ports command
7406 ****************************************************************************/
7408 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7410 char *cmd = lp_enumports_cmd();
7411 char **qlines = NULL;
7412 char *command = NULL;
7420 /* if no hook then just fill in the default port */
7423 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7426 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7427 TALLOC_FREE(qlines);
7434 /* we have a valid enumport command */
7436 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7441 DEBUG(10,("Running [%s]\n", command));
7442 ret = smbrun(command, &fd);
7443 DEBUG(10,("Returned [%d]\n", ret));
7444 TALLOC_FREE(command);
7449 return WERR_ACCESS_DENIED;
7453 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7454 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7464 /****************************************************************************
7466 ****************************************************************************/
7468 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7469 union spoolss_PortInfo **info_p,
7472 union spoolss_PortInfo *info = NULL;
7474 WERROR result = WERR_OK;
7475 char **qlines = NULL;
7478 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7479 if (!W_ERROR_IS_OK(result)) {
7484 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7486 DEBUG(10,("Returning WERR_NOMEM\n"));
7487 result = WERR_NOMEM;
7491 for (i=0; i<numlines; i++) {
7492 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7493 result = fill_port_1(info, &info[i].info1, qlines[i]);
7494 if (!W_ERROR_IS_OK(result)) {
7499 TALLOC_FREE(qlines);
7502 if (!W_ERROR_IS_OK(result)) {
7504 TALLOC_FREE(qlines);
7516 /****************************************************************************
7518 ****************************************************************************/
7520 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7521 union spoolss_PortInfo **info_p,
7524 union spoolss_PortInfo *info = NULL;
7526 WERROR result = WERR_OK;
7527 char **qlines = NULL;
7530 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7531 if (!W_ERROR_IS_OK(result)) {
7536 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7538 DEBUG(10,("Returning WERR_NOMEM\n"));
7539 result = WERR_NOMEM;
7543 for (i=0; i<numlines; i++) {
7544 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7545 result = fill_port_2(info, &info[i].info2, qlines[i]);
7546 if (!W_ERROR_IS_OK(result)) {
7551 TALLOC_FREE(qlines);
7554 if (!W_ERROR_IS_OK(result)) {
7556 TALLOC_FREE(qlines);
7568 /****************************************************************
7570 ****************************************************************/
7572 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
7573 struct spoolss_EnumPorts *r)
7577 /* that's an [in out] buffer */
7579 if (!r->in.buffer && (r->in.offered != 0)) {
7580 return WERR_INVALID_PARAM;
7583 DEBUG(4,("_spoolss_EnumPorts\n"));
7587 *r->out.info = NULL;
7589 switch (r->in.level) {
7591 result = enumports_level_1(p->mem_ctx, r->out.info,
7595 result = enumports_level_2(p->mem_ctx, r->out.info,
7599 return WERR_UNKNOWN_LEVEL;
7602 if (!W_ERROR_IS_OK(result)) {
7606 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7608 *r->out.info, r->in.level,
7610 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7611 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7613 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7616 /****************************************************************************
7617 ****************************************************************************/
7619 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
7621 struct spoolss_SetPrinterInfoCtr *info_ctr,
7622 struct spoolss_DeviceMode *devmode,
7623 struct security_descriptor *secdesc,
7624 struct spoolss_UserLevelCtr *user_ctr,
7625 struct policy_handle *handle)
7627 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7628 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7630 WERROR err = WERR_OK;
7632 /* samba does not have a concept of local, non-shared printers yet, so
7633 * make sure we always setup sharename - gd */
7634 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7635 (info2->printername != NULL && info2->printername[0] != '\0')) {
7636 DEBUG(5, ("spoolss_addprinterex_level_2: "
7637 "no sharename has been set, setting printername %s as sharename\n",
7638 info2->printername));
7639 info2->sharename = info2->printername;
7642 /* check to see if the printer already exists */
7643 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7644 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7646 return WERR_PRINTER_ALREADY_EXISTS;
7649 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7650 if ((snum = print_queue_snum(info2->printername)) != -1) {
7651 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7652 info2->printername));
7653 return WERR_PRINTER_ALREADY_EXISTS;
7657 /* validate printer info struct */
7658 if (!info2->printername || strlen(info2->printername) == 0) {
7659 return WERR_INVALID_PRINTER_NAME;
7661 if (!info2->portname || strlen(info2->portname) == 0) {
7662 return WERR_UNKNOWN_PORT;
7664 if (!info2->drivername || strlen(info2->drivername) == 0) {
7665 return WERR_UNKNOWN_PRINTER_DRIVER;
7667 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7668 return WERR_UNKNOWN_PRINTPROCESSOR;
7671 /* FIXME!!! smbd should check to see if the driver is installed before
7672 trying to add a printer like this --jerry */
7674 if (*lp_addprinter_cmd() ) {
7675 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7676 info2, p->client_id->addr,
7678 return WERR_ACCESS_DENIED;
7681 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7682 "smb.conf parameter \"addprinter command\" is defined. This"
7683 "parameter must exist for this call to succeed\n",
7684 info2->sharename ));
7687 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7688 return WERR_ACCESS_DENIED;
7691 /* you must be a printer admin to add a new printer */
7692 if (!print_access_check(get_server_info_system(),
7695 PRINTER_ACCESS_ADMINISTER)) {
7696 return WERR_ACCESS_DENIED;
7700 * Do sanity check on the requested changes for Samba.
7703 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7704 return WERR_INVALID_PARAM;
7707 if (devmode == NULL) {
7708 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7711 update_dsspooler(p->mem_ctx,
7712 get_server_info_system(),
7718 err = winreg_update_printer(p->mem_ctx,
7719 get_server_info_system(),
7726 if (!W_ERROR_IS_OK(err)) {
7730 if (!open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER)) {
7731 /* Handle open failed - remove addition. */
7732 ZERO_STRUCTP(handle);
7733 return WERR_ACCESS_DENIED;
7739 /****************************************************************
7740 _spoolss_AddPrinterEx
7741 ****************************************************************/
7743 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
7744 struct spoolss_AddPrinterEx *r)
7746 switch (r->in.info_ctr->level) {
7748 /* we don't handle yet */
7749 /* but I know what to do ... */
7750 return WERR_UNKNOWN_LEVEL;
7752 return spoolss_addprinterex_level_2(p, r->in.server,
7754 r->in.devmode_ctr->devmode,
7755 r->in.secdesc_ctr->sd,
7756 r->in.userlevel_ctr,
7759 return WERR_UNKNOWN_LEVEL;
7763 /****************************************************************
7765 ****************************************************************/
7767 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
7768 struct spoolss_AddPrinter *r)
7770 struct spoolss_AddPrinterEx a;
7771 struct spoolss_UserLevelCtr userlevel_ctr;
7773 ZERO_STRUCT(userlevel_ctr);
7775 userlevel_ctr.level = 1;
7777 a.in.server = r->in.server;
7778 a.in.info_ctr = r->in.info_ctr;
7779 a.in.devmode_ctr = r->in.devmode_ctr;
7780 a.in.secdesc_ctr = r->in.secdesc_ctr;
7781 a.in.userlevel_ctr = &userlevel_ctr;
7782 a.out.handle = r->out.handle;
7784 return _spoolss_AddPrinterEx(p, &a);
7787 /****************************************************************
7788 _spoolss_AddPrinterDriverEx
7789 ****************************************************************/
7791 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
7792 struct spoolss_AddPrinterDriverEx *r)
7794 WERROR err = WERR_OK;
7795 const char *driver_name = NULL;
7800 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7801 fn = "_spoolss_AddPrinterDriver";
7803 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7804 fn = "_spoolss_AddPrinterDriverEx";
7807 return WERR_INVALID_PARAM;
7811 * we only support the semantics of AddPrinterDriver()
7812 * i.e. only copy files that are newer than existing ones
7815 if (r->in.flags == 0) {
7816 return WERR_INVALID_PARAM;
7819 if (r->in.flags != APD_COPY_NEW_FILES) {
7820 return WERR_ACCESS_DENIED;
7824 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7825 /* Clever hack from Martin Zielinski <mz@seh.de>
7826 * to allow downgrade from level 8 (Vista).
7828 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7829 r->in.info_ctr->level));
7830 return WERR_UNKNOWN_LEVEL;
7833 DEBUG(5,("Cleaning driver's information\n"));
7834 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
7835 if (!W_ERROR_IS_OK(err))
7838 DEBUG(5,("Moving driver to final destination\n"));
7839 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7844 err = winreg_add_driver(p->mem_ctx,
7845 get_server_info_system(),
7850 if (!W_ERROR_IS_OK(err)) {
7855 * I think this is where he DrvUpgradePrinter() hook would be
7856 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7857 * server. Right now, we just need to send ourselves a message
7858 * to update each printer bound to this driver. --jerry
7861 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
7862 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7870 /****************************************************************
7871 _spoolss_AddPrinterDriver
7872 ****************************************************************/
7874 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
7875 struct spoolss_AddPrinterDriver *r)
7877 struct spoolss_AddPrinterDriverEx a;
7879 switch (r->in.info_ctr->level) {
7886 return WERR_UNKNOWN_LEVEL;
7889 a.in.servername = r->in.servername;
7890 a.in.info_ctr = r->in.info_ctr;
7891 a.in.flags = APD_COPY_NEW_FILES;
7893 return _spoolss_AddPrinterDriverEx(p, &a);
7896 /****************************************************************************
7897 ****************************************************************************/
7899 struct _spoolss_paths {
7905 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7907 static const struct _spoolss_paths spoolss_paths[]= {
7908 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7909 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7912 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7913 const char *servername,
7914 const char *environment,
7918 const char *pservername = NULL;
7919 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7920 const char *short_archi;
7924 /* environment may be empty */
7925 if (environment && strlen(environment)) {
7926 long_archi = environment;
7929 /* servername may be empty */
7930 if (servername && strlen(servername)) {
7931 pservername = canon_servername(servername);
7933 if (!is_myname_or_ipaddr(pservername)) {
7934 return WERR_INVALID_PARAM;
7938 if (!(short_archi = get_short_archi(long_archi))) {
7939 return WERR_INVALID_ENVIRONMENT;
7942 switch (component) {
7943 case SPOOLSS_PRTPROCS_PATH:
7944 case SPOOLSS_DRIVER_PATH:
7946 *path = talloc_asprintf(mem_ctx,
7949 spoolss_paths[component].share,
7952 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7953 SPOOLSS_DEFAULT_SERVER_PATH,
7954 spoolss_paths[component].dir,
7959 return WERR_INVALID_PARAM;
7969 /****************************************************************************
7970 ****************************************************************************/
7972 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7973 const char *servername,
7974 const char *environment,
7975 struct spoolss_DriverDirectoryInfo1 *r)
7980 werr = compose_spoolss_server_path(mem_ctx,
7983 SPOOLSS_DRIVER_PATH,
7985 if (!W_ERROR_IS_OK(werr)) {
7989 DEBUG(4,("printer driver directory: [%s]\n", path));
7991 r->directory_name = path;
7996 /****************************************************************
7997 _spoolss_GetPrinterDriverDirectory
7998 ****************************************************************/
8000 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
8001 struct spoolss_GetPrinterDriverDirectory *r)
8005 /* that's an [in out] buffer */
8007 if (!r->in.buffer && (r->in.offered != 0)) {
8008 return WERR_INVALID_PARAM;
8011 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8016 /* r->in.level is ignored */
8018 werror = getprinterdriverdir_level_1(p->mem_ctx,
8021 &r->out.info->info1);
8022 if (!W_ERROR_IS_OK(werror)) {
8023 TALLOC_FREE(r->out.info);
8027 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
8028 r->out.info, r->in.level);
8029 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8031 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8034 /****************************************************************
8035 _spoolss_EnumPrinterData
8036 ****************************************************************/
8038 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
8039 struct spoolss_EnumPrinterData *r)
8042 struct spoolss_EnumPrinterDataEx r2;
8044 struct spoolss_PrinterEnumValues *info, *val = NULL;
8047 r2.in.handle = r->in.handle;
8048 r2.in.key_name = "PrinterDriverData";
8050 r2.out.count = &count;
8051 r2.out.info = &info;
8052 r2.out.needed = &needed;
8054 result = _spoolss_EnumPrinterDataEx(p, &r2);
8055 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8056 r2.in.offered = needed;
8057 result = _spoolss_EnumPrinterDataEx(p, &r2);
8059 if (!W_ERROR_IS_OK(result)) {
8064 * The NT machine wants to know the biggest size of value and data
8066 * cf: MSDN EnumPrinterData remark section
8069 if (!r->in.value_offered && !r->in.data_offered) {
8070 uint32_t biggest_valuesize = 0;
8071 uint32_t biggest_datasize = 0;
8074 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8076 for (i=0; i<count; i++) {
8078 name_length = strlen(info[i].value_name);
8079 if (strlen(info[i].value_name) > biggest_valuesize) {
8080 biggest_valuesize = name_length;
8083 if (info[i].data_length > biggest_datasize) {
8084 biggest_datasize = info[i].data_length;
8087 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8091 /* the value is an UNICODE string but real_value_size is the length
8092 in bytes including the trailing 0 */
8094 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8095 *r->out.data_needed = biggest_datasize;
8097 DEBUG(6,("final values: [%d], [%d]\n",
8098 *r->out.value_needed, *r->out.data_needed));
8103 if (r->in.enum_index < count) {
8104 val = &info[r->in.enum_index];
8108 /* out_value should default to "" or else NT4 has
8109 problems unmarshalling the response */
8111 if (r->in.value_offered) {
8112 *r->out.value_needed = 1;
8113 r->out.value_name = talloc_strdup(r, "");
8114 if (!r->out.value_name) {
8118 r->out.value_name = NULL;
8119 *r->out.value_needed = 0;
8122 /* the data is counted in bytes */
8124 *r->out.data_needed = r->in.data_offered;
8126 result = WERR_NO_MORE_ITEMS;
8130 * - counted in bytes in the request
8131 * - counted in UNICODE chars in the max reply
8132 * - counted in bytes in the real size
8134 * take a pause *before* coding not *during* coding
8138 if (r->in.value_offered) {
8139 r->out.value_name = talloc_strdup(r, val->value_name);
8140 if (!r->out.value_name) {
8143 *r->out.value_needed = val->value_name_len;
8145 r->out.value_name = NULL;
8146 *r->out.value_needed = 0;
8151 *r->out.type = val->type;
8153 /* data - counted in bytes */
8156 * See the section "Dynamically Typed Query Parameters"
8160 if (r->out.data && val->data && val->data->data &&
8161 val->data_length && r->in.data_offered) {
8162 memcpy(r->out.data, val->data->data,
8163 MIN(val->data_length,r->in.data_offered));
8166 *r->out.data_needed = val->data_length;
8174 /****************************************************************
8175 _spoolss_SetPrinterData
8176 ****************************************************************/
8178 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
8179 struct spoolss_SetPrinterData *r)
8181 struct spoolss_SetPrinterDataEx r2;
8183 r2.in.handle = r->in.handle;
8184 r2.in.key_name = "PrinterDriverData";
8185 r2.in.value_name = r->in.value_name;
8186 r2.in.type = r->in.type;
8187 r2.in.data = r->in.data;
8188 r2.in.offered = r->in.offered;
8190 return _spoolss_SetPrinterDataEx(p, &r2);
8193 /****************************************************************
8194 _spoolss_ResetPrinter
8195 ****************************************************************/
8197 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
8198 struct spoolss_ResetPrinter *r)
8200 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8203 DEBUG(5,("_spoolss_ResetPrinter\n"));
8206 * All we do is to check to see if the handle and queue is valid.
8207 * This call really doesn't mean anything to us because we only
8208 * support RAW printing. --jerry
8212 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8213 OUR_HANDLE(r->in.handle)));
8217 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8221 /* blindly return success */
8225 /****************************************************************
8226 _spoolss_DeletePrinterData
8227 ****************************************************************/
8229 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
8230 struct spoolss_DeletePrinterData *r)
8232 struct spoolss_DeletePrinterDataEx r2;
8234 r2.in.handle = r->in.handle;
8235 r2.in.key_name = "PrinterDriverData";
8236 r2.in.value_name = r->in.value_name;
8238 return _spoolss_DeletePrinterDataEx(p, &r2);
8241 /****************************************************************
8243 ****************************************************************/
8245 WERROR _spoolss_AddForm(struct pipes_struct *p,
8246 struct spoolss_AddForm *r)
8248 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8250 WERROR status = WERR_OK;
8251 uint64_t se_printop = SE_PRINT_OPERATOR;
8253 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8255 DEBUG(5,("_spoolss_AddForm\n"));
8258 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8259 OUR_HANDLE(r->in.handle)));
8263 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8264 and not a printer admin, then fail */
8266 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8267 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8268 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8269 p->server_info->info3->base.domain.string,
8271 p->server_info->ptok,
8272 lp_printer_admin(snum))) {
8273 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8274 return WERR_ACCESS_DENIED;
8277 switch (form->flags) {
8278 case SPOOLSS_FORM_USER:
8279 case SPOOLSS_FORM_BUILTIN:
8280 case SPOOLSS_FORM_PRINTER:
8283 return WERR_INVALID_PARAM;
8286 status = winreg_printer_addform1(p->mem_ctx,
8287 get_server_info_system(),
8290 if (!W_ERROR_IS_OK(status)) {
8295 * ChangeID must always be set if this is a printer
8297 if (Printer->printer_type == SPLHND_PRINTER) {
8298 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8302 status = winreg_printer_update_changeid(p->mem_ctx,
8303 get_server_info_system(),
8305 lp_const_servicename(snum));
8306 if (!W_ERROR_IS_OK(status)) {
8314 /****************************************************************
8316 ****************************************************************/
8318 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8319 struct spoolss_DeleteForm *r)
8321 const char *form_name = r->in.form_name;
8322 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8324 WERROR status = WERR_OK;
8325 uint64_t se_printop = SE_PRINT_OPERATOR;
8327 DEBUG(5,("_spoolss_DeleteForm\n"));
8330 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8331 OUR_HANDLE(r->in.handle)));
8335 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8336 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8337 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8338 p->server_info->info3->base.domain.string,
8340 p->server_info->ptok,
8341 lp_printer_admin(snum))) {
8342 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8343 return WERR_ACCESS_DENIED;
8346 status = winreg_printer_deleteform1(p->mem_ctx,
8347 get_server_info_system(),
8350 if (!W_ERROR_IS_OK(status)) {
8355 * ChangeID must always be set if this is a printer
8357 if (Printer->printer_type == SPLHND_PRINTER) {
8358 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8362 status = winreg_printer_update_changeid(p->mem_ctx,
8363 get_server_info_system(),
8365 lp_const_servicename(snum));
8366 if (!W_ERROR_IS_OK(status)) {
8374 /****************************************************************
8376 ****************************************************************/
8378 WERROR _spoolss_SetForm(struct pipes_struct *p,
8379 struct spoolss_SetForm *r)
8381 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8382 const char *form_name = r->in.form_name;
8384 WERROR status = WERR_OK;
8385 uint64_t se_printop = SE_PRINT_OPERATOR;
8387 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8389 DEBUG(5,("_spoolss_SetForm\n"));
8392 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8393 OUR_HANDLE(r->in.handle)));
8397 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8398 and not a printer admin, then fail */
8400 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8401 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8402 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8403 p->server_info->info3->base.domain.string,
8405 p->server_info->ptok,
8406 lp_printer_admin(snum))) {
8407 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8408 return WERR_ACCESS_DENIED;
8411 status = winreg_printer_setform1(p->mem_ctx,
8412 get_server_info_system(),
8416 if (!W_ERROR_IS_OK(status)) {
8421 * ChangeID must always be set if this is a printer
8423 if (Printer->printer_type == SPLHND_PRINTER) {
8424 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8428 status = winreg_printer_update_changeid(p->mem_ctx,
8429 get_server_info_system(),
8431 lp_const_servicename(snum));
8432 if (!W_ERROR_IS_OK(status)) {
8440 /****************************************************************************
8441 fill_print_processor1
8442 ****************************************************************************/
8444 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8445 struct spoolss_PrintProcessorInfo1 *r,
8446 const char *print_processor_name)
8448 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8449 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8454 /****************************************************************************
8455 enumprintprocessors level 1.
8456 ****************************************************************************/
8458 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8459 union spoolss_PrintProcessorInfo **info_p,
8462 union spoolss_PrintProcessorInfo *info;
8465 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8466 W_ERROR_HAVE_NO_MEMORY(info);
8470 result = fill_print_processor1(info, &info[0].info1, "winprint");
8471 if (!W_ERROR_IS_OK(result)) {
8476 if (!W_ERROR_IS_OK(result)) {
8487 /****************************************************************
8488 _spoolss_EnumPrintProcessors
8489 ****************************************************************/
8491 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8492 struct spoolss_EnumPrintProcessors *r)
8496 /* that's an [in out] buffer */
8498 if (!r->in.buffer && (r->in.offered != 0)) {
8499 return WERR_INVALID_PARAM;
8502 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8505 * Enumerate the print processors ...
8507 * Just reply with "winprint", to keep NT happy
8508 * and I can use my nice printer checker.
8513 *r->out.info = NULL;
8515 switch (r->in.level) {
8517 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8521 return WERR_UNKNOWN_LEVEL;
8524 if (!W_ERROR_IS_OK(result)) {
8528 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8529 spoolss_EnumPrintProcessors,
8530 *r->out.info, r->in.level,
8532 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8533 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8535 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8538 /****************************************************************************
8539 fill_printprocdatatype1
8540 ****************************************************************************/
8542 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8543 struct spoolss_PrintProcDataTypesInfo1 *r,
8544 const char *name_array)
8546 r->name_array = talloc_strdup(mem_ctx, name_array);
8547 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8552 /****************************************************************************
8553 enumprintprocdatatypes level 1.
8554 ****************************************************************************/
8556 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8557 union spoolss_PrintProcDataTypesInfo **info_p,
8561 union spoolss_PrintProcDataTypesInfo *info;
8563 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8564 W_ERROR_HAVE_NO_MEMORY(info);
8568 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8569 if (!W_ERROR_IS_OK(result)) {
8574 if (!W_ERROR_IS_OK(result)) {
8585 /****************************************************************
8586 _spoolss_EnumPrintProcDataTypes
8587 ****************************************************************/
8589 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
8590 struct spoolss_EnumPrintProcDataTypes *r)
8594 /* that's an [in out] buffer */
8596 if (!r->in.buffer && (r->in.offered != 0)) {
8597 return WERR_INVALID_PARAM;
8600 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8604 *r->out.info = NULL;
8606 switch (r->in.level) {
8608 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8612 return WERR_UNKNOWN_LEVEL;
8615 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8616 spoolss_EnumPrintProcDataTypes,
8617 *r->out.info, r->in.level,
8619 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8620 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8622 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8625 /****************************************************************************
8627 ****************************************************************************/
8629 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8630 struct spoolss_MonitorInfo1 *r,
8631 const char *monitor_name)
8633 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8634 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8639 /****************************************************************************
8641 ****************************************************************************/
8643 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8644 struct spoolss_MonitorInfo2 *r,
8645 const char *monitor_name,
8646 const char *environment,
8647 const char *dll_name)
8649 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8650 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8651 r->environment = talloc_strdup(mem_ctx, environment);
8652 W_ERROR_HAVE_NO_MEMORY(r->environment);
8653 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8654 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8659 /****************************************************************************
8660 enumprintmonitors level 1.
8661 ****************************************************************************/
8663 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8664 union spoolss_MonitorInfo **info_p,
8667 union spoolss_MonitorInfo *info;
8668 WERROR result = WERR_OK;
8670 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8671 W_ERROR_HAVE_NO_MEMORY(info);
8675 result = fill_monitor_1(info, &info[0].info1,
8677 if (!W_ERROR_IS_OK(result)) {
8681 result = fill_monitor_1(info, &info[1].info1,
8683 if (!W_ERROR_IS_OK(result)) {
8688 if (!W_ERROR_IS_OK(result)) {
8699 /****************************************************************************
8700 enumprintmonitors level 2.
8701 ****************************************************************************/
8703 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8704 union spoolss_MonitorInfo **info_p,
8707 union spoolss_MonitorInfo *info;
8708 WERROR result = WERR_OK;
8710 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8711 W_ERROR_HAVE_NO_MEMORY(info);
8715 result = fill_monitor_2(info, &info[0].info2,
8717 "Windows NT X86", /* FIXME */
8719 if (!W_ERROR_IS_OK(result)) {
8723 result = fill_monitor_2(info, &info[1].info2,
8725 "Windows NT X86", /* FIXME */
8727 if (!W_ERROR_IS_OK(result)) {
8732 if (!W_ERROR_IS_OK(result)) {
8743 /****************************************************************
8744 _spoolss_EnumMonitors
8745 ****************************************************************/
8747 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
8748 struct spoolss_EnumMonitors *r)
8752 /* that's an [in out] buffer */
8754 if (!r->in.buffer && (r->in.offered != 0)) {
8755 return WERR_INVALID_PARAM;
8758 DEBUG(5,("_spoolss_EnumMonitors\n"));
8761 * Enumerate the print monitors ...
8763 * Just reply with "Local Port", to keep NT happy
8764 * and I can use my nice printer checker.
8769 *r->out.info = NULL;
8771 switch (r->in.level) {
8773 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8777 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8781 return WERR_UNKNOWN_LEVEL;
8784 if (!W_ERROR_IS_OK(result)) {
8788 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8789 spoolss_EnumMonitors,
8790 *r->out.info, r->in.level,
8792 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8793 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8795 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8798 /****************************************************************************
8799 ****************************************************************************/
8801 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8802 const print_queue_struct *queue,
8803 int count, int snum,
8804 struct spoolss_PrinterInfo2 *pinfo2,
8806 struct spoolss_JobInfo1 *r)
8811 for (i=0; i<count; i++) {
8812 if (queue[i].job == (int)jobid) {
8818 if (found == false) {
8819 /* NT treats not found as bad param... yet another bad choice */
8820 return WERR_INVALID_PARAM;
8823 return fill_job_info1(mem_ctx,
8831 /****************************************************************************
8832 ****************************************************************************/
8834 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8835 const print_queue_struct *queue,
8836 int count, int snum,
8837 struct spoolss_PrinterInfo2 *pinfo2,
8839 struct spoolss_JobInfo2 *r)
8843 struct spoolss_DeviceMode *devmode;
8846 for (i=0; i<count; i++) {
8847 if (queue[i].job == (int)jobid) {
8853 if (found == false) {
8854 /* NT treats not found as bad param... yet another bad
8856 return WERR_INVALID_PARAM;
8860 * if the print job does not have a DEVMODE associated with it,
8861 * just use the one for the printer. A NULL devicemode is not
8862 * a failure condition
8865 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8867 result = spoolss_create_default_devmode(mem_ctx,
8868 pinfo2->printername,
8870 if (!W_ERROR_IS_OK(result)) {
8871 DEBUG(3, ("Can't proceed w/o a devmode!"));
8876 return fill_job_info2(mem_ctx,
8885 /****************************************************************
8887 ****************************************************************/
8889 WERROR _spoolss_GetJob(struct pipes_struct *p,
8890 struct spoolss_GetJob *r)
8892 WERROR result = WERR_OK;
8893 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8896 print_queue_struct *queue = NULL;
8897 print_status_struct prt_status;
8899 /* that's an [in out] buffer */
8901 if (!r->in.buffer && (r->in.offered != 0)) {
8902 return WERR_INVALID_PARAM;
8905 DEBUG(5,("_spoolss_GetJob\n"));
8909 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8913 result = winreg_get_printer(p->mem_ctx,
8914 get_server_info_system(),
8917 lp_const_servicename(snum),
8919 if (!W_ERROR_IS_OK(result)) {
8923 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
8925 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8926 count, prt_status.status, prt_status.message));
8928 switch (r->in.level) {
8930 result = getjob_level_1(p->mem_ctx,
8931 queue, count, snum, pinfo2,
8932 r->in.job_id, &r->out.info->info1);
8935 result = getjob_level_2(p->mem_ctx,
8936 queue, count, snum, pinfo2,
8937 r->in.job_id, &r->out.info->info2);
8940 result = WERR_UNKNOWN_LEVEL;
8945 TALLOC_FREE(pinfo2);
8947 if (!W_ERROR_IS_OK(result)) {
8948 TALLOC_FREE(r->out.info);
8952 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
8954 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8956 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8959 /****************************************************************
8960 _spoolss_GetPrinterDataEx
8961 ****************************************************************/
8963 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
8964 struct spoolss_GetPrinterDataEx *r)
8967 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8968 const char *printer;
8970 WERROR result = WERR_OK;
8972 enum winreg_Type val_type;
8977 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8979 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8980 r->in.key_name, r->in.value_name));
8982 /* in case of problem, return some default values */
8985 *r->out.type = REG_NONE;
8988 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8989 OUR_HANDLE(r->in.handle)));
8990 result = WERR_BADFID;
8994 /* Is the handle to a printer or to the server? */
8996 if (Printer->printer_type == SPLHND_SERVER) {
8998 union spoolss_PrinterData data;
9000 result = getprinterdata_printer_server(p->mem_ctx,
9004 if (!W_ERROR_IS_OK(result)) {
9008 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
9009 *r->out.type, &data);
9010 if (!W_ERROR_IS_OK(result)) {
9014 *r->out.needed = blob.length;
9016 if (r->in.offered >= *r->out.needed) {
9017 memcpy(r->out.data, blob.data, blob.length);
9020 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9023 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9026 printer = lp_const_servicename(snum);
9028 /* check to see if the keyname is valid */
9029 if (!strlen(r->in.key_name)) {
9030 return WERR_INVALID_PARAM;
9033 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9034 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
9035 strequal(r->in.value_name, "ChangeId")) {
9036 *r->out.type = REG_DWORD;
9038 if (r->in.offered >= *r->out.needed) {
9039 uint32_t changeid = 0;
9041 result = winreg_printer_get_changeid(p->mem_ctx,
9042 get_server_info_system(),
9046 if (!W_ERROR_IS_OK(result)) {
9050 SIVAL(r->out.data, 0, changeid);
9056 result = winreg_get_printer_dataex(p->mem_ctx,
9057 get_server_info_system(),
9065 if (!W_ERROR_IS_OK(result)) {
9069 *r->out.needed = val_size;
9070 *r->out.type = val_type;
9072 if (r->in.offered >= *r->out.needed) {
9073 memcpy(r->out.data, val_data, val_size);
9077 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
9078 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
9080 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9083 /****************************************************************
9084 _spoolss_SetPrinterDataEx
9085 ****************************************************************/
9087 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
9088 struct spoolss_SetPrinterDataEx *r)
9090 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9092 WERROR result = WERR_OK;
9093 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9096 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9098 /* From MSDN documentation of SetPrinterDataEx: pass request to
9099 SetPrinterData if key is "PrinterDriverData" */
9102 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9103 OUR_HANDLE(r->in.handle)));
9107 if (Printer->printer_type == SPLHND_SERVER) {
9108 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9109 "Not implemented for server handles yet\n"));
9110 return WERR_INVALID_PARAM;
9113 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9118 * Access check : NT returns "access denied" if you make a
9119 * SetPrinterData call without the necessary privildge.
9120 * we were originally returning OK if nothing changed
9121 * which made Win2k issue **a lot** of SetPrinterData
9122 * when connecting to a printer --jerry
9125 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9126 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9127 "change denied by handle access permissions\n"));
9128 return WERR_ACCESS_DENIED;
9131 result = winreg_get_printer(Printer,
9132 get_server_info_system(),
9134 Printer->servername,
9135 lp_servicename(snum),
9137 if (!W_ERROR_IS_OK(result)) {
9141 /* check for OID in valuename */
9143 oid_string = strchr(r->in.value_name, ',');
9149 /* save the registry data */
9151 result = winreg_set_printer_dataex(p->mem_ctx,
9152 get_server_info_system(),
9161 if (W_ERROR_IS_OK(result)) {
9162 /* save the OID if one was specified */
9164 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9165 r->in.key_name, SPOOL_OID_KEY);
9167 result = WERR_NOMEM;
9172 * I'm not checking the status here on purpose. Don't know
9173 * if this is right, but I'm returning the status from the
9174 * previous set_printer_dataex() call. I have no idea if
9175 * this is right. --jerry
9177 winreg_set_printer_dataex(p->mem_ctx,
9178 get_server_info_system(),
9184 (uint8_t *) oid_string,
9185 strlen(oid_string) + 1);
9188 result = winreg_printer_update_changeid(p->mem_ctx,
9189 get_server_info_system(),
9191 lp_const_servicename(snum));
9196 talloc_free(pinfo2);
9200 /****************************************************************
9201 _spoolss_DeletePrinterDataEx
9202 ****************************************************************/
9204 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
9205 struct spoolss_DeletePrinterDataEx *r)
9207 const char *printer;
9209 WERROR status = WERR_OK;
9210 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9212 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9215 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9216 "Invalid handle (%s:%u:%u).\n",
9217 OUR_HANDLE(r->in.handle)));
9221 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9222 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9223 "printer properties change denied by handle\n"));
9224 return WERR_ACCESS_DENIED;
9227 if (!r->in.value_name || !r->in.key_name) {
9231 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9234 printer = lp_const_servicename(snum);
9236 status = winreg_delete_printer_dataex(p->mem_ctx,
9237 get_server_info_system(),
9242 if (W_ERROR_IS_OK(status)) {
9243 status = winreg_printer_update_changeid(p->mem_ctx,
9244 get_server_info_system(),
9252 /****************************************************************
9253 _spoolss_EnumPrinterKey
9254 ****************************************************************/
9256 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
9257 struct spoolss_EnumPrinterKey *r)
9260 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9262 WERROR result = WERR_BADFILE;
9263 const char **array = NULL;
9266 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9269 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9270 OUR_HANDLE(r->in.handle)));
9274 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9278 result = winreg_enum_printer_key(p->mem_ctx,
9279 get_server_info_system(),
9281 lp_const_servicename(snum),
9285 if (!W_ERROR_IS_OK(result)) {
9289 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9290 result = WERR_NOMEM;
9294 *r->out._ndr_size = r->in.offered / 2;
9295 *r->out.needed = blob.length;
9297 if (r->in.offered < *r->out.needed) {
9298 result = WERR_MORE_DATA;
9301 r->out.key_buffer->string_array = array;
9305 if (!W_ERROR_IS_OK(result)) {
9307 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9315 /****************************************************************
9316 _spoolss_DeletePrinterKey
9317 ****************************************************************/
9319 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9320 struct spoolss_DeletePrinterKey *r)
9322 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9325 const char *printer;
9327 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9330 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9331 OUR_HANDLE(r->in.handle)));
9335 /* if keyname == NULL, return error */
9336 if ( !r->in.key_name )
9337 return WERR_INVALID_PARAM;
9339 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9343 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9344 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9345 "printer properties change denied by handle\n"));
9346 return WERR_ACCESS_DENIED;
9349 printer = lp_const_servicename(snum);
9351 /* delete the key and all subkeys */
9352 status = winreg_delete_printer_key(p->mem_ctx,
9353 get_server_info_system(),
9357 if (W_ERROR_IS_OK(status)) {
9358 status = winreg_printer_update_changeid(p->mem_ctx,
9359 get_server_info_system(),
9367 /****************************************************************
9368 _spoolss_EnumPrinterDataEx
9369 ****************************************************************/
9371 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9372 struct spoolss_EnumPrinterDataEx *r)
9375 struct spoolss_PrinterEnumValues *info = NULL;
9376 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9380 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9384 *r->out.info = NULL;
9387 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9388 OUR_HANDLE(r->in.handle)));
9393 * first check for a keyname of NULL or "". Win2k seems to send
9394 * this a lot and we should send back WERR_INVALID_PARAM
9395 * no need to spend time looking up the printer in this case.
9399 if (!strlen(r->in.key_name)) {
9400 result = WERR_INVALID_PARAM;
9404 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9408 /* now look for a match on the key name */
9409 result = winreg_enum_printer_dataex(p->mem_ctx,
9410 get_server_info_system(),
9412 lp_const_servicename(snum),
9416 if (!W_ERROR_IS_OK(result)) {
9420 #if 0 /* FIXME - gd */
9421 /* housekeeping information in the reply */
9423 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9424 * the hand marshalled container size is a multiple
9425 * of 4 bytes for RPC alignment.
9429 needed += 4-(needed % 4);
9432 *r->out.count = count;
9433 *r->out.info = info;
9436 if (!W_ERROR_IS_OK(result)) {
9440 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9441 spoolss_EnumPrinterDataEx,
9444 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9445 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9447 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9450 /****************************************************************************
9451 ****************************************************************************/
9453 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9454 const char *servername,
9455 const char *environment,
9456 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9461 werr = compose_spoolss_server_path(mem_ctx,
9464 SPOOLSS_PRTPROCS_PATH,
9466 if (!W_ERROR_IS_OK(werr)) {
9470 DEBUG(4,("print processor directory: [%s]\n", path));
9472 r->directory_name = path;
9477 /****************************************************************
9478 _spoolss_GetPrintProcessorDirectory
9479 ****************************************************************/
9481 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
9482 struct spoolss_GetPrintProcessorDirectory *r)
9486 /* that's an [in out] buffer */
9488 if (!r->in.buffer && (r->in.offered != 0)) {
9489 return WERR_INVALID_PARAM;
9492 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9497 /* r->in.level is ignored */
9499 /* We always should reply with a local print processor directory so that
9500 * users are not forced to have a [prnproc$] share on the Samba spoolss
9501 * server - Guenther */
9503 result = getprintprocessordirectory_level_1(p->mem_ctx,
9504 NULL, /* r->in.server */
9506 &r->out.info->info1);
9507 if (!W_ERROR_IS_OK(result)) {
9508 TALLOC_FREE(r->out.info);
9512 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9513 r->out.info, r->in.level);
9514 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9516 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9519 /*******************************************************************
9520 ********************************************************************/
9522 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9523 const char *dllname)
9525 enum ndr_err_code ndr_err;
9526 struct spoolss_MonitorUi ui;
9528 ui.dll_name = dllname;
9530 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9531 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9532 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9533 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9535 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9538 /*******************************************************************
9539 Streams the monitor UI DLL name in UNICODE
9540 *******************************************************************/
9542 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9543 NT_USER_TOKEN *token, DATA_BLOB *in,
9544 DATA_BLOB *out, uint32_t *needed)
9546 const char *dllname = "tcpmonui.dll";
9548 *needed = (strlen(dllname)+1) * 2;
9550 if (out->length < *needed) {
9551 return WERR_INSUFFICIENT_BUFFER;
9554 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9561 /*******************************************************************
9562 ********************************************************************/
9564 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9565 struct spoolss_PortData1 *port1,
9566 const DATA_BLOB *buf)
9568 enum ndr_err_code ndr_err;
9569 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9570 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9571 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9572 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9574 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9577 /*******************************************************************
9578 ********************************************************************/
9580 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9581 struct spoolss_PortData2 *port2,
9582 const DATA_BLOB *buf)
9584 enum ndr_err_code ndr_err;
9585 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9586 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9587 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9588 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9590 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9593 /*******************************************************************
9594 Create a new TCP/IP port
9595 *******************************************************************/
9597 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9598 NT_USER_TOKEN *token, DATA_BLOB *in,
9599 DATA_BLOB *out, uint32_t *needed)
9601 struct spoolss_PortData1 port1;
9602 struct spoolss_PortData2 port2;
9603 char *device_uri = NULL;
9606 const char *portname;
9607 const char *hostaddress;
9609 uint32_t port_number;
9612 /* peek for spoolss_PortData version */
9614 if (!in || (in->length < (128 + 4))) {
9615 return WERR_GENERAL_FAILURE;
9618 version = IVAL(in->data, 128);
9624 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9628 portname = port1.portname;
9629 hostaddress = port1.hostaddress;
9630 queue = port1.queue;
9631 protocol = port1.protocol;
9632 port_number = port1.port_number;
9638 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9642 portname = port2.portname;
9643 hostaddress = port2.hostaddress;
9644 queue = port2.queue;
9645 protocol = port2.protocol;
9646 port_number = port2.port_number;
9650 DEBUG(1,("xcvtcp_addport: "
9651 "unknown version of port_data: %d\n", version));
9652 return WERR_UNKNOWN_PORT;
9655 /* create the device URI and call the add_port_hook() */
9658 case PROTOCOL_RAWTCP_TYPE:
9659 device_uri = talloc_asprintf(mem_ctx,
9660 "socket://%s:%d/", hostaddress,
9664 case PROTOCOL_LPR_TYPE:
9665 device_uri = talloc_asprintf(mem_ctx,
9666 "lpr://%s/%s", hostaddress, queue );
9670 return WERR_UNKNOWN_PORT;
9677 return add_port_hook(mem_ctx, token, portname, device_uri);
9680 /*******************************************************************
9681 *******************************************************************/
9683 struct xcv_api_table xcvtcp_cmds[] = {
9684 { "MonitorUI", xcvtcp_monitorui },
9685 { "AddPort", xcvtcp_addport},
9689 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9690 NT_USER_TOKEN *token, const char *command,
9697 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9699 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9700 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9701 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9704 return WERR_BADFUNC;
9707 /*******************************************************************
9708 *******************************************************************/
9709 #if 0 /* don't support management using the "Local Port" monitor */
9711 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9712 NT_USER_TOKEN *token, DATA_BLOB *in,
9713 DATA_BLOB *out, uint32_t *needed)
9715 const char *dllname = "localui.dll";
9717 *needed = (strlen(dllname)+1) * 2;
9719 if (out->length < *needed) {
9720 return WERR_INSUFFICIENT_BUFFER;
9723 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9730 /*******************************************************************
9731 *******************************************************************/
9733 struct xcv_api_table xcvlocal_cmds[] = {
9734 { "MonitorUI", xcvlocal_monitorui },
9738 struct xcv_api_table xcvlocal_cmds[] = {
9745 /*******************************************************************
9746 *******************************************************************/
9748 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9749 NT_USER_TOKEN *token, const char *command,
9750 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9755 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9757 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9758 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9759 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9761 return WERR_BADFUNC;
9764 /****************************************************************
9766 ****************************************************************/
9768 WERROR _spoolss_XcvData(struct pipes_struct *p,
9769 struct spoolss_XcvData *r)
9771 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9772 DATA_BLOB out_data = data_blob_null;
9776 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9777 OUR_HANDLE(r->in.handle)));
9781 /* Has to be a handle to the TCP/IP port monitor */
9783 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9784 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9788 /* requires administrative access to the server */
9790 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9791 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9792 return WERR_ACCESS_DENIED;
9795 /* Allocate the outgoing buffer */
9797 if (r->in.out_data_size) {
9798 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9799 if (out_data.data == NULL) {
9804 switch ( Printer->printer_type ) {
9805 case SPLHND_PORTMON_TCP:
9806 werror = process_xcvtcp_command(p->mem_ctx,
9807 p->server_info->ptok,
9808 r->in.function_name,
9809 &r->in.in_data, &out_data,
9812 case SPLHND_PORTMON_LOCAL:
9813 werror = process_xcvlocal_command(p->mem_ctx,
9814 p->server_info->ptok,
9815 r->in.function_name,
9816 &r->in.in_data, &out_data,
9820 werror = WERR_INVALID_PRINT_MONITOR;
9823 if (!W_ERROR_IS_OK(werror)) {
9827 *r->out.status_code = 0;
9829 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9830 memcpy(r->out.out_data, out_data.data,
9831 MIN(r->in.out_data_size, out_data.length));
9837 /****************************************************************
9838 _spoolss_AddPrintProcessor
9839 ****************************************************************/
9841 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
9842 struct spoolss_AddPrintProcessor *r)
9844 /* for now, just indicate success and ignore the add. We'll
9845 automatically set the winprint processor for printer
9846 entries later. Used to debug the LexMark Optra S 1855 PCL
9852 /****************************************************************
9854 ****************************************************************/
9856 WERROR _spoolss_AddPort(struct pipes_struct *p,
9857 struct spoolss_AddPort *r)
9859 /* do what w2k3 does */
9861 return WERR_NOT_SUPPORTED;
9864 /****************************************************************
9865 _spoolss_GetPrinterDriver
9866 ****************************************************************/
9868 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
9869 struct spoolss_GetPrinterDriver *r)
9871 p->rng_fault_state = true;
9872 return WERR_NOT_SUPPORTED;
9875 /****************************************************************
9876 _spoolss_ReadPrinter
9877 ****************************************************************/
9879 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
9880 struct spoolss_ReadPrinter *r)
9882 p->rng_fault_state = true;
9883 return WERR_NOT_SUPPORTED;
9886 /****************************************************************
9887 _spoolss_WaitForPrinterChange
9888 ****************************************************************/
9890 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
9891 struct spoolss_WaitForPrinterChange *r)
9893 p->rng_fault_state = true;
9894 return WERR_NOT_SUPPORTED;
9897 /****************************************************************
9898 _spoolss_ConfigurePort
9899 ****************************************************************/
9901 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
9902 struct spoolss_ConfigurePort *r)
9904 p->rng_fault_state = true;
9905 return WERR_NOT_SUPPORTED;
9908 /****************************************************************
9910 ****************************************************************/
9912 WERROR _spoolss_DeletePort(struct pipes_struct *p,
9913 struct spoolss_DeletePort *r)
9915 p->rng_fault_state = true;
9916 return WERR_NOT_SUPPORTED;
9919 /****************************************************************
9920 _spoolss_CreatePrinterIC
9921 ****************************************************************/
9923 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
9924 struct spoolss_CreatePrinterIC *r)
9926 p->rng_fault_state = true;
9927 return WERR_NOT_SUPPORTED;
9930 /****************************************************************
9931 _spoolss_PlayGDIScriptOnPrinterIC
9932 ****************************************************************/
9934 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
9935 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9937 p->rng_fault_state = true;
9938 return WERR_NOT_SUPPORTED;
9941 /****************************************************************
9942 _spoolss_DeletePrinterIC
9943 ****************************************************************/
9945 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
9946 struct spoolss_DeletePrinterIC *r)
9948 p->rng_fault_state = true;
9949 return WERR_NOT_SUPPORTED;
9952 /****************************************************************
9953 _spoolss_AddPrinterConnection
9954 ****************************************************************/
9956 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
9957 struct spoolss_AddPrinterConnection *r)
9959 p->rng_fault_state = true;
9960 return WERR_NOT_SUPPORTED;
9963 /****************************************************************
9964 _spoolss_DeletePrinterConnection
9965 ****************************************************************/
9967 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
9968 struct spoolss_DeletePrinterConnection *r)
9970 p->rng_fault_state = true;
9971 return WERR_NOT_SUPPORTED;
9974 /****************************************************************
9975 _spoolss_PrinterMessageBox
9976 ****************************************************************/
9978 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
9979 struct spoolss_PrinterMessageBox *r)
9981 p->rng_fault_state = true;
9982 return WERR_NOT_SUPPORTED;
9985 /****************************************************************
9987 ****************************************************************/
9989 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
9990 struct spoolss_AddMonitor *r)
9992 p->rng_fault_state = true;
9993 return WERR_NOT_SUPPORTED;
9996 /****************************************************************
9997 _spoolss_DeleteMonitor
9998 ****************************************************************/
10000 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
10001 struct spoolss_DeleteMonitor *r)
10003 p->rng_fault_state = true;
10004 return WERR_NOT_SUPPORTED;
10007 /****************************************************************
10008 _spoolss_DeletePrintProcessor
10009 ****************************************************************/
10011 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
10012 struct spoolss_DeletePrintProcessor *r)
10014 p->rng_fault_state = true;
10015 return WERR_NOT_SUPPORTED;
10018 /****************************************************************
10019 _spoolss_AddPrintProvidor
10020 ****************************************************************/
10022 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
10023 struct spoolss_AddPrintProvidor *r)
10025 p->rng_fault_state = true;
10026 return WERR_NOT_SUPPORTED;
10029 /****************************************************************
10030 _spoolss_DeletePrintProvidor
10031 ****************************************************************/
10033 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
10034 struct spoolss_DeletePrintProvidor *r)
10036 p->rng_fault_state = true;
10037 return WERR_NOT_SUPPORTED;
10040 /****************************************************************
10041 _spoolss_FindFirstPrinterChangeNotification
10042 ****************************************************************/
10044 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
10045 struct spoolss_FindFirstPrinterChangeNotification *r)
10047 p->rng_fault_state = true;
10048 return WERR_NOT_SUPPORTED;
10051 /****************************************************************
10052 _spoolss_FindNextPrinterChangeNotification
10053 ****************************************************************/
10055 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
10056 struct spoolss_FindNextPrinterChangeNotification *r)
10058 p->rng_fault_state = true;
10059 return WERR_NOT_SUPPORTED;
10062 /****************************************************************
10063 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10064 ****************************************************************/
10066 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
10067 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10069 p->rng_fault_state = true;
10070 return WERR_NOT_SUPPORTED;
10073 /****************************************************************
10074 _spoolss_ReplyOpenPrinter
10075 ****************************************************************/
10077 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
10078 struct spoolss_ReplyOpenPrinter *r)
10080 p->rng_fault_state = true;
10081 return WERR_NOT_SUPPORTED;
10084 /****************************************************************
10085 _spoolss_RouterReplyPrinter
10086 ****************************************************************/
10088 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
10089 struct spoolss_RouterReplyPrinter *r)
10091 p->rng_fault_state = true;
10092 return WERR_NOT_SUPPORTED;
10095 /****************************************************************
10096 _spoolss_ReplyClosePrinter
10097 ****************************************************************/
10099 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
10100 struct spoolss_ReplyClosePrinter *r)
10102 p->rng_fault_state = true;
10103 return WERR_NOT_SUPPORTED;
10106 /****************************************************************
10108 ****************************************************************/
10110 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
10111 struct spoolss_AddPortEx *r)
10113 p->rng_fault_state = true;
10114 return WERR_NOT_SUPPORTED;
10117 /****************************************************************
10118 _spoolss_RouterFindFirstPrinterChangeNotification
10119 ****************************************************************/
10121 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
10122 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10124 p->rng_fault_state = true;
10125 return WERR_NOT_SUPPORTED;
10128 /****************************************************************
10129 _spoolss_SpoolerInit
10130 ****************************************************************/
10132 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
10133 struct spoolss_SpoolerInit *r)
10135 p->rng_fault_state = true;
10136 return WERR_NOT_SUPPORTED;
10139 /****************************************************************
10140 _spoolss_ResetPrinterEx
10141 ****************************************************************/
10143 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
10144 struct spoolss_ResetPrinterEx *r)
10146 p->rng_fault_state = true;
10147 return WERR_NOT_SUPPORTED;
10150 /****************************************************************
10151 _spoolss_RouterReplyPrinterEx
10152 ****************************************************************/
10154 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
10155 struct spoolss_RouterReplyPrinterEx *r)
10157 p->rng_fault_state = true;
10158 return WERR_NOT_SUPPORTED;
10161 /****************************************************************
10163 ****************************************************************/
10165 WERROR _spoolss_44(struct pipes_struct *p,
10166 struct spoolss_44 *r)
10168 p->rng_fault_state = true;
10169 return WERR_NOT_SUPPORTED;
10172 /****************************************************************
10174 ****************************************************************/
10176 WERROR _spoolss_47(struct pipes_struct *p,
10177 struct spoolss_47 *r)
10179 p->rng_fault_state = true;
10180 return WERR_NOT_SUPPORTED;
10183 /****************************************************************
10185 ****************************************************************/
10187 WERROR _spoolss_4a(struct pipes_struct *p,
10188 struct spoolss_4a *r)
10190 p->rng_fault_state = true;
10191 return WERR_NOT_SUPPORTED;
10194 /****************************************************************
10196 ****************************************************************/
10198 WERROR _spoolss_4b(struct pipes_struct *p,
10199 struct spoolss_4b *r)
10201 p->rng_fault_state = true;
10202 return WERR_NOT_SUPPORTED;
10205 /****************************************************************
10207 ****************************************************************/
10209 WERROR _spoolss_4c(struct pipes_struct *p,
10210 struct spoolss_4c *r)
10212 p->rng_fault_state = true;
10213 return WERR_NOT_SUPPORTED;
10216 /****************************************************************
10218 ****************************************************************/
10220 WERROR _spoolss_53(struct pipes_struct *p,
10221 struct spoolss_53 *r)
10223 p->rng_fault_state = true;
10224 return WERR_NOT_SUPPORTED;
10227 /****************************************************************
10229 ****************************************************************/
10231 WERROR _spoolss_55(struct pipes_struct *p,
10232 struct spoolss_55 *r)
10234 p->rng_fault_state = true;
10235 return WERR_NOT_SUPPORTED;
10238 /****************************************************************
10240 ****************************************************************/
10242 WERROR _spoolss_56(struct pipes_struct *p,
10243 struct spoolss_56 *r)
10245 p->rng_fault_state = true;
10246 return WERR_NOT_SUPPORTED;
10249 /****************************************************************
10251 ****************************************************************/
10253 WERROR _spoolss_57(struct pipes_struct *p,
10254 struct spoolss_57 *r)
10256 p->rng_fault_state = true;
10257 return WERR_NOT_SUPPORTED;
10260 /****************************************************************
10262 ****************************************************************/
10264 WERROR _spoolss_5a(struct pipes_struct *p,
10265 struct spoolss_5a *r)
10267 p->rng_fault_state = true;
10268 return WERR_NOT_SUPPORTED;
10271 /****************************************************************
10273 ****************************************************************/
10275 WERROR _spoolss_5b(struct pipes_struct *p,
10276 struct spoolss_5b *r)
10278 p->rng_fault_state = true;
10279 return WERR_NOT_SUPPORTED;
10282 /****************************************************************
10284 ****************************************************************/
10286 WERROR _spoolss_5c(struct pipes_struct *p,
10287 struct spoolss_5c *r)
10289 p->rng_fault_state = true;
10290 return WERR_NOT_SUPPORTED;
10293 /****************************************************************
10295 ****************************************************************/
10297 WERROR _spoolss_5d(struct pipes_struct *p,
10298 struct spoolss_5d *r)
10300 p->rng_fault_state = true;
10301 return WERR_NOT_SUPPORTED;
10304 /****************************************************************
10306 ****************************************************************/
10308 WERROR _spoolss_5e(struct pipes_struct *p,
10309 struct spoolss_5e *r)
10311 p->rng_fault_state = true;
10312 return WERR_NOT_SUPPORTED;
10315 /****************************************************************
10317 ****************************************************************/
10319 WERROR _spoolss_5f(struct pipes_struct *p,
10320 struct spoolss_5f *r)
10322 p->rng_fault_state = true;
10323 return WERR_NOT_SUPPORTED;
10326 /****************************************************************
10328 ****************************************************************/
10330 WERROR _spoolss_60(struct pipes_struct *p,
10331 struct spoolss_60 *r)
10333 p->rng_fault_state = true;
10334 return WERR_NOT_SUPPORTED;
10337 /****************************************************************
10339 ****************************************************************/
10341 WERROR _spoolss_61(struct pipes_struct *p,
10342 struct spoolss_61 *r)
10344 p->rng_fault_state = true;
10345 return WERR_NOT_SUPPORTED;
10348 /****************************************************************
10350 ****************************************************************/
10352 WERROR _spoolss_62(struct pipes_struct *p,
10353 struct spoolss_62 *r)
10355 p->rng_fault_state = true;
10356 return WERR_NOT_SUPPORTED;
10359 /****************************************************************
10361 ****************************************************************/
10363 WERROR _spoolss_63(struct pipes_struct *p,
10364 struct spoolss_63 *r)
10366 p->rng_fault_state = true;
10367 return WERR_NOT_SUPPORTED;
10370 /****************************************************************
10372 ****************************************************************/
10374 WERROR _spoolss_64(struct pipes_struct *p,
10375 struct spoolss_64 *r)
10377 p->rng_fault_state = true;
10378 return WERR_NOT_SUPPORTED;
10381 /****************************************************************
10383 ****************************************************************/
10385 WERROR _spoolss_65(struct pipes_struct *p,
10386 struct spoolss_65 *r)
10388 p->rng_fault_state = true;
10389 return WERR_NOT_SUPPORTED;
10392 /****************************************************************
10393 _spoolss_GetCorePrinterDrivers
10394 ****************************************************************/
10396 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10397 struct spoolss_GetCorePrinterDrivers *r)
10399 p->rng_fault_state = true;
10400 return WERR_NOT_SUPPORTED;
10403 /****************************************************************
10405 ****************************************************************/
10407 WERROR _spoolss_67(struct pipes_struct *p,
10408 struct spoolss_67 *r)
10410 p->rng_fault_state = true;
10411 return WERR_NOT_SUPPORTED;
10414 /****************************************************************
10415 _spoolss_GetPrinterDriverPackagePath
10416 ****************************************************************/
10418 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10419 struct spoolss_GetPrinterDriverPackagePath *r)
10421 p->rng_fault_state = true;
10422 return WERR_NOT_SUPPORTED;
10425 /****************************************************************
10427 ****************************************************************/
10429 WERROR _spoolss_69(struct pipes_struct *p,
10430 struct spoolss_69 *r)
10432 p->rng_fault_state = true;
10433 return WERR_NOT_SUPPORTED;
10436 /****************************************************************
10438 ****************************************************************/
10440 WERROR _spoolss_6a(struct pipes_struct *p,
10441 struct spoolss_6a *r)
10443 p->rng_fault_state = true;
10444 return WERR_NOT_SUPPORTED;
10447 /****************************************************************
10449 ****************************************************************/
10451 WERROR _spoolss_6b(struct pipes_struct *p,
10452 struct spoolss_6b *r)
10454 p->rng_fault_state = true;
10455 return WERR_NOT_SUPPORTED;
10458 /****************************************************************
10460 ****************************************************************/
10462 WERROR _spoolss_6c(struct pipes_struct *p,
10463 struct spoolss_6c *r)
10465 p->rng_fault_state = true;
10466 return WERR_NOT_SUPPORTED;
10469 /****************************************************************
10471 ****************************************************************/
10473 WERROR _spoolss_6d(struct pipes_struct *p,
10474 struct spoolss_6d *r)
10476 p->rng_fault_state = true;
10477 return WERR_NOT_SUPPORTED;