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, struct security_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, struct security_token *token,
361 const char *sharename,
362 struct messaging_context *msg_ctx)
364 char *cmd = lp_deleteprinter_cmd();
365 char *command = NULL;
367 bool is_print_op = false;
369 /* can't fail if we don't try */
374 command = talloc_asprintf(ctx,
381 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
383 DEBUG(10,("Running [%s]\n", command));
385 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
390 if ( (ret = smbrun(command, NULL)) == 0 ) {
391 /* Tell everyone we updated smb.conf. */
392 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
398 /********** END SePrintOperatorPrivlege BLOCK **********/
400 DEBUGADD(10,("returned [%d]\n", ret));
402 TALLOC_FREE(command);
405 return WERR_BADFID; /* What to return here? */
407 /* go ahead and re-read the services immediately */
409 reload_services(msg_ctx, -1, false);
412 if ( lp_servicenumber( sharename ) > 0 )
413 return WERR_ACCESS_DENIED;
418 /****************************************************************************
419 Delete a printer given a handle.
420 ****************************************************************************/
422 static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
424 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
428 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
434 * It turns out that Windows allows delete printer on a handle
435 * opened by an admin user, then used on a pipe handle created
436 * by an anonymous user..... but they're working on security.... riiight !
440 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
441 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
442 return WERR_ACCESS_DENIED;
445 /* this does not need a become root since the access check has been
446 done on the handle already */
448 result = winreg_delete_printer_key(p->mem_ctx,
449 get_server_info_system(),
453 if (!W_ERROR_IS_OK(result)) {
454 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
458 result = delete_printer_hook(p->mem_ctx, p->server_info->ptok,
459 Printer->sharename, p->msg_ctx);
460 if (!W_ERROR_IS_OK(result)) {
463 prune_printername_cache();
467 /****************************************************************************
468 Return the snum of a printer corresponding to an handle.
469 ****************************************************************************/
471 static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
472 int *number, struct share_params **params)
474 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
477 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
482 switch (Printer->printer_type) {
484 DEBUG(4,("short name:%s\n", Printer->sharename));
485 *number = print_queue_snum(Printer->sharename);
486 return (*number != -1);
494 /****************************************************************************
495 Set printer handle type.
496 Check if it's \\server or \\server\printer
497 ****************************************************************************/
499 static bool set_printer_hnd_printertype(struct printer_handle *Printer, const char *handlename)
501 DEBUG(3,("Setting printer type=%s\n", handlename));
503 /* it's a print server */
504 if (handlename && *handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
505 DEBUGADD(4,("Printer is a print server\n"));
506 Printer->printer_type = SPLHND_SERVER;
508 /* it's a printer (set_printer_hnd_name() will handle port monitors */
510 DEBUGADD(4,("Printer is a printer\n"));
511 Printer->printer_type = SPLHND_PRINTER;
517 static void prune_printername_cache_fn(const char *key, const char *value,
518 time_t timeout, void *private_data)
523 static void prune_printername_cache(void)
525 gencache_iterate(prune_printername_cache_fn, NULL, "PRINTERNAME/*");
528 /****************************************************************************
529 Set printer handle name.. Accept names like \\server, \\server\printer,
530 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
531 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
532 XcvDataPort() interface.
533 ****************************************************************************/
535 static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
536 const struct auth_serversupplied_info *server_info,
537 struct messaging_context *msg_ctx,
538 struct printer_handle *Printer,
539 const char *handlename)
542 int n_services=lp_numservices();
544 const char *printername;
545 const char *servername = NULL;
548 struct spoolss_PrinterInfo2 *info2 = NULL;
552 * Hopefully nobody names his printers like this. Maybe \ or ,
553 * are illegal in printer names even?
555 const char printer_not_found[] = "Printer \\, !@#$%^&*( not found";
559 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
560 (unsigned long)strlen(handlename)));
562 aprinter = CONST_DISCARD(char *, handlename);
563 if ( *handlename == '\\' ) {
564 servername = canon_servername(handlename);
565 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
569 if (!is_myname_or_ipaddr(servername)) {
573 fstrcpy(Printer->servername, servername);
576 if (Printer->printer_type == SPLHND_SERVER) {
580 if (Printer->printer_type != SPLHND_PRINTER) {
584 DEBUGADD(5, ("searching for [%s]\n", aprinter));
586 /* check for the Port Monitor Interface */
587 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
588 Printer->printer_type = SPLHND_PORTMON_TCP;
589 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
592 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
593 Printer->printer_type = SPLHND_PORTMON_LOCAL;
594 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
599 * With hundreds of printers, the "for" loop iterating all
600 * shares can be quite expensive, as it is done on every
601 * OpenPrinter. The loop maps "aprinter" to "sname", the
602 * result of which we cache in gencache.
605 cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
607 if ((cache_key != NULL) && gencache_get(cache_key, &tmp, NULL)) {
609 found = (strcmp(tmp, printer_not_found) != 0);
611 DEBUG(4, ("Printer %s not found\n", aprinter));
619 /* Search all sharenames first as this is easier than pulling
620 the printer_info_2 off of disk. Don't use find_service() since
621 that calls out to map_username() */
623 /* do another loop to look for printernames */
624 for (snum = 0; !found && snum < n_services; snum++) {
625 const char *printer = lp_const_servicename(snum);
627 /* no point going on if this is not a printer */
628 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
632 /* ignore [printers] share */
633 if (strequal(printer, "printers")) {
637 fstrcpy(sname, printer);
638 if (strequal(aprinter, printer)) {
643 /* no point looking up the printer object if
644 we aren't allowing printername != sharename */
645 if (lp_force_printername(snum)) {
649 result = winreg_get_printer(mem_ctx,
655 if ( !W_ERROR_IS_OK(result) ) {
656 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
657 sname, win_errstr(result)));
661 printername = strrchr(info2->printername, '\\');
662 if (printername == NULL) {
663 printername = info2->printername;
668 if (strequal(printername, aprinter)) {
673 DEBUGADD(10, ("printername: %s\n", printername));
679 if (cache_key != NULL) {
680 gencache_set(cache_key, printer_not_found,
682 TALLOC_FREE(cache_key);
684 DEBUGADD(4,("Printer not found\n"));
688 if (cache_key != NULL) {
689 gencache_set(cache_key, sname, time(NULL)+300);
690 TALLOC_FREE(cache_key);
693 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
695 fstrcpy(Printer->sharename, sname);
700 /****************************************************************************
701 Find first available printer slot. creates a printer handle for you.
702 ****************************************************************************/
704 static bool open_printer_hnd(struct pipes_struct *p, struct policy_handle *hnd,
705 const char *name, uint32_t access_granted)
707 struct printer_handle *new_printer;
709 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
711 new_printer = talloc_zero(p->mem_ctx, struct printer_handle);
712 if (new_printer == NULL) {
715 talloc_set_destructor(new_printer, printer_entry_destructor);
717 /* This also steals the printer_handle on the policy_handle */
718 if (!create_policy_hnd(p, hnd, new_printer)) {
719 TALLOC_FREE(new_printer);
723 /* Add to the internal list. */
724 DLIST_ADD(printers_list, new_printer);
726 new_printer->notify.option=NULL;
728 if (!set_printer_hnd_printertype(new_printer, name)) {
729 close_printer_handle(p, hnd);
733 if (!set_printer_hnd_name(p->mem_ctx,
734 get_server_info_system(),
736 new_printer, name)) {
737 close_printer_handle(p, hnd);
741 new_printer->access_granted = access_granted;
743 DEBUG(5, ("%d printer handles active\n",
744 (int)num_pipe_handles(p)));
749 /***************************************************************************
750 check to see if the client motify handle is monitoring the notification
751 given by (notify_type, notify_field).
752 **************************************************************************/
754 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
755 uint16_t notify_field)
760 static bool is_monitoring_event(struct printer_handle *p, uint16_t notify_type,
761 uint16_t notify_field)
763 struct spoolss_NotifyOption *option = p->notify.option;
767 * Flags should always be zero when the change notify
768 * is registered by the client's spooler. A user Win32 app
769 * might use the flags though instead of the NOTIFY_OPTION_INFO
778 return is_monitoring_event_flags(
779 p->notify.flags, notify_type, notify_field);
781 for (i = 0; i < option->count; i++) {
783 /* Check match for notify_type */
785 if (option->types[i].type != notify_type)
788 /* Check match for field */
790 for (j = 0; j < option->types[i].count; j++) {
791 if (option->types[i].fields[j].field == notify_field) {
797 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
798 p->servername, p->sharename, notify_type, notify_field));
803 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
804 _data->data.integer[0] = _integer; \
805 _data->data.integer[1] = 0;
808 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
809 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
810 if (!_data->data.string.string) {\
811 _data->data.string.size = 0; \
813 _data->data.string.size = strlen_m_term(_p) * 2;
815 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
816 _data->data.devmode.devmode = _devmode;
818 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
819 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
820 if (!_data->data.sd.sd) { \
821 _data->data.sd.sd_size = 0; \
823 _data->data.sd.sd_size = \
824 ndr_size_security_descriptor(_data->data.sd.sd, 0);
826 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
831 struct spoolss_Time st;
835 if (!init_systemtime(&st, t)) {
839 p = talloc_array(mem_ctx, char, len);
845 * Systemtime must be linearized as a set of UINT16's.
846 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
849 SSVAL(p, 0, st.year);
850 SSVAL(p, 2, st.month);
851 SSVAL(p, 4, st.day_of_week);
853 SSVAL(p, 8, st.hour);
854 SSVAL(p, 10, st.minute);
855 SSVAL(p, 12, st.second);
856 SSVAL(p, 14, st.millisecond);
862 /* Convert a notification message to a struct spoolss_Notify */
864 static void notify_one_value(struct spoolss_notify_msg *msg,
865 struct spoolss_Notify *data,
868 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
871 static void notify_string(struct spoolss_notify_msg *msg,
872 struct spoolss_Notify *data,
875 /* The length of the message includes the trailing \0 */
877 data->data.string.size = msg->len * 2;
878 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
879 if (!data->data.string.string) {
880 data->data.string.size = 0;
885 static void notify_system_time(struct spoolss_notify_msg *msg,
886 struct spoolss_Notify *data,
889 data->data.string.string = NULL;
890 data->data.string.size = 0;
892 if (msg->len != sizeof(time_t)) {
893 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
898 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
899 &data->data.string.string,
900 &data->data.string.size);
903 struct notify2_message_table {
905 void (*fn)(struct spoolss_notify_msg *msg,
906 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
909 static struct notify2_message_table printer_notify_table[] = {
910 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
911 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
912 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
913 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
914 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
915 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
916 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
917 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
918 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
919 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
920 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
921 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
922 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
923 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
924 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
925 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
926 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
927 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
928 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
931 static struct notify2_message_table job_notify_table[] = {
932 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
933 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
934 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
935 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
936 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
937 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
938 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
939 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
940 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
941 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
942 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
943 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
944 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
945 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
946 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
947 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
948 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
949 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
950 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
951 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
952 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
953 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
954 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
955 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
959 /***********************************************************************
960 Allocate talloc context for container object
961 **********************************************************************/
963 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
968 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
973 /***********************************************************************
974 release all allocated memory and zero out structure
975 **********************************************************************/
977 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
983 talloc_destroy(ctr->ctx);
990 /***********************************************************************
991 **********************************************************************/
993 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1001 /***********************************************************************
1002 **********************************************************************/
1004 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1006 if ( !ctr || !ctr->msg_groups )
1009 if ( idx >= ctr->num_groups )
1012 return &ctr->msg_groups[idx];
1016 /***********************************************************************
1017 How many groups of change messages do we have ?
1018 **********************************************************************/
1020 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1025 return ctr->num_groups;
1028 /***********************************************************************
1029 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1030 **********************************************************************/
1032 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
1034 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
1035 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
1036 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
1042 /* loop over all groups looking for a matching printer name */
1044 for ( i=0; i<ctr->num_groups; i++ ) {
1045 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
1049 /* add a new group? */
1051 if ( i == ctr->num_groups ) {
1054 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
1055 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1058 ctr->msg_groups = groups;
1060 /* clear the new entry and set the printer name */
1062 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
1063 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
1066 /* add the change messages; 'i' is the correct index now regardless */
1068 msg_grp = &ctr->msg_groups[i];
1070 msg_grp->num_msgs++;
1072 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
1073 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
1076 msg_grp->msgs = msg_list;
1078 new_slot = msg_grp->num_msgs-1;
1079 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
1081 /* need to allocate own copy of data */
1083 if ( msg->len != 0 )
1084 msg_grp->msgs[new_slot].notify.data = (char *)
1085 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
1087 return ctr->num_groups;
1090 static void construct_info_data(struct spoolss_Notify *info_data,
1091 enum spoolss_NotifyType type,
1092 uint16_t field, int id);
1094 /***********************************************************************
1095 Send a change notication message on all handles which have a call
1097 **********************************************************************/
1099 static int build_notify2_messages(TALLOC_CTX *mem_ctx,
1100 struct printer_handle *prn_hnd,
1101 SPOOLSS_NOTIFY_MSG *messages,
1103 struct spoolss_Notify **_notifies,
1106 struct spoolss_Notify *notifies;
1107 SPOOLSS_NOTIFY_MSG *msg;
1112 notifies = talloc_zero_array(mem_ctx,
1113 struct spoolss_Notify, num_msgs);
1118 for (i = 0; i < num_msgs; i++) {
1122 /* Are we monitoring this event? */
1124 if (!is_monitoring_event(prn_hnd, msg->type, msg->field)) {
1128 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1129 "for printer [%s]\n",
1130 msg->type, msg->field, prn_hnd->sharename));
1133 * if the is a printer notification handle and not a job
1134 * notification type, then set the id to 0.
1135 * Otherwise just use what was specified in the message.
1137 * When registering change notification on a print server
1138 * handle we always need to send back the id (snum) matching
1139 * the printer for which the change took place.
1140 * For change notify registered on a printer handle,
1141 * this does not matter and the id should be 0.
1146 if ((msg->type == PRINTER_NOTIFY_TYPE) &&
1147 (prn_hnd->printer_type == SPLHND_PRINTER)) {
1153 /* Convert unix jobid to smb jobid */
1155 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1156 id = sysjob_to_jobid(msg->id);
1159 DEBUG(3, ("no such unix jobid %d\n",
1165 construct_info_data(¬ifies[count],
1166 msg->type, msg->field, id);
1169 case PRINTER_NOTIFY_TYPE:
1170 if (printer_notify_table[msg->field].fn) {
1171 printer_notify_table[msg->field].fn(msg,
1172 ¬ifies[count], mem_ctx);
1176 case JOB_NOTIFY_TYPE:
1177 if (job_notify_table[msg->field].fn) {
1178 job_notify_table[msg->field].fn(msg,
1179 ¬ifies[count], mem_ctx);
1184 DEBUG(5, ("Unknown notification type %d\n",
1192 *_notifies = notifies;
1198 static int send_notify2_printer(TALLOC_CTX *mem_ctx,
1199 struct printer_handle *prn_hnd,
1200 SPOOLSS_NOTIFY_MSG_GROUP *msg_group)
1202 struct spoolss_Notify *notifies;
1204 union spoolss_ReplyPrinterInfo info;
1205 struct spoolss_NotifyInfo info0;
1206 uint32_t reply_result;
1211 /* Is there notification on this handle? */
1212 if (prn_hnd->notify.cli_chan == NULL ||
1213 prn_hnd->notify.cli_chan->active_connections == 0) {
1217 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1218 prn_hnd->servername, prn_hnd->sharename));
1220 /* For this printer? Print servers always receive notifications. */
1221 if ((prn_hnd->printer_type == SPLHND_PRINTER) &&
1222 (!strequal(msg_group->printername, prn_hnd->sharename))) {
1226 DEBUG(10,("Our printer\n"));
1228 /* build the array of change notifications */
1229 ret = build_notify2_messages(mem_ctx, prn_hnd,
1231 msg_group->num_msgs,
1237 info0.version = 0x2;
1238 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1239 info0.count = count;
1240 info0.notifies = notifies;
1242 info.info0 = &info0;
1244 status = rpccli_spoolss_RouterReplyPrinterEx(
1245 prn_hnd->notify.cli_chan->cli_pipe,
1247 &prn_hnd->notify.cli_hnd,
1248 prn_hnd->notify.change, /* color */
1249 prn_hnd->notify.flags,
1251 0, /* reply_type, must be 0 */
1253 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1254 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1256 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1259 switch (reply_result) {
1262 case PRINTER_NOTIFY_INFO_DISCARDED:
1263 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1264 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1273 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1275 struct printer_handle *p;
1276 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
1277 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
1281 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1285 if (!msg_group->msgs) {
1286 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1290 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
1292 /* loop over all printers */
1294 for (p = printers_list; p; p = p->next) {
1295 ret = send_notify2_printer(mem_ctx, p, msg_group);
1302 DEBUG(8,("send_notify2_changes: Exit...\n"));
1306 /***********************************************************************
1307 **********************************************************************/
1309 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1312 uint32_t tv_sec, tv_usec;
1315 /* Unpack message */
1317 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1320 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1322 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1325 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1326 &msg->notify.value[0], &msg->notify.value[1]);
1328 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1329 &msg->len, &msg->notify.data);
1331 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1332 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1334 tv->tv_sec = tv_sec;
1335 tv->tv_usec = tv_usec;
1338 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1339 msg->notify.value[1]));
1341 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1346 /********************************************************************
1347 Receive a notify2 message list
1348 ********************************************************************/
1350 static void receive_notify2_message_list(struct messaging_context *msg,
1353 struct server_id server_id,
1356 size_t msg_count, i;
1357 char *buf = (char *)data->data;
1360 SPOOLSS_NOTIFY_MSG notify;
1361 SPOOLSS_NOTIFY_MSG_CTR messages;
1364 if (data->length < 4) {
1365 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1369 msg_count = IVAL(buf, 0);
1372 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1374 if (msg_count == 0) {
1375 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1379 /* initialize the container */
1381 ZERO_STRUCT( messages );
1382 notify_msg_ctr_init( &messages );
1385 * build message groups for each printer identified
1386 * in a change_notify msg. Remember that a PCN message
1387 * includes the handle returned for the srv_spoolss_replyopenprinter()
1388 * call. Therefore messages are grouped according to printer handle.
1391 for ( i=0; i<msg_count; i++ ) {
1392 struct timeval msg_tv;
1394 if (msg_ptr + 4 - buf > data->length) {
1395 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1399 msg_len = IVAL(msg_ptr,0);
1402 if (msg_ptr + msg_len - buf > data->length) {
1403 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1407 /* unpack messages */
1409 ZERO_STRUCT( notify );
1410 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1413 /* add to correct list in container */
1415 notify_msg_ctr_addmsg( &messages, ¬ify );
1417 /* free memory that might have been allocated by notify2_unpack_msg() */
1419 if ( notify.len != 0 )
1420 SAFE_FREE( notify.notify.data );
1423 /* process each group of messages */
1425 num_groups = notify_msg_ctr_numgroups( &messages );
1426 for ( i=0; i<num_groups; i++ )
1427 send_notify2_changes( &messages, i );
1432 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1433 (uint32_t)msg_count ));
1435 notify_msg_ctr_destroy( &messages );
1440 /********************************************************************
1441 Send a message to ourself about new driver being installed
1442 so we can upgrade the information for each printer bound to this
1444 ********************************************************************/
1446 static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
1447 struct messaging_context *msg_ctx)
1449 int len = strlen(drivername);
1454 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1457 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
1458 MSG_PRINTER_DRVUPGRADE,
1459 (uint8_t *)drivername, len+1);
1464 void srv_spoolss_cleanup(void)
1466 struct printer_session_counter *session_counter;
1468 for (session_counter = counter_list;
1469 session_counter != NULL;
1470 session_counter = counter_list) {
1471 DLIST_REMOVE(counter_list, session_counter);
1472 TALLOC_FREE(session_counter);
1476 /**********************************************************************
1477 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1478 over all printers, upgrading ones as necessary
1479 **********************************************************************/
1481 void do_drv_upgrade_printer(struct messaging_context *msg,
1484 struct server_id server_id,
1487 TALLOC_CTX *tmp_ctx;
1488 struct auth_serversupplied_info *server_info = NULL;
1489 struct spoolss_PrinterInfo2 *pinfo2;
1492 const char *drivername;
1494 int n_services = lp_numservices();
1497 tmp_ctx = talloc_new(NULL);
1498 if (!tmp_ctx) return;
1500 status = make_server_info_system(tmp_ctx, &server_info);
1501 if (!NT_STATUS_IS_OK(status)) {
1502 DEBUG(0, ("do_drv_upgrade_printer: "
1503 "Could not create system server_info\n"));
1507 len = MIN(data->length,sizeof(drivername)-1);
1508 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, len);
1510 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1514 DEBUG(10, ("do_drv_upgrade_printer: "
1515 "Got message for new driver [%s]\n", drivername));
1517 /* Iterate the printer list */
1519 for (snum = 0; snum < n_services; snum++) {
1520 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1524 result = winreg_get_printer(tmp_ctx, server_info, msg,
1526 lp_const_servicename(snum),
1529 if (!W_ERROR_IS_OK(result)) {
1533 if (!pinfo2->drivername) {
1537 if (strcmp(drivername, pinfo2->drivername) != 0) {
1541 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1543 /* all we care about currently is the change_id */
1544 result = winreg_printer_update_changeid(tmp_ctx,
1547 pinfo2->printername);
1549 if (!W_ERROR_IS_OK(result)) {
1550 DEBUG(3, ("do_drv_upgrade_printer: "
1551 "Failed to update changeid [%s]\n",
1552 win_errstr(result)));
1558 talloc_free(tmp_ctx);
1561 /********************************************************************
1562 Update the cache for all printq's with a registered client
1564 ********************************************************************/
1566 void update_monitored_printq_cache(struct messaging_context *msg_ctx)
1568 struct printer_handle *printer = printers_list;
1571 /* loop through all printers and update the cache where
1572 a client is connected */
1574 if ((printer->printer_type == SPLHND_PRINTER) &&
1575 ((printer->notify.cli_chan != NULL) &&
1576 (printer->notify.cli_chan->active_connections > 0))) {
1577 snum = print_queue_snum(printer->sharename);
1578 print_queue_status(msg_ctx, snum, NULL, NULL);
1581 printer = printer->next;
1587 /****************************************************************
1588 _spoolss_OpenPrinter
1589 ****************************************************************/
1591 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1592 struct spoolss_OpenPrinter *r)
1594 struct spoolss_OpenPrinterEx e;
1597 ZERO_STRUCT(e.in.userlevel);
1599 e.in.printername = r->in.printername;
1600 e.in.datatype = r->in.datatype;
1601 e.in.devmode_ctr = r->in.devmode_ctr;
1602 e.in.access_mask = r->in.access_mask;
1605 e.out.handle = r->out.handle;
1607 werr = _spoolss_OpenPrinterEx(p, &e);
1609 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1610 /* OpenPrinterEx returns this for a bad
1611 * printer name. We must return WERR_INVALID_PRINTER_NAME
1614 werr = WERR_INVALID_PRINTER_NAME;
1620 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1621 struct spoolss_DeviceMode *orig,
1622 struct spoolss_DeviceMode **dest)
1624 struct spoolss_DeviceMode *dm;
1626 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1631 /* copy all values, then duplicate strings and structs */
1634 dm->devicename = talloc_strdup(dm, orig->devicename);
1635 if (!dm->devicename) {
1638 dm->formname = talloc_strdup(dm, orig->formname);
1639 if (!dm->formname) {
1642 if (orig->driverextra_data.data) {
1643 dm->driverextra_data.data =
1644 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1645 orig->driverextra_data.length);
1646 if (!dm->driverextra_data.data) {
1655 /****************************************************************
1656 _spoolss_OpenPrinterEx
1657 ****************************************************************/
1659 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1660 struct spoolss_OpenPrinterEx *r)
1663 struct printer_handle *Printer=NULL;
1665 if (!r->in.printername) {
1666 return WERR_INVALID_PARAM;
1669 /* some sanity check because you can open a printer or a print server */
1670 /* aka: \\server\printer or \\server */
1672 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1674 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1675 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1676 "for printer %s\n", r->in.printername));
1677 ZERO_STRUCTP(r->out.handle);
1678 return WERR_INVALID_PARAM;
1681 Printer = find_printer_index_by_hnd(p, r->out.handle);
1683 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1684 "handle we created for printer %s\n", r->in.printername));
1685 close_printer_handle(p, r->out.handle);
1686 ZERO_STRUCTP(r->out.handle);
1687 return WERR_INVALID_PARAM;
1691 * First case: the user is opening the print server:
1693 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1694 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1696 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1697 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1698 * or if the user is listed in the smb.conf printer admin parameter.
1700 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1701 * client view printer folder, but does not show the MSAPW.
1703 * Note: this test needs code to check access rights here too. Jeremy
1704 * could you look at this?
1706 * Second case: the user is opening a printer:
1707 * NT doesn't let us connect to a printer if the connecting user
1708 * doesn't have print permission.
1710 * Third case: user is opening a Port Monitor
1711 * access checks same as opening a handle to the print server.
1714 switch (Printer->printer_type )
1717 case SPLHND_PORTMON_TCP:
1718 case SPLHND_PORTMON_LOCAL:
1719 /* Printserver handles use global struct... */
1723 /* Map standard access rights to object specific access rights */
1725 se_map_standard(&r->in.access_mask,
1726 &printserver_std_mapping);
1728 /* Deny any object specific bits that don't apply to print
1729 servers (i.e printer and job specific bits) */
1731 r->in.access_mask &= SEC_MASK_SPECIFIC;
1733 if (r->in.access_mask &
1734 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1735 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1736 close_printer_handle(p, r->out.handle);
1737 ZERO_STRUCTP(r->out.handle);
1738 return WERR_ACCESS_DENIED;
1741 /* Allow admin access */
1743 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1745 if (!lp_ms_add_printer_wizard()) {
1746 close_printer_handle(p, r->out.handle);
1747 ZERO_STRUCTP(r->out.handle);
1748 return WERR_ACCESS_DENIED;
1751 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1752 and not a printer admin, then fail */
1754 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1755 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
1756 !token_contains_name_in_list(
1757 uidtoname(p->server_info->utok.uid),
1758 p->server_info->info3->base.domain.string,
1760 p->server_info->ptok,
1761 lp_printer_admin(snum))) {
1762 close_printer_handle(p, r->out.handle);
1763 ZERO_STRUCTP(r->out.handle);
1764 return WERR_ACCESS_DENIED;
1767 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1771 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1774 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1775 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1777 /* We fall through to return WERR_OK */
1780 case SPLHND_PRINTER:
1781 /* NT doesn't let us connect to a printer if the connecting user
1782 doesn't have print permission. */
1784 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1785 close_printer_handle(p, r->out.handle);
1786 ZERO_STRUCTP(r->out.handle);
1790 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1791 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1794 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1796 /* map an empty access mask to the minimum access mask */
1797 if (r->in.access_mask == 0x0)
1798 r->in.access_mask = PRINTER_ACCESS_USE;
1801 * If we are not serving the printer driver for this printer,
1802 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1803 * will keep NT clients happy --jerry
1806 if (lp_use_client_driver(snum)
1807 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1809 r->in.access_mask = PRINTER_ACCESS_USE;
1812 /* check smb.conf parameters and the the sec_desc */
1814 if (!allow_access(lp_hostsdeny(snum), lp_hostsallow(snum),
1815 p->client_id->name, p->client_id->addr)) {
1816 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1817 ZERO_STRUCTP(r->out.handle);
1818 return WERR_ACCESS_DENIED;
1821 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1822 p->server_info->ptok, snum) ||
1823 !print_access_check(get_server_info_system(),
1826 r->in.access_mask)) {
1827 DEBUG(3, ("access DENIED for printer open\n"));
1828 close_printer_handle(p, r->out.handle);
1829 ZERO_STRUCTP(r->out.handle);
1830 return WERR_ACCESS_DENIED;
1833 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1834 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1835 close_printer_handle(p, r->out.handle);
1836 ZERO_STRUCTP(r->out.handle);
1837 return WERR_ACCESS_DENIED;
1840 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1841 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1843 r->in.access_mask = PRINTER_ACCESS_USE;
1845 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1846 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1848 winreg_create_printer(p->mem_ctx,
1849 get_server_info_system(),
1851 Printer->servername,
1852 lp_const_servicename(snum));
1857 /* sanity check to prevent programmer error */
1858 ZERO_STRUCTP(r->out.handle);
1862 Printer->access_granted = r->in.access_mask;
1865 * If the client sent a devmode in the OpenPrinter() call, then
1866 * save it here in case we get a job submission on this handle
1869 if ((Printer->printer_type != SPLHND_SERVER) &&
1870 r->in.devmode_ctr.devmode) {
1871 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1875 #if 0 /* JERRY -- I'm doubtful this is really effective */
1876 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1877 optimization in Windows 2000 clients --jerry */
1879 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1880 && (RA_WIN2K == get_remote_arch()) )
1882 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1883 sys_usleep( 500000 );
1890 /****************************************************************
1891 _spoolss_ClosePrinter
1892 ****************************************************************/
1894 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1895 struct spoolss_ClosePrinter *r)
1897 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1899 if (Printer && Printer->document_started) {
1900 struct spoolss_EndDocPrinter e;
1902 e.in.handle = r->in.handle;
1904 _spoolss_EndDocPrinter(p, &e);
1907 if (!close_printer_handle(p, r->in.handle))
1910 /* clear the returned printer handle. Observed behavior
1911 from Win2k server. Don't think this really matters.
1912 Previous code just copied the value of the closed
1915 ZERO_STRUCTP(r->out.handle);
1920 /****************************************************************
1921 _spoolss_DeletePrinter
1922 ****************************************************************/
1924 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1925 struct spoolss_DeletePrinter *r)
1927 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1931 if (Printer && Printer->document_started) {
1932 struct spoolss_EndDocPrinter e;
1934 e.in.handle = r->in.handle;
1936 _spoolss_EndDocPrinter(p, &e);
1939 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
1940 winreg_delete_printer_key(p->mem_ctx,
1941 get_server_info_system(),
1943 lp_const_servicename(snum),
1947 result = delete_printer_handle(p, r->in.handle);
1952 /*******************************************************************
1953 * static function to lookup the version id corresponding to an
1954 * long architecture string
1955 ******************************************************************/
1957 static const struct print_architecture_table_node archi_table[]= {
1959 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1960 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1961 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1962 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
1963 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
1964 {"Windows IA64", SPL_ARCH_IA64, 3 },
1965 {"Windows x64", SPL_ARCH_X64, 3 },
1969 static int get_version_id(const char *arch)
1973 for (i=0; archi_table[i].long_archi != NULL; i++)
1975 if (strcmp(arch, archi_table[i].long_archi) == 0)
1976 return (archi_table[i].version);
1982 /****************************************************************
1983 _spoolss_DeletePrinterDriver
1984 ****************************************************************/
1986 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
1987 struct spoolss_DeletePrinterDriver *r)
1990 struct spoolss_DriverInfo8 *info = NULL;
1991 struct spoolss_DriverInfo8 *info_win2k = NULL;
1995 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1996 and not a printer admin, then fail */
1998 if ( (p->server_info->utok.uid != sec_initial_uid())
1999 && !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR)
2000 && !token_contains_name_in_list(
2001 uidtoname(p->server_info->utok.uid),
2002 p->server_info->info3->base.domain.string,
2004 p->server_info->ptok,
2005 lp_printer_admin(-1)) )
2007 return WERR_ACCESS_DENIED;
2010 /* check that we have a valid driver name first */
2012 if ((version = get_version_id(r->in.architecture)) == -1)
2013 return WERR_INVALID_ENVIRONMENT;
2015 status = winreg_get_driver(p->mem_ctx,
2016 get_server_info_system(),
2018 r->in.architecture, r->in.driver,
2020 if (!W_ERROR_IS_OK(status)) {
2021 /* try for Win2k driver if "Windows NT x86" */
2023 if ( version == 2 ) {
2026 status = winreg_get_driver(p->mem_ctx,
2027 get_server_info_system(),
2032 if (!W_ERROR_IS_OK(status)) {
2033 status = WERR_UNKNOWN_PRINTER_DRIVER;
2037 /* otherwise it was a failure */
2039 status = WERR_UNKNOWN_PRINTER_DRIVER;
2045 if (printer_driver_in_use(p->mem_ctx,
2046 get_server_info_system(),
2049 status = WERR_PRINTER_DRIVER_IN_USE;
2054 status = winreg_get_driver(p->mem_ctx,
2055 get_server_info_system(),
2058 r->in.driver, 3, &info_win2k);
2059 if (W_ERROR_IS_OK(status)) {
2060 /* if we get to here, we now have 2 driver info structures to remove */
2061 /* remove the Win2k driver first*/
2063 status = winreg_del_driver(p->mem_ctx,
2064 get_server_info_system(),
2067 talloc_free(info_win2k);
2069 /* this should not have failed---if it did, report to client */
2070 if (!W_ERROR_IS_OK(status)) {
2076 status = winreg_del_driver(p->mem_ctx,
2077 get_server_info_system(),
2087 /****************************************************************
2088 _spoolss_DeletePrinterDriverEx
2089 ****************************************************************/
2091 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
2092 struct spoolss_DeletePrinterDriverEx *r)
2094 struct spoolss_DriverInfo8 *info = NULL;
2095 struct spoolss_DriverInfo8 *info_win2k = NULL;
2100 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2101 and not a printer admin, then fail */
2103 if ( (p->server_info->utok.uid != sec_initial_uid())
2104 && !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR)
2105 && !token_contains_name_in_list(
2106 uidtoname(p->server_info->utok.uid),
2107 p->server_info->info3->base.domain.string,
2109 p->server_info->ptok, lp_printer_admin(-1)) )
2111 return WERR_ACCESS_DENIED;
2114 /* check that we have a valid driver name first */
2115 if ((version = get_version_id(r->in.architecture)) == -1) {
2116 /* this is what NT returns */
2117 return WERR_INVALID_ENVIRONMENT;
2120 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2121 version = r->in.version;
2123 status = winreg_get_driver(p->mem_ctx,
2124 get_server_info_system(),
2130 if (!W_ERROR_IS_OK(status)) {
2131 status = WERR_UNKNOWN_PRINTER_DRIVER;
2134 * if the client asked for a specific version,
2135 * or this is something other than Windows NT x86,
2139 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2142 /* try for Win2k driver if "Windows NT x86" */
2145 status = winreg_get_driver(info,
2146 get_server_info_system(),
2151 if (!W_ERROR_IS_OK(status)) {
2152 status = WERR_UNKNOWN_PRINTER_DRIVER;
2157 if (printer_driver_in_use(info,
2158 get_server_info_system(),
2161 status = WERR_PRINTER_DRIVER_IN_USE;
2166 * we have a couple of cases to consider.
2167 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2168 * then the delete should fail if **any** files overlap with
2170 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2171 * non-overlapping files
2172 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2173 * is set, the do not delete any files
2174 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2177 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2179 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2182 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2183 printer_driver_files_in_use(info,
2184 get_server_info_system(),
2187 /* no idea of the correct error here */
2188 status = WERR_ACCESS_DENIED;
2193 /* also check for W32X86/3 if necessary; maybe we already have? */
2195 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2196 status = winreg_get_driver(info,
2197 get_server_info_system(),
2200 r->in.driver, 3, &info_win2k);
2201 if (W_ERROR_IS_OK(status)) {
2204 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2205 printer_driver_files_in_use(info,
2206 get_server_info_system(),
2209 /* no idea of the correct error here */
2210 talloc_free(info_win2k);
2211 status = WERR_ACCESS_DENIED;
2215 /* if we get to here, we now have 2 driver info structures to remove */
2216 /* remove the Win2k driver first*/
2218 status = winreg_del_driver(info,
2219 get_server_info_system(),
2224 /* this should not have failed---if it did, report to client */
2226 if (!W_ERROR_IS_OK(status)) {
2231 * now delete any associated files if delete_files is
2232 * true. Even if this part failes, we return succes
2233 * because the driver doesn not exist any more
2236 delete_driver_files(get_server_info_system(),
2242 status = winreg_del_driver(info,
2243 get_server_info_system(),
2247 if (!W_ERROR_IS_OK(status)) {
2252 * now delete any associated files if delete_files is
2253 * true. Even if this part failes, we return succes
2254 * because the driver doesn not exist any more
2257 delete_driver_files(get_server_info_system(), info);
2266 /********************************************************************
2267 GetPrinterData on a printer server Handle.
2268 ********************************************************************/
2270 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2272 enum winreg_Type *type,
2273 union spoolss_PrinterData *data)
2275 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2277 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2283 if (!StrCaseCmp(value, "BeepEnabled")) {
2289 if (!StrCaseCmp(value, "EventLog")) {
2291 /* formally was 0x1b */
2296 if (!StrCaseCmp(value, "NetPopup")) {
2302 if (!StrCaseCmp(value, "MajorVersion")) {
2305 /* Windows NT 4.0 seems to not allow uploading of drivers
2306 to a server that reports 0x3 as the MajorVersion.
2307 need to investigate more how Win2k gets around this .
2310 if (RA_WINNT == get_remote_arch()) {
2319 if (!StrCaseCmp(value, "MinorVersion")) {
2326 * uint32_t size = 0x114
2327 * uint32_t major = 5
2328 * uint32_t minor = [0|1]
2329 * uint32_t build = [2195|2600]
2330 * extra unicode string = e.g. "Service Pack 3"
2332 if (!StrCaseCmp(value, "OSVersion")) {
2334 enum ndr_err_code ndr_err;
2335 struct spoolss_OSVersion os;
2337 os.major = 5; /* Windows 2000 == 5.0 */
2339 os.build = 2195; /* build */
2340 os.extra_string = ""; /* leave extra string empty */
2342 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2343 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2344 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2345 return WERR_GENERAL_FAILURE;
2349 data->binary = blob;
2355 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2358 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2359 W_ERROR_HAVE_NO_MEMORY(data->string);
2364 if (!StrCaseCmp(value, "Architecture")) {
2366 data->string = talloc_strdup(mem_ctx,
2367 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2368 W_ERROR_HAVE_NO_MEMORY(data->string);
2373 if (!StrCaseCmp(value, "DsPresent")) {
2376 /* only show the publish check box if we are a
2377 member of a AD domain */
2379 if (lp_security() == SEC_ADS) {
2387 if (!StrCaseCmp(value, "DNSMachineName")) {
2388 const char *hostname = get_mydnsfullname();
2391 return WERR_BADFILE;
2395 data->string = talloc_strdup(mem_ctx, hostname);
2396 W_ERROR_HAVE_NO_MEMORY(data->string);
2403 return WERR_INVALID_PARAM;
2406 /****************************************************************
2407 _spoolss_GetPrinterData
2408 ****************************************************************/
2410 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2411 struct spoolss_GetPrinterData *r)
2413 struct spoolss_GetPrinterDataEx r2;
2415 r2.in.handle = r->in.handle;
2416 r2.in.key_name = "PrinterDriverData";
2417 r2.in.value_name = r->in.value_name;
2418 r2.in.offered = r->in.offered;
2419 r2.out.type = r->out.type;
2420 r2.out.data = r->out.data;
2421 r2.out.needed = r->out.needed;
2423 return _spoolss_GetPrinterDataEx(p, &r2);
2426 /*********************************************************
2427 Connect to the client machine.
2428 **********************************************************/
2430 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2431 struct sockaddr_storage *client_ss, const char *remote_machine)
2434 struct cli_state *the_cli;
2435 struct sockaddr_storage rm_addr;
2436 char addr[INET6_ADDRSTRLEN];
2438 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2439 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2441 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2442 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2445 print_sockaddr(addr, sizeof(addr), &rm_addr);
2447 rm_addr = *client_ss;
2448 print_sockaddr(addr, sizeof(addr), &rm_addr);
2449 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2453 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2454 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2459 /* setup the connection */
2460 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2461 &rm_addr, 0, "IPC$", "IPC",
2465 0, lp_client_signing(), NULL );
2467 if ( !NT_STATUS_IS_OK( ret ) ) {
2468 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2473 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2474 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2475 cli_shutdown(the_cli);
2480 * Ok - we have an anonymous connection to the IPC$ share.
2481 * Now start the NT Domain stuff :-).
2484 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2485 if (!NT_STATUS_IS_OK(ret)) {
2486 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2487 remote_machine, nt_errstr(ret)));
2488 cli_shutdown(the_cli);
2495 /***************************************************************************
2496 Connect to the client.
2497 ****************************************************************************/
2499 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2500 uint32_t localprinter,
2501 enum winreg_Type type,
2502 struct policy_handle *handle,
2503 struct notify_back_channel **_chan,
2504 struct sockaddr_storage *client_ss,
2505 struct messaging_context *msg_ctx)
2509 struct notify_back_channel *chan;
2511 for (chan = back_channels; chan; chan = chan->next) {
2512 if (memcmp(&chan->client_address, client_ss,
2513 sizeof(struct sockaddr_storage)) == 0) {
2519 * If it's the first connection, contact the client
2520 * and connect to the IPC$ share anonymously
2523 fstring unix_printer;
2525 /* the +2 is to strip the leading 2 backslashs */
2526 fstrcpy(unix_printer, printer + 2);
2528 chan = talloc_zero(back_channels, struct notify_back_channel);
2532 chan->client_address = *client_ss;
2534 if (!spoolss_connect_to_client(&chan->cli_pipe, client_ss, unix_printer)) {
2539 DLIST_ADD(back_channels, chan);
2541 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2542 receive_notify2_message_list);
2543 /* Tell the connections db we're now interested in printer
2544 * notify messages. */
2545 serverid_register_msg_flags(messaging_server_id(msg_ctx),
2546 true, FLAG_MSG_PRINT_NOTIFY);
2550 * Tell the specific printing tdb we want messages for this printer
2551 * by registering our PID.
2554 if (!print_notify_register_pid(snum)) {
2555 DEBUG(0, ("Failed to register our pid for printer %s\n",
2559 status = rpccli_spoolss_ReplyOpenPrinter(chan->cli_pipe, talloc_tos(),
2567 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
2568 DEBUG(5, ("Client RPC returned [%s]\n", win_errstr(result)));
2571 chan->active_connections++;
2574 return (W_ERROR_IS_OK(result));
2577 /****************************************************************
2578 ****************************************************************/
2580 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2581 const struct spoolss_NotifyOption *r)
2583 struct spoolss_NotifyOption *option;
2590 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2597 if (!option->count) {
2601 option->types = talloc_zero_array(option,
2602 struct spoolss_NotifyOptionType, option->count);
2603 if (!option->types) {
2604 talloc_free(option);
2608 for (i=0; i < option->count; i++) {
2609 option->types[i] = r->types[i];
2611 if (option->types[i].count) {
2612 option->types[i].fields = talloc_zero_array(option,
2613 union spoolss_Field, option->types[i].count);
2614 if (!option->types[i].fields) {
2615 talloc_free(option);
2618 for (k=0; k<option->types[i].count; k++) {
2619 option->types[i].fields[k] =
2620 r->types[i].fields[k];
2628 /****************************************************************
2629 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2631 * before replying OK: status=0 a rpc call is made to the workstation
2632 * asking ReplyOpenPrinter
2634 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2635 * called from api_spoolss_rffpcnex
2636 ****************************************************************/
2638 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2639 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2642 struct spoolss_NotifyOption *option = r->in.notify_options;
2643 struct sockaddr_storage client_ss;
2645 /* store the notify value in the printer struct */
2647 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2650 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2651 "Invalid handle (%s:%u:%u).\n",
2652 OUR_HANDLE(r->in.handle)));
2656 Printer->notify.flags = r->in.flags;
2657 Printer->notify.options = r->in.options;
2658 Printer->notify.printerlocal = r->in.printer_local;
2659 Printer->notify.msg_ctx = p->msg_ctx;
2661 TALLOC_FREE(Printer->notify.option);
2662 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2664 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2666 /* Connect to the client machine and send a ReplyOpenPrinter */
2668 if ( Printer->printer_type == SPLHND_SERVER)
2670 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2671 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2674 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2675 "client_address is %s\n", p->client_id->addr));
2677 if (!interpret_string_addr(&client_ss, p->client_id->addr,
2679 return WERR_SERVER_UNAVAILABLE;
2682 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2683 Printer->notify.printerlocal, REG_SZ,
2684 &Printer->notify.cli_hnd,
2685 &Printer->notify.cli_chan,
2686 &client_ss, p->msg_ctx)) {
2687 return WERR_SERVER_UNAVAILABLE;
2693 /*******************************************************************
2694 * fill a notify_info_data with the servername
2695 ********************************************************************/
2697 static void spoolss_notify_server_name(struct messaging_context *msg_ctx,
2699 struct spoolss_Notify *data,
2700 print_queue_struct *queue,
2701 struct spoolss_PrinterInfo2 *pinfo2,
2702 TALLOC_CTX *mem_ctx)
2704 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2707 /*******************************************************************
2708 * fill a notify_info_data with the printername (not including the servername).
2709 ********************************************************************/
2711 static void spoolss_notify_printer_name(struct messaging_context *msg_ctx,
2713 struct spoolss_Notify *data,
2714 print_queue_struct *queue,
2715 struct spoolss_PrinterInfo2 *pinfo2,
2716 TALLOC_CTX *mem_ctx)
2718 /* the notify name should not contain the \\server\ part */
2719 const char *p = strrchr(pinfo2->printername, '\\');
2722 p = pinfo2->printername;
2727 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2730 /*******************************************************************
2731 * fill a notify_info_data with the servicename
2732 ********************************************************************/
2734 static void spoolss_notify_share_name(struct messaging_context *msg_ctx,
2736 struct spoolss_Notify *data,
2737 print_queue_struct *queue,
2738 struct spoolss_PrinterInfo2 *pinfo2,
2739 TALLOC_CTX *mem_ctx)
2741 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2744 /*******************************************************************
2745 * fill a notify_info_data with the port name
2746 ********************************************************************/
2748 static void spoolss_notify_port_name(struct messaging_context *msg_ctx,
2750 struct spoolss_Notify *data,
2751 print_queue_struct *queue,
2752 struct spoolss_PrinterInfo2 *pinfo2,
2753 TALLOC_CTX *mem_ctx)
2755 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2758 /*******************************************************************
2759 * fill a notify_info_data with the printername
2760 * but it doesn't exist, have to see what to do
2761 ********************************************************************/
2763 static void spoolss_notify_driver_name(struct messaging_context *msg_ctx,
2765 struct spoolss_Notify *data,
2766 print_queue_struct *queue,
2767 struct spoolss_PrinterInfo2 *pinfo2,
2768 TALLOC_CTX *mem_ctx)
2770 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2773 /*******************************************************************
2774 * fill a notify_info_data with the comment
2775 ********************************************************************/
2777 static void spoolss_notify_comment(struct messaging_context *msg_ctx,
2779 struct spoolss_Notify *data,
2780 print_queue_struct *queue,
2781 struct spoolss_PrinterInfo2 *pinfo2,
2782 TALLOC_CTX *mem_ctx)
2786 if (*pinfo2->comment == '\0') {
2787 p = lp_comment(snum);
2789 p = pinfo2->comment;
2792 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2795 /*******************************************************************
2796 * fill a notify_info_data with the comment
2797 * location = "Room 1, floor 2, building 3"
2798 ********************************************************************/
2800 static void spoolss_notify_location(struct messaging_context *msg_ctx,
2802 struct spoolss_Notify *data,
2803 print_queue_struct *queue,
2804 struct spoolss_PrinterInfo2 *pinfo2,
2805 TALLOC_CTX *mem_ctx)
2807 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
2810 /*******************************************************************
2811 * fill a notify_info_data with the device mode
2812 * jfm:xxxx don't to it for know but that's a real problem !!!
2813 ********************************************************************/
2815 static void spoolss_notify_devmode(struct messaging_context *msg_ctx,
2817 struct spoolss_Notify *data,
2818 print_queue_struct *queue,
2819 struct spoolss_PrinterInfo2 *pinfo2,
2820 TALLOC_CTX *mem_ctx)
2822 /* for a dummy implementation we have to zero the fields */
2823 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2826 /*******************************************************************
2827 * fill a notify_info_data with the separator file name
2828 ********************************************************************/
2830 static void spoolss_notify_sepfile(struct messaging_context *msg_ctx,
2832 struct spoolss_Notify *data,
2833 print_queue_struct *queue,
2834 struct spoolss_PrinterInfo2 *pinfo2,
2835 TALLOC_CTX *mem_ctx)
2837 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2840 /*******************************************************************
2841 * fill a notify_info_data with the print processor
2842 * jfm:xxxx return always winprint to indicate we don't do anything to it
2843 ********************************************************************/
2845 static void spoolss_notify_print_processor(struct messaging_context *msg_ctx,
2847 struct spoolss_Notify *data,
2848 print_queue_struct *queue,
2849 struct spoolss_PrinterInfo2 *pinfo2,
2850 TALLOC_CTX *mem_ctx)
2852 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2855 /*******************************************************************
2856 * fill a notify_info_data with the print processor options
2857 * jfm:xxxx send an empty string
2858 ********************************************************************/
2860 static void spoolss_notify_parameters(struct messaging_context *msg_ctx,
2862 struct spoolss_Notify *data,
2863 print_queue_struct *queue,
2864 struct spoolss_PrinterInfo2 *pinfo2,
2865 TALLOC_CTX *mem_ctx)
2867 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2870 /*******************************************************************
2871 * fill a notify_info_data with the data type
2872 * jfm:xxxx always send RAW as data type
2873 ********************************************************************/
2875 static void spoolss_notify_datatype(struct messaging_context *msg_ctx,
2877 struct spoolss_Notify *data,
2878 print_queue_struct *queue,
2879 struct spoolss_PrinterInfo2 *pinfo2,
2880 TALLOC_CTX *mem_ctx)
2882 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2885 /*******************************************************************
2886 * fill a notify_info_data with the security descriptor
2887 * jfm:xxxx send an null pointer to say no security desc
2888 * have to implement security before !
2889 ********************************************************************/
2891 static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
2893 struct spoolss_Notify *data,
2894 print_queue_struct *queue,
2895 struct spoolss_PrinterInfo2 *pinfo2,
2896 TALLOC_CTX *mem_ctx)
2898 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2901 /*******************************************************************
2902 * fill a notify_info_data with the attributes
2903 * jfm:xxxx a samba printer is always shared
2904 ********************************************************************/
2906 static void spoolss_notify_attributes(struct messaging_context *msg_ctx,
2908 struct spoolss_Notify *data,
2909 print_queue_struct *queue,
2910 struct spoolss_PrinterInfo2 *pinfo2,
2911 TALLOC_CTX *mem_ctx)
2913 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2916 /*******************************************************************
2917 * fill a notify_info_data with the priority
2918 ********************************************************************/
2920 static void spoolss_notify_priority(struct messaging_context *msg_ctx,
2922 struct spoolss_Notify *data,
2923 print_queue_struct *queue,
2924 struct spoolss_PrinterInfo2 *pinfo2,
2925 TALLOC_CTX *mem_ctx)
2927 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2930 /*******************************************************************
2931 * fill a notify_info_data with the default priority
2932 ********************************************************************/
2934 static void spoolss_notify_default_priority(struct messaging_context *msg_ctx,
2936 struct spoolss_Notify *data,
2937 print_queue_struct *queue,
2938 struct spoolss_PrinterInfo2 *pinfo2,
2939 TALLOC_CTX *mem_ctx)
2941 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
2944 /*******************************************************************
2945 * fill a notify_info_data with the start time
2946 ********************************************************************/
2948 static void spoolss_notify_start_time(struct messaging_context *msg_ctx,
2950 struct spoolss_Notify *data,
2951 print_queue_struct *queue,
2952 struct spoolss_PrinterInfo2 *pinfo2,
2953 TALLOC_CTX *mem_ctx)
2955 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
2958 /*******************************************************************
2959 * fill a notify_info_data with the until time
2960 ********************************************************************/
2962 static void spoolss_notify_until_time(struct messaging_context *msg_ctx,
2964 struct spoolss_Notify *data,
2965 print_queue_struct *queue,
2966 struct spoolss_PrinterInfo2 *pinfo2,
2967 TALLOC_CTX *mem_ctx)
2969 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
2972 /*******************************************************************
2973 * fill a notify_info_data with the status
2974 ********************************************************************/
2976 static void spoolss_notify_status(struct messaging_context *msg_ctx,
2978 struct spoolss_Notify *data,
2979 print_queue_struct *queue,
2980 struct spoolss_PrinterInfo2 *pinfo2,
2981 TALLOC_CTX *mem_ctx)
2983 print_status_struct status;
2985 print_queue_length(msg_ctx, snum, &status);
2986 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
2989 /*******************************************************************
2990 * fill a notify_info_data with the number of jobs queued
2991 ********************************************************************/
2993 static void spoolss_notify_cjobs(struct messaging_context *msg_ctx,
2995 struct spoolss_Notify *data,
2996 print_queue_struct *queue,
2997 struct spoolss_PrinterInfo2 *pinfo2,
2998 TALLOC_CTX *mem_ctx)
3000 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3001 data, print_queue_length(msg_ctx, snum, NULL));
3004 /*******************************************************************
3005 * fill a notify_info_data with the average ppm
3006 ********************************************************************/
3008 static void spoolss_notify_average_ppm(struct messaging_context *msg_ctx,
3010 struct spoolss_Notify *data,
3011 print_queue_struct *queue,
3012 struct spoolss_PrinterInfo2 *pinfo2,
3013 TALLOC_CTX *mem_ctx)
3015 /* always respond 8 pages per minutes */
3016 /* a little hard ! */
3017 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
3020 /*******************************************************************
3021 * fill a notify_info_data with username
3022 ********************************************************************/
3024 static void spoolss_notify_username(struct messaging_context *msg_ctx,
3026 struct spoolss_Notify *data,
3027 print_queue_struct *queue,
3028 struct spoolss_PrinterInfo2 *pinfo2,
3029 TALLOC_CTX *mem_ctx)
3031 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3034 /*******************************************************************
3035 * fill a notify_info_data with job status
3036 ********************************************************************/
3038 static void spoolss_notify_job_status(struct messaging_context *msg_ctx,
3040 struct spoolss_Notify *data,
3041 print_queue_struct *queue,
3042 struct spoolss_PrinterInfo2 *pinfo2,
3043 TALLOC_CTX *mem_ctx)
3045 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3048 /*******************************************************************
3049 * fill a notify_info_data with job name
3050 ********************************************************************/
3052 static void spoolss_notify_job_name(struct messaging_context *msg_ctx,
3054 struct spoolss_Notify *data,
3055 print_queue_struct *queue,
3056 struct spoolss_PrinterInfo2 *pinfo2,
3057 TALLOC_CTX *mem_ctx)
3059 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3062 /*******************************************************************
3063 * fill a notify_info_data with job status
3064 ********************************************************************/
3066 static void spoolss_notify_job_status_string(struct messaging_context *msg_ctx,
3068 struct spoolss_Notify *data,
3069 print_queue_struct *queue,
3070 struct spoolss_PrinterInfo2 *pinfo2,
3071 TALLOC_CTX *mem_ctx)
3074 * Now we're returning job status codes we just return a "" here. JRA.
3079 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3082 switch (queue->status) {
3087 p = ""; /* NT provides the paused string */
3096 #endif /* NO LONGER NEEDED. */
3098 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3101 /*******************************************************************
3102 * fill a notify_info_data with job time
3103 ********************************************************************/
3105 static void spoolss_notify_job_time(struct messaging_context *msg_ctx,
3107 struct spoolss_Notify *data,
3108 print_queue_struct *queue,
3109 struct spoolss_PrinterInfo2 *pinfo2,
3110 TALLOC_CTX *mem_ctx)
3112 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3115 /*******************************************************************
3116 * fill a notify_info_data with job size
3117 ********************************************************************/
3119 static void spoolss_notify_job_size(struct messaging_context *msg_ctx,
3121 struct spoolss_Notify *data,
3122 print_queue_struct *queue,
3123 struct spoolss_PrinterInfo2 *pinfo2,
3124 TALLOC_CTX *mem_ctx)
3126 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3129 /*******************************************************************
3130 * fill a notify_info_data with page info
3131 ********************************************************************/
3132 static void spoolss_notify_total_pages(struct messaging_context *msg_ctx,
3134 struct spoolss_Notify *data,
3135 print_queue_struct *queue,
3136 struct spoolss_PrinterInfo2 *pinfo2,
3137 TALLOC_CTX *mem_ctx)
3139 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3142 /*******************************************************************
3143 * fill a notify_info_data with pages printed info.
3144 ********************************************************************/
3145 static void spoolss_notify_pages_printed(struct messaging_context *msg_ctx,
3147 struct spoolss_Notify *data,
3148 print_queue_struct *queue,
3149 struct spoolss_PrinterInfo2 *pinfo2,
3150 TALLOC_CTX *mem_ctx)
3152 /* Add code when back-end tracks this */
3153 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3156 /*******************************************************************
3157 Fill a notify_info_data with job position.
3158 ********************************************************************/
3160 static void spoolss_notify_job_position(struct messaging_context *msg_ctx,
3162 struct spoolss_Notify *data,
3163 print_queue_struct *queue,
3164 struct spoolss_PrinterInfo2 *pinfo2,
3165 TALLOC_CTX *mem_ctx)
3167 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3170 /*******************************************************************
3171 Fill a notify_info_data with submitted time.
3172 ********************************************************************/
3174 static void spoolss_notify_submitted_time(struct messaging_context *msg_ctx,
3176 struct spoolss_Notify *data,
3177 print_queue_struct *queue,
3178 struct spoolss_PrinterInfo2 *pinfo2,
3179 TALLOC_CTX *mem_ctx)
3181 data->data.string.string = NULL;
3182 data->data.string.size = 0;
3184 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3185 &data->data.string.string,
3186 &data->data.string.size);
3190 struct s_notify_info_data_table
3192 enum spoolss_NotifyType type;
3195 enum spoolss_NotifyTable variable_type;
3196 void (*fn) (struct messaging_context *msg_ctx,
3197 int snum, struct spoolss_Notify *data,
3198 print_queue_struct *queue,
3199 struct spoolss_PrinterInfo2 *pinfo2,
3200 TALLOC_CTX *mem_ctx);
3203 /* A table describing the various print notification constants and
3204 whether the notification data is a pointer to a variable sized
3205 buffer, a one value uint32_t or a two value uint32_t. */
3207 static const struct s_notify_info_data_table notify_info_data_table[] =
3209 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3210 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3211 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3212 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3213 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3214 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3215 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3216 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3217 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3218 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3219 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3220 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3221 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3222 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3223 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3224 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3225 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3226 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3227 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3228 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3229 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3230 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3231 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3232 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3233 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3234 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3235 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3236 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3237 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3238 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3239 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3240 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3241 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3242 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3243 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3244 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3245 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3246 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3247 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3248 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3249 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3250 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3251 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3252 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3253 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3254 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3255 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3256 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3257 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3260 /*******************************************************************
3261 Return the variable_type of info_data structure.
3262 ********************************************************************/
3264 static enum spoolss_NotifyTable variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3269 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3270 if ( (notify_info_data_table[i].type == type) &&
3271 (notify_info_data_table[i].field == field) ) {
3272 return notify_info_data_table[i].variable_type;
3276 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3278 return (enum spoolss_NotifyTable) 0;
3281 /****************************************************************************
3282 ****************************************************************************/
3284 static bool search_notify(enum spoolss_NotifyType type,
3290 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3291 if (notify_info_data_table[i].type == type &&
3292 notify_info_data_table[i].field == field &&
3293 notify_info_data_table[i].fn != NULL) {
3302 /****************************************************************************
3303 ****************************************************************************/
3305 static void construct_info_data(struct spoolss_Notify *info_data,
3306 enum spoolss_NotifyType type,
3307 uint16_t field, int id)
3309 info_data->type = type;
3310 info_data->field.field = field;
3311 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3312 info_data->job_id = id;
3315 /*******************************************************************
3317 * fill a notify_info struct with info asked
3319 ********************************************************************/
3321 static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
3322 struct printer_handle *print_hnd,
3323 struct spoolss_NotifyInfo *info,
3324 struct spoolss_PrinterInfo2 *pinfo2,
3326 const struct spoolss_NotifyOptionType *option_type,
3328 TALLOC_CTX *mem_ctx)
3331 enum spoolss_NotifyType type;
3334 struct spoolss_Notify *current_data;
3335 print_queue_struct *queue=NULL;
3337 type = option_type->type;
3339 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3340 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3341 option_type->count, lp_servicename(snum)));
3343 for(field_num=0; field_num < option_type->count; field_num++) {
3344 field = option_type->fields[field_num].field;
3346 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3348 if (!search_notify(type, field, &j) )
3351 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3352 struct spoolss_Notify,
3354 if (info->notifies == NULL) {
3355 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3359 current_data = &info->notifies[info->count];
3361 construct_info_data(current_data, type, field, id);
3363 DEBUG(10, ("construct_notify_printer_info: "
3364 "calling [%s] snum=%d printername=[%s])\n",
3365 notify_info_data_table[j].name, snum,
3366 pinfo2->printername));
3368 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3369 queue, pinfo2, mem_ctx);
3377 /*******************************************************************
3379 * fill a notify_info struct with info asked
3381 ********************************************************************/
3383 static bool construct_notify_jobs_info(struct messaging_context *msg_ctx,
3384 print_queue_struct *queue,
3385 struct spoolss_NotifyInfo *info,
3386 struct spoolss_PrinterInfo2 *pinfo2,
3388 const struct spoolss_NotifyOptionType *option_type,
3390 TALLOC_CTX *mem_ctx)
3393 enum spoolss_NotifyType type;
3395 struct spoolss_Notify *current_data;
3397 DEBUG(4,("construct_notify_jobs_info\n"));
3399 type = option_type->type;
3401 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3402 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3403 option_type->count));
3405 for(field_num=0; field_num<option_type->count; field_num++) {
3406 field = option_type->fields[field_num].field;
3408 if (!search_notify(type, field, &j) )
3411 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3412 struct spoolss_Notify,
3414 if (info->notifies == NULL) {
3415 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3419 current_data=&(info->notifies[info->count]);
3421 construct_info_data(current_data, type, field, id);
3422 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3423 queue, pinfo2, mem_ctx);
3431 * JFM: The enumeration is not that simple, it's even non obvious.
3433 * let's take an example: I want to monitor the PRINTER SERVER for
3434 * the printer's name and the number of jobs currently queued.
3435 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3436 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3438 * I have 3 printers on the back of my server.
3440 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3443 * 1 printer 1 name 1
3444 * 2 printer 1 cjob 1
3445 * 3 printer 2 name 2
3446 * 4 printer 2 cjob 2
3447 * 5 printer 3 name 3
3448 * 6 printer 3 name 3
3450 * that's the print server case, the printer case is even worse.
3453 /*******************************************************************
3455 * enumerate all printers on the printserver
3456 * fill a notify_info struct with info asked
3458 ********************************************************************/
3460 static WERROR printserver_notify_info(struct pipes_struct *p,
3461 struct policy_handle *hnd,
3462 struct spoolss_NotifyInfo *info,
3463 TALLOC_CTX *mem_ctx)
3466 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3467 int n_services=lp_numservices();
3469 struct spoolss_NotifyOption *option;
3470 struct spoolss_NotifyOptionType option_type;
3471 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3474 DEBUG(4,("printserver_notify_info\n"));
3479 option = Printer->notify.option;
3482 info->notifies = NULL;
3485 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3486 sending a ffpcn() request first */
3491 for (i=0; i<option->count; i++) {
3492 option_type = option->types[i];
3494 if (option_type.type != PRINTER_NOTIFY_TYPE)
3497 for (snum = 0; snum < n_services; snum++) {
3498 if (!lp_browseable(snum) ||
3499 !lp_snum_ok(snum) ||
3500 !lp_print_ok(snum)) {
3501 continue; /* skip */
3504 /* Maybe we should use the SYSTEM server_info here... */
3505 result = winreg_get_printer(mem_ctx,
3506 get_server_info_system(),
3508 Printer->servername,
3509 lp_servicename(snum),
3511 if (!W_ERROR_IS_OK(result)) {
3512 DEBUG(4, ("printserver_notify_info: "
3513 "Failed to get printer [%s]\n",
3514 lp_servicename(snum)));
3519 construct_notify_printer_info(p->msg_ctx,
3525 TALLOC_FREE(pinfo2);
3531 * Debugging information, don't delete.
3534 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3535 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3536 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3538 for (i=0; i<info->count; i++) {
3539 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3540 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3541 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3548 /*******************************************************************
3550 * fill a notify_info struct with info asked
3552 ********************************************************************/
3554 static WERROR printer_notify_info(struct pipes_struct *p,
3555 struct policy_handle *hnd,
3556 struct spoolss_NotifyInfo *info,
3557 TALLOC_CTX *mem_ctx)
3560 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3563 struct spoolss_NotifyOption *option;
3564 struct spoolss_NotifyOptionType option_type;
3566 print_queue_struct *queue=NULL;
3567 print_status_struct status;
3568 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3571 DEBUG(4,("printer_notify_info\n"));
3576 option = Printer->notify.option;
3580 info->notifies = NULL;
3583 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3584 sending a ffpcn() request first */
3589 get_printer_snum(p, hnd, &snum, NULL);
3591 /* Maybe we should use the SYSTEM server_info here... */
3592 result = winreg_get_printer(mem_ctx,
3593 get_server_info_system(),
3595 Printer->servername,
3596 lp_servicename(snum), &pinfo2);
3597 if (!W_ERROR_IS_OK(result)) {
3601 for (i=0; i<option->count; i++) {
3602 option_type = option->types[i];
3604 switch (option_type.type) {
3605 case PRINTER_NOTIFY_TYPE:
3606 if (construct_notify_printer_info(p->msg_ctx,
3615 case JOB_NOTIFY_TYPE:
3617 count = print_queue_status(p->msg_ctx, snum, &queue,
3620 for (j=0; j<count; j++) {
3621 construct_notify_jobs_info(p->msg_ctx,
3635 * Debugging information, don't delete.
3638 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3639 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3640 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3642 for (i=0; i<info->count; i++) {
3643 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3644 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3645 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3649 talloc_free(pinfo2);
3653 /****************************************************************
3654 _spoolss_RouterRefreshPrinterChangeNotify
3655 ****************************************************************/
3657 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3658 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3660 struct spoolss_NotifyInfo *info;
3662 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
3663 WERROR result = WERR_BADFID;
3665 /* we always have a spoolss_NotifyInfo struct */
3666 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3668 result = WERR_NOMEM;
3672 *r->out.info = info;
3675 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3676 "Invalid handle (%s:%u:%u).\n",
3677 OUR_HANDLE(r->in.handle)));
3681 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3684 * We are now using the change value, and
3685 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3686 * I don't have a global notification system, I'm sending back all the
3687 * informations even when _NOTHING_ has changed.
3690 /* We need to keep track of the change value to send back in
3691 RRPCN replies otherwise our updates are ignored. */
3693 Printer->notify.fnpcn = true;
3695 if (Printer->notify.cli_chan != NULL &&
3696 Printer->notify.cli_chan->active_connections > 0) {
3697 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3698 "Saving change value in request [%x]\n",
3700 Printer->notify.change = r->in.change_low;
3703 /* just ignore the spoolss_NotifyOption */
3705 switch (Printer->printer_type) {
3707 result = printserver_notify_info(p, r->in.handle,
3711 case SPLHND_PRINTER:
3712 result = printer_notify_info(p, r->in.handle,
3717 Printer->notify.fnpcn = false;
3723 /********************************************************************
3724 * construct_printer_info_0
3725 * fill a printer_info_0 struct
3726 ********************************************************************/
3728 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3729 const struct auth_serversupplied_info *server_info,
3730 struct messaging_context *msg_ctx,
3731 struct spoolss_PrinterInfo2 *info2,
3732 struct spoolss_PrinterInfo0 *r,
3736 struct printer_session_counter *session_counter;
3737 struct timeval setuptime;
3738 print_status_struct status;
3740 r->printername = talloc_strdup(mem_ctx, info2->printername);
3741 W_ERROR_HAVE_NO_MEMORY(r->printername);
3743 r->servername = talloc_strdup(mem_ctx, info2->servername);
3744 W_ERROR_HAVE_NO_MEMORY(r->servername);
3746 count = print_queue_length(msg_ctx, snum, &status);
3748 /* check if we already have a counter for this printer */
3749 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3750 if (session_counter->snum == snum)
3754 /* it's the first time, add it to the list */
3755 if (session_counter == NULL) {
3756 session_counter = talloc_zero(counter_list, struct printer_session_counter);
3757 W_ERROR_HAVE_NO_MEMORY(session_counter);
3758 session_counter->snum = snum;
3759 session_counter->counter = 0;
3760 DLIST_ADD(counter_list, session_counter);
3764 session_counter->counter++;
3770 get_startup_time(&setuptime);
3771 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3774 * the global_counter should be stored in a TDB as it's common to all the clients
3775 * and should be zeroed on samba startup
3777 r->global_counter = session_counter->counter;
3779 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3780 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3781 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3782 r->free_build = SPOOLSS_RELEASE_BUILD;
3784 r->max_spooling = 0;
3785 r->session_counter = session_counter->counter;
3786 r->num_error_out_of_paper = 0x0;
3787 r->num_error_not_ready = 0x0; /* number of print failure */
3789 r->number_of_processors = 0x1;
3790 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3791 r->high_part_total_bytes = 0x0;
3793 /* ChangeID in milliseconds*/
3794 winreg_printer_get_changeid(mem_ctx, server_info, msg_ctx,
3795 info2->sharename, &r->change_id);
3797 r->last_error = WERR_OK;
3798 r->status = nt_printq_status(status.status);
3799 r->enumerate_network_printers = 0x0;
3800 r->c_setprinter = 0x0;
3801 r->processor_architecture = PROCESSOR_ARCHITECTURE_INTEL;
3802 r->processor_level = 0x6; /* 6 ???*/
3811 /********************************************************************
3812 * construct_printer_info1
3813 * fill a spoolss_PrinterInfo1 struct
3814 ********************************************************************/
3816 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3817 const struct spoolss_PrinterInfo2 *info2,
3819 struct spoolss_PrinterInfo1 *r,
3824 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3828 W_ERROR_HAVE_NO_MEMORY(r->description);
3830 if (info2->comment == NULL || info2->comment[0] == '\0') {
3831 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3833 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3835 W_ERROR_HAVE_NO_MEMORY(r->comment);
3837 r->name = talloc_strdup(mem_ctx, info2->printername);
3838 W_ERROR_HAVE_NO_MEMORY(r->name);
3843 /********************************************************************
3844 * construct_printer_info2
3845 * fill a spoolss_PrinterInfo2 struct
3846 ********************************************************************/
3848 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3849 struct messaging_context *msg_ctx,
3850 const struct spoolss_PrinterInfo2 *info2,
3851 struct spoolss_PrinterInfo2 *r,
3855 print_status_struct status;
3857 count = print_queue_length(msg_ctx, snum, &status);
3859 r->servername = talloc_strdup(mem_ctx, info2->servername);
3860 W_ERROR_HAVE_NO_MEMORY(r->servername);
3861 r->printername = talloc_strdup(mem_ctx, info2->printername);
3862 W_ERROR_HAVE_NO_MEMORY(r->printername);
3863 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3864 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3865 r->portname = talloc_strdup(mem_ctx, info2->portname);
3866 W_ERROR_HAVE_NO_MEMORY(r->portname);
3867 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
3868 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3870 if (info2->comment[0] == '\0') {
3871 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3873 r->comment = talloc_strdup(mem_ctx, info2->comment);
3875 W_ERROR_HAVE_NO_MEMORY(r->comment);
3877 r->location = talloc_strdup(mem_ctx, info2->location);
3878 W_ERROR_HAVE_NO_MEMORY(r->location);
3879 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
3880 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3881 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
3882 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3883 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
3884 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3885 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
3886 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3888 r->attributes = info2->attributes;
3890 r->priority = info2->priority;
3891 r->defaultpriority = info2->defaultpriority;
3892 r->starttime = info2->starttime;
3893 r->untiltime = info2->untiltime;
3894 r->status = nt_printq_status(status.status);
3896 r->averageppm = info2->averageppm;
3898 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3900 DEBUG(8,("Returning NULL Devicemode!\n"));
3905 if (info2->secdesc != NULL) {
3906 /* don't use talloc_steal() here unless you do a deep steal of all
3907 the SEC_DESC members */
3909 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3915 /********************************************************************
3916 * construct_printer_info3
3917 * fill a spoolss_PrinterInfo3 struct
3918 ********************************************************************/
3920 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3921 const struct spoolss_PrinterInfo2 *info2,
3922 struct spoolss_PrinterInfo3 *r,
3925 /* These are the components of the SD we are returning. */
3927 if (info2->secdesc != NULL) {
3928 /* don't use talloc_steal() here unless you do a deep steal of all
3929 the SEC_DESC members */
3931 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3932 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3938 /********************************************************************
3939 * construct_printer_info4
3940 * fill a spoolss_PrinterInfo4 struct
3941 ********************************************************************/
3943 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
3944 const struct spoolss_PrinterInfo2 *info2,
3945 struct spoolss_PrinterInfo4 *r,
3948 r->printername = talloc_strdup(mem_ctx, info2->printername);
3949 W_ERROR_HAVE_NO_MEMORY(r->printername);
3950 r->servername = talloc_strdup(mem_ctx, info2->servername);
3951 W_ERROR_HAVE_NO_MEMORY(r->servername);
3953 r->attributes = info2->attributes;
3958 /********************************************************************
3959 * construct_printer_info5
3960 * fill a spoolss_PrinterInfo5 struct
3961 ********************************************************************/
3963 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
3964 const struct spoolss_PrinterInfo2 *info2,
3965 struct spoolss_PrinterInfo5 *r,
3968 r->printername = talloc_strdup(mem_ctx, info2->printername);
3969 W_ERROR_HAVE_NO_MEMORY(r->printername);
3970 r->portname = talloc_strdup(mem_ctx, info2->portname);
3971 W_ERROR_HAVE_NO_MEMORY(r->portname);
3973 r->attributes = info2->attributes;
3975 /* these two are not used by NT+ according to MSDN */
3976 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
3977 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
3982 /********************************************************************
3983 * construct_printer_info_6
3984 * fill a spoolss_PrinterInfo6 struct
3985 ********************************************************************/
3987 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
3988 struct messaging_context *msg_ctx,
3989 const struct spoolss_PrinterInfo2 *info2,
3990 struct spoolss_PrinterInfo6 *r,
3994 print_status_struct status;
3996 count = print_queue_length(msg_ctx, snum, &status);
3998 r->status = nt_printq_status(status.status);
4003 /********************************************************************
4004 * construct_printer_info7
4005 * fill a spoolss_PrinterInfo7 struct
4006 ********************************************************************/
4008 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4009 struct messaging_context *msg_ctx,
4010 struct printer_handle *print_hnd,
4011 struct spoolss_PrinterInfo7 *r,
4014 struct auth_serversupplied_info *server_info;
4018 status = make_server_info_system(mem_ctx, &server_info);
4019 if (!NT_STATUS_IS_OK(status)) {
4020 DEBUG(0, ("construct_printer_info7: "
4021 "Could not create system server_info\n"));
4025 if (is_printer_published(mem_ctx, server_info, msg_ctx,
4026 print_hnd->servername,
4027 lp_servicename(snum), &guid, NULL)) {
4028 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4029 r->action = DSPRINT_PUBLISH;
4031 r->guid = talloc_strdup(mem_ctx, "");
4032 r->action = DSPRINT_UNPUBLISH;
4034 W_ERROR_HAVE_NO_MEMORY(r->guid);
4036 TALLOC_FREE(server_info);
4040 /********************************************************************
4041 * construct_printer_info8
4042 * fill a spoolss_PrinterInfo8 struct
4043 ********************************************************************/
4045 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4046 const struct spoolss_PrinterInfo2 *info2,
4047 struct spoolss_DeviceModeInfo *r,
4050 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
4052 DEBUG(8,("Returning NULL Devicemode!\n"));
4059 /********************************************************************
4060 ********************************************************************/
4062 static bool snum_is_shared_printer(int snum)
4064 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4067 /********************************************************************
4068 Spoolss_enumprinters.
4069 ********************************************************************/
4071 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4072 const struct auth_serversupplied_info *server_info,
4073 struct messaging_context *msg_ctx,
4076 union spoolss_PrinterInfo **info_p,
4080 int n_services = lp_numservices();
4081 union spoolss_PrinterInfo *info = NULL;
4083 WERROR result = WERR_OK;
4088 for (snum = 0; snum < n_services; snum++) {
4090 const char *printer;
4091 struct spoolss_PrinterInfo2 *info2;
4093 if (!snum_is_shared_printer(snum)) {
4097 printer = lp_const_servicename(snum);
4099 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4102 result = winreg_create_printer(mem_ctx,
4107 if (!W_ERROR_IS_OK(result)) {
4111 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4112 union spoolss_PrinterInfo,
4115 result = WERR_NOMEM;
4119 result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
4120 NULL, printer, &info2);
4121 if (!W_ERROR_IS_OK(result)) {
4127 result = construct_printer_info0(info, server_info,
4129 &info[count].info0, snum);
4132 result = construct_printer_info1(info, info2, flags,
4133 &info[count].info1, snum);
4136 result = construct_printer_info2(info, msg_ctx, info2,
4137 &info[count].info2, snum);
4140 result = construct_printer_info4(info, info2,
4141 &info[count].info4, snum);
4144 result = construct_printer_info5(info, info2,
4145 &info[count].info5, snum);
4149 result = WERR_UNKNOWN_LEVEL;
4153 if (!W_ERROR_IS_OK(result)) {
4164 if (!W_ERROR_IS_OK(result)) {
4174 /********************************************************************
4175 * handle enumeration of printers at level 0
4176 ********************************************************************/
4178 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4179 const struct auth_serversupplied_info *server_info,
4180 struct messaging_context *msg_ctx,
4182 const char *servername,
4183 union spoolss_PrinterInfo **info,
4186 DEBUG(4,("enum_all_printers_info_0\n"));
4188 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4189 0, flags, info, count);
4193 /********************************************************************
4194 ********************************************************************/
4196 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4197 const struct auth_serversupplied_info *server_info,
4198 struct messaging_context *msg_ctx,
4200 union spoolss_PrinterInfo **info,
4203 DEBUG(4,("enum_all_printers_info_1\n"));
4205 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4206 1, flags, info, count);
4209 /********************************************************************
4210 enum_all_printers_info_1_local.
4211 *********************************************************************/
4213 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4214 const struct auth_serversupplied_info *server_info,
4215 struct messaging_context *msg_ctx,
4216 union spoolss_PrinterInfo **info,
4219 DEBUG(4,("enum_all_printers_info_1_local\n"));
4221 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4222 PRINTER_ENUM_ICON8, info, count);
4225 /********************************************************************
4226 enum_all_printers_info_1_name.
4227 *********************************************************************/
4229 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4230 const struct auth_serversupplied_info *server_info,
4231 struct messaging_context *msg_ctx,
4233 union spoolss_PrinterInfo **info,
4236 const char *s = name;
4238 DEBUG(4,("enum_all_printers_info_1_name\n"));
4240 if ((name[0] == '\\') && (name[1] == '\\')) {
4244 if (!is_myname_or_ipaddr(s)) {
4245 return WERR_INVALID_NAME;
4248 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4249 PRINTER_ENUM_ICON8, info, count);
4252 /********************************************************************
4253 enum_all_printers_info_1_network.
4254 *********************************************************************/
4256 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4257 const struct auth_serversupplied_info *server_info,
4258 struct messaging_context *msg_ctx,
4260 union spoolss_PrinterInfo **info,
4263 const char *s = name;
4265 DEBUG(4,("enum_all_printers_info_1_network\n"));
4267 /* If we respond to a enum_printers level 1 on our name with flags
4268 set to PRINTER_ENUM_REMOTE with a list of printers then these
4269 printers incorrectly appear in the APW browse list.
4270 Specifically the printers for the server appear at the workgroup
4271 level where all the other servers in the domain are
4272 listed. Windows responds to this call with a
4273 WERR_CAN_NOT_COMPLETE so we should do the same. */
4275 if (name[0] == '\\' && name[1] == '\\') {
4279 if (is_myname_or_ipaddr(s)) {
4280 return WERR_CAN_NOT_COMPLETE;
4283 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4284 PRINTER_ENUM_NAME, info, count);
4287 /********************************************************************
4288 * api_spoolss_enumprinters
4290 * called from api_spoolss_enumprinters (see this to understand)
4291 ********************************************************************/
4293 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4294 const struct auth_serversupplied_info *server_info,
4295 struct messaging_context *msg_ctx,
4296 union spoolss_PrinterInfo **info,
4299 DEBUG(4,("enum_all_printers_info_2\n"));
4301 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4305 /********************************************************************
4306 * handle enumeration of printers at level 1
4307 ********************************************************************/
4309 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4310 const struct auth_serversupplied_info *server_info,
4311 struct messaging_context *msg_ctx,
4314 union spoolss_PrinterInfo **info,
4317 /* Not all the flags are equals */
4319 if (flags & PRINTER_ENUM_LOCAL) {
4320 return enum_all_printers_info_1_local(mem_ctx, server_info,
4321 msg_ctx, info, count);
4324 if (flags & PRINTER_ENUM_NAME) {
4325 return enum_all_printers_info_1_name(mem_ctx, server_info,
4326 msg_ctx, name, info,
4330 if (flags & PRINTER_ENUM_NETWORK) {
4331 return enum_all_printers_info_1_network(mem_ctx, server_info,
4332 msg_ctx, name, info,
4336 return WERR_OK; /* NT4sp5 does that */
4339 /********************************************************************
4340 * handle enumeration of printers at level 2
4341 ********************************************************************/
4343 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4344 const struct auth_serversupplied_info *server_info,
4345 struct messaging_context *msg_ctx,
4347 const char *servername,
4348 union spoolss_PrinterInfo **info,
4351 if (flags & PRINTER_ENUM_LOCAL) {
4352 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4356 if (flags & PRINTER_ENUM_NAME) {
4357 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4358 return WERR_INVALID_NAME;
4361 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4365 if (flags & PRINTER_ENUM_REMOTE) {
4366 return WERR_UNKNOWN_LEVEL;
4372 /********************************************************************
4373 * handle enumeration of printers at level 4
4374 ********************************************************************/
4376 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4377 const struct auth_serversupplied_info *server_info,
4378 struct messaging_context *msg_ctx,
4380 const char *servername,
4381 union spoolss_PrinterInfo **info,
4384 DEBUG(4,("enum_all_printers_info_4\n"));
4386 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4387 4, flags, info, count);
4391 /********************************************************************
4392 * handle enumeration of printers at level 5
4393 ********************************************************************/
4395 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4396 const struct auth_serversupplied_info *server_info,
4397 struct messaging_context *msg_ctx,
4399 const char *servername,
4400 union spoolss_PrinterInfo **info,
4403 DEBUG(4,("enum_all_printers_info_5\n"));
4405 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4406 5, flags, info, count);
4409 /****************************************************************
4410 _spoolss_EnumPrinters
4411 ****************************************************************/
4413 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4414 struct spoolss_EnumPrinters *r)
4416 const struct auth_serversupplied_info *server_info = get_server_info_system();
4417 const char *name = NULL;
4420 /* that's an [in out] buffer */
4422 if (!r->in.buffer && (r->in.offered != 0)) {
4423 return WERR_INVALID_PARAM;
4426 DEBUG(4,("_spoolss_EnumPrinters\n"));
4430 *r->out.info = NULL;
4434 * flags==PRINTER_ENUM_NAME
4435 * if name=="" then enumerates all printers
4436 * if name!="" then enumerate the printer
4437 * flags==PRINTER_ENUM_REMOTE
4438 * name is NULL, enumerate printers
4439 * Level 2: name!="" enumerates printers, name can't be NULL
4440 * Level 3: doesn't exist
4441 * Level 4: does a local registry lookup
4442 * Level 5: same as Level 2
4446 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4447 W_ERROR_HAVE_NO_MEMORY(name);
4450 switch (r->in.level) {
4452 result = enumprinters_level0(p->mem_ctx, server_info,
4453 p->msg_ctx, r->in.flags, name,
4454 r->out.info, r->out.count);
4457 result = enumprinters_level1(p->mem_ctx, server_info,
4458 p->msg_ctx, r->in.flags, name,
4459 r->out.info, r->out.count);
4462 result = enumprinters_level2(p->mem_ctx, server_info,
4463 p->msg_ctx, r->in.flags, name,
4464 r->out.info, r->out.count);
4467 result = enumprinters_level4(p->mem_ctx, server_info,
4468 p->msg_ctx, r->in.flags, name,
4469 r->out.info, r->out.count);
4472 result = enumprinters_level5(p->mem_ctx, server_info,
4473 p->msg_ctx, r->in.flags, name,
4474 r->out.info, r->out.count);
4477 return WERR_UNKNOWN_LEVEL;
4480 if (!W_ERROR_IS_OK(result)) {
4484 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4485 spoolss_EnumPrinters,
4486 *r->out.info, r->in.level,
4488 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4489 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4491 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4494 /****************************************************************
4496 ****************************************************************/
4498 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4499 struct spoolss_GetPrinter *r)
4501 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
4502 struct spoolss_PrinterInfo2 *info2 = NULL;
4503 WERROR result = WERR_OK;
4504 const char *servername = NULL;
4507 /* that's an [in out] buffer */
4509 if (!r->in.buffer && (r->in.offered != 0)) {
4510 return WERR_INVALID_PARAM;
4515 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4519 if (Printer != NULL || Printer->servername != NULL) {
4520 servername = Printer->servername;
4523 result = winreg_get_printer(p->mem_ctx,
4524 get_server_info_system(),
4527 lp_const_servicename(snum),
4529 if (!W_ERROR_IS_OK(result)) {
4533 switch (r->in.level) {
4535 result = construct_printer_info0(p->mem_ctx,
4536 get_server_info_system(),
4539 &r->out.info->info0,
4543 result = construct_printer_info1(p->mem_ctx, info2,
4545 &r->out.info->info1, snum);
4548 result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
4549 &r->out.info->info2, snum);
4552 result = construct_printer_info3(p->mem_ctx, info2,
4553 &r->out.info->info3, snum);
4556 result = construct_printer_info4(p->mem_ctx, info2,
4557 &r->out.info->info4, snum);
4560 result = construct_printer_info5(p->mem_ctx, info2,
4561 &r->out.info->info5, snum);
4564 result = construct_printer_info6(p->mem_ctx, p->msg_ctx, info2,
4565 &r->out.info->info6, snum);
4568 result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
4570 &r->out.info->info7, snum);
4573 result = construct_printer_info8(p->mem_ctx, info2,
4574 &r->out.info->info8, snum);
4577 result = WERR_UNKNOWN_LEVEL;
4582 if (!W_ERROR_IS_OK(result)) {
4583 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4584 r->in.level, win_errstr(result)));
4585 TALLOC_FREE(r->out.info);
4589 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4590 r->out.info, r->in.level);
4591 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4593 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4596 /********************************************************************
4597 ********************************************************************/
4599 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4601 if (in && strlen(in)) { \
4602 out = talloc_strdup(mem_ctx, in); \
4604 out = talloc_strdup(mem_ctx, ""); \
4606 W_ERROR_HAVE_NO_MEMORY(out); \
4609 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4611 if (in && strlen(in)) { \
4612 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4614 out = talloc_strdup(mem_ctx, ""); \
4616 W_ERROR_HAVE_NO_MEMORY(out); \
4619 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4620 const char **string_array,
4621 const char ***presult,
4622 const char *cservername,
4626 int i, num_strings = 0;
4627 const char **array = NULL;
4629 if (string_array == NULL) {
4630 return WERR_INVALID_PARAMETER;;
4633 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4634 const char *str = NULL;
4636 if (cservername == NULL || arch == NULL) {
4637 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4639 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4642 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4649 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4650 &array, &num_strings);
4660 /********************************************************************
4661 * fill a spoolss_DriverInfo1 struct
4662 ********************************************************************/
4664 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4665 struct spoolss_DriverInfo1 *r,
4666 const struct spoolss_DriverInfo8 *driver,
4667 const char *servername)
4669 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4670 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4675 /********************************************************************
4676 * fill a spoolss_DriverInfo2 struct
4677 ********************************************************************/
4679 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4680 struct spoolss_DriverInfo2 *r,
4681 const struct spoolss_DriverInfo8 *driver,
4682 const char *servername)
4685 const char *cservername = canon_servername(servername);
4687 r->version = driver->version;
4689 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4690 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4691 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4692 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4694 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4695 driver->architecture,
4697 driver->driver_path,
4700 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4701 driver->architecture,
4706 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4707 driver->architecture,
4709 driver->config_file,
4715 /********************************************************************
4716 * fill a spoolss_DriverInfo3 struct
4717 ********************************************************************/
4719 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4720 struct spoolss_DriverInfo3 *r,
4721 const struct spoolss_DriverInfo8 *driver,
4722 const char *servername)
4724 const char *cservername = canon_servername(servername);
4726 r->version = driver->version;
4728 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4729 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4730 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4731 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4733 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4734 driver->architecture,
4736 driver->driver_path,
4739 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4740 driver->architecture,
4745 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4746 driver->architecture,
4748 driver->config_file,
4751 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4752 driver->architecture,
4757 FILL_DRIVER_STRING(mem_ctx,
4758 driver->monitor_name,
4761 FILL_DRIVER_STRING(mem_ctx,
4762 driver->default_datatype,
4763 r->default_datatype);
4765 return string_array_from_driver_info(mem_ctx,
4766 driver->dependent_files,
4767 &r->dependent_files,
4769 driver->architecture,
4773 /********************************************************************
4774 * fill a spoolss_DriverInfo4 struct
4775 ********************************************************************/
4777 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4778 struct spoolss_DriverInfo4 *r,
4779 const struct spoolss_DriverInfo8 *driver,
4780 const char *servername)
4782 const char *cservername = canon_servername(servername);
4785 r->version = driver->version;
4787 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4788 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4789 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4790 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4792 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4793 driver->architecture,
4795 driver->driver_path,
4798 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4799 driver->architecture,
4804 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4805 driver->architecture,
4807 driver->config_file,
4810 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4811 driver->architecture,
4816 result = string_array_from_driver_info(mem_ctx,
4817 driver->dependent_files,
4818 &r->dependent_files,
4820 driver->architecture,
4822 if (!W_ERROR_IS_OK(result)) {
4826 FILL_DRIVER_STRING(mem_ctx,
4827 driver->monitor_name,
4830 FILL_DRIVER_STRING(mem_ctx,
4831 driver->default_datatype,
4832 r->default_datatype);
4835 result = string_array_from_driver_info(mem_ctx,
4836 driver->previous_names,
4843 /********************************************************************
4844 * fill a spoolss_DriverInfo5 struct
4845 ********************************************************************/
4847 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4848 struct spoolss_DriverInfo5 *r,
4849 const struct spoolss_DriverInfo8 *driver,
4850 const char *servername)
4852 const char *cservername = canon_servername(servername);
4854 r->version = driver->version;
4856 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4857 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4858 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4859 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4861 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4862 driver->architecture,
4864 driver->driver_path,
4867 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4868 driver->architecture,
4873 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4874 driver->architecture,
4876 driver->config_file,
4879 r->driver_attributes = 0;
4880 r->config_version = 0;
4881 r->driver_version = 0;
4885 /********************************************************************
4886 * fill a spoolss_DriverInfo6 struct
4887 ********************************************************************/
4889 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4890 struct spoolss_DriverInfo6 *r,
4891 const struct spoolss_DriverInfo8 *driver,
4892 const char *servername)
4894 const char *cservername = canon_servername(servername);
4897 r->version = driver->version;
4899 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4900 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4901 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4902 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4904 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4905 driver->architecture,
4907 driver->driver_path,
4910 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4911 driver->architecture,
4916 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4917 driver->architecture,
4919 driver->config_file,
4922 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4923 driver->architecture,
4928 FILL_DRIVER_STRING(mem_ctx,
4929 driver->monitor_name,
4932 FILL_DRIVER_STRING(mem_ctx,
4933 driver->default_datatype,
4934 r->default_datatype);
4936 result = string_array_from_driver_info(mem_ctx,
4937 driver->dependent_files,
4938 &r->dependent_files,
4940 driver->architecture,
4942 if (!W_ERROR_IS_OK(result)) {
4946 result = string_array_from_driver_info(mem_ctx,
4947 driver->previous_names,
4950 if (!W_ERROR_IS_OK(result)) {
4954 r->driver_date = driver->driver_date;
4955 r->driver_version = driver->driver_version;
4957 FILL_DRIVER_STRING(mem_ctx,
4958 driver->manufacturer_name,
4959 r->manufacturer_name);
4960 FILL_DRIVER_STRING(mem_ctx,
4961 driver->manufacturer_url,
4962 r->manufacturer_url);
4963 FILL_DRIVER_STRING(mem_ctx,
4964 driver->hardware_id,
4966 FILL_DRIVER_STRING(mem_ctx,
4973 /********************************************************************
4974 * fill a spoolss_DriverInfo8 struct
4975 ********************************************************************/
4977 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
4978 struct spoolss_DriverInfo8 *r,
4979 const struct spoolss_DriverInfo8 *driver,
4980 const char *servername)
4982 const char *cservername = canon_servername(servername);
4985 r->version = driver->version;
4987 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4988 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4989 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4990 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4992 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4993 driver->architecture,
4995 driver->driver_path,
4998 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4999 driver->architecture,
5004 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5005 driver->architecture,
5007 driver->config_file,
5010 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5011 driver->architecture,
5016 FILL_DRIVER_STRING(mem_ctx,
5017 driver->monitor_name,
5020 FILL_DRIVER_STRING(mem_ctx,
5021 driver->default_datatype,
5022 r->default_datatype);
5024 result = string_array_from_driver_info(mem_ctx,
5025 driver->dependent_files,
5026 &r->dependent_files,
5028 driver->architecture,
5030 if (!W_ERROR_IS_OK(result)) {
5034 result = string_array_from_driver_info(mem_ctx,
5035 driver->previous_names,
5038 if (!W_ERROR_IS_OK(result)) {
5042 r->driver_date = driver->driver_date;
5043 r->driver_version = driver->driver_version;
5045 FILL_DRIVER_STRING(mem_ctx,
5046 driver->manufacturer_name,
5047 r->manufacturer_name);
5048 FILL_DRIVER_STRING(mem_ctx,
5049 driver->manufacturer_url,
5050 r->manufacturer_url);
5051 FILL_DRIVER_STRING(mem_ctx,
5052 driver->hardware_id,
5054 FILL_DRIVER_STRING(mem_ctx,
5058 FILL_DRIVER_STRING(mem_ctx,
5059 driver->print_processor,
5060 r->print_processor);
5061 FILL_DRIVER_STRING(mem_ctx,
5062 driver->vendor_setup,
5065 result = string_array_from_driver_info(mem_ctx,
5066 driver->color_profiles,
5069 if (!W_ERROR_IS_OK(result)) {
5073 FILL_DRIVER_STRING(mem_ctx,
5077 r->printer_driver_attributes = driver->printer_driver_attributes;
5079 result = string_array_from_driver_info(mem_ctx,
5080 driver->core_driver_dependencies,
5081 &r->core_driver_dependencies,
5083 if (!W_ERROR_IS_OK(result)) {
5087 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
5088 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
5093 #if 0 /* disabled until marshalling issues are resolved - gd */
5094 /********************************************************************
5095 ********************************************************************/
5097 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5098 struct spoolss_DriverFileInfo *r,
5099 const char *cservername,
5100 const char *file_name,
5101 enum spoolss_DriverFileType file_type,
5102 uint32_t file_version)
5104 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5105 cservername, file_name);
5106 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5107 r->file_type = file_type;
5108 r->file_version = file_version;
5113 /********************************************************************
5114 ********************************************************************/
5116 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5117 const struct spoolss_DriverInfo8 *driver,
5118 const char *cservername,
5119 struct spoolss_DriverFileInfo **info_p,
5122 struct spoolss_DriverFileInfo *info = NULL;
5130 if (strlen(driver->driver_path)) {
5131 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5132 struct spoolss_DriverFileInfo,
5134 W_ERROR_HAVE_NO_MEMORY(info);
5135 result = fill_spoolss_DriverFileInfo(info,
5138 driver->driver_path,
5139 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5141 W_ERROR_NOT_OK_RETURN(result);
5145 if (strlen(driver->config_file)) {
5146 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5147 struct spoolss_DriverFileInfo,
5149 W_ERROR_HAVE_NO_MEMORY(info);
5150 result = fill_spoolss_DriverFileInfo(info,
5153 driver->config_file,
5154 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5156 W_ERROR_NOT_OK_RETURN(result);
5160 if (strlen(driver->data_file)) {
5161 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5162 struct spoolss_DriverFileInfo,
5164 W_ERROR_HAVE_NO_MEMORY(info);
5165 result = fill_spoolss_DriverFileInfo(info,
5169 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5171 W_ERROR_NOT_OK_RETURN(result);
5175 if (strlen(driver->help_file)) {
5176 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5177 struct spoolss_DriverFileInfo,
5179 W_ERROR_HAVE_NO_MEMORY(info);
5180 result = fill_spoolss_DriverFileInfo(info,
5184 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5186 W_ERROR_NOT_OK_RETURN(result);
5190 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
5191 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5192 struct spoolss_DriverFileInfo,
5194 W_ERROR_HAVE_NO_MEMORY(info);
5195 result = fill_spoolss_DriverFileInfo(info,
5198 driver->dependent_files[i],
5199 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5201 W_ERROR_NOT_OK_RETURN(result);
5211 /********************************************************************
5212 * fill a spoolss_DriverInfo101 struct
5213 ********************************************************************/
5215 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5216 struct spoolss_DriverInfo101 *r,
5217 const struct spoolss_DriverInfo8 *driver,
5218 const char *servername)
5220 const char *cservername = canon_servername(servername);
5223 r->version = driver->version;
5225 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5226 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5227 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5228 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5230 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5234 if (!W_ERROR_IS_OK(result)) {
5238 FILL_DRIVER_STRING(mem_ctx,
5239 driver->monitor_name,
5242 FILL_DRIVER_STRING(mem_ctx,
5243 driver->default_datatype,
5244 r->default_datatype);
5246 result = string_array_from_driver_info(mem_ctx,
5247 driver->previous_names,
5250 if (!W_ERROR_IS_OK(result)) {
5254 r->driver_date = driver->driver_date;
5255 r->driver_version = driver->driver_version;
5257 FILL_DRIVER_STRING(mem_ctx,
5258 driver->manufacturer_name,
5259 r->manufacturer_name);
5260 FILL_DRIVER_STRING(mem_ctx,
5261 driver->manufacturer_url,
5262 r->manufacturer_url);
5263 FILL_DRIVER_STRING(mem_ctx,
5264 driver->hardware_id,
5266 FILL_DRIVER_STRING(mem_ctx,
5273 /********************************************************************
5274 ********************************************************************/
5276 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5277 const struct auth_serversupplied_info *server_info,
5278 struct messaging_context *msg_ctx,
5280 union spoolss_DriverInfo *r,
5282 const char *servername,
5283 const char *architecture,
5286 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5287 struct spoolss_DriverInfo8 *driver;
5290 result = winreg_get_printer(mem_ctx,
5294 lp_const_servicename(snum),
5297 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5298 win_errstr(result)));
5300 if (!W_ERROR_IS_OK(result)) {
5301 return WERR_INVALID_PRINTER_NAME;
5304 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5306 pinfo2->drivername, version, &driver);
5308 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5309 win_errstr(result)));
5311 if (!W_ERROR_IS_OK(result)) {
5313 * Is this a W2k client ?
5317 talloc_free(pinfo2);
5318 return WERR_UNKNOWN_PRINTER_DRIVER;
5321 /* Yes - try again with a WinNT driver. */
5323 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5327 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5328 win_errstr(result)));
5329 if (!W_ERROR_IS_OK(result)) {
5330 talloc_free(pinfo2);
5331 return WERR_UNKNOWN_PRINTER_DRIVER;
5337 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5340 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5343 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5346 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5349 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5352 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5355 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5357 #if 0 /* disabled until marshalling issues are resolved - gd */
5359 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5363 result = WERR_UNKNOWN_LEVEL;
5367 talloc_free(pinfo2);
5368 talloc_free(driver);
5373 /****************************************************************
5374 _spoolss_GetPrinterDriver2
5375 ****************************************************************/
5377 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5378 struct spoolss_GetPrinterDriver2 *r)
5380 struct printer_handle *printer;
5385 /* that's an [in out] buffer */
5387 if (!r->in.buffer && (r->in.offered != 0)) {
5388 return WERR_INVALID_PARAM;
5391 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5393 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5394 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5395 return WERR_INVALID_PRINTER_NAME;
5399 *r->out.server_major_version = 0;
5400 *r->out.server_minor_version = 0;
5402 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5406 result = construct_printer_driver_info_level(p->mem_ctx,
5407 get_server_info_system(),
5409 r->in.level, r->out.info,
5410 snum, printer->servername,
5412 r->in.client_major_version);
5413 if (!W_ERROR_IS_OK(result)) {
5414 TALLOC_FREE(r->out.info);
5418 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5419 r->out.info, r->in.level);
5420 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5422 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5426 /****************************************************************
5427 _spoolss_StartPagePrinter
5428 ****************************************************************/
5430 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5431 struct spoolss_StartPagePrinter *r)
5433 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5436 DEBUG(3,("_spoolss_StartPagePrinter: "
5437 "Error in startpageprinter printer handle\n"));
5441 Printer->page_started = true;
5445 /****************************************************************
5446 _spoolss_EndPagePrinter
5447 ****************************************************************/
5449 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5450 struct spoolss_EndPagePrinter *r)
5454 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5457 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5458 OUR_HANDLE(r->in.handle)));
5462 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5465 Printer->page_started = false;
5466 print_job_endpage(p->msg_ctx, snum, Printer->jobid);
5471 /****************************************************************
5472 _spoolss_StartDocPrinter
5473 ****************************************************************/
5475 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5476 struct spoolss_StartDocPrinter *r)
5478 struct spoolss_DocumentInfo1 *info_1;
5480 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5484 DEBUG(2,("_spoolss_StartDocPrinter: "
5485 "Invalid handle (%s:%u:%u)\n",
5486 OUR_HANDLE(r->in.handle)));
5490 if (Printer->jobid) {
5491 DEBUG(2, ("_spoolss_StartDocPrinter: "
5492 "StartDocPrinter called twice! "
5493 "(existing jobid = %d)\n", Printer->jobid));
5494 return WERR_INVALID_HANDLE;
5497 if (r->in.level != 1) {
5498 return WERR_UNKNOWN_LEVEL;
5501 info_1 = r->in.info.info1;
5504 * a nice thing with NT is it doesn't listen to what you tell it.
5505 * when asked to send _only_ RAW datas, it tries to send datas
5508 * So I add checks like in NT Server ...
5511 if (info_1->datatype) {
5512 if (strcmp(info_1->datatype, "RAW") != 0) {
5514 return WERR_INVALID_DATATYPE;
5518 /* get the share number of the printer */
5519 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5523 werr = print_job_start(get_server_info_system(),
5527 info_1->document_name,
5528 info_1->output_file,
5532 /* An error occured in print_job_start() so return an appropriate
5535 if (!W_ERROR_IS_OK(werr)) {
5539 Printer->document_started = true;
5540 *r->out.job_id = Printer->jobid;
5545 /****************************************************************
5546 _spoolss_EndDocPrinter
5547 ****************************************************************/
5549 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5550 struct spoolss_EndDocPrinter *r)
5552 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5557 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5558 OUR_HANDLE(r->in.handle)));
5562 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5566 Printer->document_started = false;
5567 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5568 if (!NT_STATUS_IS_OK(status)) {
5569 DEBUG(2, ("_spoolss_EndDocPrinter: "
5570 "print_job_end failed [%s]\n",
5571 nt_errstr(status)));
5575 return ntstatus_to_werror(status);
5578 /****************************************************************
5579 _spoolss_WritePrinter
5580 ****************************************************************/
5582 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5583 struct spoolss_WritePrinter *r)
5585 ssize_t buffer_written;
5587 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5590 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5591 OUR_HANDLE(r->in.handle)));
5592 *r->out.num_written = r->in._data_size;
5596 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5599 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5600 buffer_written = print_job_write(server_event_context(),p->msg_ctx,
5601 snum, Printer->jobid,
5602 (const char *)r->in.data.data,
5603 (size_t)r->in._data_size);
5604 if (buffer_written == (ssize_t)-1) {
5605 *r->out.num_written = 0;
5606 if (errno == ENOSPC)
5607 return WERR_NO_SPOOL_SPACE;
5609 return WERR_ACCESS_DENIED;
5612 *r->out.num_written = r->in._data_size;
5617 /********************************************************************
5618 * api_spoolss_getprinter
5619 * called from the spoolss dispatcher
5621 ********************************************************************/
5623 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5624 struct pipes_struct *p)
5626 const struct auth_serversupplied_info *server_info = get_server_info_system();
5628 WERROR errcode = WERR_BADFUNC;
5629 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5632 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5633 OUR_HANDLE(handle)));
5637 if (!get_printer_snum(p, handle, &snum, NULL))
5641 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5642 errcode = print_queue_pause(server_info, p->msg_ctx, snum);
5644 case SPOOLSS_PRINTER_CONTROL_RESUME:
5645 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5646 errcode = print_queue_resume(server_info, p->msg_ctx, snum);
5648 case SPOOLSS_PRINTER_CONTROL_PURGE:
5649 errcode = print_queue_purge(server_info, p->msg_ctx, snum);
5652 return WERR_UNKNOWN_LEVEL;
5659 /****************************************************************
5660 _spoolss_AbortPrinter
5661 * From MSDN: "Deletes printer's spool file if printer is configured
5663 ****************************************************************/
5665 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5666 struct spoolss_AbortPrinter *r)
5668 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5670 WERROR errcode = WERR_OK;
5673 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5674 OUR_HANDLE(r->in.handle)));
5678 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5681 if (!Printer->document_started) {
5682 return WERR_SPL_NO_STARTDOC;
5685 errcode = print_job_delete(get_server_info_system(),
5693 /********************************************************************
5694 * called by spoolss_api_setprinter
5695 * when updating a printer description
5696 ********************************************************************/
5698 static WERROR update_printer_sec(struct policy_handle *handle,
5699 struct pipes_struct *p,
5700 struct sec_desc_buf *secdesc_ctr)
5702 struct spoolss_security_descriptor *new_secdesc = NULL;
5703 struct spoolss_security_descriptor *old_secdesc = NULL;
5704 const char *printer;
5708 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5710 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5711 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5712 OUR_HANDLE(handle)));
5714 result = WERR_BADFID;
5718 if (secdesc_ctr == NULL) {
5719 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5720 result = WERR_INVALID_PARAM;
5723 printer = lp_const_servicename(snum);
5725 /* Check the user has permissions to change the security
5726 descriptor. By experimentation with two NT machines, the user
5727 requires Full Access to the printer to change security
5730 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5731 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5732 result = WERR_ACCESS_DENIED;
5736 /* NT seems to like setting the security descriptor even though
5737 nothing may have actually changed. */
5738 result = winreg_get_printer_secdesc(p->mem_ctx,
5739 get_server_info_system(),
5743 if (!W_ERROR_IS_OK(result)) {
5744 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5745 result = WERR_BADFID;
5749 if (DEBUGLEVEL >= 10) {
5750 struct security_acl *the_acl;
5753 the_acl = old_secdesc->dacl;
5754 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5755 printer, the_acl->num_aces));
5757 for (i = 0; i < the_acl->num_aces; i++) {
5758 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5759 &the_acl->aces[i].trustee),
5760 the_acl->aces[i].access_mask));
5763 the_acl = secdesc_ctr->sd->dacl;
5766 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5767 printer, the_acl->num_aces));
5769 for (i = 0; i < the_acl->num_aces; i++) {
5770 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5771 &the_acl->aces[i].trustee),
5772 the_acl->aces[i].access_mask));
5775 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5779 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
5780 if (new_secdesc == NULL) {
5781 result = WERR_NOMEM;
5785 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
5790 result = winreg_set_printer_secdesc(p->mem_ctx,
5791 get_server_info_system(),
5800 /********************************************************************
5801 Canonicalize printer info from a client
5802 ********************************************************************/
5804 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
5805 struct spoolss_SetPrinterInfo2 *info2,
5808 fstring printername;
5811 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5812 "portname=%s drivername=%s comment=%s location=%s\n",
5813 info2->servername, info2->printername, info2->sharename,
5814 info2->portname, info2->drivername, info2->comment,
5817 /* we force some elements to "correct" values */
5818 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
5819 if (info2->servername == NULL) {
5822 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
5823 if (info2->sharename == NULL) {
5827 /* check to see if we allow printername != sharename */
5828 if (lp_force_printername(snum)) {
5829 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5830 global_myname(), info2->sharename);
5832 /* make sure printername is in \\server\printername format */
5833 fstrcpy(printername, info2->printername);
5835 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5836 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5840 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5841 global_myname(), p);
5843 if (info2->printername == NULL) {
5847 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5848 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5853 /****************************************************************************
5854 ****************************************************************************/
5856 static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const char *portname, const char *uri)
5858 char *cmd = lp_addport_cmd();
5859 char *command = NULL;
5861 bool is_print_op = false;
5864 return WERR_ACCESS_DENIED;
5867 command = talloc_asprintf(ctx,
5868 "%s \"%s\" \"%s\"", cmd, portname, uri );
5874 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
5876 DEBUG(10,("Running [%s]\n", command));
5878 /********* BEGIN SePrintOperatorPrivilege **********/
5883 ret = smbrun(command, NULL);
5888 /********* END SePrintOperatorPrivilege **********/
5890 DEBUGADD(10,("returned [%d]\n", ret));
5892 TALLOC_FREE(command);
5895 return WERR_ACCESS_DENIED;
5901 /****************************************************************************
5902 ****************************************************************************/
5904 static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
5905 struct spoolss_SetPrinterInfo2 *info2,
5906 const char *remote_machine,
5907 struct messaging_context *msg_ctx)
5909 char *cmd = lp_addprinter_cmd();
5911 char *command = NULL;
5915 bool is_print_op = false;
5917 if (!remote_machine) {
5921 command = talloc_asprintf(ctx,
5922 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5923 cmd, info2->printername, info2->sharename,
5924 info2->portname, info2->drivername,
5925 info2->location, info2->comment, remote_machine);
5931 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
5933 DEBUG(10,("Running [%s]\n", command));
5935 /********* BEGIN SePrintOperatorPrivilege **********/
5940 if ( (ret = smbrun(command, &fd)) == 0 ) {
5941 /* Tell everyone we updated smb.conf. */
5942 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5948 /********* END SePrintOperatorPrivilege **********/
5950 DEBUGADD(10,("returned [%d]\n", ret));
5952 TALLOC_FREE(command);
5960 /* reload our services immediately */
5962 reload_services(msg_ctx, -1, false);
5966 /* Get lines and convert them back to dos-codepage */
5967 qlines = fd_lines_load(fd, &numlines, 0, NULL);
5968 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
5971 /* Set the portname to what the script says the portname should be. */
5972 /* but don't require anything to be return from the script exit a good error code */
5975 /* Set the portname to what the script says the portname should be. */
5976 info2->portname = talloc_strdup(ctx, qlines[0]);
5977 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
5980 TALLOC_FREE(qlines);
5984 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
5985 const struct auth_serversupplied_info *server_info,
5986 struct messaging_context *msg_ctx,
5988 struct spoolss_SetPrinterInfo2 *printer,
5989 struct spoolss_PrinterInfo2 *old_printer)
5991 bool force_update = (old_printer == NULL);
5992 const char *dnsdomname;
5993 const char *longname;
5994 const char *uncname;
5995 const char *spooling;
5997 WERROR result = WERR_OK;
5999 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
6000 push_reg_sz(mem_ctx, &buffer, printer->drivername);
6001 winreg_set_printer_dataex(mem_ctx,
6005 SPOOL_DSSPOOLER_KEY,
6006 SPOOL_REG_DRIVERNAME,
6011 if (!force_update) {
6012 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6013 printer->drivername));
6015 notify_printer_driver(server_event_context(), msg_ctx,
6016 snum, printer->drivername);
6020 if (force_update || !strequal(printer->comment, old_printer->comment)) {
6021 push_reg_sz(mem_ctx, &buffer, printer->comment);
6022 winreg_set_printer_dataex(mem_ctx,
6026 SPOOL_DSSPOOLER_KEY,
6027 SPOOL_REG_DESCRIPTION,
6032 if (!force_update) {
6033 notify_printer_comment(server_event_context(), msg_ctx,
6034 snum, printer->comment);
6038 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
6039 push_reg_sz(mem_ctx, &buffer, printer->sharename);
6040 winreg_set_printer_dataex(mem_ctx,
6044 SPOOL_DSSPOOLER_KEY,
6045 SPOOL_REG_PRINTSHARENAME,
6050 if (!force_update) {
6051 notify_printer_sharename(server_event_context(),
6053 snum, printer->sharename);
6057 if (force_update || !strequal(printer->printername, old_printer->printername)) {
6060 p = strrchr(printer->printername, '\\' );
6064 p = printer->printername;
6067 push_reg_sz(mem_ctx, &buffer, p);
6068 winreg_set_printer_dataex(mem_ctx,
6072 SPOOL_DSSPOOLER_KEY,
6073 SPOOL_REG_PRINTERNAME,
6078 if (!force_update) {
6079 notify_printer_printername(server_event_context(),
6084 if (force_update || !strequal(printer->portname, old_printer->portname)) {
6085 push_reg_sz(mem_ctx, &buffer, printer->portname);
6086 winreg_set_printer_dataex(mem_ctx,
6090 SPOOL_DSSPOOLER_KEY,
6096 if (!force_update) {
6097 notify_printer_port(server_event_context(),
6098 msg_ctx, snum, printer->portname);
6102 if (force_update || !strequal(printer->location, old_printer->location)) {
6103 push_reg_sz(mem_ctx, &buffer, printer->location);
6104 winreg_set_printer_dataex(mem_ctx,
6108 SPOOL_DSSPOOLER_KEY,
6114 if (!force_update) {
6115 notify_printer_location(server_event_context(),
6121 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
6122 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
6123 winreg_set_printer_dataex(mem_ctx,
6127 SPOOL_DSSPOOLER_KEY,
6128 SPOOL_REG_PRINTSEPARATORFILE,
6133 if (!force_update) {
6134 notify_printer_location(server_event_context(),
6140 if (force_update || printer->starttime != old_printer->starttime) {
6141 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6142 SIVAL(buffer.data, 0, printer->starttime);
6143 winreg_set_printer_dataex(mem_ctx,
6147 SPOOL_DSSPOOLER_KEY,
6148 SPOOL_REG_PRINTSTARTTIME,
6154 if (force_update || printer->untiltime != old_printer->untiltime) {
6155 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6156 SIVAL(buffer.data, 0, printer->untiltime);
6157 winreg_set_printer_dataex(mem_ctx,
6161 SPOOL_DSSPOOLER_KEY,
6162 SPOOL_REG_PRINTENDTIME,
6168 if (force_update || printer->priority != old_printer->priority) {
6169 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6170 SIVAL(buffer.data, 0, printer->priority);
6171 winreg_set_printer_dataex(mem_ctx,
6175 SPOOL_DSSPOOLER_KEY,
6182 if (force_update || printer->attributes != old_printer->attributes) {
6183 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6184 SIVAL(buffer.data, 0, (printer->attributes &
6185 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
6186 winreg_set_printer_dataex(mem_ctx,
6190 SPOOL_DSSPOOLER_KEY,
6191 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
6196 switch (printer->attributes & 0x3) {
6198 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
6201 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
6204 spooling = SPOOL_REGVAL_PRINTDIRECT;
6207 spooling = "unknown";
6209 push_reg_sz(mem_ctx, &buffer, spooling);
6210 winreg_set_printer_dataex(mem_ctx,
6214 SPOOL_DSSPOOLER_KEY,
6215 SPOOL_REG_PRINTSPOOLING,
6221 push_reg_sz(mem_ctx, &buffer, global_myname());
6222 winreg_set_printer_dataex(mem_ctx,
6226 SPOOL_DSSPOOLER_KEY,
6227 SPOOL_REG_SHORTSERVERNAME,
6232 dnsdomname = get_mydnsfullname();
6233 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
6234 longname = talloc_strdup(mem_ctx, dnsdomname);
6236 longname = talloc_strdup(mem_ctx, global_myname());
6238 if (longname == NULL) {
6239 result = WERR_NOMEM;
6243 push_reg_sz(mem_ctx, &buffer, longname);
6244 winreg_set_printer_dataex(mem_ctx,
6248 SPOOL_DSSPOOLER_KEY,
6249 SPOOL_REG_SERVERNAME,
6254 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6255 global_myname(), printer->sharename);
6256 push_reg_sz(mem_ctx, &buffer, uncname);
6257 winreg_set_printer_dataex(mem_ctx,
6261 SPOOL_DSSPOOLER_KEY,
6271 /********************************************************************
6272 * Called by spoolss_api_setprinter
6273 * when updating a printer description.
6274 ********************************************************************/
6276 static WERROR update_printer(struct pipes_struct *p,
6277 struct policy_handle *handle,
6278 struct spoolss_SetPrinterInfoCtr *info_ctr,
6279 struct spoolss_DeviceMode *devmode)
6281 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6282 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6283 struct spoolss_PrinterInfo2 *old_printer;
6284 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6285 const char *servername = NULL;
6287 WERROR result = WERR_OK;
6288 TALLOC_CTX *tmp_ctx;
6290 DEBUG(8,("update_printer\n"));
6292 tmp_ctx = talloc_new(p->mem_ctx);
6293 if (tmp_ctx == NULL) {
6298 result = WERR_BADFID;
6302 if (!get_printer_snum(p, handle, &snum, NULL)) {
6303 result = WERR_BADFID;
6307 if (Printer != NULL || Printer->servername != NULL) {
6308 servername = Printer->servername;
6311 result = winreg_get_printer(tmp_ctx,
6312 get_server_info_system(),
6315 lp_const_servicename(snum),
6317 if (!W_ERROR_IS_OK(result)) {
6318 result = WERR_BADFID;
6322 /* Do sanity check on the requested changes for Samba */
6323 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6324 result = WERR_INVALID_PARAM;
6328 /* FIXME!!! If the driver has changed we really should verify that
6329 it is installed before doing much else --jerry */
6331 /* Check calling user has permission to update printer description */
6332 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6333 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6334 result = WERR_ACCESS_DENIED;
6338 /* Call addprinter hook */
6339 /* Check changes to see if this is really needed */
6341 if (*lp_addprinter_cmd() &&
6342 (!strequal(printer->drivername, old_printer->drivername) ||
6343 !strequal(printer->comment, old_printer->comment) ||
6344 !strequal(printer->portname, old_printer->portname) ||
6345 !strequal(printer->location, old_printer->location)) )
6347 /* add_printer_hook() will call reload_services() */
6348 if (!add_printer_hook(tmp_ctx, p->server_info->ptok,
6349 printer, p->client_id->addr,
6351 result = WERR_ACCESS_DENIED;
6356 update_dsspooler(tmp_ctx,
6357 get_server_info_system(),
6363 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6365 if (devmode == NULL) {
6366 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6368 result = winreg_update_printer(tmp_ctx,
6369 get_server_info_system(),
6378 talloc_free(tmp_ctx);
6383 /****************************************************************************
6384 ****************************************************************************/
6385 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6386 struct policy_handle *handle,
6387 struct spoolss_SetPrinterInfo7 *info7)
6390 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6393 struct printer_handle *Printer;
6395 if ( lp_security() != SEC_ADS ) {
6396 return WERR_UNKNOWN_LEVEL;
6399 Printer = find_printer_index_by_hnd(p, handle);
6401 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6406 if (!get_printer_snum(p, handle, &snum, NULL))
6409 result = winreg_get_printer(p->mem_ctx,
6410 get_server_info_system(),
6412 Printer->servername,
6413 lp_servicename(snum),
6415 if (!W_ERROR_IS_OK(result)) {
6419 nt_printer_publish(pinfo2,
6420 get_server_info_system(),
6425 TALLOC_FREE(pinfo2);
6428 return WERR_UNKNOWN_LEVEL;
6432 /********************************************************************
6433 ********************************************************************/
6435 static WERROR update_printer_devmode(struct pipes_struct *p,
6436 struct policy_handle *handle,
6437 struct spoolss_DeviceMode *devmode)
6440 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6441 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6443 DEBUG(8,("update_printer_devmode\n"));
6449 if (!get_printer_snum(p, handle, &snum, NULL)) {
6453 /* Check calling user has permission to update printer description */
6454 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6455 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6456 return WERR_ACCESS_DENIED;
6459 return winreg_update_printer(p->mem_ctx,
6460 get_server_info_system(),
6462 lp_const_servicename(snum),
6470 /****************************************************************
6472 ****************************************************************/
6474 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6475 struct spoolss_SetPrinter *r)
6479 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6482 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6483 OUR_HANDLE(r->in.handle)));
6487 /* check the level */
6488 switch (r->in.info_ctr->level) {
6490 return control_printer(r->in.handle, r->in.command, p);
6492 result = update_printer(p, r->in.handle,
6494 r->in.devmode_ctr->devmode);
6495 if (!W_ERROR_IS_OK(result))
6497 if (r->in.secdesc_ctr->sd)
6498 result = update_printer_sec(r->in.handle, p,
6502 return update_printer_sec(r->in.handle, p,
6505 return publish_or_unpublish_printer(p, r->in.handle,
6506 r->in.info_ctr->info.info7);
6508 return update_printer_devmode(p, r->in.handle,
6509 r->in.devmode_ctr->devmode);
6511 return WERR_UNKNOWN_LEVEL;
6515 /****************************************************************
6516 _spoolss_FindClosePrinterNotify
6517 ****************************************************************/
6519 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6520 struct spoolss_FindClosePrinterNotify *r)
6522 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6525 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6526 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6530 if (Printer->notify.cli_chan != NULL &&
6531 Printer->notify.cli_chan->active_connections > 0) {
6534 if (Printer->printer_type == SPLHND_PRINTER) {
6535 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6540 srv_spoolss_replycloseprinter(snum, Printer);
6543 Printer->notify.flags=0;
6544 Printer->notify.options=0;
6545 Printer->notify.localmachine[0]='\0';
6546 Printer->notify.printerlocal=0;
6547 TALLOC_FREE(Printer->notify.option);
6552 /****************************************************************
6554 ****************************************************************/
6556 WERROR _spoolss_AddJob(struct pipes_struct *p,
6557 struct spoolss_AddJob *r)
6559 if (!r->in.buffer && (r->in.offered != 0)) {
6560 return WERR_INVALID_PARAM;
6563 /* this is what a NT server returns for AddJob. AddJob must fail on
6564 * non-local printers */
6566 if (r->in.level != 1) {
6567 return WERR_UNKNOWN_LEVEL;
6570 return WERR_INVALID_PARAM;
6573 /****************************************************************************
6575 ****************************************************************************/
6577 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6578 struct spoolss_JobInfo1 *r,
6579 const print_queue_struct *queue,
6580 int position, int snum,
6581 struct spoolss_PrinterInfo2 *pinfo2)
6585 t = gmtime(&queue->time);
6587 r->job_id = queue->job;
6589 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6590 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6591 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6592 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6593 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6594 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6595 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6596 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6597 r->data_type = talloc_strdup(mem_ctx, "RAW");
6598 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6599 r->text_status = talloc_strdup(mem_ctx, "");
6600 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6602 r->status = nt_printj_status(queue->status);
6603 r->priority = queue->priority;
6604 r->position = position;
6605 r->total_pages = queue->page_count;
6606 r->pages_printed = 0; /* ??? */
6608 init_systemtime(&r->submitted, t);
6613 /****************************************************************************
6615 ****************************************************************************/
6617 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6618 struct spoolss_JobInfo2 *r,
6619 const print_queue_struct *queue,
6620 int position, int snum,
6621 struct spoolss_PrinterInfo2 *pinfo2,
6622 struct spoolss_DeviceMode *devmode)
6626 t = gmtime(&queue->time);
6628 r->job_id = queue->job;
6630 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6631 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6632 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6633 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6634 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6635 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6636 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6637 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6638 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6639 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6640 r->data_type = talloc_strdup(mem_ctx, "RAW");
6641 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6642 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6643 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6644 r->parameters = talloc_strdup(mem_ctx, "");
6645 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6646 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6647 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6649 r->devmode = devmode;
6651 r->text_status = talloc_strdup(mem_ctx, "");
6652 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6656 r->status = nt_printj_status(queue->status);
6657 r->priority = queue->priority;
6658 r->position = position;
6661 r->total_pages = queue->page_count;
6662 r->size = queue->size;
6663 init_systemtime(&r->submitted, t);
6665 r->pages_printed = 0; /* ??? */
6670 /****************************************************************************
6672 ****************************************************************************/
6674 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6675 struct spoolss_JobInfo3 *r,
6676 const print_queue_struct *queue,
6677 const print_queue_struct *next_queue,
6678 int position, int snum,
6679 struct spoolss_PrinterInfo2 *pinfo2)
6681 r->job_id = queue->job;
6684 r->next_job_id = next_queue->job;
6691 /****************************************************************************
6692 Enumjobs at level 1.
6693 ****************************************************************************/
6695 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6696 const print_queue_struct *queue,
6697 uint32_t num_queues, int snum,
6698 struct spoolss_PrinterInfo2 *pinfo2,
6699 union spoolss_JobInfo **info_p,
6702 union spoolss_JobInfo *info;
6704 WERROR result = WERR_OK;
6706 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6707 W_ERROR_HAVE_NO_MEMORY(info);
6709 *count = num_queues;
6711 for (i=0; i<*count; i++) {
6712 result = fill_job_info1(info,
6718 if (!W_ERROR_IS_OK(result)) {
6724 if (!W_ERROR_IS_OK(result)) {
6735 /****************************************************************************
6736 Enumjobs at level 2.
6737 ****************************************************************************/
6739 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6740 const print_queue_struct *queue,
6741 uint32_t num_queues, int snum,
6742 struct spoolss_PrinterInfo2 *pinfo2,
6743 union spoolss_JobInfo **info_p,
6746 union spoolss_JobInfo *info;
6748 WERROR result = WERR_OK;
6750 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6751 W_ERROR_HAVE_NO_MEMORY(info);
6753 *count = num_queues;
6755 for (i=0; i<*count; i++) {
6756 struct spoolss_DeviceMode *devmode;
6758 result = spoolss_create_default_devmode(info,
6759 pinfo2->printername,
6761 if (!W_ERROR_IS_OK(result)) {
6762 DEBUG(3, ("Can't proceed w/o a devmode!"));
6766 result = fill_job_info2(info,
6773 if (!W_ERROR_IS_OK(result)) {
6779 if (!W_ERROR_IS_OK(result)) {
6790 /****************************************************************************
6791 Enumjobs at level 3.
6792 ****************************************************************************/
6794 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6795 const print_queue_struct *queue,
6796 uint32_t num_queues, int snum,
6797 struct spoolss_PrinterInfo2 *pinfo2,
6798 union spoolss_JobInfo **info_p,
6801 union spoolss_JobInfo *info;
6803 WERROR result = WERR_OK;
6805 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6806 W_ERROR_HAVE_NO_MEMORY(info);
6808 *count = num_queues;
6810 for (i=0; i<*count; i++) {
6811 const print_queue_struct *next_queue = NULL;
6814 next_queue = &queue[i+1];
6817 result = fill_job_info3(info,
6824 if (!W_ERROR_IS_OK(result)) {
6830 if (!W_ERROR_IS_OK(result)) {
6841 /****************************************************************
6843 ****************************************************************/
6845 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
6846 struct spoolss_EnumJobs *r)
6849 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6851 print_status_struct prt_status;
6852 print_queue_struct *queue = NULL;
6855 /* that's an [in out] buffer */
6857 if (!r->in.buffer && (r->in.offered != 0)) {
6858 return WERR_INVALID_PARAM;
6861 DEBUG(4,("_spoolss_EnumJobs\n"));
6865 *r->out.info = NULL;
6867 /* lookup the printer snum and tdb entry */
6869 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6873 result = winreg_get_printer(p->mem_ctx,
6874 get_server_info_system(),
6877 lp_const_servicename(snum),
6879 if (!W_ERROR_IS_OK(result)) {
6883 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
6884 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6885 count, prt_status.status, prt_status.message));
6889 TALLOC_FREE(pinfo2);
6893 switch (r->in.level) {
6895 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6896 pinfo2, r->out.info, r->out.count);
6899 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6900 pinfo2, r->out.info, r->out.count);
6903 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
6904 pinfo2, r->out.info, r->out.count);
6907 result = WERR_UNKNOWN_LEVEL;
6912 TALLOC_FREE(pinfo2);
6914 if (!W_ERROR_IS_OK(result)) {
6918 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6920 *r->out.info, r->in.level,
6922 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6923 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6925 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6928 /****************************************************************
6929 _spoolss_ScheduleJob
6930 ****************************************************************/
6932 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
6933 struct spoolss_ScheduleJob *r)
6938 /****************************************************************
6939 ****************************************************************/
6941 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
6942 struct messaging_context *msg_ctx,
6943 const char *printer_name,
6945 struct spoolss_SetJobInfo1 *r)
6949 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
6953 if (strequal(old_doc_name, r->document_name)) {
6957 if (!print_job_set_name(server_event_context(), msg_ctx,
6958 printer_name, job_id, r->document_name)) {
6965 /****************************************************************
6967 ****************************************************************/
6969 WERROR _spoolss_SetJob(struct pipes_struct *p,
6970 struct spoolss_SetJob *r)
6972 const struct auth_serversupplied_info *server_info = get_server_info_system();
6974 WERROR errcode = WERR_BADFUNC;
6976 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6980 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6981 return WERR_INVALID_PRINTER_NAME;
6984 switch (r->in.command) {
6985 case SPOOLSS_JOB_CONTROL_CANCEL:
6986 case SPOOLSS_JOB_CONTROL_DELETE:
6987 errcode = print_job_delete(server_info, p->msg_ctx,
6988 snum, r->in.job_id);
6989 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
6993 case SPOOLSS_JOB_CONTROL_PAUSE:
6994 if (print_job_pause(server_info, p->msg_ctx,
6995 snum, r->in.job_id, &errcode)) {
6999 case SPOOLSS_JOB_CONTROL_RESTART:
7000 case SPOOLSS_JOB_CONTROL_RESUME:
7001 if (print_job_resume(server_info, p->msg_ctx,
7002 snum, r->in.job_id, &errcode)) {
7010 return WERR_UNKNOWN_LEVEL;
7013 if (!W_ERROR_IS_OK(errcode)) {
7017 if (r->in.ctr == NULL) {
7021 switch (r->in.ctr->level) {
7023 errcode = spoolss_setjob_1(p->mem_ctx, p->msg_ctx,
7024 lp_const_servicename(snum),
7026 r->in.ctr->info.info1);
7032 return WERR_UNKNOWN_LEVEL;
7038 /****************************************************************************
7039 Enumerates all printer drivers by level and architecture.
7040 ****************************************************************************/
7042 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
7043 const struct auth_serversupplied_info *server_info,
7044 struct messaging_context *msg_ctx,
7045 const char *servername,
7046 const char *architecture,
7048 union spoolss_DriverInfo **info_p,
7053 struct spoolss_DriverInfo8 *driver;
7054 union spoolss_DriverInfo *info = NULL;
7056 WERROR result = WERR_OK;
7057 uint32_t num_drivers;
7058 const char **drivers;
7063 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7064 result = winreg_get_driver_list(mem_ctx, server_info, msg_ctx,
7065 architecture, version,
7066 &num_drivers, &drivers);
7067 if (!W_ERROR_IS_OK(result)) {
7070 DEBUG(4, ("we have:[%d] drivers in environment"
7071 " [%s] and version [%d]\n",
7072 num_drivers, architecture, version));
7074 if (num_drivers != 0) {
7075 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
7076 union spoolss_DriverInfo,
7077 count + num_drivers);
7079 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7080 "failed to enlarge driver info buffer!\n"));
7081 result = WERR_NOMEM;
7086 for (i = 0; i < num_drivers; i++) {
7087 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
7089 result = winreg_get_driver(mem_ctx, server_info,
7091 architecture, drivers[i],
7093 if (!W_ERROR_IS_OK(result)) {
7099 result = fill_printer_driver_info1(info, &info[count+i].info1,
7100 driver, servername);
7103 result = fill_printer_driver_info2(info, &info[count+i].info2,
7104 driver, servername);
7107 result = fill_printer_driver_info3(info, &info[count+i].info3,
7108 driver, servername);
7111 result = fill_printer_driver_info4(info, &info[count+i].info4,
7112 driver, servername);
7115 result = fill_printer_driver_info5(info, &info[count+i].info5,
7116 driver, servername);
7119 result = fill_printer_driver_info6(info, &info[count+i].info6,
7120 driver, servername);
7123 result = fill_printer_driver_info8(info, &info[count+i].info8,
7124 driver, servername);
7127 result = WERR_UNKNOWN_LEVEL;
7131 TALLOC_FREE(driver);
7133 if (!W_ERROR_IS_OK(result)) {
7138 count += num_drivers;
7139 TALLOC_FREE(drivers);
7143 TALLOC_FREE(drivers);
7145 if (!W_ERROR_IS_OK(result)) {
7156 /****************************************************************************
7157 Enumerates all printer drivers by level.
7158 ****************************************************************************/
7160 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
7161 const struct auth_serversupplied_info *server_info,
7162 struct messaging_context *msg_ctx,
7163 const char *servername,
7164 const char *architecture,
7166 union spoolss_DriverInfo **info_p,
7170 WERROR result = WERR_OK;
7172 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
7174 for (a=0; archi_table[a].long_archi != NULL; a++) {
7176 union spoolss_DriverInfo *info = NULL;
7179 result = enumprinterdrivers_level_by_architecture(mem_ctx,
7183 archi_table[a].long_archi,
7187 if (!W_ERROR_IS_OK(result)) {
7191 for (i=0; i < count; i++) {
7192 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
7193 info[i], info_p, count_p);
7200 return enumprinterdrivers_level_by_architecture(mem_ctx,
7210 /****************************************************************
7211 _spoolss_EnumPrinterDrivers
7212 ****************************************************************/
7214 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
7215 struct spoolss_EnumPrinterDrivers *r)
7217 const char *cservername;
7220 /* that's an [in out] buffer */
7222 if (!r->in.buffer && (r->in.offered != 0)) {
7223 return WERR_INVALID_PARAM;
7226 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7230 *r->out.info = NULL;
7232 cservername = canon_servername(r->in.server);
7234 if (!is_myname_or_ipaddr(cservername)) {
7235 return WERR_UNKNOWN_PRINTER_DRIVER;
7238 result = enumprinterdrivers_level(p->mem_ctx,
7239 get_server_info_system(),
7246 if (!W_ERROR_IS_OK(result)) {
7250 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7251 spoolss_EnumPrinterDrivers,
7252 *r->out.info, r->in.level,
7254 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7255 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7257 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7260 /****************************************************************
7262 ****************************************************************/
7264 WERROR _spoolss_EnumForms(struct pipes_struct *p,
7265 struct spoolss_EnumForms *r)
7271 *r->out.info = NULL;
7273 /* that's an [in out] buffer */
7275 if (!r->in.buffer && (r->in.offered != 0) ) {
7276 return WERR_INVALID_PARAM;
7279 DEBUG(4,("_spoolss_EnumForms\n"));
7280 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7281 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7283 switch (r->in.level) {
7285 result = winreg_printer_enumforms1(p->mem_ctx,
7286 get_server_info_system(),
7292 result = WERR_UNKNOWN_LEVEL;
7296 if (!W_ERROR_IS_OK(result)) {
7300 if (*r->out.count == 0) {
7301 return WERR_NO_MORE_ITEMS;
7304 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7306 *r->out.info, r->in.level,
7308 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7309 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7311 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7314 /****************************************************************
7316 ****************************************************************/
7318 WERROR _spoolss_GetForm(struct pipes_struct *p,
7319 struct spoolss_GetForm *r)
7323 /* that's an [in out] buffer */
7325 if (!r->in.buffer && (r->in.offered != 0)) {
7326 return WERR_INVALID_PARAM;
7329 DEBUG(4,("_spoolss_GetForm\n"));
7330 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7331 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7333 switch (r->in.level) {
7335 result = winreg_printer_getform1(p->mem_ctx,
7336 get_server_info_system(),
7339 &r->out.info->info1);
7342 result = WERR_UNKNOWN_LEVEL;
7346 if (!W_ERROR_IS_OK(result)) {
7347 TALLOC_FREE(r->out.info);
7351 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7352 r->out.info, r->in.level);
7353 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7355 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7358 /****************************************************************************
7359 ****************************************************************************/
7361 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7362 struct spoolss_PortInfo1 *r,
7365 r->port_name = talloc_strdup(mem_ctx, name);
7366 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7371 /****************************************************************************
7372 TODO: This probably needs distinguish between TCP/IP and Local ports
7374 ****************************************************************************/
7376 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7377 struct spoolss_PortInfo2 *r,
7380 r->port_name = talloc_strdup(mem_ctx, name);
7381 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7383 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7384 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7386 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7387 W_ERROR_HAVE_NO_MEMORY(r->description);
7389 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7396 /****************************************************************************
7397 wrapper around the enumer ports command
7398 ****************************************************************************/
7400 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7402 char *cmd = lp_enumports_cmd();
7403 char **qlines = NULL;
7404 char *command = NULL;
7412 /* if no hook then just fill in the default port */
7415 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7418 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7419 TALLOC_FREE(qlines);
7426 /* we have a valid enumport command */
7428 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7433 DEBUG(10,("Running [%s]\n", command));
7434 ret = smbrun(command, &fd);
7435 DEBUG(10,("Returned [%d]\n", ret));
7436 TALLOC_FREE(command);
7441 return WERR_ACCESS_DENIED;
7445 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7446 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7456 /****************************************************************************
7458 ****************************************************************************/
7460 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7461 union spoolss_PortInfo **info_p,
7464 union spoolss_PortInfo *info = NULL;
7466 WERROR result = WERR_OK;
7467 char **qlines = NULL;
7470 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7471 if (!W_ERROR_IS_OK(result)) {
7476 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7478 DEBUG(10,("Returning WERR_NOMEM\n"));
7479 result = WERR_NOMEM;
7483 for (i=0; i<numlines; i++) {
7484 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7485 result = fill_port_1(info, &info[i].info1, qlines[i]);
7486 if (!W_ERROR_IS_OK(result)) {
7491 TALLOC_FREE(qlines);
7494 if (!W_ERROR_IS_OK(result)) {
7496 TALLOC_FREE(qlines);
7508 /****************************************************************************
7510 ****************************************************************************/
7512 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7513 union spoolss_PortInfo **info_p,
7516 union spoolss_PortInfo *info = NULL;
7518 WERROR result = WERR_OK;
7519 char **qlines = NULL;
7522 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7523 if (!W_ERROR_IS_OK(result)) {
7528 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7530 DEBUG(10,("Returning WERR_NOMEM\n"));
7531 result = WERR_NOMEM;
7535 for (i=0; i<numlines; i++) {
7536 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7537 result = fill_port_2(info, &info[i].info2, qlines[i]);
7538 if (!W_ERROR_IS_OK(result)) {
7543 TALLOC_FREE(qlines);
7546 if (!W_ERROR_IS_OK(result)) {
7548 TALLOC_FREE(qlines);
7560 /****************************************************************
7562 ****************************************************************/
7564 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
7565 struct spoolss_EnumPorts *r)
7569 /* that's an [in out] buffer */
7571 if (!r->in.buffer && (r->in.offered != 0)) {
7572 return WERR_INVALID_PARAM;
7575 DEBUG(4,("_spoolss_EnumPorts\n"));
7579 *r->out.info = NULL;
7581 switch (r->in.level) {
7583 result = enumports_level_1(p->mem_ctx, r->out.info,
7587 result = enumports_level_2(p->mem_ctx, r->out.info,
7591 return WERR_UNKNOWN_LEVEL;
7594 if (!W_ERROR_IS_OK(result)) {
7598 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7600 *r->out.info, r->in.level,
7602 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7603 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7605 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7608 /****************************************************************************
7609 ****************************************************************************/
7611 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
7613 struct spoolss_SetPrinterInfoCtr *info_ctr,
7614 struct spoolss_DeviceMode *devmode,
7615 struct security_descriptor *secdesc,
7616 struct spoolss_UserLevelCtr *user_ctr,
7617 struct policy_handle *handle)
7619 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7620 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7622 WERROR err = WERR_OK;
7624 /* samba does not have a concept of local, non-shared printers yet, so
7625 * make sure we always setup sharename - gd */
7626 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7627 (info2->printername != NULL && info2->printername[0] != '\0')) {
7628 DEBUG(5, ("spoolss_addprinterex_level_2: "
7629 "no sharename has been set, setting printername %s as sharename\n",
7630 info2->printername));
7631 info2->sharename = info2->printername;
7634 /* check to see if the printer already exists */
7635 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7636 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7638 return WERR_PRINTER_ALREADY_EXISTS;
7641 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7642 if ((snum = print_queue_snum(info2->printername)) != -1) {
7643 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7644 info2->printername));
7645 return WERR_PRINTER_ALREADY_EXISTS;
7649 /* validate printer info struct */
7650 if (!info2->printername || strlen(info2->printername) == 0) {
7651 return WERR_INVALID_PRINTER_NAME;
7653 if (!info2->portname || strlen(info2->portname) == 0) {
7654 return WERR_UNKNOWN_PORT;
7656 if (!info2->drivername || strlen(info2->drivername) == 0) {
7657 return WERR_UNKNOWN_PRINTER_DRIVER;
7659 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7660 return WERR_UNKNOWN_PRINTPROCESSOR;
7663 /* FIXME!!! smbd should check to see if the driver is installed before
7664 trying to add a printer like this --jerry */
7666 if (*lp_addprinter_cmd() ) {
7667 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7668 info2, p->client_id->addr,
7670 return WERR_ACCESS_DENIED;
7673 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7674 "smb.conf parameter \"addprinter command\" is defined. This"
7675 "parameter must exist for this call to succeed\n",
7676 info2->sharename ));
7679 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7680 return WERR_ACCESS_DENIED;
7683 /* you must be a printer admin to add a new printer */
7684 if (!print_access_check(get_server_info_system(),
7687 PRINTER_ACCESS_ADMINISTER)) {
7688 return WERR_ACCESS_DENIED;
7692 * Do sanity check on the requested changes for Samba.
7695 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7696 return WERR_INVALID_PARAM;
7699 if (devmode == NULL) {
7700 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7703 update_dsspooler(p->mem_ctx,
7704 get_server_info_system(),
7710 err = winreg_update_printer(p->mem_ctx,
7711 get_server_info_system(),
7718 if (!W_ERROR_IS_OK(err)) {
7722 if (!open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER)) {
7723 /* Handle open failed - remove addition. */
7724 ZERO_STRUCTP(handle);
7725 return WERR_ACCESS_DENIED;
7731 /****************************************************************
7732 _spoolss_AddPrinterEx
7733 ****************************************************************/
7735 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
7736 struct spoolss_AddPrinterEx *r)
7738 switch (r->in.info_ctr->level) {
7740 /* we don't handle yet */
7741 /* but I know what to do ... */
7742 return WERR_UNKNOWN_LEVEL;
7744 return spoolss_addprinterex_level_2(p, r->in.server,
7746 r->in.devmode_ctr->devmode,
7747 r->in.secdesc_ctr->sd,
7748 r->in.userlevel_ctr,
7751 return WERR_UNKNOWN_LEVEL;
7755 /****************************************************************
7757 ****************************************************************/
7759 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
7760 struct spoolss_AddPrinter *r)
7762 struct spoolss_AddPrinterEx a;
7763 struct spoolss_UserLevelCtr userlevel_ctr;
7765 ZERO_STRUCT(userlevel_ctr);
7767 userlevel_ctr.level = 1;
7769 a.in.server = r->in.server;
7770 a.in.info_ctr = r->in.info_ctr;
7771 a.in.devmode_ctr = r->in.devmode_ctr;
7772 a.in.secdesc_ctr = r->in.secdesc_ctr;
7773 a.in.userlevel_ctr = &userlevel_ctr;
7774 a.out.handle = r->out.handle;
7776 return _spoolss_AddPrinterEx(p, &a);
7779 /****************************************************************
7780 _spoolss_AddPrinterDriverEx
7781 ****************************************************************/
7783 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
7784 struct spoolss_AddPrinterDriverEx *r)
7786 WERROR err = WERR_OK;
7787 const char *driver_name = NULL;
7792 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7793 fn = "_spoolss_AddPrinterDriver";
7795 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7796 fn = "_spoolss_AddPrinterDriverEx";
7799 return WERR_INVALID_PARAM;
7803 * we only support the semantics of AddPrinterDriver()
7804 * i.e. only copy files that are newer than existing ones
7807 if (r->in.flags == 0) {
7808 return WERR_INVALID_PARAM;
7811 if (r->in.flags != APD_COPY_NEW_FILES) {
7812 return WERR_ACCESS_DENIED;
7816 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7817 /* Clever hack from Martin Zielinski <mz@seh.de>
7818 * to allow downgrade from level 8 (Vista).
7820 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7821 r->in.info_ctr->level));
7822 return WERR_UNKNOWN_LEVEL;
7825 DEBUG(5,("Cleaning driver's information\n"));
7826 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
7827 if (!W_ERROR_IS_OK(err))
7830 DEBUG(5,("Moving driver to final destination\n"));
7831 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7836 err = winreg_add_driver(p->mem_ctx,
7837 get_server_info_system(),
7842 if (!W_ERROR_IS_OK(err)) {
7847 * I think this is where he DrvUpgradePrinter() hook would be
7848 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7849 * server. Right now, we just need to send ourselves a message
7850 * to update each printer bound to this driver. --jerry
7853 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
7854 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7862 /****************************************************************
7863 _spoolss_AddPrinterDriver
7864 ****************************************************************/
7866 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
7867 struct spoolss_AddPrinterDriver *r)
7869 struct spoolss_AddPrinterDriverEx a;
7871 switch (r->in.info_ctr->level) {
7878 return WERR_UNKNOWN_LEVEL;
7881 a.in.servername = r->in.servername;
7882 a.in.info_ctr = r->in.info_ctr;
7883 a.in.flags = APD_COPY_NEW_FILES;
7885 return _spoolss_AddPrinterDriverEx(p, &a);
7888 /****************************************************************************
7889 ****************************************************************************/
7891 struct _spoolss_paths {
7897 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7899 static const struct _spoolss_paths spoolss_paths[]= {
7900 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7901 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7904 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7905 const char *servername,
7906 const char *environment,
7910 const char *pservername = NULL;
7911 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7912 const char *short_archi;
7916 /* environment may be empty */
7917 if (environment && strlen(environment)) {
7918 long_archi = environment;
7921 /* servername may be empty */
7922 if (servername && strlen(servername)) {
7923 pservername = canon_servername(servername);
7925 if (!is_myname_or_ipaddr(pservername)) {
7926 return WERR_INVALID_PARAM;
7930 if (!(short_archi = get_short_archi(long_archi))) {
7931 return WERR_INVALID_ENVIRONMENT;
7934 switch (component) {
7935 case SPOOLSS_PRTPROCS_PATH:
7936 case SPOOLSS_DRIVER_PATH:
7938 *path = talloc_asprintf(mem_ctx,
7941 spoolss_paths[component].share,
7944 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7945 SPOOLSS_DEFAULT_SERVER_PATH,
7946 spoolss_paths[component].dir,
7951 return WERR_INVALID_PARAM;
7961 /****************************************************************************
7962 ****************************************************************************/
7964 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7965 const char *servername,
7966 const char *environment,
7967 struct spoolss_DriverDirectoryInfo1 *r)
7972 werr = compose_spoolss_server_path(mem_ctx,
7975 SPOOLSS_DRIVER_PATH,
7977 if (!W_ERROR_IS_OK(werr)) {
7981 DEBUG(4,("printer driver directory: [%s]\n", path));
7983 r->directory_name = path;
7988 /****************************************************************
7989 _spoolss_GetPrinterDriverDirectory
7990 ****************************************************************/
7992 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
7993 struct spoolss_GetPrinterDriverDirectory *r)
7997 /* that's an [in out] buffer */
7999 if (!r->in.buffer && (r->in.offered != 0)) {
8000 return WERR_INVALID_PARAM;
8003 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8008 /* r->in.level is ignored */
8010 werror = getprinterdriverdir_level_1(p->mem_ctx,
8013 &r->out.info->info1);
8014 if (!W_ERROR_IS_OK(werror)) {
8015 TALLOC_FREE(r->out.info);
8019 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
8020 r->out.info, r->in.level);
8021 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8023 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8026 /****************************************************************
8027 _spoolss_EnumPrinterData
8028 ****************************************************************/
8030 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
8031 struct spoolss_EnumPrinterData *r)
8034 struct spoolss_EnumPrinterDataEx r2;
8036 struct spoolss_PrinterEnumValues *info, *val = NULL;
8039 r2.in.handle = r->in.handle;
8040 r2.in.key_name = "PrinterDriverData";
8042 r2.out.count = &count;
8043 r2.out.info = &info;
8044 r2.out.needed = &needed;
8046 result = _spoolss_EnumPrinterDataEx(p, &r2);
8047 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8048 r2.in.offered = needed;
8049 result = _spoolss_EnumPrinterDataEx(p, &r2);
8051 if (!W_ERROR_IS_OK(result)) {
8056 * The NT machine wants to know the biggest size of value and data
8058 * cf: MSDN EnumPrinterData remark section
8061 if (!r->in.value_offered && !r->in.data_offered) {
8062 uint32_t biggest_valuesize = 0;
8063 uint32_t biggest_datasize = 0;
8066 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8068 for (i=0; i<count; i++) {
8070 name_length = strlen(info[i].value_name);
8071 if (strlen(info[i].value_name) > biggest_valuesize) {
8072 biggest_valuesize = name_length;
8075 if (info[i].data_length > biggest_datasize) {
8076 biggest_datasize = info[i].data_length;
8079 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8083 /* the value is an UNICODE string but real_value_size is the length
8084 in bytes including the trailing 0 */
8086 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8087 *r->out.data_needed = biggest_datasize;
8089 DEBUG(6,("final values: [%d], [%d]\n",
8090 *r->out.value_needed, *r->out.data_needed));
8095 if (r->in.enum_index < count) {
8096 val = &info[r->in.enum_index];
8100 /* out_value should default to "" or else NT4 has
8101 problems unmarshalling the response */
8103 if (r->in.value_offered) {
8104 *r->out.value_needed = 1;
8105 r->out.value_name = talloc_strdup(r, "");
8106 if (!r->out.value_name) {
8110 r->out.value_name = NULL;
8111 *r->out.value_needed = 0;
8114 /* the data is counted in bytes */
8116 *r->out.data_needed = r->in.data_offered;
8118 result = WERR_NO_MORE_ITEMS;
8122 * - counted in bytes in the request
8123 * - counted in UNICODE chars in the max reply
8124 * - counted in bytes in the real size
8126 * take a pause *before* coding not *during* coding
8130 if (r->in.value_offered) {
8131 r->out.value_name = talloc_strdup(r, val->value_name);
8132 if (!r->out.value_name) {
8135 *r->out.value_needed = val->value_name_len;
8137 r->out.value_name = NULL;
8138 *r->out.value_needed = 0;
8143 *r->out.type = val->type;
8145 /* data - counted in bytes */
8148 * See the section "Dynamically Typed Query Parameters"
8152 if (r->out.data && val->data && val->data->data &&
8153 val->data_length && r->in.data_offered) {
8154 memcpy(r->out.data, val->data->data,
8155 MIN(val->data_length,r->in.data_offered));
8158 *r->out.data_needed = val->data_length;
8166 /****************************************************************
8167 _spoolss_SetPrinterData
8168 ****************************************************************/
8170 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
8171 struct spoolss_SetPrinterData *r)
8173 struct spoolss_SetPrinterDataEx r2;
8175 r2.in.handle = r->in.handle;
8176 r2.in.key_name = "PrinterDriverData";
8177 r2.in.value_name = r->in.value_name;
8178 r2.in.type = r->in.type;
8179 r2.in.data = r->in.data;
8180 r2.in.offered = r->in.offered;
8182 return _spoolss_SetPrinterDataEx(p, &r2);
8185 /****************************************************************
8186 _spoolss_ResetPrinter
8187 ****************************************************************/
8189 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
8190 struct spoolss_ResetPrinter *r)
8192 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8195 DEBUG(5,("_spoolss_ResetPrinter\n"));
8198 * All we do is to check to see if the handle and queue is valid.
8199 * This call really doesn't mean anything to us because we only
8200 * support RAW printing. --jerry
8204 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8205 OUR_HANDLE(r->in.handle)));
8209 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8213 /* blindly return success */
8217 /****************************************************************
8218 _spoolss_DeletePrinterData
8219 ****************************************************************/
8221 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
8222 struct spoolss_DeletePrinterData *r)
8224 struct spoolss_DeletePrinterDataEx r2;
8226 r2.in.handle = r->in.handle;
8227 r2.in.key_name = "PrinterDriverData";
8228 r2.in.value_name = r->in.value_name;
8230 return _spoolss_DeletePrinterDataEx(p, &r2);
8233 /****************************************************************
8235 ****************************************************************/
8237 WERROR _spoolss_AddForm(struct pipes_struct *p,
8238 struct spoolss_AddForm *r)
8240 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8242 WERROR status = WERR_OK;
8244 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8246 DEBUG(5,("_spoolss_AddForm\n"));
8249 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8250 OUR_HANDLE(r->in.handle)));
8254 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8255 and not a printer admin, then fail */
8257 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8258 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
8259 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8260 p->server_info->info3->base.domain.string,
8262 p->server_info->ptok,
8263 lp_printer_admin(snum))) {
8264 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8265 return WERR_ACCESS_DENIED;
8268 switch (form->flags) {
8269 case SPOOLSS_FORM_USER:
8270 case SPOOLSS_FORM_BUILTIN:
8271 case SPOOLSS_FORM_PRINTER:
8274 return WERR_INVALID_PARAM;
8277 status = winreg_printer_addform1(p->mem_ctx,
8278 get_server_info_system(),
8281 if (!W_ERROR_IS_OK(status)) {
8286 * ChangeID must always be set if this is a printer
8288 if (Printer->printer_type == SPLHND_PRINTER) {
8289 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8293 status = winreg_printer_update_changeid(p->mem_ctx,
8294 get_server_info_system(),
8296 lp_const_servicename(snum));
8297 if (!W_ERROR_IS_OK(status)) {
8305 /****************************************************************
8307 ****************************************************************/
8309 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8310 struct spoolss_DeleteForm *r)
8312 const char *form_name = r->in.form_name;
8313 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8315 WERROR status = WERR_OK;
8317 DEBUG(5,("_spoolss_DeleteForm\n"));
8320 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8321 OUR_HANDLE(r->in.handle)));
8325 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8326 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
8327 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8328 p->server_info->info3->base.domain.string,
8330 p->server_info->ptok,
8331 lp_printer_admin(snum))) {
8332 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8333 return WERR_ACCESS_DENIED;
8336 status = winreg_printer_deleteform1(p->mem_ctx,
8337 get_server_info_system(),
8340 if (!W_ERROR_IS_OK(status)) {
8345 * ChangeID must always be set if this is a printer
8347 if (Printer->printer_type == SPLHND_PRINTER) {
8348 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8352 status = winreg_printer_update_changeid(p->mem_ctx,
8353 get_server_info_system(),
8355 lp_const_servicename(snum));
8356 if (!W_ERROR_IS_OK(status)) {
8364 /****************************************************************
8366 ****************************************************************/
8368 WERROR _spoolss_SetForm(struct pipes_struct *p,
8369 struct spoolss_SetForm *r)
8371 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8372 const char *form_name = r->in.form_name;
8374 WERROR status = WERR_OK;
8376 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8378 DEBUG(5,("_spoolss_SetForm\n"));
8381 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8382 OUR_HANDLE(r->in.handle)));
8386 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8387 and not a printer admin, then fail */
8389 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8390 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
8391 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8392 p->server_info->info3->base.domain.string,
8394 p->server_info->ptok,
8395 lp_printer_admin(snum))) {
8396 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8397 return WERR_ACCESS_DENIED;
8400 status = winreg_printer_setform1(p->mem_ctx,
8401 get_server_info_system(),
8405 if (!W_ERROR_IS_OK(status)) {
8410 * ChangeID must always be set if this is a printer
8412 if (Printer->printer_type == SPLHND_PRINTER) {
8413 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8417 status = winreg_printer_update_changeid(p->mem_ctx,
8418 get_server_info_system(),
8420 lp_const_servicename(snum));
8421 if (!W_ERROR_IS_OK(status)) {
8429 /****************************************************************************
8430 fill_print_processor1
8431 ****************************************************************************/
8433 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8434 struct spoolss_PrintProcessorInfo1 *r,
8435 const char *print_processor_name)
8437 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8438 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8443 /****************************************************************************
8444 enumprintprocessors level 1.
8445 ****************************************************************************/
8447 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8448 union spoolss_PrintProcessorInfo **info_p,
8451 union spoolss_PrintProcessorInfo *info;
8454 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8455 W_ERROR_HAVE_NO_MEMORY(info);
8459 result = fill_print_processor1(info, &info[0].info1, "winprint");
8460 if (!W_ERROR_IS_OK(result)) {
8465 if (!W_ERROR_IS_OK(result)) {
8476 /****************************************************************
8477 _spoolss_EnumPrintProcessors
8478 ****************************************************************/
8480 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8481 struct spoolss_EnumPrintProcessors *r)
8485 /* that's an [in out] buffer */
8487 if (!r->in.buffer && (r->in.offered != 0)) {
8488 return WERR_INVALID_PARAM;
8491 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8494 * Enumerate the print processors ...
8496 * Just reply with "winprint", to keep NT happy
8497 * and I can use my nice printer checker.
8502 *r->out.info = NULL;
8504 if (!get_short_archi(r->in.environment)) {
8505 return WERR_INVALID_ENVIRONMENT;
8508 switch (r->in.level) {
8510 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8514 return WERR_UNKNOWN_LEVEL;
8517 if (!W_ERROR_IS_OK(result)) {
8521 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8522 spoolss_EnumPrintProcessors,
8523 *r->out.info, r->in.level,
8525 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8526 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8528 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8531 /****************************************************************************
8532 fill_printprocdatatype1
8533 ****************************************************************************/
8535 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8536 struct spoolss_PrintProcDataTypesInfo1 *r,
8537 const char *name_array)
8539 r->name_array = talloc_strdup(mem_ctx, name_array);
8540 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8545 /****************************************************************************
8546 enumprintprocdatatypes level 1.
8547 ****************************************************************************/
8549 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8550 union spoolss_PrintProcDataTypesInfo **info_p,
8554 union spoolss_PrintProcDataTypesInfo *info;
8556 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8557 W_ERROR_HAVE_NO_MEMORY(info);
8561 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8562 if (!W_ERROR_IS_OK(result)) {
8567 if (!W_ERROR_IS_OK(result)) {
8578 /****************************************************************
8579 _spoolss_EnumPrintProcDataTypes
8580 ****************************************************************/
8582 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
8583 struct spoolss_EnumPrintProcDataTypes *r)
8587 /* that's an [in out] buffer */
8589 if (!r->in.buffer && (r->in.offered != 0)) {
8590 return WERR_INVALID_PARAM;
8593 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8597 *r->out.info = NULL;
8599 switch (r->in.level) {
8601 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8605 return WERR_UNKNOWN_LEVEL;
8608 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8609 spoolss_EnumPrintProcDataTypes,
8610 *r->out.info, r->in.level,
8612 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8613 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8615 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8618 /****************************************************************************
8620 ****************************************************************************/
8622 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8623 struct spoolss_MonitorInfo1 *r,
8624 const char *monitor_name)
8626 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8627 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8632 /****************************************************************************
8634 ****************************************************************************/
8636 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8637 struct spoolss_MonitorInfo2 *r,
8638 const char *monitor_name,
8639 const char *environment,
8640 const char *dll_name)
8642 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8643 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8644 r->environment = talloc_strdup(mem_ctx, environment);
8645 W_ERROR_HAVE_NO_MEMORY(r->environment);
8646 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8647 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8652 /****************************************************************************
8653 enumprintmonitors level 1.
8654 ****************************************************************************/
8656 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8657 union spoolss_MonitorInfo **info_p,
8660 union spoolss_MonitorInfo *info;
8661 WERROR result = WERR_OK;
8663 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8664 W_ERROR_HAVE_NO_MEMORY(info);
8668 result = fill_monitor_1(info, &info[0].info1,
8670 if (!W_ERROR_IS_OK(result)) {
8674 result = fill_monitor_1(info, &info[1].info1,
8676 if (!W_ERROR_IS_OK(result)) {
8681 if (!W_ERROR_IS_OK(result)) {
8692 /****************************************************************************
8693 enumprintmonitors level 2.
8694 ****************************************************************************/
8696 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8697 union spoolss_MonitorInfo **info_p,
8700 union spoolss_MonitorInfo *info;
8701 WERROR result = WERR_OK;
8703 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8704 W_ERROR_HAVE_NO_MEMORY(info);
8708 result = fill_monitor_2(info, &info[0].info2,
8710 "Windows NT X86", /* FIXME */
8712 if (!W_ERROR_IS_OK(result)) {
8716 result = fill_monitor_2(info, &info[1].info2,
8718 "Windows NT X86", /* FIXME */
8720 if (!W_ERROR_IS_OK(result)) {
8725 if (!W_ERROR_IS_OK(result)) {
8736 /****************************************************************
8737 _spoolss_EnumMonitors
8738 ****************************************************************/
8740 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
8741 struct spoolss_EnumMonitors *r)
8745 /* that's an [in out] buffer */
8747 if (!r->in.buffer && (r->in.offered != 0)) {
8748 return WERR_INVALID_PARAM;
8751 DEBUG(5,("_spoolss_EnumMonitors\n"));
8754 * Enumerate the print monitors ...
8756 * Just reply with "Local Port", to keep NT happy
8757 * and I can use my nice printer checker.
8762 *r->out.info = NULL;
8764 switch (r->in.level) {
8766 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8770 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8774 return WERR_UNKNOWN_LEVEL;
8777 if (!W_ERROR_IS_OK(result)) {
8781 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8782 spoolss_EnumMonitors,
8783 *r->out.info, r->in.level,
8785 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8786 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8788 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8791 /****************************************************************************
8792 ****************************************************************************/
8794 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8795 const print_queue_struct *queue,
8796 int count, int snum,
8797 struct spoolss_PrinterInfo2 *pinfo2,
8799 struct spoolss_JobInfo1 *r)
8804 for (i=0; i<count; i++) {
8805 if (queue[i].job == (int)jobid) {
8811 if (found == false) {
8812 /* NT treats not found as bad param... yet another bad choice */
8813 return WERR_INVALID_PARAM;
8816 return fill_job_info1(mem_ctx,
8824 /****************************************************************************
8825 ****************************************************************************/
8827 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8828 const print_queue_struct *queue,
8829 int count, int snum,
8830 struct spoolss_PrinterInfo2 *pinfo2,
8832 struct spoolss_JobInfo2 *r)
8836 struct spoolss_DeviceMode *devmode;
8839 for (i=0; i<count; i++) {
8840 if (queue[i].job == (int)jobid) {
8846 if (found == false) {
8847 /* NT treats not found as bad param... yet another bad
8849 return WERR_INVALID_PARAM;
8853 * if the print job does not have a DEVMODE associated with it,
8854 * just use the one for the printer. A NULL devicemode is not
8855 * a failure condition
8858 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8860 result = spoolss_create_default_devmode(mem_ctx,
8861 pinfo2->printername,
8863 if (!W_ERROR_IS_OK(result)) {
8864 DEBUG(3, ("Can't proceed w/o a devmode!"));
8869 return fill_job_info2(mem_ctx,
8878 /****************************************************************
8880 ****************************************************************/
8882 WERROR _spoolss_GetJob(struct pipes_struct *p,
8883 struct spoolss_GetJob *r)
8885 WERROR result = WERR_OK;
8886 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8889 print_queue_struct *queue = NULL;
8890 print_status_struct prt_status;
8892 /* that's an [in out] buffer */
8894 if (!r->in.buffer && (r->in.offered != 0)) {
8895 return WERR_INVALID_PARAM;
8898 DEBUG(5,("_spoolss_GetJob\n"));
8902 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8906 result = winreg_get_printer(p->mem_ctx,
8907 get_server_info_system(),
8910 lp_const_servicename(snum),
8912 if (!W_ERROR_IS_OK(result)) {
8916 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
8918 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8919 count, prt_status.status, prt_status.message));
8921 switch (r->in.level) {
8923 result = getjob_level_1(p->mem_ctx,
8924 queue, count, snum, pinfo2,
8925 r->in.job_id, &r->out.info->info1);
8928 result = getjob_level_2(p->mem_ctx,
8929 queue, count, snum, pinfo2,
8930 r->in.job_id, &r->out.info->info2);
8933 result = WERR_UNKNOWN_LEVEL;
8938 TALLOC_FREE(pinfo2);
8940 if (!W_ERROR_IS_OK(result)) {
8941 TALLOC_FREE(r->out.info);
8945 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
8947 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8949 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8952 /****************************************************************
8953 _spoolss_GetPrinterDataEx
8954 ****************************************************************/
8956 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
8957 struct spoolss_GetPrinterDataEx *r)
8960 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8961 const char *printer;
8963 WERROR result = WERR_OK;
8965 enum winreg_Type val_type;
8970 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8972 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8973 r->in.key_name, r->in.value_name));
8975 /* in case of problem, return some default values */
8978 *r->out.type = REG_NONE;
8981 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8982 OUR_HANDLE(r->in.handle)));
8983 result = WERR_BADFID;
8987 /* Is the handle to a printer or to the server? */
8989 if (Printer->printer_type == SPLHND_SERVER) {
8991 union spoolss_PrinterData data;
8993 result = getprinterdata_printer_server(p->mem_ctx,
8997 if (!W_ERROR_IS_OK(result)) {
9001 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
9002 *r->out.type, &data);
9003 if (!W_ERROR_IS_OK(result)) {
9007 *r->out.needed = blob.length;
9009 if (r->in.offered >= *r->out.needed) {
9010 memcpy(r->out.data, blob.data, blob.length);
9013 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9016 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9019 printer = lp_const_servicename(snum);
9021 /* check to see if the keyname is valid */
9022 if (!strlen(r->in.key_name)) {
9023 return WERR_INVALID_PARAM;
9026 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9027 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
9028 strequal(r->in.value_name, "ChangeId")) {
9029 *r->out.type = REG_DWORD;
9031 if (r->in.offered >= *r->out.needed) {
9032 uint32_t changeid = 0;
9034 result = winreg_printer_get_changeid(p->mem_ctx,
9035 get_server_info_system(),
9039 if (!W_ERROR_IS_OK(result)) {
9043 SIVAL(r->out.data, 0, changeid);
9049 result = winreg_get_printer_dataex(p->mem_ctx,
9050 get_server_info_system(),
9058 if (!W_ERROR_IS_OK(result)) {
9062 *r->out.needed = val_size;
9063 *r->out.type = val_type;
9065 if (r->in.offered >= *r->out.needed) {
9066 memcpy(r->out.data, val_data, val_size);
9070 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
9071 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
9073 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9076 /****************************************************************
9077 _spoolss_SetPrinterDataEx
9078 ****************************************************************/
9080 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
9081 struct spoolss_SetPrinterDataEx *r)
9083 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9085 WERROR result = WERR_OK;
9086 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9089 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9091 /* From MSDN documentation of SetPrinterDataEx: pass request to
9092 SetPrinterData if key is "PrinterDriverData" */
9095 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9096 OUR_HANDLE(r->in.handle)));
9100 if (Printer->printer_type == SPLHND_SERVER) {
9101 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9102 "Not implemented for server handles yet\n"));
9103 return WERR_INVALID_PARAM;
9106 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9111 * Access check : NT returns "access denied" if you make a
9112 * SetPrinterData call without the necessary privildge.
9113 * we were originally returning OK if nothing changed
9114 * which made Win2k issue **a lot** of SetPrinterData
9115 * when connecting to a printer --jerry
9118 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9119 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9120 "change denied by handle access permissions\n"));
9121 return WERR_ACCESS_DENIED;
9124 result = winreg_get_printer(Printer,
9125 get_server_info_system(),
9127 Printer->servername,
9128 lp_servicename(snum),
9130 if (!W_ERROR_IS_OK(result)) {
9134 /* check for OID in valuename */
9136 oid_string = strchr(r->in.value_name, ',');
9142 /* save the registry data */
9144 result = winreg_set_printer_dataex(p->mem_ctx,
9145 get_server_info_system(),
9154 if (W_ERROR_IS_OK(result)) {
9155 /* save the OID if one was specified */
9157 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9158 r->in.key_name, SPOOL_OID_KEY);
9160 result = WERR_NOMEM;
9165 * I'm not checking the status here on purpose. Don't know
9166 * if this is right, but I'm returning the status from the
9167 * previous set_printer_dataex() call. I have no idea if
9168 * this is right. --jerry
9170 winreg_set_printer_dataex(p->mem_ctx,
9171 get_server_info_system(),
9177 (uint8_t *) oid_string,
9178 strlen(oid_string) + 1);
9181 result = winreg_printer_update_changeid(p->mem_ctx,
9182 get_server_info_system(),
9184 lp_const_servicename(snum));
9189 talloc_free(pinfo2);
9193 /****************************************************************
9194 _spoolss_DeletePrinterDataEx
9195 ****************************************************************/
9197 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
9198 struct spoolss_DeletePrinterDataEx *r)
9200 const char *printer;
9202 WERROR status = WERR_OK;
9203 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9205 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9208 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9209 "Invalid handle (%s:%u:%u).\n",
9210 OUR_HANDLE(r->in.handle)));
9214 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9215 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9216 "printer properties change denied by handle\n"));
9217 return WERR_ACCESS_DENIED;
9220 if (!r->in.value_name || !r->in.key_name) {
9224 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9227 printer = lp_const_servicename(snum);
9229 status = winreg_delete_printer_dataex(p->mem_ctx,
9230 get_server_info_system(),
9235 if (W_ERROR_IS_OK(status)) {
9236 status = winreg_printer_update_changeid(p->mem_ctx,
9237 get_server_info_system(),
9245 /****************************************************************
9246 _spoolss_EnumPrinterKey
9247 ****************************************************************/
9249 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
9250 struct spoolss_EnumPrinterKey *r)
9253 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9255 WERROR result = WERR_BADFILE;
9256 const char **array = NULL;
9259 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9262 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9263 OUR_HANDLE(r->in.handle)));
9267 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9271 result = winreg_enum_printer_key(p->mem_ctx,
9272 get_server_info_system(),
9274 lp_const_servicename(snum),
9278 if (!W_ERROR_IS_OK(result)) {
9282 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9283 result = WERR_NOMEM;
9287 *r->out._ndr_size = r->in.offered / 2;
9288 *r->out.needed = blob.length;
9290 if (r->in.offered < *r->out.needed) {
9291 result = WERR_MORE_DATA;
9294 r->out.key_buffer->string_array = array;
9298 if (!W_ERROR_IS_OK(result)) {
9300 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9308 /****************************************************************
9309 _spoolss_DeletePrinterKey
9310 ****************************************************************/
9312 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9313 struct spoolss_DeletePrinterKey *r)
9315 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9318 const char *printer;
9320 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9323 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9324 OUR_HANDLE(r->in.handle)));
9328 /* if keyname == NULL, return error */
9329 if ( !r->in.key_name )
9330 return WERR_INVALID_PARAM;
9332 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9336 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9337 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9338 "printer properties change denied by handle\n"));
9339 return WERR_ACCESS_DENIED;
9342 printer = lp_const_servicename(snum);
9344 /* delete the key and all subkeys */
9345 status = winreg_delete_printer_key(p->mem_ctx,
9346 get_server_info_system(),
9350 if (W_ERROR_IS_OK(status)) {
9351 status = winreg_printer_update_changeid(p->mem_ctx,
9352 get_server_info_system(),
9360 /****************************************************************
9361 _spoolss_EnumPrinterDataEx
9362 ****************************************************************/
9364 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9365 struct spoolss_EnumPrinterDataEx *r)
9368 struct spoolss_PrinterEnumValues *info = NULL;
9369 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9373 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9377 *r->out.info = NULL;
9380 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9381 OUR_HANDLE(r->in.handle)));
9386 * first check for a keyname of NULL or "". Win2k seems to send
9387 * this a lot and we should send back WERR_INVALID_PARAM
9388 * no need to spend time looking up the printer in this case.
9392 if (!strlen(r->in.key_name)) {
9393 result = WERR_INVALID_PARAM;
9397 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9401 /* now look for a match on the key name */
9402 result = winreg_enum_printer_dataex(p->mem_ctx,
9403 get_server_info_system(),
9405 lp_const_servicename(snum),
9409 if (!W_ERROR_IS_OK(result)) {
9413 #if 0 /* FIXME - gd */
9414 /* housekeeping information in the reply */
9416 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9417 * the hand marshalled container size is a multiple
9418 * of 4 bytes for RPC alignment.
9422 needed += 4-(needed % 4);
9425 *r->out.count = count;
9426 *r->out.info = info;
9429 if (!W_ERROR_IS_OK(result)) {
9433 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9434 spoolss_EnumPrinterDataEx,
9437 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9438 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9440 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9443 /****************************************************************************
9444 ****************************************************************************/
9446 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9447 const char *servername,
9448 const char *environment,
9449 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9454 werr = compose_spoolss_server_path(mem_ctx,
9457 SPOOLSS_PRTPROCS_PATH,
9459 if (!W_ERROR_IS_OK(werr)) {
9463 DEBUG(4,("print processor directory: [%s]\n", path));
9465 r->directory_name = path;
9470 /****************************************************************
9471 _spoolss_GetPrintProcessorDirectory
9472 ****************************************************************/
9474 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
9475 struct spoolss_GetPrintProcessorDirectory *r)
9479 /* that's an [in out] buffer */
9481 if (!r->in.buffer && (r->in.offered != 0)) {
9482 return WERR_INVALID_PARAM;
9485 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9490 /* r->in.level is ignored */
9492 /* We always should reply with a local print processor directory so that
9493 * users are not forced to have a [prnproc$] share on the Samba spoolss
9494 * server - Guenther */
9496 result = getprintprocessordirectory_level_1(p->mem_ctx,
9497 NULL, /* r->in.server */
9499 &r->out.info->info1);
9500 if (!W_ERROR_IS_OK(result)) {
9501 TALLOC_FREE(r->out.info);
9505 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9506 r->out.info, r->in.level);
9507 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9509 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9512 /*******************************************************************
9513 ********************************************************************/
9515 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9516 const char *dllname)
9518 enum ndr_err_code ndr_err;
9519 struct spoolss_MonitorUi ui;
9521 ui.dll_name = dllname;
9523 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9524 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9525 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9526 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9528 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9531 /*******************************************************************
9532 Streams the monitor UI DLL name in UNICODE
9533 *******************************************************************/
9535 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9536 struct security_token *token, DATA_BLOB *in,
9537 DATA_BLOB *out, uint32_t *needed)
9539 const char *dllname = "tcpmonui.dll";
9541 *needed = (strlen(dllname)+1) * 2;
9543 if (out->length < *needed) {
9544 return WERR_INSUFFICIENT_BUFFER;
9547 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9554 /*******************************************************************
9555 ********************************************************************/
9557 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9558 struct spoolss_PortData1 *port1,
9559 const DATA_BLOB *buf)
9561 enum ndr_err_code ndr_err;
9562 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9563 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9564 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9565 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9567 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9570 /*******************************************************************
9571 ********************************************************************/
9573 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9574 struct spoolss_PortData2 *port2,
9575 const DATA_BLOB *buf)
9577 enum ndr_err_code ndr_err;
9578 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9579 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9580 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9581 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9583 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9586 /*******************************************************************
9587 Create a new TCP/IP port
9588 *******************************************************************/
9590 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9591 struct security_token *token, DATA_BLOB *in,
9592 DATA_BLOB *out, uint32_t *needed)
9594 struct spoolss_PortData1 port1;
9595 struct spoolss_PortData2 port2;
9596 char *device_uri = NULL;
9599 const char *portname;
9600 const char *hostaddress;
9602 uint32_t port_number;
9605 /* peek for spoolss_PortData version */
9607 if (!in || (in->length < (128 + 4))) {
9608 return WERR_GENERAL_FAILURE;
9611 version = IVAL(in->data, 128);
9617 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9621 portname = port1.portname;
9622 hostaddress = port1.hostaddress;
9623 queue = port1.queue;
9624 protocol = port1.protocol;
9625 port_number = port1.port_number;
9631 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9635 portname = port2.portname;
9636 hostaddress = port2.hostaddress;
9637 queue = port2.queue;
9638 protocol = port2.protocol;
9639 port_number = port2.port_number;
9643 DEBUG(1,("xcvtcp_addport: "
9644 "unknown version of port_data: %d\n", version));
9645 return WERR_UNKNOWN_PORT;
9648 /* create the device URI and call the add_port_hook() */
9651 case PROTOCOL_RAWTCP_TYPE:
9652 device_uri = talloc_asprintf(mem_ctx,
9653 "socket://%s:%d/", hostaddress,
9657 case PROTOCOL_LPR_TYPE:
9658 device_uri = talloc_asprintf(mem_ctx,
9659 "lpr://%s/%s", hostaddress, queue );
9663 return WERR_UNKNOWN_PORT;
9670 return add_port_hook(mem_ctx, token, portname, device_uri);
9673 /*******************************************************************
9674 *******************************************************************/
9676 struct xcv_api_table xcvtcp_cmds[] = {
9677 { "MonitorUI", xcvtcp_monitorui },
9678 { "AddPort", xcvtcp_addport},
9682 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9683 struct security_token *token, const char *command,
9690 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9692 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9693 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9694 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9697 return WERR_BADFUNC;
9700 /*******************************************************************
9701 *******************************************************************/
9702 #if 0 /* don't support management using the "Local Port" monitor */
9704 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9705 struct security_token *token, DATA_BLOB *in,
9706 DATA_BLOB *out, uint32_t *needed)
9708 const char *dllname = "localui.dll";
9710 *needed = (strlen(dllname)+1) * 2;
9712 if (out->length < *needed) {
9713 return WERR_INSUFFICIENT_BUFFER;
9716 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9723 /*******************************************************************
9724 *******************************************************************/
9726 struct xcv_api_table xcvlocal_cmds[] = {
9727 { "MonitorUI", xcvlocal_monitorui },
9731 struct xcv_api_table xcvlocal_cmds[] = {
9738 /*******************************************************************
9739 *******************************************************************/
9741 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9742 struct security_token *token, const char *command,
9743 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9748 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9750 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9751 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9752 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9754 return WERR_BADFUNC;
9757 /****************************************************************
9759 ****************************************************************/
9761 WERROR _spoolss_XcvData(struct pipes_struct *p,
9762 struct spoolss_XcvData *r)
9764 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9765 DATA_BLOB out_data = data_blob_null;
9769 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9770 OUR_HANDLE(r->in.handle)));
9774 /* Has to be a handle to the TCP/IP port monitor */
9776 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9777 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9781 /* requires administrative access to the server */
9783 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9784 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9785 return WERR_ACCESS_DENIED;
9788 /* Allocate the outgoing buffer */
9790 if (r->in.out_data_size) {
9791 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9792 if (out_data.data == NULL) {
9797 switch ( Printer->printer_type ) {
9798 case SPLHND_PORTMON_TCP:
9799 werror = process_xcvtcp_command(p->mem_ctx,
9800 p->server_info->ptok,
9801 r->in.function_name,
9802 &r->in.in_data, &out_data,
9805 case SPLHND_PORTMON_LOCAL:
9806 werror = process_xcvlocal_command(p->mem_ctx,
9807 p->server_info->ptok,
9808 r->in.function_name,
9809 &r->in.in_data, &out_data,
9813 werror = WERR_INVALID_PRINT_MONITOR;
9816 if (!W_ERROR_IS_OK(werror)) {
9820 *r->out.status_code = 0;
9822 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9823 memcpy(r->out.out_data, out_data.data,
9824 MIN(r->in.out_data_size, out_data.length));
9830 /****************************************************************
9831 _spoolss_AddPrintProcessor
9832 ****************************************************************/
9834 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
9835 struct spoolss_AddPrintProcessor *r)
9837 /* for now, just indicate success and ignore the add. We'll
9838 automatically set the winprint processor for printer
9839 entries later. Used to debug the LexMark Optra S 1855 PCL
9845 /****************************************************************
9847 ****************************************************************/
9849 WERROR _spoolss_AddPort(struct pipes_struct *p,
9850 struct spoolss_AddPort *r)
9852 /* do what w2k3 does */
9854 return WERR_NOT_SUPPORTED;
9857 /****************************************************************
9858 _spoolss_GetPrinterDriver
9859 ****************************************************************/
9861 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
9862 struct spoolss_GetPrinterDriver *r)
9864 p->rng_fault_state = true;
9865 return WERR_NOT_SUPPORTED;
9868 /****************************************************************
9869 _spoolss_ReadPrinter
9870 ****************************************************************/
9872 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
9873 struct spoolss_ReadPrinter *r)
9875 p->rng_fault_state = true;
9876 return WERR_NOT_SUPPORTED;
9879 /****************************************************************
9880 _spoolss_WaitForPrinterChange
9881 ****************************************************************/
9883 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
9884 struct spoolss_WaitForPrinterChange *r)
9886 p->rng_fault_state = true;
9887 return WERR_NOT_SUPPORTED;
9890 /****************************************************************
9891 _spoolss_ConfigurePort
9892 ****************************************************************/
9894 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
9895 struct spoolss_ConfigurePort *r)
9897 p->rng_fault_state = true;
9898 return WERR_NOT_SUPPORTED;
9901 /****************************************************************
9903 ****************************************************************/
9905 WERROR _spoolss_DeletePort(struct pipes_struct *p,
9906 struct spoolss_DeletePort *r)
9908 p->rng_fault_state = true;
9909 return WERR_NOT_SUPPORTED;
9912 /****************************************************************
9913 _spoolss_CreatePrinterIC
9914 ****************************************************************/
9916 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
9917 struct spoolss_CreatePrinterIC *r)
9919 p->rng_fault_state = true;
9920 return WERR_NOT_SUPPORTED;
9923 /****************************************************************
9924 _spoolss_PlayGDIScriptOnPrinterIC
9925 ****************************************************************/
9927 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
9928 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9930 p->rng_fault_state = true;
9931 return WERR_NOT_SUPPORTED;
9934 /****************************************************************
9935 _spoolss_DeletePrinterIC
9936 ****************************************************************/
9938 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
9939 struct spoolss_DeletePrinterIC *r)
9941 p->rng_fault_state = true;
9942 return WERR_NOT_SUPPORTED;
9945 /****************************************************************
9946 _spoolss_AddPrinterConnection
9947 ****************************************************************/
9949 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
9950 struct spoolss_AddPrinterConnection *r)
9952 p->rng_fault_state = true;
9953 return WERR_NOT_SUPPORTED;
9956 /****************************************************************
9957 _spoolss_DeletePrinterConnection
9958 ****************************************************************/
9960 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
9961 struct spoolss_DeletePrinterConnection *r)
9963 p->rng_fault_state = true;
9964 return WERR_NOT_SUPPORTED;
9967 /****************************************************************
9968 _spoolss_PrinterMessageBox
9969 ****************************************************************/
9971 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
9972 struct spoolss_PrinterMessageBox *r)
9974 p->rng_fault_state = true;
9975 return WERR_NOT_SUPPORTED;
9978 /****************************************************************
9980 ****************************************************************/
9982 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
9983 struct spoolss_AddMonitor *r)
9985 p->rng_fault_state = true;
9986 return WERR_NOT_SUPPORTED;
9989 /****************************************************************
9990 _spoolss_DeleteMonitor
9991 ****************************************************************/
9993 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
9994 struct spoolss_DeleteMonitor *r)
9996 p->rng_fault_state = true;
9997 return WERR_NOT_SUPPORTED;
10000 /****************************************************************
10001 _spoolss_DeletePrintProcessor
10002 ****************************************************************/
10004 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
10005 struct spoolss_DeletePrintProcessor *r)
10007 p->rng_fault_state = true;
10008 return WERR_NOT_SUPPORTED;
10011 /****************************************************************
10012 _spoolss_AddPrintProvidor
10013 ****************************************************************/
10015 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
10016 struct spoolss_AddPrintProvidor *r)
10018 p->rng_fault_state = true;
10019 return WERR_NOT_SUPPORTED;
10022 /****************************************************************
10023 _spoolss_DeletePrintProvidor
10024 ****************************************************************/
10026 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
10027 struct spoolss_DeletePrintProvidor *r)
10029 p->rng_fault_state = true;
10030 return WERR_NOT_SUPPORTED;
10033 /****************************************************************
10034 _spoolss_FindFirstPrinterChangeNotification
10035 ****************************************************************/
10037 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
10038 struct spoolss_FindFirstPrinterChangeNotification *r)
10040 p->rng_fault_state = true;
10041 return WERR_NOT_SUPPORTED;
10044 /****************************************************************
10045 _spoolss_FindNextPrinterChangeNotification
10046 ****************************************************************/
10048 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
10049 struct spoolss_FindNextPrinterChangeNotification *r)
10051 p->rng_fault_state = true;
10052 return WERR_NOT_SUPPORTED;
10055 /****************************************************************
10056 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10057 ****************************************************************/
10059 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
10060 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10062 p->rng_fault_state = true;
10063 return WERR_NOT_SUPPORTED;
10066 /****************************************************************
10067 _spoolss_ReplyOpenPrinter
10068 ****************************************************************/
10070 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
10071 struct spoolss_ReplyOpenPrinter *r)
10073 p->rng_fault_state = true;
10074 return WERR_NOT_SUPPORTED;
10077 /****************************************************************
10078 _spoolss_RouterReplyPrinter
10079 ****************************************************************/
10081 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
10082 struct spoolss_RouterReplyPrinter *r)
10084 p->rng_fault_state = true;
10085 return WERR_NOT_SUPPORTED;
10088 /****************************************************************
10089 _spoolss_ReplyClosePrinter
10090 ****************************************************************/
10092 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
10093 struct spoolss_ReplyClosePrinter *r)
10095 p->rng_fault_state = true;
10096 return WERR_NOT_SUPPORTED;
10099 /****************************************************************
10101 ****************************************************************/
10103 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
10104 struct spoolss_AddPortEx *r)
10106 p->rng_fault_state = true;
10107 return WERR_NOT_SUPPORTED;
10110 /****************************************************************
10111 _spoolss_RouterFindFirstPrinterChangeNotification
10112 ****************************************************************/
10114 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
10115 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10117 p->rng_fault_state = true;
10118 return WERR_NOT_SUPPORTED;
10121 /****************************************************************
10122 _spoolss_SpoolerInit
10123 ****************************************************************/
10125 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
10126 struct spoolss_SpoolerInit *r)
10128 p->rng_fault_state = true;
10129 return WERR_NOT_SUPPORTED;
10132 /****************************************************************
10133 _spoolss_ResetPrinterEx
10134 ****************************************************************/
10136 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
10137 struct spoolss_ResetPrinterEx *r)
10139 p->rng_fault_state = true;
10140 return WERR_NOT_SUPPORTED;
10143 /****************************************************************
10144 _spoolss_RouterReplyPrinterEx
10145 ****************************************************************/
10147 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
10148 struct spoolss_RouterReplyPrinterEx *r)
10150 p->rng_fault_state = true;
10151 return WERR_NOT_SUPPORTED;
10154 /****************************************************************
10156 ****************************************************************/
10158 WERROR _spoolss_44(struct pipes_struct *p,
10159 struct spoolss_44 *r)
10161 p->rng_fault_state = true;
10162 return WERR_NOT_SUPPORTED;
10165 /****************************************************************
10167 ****************************************************************/
10169 WERROR _spoolss_47(struct pipes_struct *p,
10170 struct spoolss_47 *r)
10172 p->rng_fault_state = true;
10173 return WERR_NOT_SUPPORTED;
10176 /****************************************************************
10178 ****************************************************************/
10180 WERROR _spoolss_4a(struct pipes_struct *p,
10181 struct spoolss_4a *r)
10183 p->rng_fault_state = true;
10184 return WERR_NOT_SUPPORTED;
10187 /****************************************************************
10189 ****************************************************************/
10191 WERROR _spoolss_4b(struct pipes_struct *p,
10192 struct spoolss_4b *r)
10194 p->rng_fault_state = true;
10195 return WERR_NOT_SUPPORTED;
10198 /****************************************************************
10200 ****************************************************************/
10202 WERROR _spoolss_4c(struct pipes_struct *p,
10203 struct spoolss_4c *r)
10205 p->rng_fault_state = true;
10206 return WERR_NOT_SUPPORTED;
10209 /****************************************************************
10211 ****************************************************************/
10213 WERROR _spoolss_53(struct pipes_struct *p,
10214 struct spoolss_53 *r)
10216 p->rng_fault_state = true;
10217 return WERR_NOT_SUPPORTED;
10220 /****************************************************************
10222 ****************************************************************/
10224 WERROR _spoolss_55(struct pipes_struct *p,
10225 struct spoolss_55 *r)
10227 p->rng_fault_state = true;
10228 return WERR_NOT_SUPPORTED;
10231 /****************************************************************
10233 ****************************************************************/
10235 WERROR _spoolss_56(struct pipes_struct *p,
10236 struct spoolss_56 *r)
10238 p->rng_fault_state = true;
10239 return WERR_NOT_SUPPORTED;
10242 /****************************************************************
10244 ****************************************************************/
10246 WERROR _spoolss_57(struct pipes_struct *p,
10247 struct spoolss_57 *r)
10249 p->rng_fault_state = true;
10250 return WERR_NOT_SUPPORTED;
10253 /****************************************************************
10255 ****************************************************************/
10257 WERROR _spoolss_5a(struct pipes_struct *p,
10258 struct spoolss_5a *r)
10260 p->rng_fault_state = true;
10261 return WERR_NOT_SUPPORTED;
10264 /****************************************************************
10266 ****************************************************************/
10268 WERROR _spoolss_5b(struct pipes_struct *p,
10269 struct spoolss_5b *r)
10271 p->rng_fault_state = true;
10272 return WERR_NOT_SUPPORTED;
10275 /****************************************************************
10277 ****************************************************************/
10279 WERROR _spoolss_5c(struct pipes_struct *p,
10280 struct spoolss_5c *r)
10282 p->rng_fault_state = true;
10283 return WERR_NOT_SUPPORTED;
10286 /****************************************************************
10288 ****************************************************************/
10290 WERROR _spoolss_5d(struct pipes_struct *p,
10291 struct spoolss_5d *r)
10293 p->rng_fault_state = true;
10294 return WERR_NOT_SUPPORTED;
10297 /****************************************************************
10299 ****************************************************************/
10301 WERROR _spoolss_5e(struct pipes_struct *p,
10302 struct spoolss_5e *r)
10304 p->rng_fault_state = true;
10305 return WERR_NOT_SUPPORTED;
10308 /****************************************************************
10310 ****************************************************************/
10312 WERROR _spoolss_5f(struct pipes_struct *p,
10313 struct spoolss_5f *r)
10315 p->rng_fault_state = true;
10316 return WERR_NOT_SUPPORTED;
10319 /****************************************************************
10321 ****************************************************************/
10323 WERROR _spoolss_60(struct pipes_struct *p,
10324 struct spoolss_60 *r)
10326 p->rng_fault_state = true;
10327 return WERR_NOT_SUPPORTED;
10330 /****************************************************************
10332 ****************************************************************/
10334 WERROR _spoolss_61(struct pipes_struct *p,
10335 struct spoolss_61 *r)
10337 p->rng_fault_state = true;
10338 return WERR_NOT_SUPPORTED;
10341 /****************************************************************
10343 ****************************************************************/
10345 WERROR _spoolss_62(struct pipes_struct *p,
10346 struct spoolss_62 *r)
10348 p->rng_fault_state = true;
10349 return WERR_NOT_SUPPORTED;
10352 /****************************************************************
10354 ****************************************************************/
10356 WERROR _spoolss_63(struct pipes_struct *p,
10357 struct spoolss_63 *r)
10359 p->rng_fault_state = true;
10360 return WERR_NOT_SUPPORTED;
10363 /****************************************************************
10365 ****************************************************************/
10367 WERROR _spoolss_64(struct pipes_struct *p,
10368 struct spoolss_64 *r)
10370 p->rng_fault_state = true;
10371 return WERR_NOT_SUPPORTED;
10374 /****************************************************************
10376 ****************************************************************/
10378 WERROR _spoolss_65(struct pipes_struct *p,
10379 struct spoolss_65 *r)
10381 p->rng_fault_state = true;
10382 return WERR_NOT_SUPPORTED;
10385 /****************************************************************
10386 _spoolss_GetCorePrinterDrivers
10387 ****************************************************************/
10389 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10390 struct spoolss_GetCorePrinterDrivers *r)
10392 p->rng_fault_state = true;
10393 return WERR_NOT_SUPPORTED;
10396 /****************************************************************
10398 ****************************************************************/
10400 WERROR _spoolss_67(struct pipes_struct *p,
10401 struct spoolss_67 *r)
10403 p->rng_fault_state = true;
10404 return WERR_NOT_SUPPORTED;
10407 /****************************************************************
10408 _spoolss_GetPrinterDriverPackagePath
10409 ****************************************************************/
10411 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10412 struct spoolss_GetPrinterDriverPackagePath *r)
10414 p->rng_fault_state = true;
10415 return WERR_NOT_SUPPORTED;
10418 /****************************************************************
10420 ****************************************************************/
10422 WERROR _spoolss_69(struct pipes_struct *p,
10423 struct spoolss_69 *r)
10425 p->rng_fault_state = true;
10426 return WERR_NOT_SUPPORTED;
10429 /****************************************************************
10431 ****************************************************************/
10433 WERROR _spoolss_6a(struct pipes_struct *p,
10434 struct spoolss_6a *r)
10436 p->rng_fault_state = true;
10437 return WERR_NOT_SUPPORTED;
10440 /****************************************************************
10442 ****************************************************************/
10444 WERROR _spoolss_6b(struct pipes_struct *p,
10445 struct spoolss_6b *r)
10447 p->rng_fault_state = true;
10448 return WERR_NOT_SUPPORTED;
10451 /****************************************************************
10453 ****************************************************************/
10455 WERROR _spoolss_6c(struct pipes_struct *p,
10456 struct spoolss_6c *r)
10458 p->rng_fault_state = true;
10459 return WERR_NOT_SUPPORTED;
10462 /****************************************************************
10464 ****************************************************************/
10466 WERROR _spoolss_6d(struct pipes_struct *p,
10467 struct spoolss_6d *r)
10469 p->rng_fault_state = true;
10470 return WERR_NOT_SUPPORTED;