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 /* macros stolen from s4 spoolss server */
43 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
44 ((info)?ndr_size_##fn(info, level, 0):0)
46 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
47 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
49 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
50 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
52 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
55 extern userdom_struct current_user_info;
58 #define DBGC_CLASS DBGC_RPC_SRV
60 #ifndef MAX_OPEN_PRINTER_EXS
61 #define MAX_OPEN_PRINTER_EXS 50
64 #define MAGIC_DISPLAY_FREQUENCY 0xfade2bad
66 static Printer_entry *printers_list;
68 typedef struct _counter_printer_0 {
69 struct _counter_printer_0 *next;
70 struct _counter_printer_0 *prev;
76 static counter_printer_0 *counter_list;
78 static struct rpc_pipe_client *notify_cli_pipe; /* print notify back-channel pipe handle*/
79 static uint32_t smb_connections = 0;
82 /* in printing/nt_printing.c */
84 extern struct standard_mapping printer_std_mapping, printserver_std_mapping;
86 /* API table for Xcv Monitor functions */
88 struct xcv_api_table {
90 WERROR(*fn) (TALLOC_CTX *mem_ctx, NT_USER_TOKEN *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
93 /********************************************************************
94 * Canonicalize servername.
95 ********************************************************************/
97 static const char *canon_servername(const char *servername)
99 const char *pservername = servername;
100 while (*pservername == '\\') {
106 /* translate between internal status numbers and NT status numbers */
107 static int nt_printj_status(int v)
113 return JOB_STATUS_PAUSED;
115 return JOB_STATUS_SPOOLING;
117 return JOB_STATUS_PRINTING;
119 return JOB_STATUS_ERROR;
121 return JOB_STATUS_DELETING;
123 return JOB_STATUS_OFFLINE;
125 return JOB_STATUS_PAPEROUT;
127 return JOB_STATUS_PRINTED;
129 return JOB_STATUS_DELETED;
131 return JOB_STATUS_BLOCKED_DEVQ;
132 case LPQ_USER_INTERVENTION:
133 return JOB_STATUS_USER_INTERVENTION;
138 static int nt_printq_status(int v)
142 return PRINTER_STATUS_PAUSED;
151 /***************************************************************************
152 Disconnect from the client
153 ****************************************************************************/
155 static void srv_spoolss_replycloseprinter(int snum, struct policy_handle *handle)
161 * Tell the specific printing tdb we no longer want messages for this printer
162 * by deregistering our PID.
165 if (!print_notify_deregister_pid(snum))
166 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
168 /* weird if the test succeds !!! */
169 if (smb_connections==0) {
170 DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
174 status = rpccli_spoolss_ReplyClosePrinter(notify_cli_pipe, talloc_tos(),
177 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
178 DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
179 win_errstr(result)));
181 /* if it's the last connection, deconnect the IPC$ share */
182 if (smb_connections==1) {
184 cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) );
185 notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */
187 messaging_deregister(smbd_messaging_context(),
188 MSG_PRINTER_NOTIFY2, NULL);
190 /* Tell the connections db we're no longer interested in
191 * printer notify messages. */
193 serverid_register_msg_flags(
194 messaging_server_id(smbd_messaging_context()),
195 false, FLAG_MSG_PRINT_NOTIFY);
201 /****************************************************************************
202 Functions to free a printer entry datastruct.
203 ****************************************************************************/
205 static int printer_entry_destructor(Printer_entry *Printer)
207 if (Printer->notify.client_connected == true) {
210 if ( Printer->printer_type == SPLHND_SERVER) {
212 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
213 } else if (Printer->printer_type == SPLHND_PRINTER) {
214 snum = print_queue_snum(Printer->sharename);
216 srv_spoolss_replycloseprinter(snum,
217 &Printer->notify.client_hnd);
221 Printer->notify.flags=0;
222 Printer->notify.options=0;
223 Printer->notify.localmachine[0]='\0';
224 Printer->notify.printerlocal=0;
225 TALLOC_FREE(Printer->notify.option);
226 Printer->notify.client_connected = false;
228 TALLOC_FREE(Printer->devmode);
230 /* Remove from the internal list. */
231 DLIST_REMOVE(printers_list, Printer);
235 /****************************************************************************
236 find printer index by handle
237 ****************************************************************************/
239 static Printer_entry *find_printer_index_by_hnd(pipes_struct *p,
240 struct policy_handle *hnd)
242 Printer_entry *find_printer = NULL;
244 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
245 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
252 /****************************************************************************
253 Close printer index by handle.
254 ****************************************************************************/
256 static bool close_printer_handle(pipes_struct *p, struct policy_handle *hnd)
258 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
261 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
266 close_policy_hnd(p, hnd);
271 /****************************************************************************
272 Delete a printer given a handle.
273 ****************************************************************************/
275 static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *sharename)
277 char *cmd = lp_deleteprinter_cmd();
278 char *command = NULL;
280 SE_PRIV se_printop = SE_PRINT_OPERATOR;
281 bool is_print_op = false;
283 /* can't fail if we don't try */
288 command = talloc_asprintf(ctx,
295 is_print_op = user_has_privileges( token, &se_printop );
297 DEBUG(10,("Running [%s]\n", command));
299 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
304 if ( (ret = smbrun(command, NULL)) == 0 ) {
305 /* Tell everyone we updated smb.conf. */
306 message_send_all(smbd_messaging_context(),
307 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
313 /********** END SePrintOperatorPrivlege BLOCK **********/
315 DEBUGADD(10,("returned [%d]\n", ret));
317 TALLOC_FREE(command);
320 return WERR_BADFID; /* What to return here? */
322 /* go ahead and re-read the services immediately */
324 reload_services(false);
327 if ( lp_servicenumber( sharename ) > 0 )
328 return WERR_ACCESS_DENIED;
333 /****************************************************************************
334 Delete a printer given a handle.
335 ****************************************************************************/
337 static WERROR delete_printer_handle(pipes_struct *p, struct policy_handle *hnd)
339 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
343 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
349 * It turns out that Windows allows delete printer on a handle
350 * opened by an admin user, then used on a pipe handle created
351 * by an anonymous user..... but they're working on security.... riiight !
355 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
356 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
357 return WERR_ACCESS_DENIED;
360 /* this does not need a become root since the access check has been
361 done on the handle already */
363 result = winreg_delete_printer_key(p->mem_ctx, p->server_info,
364 Printer->sharename, "");
365 if (!W_ERROR_IS_OK(result)) {
366 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
370 return delete_printer_hook(p->mem_ctx, p->server_info->ptok,
371 Printer->sharename );
374 /****************************************************************************
375 Return the snum of a printer corresponding to an handle.
376 ****************************************************************************/
378 static bool get_printer_snum(pipes_struct *p, struct policy_handle *hnd,
379 int *number, struct share_params **params)
381 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
384 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
389 switch (Printer->printer_type) {
391 DEBUG(4,("short name:%s\n", Printer->sharename));
392 *number = print_queue_snum(Printer->sharename);
393 return (*number != -1);
401 /****************************************************************************
402 Set printer handle type.
403 Check if it's \\server or \\server\printer
404 ****************************************************************************/
406 static bool set_printer_hnd_printertype(Printer_entry *Printer, const char *handlename)
408 DEBUG(3,("Setting printer type=%s\n", handlename));
410 if ( strlen(handlename) < 3 ) {
411 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", handlename));
415 /* it's a print server */
416 if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
417 DEBUGADD(4,("Printer is a print server\n"));
418 Printer->printer_type = SPLHND_SERVER;
420 /* it's a printer (set_printer_hnd_name() will handle port monitors */
422 DEBUGADD(4,("Printer is a printer\n"));
423 Printer->printer_type = SPLHND_PRINTER;
429 /****************************************************************************
430 Set printer handle name.. Accept names like \\server, \\server\printer,
431 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
432 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
433 XcvDataPort() interface.
434 ****************************************************************************/
436 static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
437 struct auth_serversupplied_info *server_info,
438 Printer_entry *Printer,
439 const char *handlename)
442 int n_services=lp_numservices();
444 const char *printername;
445 const char *servername;
448 struct spoolss_PrinterInfo2 *info2 = NULL;
451 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
452 (unsigned long)strlen(handlename)));
454 aprinter = CONST_DISCARD(char *, handlename);
455 if ( *handlename == '\\' ) {
456 servername = canon_servername(handlename);
457 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
461 if (!is_myname_or_ipaddr(servername)) {
465 fstrcpy(Printer->servername, servername);
468 if (Printer->printer_type == SPLHND_SERVER) {
472 if (Printer->printer_type != SPLHND_PRINTER) {
476 DEBUGADD(5, ("searching for [%s]\n", aprinter));
478 /* check for the Port Monitor Interface */
479 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
480 Printer->printer_type = SPLHND_PORTMON_TCP;
481 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
484 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
485 Printer->printer_type = SPLHND_PORTMON_LOCAL;
486 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
490 /* Search all sharenames first as this is easier than pulling
491 the printer_info_2 off of disk. Don't use find_service() since
492 that calls out to map_username() */
494 /* do another loop to look for printernames */
495 for (snum = 0; !found && snum < n_services; snum++) {
496 const char *printer = lp_const_servicename(snum);
498 /* no point going on if this is not a printer */
499 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
503 /* ignore [printers] share */
504 if (strequal(printer, "printers")) {
508 fstrcpy(sname, printer);
509 if (strequal(aprinter, printer)) {
514 /* no point looking up the printer object if
515 we aren't allowing printername != sharename */
516 if (lp_force_printername(snum)) {
520 result = winreg_get_printer(mem_ctx,
525 if ( !W_ERROR_IS_OK(result) ) {
526 DEBUG(0,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
527 sname, win_errstr(result)));
531 printername = strrchr(info2->printername, '\\');
532 if (printername == NULL) {
533 printername = info2->printername;
538 if (strequal(printername, aprinter)) {
543 DEBUGADD(10, ("printername: %s\n", printername));
549 DEBUGADD(4,("Printer not found\n"));
553 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
555 fstrcpy(Printer->sharename, sname);
560 /****************************************************************************
561 Find first available printer slot. creates a printer handle for you.
562 ****************************************************************************/
564 static bool open_printer_hnd(pipes_struct *p, struct policy_handle *hnd,
565 const char *name, uint32_t access_granted)
567 Printer_entry *new_printer;
569 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
571 new_printer = TALLOC_ZERO_P(NULL, Printer_entry);
572 if (new_printer == NULL) {
575 talloc_set_destructor(new_printer, printer_entry_destructor);
577 if (!create_policy_hnd(p, hnd, new_printer)) {
578 TALLOC_FREE(new_printer);
582 /* Add to the internal list. */
583 DLIST_ADD(printers_list, new_printer);
585 new_printer->notify.option=NULL;
587 if (!set_printer_hnd_printertype(new_printer, name)) {
588 close_printer_handle(p, hnd);
592 if (!set_printer_hnd_name(p->mem_ctx, p->server_info, new_printer, name)) {
593 close_printer_handle(p, hnd);
597 new_printer->access_granted = access_granted;
599 DEBUG(5, ("%d printer handles active\n",
600 (int)num_pipe_handles(p)));
605 /***************************************************************************
606 check to see if the client motify handle is monitoring the notification
607 given by (notify_type, notify_field).
608 **************************************************************************/
610 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
611 uint16_t notify_field)
616 static bool is_monitoring_event(Printer_entry *p, uint16_t notify_type,
617 uint16_t notify_field)
619 struct spoolss_NotifyOption *option = p->notify.option;
623 * Flags should always be zero when the change notify
624 * is registered by the client's spooler. A user Win32 app
625 * might use the flags though instead of the NOTIFY_OPTION_INFO
634 return is_monitoring_event_flags(
635 p->notify.flags, notify_type, notify_field);
637 for (i = 0; i < option->count; i++) {
639 /* Check match for notify_type */
641 if (option->types[i].type != notify_type)
644 /* Check match for field */
646 for (j = 0; j < option->types[i].count; j++) {
647 if (option->types[i].fields[j].field == notify_field) {
653 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
654 p->servername, p->sharename, notify_type, notify_field));
659 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
660 _data->data.integer[0] = _integer; \
661 _data->data.integer[1] = 0;
664 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
665 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
666 if (!_data->data.string.string) {\
667 _data->data.string.size = 0; \
669 _data->data.string.size = strlen_m_term(_p) * 2;
671 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
672 _data->data.devmode.devmode = _devmode;
674 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
675 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
676 if (!_data->data.sd.sd) { \
677 _data->data.sd.sd_size = 0; \
679 _data->data.sd.sd_size = \
680 ndr_size_security_descriptor(_data->data.sd.sd, 0);
682 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
687 struct spoolss_Time st;
691 if (!init_systemtime(&st, t)) {
695 p = talloc_array(mem_ctx, char, len);
701 * Systemtime must be linearized as a set of UINT16's.
702 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
705 SSVAL(p, 0, st.year);
706 SSVAL(p, 2, st.month);
707 SSVAL(p, 4, st.day_of_week);
709 SSVAL(p, 8, st.hour);
710 SSVAL(p, 10, st.minute);
711 SSVAL(p, 12, st.second);
712 SSVAL(p, 14, st.millisecond);
718 /* Convert a notification message to a struct spoolss_Notify */
720 static void notify_one_value(struct spoolss_notify_msg *msg,
721 struct spoolss_Notify *data,
724 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
727 static void notify_string(struct spoolss_notify_msg *msg,
728 struct spoolss_Notify *data,
731 /* The length of the message includes the trailing \0 */
733 data->data.string.size = msg->len * 2;
734 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
735 if (!data->data.string.string) {
736 data->data.string.size = 0;
741 static void notify_system_time(struct spoolss_notify_msg *msg,
742 struct spoolss_Notify *data,
745 data->data.string.string = NULL;
746 data->data.string.size = 0;
748 if (msg->len != sizeof(time_t)) {
749 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
754 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
755 &data->data.string.string,
756 &data->data.string.size);
759 struct notify2_message_table {
761 void (*fn)(struct spoolss_notify_msg *msg,
762 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
765 static struct notify2_message_table printer_notify_table[] = {
766 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
767 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
768 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
769 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
770 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
771 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
772 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
773 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
774 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
775 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
776 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
777 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
778 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
779 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
780 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
781 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
782 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
783 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
784 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
787 static struct notify2_message_table job_notify_table[] = {
788 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
789 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
790 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
791 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
792 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
793 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
794 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
795 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
796 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
797 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
798 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
799 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
800 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
801 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
802 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
803 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
804 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
805 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
806 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
807 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
808 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
809 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
810 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
811 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
815 /***********************************************************************
816 Allocate talloc context for container object
817 **********************************************************************/
819 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
824 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
829 /***********************************************************************
830 release all allocated memory and zero out structure
831 **********************************************************************/
833 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
839 talloc_destroy(ctr->ctx);
846 /***********************************************************************
847 **********************************************************************/
849 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
857 /***********************************************************************
858 **********************************************************************/
860 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
862 if ( !ctr || !ctr->msg_groups )
865 if ( idx >= ctr->num_groups )
868 return &ctr->msg_groups[idx];
872 /***********************************************************************
873 How many groups of change messages do we have ?
874 **********************************************************************/
876 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
881 return ctr->num_groups;
884 /***********************************************************************
885 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
886 **********************************************************************/
888 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
890 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
891 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
892 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
898 /* loop over all groups looking for a matching printer name */
900 for ( i=0; i<ctr->num_groups; i++ ) {
901 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
905 /* add a new group? */
907 if ( i == ctr->num_groups ) {
910 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
911 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
914 ctr->msg_groups = groups;
916 /* clear the new entry and set the printer name */
918 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
919 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
922 /* add the change messages; 'i' is the correct index now regardless */
924 msg_grp = &ctr->msg_groups[i];
928 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
929 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
932 msg_grp->msgs = msg_list;
934 new_slot = msg_grp->num_msgs-1;
935 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
937 /* need to allocate own copy of data */
940 msg_grp->msgs[new_slot].notify.data = (char *)
941 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
943 return ctr->num_groups;
946 static void construct_info_data(struct spoolss_Notify *info_data,
947 enum spoolss_NotifyType type,
948 uint16_t field, int id);
950 /***********************************************************************
951 Send a change notication message on all handles which have a call
953 **********************************************************************/
955 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
958 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
959 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
960 SPOOLSS_NOTIFY_MSG *messages;
961 int sending_msg_count;
964 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
968 messages = msg_group->msgs;
971 DEBUG(5,("send_notify2_changes() called with no messages!\n"));
975 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
977 /* loop over all printers */
979 for (p = printers_list; p; p = p->next) {
980 struct spoolss_Notify *notifies;
985 /* Is there notification on this handle? */
987 if ( !p->notify.client_connected )
990 DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
992 /* For this printer? Print servers always receive
995 if ( ( p->printer_type == SPLHND_PRINTER ) &&
996 ( !strequal(msg_group->printername, p->sharename) ) )
999 DEBUG(10,("Our printer\n"));
1001 /* allocate the max entries possible */
1003 notifies = TALLOC_ZERO_ARRAY(mem_ctx, struct spoolss_Notify, msg_group->num_msgs);
1008 /* build the array of change notifications */
1010 sending_msg_count = 0;
1012 for ( i=0; i<msg_group->num_msgs; i++ ) {
1013 SPOOLSS_NOTIFY_MSG *msg = &messages[i];
1015 /* Are we monitoring this event? */
1017 if (!is_monitoring_event(p, msg->type, msg->field))
1020 sending_msg_count++;
1023 DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
1024 msg->type, msg->field, p->sharename));
1027 * if the is a printer notification handle and not a job notification
1028 * type, then set the id to 0. Other wise just use what was specified
1031 * When registering change notification on a print server handle
1032 * we always need to send back the id (snum) matching the printer
1033 * for which the change took place. For change notify registered
1034 * on a printer handle, this does not matter and the id should be 0.
1039 if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
1045 /* Convert unix jobid to smb jobid */
1047 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1048 id = sysjob_to_jobid(msg->id);
1051 DEBUG(3, ("no such unix jobid %d\n", msg->id));
1056 construct_info_data( ¬ifies[count], msg->type, msg->field, id );
1059 case PRINTER_NOTIFY_TYPE:
1060 if ( printer_notify_table[msg->field].fn )
1061 printer_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1064 case JOB_NOTIFY_TYPE:
1065 if ( job_notify_table[msg->field].fn )
1066 job_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1070 DEBUG(5, ("Unknown notification type %d\n", msg->type));
1077 if ( sending_msg_count ) {
1080 union spoolss_ReplyPrinterInfo info;
1081 struct spoolss_NotifyInfo info0;
1082 uint32_t reply_result;
1084 info0.version = 0x2;
1085 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1086 info0.count = count;
1087 info0.notifies = notifies;
1089 info.info0 = &info0;
1091 status = rpccli_spoolss_RouterReplyPrinterEx(notify_cli_pipe, mem_ctx,
1092 &p->notify.client_hnd,
1093 p->notify.change, /* color */
1096 0, /* reply_type, must be 0 */
1099 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1100 DEBUG(1,("RouterReplyPrinterEx to client: %s failed: %s\n",
1101 notify_cli_pipe->srv_name_slash,
1104 switch (reply_result) {
1107 case PRINTER_NOTIFY_INFO_DISCARDED:
1108 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1109 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1118 DEBUG(8,("send_notify2_changes: Exit...\n"));
1122 /***********************************************************************
1123 **********************************************************************/
1125 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1128 uint32_t tv_sec, tv_usec;
1131 /* Unpack message */
1133 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1136 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1138 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1141 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1142 &msg->notify.value[0], &msg->notify.value[1]);
1144 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1145 &msg->len, &msg->notify.data);
1147 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1148 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1150 tv->tv_sec = tv_sec;
1151 tv->tv_usec = tv_usec;
1154 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1155 msg->notify.value[1]));
1157 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1162 /********************************************************************
1163 Receive a notify2 message list
1164 ********************************************************************/
1166 static void receive_notify2_message_list(struct messaging_context *msg,
1169 struct server_id server_id,
1172 size_t msg_count, i;
1173 char *buf = (char *)data->data;
1176 SPOOLSS_NOTIFY_MSG notify;
1177 SPOOLSS_NOTIFY_MSG_CTR messages;
1180 if (data->length < 4) {
1181 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1185 msg_count = IVAL(buf, 0);
1188 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1190 if (msg_count == 0) {
1191 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1195 /* initialize the container */
1197 ZERO_STRUCT( messages );
1198 notify_msg_ctr_init( &messages );
1201 * build message groups for each printer identified
1202 * in a change_notify msg. Remember that a PCN message
1203 * includes the handle returned for the srv_spoolss_replyopenprinter()
1204 * call. Therefore messages are grouped according to printer handle.
1207 for ( i=0; i<msg_count; i++ ) {
1208 struct timeval msg_tv;
1210 if (msg_ptr + 4 - buf > data->length) {
1211 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1215 msg_len = IVAL(msg_ptr,0);
1218 if (msg_ptr + msg_len - buf > data->length) {
1219 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1223 /* unpack messages */
1225 ZERO_STRUCT( notify );
1226 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1229 /* add to correct list in container */
1231 notify_msg_ctr_addmsg( &messages, ¬ify );
1233 /* free memory that might have been allocated by notify2_unpack_msg() */
1235 if ( notify.len != 0 )
1236 SAFE_FREE( notify.notify.data );
1239 /* process each group of messages */
1241 num_groups = notify_msg_ctr_numgroups( &messages );
1242 for ( i=0; i<num_groups; i++ )
1243 send_notify2_changes( &messages, i );
1248 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1249 (uint32_t)msg_count ));
1251 notify_msg_ctr_destroy( &messages );
1256 /********************************************************************
1257 Send a message to ourself about new driver being installed
1258 so we can upgrade the information for each printer bound to this
1260 ********************************************************************/
1262 static bool srv_spoolss_drv_upgrade_printer(const char *drivername)
1264 int len = strlen(drivername);
1269 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1272 messaging_send_buf(smbd_messaging_context(),
1273 messaging_server_id(smbd_messaging_context()),
1274 MSG_PRINTER_DRVUPGRADE,
1275 (uint8_t *)drivername, len+1);
1280 /**********************************************************************
1281 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1282 over all printers, upgrading ones as necessary
1283 **********************************************************************/
1285 void do_drv_upgrade_printer(struct messaging_context *msg,
1288 struct server_id server_id,
1291 TALLOC_CTX *tmp_ctx;
1292 struct auth_serversupplied_info *server_info = NULL;
1293 struct spoolss_PrinterInfo2 *pinfo2;
1296 const char *drivername;
1298 int n_services = lp_numservices();
1301 tmp_ctx = talloc_new(NULL);
1302 if (!tmp_ctx) return;
1304 status = make_server_info_system(tmp_ctx, &server_info);
1305 if (!NT_STATUS_IS_OK(status)) {
1306 DEBUG(0, ("do_drv_upgrade_printer: "
1307 "Could not create system server_info\n"));
1311 len = MIN(data->length,sizeof(drivername)-1);
1312 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, len);
1314 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1318 DEBUG(10, ("do_drv_upgrade_printer: "
1319 "Got message for new driver [%s]\n", drivername));
1321 /* Iterate the printer list */
1323 for (snum = 0; snum < n_services; snum++) {
1324 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1328 result = winreg_get_printer(tmp_ctx, server_info, NULL,
1329 lp_const_servicename(snum),
1332 if (!W_ERROR_IS_OK(result)) {
1336 if (strcmp(drivername, pinfo2->drivername) != 0) {
1340 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1342 /* all we care about currently is the change_id */
1343 result = winreg_printer_update_changeid(tmp_ctx,
1345 pinfo2->printername);
1347 if (!W_ERROR_IS_OK(result)) {
1348 DEBUG(3, ("do_drv_upgrade_printer: "
1349 "Failed to update changeid [%s]\n",
1350 win_errstr(result)));
1356 talloc_free(tmp_ctx);
1359 /********************************************************************
1360 Update the cache for all printq's with a registered client
1362 ********************************************************************/
1364 void update_monitored_printq_cache( void )
1366 Printer_entry *printer = printers_list;
1369 /* loop through all printers and update the cache where
1370 client_connected == true */
1373 if ( (printer->printer_type == SPLHND_PRINTER)
1374 && printer->notify.client_connected )
1376 snum = print_queue_snum(printer->sharename);
1377 print_queue_status( snum, NULL, NULL );
1380 printer = printer->next;
1386 /****************************************************************
1387 _spoolss_OpenPrinter
1388 ****************************************************************/
1390 WERROR _spoolss_OpenPrinter(pipes_struct *p,
1391 struct spoolss_OpenPrinter *r)
1393 struct spoolss_OpenPrinterEx e;
1396 ZERO_STRUCT(e.in.userlevel);
1398 e.in.printername = r->in.printername;
1399 e.in.datatype = r->in.datatype;
1400 e.in.devmode_ctr = r->in.devmode_ctr;
1401 e.in.access_mask = r->in.access_mask;
1404 e.out.handle = r->out.handle;
1406 werr = _spoolss_OpenPrinterEx(p, &e);
1408 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1409 /* OpenPrinterEx returns this for a bad
1410 * printer name. We must return WERR_INVALID_PRINTER_NAME
1413 werr = WERR_INVALID_PRINTER_NAME;
1419 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1420 struct spoolss_DeviceMode *orig,
1421 struct spoolss_DeviceMode **dest)
1423 struct spoolss_DeviceMode *dm;
1425 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1430 /* copy all values, then duplicate strings and structs */
1433 dm->devicename = talloc_strdup(dm, orig->devicename);
1434 if (!dm->devicename) {
1437 dm->formname = talloc_strdup(dm, orig->formname);
1438 if (!dm->formname) {
1441 if (orig->driverextra_data.data) {
1442 dm->driverextra_data.data =
1443 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1444 orig->driverextra_data.length);
1445 if (!dm->driverextra_data.data) {
1454 /****************************************************************
1455 _spoolss_OpenPrinterEx
1456 ****************************************************************/
1458 WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
1459 struct spoolss_OpenPrinterEx *r)
1462 Printer_entry *Printer=NULL;
1464 if (!r->in.printername) {
1465 return WERR_INVALID_PARAM;
1468 /* some sanity check because you can open a printer or a print server */
1469 /* aka: \\server\printer or \\server */
1471 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1473 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1474 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1475 " for printer %s\n", r->in.printername));
1476 ZERO_STRUCTP(r->out.handle);
1477 return WERR_INVALID_PARAM;
1480 Printer = find_printer_index_by_hnd(p, r->out.handle);
1482 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1483 "handle we created for printer %s\n", r->in.printername));
1484 close_printer_handle(p, r->out.handle);
1485 ZERO_STRUCTP(r->out.handle);
1486 return WERR_INVALID_PARAM;
1490 * First case: the user is opening the print server:
1492 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1493 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1495 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1496 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1497 * or if the user is listed in the smb.conf printer admin parameter.
1499 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1500 * client view printer folder, but does not show the MSAPW.
1502 * Note: this test needs code to check access rights here too. Jeremy
1503 * could you look at this?
1505 * Second case: the user is opening a printer:
1506 * NT doesn't let us connect to a printer if the connecting user
1507 * doesn't have print permission.
1509 * Third case: user is opening a Port Monitor
1510 * access checks same as opening a handle to the print server.
1513 switch (Printer->printer_type )
1516 case SPLHND_PORTMON_TCP:
1517 case SPLHND_PORTMON_LOCAL:
1518 /* Printserver handles use global struct... */
1522 /* Map standard access rights to object specific access rights */
1524 se_map_standard(&r->in.access_mask,
1525 &printserver_std_mapping);
1527 /* Deny any object specific bits that don't apply to print
1528 servers (i.e printer and job specific bits) */
1530 r->in.access_mask &= SEC_MASK_SPECIFIC;
1532 if (r->in.access_mask &
1533 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1534 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1535 close_printer_handle(p, r->out.handle);
1536 ZERO_STRUCTP(r->out.handle);
1537 return WERR_ACCESS_DENIED;
1540 /* Allow admin access */
1542 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1544 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1546 if (!lp_ms_add_printer_wizard()) {
1547 close_printer_handle(p, r->out.handle);
1548 ZERO_STRUCTP(r->out.handle);
1549 return WERR_ACCESS_DENIED;
1552 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1553 and not a printer admin, then fail */
1555 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1556 !user_has_privileges(p->server_info->ptok,
1558 !token_contains_name_in_list(
1559 uidtoname(p->server_info->utok.uid),
1560 p->server_info->info3->base.domain.string,
1562 p->server_info->ptok,
1563 lp_printer_admin(snum))) {
1564 close_printer_handle(p, r->out.handle);
1565 ZERO_STRUCTP(r->out.handle);
1566 return WERR_ACCESS_DENIED;
1569 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1573 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1576 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1577 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1579 /* We fall through to return WERR_OK */
1582 case SPLHND_PRINTER:
1583 /* NT doesn't let us connect to a printer if the connecting user
1584 doesn't have print permission. */
1586 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1587 close_printer_handle(p, r->out.handle);
1588 ZERO_STRUCTP(r->out.handle);
1592 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1593 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1596 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1598 /* map an empty access mask to the minimum access mask */
1599 if (r->in.access_mask == 0x0)
1600 r->in.access_mask = PRINTER_ACCESS_USE;
1603 * If we are not serving the printer driver for this printer,
1604 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1605 * will keep NT clients happy --jerry
1608 if (lp_use_client_driver(snum)
1609 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1611 r->in.access_mask = PRINTER_ACCESS_USE;
1614 /* check smb.conf parameters and the the sec_desc */
1616 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1617 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1618 ZERO_STRUCTP(r->out.handle);
1619 return WERR_ACCESS_DENIED;
1622 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1623 p->server_info->ptok, snum) ||
1624 !print_access_check(p->server_info, snum,
1625 r->in.access_mask)) {
1626 DEBUG(3, ("access DENIED for printer open\n"));
1627 close_printer_handle(p, r->out.handle);
1628 ZERO_STRUCTP(r->out.handle);
1629 return WERR_ACCESS_DENIED;
1632 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1633 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1634 close_printer_handle(p, r->out.handle);
1635 ZERO_STRUCTP(r->out.handle);
1636 return WERR_ACCESS_DENIED;
1639 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1640 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1642 r->in.access_mask = PRINTER_ACCESS_USE;
1644 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1645 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1647 winreg_create_printer(p->mem_ctx,
1649 Printer->servername,
1650 lp_const_servicename(snum));
1655 /* sanity check to prevent programmer error */
1656 ZERO_STRUCTP(r->out.handle);
1660 Printer->access_granted = r->in.access_mask;
1663 * If the client sent a devmode in the OpenPrinter() call, then
1664 * save it here in case we get a job submission on this handle
1667 if ((Printer->printer_type != SPLHND_SERVER) &&
1668 r->in.devmode_ctr.devmode) {
1669 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1673 #if 0 /* JERRY -- I'm doubtful this is really effective */
1674 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1675 optimization in Windows 2000 clients --jerry */
1677 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1678 && (RA_WIN2K == get_remote_arch()) )
1680 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1681 sys_usleep( 500000 );
1688 /****************************************************************
1689 _spoolss_ClosePrinter
1690 ****************************************************************/
1692 WERROR _spoolss_ClosePrinter(pipes_struct *p,
1693 struct spoolss_ClosePrinter *r)
1695 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1697 if (Printer && Printer->document_started) {
1698 struct spoolss_EndDocPrinter e;
1700 e.in.handle = r->in.handle;
1702 _spoolss_EndDocPrinter(p, &e);
1705 if (!close_printer_handle(p, r->in.handle))
1708 /* clear the returned printer handle. Observed behavior
1709 from Win2k server. Don't think this really matters.
1710 Previous code just copied the value of the closed
1713 ZERO_STRUCTP(r->out.handle);
1718 /****************************************************************
1719 _spoolss_DeletePrinter
1720 ****************************************************************/
1722 WERROR _spoolss_DeletePrinter(pipes_struct *p,
1723 struct spoolss_DeletePrinter *r)
1725 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1729 if (Printer && Printer->document_started) {
1730 struct spoolss_EndDocPrinter e;
1732 e.in.handle = r->in.handle;
1734 _spoolss_EndDocPrinter(p, &e);
1737 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
1738 winreg_delete_printer_key(p->mem_ctx,
1740 lp_const_servicename(snum),
1744 result = delete_printer_handle(p, r->in.handle);
1749 /*******************************************************************
1750 * static function to lookup the version id corresponding to an
1751 * long architecture string
1752 ******************************************************************/
1754 static const struct print_architecture_table_node archi_table[]= {
1756 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1757 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1758 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1759 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
1760 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
1761 {"Windows IA64", SPL_ARCH_IA64, 3 },
1762 {"Windows x64", SPL_ARCH_X64, 3 },
1766 static int get_version_id(const char *arch)
1770 for (i=0; archi_table[i].long_archi != NULL; i++)
1772 if (strcmp(arch, archi_table[i].long_archi) == 0)
1773 return (archi_table[i].version);
1779 /****************************************************************
1780 _spoolss_DeletePrinterDriver
1781 ****************************************************************/
1783 WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
1784 struct spoolss_DeletePrinterDriver *r)
1787 struct spoolss_DriverInfo8 *info = NULL;
1788 struct spoolss_DriverInfo8 *info_win2k = NULL;
1791 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1793 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1794 and not a printer admin, then fail */
1796 if ( (p->server_info->utok.uid != sec_initial_uid())
1797 && !user_has_privileges(p->server_info->ptok, &se_printop )
1798 && !token_contains_name_in_list(
1799 uidtoname(p->server_info->utok.uid),
1800 p->server_info->info3->base.domain.string,
1802 p->server_info->ptok,
1803 lp_printer_admin(-1)) )
1805 return WERR_ACCESS_DENIED;
1808 /* check that we have a valid driver name first */
1810 if ((version = get_version_id(r->in.architecture)) == -1)
1811 return WERR_INVALID_ENVIRONMENT;
1813 status = winreg_get_driver(p->mem_ctx, p->server_info,
1814 r->in.architecture, r->in.driver,
1816 if (!W_ERROR_IS_OK(status)) {
1817 /* try for Win2k driver if "Windows NT x86" */
1819 if ( version == 2 ) {
1822 status = winreg_get_driver(p->mem_ctx, p->server_info,
1826 if (!W_ERROR_IS_OK(status)) {
1827 status = WERR_UNKNOWN_PRINTER_DRIVER;
1831 /* otherwise it was a failure */
1833 status = WERR_UNKNOWN_PRINTER_DRIVER;
1839 if (printer_driver_in_use(p->mem_ctx, p->server_info, info)) {
1840 status = WERR_PRINTER_DRIVER_IN_USE;
1845 status = winreg_get_driver(p->mem_ctx, p->server_info,
1847 r->in.driver, 3, &info_win2k);
1848 if (W_ERROR_IS_OK(status)) {
1849 /* if we get to here, we now have 2 driver info structures to remove */
1850 /* remove the Win2k driver first*/
1852 status = winreg_del_driver(p->mem_ctx,
1855 talloc_free(info_win2k);
1857 /* this should not have failed---if it did, report to client */
1858 if (!W_ERROR_IS_OK(status)) {
1864 status = winreg_del_driver(p->mem_ctx, p->server_info, info, version);
1872 /****************************************************************
1873 _spoolss_DeletePrinterDriverEx
1874 ****************************************************************/
1876 WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
1877 struct spoolss_DeletePrinterDriverEx *r)
1879 struct spoolss_DriverInfo8 *info = NULL;
1880 struct spoolss_DriverInfo8 *info_win2k = NULL;
1884 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1886 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1887 and not a printer admin, then fail */
1889 if ( (p->server_info->utok.uid != sec_initial_uid())
1890 && !user_has_privileges(p->server_info->ptok, &se_printop )
1891 && !token_contains_name_in_list(
1892 uidtoname(p->server_info->utok.uid),
1893 p->server_info->info3->base.domain.string,
1895 p->server_info->ptok, lp_printer_admin(-1)) )
1897 return WERR_ACCESS_DENIED;
1900 /* check that we have a valid driver name first */
1901 if ((version = get_version_id(r->in.architecture)) == -1) {
1902 /* this is what NT returns */
1903 return WERR_INVALID_ENVIRONMENT;
1906 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
1907 version = r->in.version;
1909 status = winreg_get_driver(p->mem_ctx, p->server_info,
1910 r->in.architecture, r->in.driver,
1912 if (!W_ERROR_IS_OK(status)) {
1913 status = WERR_UNKNOWN_PRINTER_DRIVER;
1916 * if the client asked for a specific version,
1917 * or this is something other than Windows NT x86,
1921 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
1924 /* try for Win2k driver if "Windows NT x86" */
1927 status = winreg_get_driver(info, p->server_info,
1931 if (!W_ERROR_IS_OK(status)) {
1932 status = WERR_UNKNOWN_PRINTER_DRIVER;
1937 if (printer_driver_in_use(info, p->server_info, info)) {
1938 status = WERR_PRINTER_DRIVER_IN_USE;
1943 * we have a couple of cases to consider.
1944 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
1945 * then the delete should fail if **any** files overlap with
1947 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
1948 * non-overlapping files
1949 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
1950 * is set, the do not delete any files
1951 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
1954 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
1956 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
1959 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
1960 printer_driver_files_in_use(info, p->server_info, info)) {
1961 /* no idea of the correct error here */
1962 status = WERR_ACCESS_DENIED;
1967 /* also check for W32X86/3 if necessary; maybe we already have? */
1969 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
1970 status = winreg_get_driver(info, p->server_info,
1972 r->in.driver, 3, &info_win2k);
1973 if (W_ERROR_IS_OK(status)) {
1976 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
1977 printer_driver_files_in_use(info, p->server_info,
1979 /* no idea of the correct error here */
1980 talloc_free(info_win2k);
1981 status = WERR_ACCESS_DENIED;
1985 /* if we get to here, we now have 2 driver info structures to remove */
1986 /* remove the Win2k driver first*/
1988 status = winreg_del_driver(info, p->server_info,
1991 /* this should not have failed---if it did, report to client */
1993 if (!W_ERROR_IS_OK(status)) {
1998 * now delete any associated files if delete_files is
1999 * true. Even if this part failes, we return succes
2000 * because the driver doesn not exist any more
2003 delete_driver_files(p->server_info,
2009 status = winreg_del_driver(info, p->server_info, info, version);
2010 if (!W_ERROR_IS_OK(status)) {
2015 * now delete any associated files if delete_files is
2016 * true. Even if this part failes, we return succes
2017 * because the driver doesn not exist any more
2020 delete_driver_files(p->server_info, info);
2029 /********************************************************************
2030 GetPrinterData on a printer server Handle.
2031 ********************************************************************/
2033 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2035 enum winreg_Type *type,
2036 union spoolss_PrinterData *data)
2038 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2040 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2046 if (!StrCaseCmp(value, "BeepEnabled")) {
2052 if (!StrCaseCmp(value, "EventLog")) {
2054 /* formally was 0x1b */
2059 if (!StrCaseCmp(value, "NetPopup")) {
2065 if (!StrCaseCmp(value, "MajorVersion")) {
2068 /* Windows NT 4.0 seems to not allow uploading of drivers
2069 to a server that reports 0x3 as the MajorVersion.
2070 need to investigate more how Win2k gets around this .
2073 if (RA_WINNT == get_remote_arch()) {
2082 if (!StrCaseCmp(value, "MinorVersion")) {
2089 * uint32_t size = 0x114
2090 * uint32_t major = 5
2091 * uint32_t minor = [0|1]
2092 * uint32_t build = [2195|2600]
2093 * extra unicode string = e.g. "Service Pack 3"
2095 if (!StrCaseCmp(value, "OSVersion")) {
2097 enum ndr_err_code ndr_err;
2098 struct spoolss_OSVersion os;
2100 os.major = 5; /* Windows 2000 == 5.0 */
2102 os.build = 2195; /* build */
2103 os.extra_string = ""; /* leave extra string empty */
2105 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2106 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2107 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2108 return WERR_GENERAL_FAILURE;
2112 data->binary = blob;
2118 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2121 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2122 W_ERROR_HAVE_NO_MEMORY(data->string);
2127 if (!StrCaseCmp(value, "Architecture")) {
2129 data->string = talloc_strdup(mem_ctx,
2130 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2131 W_ERROR_HAVE_NO_MEMORY(data->string);
2136 if (!StrCaseCmp(value, "DsPresent")) {
2139 /* only show the publish check box if we are a
2140 member of a AD domain */
2142 if (lp_security() == SEC_ADS) {
2150 if (!StrCaseCmp(value, "DNSMachineName")) {
2151 const char *hostname = get_mydnsfullname();
2154 return WERR_BADFILE;
2158 data->string = talloc_strdup(mem_ctx, hostname);
2159 W_ERROR_HAVE_NO_MEMORY(data->string);
2166 return WERR_INVALID_PARAM;
2169 /****************************************************************
2170 _spoolss_GetPrinterData
2171 ****************************************************************/
2173 WERROR _spoolss_GetPrinterData(pipes_struct *p,
2174 struct spoolss_GetPrinterData *r)
2176 struct spoolss_GetPrinterDataEx r2;
2178 r2.in.handle = r->in.handle;
2179 r2.in.key_name = "PrinterDriverData";
2180 r2.in.value_name = r->in.value_name;
2181 r2.in.offered = r->in.offered;
2182 r2.out.type = r->out.type;
2183 r2.out.data = r->out.data;
2184 r2.out.needed = r->out.needed;
2186 return _spoolss_GetPrinterDataEx(p, &r2);
2189 /*********************************************************
2190 Connect to the client machine.
2191 **********************************************************/
2193 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2194 struct sockaddr_storage *client_ss, const char *remote_machine)
2197 struct cli_state *the_cli;
2198 struct sockaddr_storage rm_addr;
2199 char addr[INET6_ADDRSTRLEN];
2201 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2202 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2204 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2205 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2208 print_sockaddr(addr, sizeof(addr), &rm_addr);
2210 rm_addr = *client_ss;
2211 print_sockaddr(addr, sizeof(addr), &rm_addr);
2212 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2216 if (ismyaddr((struct sockaddr *)&rm_addr)) {
2217 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2222 /* setup the connection */
2223 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2224 &rm_addr, 0, "IPC$", "IPC",
2228 0, lp_client_signing(), NULL );
2230 if ( !NT_STATUS_IS_OK( ret ) ) {
2231 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2236 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2237 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2238 cli_shutdown(the_cli);
2243 * Ok - we have an anonymous connection to the IPC$ share.
2244 * Now start the NT Domain stuff :-).
2247 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2248 if (!NT_STATUS_IS_OK(ret)) {
2249 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2250 remote_machine, nt_errstr(ret)));
2251 cli_shutdown(the_cli);
2258 /***************************************************************************
2259 Connect to the client.
2260 ****************************************************************************/
2262 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2263 uint32_t localprinter, uint32_t type,
2264 struct policy_handle *handle,
2265 struct sockaddr_storage *client_ss)
2271 * If it's the first connection, contact the client
2272 * and connect to the IPC$ share anonymously
2274 if (smb_connections==0) {
2275 fstring unix_printer;
2277 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2279 if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ss, unix_printer ))
2282 messaging_register(smbd_messaging_context(), NULL,
2283 MSG_PRINTER_NOTIFY2,
2284 receive_notify2_message_list);
2285 /* Tell the connections db we're now interested in printer
2286 * notify messages. */
2287 serverid_register_msg_flags(
2288 messaging_server_id(smbd_messaging_context()),
2289 true, FLAG_MSG_PRINT_NOTIFY);
2293 * Tell the specific printing tdb we want messages for this printer
2294 * by registering our PID.
2297 if (!print_notify_register_pid(snum))
2298 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2302 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2310 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2311 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2312 win_errstr(result)));
2314 return (W_ERROR_IS_OK(result));
2317 /****************************************************************
2318 ****************************************************************/
2320 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2321 const struct spoolss_NotifyOption *r)
2323 struct spoolss_NotifyOption *option;
2330 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2337 if (!option->count) {
2341 option->types = talloc_zero_array(option,
2342 struct spoolss_NotifyOptionType, option->count);
2343 if (!option->types) {
2344 talloc_free(option);
2348 for (i=0; i < option->count; i++) {
2349 option->types[i] = r->types[i];
2351 if (option->types[i].count) {
2352 option->types[i].fields = talloc_zero_array(option,
2353 union spoolss_Field, option->types[i].count);
2354 if (!option->types[i].fields) {
2355 talloc_free(option);
2358 for (k=0; k<option->types[i].count; k++) {
2359 option->types[i].fields[k] =
2360 r->types[i].fields[k];
2368 /****************************************************************
2369 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2371 * before replying OK: status=0 a rpc call is made to the workstation
2372 * asking ReplyOpenPrinter
2374 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2375 * called from api_spoolss_rffpcnex
2376 ****************************************************************/
2378 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
2379 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2382 struct spoolss_NotifyOption *option = r->in.notify_options;
2383 struct sockaddr_storage client_ss;
2385 /* store the notify value in the printer struct */
2387 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2390 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2391 "Invalid handle (%s:%u:%u).\n",
2392 OUR_HANDLE(r->in.handle)));
2396 Printer->notify.flags = r->in.flags;
2397 Printer->notify.options = r->in.options;
2398 Printer->notify.printerlocal = r->in.printer_local;
2400 TALLOC_FREE(Printer->notify.option);
2401 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2403 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2405 /* Connect to the client machine and send a ReplyOpenPrinter */
2407 if ( Printer->printer_type == SPLHND_SERVER)
2409 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2410 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2413 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2414 "client_address is %s\n", p->client_address));
2416 if (!interpret_string_addr(&client_ss, p->client_address,
2418 return WERR_SERVER_UNAVAILABLE;
2421 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2422 Printer->notify.printerlocal, 1,
2423 &Printer->notify.client_hnd, &client_ss))
2424 return WERR_SERVER_UNAVAILABLE;
2426 Printer->notify.client_connected = true;
2431 /*******************************************************************
2432 * fill a notify_info_data with the servername
2433 ********************************************************************/
2435 static void spoolss_notify_server_name(int snum,
2436 struct spoolss_Notify *data,
2437 print_queue_struct *queue,
2438 struct spoolss_PrinterInfo2 *pinfo2,
2439 TALLOC_CTX *mem_ctx)
2441 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2444 /*******************************************************************
2445 * fill a notify_info_data with the printername (not including the servername).
2446 ********************************************************************/
2448 static void spoolss_notify_printer_name(int snum,
2449 struct spoolss_Notify *data,
2450 print_queue_struct *queue,
2451 struct spoolss_PrinterInfo2 *pinfo2,
2452 TALLOC_CTX *mem_ctx)
2454 /* the notify name should not contain the \\server\ part */
2455 const char *p = strrchr(pinfo2->printername, '\\');
2458 p = pinfo2->printername;
2463 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2466 /*******************************************************************
2467 * fill a notify_info_data with the servicename
2468 ********************************************************************/
2470 static void spoolss_notify_share_name(int snum,
2471 struct spoolss_Notify *data,
2472 print_queue_struct *queue,
2473 struct spoolss_PrinterInfo2 *pinfo2,
2474 TALLOC_CTX *mem_ctx)
2476 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2479 /*******************************************************************
2480 * fill a notify_info_data with the port name
2481 ********************************************************************/
2483 static void spoolss_notify_port_name(int snum,
2484 struct spoolss_Notify *data,
2485 print_queue_struct *queue,
2486 struct spoolss_PrinterInfo2 *pinfo2,
2487 TALLOC_CTX *mem_ctx)
2489 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2492 /*******************************************************************
2493 * fill a notify_info_data with the printername
2494 * but it doesn't exist, have to see what to do
2495 ********************************************************************/
2497 static void spoolss_notify_driver_name(int snum,
2498 struct spoolss_Notify *data,
2499 print_queue_struct *queue,
2500 struct spoolss_PrinterInfo2 *pinfo2,
2501 TALLOC_CTX *mem_ctx)
2503 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2506 /*******************************************************************
2507 * fill a notify_info_data with the comment
2508 ********************************************************************/
2510 static void spoolss_notify_comment(int snum,
2511 struct spoolss_Notify *data,
2512 print_queue_struct *queue,
2513 struct spoolss_PrinterInfo2 *pinfo2,
2514 TALLOC_CTX *mem_ctx)
2518 if (*pinfo2->comment == '\0') {
2519 p = lp_comment(snum);
2521 p = pinfo2->comment;
2524 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2527 /*******************************************************************
2528 * fill a notify_info_data with the comment
2529 * location = "Room 1, floor 2, building 3"
2530 ********************************************************************/
2532 static void spoolss_notify_location(int snum,
2533 struct spoolss_Notify *data,
2534 print_queue_struct *queue,
2535 struct spoolss_PrinterInfo2 *pinfo2,
2536 TALLOC_CTX *mem_ctx)
2538 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
2541 /*******************************************************************
2542 * fill a notify_info_data with the device mode
2543 * jfm:xxxx don't to it for know but that's a real problem !!!
2544 ********************************************************************/
2546 static void spoolss_notify_devmode(int snum,
2547 struct spoolss_Notify *data,
2548 print_queue_struct *queue,
2549 struct spoolss_PrinterInfo2 *pinfo2,
2550 TALLOC_CTX *mem_ctx)
2552 /* for a dummy implementation we have to zero the fields */
2553 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2556 /*******************************************************************
2557 * fill a notify_info_data with the separator file name
2558 ********************************************************************/
2560 static void spoolss_notify_sepfile(int snum,
2561 struct spoolss_Notify *data,
2562 print_queue_struct *queue,
2563 struct spoolss_PrinterInfo2 *pinfo2,
2564 TALLOC_CTX *mem_ctx)
2566 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2569 /*******************************************************************
2570 * fill a notify_info_data with the print processor
2571 * jfm:xxxx return always winprint to indicate we don't do anything to it
2572 ********************************************************************/
2574 static void spoolss_notify_print_processor(int snum,
2575 struct spoolss_Notify *data,
2576 print_queue_struct *queue,
2577 struct spoolss_PrinterInfo2 *pinfo2,
2578 TALLOC_CTX *mem_ctx)
2580 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2583 /*******************************************************************
2584 * fill a notify_info_data with the print processor options
2585 * jfm:xxxx send an empty string
2586 ********************************************************************/
2588 static void spoolss_notify_parameters(int snum,
2589 struct spoolss_Notify *data,
2590 print_queue_struct *queue,
2591 struct spoolss_PrinterInfo2 *pinfo2,
2592 TALLOC_CTX *mem_ctx)
2594 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2597 /*******************************************************************
2598 * fill a notify_info_data with the data type
2599 * jfm:xxxx always send RAW as data type
2600 ********************************************************************/
2602 static void spoolss_notify_datatype(int snum,
2603 struct spoolss_Notify *data,
2604 print_queue_struct *queue,
2605 struct spoolss_PrinterInfo2 *pinfo2,
2606 TALLOC_CTX *mem_ctx)
2608 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2611 /*******************************************************************
2612 * fill a notify_info_data with the security descriptor
2613 * jfm:xxxx send an null pointer to say no security desc
2614 * have to implement security before !
2615 ********************************************************************/
2617 static void spoolss_notify_security_desc(int snum,
2618 struct spoolss_Notify *data,
2619 print_queue_struct *queue,
2620 struct spoolss_PrinterInfo2 *pinfo2,
2621 TALLOC_CTX *mem_ctx)
2623 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2626 /*******************************************************************
2627 * fill a notify_info_data with the attributes
2628 * jfm:xxxx a samba printer is always shared
2629 ********************************************************************/
2631 static void spoolss_notify_attributes(int snum,
2632 struct spoolss_Notify *data,
2633 print_queue_struct *queue,
2634 struct spoolss_PrinterInfo2 *pinfo2,
2635 TALLOC_CTX *mem_ctx)
2637 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2640 /*******************************************************************
2641 * fill a notify_info_data with the priority
2642 ********************************************************************/
2644 static void spoolss_notify_priority(int snum,
2645 struct spoolss_Notify *data,
2646 print_queue_struct *queue,
2647 struct spoolss_PrinterInfo2 *pinfo2,
2648 TALLOC_CTX *mem_ctx)
2650 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2653 /*******************************************************************
2654 * fill a notify_info_data with the default priority
2655 ********************************************************************/
2657 static void spoolss_notify_default_priority(int snum,
2658 struct spoolss_Notify *data,
2659 print_queue_struct *queue,
2660 struct spoolss_PrinterInfo2 *pinfo2,
2661 TALLOC_CTX *mem_ctx)
2663 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
2666 /*******************************************************************
2667 * fill a notify_info_data with the start time
2668 ********************************************************************/
2670 static void spoolss_notify_start_time(int snum,
2671 struct spoolss_Notify *data,
2672 print_queue_struct *queue,
2673 struct spoolss_PrinterInfo2 *pinfo2,
2674 TALLOC_CTX *mem_ctx)
2676 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
2679 /*******************************************************************
2680 * fill a notify_info_data with the until time
2681 ********************************************************************/
2683 static void spoolss_notify_until_time(int snum,
2684 struct spoolss_Notify *data,
2685 print_queue_struct *queue,
2686 struct spoolss_PrinterInfo2 *pinfo2,
2687 TALLOC_CTX *mem_ctx)
2689 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
2692 /*******************************************************************
2693 * fill a notify_info_data with the status
2694 ********************************************************************/
2696 static void spoolss_notify_status(int snum,
2697 struct spoolss_Notify *data,
2698 print_queue_struct *queue,
2699 struct spoolss_PrinterInfo2 *pinfo2,
2700 TALLOC_CTX *mem_ctx)
2702 print_status_struct status;
2704 print_queue_length(snum, &status);
2705 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
2708 /*******************************************************************
2709 * fill a notify_info_data with the number of jobs queued
2710 ********************************************************************/
2712 static void spoolss_notify_cjobs(int snum,
2713 struct spoolss_Notify *data,
2714 print_queue_struct *queue,
2715 struct spoolss_PrinterInfo2 *pinfo2,
2716 TALLOC_CTX *mem_ctx)
2718 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
2721 /*******************************************************************
2722 * fill a notify_info_data with the average ppm
2723 ********************************************************************/
2725 static void spoolss_notify_average_ppm(int snum,
2726 struct spoolss_Notify *data,
2727 print_queue_struct *queue,
2728 struct spoolss_PrinterInfo2 *pinfo2,
2729 TALLOC_CTX *mem_ctx)
2731 /* always respond 8 pages per minutes */
2732 /* a little hard ! */
2733 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
2736 /*******************************************************************
2737 * fill a notify_info_data with username
2738 ********************************************************************/
2740 static void spoolss_notify_username(int snum,
2741 struct spoolss_Notify *data,
2742 print_queue_struct *queue,
2743 struct spoolss_PrinterInfo2 *pinfo2,
2744 TALLOC_CTX *mem_ctx)
2746 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
2749 /*******************************************************************
2750 * fill a notify_info_data with job status
2751 ********************************************************************/
2753 static void spoolss_notify_job_status(int snum,
2754 struct spoolss_Notify *data,
2755 print_queue_struct *queue,
2756 struct spoolss_PrinterInfo2 *pinfo2,
2757 TALLOC_CTX *mem_ctx)
2759 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
2762 /*******************************************************************
2763 * fill a notify_info_data with job name
2764 ********************************************************************/
2766 static void spoolss_notify_job_name(int snum,
2767 struct spoolss_Notify *data,
2768 print_queue_struct *queue,
2769 struct spoolss_PrinterInfo2 *pinfo2,
2770 TALLOC_CTX *mem_ctx)
2772 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
2775 /*******************************************************************
2776 * fill a notify_info_data with job status
2777 ********************************************************************/
2779 static void spoolss_notify_job_status_string(int snum,
2780 struct spoolss_Notify *data,
2781 print_queue_struct *queue,
2782 struct spoolss_PrinterInfo2 *pinfo2,
2783 TALLOC_CTX *mem_ctx)
2786 * Now we're returning job status codes we just return a "" here. JRA.
2791 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
2794 switch (queue->status) {
2799 p = ""; /* NT provides the paused string */
2808 #endif /* NO LONGER NEEDED. */
2810 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2813 /*******************************************************************
2814 * fill a notify_info_data with job time
2815 ********************************************************************/
2817 static void spoolss_notify_job_time(int snum,
2818 struct spoolss_Notify *data,
2819 print_queue_struct *queue,
2820 struct spoolss_PrinterInfo2 *pinfo2,
2821 TALLOC_CTX *mem_ctx)
2823 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2826 /*******************************************************************
2827 * fill a notify_info_data with job size
2828 ********************************************************************/
2830 static void spoolss_notify_job_size(int snum,
2831 struct spoolss_Notify *data,
2832 print_queue_struct *queue,
2833 struct spoolss_PrinterInfo2 *pinfo2,
2834 TALLOC_CTX *mem_ctx)
2836 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
2839 /*******************************************************************
2840 * fill a notify_info_data with page info
2841 ********************************************************************/
2842 static void spoolss_notify_total_pages(int snum,
2843 struct spoolss_Notify *data,
2844 print_queue_struct *queue,
2845 struct spoolss_PrinterInfo2 *pinfo2,
2846 TALLOC_CTX *mem_ctx)
2848 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
2851 /*******************************************************************
2852 * fill a notify_info_data with pages printed info.
2853 ********************************************************************/
2854 static void spoolss_notify_pages_printed(int snum,
2855 struct spoolss_Notify *data,
2856 print_queue_struct *queue,
2857 struct spoolss_PrinterInfo2 *pinfo2,
2858 TALLOC_CTX *mem_ctx)
2860 /* Add code when back-end tracks this */
2861 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2864 /*******************************************************************
2865 Fill a notify_info_data with job position.
2866 ********************************************************************/
2868 static void spoolss_notify_job_position(int snum,
2869 struct spoolss_Notify *data,
2870 print_queue_struct *queue,
2871 struct spoolss_PrinterInfo2 *pinfo2,
2872 TALLOC_CTX *mem_ctx)
2874 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
2877 /*******************************************************************
2878 Fill a notify_info_data with submitted time.
2879 ********************************************************************/
2881 static void spoolss_notify_submitted_time(int snum,
2882 struct spoolss_Notify *data,
2883 print_queue_struct *queue,
2884 struct spoolss_PrinterInfo2 *pinfo2,
2885 TALLOC_CTX *mem_ctx)
2887 data->data.string.string = NULL;
2888 data->data.string.size = 0;
2890 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
2891 &data->data.string.string,
2892 &data->data.string.size);
2896 struct s_notify_info_data_table
2898 enum spoolss_NotifyType type;
2901 enum spoolss_NotifyTable variable_type;
2902 void (*fn) (int snum, struct spoolss_Notify *data,
2903 print_queue_struct *queue,
2904 struct spoolss_PrinterInfo2 *pinfo2,
2905 TALLOC_CTX *mem_ctx);
2908 /* A table describing the various print notification constants and
2909 whether the notification data is a pointer to a variable sized
2910 buffer, a one value uint32_t or a two value uint32_t. */
2912 static const struct s_notify_info_data_table notify_info_data_table[] =
2914 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2915 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2916 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
2917 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2918 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2919 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
2920 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
2921 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2922 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
2923 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2924 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2925 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2926 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
2927 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
2928 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2929 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
2930 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2931 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2932 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
2933 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
2934 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
2935 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
2936 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
2937 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2938 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
2939 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2940 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2941 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2942 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2943 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2944 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2945 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2946 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2947 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2948 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2949 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2950 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
2951 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
2952 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
2953 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
2954 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2955 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
2956 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
2957 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2958 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2959 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
2960 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
2961 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
2962 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
2965 /*******************************************************************
2966 Return the variable_type of info_data structure.
2967 ********************************************************************/
2969 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
2974 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
2975 if ( (notify_info_data_table[i].type == type) &&
2976 (notify_info_data_table[i].field == field) ) {
2977 return notify_info_data_table[i].variable_type;
2981 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
2986 /****************************************************************************
2987 ****************************************************************************/
2989 static bool search_notify(enum spoolss_NotifyType type,
2995 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
2996 if (notify_info_data_table[i].type == type &&
2997 notify_info_data_table[i].field == field &&
2998 notify_info_data_table[i].fn != NULL) {
3007 /****************************************************************************
3008 ****************************************************************************/
3010 static void construct_info_data(struct spoolss_Notify *info_data,
3011 enum spoolss_NotifyType type,
3012 uint16_t field, int id)
3014 info_data->type = type;
3015 info_data->field.field = field;
3016 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3017 info_data->job_id = id;
3020 /*******************************************************************
3022 * fill a notify_info struct with info asked
3024 ********************************************************************/
3026 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3027 struct spoolss_NotifyInfo *info,
3028 struct spoolss_PrinterInfo2 *pinfo2,
3030 const struct spoolss_NotifyOptionType *option_type,
3032 TALLOC_CTX *mem_ctx)
3035 enum spoolss_NotifyType type;
3038 struct spoolss_Notify *current_data;
3039 print_queue_struct *queue=NULL;
3041 type = option_type->type;
3043 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3044 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3045 option_type->count, lp_servicename(snum)));
3047 for(field_num=0; field_num < option_type->count; field_num++) {
3048 field = option_type->fields[field_num].field;
3050 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3052 if (!search_notify(type, field, &j) )
3055 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3056 struct spoolss_Notify,
3058 if (info->notifies == NULL) {
3059 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3063 current_data = &info->notifies[info->count];
3065 construct_info_data(current_data, type, field, id);
3067 DEBUG(10, ("construct_notify_printer_info: "
3068 "calling [%s] snum=%d printername=[%s])\n",
3069 notify_info_data_table[j].name, snum,
3070 pinfo2->printername));
3072 notify_info_data_table[j].fn(snum, current_data, queue,
3081 /*******************************************************************
3083 * fill a notify_info struct with info asked
3085 ********************************************************************/
3087 static bool construct_notify_jobs_info(print_queue_struct *queue,
3088 struct spoolss_NotifyInfo *info,
3089 struct spoolss_PrinterInfo2 *pinfo2,
3091 const struct spoolss_NotifyOptionType *option_type,
3093 TALLOC_CTX *mem_ctx)
3096 enum spoolss_NotifyType type;
3098 struct spoolss_Notify *current_data;
3100 DEBUG(4,("construct_notify_jobs_info\n"));
3102 type = option_type->type;
3104 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3105 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3106 option_type->count));
3108 for(field_num=0; field_num<option_type->count; field_num++) {
3109 field = option_type->fields[field_num].field;
3111 if (!search_notify(type, field, &j) )
3114 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3115 struct spoolss_Notify,
3117 if (info->notifies == NULL) {
3118 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3122 current_data=&(info->notifies[info->count]);
3124 construct_info_data(current_data, type, field, id);
3125 notify_info_data_table[j].fn(snum, current_data, queue,
3134 * JFM: The enumeration is not that simple, it's even non obvious.
3136 * let's take an example: I want to monitor the PRINTER SERVER for
3137 * the printer's name and the number of jobs currently queued.
3138 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3139 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3141 * I have 3 printers on the back of my server.
3143 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3146 * 1 printer 1 name 1
3147 * 2 printer 1 cjob 1
3148 * 3 printer 2 name 2
3149 * 4 printer 2 cjob 2
3150 * 5 printer 3 name 3
3151 * 6 printer 3 name 3
3153 * that's the print server case, the printer case is even worse.
3156 /*******************************************************************
3158 * enumerate all printers on the printserver
3159 * fill a notify_info struct with info asked
3161 ********************************************************************/
3163 static WERROR printserver_notify_info(pipes_struct *p,
3164 struct policy_handle *hnd,
3165 struct spoolss_NotifyInfo *info,
3166 TALLOC_CTX *mem_ctx)
3169 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3170 int n_services=lp_numservices();
3172 struct spoolss_NotifyOption *option;
3173 struct spoolss_NotifyOptionType option_type;
3174 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3177 DEBUG(4,("printserver_notify_info\n"));
3182 option = Printer->notify.option;
3185 info->notifies = NULL;
3188 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3189 sending a ffpcn() request first */
3194 for (i=0; i<option->count; i++) {
3195 option_type = option->types[i];
3197 if (option_type.type != PRINTER_NOTIFY_TYPE)
3200 for (snum = 0; snum < n_services; snum++) {
3201 if (!lp_browseable(snum) ||
3202 !lp_snum_ok(snum) ||
3203 !lp_print_ok(snum)) {
3204 continue; /* skip */
3207 /* FIXME: should we use a SYSTEM server_info here? */
3208 result = winreg_get_printer(mem_ctx, p->server_info,
3209 Printer->servername,
3210 lp_servicename(snum),
3212 if (!W_ERROR_IS_OK(result)) {
3213 DEBUG(4, ("printserver_notify_info: "
3214 "Failed to get printer [%s]\n",
3215 lp_servicename(snum)));
3220 construct_notify_printer_info(Printer, info,
3225 TALLOC_FREE(pinfo2);
3231 * Debugging information, don't delete.
3234 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3235 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3236 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3238 for (i=0; i<info->count; i++) {
3239 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3240 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3241 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3248 /*******************************************************************
3250 * fill a notify_info struct with info asked
3252 ********************************************************************/
3254 static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
3255 struct spoolss_NotifyInfo *info,
3256 TALLOC_CTX *mem_ctx)
3259 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3262 struct spoolss_NotifyOption *option;
3263 struct spoolss_NotifyOptionType option_type;
3265 print_queue_struct *queue=NULL;
3266 print_status_struct status;
3267 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3270 DEBUG(4,("printer_notify_info\n"));
3275 option = Printer->notify.option;
3279 info->notifies = NULL;
3282 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3283 sending a ffpcn() request first */
3288 get_printer_snum(p, hnd, &snum, NULL);
3290 /* FIXME: should we use a SYSTEM server_info here ? */
3291 result = winreg_get_printer(mem_ctx, p->server_info,
3292 Printer->servername,
3293 lp_servicename(snum), &pinfo2);
3294 if (!W_ERROR_IS_OK(result)) {
3298 for (i=0; i<option->count; i++) {
3299 option_type = option->types[i];
3301 switch (option_type.type) {
3302 case PRINTER_NOTIFY_TYPE:
3303 if (construct_notify_printer_info(Printer, info,
3311 case JOB_NOTIFY_TYPE:
3313 count = print_queue_status(snum, &queue, &status);
3315 for (j=0; j<count; j++) {
3316 construct_notify_jobs_info(&queue[j], info,
3329 * Debugging information, don't delete.
3332 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3333 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3334 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3336 for (i=0; i<info->count; i++) {
3337 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3338 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3339 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3343 talloc_free(pinfo2);
3347 /****************************************************************
3348 _spoolss_RouterRefreshPrinterChangeNotify
3349 ****************************************************************/
3351 WERROR _spoolss_RouterRefreshPrinterChangeNotify(pipes_struct *p,
3352 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3354 struct spoolss_NotifyInfo *info;
3356 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
3357 WERROR result = WERR_BADFID;
3359 /* we always have a spoolss_NotifyInfo struct */
3360 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3362 result = WERR_NOMEM;
3366 *r->out.info = info;
3369 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3370 "Invalid handle (%s:%u:%u).\n",
3371 OUR_HANDLE(r->in.handle)));
3375 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3378 * We are now using the change value, and
3379 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3380 * I don't have a global notification system, I'm sending back all the
3381 * informations even when _NOTHING_ has changed.
3384 /* We need to keep track of the change value to send back in
3385 RRPCN replies otherwise our updates are ignored. */
3387 Printer->notify.fnpcn = true;
3389 if (Printer->notify.client_connected) {
3390 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3391 "Saving change value in request [%x]\n",
3393 Printer->notify.change = r->in.change_low;
3396 /* just ignore the spoolss_NotifyOption */
3398 switch (Printer->printer_type) {
3400 result = printserver_notify_info(p, r->in.handle,
3404 case SPLHND_PRINTER:
3405 result = printer_notify_info(p, r->in.handle,
3410 Printer->notify.fnpcn = false;
3416 /********************************************************************
3417 * construct_printer_info_0
3418 * fill a printer_info_0 struct
3419 ********************************************************************/
3421 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3422 struct auth_serversupplied_info *server_info,
3423 struct spoolss_PrinterInfo2 *info2,
3424 struct spoolss_PrinterInfo0 *r,
3428 counter_printer_0 *session_counter;
3429 struct timeval setuptime;
3430 print_status_struct status;
3432 r->printername = talloc_strdup(mem_ctx, info2->printername);
3433 W_ERROR_HAVE_NO_MEMORY(r->printername);
3435 r->servername = talloc_strdup(mem_ctx, info2->servername);
3436 W_ERROR_HAVE_NO_MEMORY(r->servername);
3438 count = print_queue_length(snum, &status);
3440 /* check if we already have a counter for this printer */
3441 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3442 if (session_counter->snum == snum)
3446 /* it's the first time, add it to the list */
3447 if (session_counter == NULL) {
3448 session_counter = SMB_MALLOC_P(counter_printer_0);
3449 W_ERROR_HAVE_NO_MEMORY(session_counter);
3450 ZERO_STRUCTP(session_counter);
3451 session_counter->snum = snum;
3452 session_counter->counter = 0;
3453 DLIST_ADD(counter_list, session_counter);
3457 session_counter->counter++;
3463 get_startup_time(&setuptime);
3464 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3467 * the global_counter should be stored in a TDB as it's common to all the clients
3468 * and should be zeroed on samba startup
3470 r->global_counter = session_counter->counter;
3472 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3473 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3474 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3475 r->free_build = SPOOLSS_RELEASE_BUILD;
3477 r->max_spooling = 0;
3478 r->session_counter = session_counter->counter;
3479 r->num_error_out_of_paper = 0x0;
3480 r->num_error_not_ready = 0x0; /* number of print failure */
3482 r->number_of_processors = 0x1;
3483 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3484 r->high_part_total_bytes = 0x0;
3485 winreg_printer_get_changeid(mem_ctx, server_info, info2->sharename, &r->change_id); /* ChangeID in milliseconds*/
3486 r->last_error = WERR_OK;
3487 r->status = nt_printq_status(status.status);
3488 r->enumerate_network_printers = 0x0;
3489 r->c_setprinter = 0x0;
3490 r->processor_architecture = 0x0;
3491 r->processor_level = 0x6; /* 6 ???*/
3500 /********************************************************************
3501 * construct_printer_info1
3502 * fill a spoolss_PrinterInfo1 struct
3503 ********************************************************************/
3505 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3506 const struct spoolss_PrinterInfo2 *info2,
3508 struct spoolss_PrinterInfo1 *r,
3513 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3517 W_ERROR_HAVE_NO_MEMORY(r->description);
3519 if (info2->comment == NULL || info2->comment[0] == '\0') {
3520 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3522 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3524 W_ERROR_HAVE_NO_MEMORY(r->comment);
3526 r->name = talloc_strdup(mem_ctx, info2->printername);
3527 W_ERROR_HAVE_NO_MEMORY(r->name);
3532 /********************************************************************
3533 * construct_printer_info2
3534 * fill a spoolss_PrinterInfo2 struct
3535 ********************************************************************/
3537 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3538 const struct spoolss_PrinterInfo2 *info2,
3539 struct spoolss_PrinterInfo2 *r,
3543 print_status_struct status;
3545 count = print_queue_length(snum, &status);
3547 r->servername = talloc_strdup(mem_ctx, info2->servername);
3548 W_ERROR_HAVE_NO_MEMORY(r->servername);
3549 r->printername = talloc_strdup(mem_ctx, info2->printername);
3550 W_ERROR_HAVE_NO_MEMORY(r->printername);
3551 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3552 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3553 r->portname = talloc_strdup(mem_ctx, info2->portname);
3554 W_ERROR_HAVE_NO_MEMORY(r->portname);
3555 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
3556 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3558 if (info2->comment[0] == '\0') {
3559 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3561 r->comment = talloc_strdup(mem_ctx, info2->comment);
3563 W_ERROR_HAVE_NO_MEMORY(r->comment);
3565 r->location = talloc_strdup(mem_ctx, info2->location);
3566 W_ERROR_HAVE_NO_MEMORY(r->location);
3567 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
3568 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3569 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
3570 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3571 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
3572 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3573 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
3574 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3576 r->attributes = info2->attributes;
3578 r->priority = info2->priority;
3579 r->defaultpriority = info2->defaultpriority;
3580 r->starttime = info2->starttime;
3581 r->untiltime = info2->untiltime;
3582 r->status = nt_printq_status(status.status);
3584 r->averageppm = info2->averageppm;
3586 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3588 DEBUG(8,("Returning NULL Devicemode!\n"));
3593 if (info2->secdesc != NULL) {
3594 /* don't use talloc_steal() here unless you do a deep steal of all
3595 the SEC_DESC members */
3597 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3603 /********************************************************************
3604 * construct_printer_info3
3605 * fill a spoolss_PrinterInfo3 struct
3606 ********************************************************************/
3608 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3609 const struct spoolss_PrinterInfo2 *info2,
3610 struct spoolss_PrinterInfo3 *r,
3613 /* These are the components of the SD we are returning. */
3615 if (info2->secdesc != NULL) {
3616 /* don't use talloc_steal() here unless you do a deep steal of all
3617 the SEC_DESC members */
3619 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3620 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3626 /********************************************************************
3627 * construct_printer_info4
3628 * fill a spoolss_PrinterInfo4 struct
3629 ********************************************************************/
3631 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
3632 const struct spoolss_PrinterInfo2 *info2,
3633 struct spoolss_PrinterInfo4 *r,
3636 r->printername = talloc_strdup(mem_ctx, info2->printername);
3637 W_ERROR_HAVE_NO_MEMORY(r->printername);
3638 r->servername = talloc_strdup(mem_ctx, info2->servername);
3639 W_ERROR_HAVE_NO_MEMORY(r->servername);
3641 r->attributes = info2->attributes;
3646 /********************************************************************
3647 * construct_printer_info5
3648 * fill a spoolss_PrinterInfo5 struct
3649 ********************************************************************/
3651 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
3652 const struct spoolss_PrinterInfo2 *info2,
3653 struct spoolss_PrinterInfo5 *r,
3656 r->printername = talloc_strdup(mem_ctx, info2->printername);
3657 W_ERROR_HAVE_NO_MEMORY(r->printername);
3658 r->portname = talloc_strdup(mem_ctx, info2->portname);
3659 W_ERROR_HAVE_NO_MEMORY(r->portname);
3661 r->attributes = info2->attributes;
3663 /* these two are not used by NT+ according to MSDN */
3664 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
3665 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
3670 /********************************************************************
3671 * construct_printer_info_6
3672 * fill a spoolss_PrinterInfo6 struct
3673 ********************************************************************/
3675 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
3676 const struct spoolss_PrinterInfo2 *info2,
3677 struct spoolss_PrinterInfo6 *r,
3681 print_status_struct status;
3683 count = print_queue_length(snum, &status);
3685 r->status = nt_printq_status(status.status);
3690 /********************************************************************
3691 * construct_printer_info7
3692 * fill a spoolss_PrinterInfo7 struct
3693 ********************************************************************/
3695 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
3696 Printer_entry *print_hnd,
3697 struct spoolss_PrinterInfo7 *r,
3700 struct auth_serversupplied_info *server_info;
3704 status = make_server_info_system(mem_ctx, &server_info);
3705 if (!NT_STATUS_IS_OK(status)) {
3706 DEBUG(0, ("construct_printer_info7: "
3707 "Could not create system server_info\n"));
3711 if (is_printer_published(mem_ctx, server_info, print_hnd->servername,
3712 lp_servicename(snum), &guid, NULL)) {
3713 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
3714 r->action = DSPRINT_PUBLISH;
3716 r->guid = talloc_strdup(mem_ctx, "");
3717 r->action = DSPRINT_UNPUBLISH;
3719 W_ERROR_HAVE_NO_MEMORY(r->guid);
3721 TALLOC_FREE(server_info);
3725 /********************************************************************
3726 * construct_printer_info8
3727 * fill a spoolss_PrinterInfo8 struct
3728 ********************************************************************/
3730 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
3731 const struct spoolss_PrinterInfo2 *info2,
3732 struct spoolss_DeviceModeInfo *r,
3735 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3737 DEBUG(8,("Returning NULL Devicemode!\n"));
3744 /********************************************************************
3745 ********************************************************************/
3747 static bool snum_is_shared_printer(int snum)
3749 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
3752 /********************************************************************
3753 Spoolss_enumprinters.
3754 ********************************************************************/
3756 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
3757 struct auth_serversupplied_info *server_info,
3760 union spoolss_PrinterInfo **info_p,
3764 int n_services = lp_numservices();
3765 union spoolss_PrinterInfo *info = NULL;
3767 WERROR result = WERR_OK;
3772 for (snum = 0; snum < n_services; snum++) {
3774 const char *printer;
3775 struct spoolss_PrinterInfo2 *info2;
3777 if (!snum_is_shared_printer(snum)) {
3781 printer = lp_const_servicename(snum);
3783 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
3786 result = winreg_create_printer(mem_ctx,
3790 if (!W_ERROR_IS_OK(result)) {
3794 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
3795 union spoolss_PrinterInfo,
3798 result = WERR_NOMEM;
3802 result = winreg_get_printer(mem_ctx, server_info,
3803 NULL, printer, &info2);
3804 if (!W_ERROR_IS_OK(result)) {
3810 result = construct_printer_info0(info, server_info, info2,
3811 &info[count].info0, snum);
3814 result = construct_printer_info1(info, info2, flags,
3815 &info[count].info1, snum);
3818 result = construct_printer_info2(info, info2,
3819 &info[count].info2, snum);
3822 result = construct_printer_info4(info, info2,
3823 &info[count].info4, snum);
3826 result = construct_printer_info5(info, info2,
3827 &info[count].info5, snum);
3831 result = WERR_UNKNOWN_LEVEL;
3835 if (!W_ERROR_IS_OK(result)) {
3846 if (!W_ERROR_IS_OK(result)) {
3856 /********************************************************************
3857 * handle enumeration of printers at level 0
3858 ********************************************************************/
3860 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
3861 struct auth_serversupplied_info *server_info,
3863 const char *servername,
3864 union spoolss_PrinterInfo **info,
3867 DEBUG(4,("enum_all_printers_info_0\n"));
3869 return enum_all_printers_info_level(mem_ctx, server_info, 0, flags, info, count);
3873 /********************************************************************
3874 ********************************************************************/
3876 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
3877 struct auth_serversupplied_info *server_info,
3879 union spoolss_PrinterInfo **info,
3882 DEBUG(4,("enum_all_printers_info_1\n"));
3884 return enum_all_printers_info_level(mem_ctx, server_info, 1, flags, info, count);
3887 /********************************************************************
3888 enum_all_printers_info_1_local.
3889 *********************************************************************/
3891 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
3892 struct auth_serversupplied_info *server_info,
3893 union spoolss_PrinterInfo **info,
3896 DEBUG(4,("enum_all_printers_info_1_local\n"));
3898 return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_ICON8, info, count);
3901 /********************************************************************
3902 enum_all_printers_info_1_name.
3903 *********************************************************************/
3905 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
3906 struct auth_serversupplied_info *server_info,
3908 union spoolss_PrinterInfo **info,
3911 const char *s = name;
3913 DEBUG(4,("enum_all_printers_info_1_name\n"));
3915 if ((name[0] == '\\') && (name[1] == '\\')) {
3919 if (!is_myname_or_ipaddr(s)) {
3920 return WERR_INVALID_NAME;
3923 return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_ICON8, info, count);
3926 /********************************************************************
3927 enum_all_printers_info_1_network.
3928 *********************************************************************/
3930 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
3931 struct auth_serversupplied_info *server_info,
3933 union spoolss_PrinterInfo **info,
3936 const char *s = name;
3938 DEBUG(4,("enum_all_printers_info_1_network\n"));
3940 /* If we respond to a enum_printers level 1 on our name with flags
3941 set to PRINTER_ENUM_REMOTE with a list of printers then these
3942 printers incorrectly appear in the APW browse list.
3943 Specifically the printers for the server appear at the workgroup
3944 level where all the other servers in the domain are
3945 listed. Windows responds to this call with a
3946 WERR_CAN_NOT_COMPLETE so we should do the same. */
3948 if (name[0] == '\\' && name[1] == '\\') {
3952 if (is_myname_or_ipaddr(s)) {
3953 return WERR_CAN_NOT_COMPLETE;
3956 return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_NAME, info, count);
3959 /********************************************************************
3960 * api_spoolss_enumprinters
3962 * called from api_spoolss_enumprinters (see this to understand)
3963 ********************************************************************/
3965 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
3966 struct auth_serversupplied_info *server_info,
3967 union spoolss_PrinterInfo **info,
3970 DEBUG(4,("enum_all_printers_info_2\n"));
3972 return enum_all_printers_info_level(mem_ctx, server_info, 2, 0, info, count);
3975 /********************************************************************
3976 * handle enumeration of printers at level 1
3977 ********************************************************************/
3979 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
3980 struct auth_serversupplied_info *server_info,
3983 union spoolss_PrinterInfo **info,
3986 /* Not all the flags are equals */
3988 if (flags & PRINTER_ENUM_LOCAL) {
3989 return enum_all_printers_info_1_local(mem_ctx, server_info, info, count);
3992 if (flags & PRINTER_ENUM_NAME) {
3993 return enum_all_printers_info_1_name(mem_ctx, server_info, name, info, count);
3996 if (flags & PRINTER_ENUM_NETWORK) {
3997 return enum_all_printers_info_1_network(mem_ctx, server_info, name, info, count);
4000 return WERR_OK; /* NT4sp5 does that */
4003 /********************************************************************
4004 * handle enumeration of printers at level 2
4005 ********************************************************************/
4007 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4008 struct auth_serversupplied_info *server_info,
4010 const char *servername,
4011 union spoolss_PrinterInfo **info,
4014 if (flags & PRINTER_ENUM_LOCAL) {
4015 return enum_all_printers_info_2(mem_ctx, server_info, info, count);
4018 if (flags & PRINTER_ENUM_NAME) {
4019 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4020 return WERR_INVALID_NAME;
4023 return enum_all_printers_info_2(mem_ctx, server_info, info, count);
4026 if (flags & PRINTER_ENUM_REMOTE) {
4027 return WERR_UNKNOWN_LEVEL;
4033 /********************************************************************
4034 * handle enumeration of printers at level 4
4035 ********************************************************************/
4037 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4038 struct auth_serversupplied_info *server_info,
4040 const char *servername,
4041 union spoolss_PrinterInfo **info,
4044 DEBUG(4,("enum_all_printers_info_4\n"));
4046 return enum_all_printers_info_level(mem_ctx, server_info, 4, flags, info, count);
4050 /********************************************************************
4051 * handle enumeration of printers at level 5
4052 ********************************************************************/
4054 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4055 struct auth_serversupplied_info *server_info,
4057 const char *servername,
4058 union spoolss_PrinterInfo **info,
4061 DEBUG(4,("enum_all_printers_info_5\n"));
4063 return enum_all_printers_info_level(mem_ctx, server_info, 5, flags, info, count);
4066 /****************************************************************
4067 _spoolss_EnumPrinters
4068 ****************************************************************/
4070 WERROR _spoolss_EnumPrinters(pipes_struct *p,
4071 struct spoolss_EnumPrinters *r)
4073 const char *name = NULL;
4076 /* that's an [in out] buffer */
4078 if (!r->in.buffer && (r->in.offered != 0)) {
4079 return WERR_INVALID_PARAM;
4082 DEBUG(4,("_spoolss_EnumPrinters\n"));
4086 *r->out.info = NULL;
4090 * flags==PRINTER_ENUM_NAME
4091 * if name=="" then enumerates all printers
4092 * if name!="" then enumerate the printer
4093 * flags==PRINTER_ENUM_REMOTE
4094 * name is NULL, enumerate printers
4095 * Level 2: name!="" enumerates printers, name can't be NULL
4096 * Level 3: doesn't exist
4097 * Level 4: does a local registry lookup
4098 * Level 5: same as Level 2
4102 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4103 W_ERROR_HAVE_NO_MEMORY(name);
4106 switch (r->in.level) {
4108 result = enumprinters_level0(p->mem_ctx, p->server_info,
4110 r->out.info, r->out.count);
4113 result = enumprinters_level1(p->mem_ctx, p->server_info,
4115 r->out.info, r->out.count);
4118 result = enumprinters_level2(p->mem_ctx, p->server_info,
4120 r->out.info, r->out.count);
4123 result = enumprinters_level4(p->mem_ctx, p->server_info,
4125 r->out.info, r->out.count);
4128 result = enumprinters_level5(p->mem_ctx, p->server_info,
4130 r->out.info, r->out.count);
4133 return WERR_UNKNOWN_LEVEL;
4136 if (!W_ERROR_IS_OK(result)) {
4140 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4141 spoolss_EnumPrinters,
4142 *r->out.info, r->in.level,
4144 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4145 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4147 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4150 /****************************************************************
4152 ****************************************************************/
4154 WERROR _spoolss_GetPrinter(pipes_struct *p,
4155 struct spoolss_GetPrinter *r)
4157 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4158 struct spoolss_PrinterInfo2 *info2 = NULL;
4159 WERROR result = WERR_OK;
4160 const char *servername = NULL;
4163 /* that's an [in out] buffer */
4165 if (!r->in.buffer && (r->in.offered != 0)) {
4166 return WERR_INVALID_PARAM;
4171 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4175 if (Printer != NULL || Printer->servername != NULL) {
4176 servername = Printer->servername;
4179 result = winreg_get_printer(p->mem_ctx,
4182 lp_const_servicename(snum),
4184 if (!W_ERROR_IS_OK(result)) {
4188 switch (r->in.level) {
4190 result = construct_printer_info0(p->mem_ctx, p->server_info,
4192 &r->out.info->info0, snum);
4195 result = construct_printer_info1(p->mem_ctx, info2,
4197 &r->out.info->info1, snum);
4200 result = construct_printer_info2(p->mem_ctx, info2,
4201 &r->out.info->info2, snum);
4204 result = construct_printer_info3(p->mem_ctx, info2,
4205 &r->out.info->info3, snum);
4208 result = construct_printer_info4(p->mem_ctx, info2,
4209 &r->out.info->info4, snum);
4212 result = construct_printer_info5(p->mem_ctx, info2,
4213 &r->out.info->info5, snum);
4216 result = construct_printer_info6(p->mem_ctx, info2,
4217 &r->out.info->info6, snum);
4220 result = construct_printer_info7(p->mem_ctx, Printer,
4221 &r->out.info->info7, snum);
4224 result = construct_printer_info8(p->mem_ctx, info2,
4225 &r->out.info->info8, snum);
4228 result = WERR_UNKNOWN_LEVEL;
4232 if (!W_ERROR_IS_OK(result)) {
4233 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4234 r->in.level, win_errstr(result)));
4235 TALLOC_FREE(r->out.info);
4239 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4240 r->out.info, r->in.level);
4241 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4243 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4246 /********************************************************************
4247 ********************************************************************/
4249 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4251 if (in && strlen(in)) { \
4252 out = talloc_strdup(mem_ctx, in); \
4253 W_ERROR_HAVE_NO_MEMORY(out); \
4259 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4261 if (in && strlen(in)) { \
4262 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4264 out = talloc_strdup(mem_ctx, ""); \
4266 W_ERROR_HAVE_NO_MEMORY(out); \
4269 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4270 const char **string_array,
4271 const char ***presult,
4272 const char *cservername,
4276 int i, num_strings = 0;
4277 const char **array = NULL;
4279 if (string_array == NULL) {
4280 return WERR_INVALID_PARAMETER;;
4283 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4284 const char *str = NULL;
4286 if (cservername == NULL || arch == NULL) {
4287 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4289 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4292 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4299 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4300 &array, &num_strings);
4310 /********************************************************************
4311 * fill a spoolss_DriverInfo1 struct
4312 ********************************************************************/
4314 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4315 struct spoolss_DriverInfo1 *r,
4316 const struct spoolss_DriverInfo8 *driver,
4317 const char *servername)
4319 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4320 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4325 /********************************************************************
4326 * fill a spoolss_DriverInfo2 struct
4327 ********************************************************************/
4329 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4330 struct spoolss_DriverInfo2 *r,
4331 const struct spoolss_DriverInfo8 *driver,
4332 const char *servername)
4335 const char *cservername = canon_servername(servername);
4337 r->version = driver->version;
4339 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4340 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4341 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4342 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4344 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4345 driver->architecture,
4347 driver->driver_path,
4350 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4351 driver->architecture,
4356 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4357 driver->architecture,
4359 driver->config_file,
4365 /********************************************************************
4366 * fill a spoolss_DriverInfo3 struct
4367 ********************************************************************/
4369 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4370 struct spoolss_DriverInfo3 *r,
4371 const struct spoolss_DriverInfo8 *driver,
4372 const char *servername)
4374 const char *cservername = canon_servername(servername);
4376 r->version = driver->version;
4378 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4379 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4380 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4381 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4383 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4384 driver->architecture,
4386 driver->driver_path,
4389 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4390 driver->architecture,
4395 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4396 driver->architecture,
4398 driver->config_file,
4401 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4402 driver->architecture,
4407 FILL_DRIVER_STRING(mem_ctx,
4408 driver->monitor_name,
4411 FILL_DRIVER_STRING(mem_ctx,
4412 driver->default_datatype,
4413 r->default_datatype);
4415 return string_array_from_driver_info(mem_ctx,
4416 driver->dependent_files,
4417 &r->dependent_files,
4419 driver->architecture,
4423 /********************************************************************
4424 * fill a spoolss_DriverInfo4 struct
4425 ********************************************************************/
4427 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4428 struct spoolss_DriverInfo4 *r,
4429 const struct spoolss_DriverInfo8 *driver,
4430 const char *servername)
4432 const char *cservername = canon_servername(servername);
4435 r->version = driver->version;
4437 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4438 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4439 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4440 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4442 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4443 driver->architecture,
4445 driver->driver_path,
4448 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4449 driver->architecture,
4454 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4455 driver->architecture,
4457 driver->config_file,
4460 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4461 driver->architecture,
4466 result = string_array_from_driver_info(mem_ctx,
4467 driver->dependent_files,
4468 &r->dependent_files,
4470 driver->architecture,
4472 if (!W_ERROR_IS_OK(result)) {
4476 FILL_DRIVER_STRING(mem_ctx,
4477 driver->monitor_name,
4480 FILL_DRIVER_STRING(mem_ctx,
4481 driver->default_datatype,
4482 r->default_datatype);
4485 result = string_array_from_driver_info(mem_ctx,
4486 driver->previous_names,
4493 /********************************************************************
4494 * fill a spoolss_DriverInfo5 struct
4495 ********************************************************************/
4497 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4498 struct spoolss_DriverInfo5 *r,
4499 const struct spoolss_DriverInfo8 *driver,
4500 const char *servername)
4502 const char *cservername = canon_servername(servername);
4504 r->version = driver->version;
4506 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4507 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4508 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4509 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4511 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4512 driver->architecture,
4514 driver->driver_path,
4517 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4518 driver->architecture,
4523 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4524 driver->architecture,
4526 driver->config_file,
4529 r->driver_attributes = 0;
4530 r->config_version = 0;
4531 r->driver_version = 0;
4535 /********************************************************************
4536 * fill a spoolss_DriverInfo6 struct
4537 ********************************************************************/
4539 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4540 struct spoolss_DriverInfo6 *r,
4541 const struct spoolss_DriverInfo8 *driver,
4542 const char *servername)
4544 const char *cservername = canon_servername(servername);
4547 r->version = driver->version;
4549 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4550 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4551 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4552 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4554 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4555 driver->architecture,
4557 driver->driver_path,
4560 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4561 driver->architecture,
4566 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4567 driver->architecture,
4569 driver->config_file,
4572 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4573 driver->architecture,
4578 FILL_DRIVER_STRING(mem_ctx,
4579 driver->monitor_name,
4582 FILL_DRIVER_STRING(mem_ctx,
4583 driver->default_datatype,
4584 r->default_datatype);
4586 result = string_array_from_driver_info(mem_ctx,
4587 driver->dependent_files,
4588 &r->dependent_files,
4590 driver->architecture,
4592 if (!W_ERROR_IS_OK(result)) {
4596 result = string_array_from_driver_info(mem_ctx,
4597 driver->previous_names,
4600 if (!W_ERROR_IS_OK(result)) {
4604 r->driver_date = driver->driver_date;
4605 r->driver_version = driver->driver_version;
4607 FILL_DRIVER_STRING(mem_ctx,
4608 driver->manufacturer_name,
4609 r->manufacturer_name);
4610 FILL_DRIVER_STRING(mem_ctx,
4611 driver->manufacturer_url,
4612 r->manufacturer_url);
4613 FILL_DRIVER_STRING(mem_ctx,
4614 driver->hardware_id,
4616 FILL_DRIVER_STRING(mem_ctx,
4623 /********************************************************************
4624 * fill a spoolss_DriverInfo8 struct
4625 ********************************************************************/
4627 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
4628 struct spoolss_DriverInfo8 *r,
4629 const struct spoolss_DriverInfo8 *driver,
4630 const char *servername)
4632 const char *cservername = canon_servername(servername);
4635 r->version = driver->version;
4637 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4638 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4639 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4640 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4642 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4643 driver->architecture,
4645 driver->driver_path,
4648 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4649 driver->architecture,
4654 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4655 driver->architecture,
4657 driver->config_file,
4660 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4661 driver->architecture,
4666 FILL_DRIVER_STRING(mem_ctx,
4667 driver->monitor_name,
4670 FILL_DRIVER_STRING(mem_ctx,
4671 driver->default_datatype,
4672 r->default_datatype);
4674 result = string_array_from_driver_info(mem_ctx,
4675 driver->dependent_files,
4676 &r->dependent_files,
4678 driver->architecture,
4680 if (!W_ERROR_IS_OK(result)) {
4684 result = string_array_from_driver_info(mem_ctx,
4685 driver->previous_names,
4688 if (!W_ERROR_IS_OK(result)) {
4692 r->driver_date = driver->driver_date;
4693 r->driver_version = driver->driver_version;
4695 FILL_DRIVER_STRING(mem_ctx,
4696 driver->manufacturer_name,
4697 r->manufacturer_name);
4698 FILL_DRIVER_STRING(mem_ctx,
4699 driver->manufacturer_url,
4700 r->manufacturer_url);
4701 FILL_DRIVER_STRING(mem_ctx,
4702 driver->hardware_id,
4704 FILL_DRIVER_STRING(mem_ctx,
4708 FILL_DRIVER_STRING(mem_ctx,
4709 driver->print_processor,
4710 r->print_processor);
4711 FILL_DRIVER_STRING(mem_ctx,
4712 driver->vendor_setup,
4715 result = string_array_from_driver_info(mem_ctx,
4716 driver->color_profiles,
4719 if (!W_ERROR_IS_OK(result)) {
4723 FILL_DRIVER_STRING(mem_ctx,
4727 r->printer_driver_attributes = driver->printer_driver_attributes;
4729 result = string_array_from_driver_info(mem_ctx,
4730 driver->core_driver_dependencies,
4731 &r->core_driver_dependencies,
4733 if (!W_ERROR_IS_OK(result)) {
4737 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
4738 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
4743 #if 0 /* disabled until marshalling issues are resolved - gd */
4744 /********************************************************************
4745 ********************************************************************/
4747 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
4748 struct spoolss_DriverFileInfo *r,
4749 const char *cservername,
4750 const char *file_name,
4751 enum spoolss_DriverFileType file_type,
4752 uint32_t file_version)
4754 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
4755 cservername, file_name);
4756 W_ERROR_HAVE_NO_MEMORY(r->file_name);
4757 r->file_type = file_type;
4758 r->file_version = file_version;
4763 /********************************************************************
4764 ********************************************************************/
4766 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
4767 const struct spoolss_DriverInfo8 *driver,
4768 const char *cservername,
4769 struct spoolss_DriverFileInfo **info_p,
4772 struct spoolss_DriverFileInfo *info = NULL;
4780 if (strlen(driver->driver_path)) {
4781 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4782 struct spoolss_DriverFileInfo,
4784 W_ERROR_HAVE_NO_MEMORY(info);
4785 result = fill_spoolss_DriverFileInfo(info,
4788 driver->driver_path,
4789 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
4791 W_ERROR_NOT_OK_RETURN(result);
4795 if (strlen(driver->config_file)) {
4796 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4797 struct spoolss_DriverFileInfo,
4799 W_ERROR_HAVE_NO_MEMORY(info);
4800 result = fill_spoolss_DriverFileInfo(info,
4803 driver->config_file,
4804 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
4806 W_ERROR_NOT_OK_RETURN(result);
4810 if (strlen(driver->data_file)) {
4811 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4812 struct spoolss_DriverFileInfo,
4814 W_ERROR_HAVE_NO_MEMORY(info);
4815 result = fill_spoolss_DriverFileInfo(info,
4819 SPOOLSS_DRIVER_FILE_TYPE_DATA,
4821 W_ERROR_NOT_OK_RETURN(result);
4825 if (strlen(driver->help_file)) {
4826 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4827 struct spoolss_DriverFileInfo,
4829 W_ERROR_HAVE_NO_MEMORY(info);
4830 result = fill_spoolss_DriverFileInfo(info,
4834 SPOOLSS_DRIVER_FILE_TYPE_HELP,
4836 W_ERROR_NOT_OK_RETURN(result);
4840 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
4841 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4842 struct spoolss_DriverFileInfo,
4844 W_ERROR_HAVE_NO_MEMORY(info);
4845 result = fill_spoolss_DriverFileInfo(info,
4848 driver->dependent_files[i],
4849 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
4851 W_ERROR_NOT_OK_RETURN(result);
4861 /********************************************************************
4862 * fill a spoolss_DriverInfo101 struct
4863 ********************************************************************/
4865 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
4866 struct spoolss_DriverInfo101 *r,
4867 const struct spoolss_DriverInfo8 *driver,
4868 const char *servername)
4870 const char *cservername = canon_servername(servername);
4873 r->version = driver->version;
4875 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4876 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4877 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4878 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4880 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
4884 if (!W_ERROR_IS_OK(result)) {
4888 FILL_DRIVER_STRING(mem_ctx,
4889 driver->monitor_name,
4892 FILL_DRIVER_STRING(mem_ctx,
4893 driver->default_datatype,
4894 r->default_datatype);
4896 result = string_array_from_driver_info(mem_ctx,
4897 driver->previous_names,
4900 if (!W_ERROR_IS_OK(result)) {
4904 r->driver_date = driver->driver_date;
4905 r->driver_version = driver->driver_version;
4907 FILL_DRIVER_STRING(mem_ctx,
4908 driver->manufacturer_name,
4909 r->manufacturer_name);
4910 FILL_DRIVER_STRING(mem_ctx,
4911 driver->manufacturer_url,
4912 r->manufacturer_url);
4913 FILL_DRIVER_STRING(mem_ctx,
4914 driver->hardware_id,
4916 FILL_DRIVER_STRING(mem_ctx,
4923 /********************************************************************
4924 ********************************************************************/
4926 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
4927 struct auth_serversupplied_info *server_info,
4929 union spoolss_DriverInfo *r,
4931 const char *servername,
4932 const char *architecture,
4935 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
4936 struct spoolss_DriverInfo8 *driver;
4939 result = winreg_get_printer(mem_ctx,
4942 lp_const_servicename(snum),
4945 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
4946 win_errstr(result)));
4948 if (!W_ERROR_IS_OK(result)) {
4949 return WERR_INVALID_PRINTER_NAME;
4952 result = winreg_get_driver(mem_ctx, server_info, architecture,
4953 pinfo2->drivername, version, &driver);
4955 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
4956 win_errstr(result)));
4958 if (!W_ERROR_IS_OK(result)) {
4960 * Is this a W2k client ?
4964 talloc_free(pinfo2);
4965 return WERR_UNKNOWN_PRINTER_DRIVER;
4968 /* Yes - try again with a WinNT driver. */
4970 result = winreg_get_driver(mem_ctx, server_info, architecture,
4973 DEBUG(8,("construct_printer_driver_level: status: %s\n",
4974 win_errstr(result)));
4975 if (!W_ERROR_IS_OK(result)) {
4976 talloc_free(pinfo2);
4977 return WERR_UNKNOWN_PRINTER_DRIVER;
4983 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
4986 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
4989 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
4992 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
4995 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
4998 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5001 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5003 #if 0 /* disabled until marshalling issues are resolved - gd */
5005 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5009 result = WERR_UNKNOWN_LEVEL;
5013 talloc_free(pinfo2);
5014 talloc_free(driver);
5019 /****************************************************************
5020 _spoolss_GetPrinterDriver2
5021 ****************************************************************/
5023 WERROR _spoolss_GetPrinterDriver2(pipes_struct *p,
5024 struct spoolss_GetPrinterDriver2 *r)
5026 Printer_entry *printer;
5031 /* that's an [in out] buffer */
5033 if (!r->in.buffer && (r->in.offered != 0)) {
5034 return WERR_INVALID_PARAM;
5037 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5039 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5040 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5041 return WERR_INVALID_PRINTER_NAME;
5045 *r->out.server_major_version = 0;
5046 *r->out.server_minor_version = 0;
5048 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5052 result = construct_printer_driver_info_level(p->mem_ctx, p->server_info,
5053 r->in.level, r->out.info,
5054 snum, printer->servername,
5056 r->in.client_major_version);
5057 if (!W_ERROR_IS_OK(result)) {
5058 TALLOC_FREE(r->out.info);
5062 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5063 r->out.info, r->in.level);
5064 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5066 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5070 /****************************************************************
5071 _spoolss_StartPagePrinter
5072 ****************************************************************/
5074 WERROR _spoolss_StartPagePrinter(pipes_struct *p,
5075 struct spoolss_StartPagePrinter *r)
5077 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5080 DEBUG(3,("_spoolss_StartPagePrinter: "
5081 "Error in startpageprinter printer handle\n"));
5085 Printer->page_started = true;
5089 /****************************************************************
5090 _spoolss_EndPagePrinter
5091 ****************************************************************/
5093 WERROR _spoolss_EndPagePrinter(pipes_struct *p,
5094 struct spoolss_EndPagePrinter *r)
5098 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5101 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5102 OUR_HANDLE(r->in.handle)));
5106 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5109 Printer->page_started = false;
5110 print_job_endpage(snum, Printer->jobid);
5115 /****************************************************************
5116 _spoolss_StartDocPrinter
5117 ****************************************************************/
5119 WERROR _spoolss_StartDocPrinter(pipes_struct *p,
5120 struct spoolss_StartDocPrinter *r)
5122 struct spoolss_DocumentInfo1 *info_1;
5124 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5128 DEBUG(2,("_spoolss_StartDocPrinter: "
5129 "Invalid handle (%s:%u:%u)\n",
5130 OUR_HANDLE(r->in.handle)));
5134 if (Printer->jobid) {
5135 DEBUG(2, ("_spoolss_StartDocPrinter: "
5136 "StartDocPrinter called twice! "
5137 "(existing jobid = %d)\n", Printer->jobid));
5138 return WERR_INVALID_HANDLE;
5141 if (r->in.level != 1) {
5142 return WERR_UNKNOWN_LEVEL;
5145 info_1 = r->in.info.info1;
5148 * a nice thing with NT is it doesn't listen to what you tell it.
5149 * when asked to send _only_ RAW datas, it tries to send datas
5152 * So I add checks like in NT Server ...
5155 if (info_1->datatype) {
5156 if (strcmp(info_1->datatype, "RAW") != 0) {
5158 return WERR_INVALID_DATATYPE;
5162 /* get the share number of the printer */
5163 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5167 werr = print_job_start(p->server_info, snum,
5168 info_1->document_name, info_1->output_file,
5169 Printer->devmode, &Printer->jobid);
5171 /* An error occured in print_job_start() so return an appropriate
5174 if (!W_ERROR_IS_OK(werr)) {
5178 Printer->document_started = true;
5179 *r->out.job_id = Printer->jobid;
5184 /****************************************************************
5185 _spoolss_EndDocPrinter
5186 ****************************************************************/
5188 WERROR _spoolss_EndDocPrinter(pipes_struct *p,
5189 struct spoolss_EndDocPrinter *r)
5191 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5196 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5197 OUR_HANDLE(r->in.handle)));
5201 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5205 Printer->document_started = false;
5206 status = print_job_end(snum, Printer->jobid, NORMAL_CLOSE);
5207 if (!NT_STATUS_IS_OK(status)) {
5208 DEBUG(2, ("_spoolss_EndDocPrinter: "
5209 "print_job_end failed [%s]\n",
5210 nt_errstr(status)));
5214 return ntstatus_to_werror(status);
5217 /****************************************************************
5218 _spoolss_WritePrinter
5219 ****************************************************************/
5221 WERROR _spoolss_WritePrinter(pipes_struct *p,
5222 struct spoolss_WritePrinter *r)
5224 ssize_t buffer_written;
5226 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5229 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5230 OUR_HANDLE(r->in.handle)));
5231 *r->out.num_written = r->in._data_size;
5235 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5238 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5239 buffer_written = print_job_write(snum, Printer->jobid,
5240 (const char *)r->in.data.data,
5242 (size_t)r->in._data_size);
5243 if (buffer_written == (ssize_t)-1) {
5244 *r->out.num_written = 0;
5245 if (errno == ENOSPC)
5246 return WERR_NO_SPOOL_SPACE;
5248 return WERR_ACCESS_DENIED;
5251 *r->out.num_written = r->in._data_size;
5256 /********************************************************************
5257 * api_spoolss_getprinter
5258 * called from the spoolss dispatcher
5260 ********************************************************************/
5262 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5266 WERROR errcode = WERR_BADFUNC;
5267 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5270 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5271 OUR_HANDLE(handle)));
5275 if (!get_printer_snum(p, handle, &snum, NULL))
5279 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5280 errcode = print_queue_pause(p->server_info, snum);
5282 case SPOOLSS_PRINTER_CONTROL_RESUME:
5283 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5284 errcode = print_queue_resume(p->server_info, snum);
5286 case SPOOLSS_PRINTER_CONTROL_PURGE:
5287 errcode = print_queue_purge(p->server_info, snum);
5290 return WERR_UNKNOWN_LEVEL;
5297 /****************************************************************
5298 _spoolss_AbortPrinter
5299 * From MSDN: "Deletes printer's spool file if printer is configured
5301 ****************************************************************/
5303 WERROR _spoolss_AbortPrinter(pipes_struct *p,
5304 struct spoolss_AbortPrinter *r)
5306 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5308 WERROR errcode = WERR_OK;
5311 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5312 OUR_HANDLE(r->in.handle)));
5316 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5319 if (!Printer->document_started) {
5320 return WERR_SPL_NO_STARTDOC;
5323 errcode = print_job_delete(p->server_info, snum, Printer->jobid);
5328 /********************************************************************
5329 * called by spoolss_api_setprinter
5330 * when updating a printer description
5331 ********************************************************************/
5333 static WERROR update_printer_sec(struct policy_handle *handle,
5334 pipes_struct *p, struct sec_desc_buf *secdesc_ctr)
5336 struct spoolss_security_descriptor *new_secdesc = NULL;
5337 struct spoolss_security_descriptor *old_secdesc = NULL;
5338 const char *printer;
5342 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5344 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5345 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5346 OUR_HANDLE(handle)));
5348 result = WERR_BADFID;
5352 if (secdesc_ctr == NULL) {
5353 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5354 result = WERR_INVALID_PARAM;
5357 printer = lp_const_servicename(snum);
5359 /* Check the user has permissions to change the security
5360 descriptor. By experimentation with two NT machines, the user
5361 requires Full Access to the printer to change security
5364 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5365 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5366 result = WERR_ACCESS_DENIED;
5370 /* NT seems to like setting the security descriptor even though
5371 nothing may have actually changed. */
5372 result = winreg_get_printer_secdesc(p->mem_ctx,
5376 if (!W_ERROR_IS_OK(result)) {
5377 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5378 result = WERR_BADFID;
5382 if (DEBUGLEVEL >= 10) {
5383 struct security_acl *the_acl;
5386 the_acl = secdesc_ctr->sd->dacl;
5387 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5388 printer, the_acl->num_aces));
5390 for (i = 0; i < the_acl->num_aces; i++) {
5391 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5392 &the_acl->aces[i].trustee),
5393 the_acl->aces[i].access_mask));
5396 the_acl = secdesc_ctr->sd->dacl;
5399 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5400 printer, the_acl->num_aces));
5402 for (i = 0; i < the_acl->num_aces; i++) {
5403 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5404 &the_acl->aces[i].trustee),
5405 the_acl->aces[i].access_mask));
5408 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5412 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
5413 if (new_secdesc == NULL) {
5414 result = WERR_NOMEM;
5418 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
5423 result = winreg_set_printer_secdesc(p->mem_ctx,
5432 /********************************************************************
5433 Canonicalize printer info from a client
5434 ********************************************************************/
5436 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
5437 struct spoolss_SetPrinterInfo2 *info2,
5440 fstring printername;
5443 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5444 "portname=%s drivername=%s comment=%s location=%s\n",
5445 info2->servername, info2->printername, info2->sharename,
5446 info2->portname, info2->drivername, info2->comment,
5449 /* we force some elements to "correct" values */
5450 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
5451 if (info2->servername == NULL) {
5454 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
5455 if (info2->sharename == NULL) {
5459 /* check to see if we allow printername != sharename */
5460 if (lp_force_printername(snum)) {
5461 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5462 global_myname(), info2->sharename);
5464 /* make sure printername is in \\server\printername format */
5465 fstrcpy(printername, info2->printername);
5467 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5468 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5472 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5473 global_myname(), p);
5475 if (info2->printername == NULL) {
5479 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5480 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5485 /****************************************************************************
5486 ****************************************************************************/
5488 static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri)
5490 char *cmd = lp_addport_cmd();
5491 char *command = NULL;
5493 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5494 bool is_print_op = false;
5497 return WERR_ACCESS_DENIED;
5500 command = talloc_asprintf(ctx,
5501 "%s \"%s\" \"%s\"", cmd, portname, uri );
5507 is_print_op = user_has_privileges( token, &se_printop );
5509 DEBUG(10,("Running [%s]\n", command));
5511 /********* BEGIN SePrintOperatorPrivilege **********/
5516 ret = smbrun(command, NULL);
5521 /********* END SePrintOperatorPrivilege **********/
5523 DEBUGADD(10,("returned [%d]\n", ret));
5525 TALLOC_FREE(command);
5528 return WERR_ACCESS_DENIED;
5534 /****************************************************************************
5535 ****************************************************************************/
5537 bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
5538 struct spoolss_SetPrinterInfo2 *info2)
5540 char *cmd = lp_addprinter_cmd();
5542 char *command = NULL;
5546 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5547 bool is_print_op = false;
5548 char *remote_machine = talloc_strdup(ctx, "%m");
5550 if (!remote_machine) {
5553 remote_machine = talloc_sub_basic(ctx,
5554 current_user_info.smb_name,
5555 current_user_info.domain,
5557 if (!remote_machine) {
5561 command = talloc_asprintf(ctx,
5562 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5563 cmd, info2->printername, info2->sharename,
5564 info2->portname, info2->drivername,
5565 info2->location, info2->comment, remote_machine);
5571 is_print_op = user_has_privileges( token, &se_printop );
5573 DEBUG(10,("Running [%s]\n", command));
5575 /********* BEGIN SePrintOperatorPrivilege **********/
5580 if ( (ret = smbrun(command, &fd)) == 0 ) {
5581 /* Tell everyone we updated smb.conf. */
5582 message_send_all(smbd_messaging_context(),
5583 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5589 /********* END SePrintOperatorPrivilege **********/
5591 DEBUGADD(10,("returned [%d]\n", ret));
5593 TALLOC_FREE(command);
5594 TALLOC_FREE(remote_machine);
5602 /* reload our services immediately */
5604 reload_services(false);
5608 /* Get lines and convert them back to dos-codepage */
5609 qlines = fd_lines_load(fd, &numlines, 0, NULL);
5610 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
5613 /* Set the portname to what the script says the portname should be. */
5614 /* but don't require anything to be return from the script exit a good error code */
5617 /* Set the portname to what the script says the portname should be. */
5618 info2->portname = talloc_strdup(ctx, qlines[0]);
5619 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
5622 TALLOC_FREE(qlines);
5626 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
5627 struct auth_serversupplied_info *server_info,
5629 struct spoolss_SetPrinterInfo2 *printer,
5630 struct spoolss_PrinterInfo2 *old_printer)
5632 bool force_update = (old_printer == NULL);
5633 const char *dnsdomname;
5634 const char *longname;
5635 const char *uncname;
5636 const char *spooling;
5638 WERROR result = WERR_OK;
5640 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
5641 push_reg_sz(mem_ctx, &buffer, printer->drivername);
5642 winreg_set_printer_dataex(mem_ctx,
5645 SPOOL_DSSPOOLER_KEY,
5646 SPOOL_REG_DRIVERNAME,
5651 if (!force_update) {
5652 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
5653 printer->drivername));
5655 notify_printer_driver(snum, printer->drivername);
5659 if (force_update || !strequal(printer->comment, old_printer->comment)) {
5660 push_reg_sz(mem_ctx, &buffer, printer->comment);
5661 winreg_set_printer_dataex(mem_ctx,
5664 SPOOL_DSSPOOLER_KEY,
5665 SPOOL_REG_DESCRIPTION,
5670 if (!force_update) {
5671 notify_printer_comment(snum, printer->comment);
5675 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
5676 push_reg_sz(mem_ctx, &buffer, printer->sharename);
5677 winreg_set_printer_dataex(mem_ctx,
5680 SPOOL_DSSPOOLER_KEY,
5681 SPOOL_REG_PRINTSHARENAME,
5686 if (!force_update) {
5687 notify_printer_sharename(snum, printer->sharename);
5691 if (force_update || !strequal(printer->printername, old_printer->printername)) {
5694 p = strrchr(printer->printername, '\\' );
5698 p = printer->printername;
5701 push_reg_sz(mem_ctx, &buffer, p);
5702 winreg_set_printer_dataex(mem_ctx,
5705 SPOOL_DSSPOOLER_KEY,
5706 SPOOL_REG_PRINTERNAME,
5711 if (!force_update) {
5712 notify_printer_printername(snum, p);
5716 if (force_update || !strequal(printer->portname, old_printer->portname)) {
5717 push_reg_sz(mem_ctx, &buffer, printer->portname);
5718 winreg_set_printer_dataex(mem_ctx,
5721 SPOOL_DSSPOOLER_KEY,
5727 if (!force_update) {
5728 notify_printer_port(snum, printer->portname);
5732 if (force_update || !strequal(printer->location, old_printer->location)) {
5733 push_reg_sz(mem_ctx, &buffer, printer->location);
5734 winreg_set_printer_dataex(mem_ctx,
5737 SPOOL_DSSPOOLER_KEY,
5743 if (!force_update) {
5744 notify_printer_location(snum, printer->location);
5748 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
5749 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
5750 winreg_set_printer_dataex(mem_ctx,
5753 SPOOL_DSSPOOLER_KEY,
5754 SPOOL_REG_PRINTSEPARATORFILE,
5759 if (!force_update) {
5760 notify_printer_location(snum, printer->location);
5764 if (force_update || printer->starttime != old_printer->starttime) {
5765 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5766 SIVAL(buffer.data, 0, printer->starttime);
5767 winreg_set_printer_dataex(mem_ctx,
5770 SPOOL_DSSPOOLER_KEY,
5771 SPOOL_REG_PRINTSTARTTIME,
5777 if (force_update || printer->untiltime != old_printer->untiltime) {
5778 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5779 SIVAL(buffer.data, 0, printer->untiltime);
5780 winreg_set_printer_dataex(mem_ctx,
5783 SPOOL_DSSPOOLER_KEY,
5784 SPOOL_REG_PRINTENDTIME,
5790 if (force_update || printer->priority != old_printer->priority) {
5791 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5792 SIVAL(buffer.data, 0, printer->priority);
5793 winreg_set_printer_dataex(mem_ctx,
5796 SPOOL_DSSPOOLER_KEY,
5803 if (force_update || printer->attributes != old_printer->attributes) {
5804 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5805 SIVAL(buffer.data, 0, (printer->attributes &
5806 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
5807 winreg_set_printer_dataex(mem_ctx,
5810 SPOOL_DSSPOOLER_KEY,
5811 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
5816 switch (printer->attributes & 0x3) {
5818 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
5821 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
5824 spooling = SPOOL_REGVAL_PRINTDIRECT;
5827 spooling = "unknown";
5829 push_reg_sz(mem_ctx, &buffer, spooling);
5830 winreg_set_printer_dataex(mem_ctx,
5833 SPOOL_DSSPOOLER_KEY,
5834 SPOOL_REG_PRINTSPOOLING,
5840 push_reg_sz(mem_ctx, &buffer, global_myname());
5841 winreg_set_printer_dataex(mem_ctx,
5844 SPOOL_DSSPOOLER_KEY,
5845 SPOOL_REG_SHORTSERVERNAME,
5850 dnsdomname = get_mydnsfullname();
5851 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
5852 longname = talloc_strdup(mem_ctx, dnsdomname);
5854 longname = talloc_strdup(mem_ctx, global_myname());
5856 if (longname == NULL) {
5857 result = WERR_NOMEM;
5861 push_reg_sz(mem_ctx, &buffer, longname);
5862 winreg_set_printer_dataex(mem_ctx,
5865 SPOOL_DSSPOOLER_KEY,
5866 SPOOL_REG_SERVERNAME,
5871 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5872 global_myname(), printer->sharename);
5873 push_reg_sz(mem_ctx, &buffer, uncname);
5874 winreg_set_printer_dataex(mem_ctx,
5877 SPOOL_DSSPOOLER_KEY,
5887 /********************************************************************
5888 * Called by spoolss_api_setprinter
5889 * when updating a printer description.
5890 ********************************************************************/
5892 static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
5893 struct spoolss_SetPrinterInfoCtr *info_ctr,
5894 struct spoolss_DeviceMode *devmode)
5896 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
5897 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
5898 struct spoolss_PrinterInfo2 *old_printer;
5899 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5900 const char *servername = NULL;
5902 WERROR result = WERR_OK;
5903 TALLOC_CTX *tmp_ctx;
5905 DEBUG(8,("update_printer\n"));
5907 tmp_ctx = talloc_new(p->mem_ctx);
5908 if (tmp_ctx == NULL) {
5913 result = WERR_BADFID;
5917 if (!get_printer_snum(p, handle, &snum, NULL)) {
5918 result = WERR_BADFID;
5922 if (Printer != NULL || Printer->servername != NULL) {
5923 servername = Printer->servername;
5926 result = winreg_get_printer(tmp_ctx,
5929 lp_const_servicename(snum),
5931 if (!W_ERROR_IS_OK(result)) {
5932 result = WERR_BADFID;
5936 /* Do sanity check on the requested changes for Samba */
5937 if (!check_printer_ok(tmp_ctx, printer, snum)) {
5938 result = WERR_INVALID_PARAM;
5942 /* FIXME!!! If the driver has changed we really should verify that
5943 it is installed before doing much else --jerry */
5945 /* Check calling user has permission to update printer description */
5946 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
5947 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
5948 result = WERR_ACCESS_DENIED;
5952 /* Call addprinter hook */
5953 /* Check changes to see if this is really needed */
5955 if (*lp_addprinter_cmd() &&
5956 (!strequal(printer->drivername, old_printer->drivername) ||
5957 !strequal(printer->comment, old_printer->comment) ||
5958 !strequal(printer->portname, old_printer->portname) ||
5959 !strequal(printer->location, old_printer->location)) )
5961 /* add_printer_hook() will call reload_services() */
5962 if (!add_printer_hook(tmp_ctx, p->server_info->ptok,
5964 result = WERR_ACCESS_DENIED;
5969 update_dsspooler(tmp_ctx,
5975 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
5977 if (devmode == NULL) {
5978 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
5980 result = winreg_update_printer(tmp_ctx,
5989 talloc_free(tmp_ctx);
5994 /****************************************************************************
5995 ****************************************************************************/
5996 static WERROR publish_or_unpublish_printer(pipes_struct *p,
5997 struct policy_handle *handle,
5998 struct spoolss_SetPrinterInfo7 *info7)
6001 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6004 Printer_entry *Printer;
6006 if ( lp_security() != SEC_ADS ) {
6007 return WERR_UNKNOWN_LEVEL;
6010 Printer = find_printer_index_by_hnd(p, handle);
6012 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6017 if (!get_printer_snum(p, handle, &snum, NULL))
6020 result = winreg_get_printer(p->mem_ctx, p->server_info,
6021 Printer->servername,
6022 lp_servicename(snum), &pinfo2);
6023 if (!W_ERROR_IS_OK(result)) {
6027 nt_printer_publish(pinfo2, p->server_info, pinfo2, info7->action);
6029 TALLOC_FREE(pinfo2);
6032 return WERR_UNKNOWN_LEVEL;
6036 /********************************************************************
6037 ********************************************************************/
6039 static WERROR update_printer_devmode(pipes_struct *p, struct policy_handle *handle,
6040 struct spoolss_DeviceMode *devmode)
6043 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6044 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6046 DEBUG(8,("update_printer_devmode\n"));
6052 if (!get_printer_snum(p, handle, &snum, NULL)) {
6056 /* Check calling user has permission to update printer description */
6057 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6058 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6059 return WERR_ACCESS_DENIED;
6062 return winreg_update_printer(p->mem_ctx,
6064 lp_const_servicename(snum),
6072 /****************************************************************
6074 ****************************************************************/
6076 WERROR _spoolss_SetPrinter(pipes_struct *p,
6077 struct spoolss_SetPrinter *r)
6081 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6084 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6085 OUR_HANDLE(r->in.handle)));
6089 /* check the level */
6090 switch (r->in.info_ctr->level) {
6092 return control_printer(r->in.handle, r->in.command, p);
6094 result = update_printer(p, r->in.handle,
6096 r->in.devmode_ctr->devmode);
6097 if (!W_ERROR_IS_OK(result))
6099 if (r->in.secdesc_ctr->sd)
6100 result = update_printer_sec(r->in.handle, p,
6104 return update_printer_sec(r->in.handle, p,
6107 return publish_or_unpublish_printer(p, r->in.handle,
6108 r->in.info_ctr->info.info7);
6110 return update_printer_devmode(p, r->in.handle,
6111 r->in.devmode_ctr->devmode);
6113 return WERR_UNKNOWN_LEVEL;
6117 /****************************************************************
6118 _spoolss_FindClosePrinterNotify
6119 ****************************************************************/
6121 WERROR _spoolss_FindClosePrinterNotify(pipes_struct *p,
6122 struct spoolss_FindClosePrinterNotify *r)
6124 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6127 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6128 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6132 if (Printer->notify.client_connected == true) {
6135 if ( Printer->printer_type == SPLHND_SERVER)
6137 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6138 !get_printer_snum(p, r->in.handle, &snum, NULL) )
6141 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
6144 Printer->notify.flags=0;
6145 Printer->notify.options=0;
6146 Printer->notify.localmachine[0]='\0';
6147 Printer->notify.printerlocal=0;
6148 TALLOC_FREE(Printer->notify.option);
6149 Printer->notify.client_connected = false;
6154 /****************************************************************
6156 ****************************************************************/
6158 WERROR _spoolss_AddJob(pipes_struct *p,
6159 struct spoolss_AddJob *r)
6161 if (!r->in.buffer && (r->in.offered != 0)) {
6162 return WERR_INVALID_PARAM;
6165 /* this is what a NT server returns for AddJob. AddJob must fail on
6166 * non-local printers */
6168 if (r->in.level != 1) {
6169 return WERR_UNKNOWN_LEVEL;
6172 return WERR_INVALID_PARAM;
6175 /****************************************************************************
6177 ****************************************************************************/
6179 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6180 struct spoolss_JobInfo1 *r,
6181 const print_queue_struct *queue,
6182 int position, int snum,
6183 struct spoolss_PrinterInfo2 *pinfo2)
6187 t = gmtime(&queue->time);
6189 r->job_id = queue->job;
6191 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6192 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6193 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6194 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6195 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6196 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6197 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6198 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6199 r->data_type = talloc_strdup(mem_ctx, "RAW");
6200 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6201 r->text_status = talloc_strdup(mem_ctx, "");
6202 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6204 r->status = nt_printj_status(queue->status);
6205 r->priority = queue->priority;
6206 r->position = position;
6207 r->total_pages = queue->page_count;
6208 r->pages_printed = 0; /* ??? */
6210 init_systemtime(&r->submitted, t);
6215 /****************************************************************************
6217 ****************************************************************************/
6219 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6220 struct spoolss_JobInfo2 *r,
6221 const print_queue_struct *queue,
6222 int position, int snum,
6223 struct spoolss_PrinterInfo2 *pinfo2,
6224 struct spoolss_DeviceMode *devmode)
6228 t = gmtime(&queue->time);
6230 r->job_id = queue->job;
6232 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6233 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6234 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6235 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6236 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6237 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6238 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6239 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6240 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6241 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6242 r->data_type = talloc_strdup(mem_ctx, "RAW");
6243 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6244 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6245 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6246 r->parameters = talloc_strdup(mem_ctx, "");
6247 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6248 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6249 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6251 r->devmode = devmode;
6253 r->text_status = talloc_strdup(mem_ctx, "");
6254 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6258 r->status = nt_printj_status(queue->status);
6259 r->priority = queue->priority;
6260 r->position = position;
6263 r->total_pages = queue->page_count;
6264 r->size = queue->size;
6265 init_systemtime(&r->submitted, t);
6267 r->pages_printed = 0; /* ??? */
6272 /****************************************************************************
6274 ****************************************************************************/
6276 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6277 struct spoolss_JobInfo3 *r,
6278 const print_queue_struct *queue,
6279 const print_queue_struct *next_queue,
6280 int position, int snum,
6281 struct spoolss_PrinterInfo2 *pinfo2)
6283 r->job_id = queue->job;
6286 r->next_job_id = next_queue->job;
6293 /****************************************************************************
6294 Enumjobs at level 1.
6295 ****************************************************************************/
6297 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6298 const print_queue_struct *queue,
6299 uint32_t num_queues, int snum,
6300 struct spoolss_PrinterInfo2 *pinfo2,
6301 union spoolss_JobInfo **info_p,
6304 union spoolss_JobInfo *info;
6306 WERROR result = WERR_OK;
6308 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6309 W_ERROR_HAVE_NO_MEMORY(info);
6311 *count = num_queues;
6313 for (i=0; i<*count; i++) {
6314 result = fill_job_info1(info,
6320 if (!W_ERROR_IS_OK(result)) {
6326 if (!W_ERROR_IS_OK(result)) {
6337 /****************************************************************************
6338 Enumjobs at level 2.
6339 ****************************************************************************/
6341 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6342 const print_queue_struct *queue,
6343 uint32_t num_queues, int snum,
6344 struct spoolss_PrinterInfo2 *pinfo2,
6345 union spoolss_JobInfo **info_p,
6348 union spoolss_JobInfo *info;
6350 WERROR result = WERR_OK;
6352 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6353 W_ERROR_HAVE_NO_MEMORY(info);
6355 *count = num_queues;
6357 for (i=0; i<*count; i++) {
6358 struct spoolss_DeviceMode *devmode;
6360 result = spoolss_create_default_devmode(info,
6361 pinfo2->printername,
6363 if (!W_ERROR_IS_OK(result)) {
6364 DEBUG(3, ("Can't proceed w/o a devmode!"));
6368 result = fill_job_info2(info,
6375 if (!W_ERROR_IS_OK(result)) {
6381 if (!W_ERROR_IS_OK(result)) {
6392 /****************************************************************************
6393 Enumjobs at level 3.
6394 ****************************************************************************/
6396 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6397 const print_queue_struct *queue,
6398 uint32_t num_queues, int snum,
6399 struct spoolss_PrinterInfo2 *pinfo2,
6400 union spoolss_JobInfo **info_p,
6403 union spoolss_JobInfo *info;
6405 WERROR result = WERR_OK;
6407 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6408 W_ERROR_HAVE_NO_MEMORY(info);
6410 *count = num_queues;
6412 for (i=0; i<*count; i++) {
6413 const print_queue_struct *next_queue = NULL;
6416 next_queue = &queue[i+1];
6419 result = fill_job_info3(info,
6426 if (!W_ERROR_IS_OK(result)) {
6432 if (!W_ERROR_IS_OK(result)) {
6443 /****************************************************************
6445 ****************************************************************/
6447 WERROR _spoolss_EnumJobs(pipes_struct *p,
6448 struct spoolss_EnumJobs *r)
6451 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6453 print_status_struct prt_status;
6454 print_queue_struct *queue = NULL;
6457 /* that's an [in out] buffer */
6459 if (!r->in.buffer && (r->in.offered != 0)) {
6460 return WERR_INVALID_PARAM;
6463 DEBUG(4,("_spoolss_EnumJobs\n"));
6467 *r->out.info = NULL;
6469 /* lookup the printer snum and tdb entry */
6471 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6475 result = winreg_get_printer(p->mem_ctx, p->server_info, NULL,
6476 lp_servicename(snum), &pinfo2);
6477 if (!W_ERROR_IS_OK(result)) {
6481 count = print_queue_status(snum, &queue, &prt_status);
6482 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6483 count, prt_status.status, prt_status.message));
6487 TALLOC_FREE(pinfo2);
6491 switch (r->in.level) {
6493 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6494 pinfo2, r->out.info, r->out.count);
6497 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6498 pinfo2, r->out.info, r->out.count);
6501 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
6502 pinfo2, r->out.info, r->out.count);
6505 result = WERR_UNKNOWN_LEVEL;
6510 TALLOC_FREE(pinfo2);
6512 if (!W_ERROR_IS_OK(result)) {
6516 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6518 *r->out.info, r->in.level,
6520 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6521 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6523 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6526 /****************************************************************
6527 _spoolss_ScheduleJob
6528 ****************************************************************/
6530 WERROR _spoolss_ScheduleJob(pipes_struct *p,
6531 struct spoolss_ScheduleJob *r)
6536 /****************************************************************
6537 ****************************************************************/
6539 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
6540 const char *printer_name,
6542 struct spoolss_SetJobInfo1 *r)
6546 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
6550 if (strequal(old_doc_name, r->document_name)) {
6554 if (!print_job_set_name(printer_name, job_id, r->document_name)) {
6561 /****************************************************************
6563 ****************************************************************/
6565 WERROR _spoolss_SetJob(pipes_struct *p,
6566 struct spoolss_SetJob *r)
6569 WERROR errcode = WERR_BADFUNC;
6571 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6575 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6576 return WERR_INVALID_PRINTER_NAME;
6579 switch (r->in.command) {
6580 case SPOOLSS_JOB_CONTROL_CANCEL:
6581 case SPOOLSS_JOB_CONTROL_DELETE:
6582 errcode = print_job_delete(p->server_info,
6583 snum, r->in.job_id);
6584 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
6588 case SPOOLSS_JOB_CONTROL_PAUSE:
6589 if (print_job_pause(p->server_info, snum, r->in.job_id, &errcode)) {
6593 case SPOOLSS_JOB_CONTROL_RESTART:
6594 case SPOOLSS_JOB_CONTROL_RESUME:
6595 if (print_job_resume(p->server_info, snum, r->in.job_id, &errcode)) {
6603 return WERR_UNKNOWN_LEVEL;
6606 if (!W_ERROR_IS_OK(errcode)) {
6610 if (r->in.ctr == NULL) {
6614 switch (r->in.ctr->level) {
6616 errcode = spoolss_setjob_1(p->mem_ctx, lp_const_servicename(snum),
6618 r->in.ctr->info.info1);
6624 return WERR_UNKNOWN_LEVEL;
6630 /****************************************************************************
6631 Enumerates all printer drivers by level and architecture.
6632 ****************************************************************************/
6634 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
6635 struct auth_serversupplied_info *server_info,
6636 const char *servername,
6637 const char *architecture,
6639 union spoolss_DriverInfo **info_p,
6644 struct spoolss_DriverInfo8 *driver;
6645 union spoolss_DriverInfo *info = NULL;
6647 WERROR result = WERR_OK;
6648 uint32_t num_drivers;
6649 const char **drivers;
6654 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6655 result = winreg_get_driver_list(mem_ctx, server_info,
6656 architecture, version,
6657 &num_drivers, &drivers);
6658 if (!W_ERROR_IS_OK(result)) {
6661 DEBUG(4, ("we have:[%d] drivers in environment"
6662 " [%s] and version [%d]\n",
6663 num_drivers, architecture, version));
6665 if (num_drivers != 0) {
6666 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6667 union spoolss_DriverInfo,
6668 count + num_drivers);
6670 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
6671 "failed to enlarge driver info buffer!\n"));
6672 result = WERR_NOMEM;
6677 for (i = 0; i < num_drivers; i++) {
6678 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
6680 result = winreg_get_driver(mem_ctx, server_info,
6681 architecture, drivers[i],
6683 if (!W_ERROR_IS_OK(result)) {
6689 result = fill_printer_driver_info1(info, &info[count+i].info1,
6690 driver, servername);
6693 result = fill_printer_driver_info2(info, &info[count+i].info2,
6694 driver, servername);
6697 result = fill_printer_driver_info3(info, &info[count+i].info3,
6698 driver, servername);
6701 result = fill_printer_driver_info4(info, &info[count+i].info4,
6702 driver, servername);
6705 result = fill_printer_driver_info5(info, &info[count+i].info5,
6706 driver, servername);
6709 result = fill_printer_driver_info6(info, &info[count+i].info6,
6710 driver, servername);
6713 result = fill_printer_driver_info8(info, &info[count+i].info8,
6714 driver, servername);
6717 result = WERR_UNKNOWN_LEVEL;
6721 TALLOC_FREE(driver);
6723 if (!W_ERROR_IS_OK(result)) {
6728 count += num_drivers;
6729 TALLOC_FREE(drivers);
6733 TALLOC_FREE(drivers);
6735 if (!W_ERROR_IS_OK(result)) {
6746 /****************************************************************************
6747 Enumerates all printer drivers by level.
6748 ****************************************************************************/
6750 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
6751 struct auth_serversupplied_info *server_info,
6752 const char *servername,
6753 const char *architecture,
6755 union spoolss_DriverInfo **info_p,
6759 WERROR result = WERR_OK;
6761 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
6763 for (a=0; archi_table[a].long_archi != NULL; a++) {
6765 union spoolss_DriverInfo *info = NULL;
6768 result = enumprinterdrivers_level_by_architecture(mem_ctx,
6771 archi_table[a].long_archi,
6775 if (!W_ERROR_IS_OK(result)) {
6779 for (i=0; i < count; i++) {
6780 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
6781 info[i], info_p, count_p);
6788 return enumprinterdrivers_level_by_architecture(mem_ctx,
6797 /****************************************************************
6798 _spoolss_EnumPrinterDrivers
6799 ****************************************************************/
6801 WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
6802 struct spoolss_EnumPrinterDrivers *r)
6804 const char *cservername;
6807 /* that's an [in out] buffer */
6809 if (!r->in.buffer && (r->in.offered != 0)) {
6810 return WERR_INVALID_PARAM;
6813 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
6817 *r->out.info = NULL;
6819 cservername = canon_servername(r->in.server);
6821 if (!is_myname_or_ipaddr(cservername)) {
6822 return WERR_UNKNOWN_PRINTER_DRIVER;
6825 result = enumprinterdrivers_level(p->mem_ctx,
6832 if (!W_ERROR_IS_OK(result)) {
6836 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6837 spoolss_EnumPrinterDrivers,
6838 *r->out.info, r->in.level,
6840 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6841 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6843 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6846 /****************************************************************
6848 ****************************************************************/
6850 WERROR _spoolss_EnumForms(pipes_struct *p,
6851 struct spoolss_EnumForms *r)
6857 *r->out.info = NULL;
6859 /* that's an [in out] buffer */
6861 if (!r->in.buffer && (r->in.offered != 0) ) {
6862 return WERR_INVALID_PARAM;
6865 DEBUG(4,("_spoolss_EnumForms\n"));
6866 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6867 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6869 switch (r->in.level) {
6871 result = winreg_printer_enumforms1(p->mem_ctx,
6877 result = WERR_UNKNOWN_LEVEL;
6881 if (!W_ERROR_IS_OK(result)) {
6885 if (*r->out.count == 0) {
6886 return WERR_NO_MORE_ITEMS;
6889 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6891 *r->out.info, r->in.level,
6893 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6894 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6896 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6899 /****************************************************************
6901 ****************************************************************/
6903 WERROR _spoolss_GetForm(pipes_struct *p,
6904 struct spoolss_GetForm *r)
6908 /* that's an [in out] buffer */
6910 if (!r->in.buffer && (r->in.offered != 0)) {
6911 return WERR_INVALID_PARAM;
6914 DEBUG(4,("_spoolss_GetForm\n"));
6915 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6916 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6918 switch (r->in.level) {
6920 result = winreg_printer_getform1(p->mem_ctx,
6923 &r->out.info->info1);
6926 result = WERR_UNKNOWN_LEVEL;
6930 if (!W_ERROR_IS_OK(result)) {
6931 TALLOC_FREE(r->out.info);
6935 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
6936 r->out.info, r->in.level);
6937 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
6939 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6942 /****************************************************************************
6943 ****************************************************************************/
6945 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
6946 struct spoolss_PortInfo1 *r,
6949 r->port_name = talloc_strdup(mem_ctx, name);
6950 W_ERROR_HAVE_NO_MEMORY(r->port_name);
6955 /****************************************************************************
6956 TODO: This probably needs distinguish between TCP/IP and Local ports
6958 ****************************************************************************/
6960 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
6961 struct spoolss_PortInfo2 *r,
6964 r->port_name = talloc_strdup(mem_ctx, name);
6965 W_ERROR_HAVE_NO_MEMORY(r->port_name);
6967 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
6968 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
6970 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
6971 W_ERROR_HAVE_NO_MEMORY(r->description);
6973 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
6980 /****************************************************************************
6981 wrapper around the enumer ports command
6982 ****************************************************************************/
6984 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
6986 char *cmd = lp_enumports_cmd();
6987 char **qlines = NULL;
6988 char *command = NULL;
6996 /* if no hook then just fill in the default port */
6999 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7002 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7003 TALLOC_FREE(qlines);
7010 /* we have a valid enumport command */
7012 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7017 DEBUG(10,("Running [%s]\n", command));
7018 ret = smbrun(command, &fd);
7019 DEBUG(10,("Returned [%d]\n", ret));
7020 TALLOC_FREE(command);
7025 return WERR_ACCESS_DENIED;
7029 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7030 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7040 /****************************************************************************
7042 ****************************************************************************/
7044 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7045 union spoolss_PortInfo **info_p,
7048 union spoolss_PortInfo *info = NULL;
7050 WERROR result = WERR_OK;
7051 char **qlines = NULL;
7054 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7055 if (!W_ERROR_IS_OK(result)) {
7060 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7062 DEBUG(10,("Returning WERR_NOMEM\n"));
7063 result = WERR_NOMEM;
7067 for (i=0; i<numlines; i++) {
7068 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7069 result = fill_port_1(info, &info[i].info1, qlines[i]);
7070 if (!W_ERROR_IS_OK(result)) {
7075 TALLOC_FREE(qlines);
7078 if (!W_ERROR_IS_OK(result)) {
7080 TALLOC_FREE(qlines);
7092 /****************************************************************************
7094 ****************************************************************************/
7096 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7097 union spoolss_PortInfo **info_p,
7100 union spoolss_PortInfo *info = NULL;
7102 WERROR result = WERR_OK;
7103 char **qlines = NULL;
7106 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7107 if (!W_ERROR_IS_OK(result)) {
7112 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7114 DEBUG(10,("Returning WERR_NOMEM\n"));
7115 result = WERR_NOMEM;
7119 for (i=0; i<numlines; i++) {
7120 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7121 result = fill_port_2(info, &info[i].info2, qlines[i]);
7122 if (!W_ERROR_IS_OK(result)) {
7127 TALLOC_FREE(qlines);
7130 if (!W_ERROR_IS_OK(result)) {
7132 TALLOC_FREE(qlines);
7144 /****************************************************************
7146 ****************************************************************/
7148 WERROR _spoolss_EnumPorts(pipes_struct *p,
7149 struct spoolss_EnumPorts *r)
7153 /* that's an [in out] buffer */
7155 if (!r->in.buffer && (r->in.offered != 0)) {
7156 return WERR_INVALID_PARAM;
7159 DEBUG(4,("_spoolss_EnumPorts\n"));
7163 *r->out.info = NULL;
7165 switch (r->in.level) {
7167 result = enumports_level_1(p->mem_ctx, r->out.info,
7171 result = enumports_level_2(p->mem_ctx, r->out.info,
7175 return WERR_UNKNOWN_LEVEL;
7178 if (!W_ERROR_IS_OK(result)) {
7182 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7184 *r->out.info, r->in.level,
7186 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7187 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7189 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7192 /****************************************************************************
7193 ****************************************************************************/
7195 static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
7197 struct spoolss_SetPrinterInfoCtr *info_ctr,
7198 struct spoolss_DeviceMode *devmode,
7199 struct security_descriptor *secdesc,
7200 struct spoolss_UserLevelCtr *user_ctr,
7201 struct policy_handle *handle)
7203 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7204 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7206 WERROR err = WERR_OK;
7208 /* samba does not have a concept of local, non-shared printers yet, so
7209 * make sure we always setup sharename - gd */
7210 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7211 (info2->printername != NULL && info2->printername[0] != '\0')) {
7212 DEBUG(5, ("spoolss_addprinterex_level_2: "
7213 "no sharename has been set, setting printername %s as sharename\n",
7214 info2->printername));
7215 info2->sharename = info2->printername;
7218 /* check to see if the printer already exists */
7219 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7220 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7222 return WERR_PRINTER_ALREADY_EXISTS;
7225 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7226 if ((snum = print_queue_snum(info2->printername)) != -1) {
7227 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7228 info2->printername));
7229 return WERR_PRINTER_ALREADY_EXISTS;
7233 /* validate printer info struct */
7234 if (!info2->printername || strlen(info2->printername) == 0) {
7235 return WERR_INVALID_PRINTER_NAME;
7237 if (!info2->portname || strlen(info2->portname) == 0) {
7238 return WERR_UNKNOWN_PORT;
7240 if (!info2->drivername || strlen(info2->drivername) == 0) {
7241 return WERR_UNKNOWN_PRINTER_DRIVER;
7243 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7244 return WERR_UNKNOWN_PRINTPROCESSOR;
7247 /* FIXME!!! smbd should check to see if the driver is installed before
7248 trying to add a printer like this --jerry */
7250 if (*lp_addprinter_cmd() ) {
7251 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7253 return WERR_ACCESS_DENIED;
7256 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7257 "smb.conf parameter \"addprinter command\" is defined. This"
7258 "parameter must exist for this call to succeed\n",
7259 info2->sharename ));
7262 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7263 return WERR_ACCESS_DENIED;
7266 /* you must be a printer admin to add a new printer */
7267 if (!print_access_check(p->server_info, snum, PRINTER_ACCESS_ADMINISTER)) {
7268 return WERR_ACCESS_DENIED;
7272 * Do sanity check on the requested changes for Samba.
7275 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7276 return WERR_INVALID_PARAM;
7279 if (devmode == NULL) {
7280 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7283 update_dsspooler(p->mem_ctx,
7289 err = winreg_update_printer(p->mem_ctx,
7296 if (!W_ERROR_IS_OK(err)) {
7300 if (!open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER)) {
7301 /* Handle open failed - remove addition. */
7302 ZERO_STRUCTP(handle);
7303 return WERR_ACCESS_DENIED;
7309 /****************************************************************
7310 _spoolss_AddPrinterEx
7311 ****************************************************************/
7313 WERROR _spoolss_AddPrinterEx(pipes_struct *p,
7314 struct spoolss_AddPrinterEx *r)
7316 switch (r->in.info_ctr->level) {
7318 /* we don't handle yet */
7319 /* but I know what to do ... */
7320 return WERR_UNKNOWN_LEVEL;
7322 return spoolss_addprinterex_level_2(p, r->in.server,
7324 r->in.devmode_ctr->devmode,
7325 r->in.secdesc_ctr->sd,
7326 r->in.userlevel_ctr,
7329 return WERR_UNKNOWN_LEVEL;
7333 /****************************************************************
7335 ****************************************************************/
7337 WERROR _spoolss_AddPrinter(pipes_struct *p,
7338 struct spoolss_AddPrinter *r)
7340 struct spoolss_AddPrinterEx a;
7341 struct spoolss_UserLevelCtr userlevel_ctr;
7343 ZERO_STRUCT(userlevel_ctr);
7345 userlevel_ctr.level = 1;
7347 a.in.server = r->in.server;
7348 a.in.info_ctr = r->in.info_ctr;
7349 a.in.devmode_ctr = r->in.devmode_ctr;
7350 a.in.secdesc_ctr = r->in.secdesc_ctr;
7351 a.in.userlevel_ctr = &userlevel_ctr;
7352 a.out.handle = r->out.handle;
7354 return _spoolss_AddPrinterEx(p, &a);
7357 /****************************************************************
7358 _spoolss_AddPrinterDriverEx
7359 ****************************************************************/
7361 WERROR _spoolss_AddPrinterDriverEx(pipes_struct *p,
7362 struct spoolss_AddPrinterDriverEx *r)
7364 WERROR err = WERR_OK;
7365 const char *driver_name = NULL;
7370 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7371 fn = "_spoolss_AddPrinterDriver";
7373 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7374 fn = "_spoolss_AddPrinterDriverEx";
7377 return WERR_INVALID_PARAM;
7381 * we only support the semantics of AddPrinterDriver()
7382 * i.e. only copy files that are newer than existing ones
7385 if (r->in.flags == 0) {
7386 return WERR_INVALID_PARAM;
7389 if (r->in.flags != APD_COPY_NEW_FILES) {
7390 return WERR_ACCESS_DENIED;
7394 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7395 /* Clever hack from Martin Zielinski <mz@seh.de>
7396 * to allow downgrade from level 8 (Vista).
7398 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7399 r->in.info_ctr->level));
7400 return WERR_UNKNOWN_LEVEL;
7403 DEBUG(5,("Cleaning driver's information\n"));
7404 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
7405 if (!W_ERROR_IS_OK(err))
7408 DEBUG(5,("Moving driver to final destination\n"));
7409 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7414 err = winreg_add_driver(p->mem_ctx, p->server_info,
7415 r->in.info_ctr, &driver_name, &version);
7416 if (!W_ERROR_IS_OK(err)) {
7421 * I think this is where he DrvUpgradePrinter() hook would be
7422 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7423 * server. Right now, we just need to send ourselves a message
7424 * to update each printer bound to this driver. --jerry
7427 if (!srv_spoolss_drv_upgrade_printer(driver_name)) {
7428 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7436 /****************************************************************
7437 _spoolss_AddPrinterDriver
7438 ****************************************************************/
7440 WERROR _spoolss_AddPrinterDriver(pipes_struct *p,
7441 struct spoolss_AddPrinterDriver *r)
7443 struct spoolss_AddPrinterDriverEx a;
7445 switch (r->in.info_ctr->level) {
7452 return WERR_UNKNOWN_LEVEL;
7455 a.in.servername = r->in.servername;
7456 a.in.info_ctr = r->in.info_ctr;
7457 a.in.flags = APD_COPY_NEW_FILES;
7459 return _spoolss_AddPrinterDriverEx(p, &a);
7462 /****************************************************************************
7463 ****************************************************************************/
7465 struct _spoolss_paths {
7471 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7473 static const struct _spoolss_paths spoolss_paths[]= {
7474 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7475 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7478 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7479 const char *servername,
7480 const char *environment,
7484 const char *pservername = NULL;
7485 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7486 const char *short_archi;
7490 /* environment may be empty */
7491 if (environment && strlen(environment)) {
7492 long_archi = environment;
7495 /* servername may be empty */
7496 if (servername && strlen(servername)) {
7497 pservername = canon_servername(servername);
7499 if (!is_myname_or_ipaddr(pservername)) {
7500 return WERR_INVALID_PARAM;
7504 if (!(short_archi = get_short_archi(long_archi))) {
7505 return WERR_INVALID_ENVIRONMENT;
7508 switch (component) {
7509 case SPOOLSS_PRTPROCS_PATH:
7510 case SPOOLSS_DRIVER_PATH:
7512 *path = talloc_asprintf(mem_ctx,
7515 spoolss_paths[component].share,
7518 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7519 SPOOLSS_DEFAULT_SERVER_PATH,
7520 spoolss_paths[component].dir,
7525 return WERR_INVALID_PARAM;
7535 /****************************************************************************
7536 ****************************************************************************/
7538 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7539 const char *servername,
7540 const char *environment,
7541 struct spoolss_DriverDirectoryInfo1 *r)
7546 werr = compose_spoolss_server_path(mem_ctx,
7549 SPOOLSS_DRIVER_PATH,
7551 if (!W_ERROR_IS_OK(werr)) {
7555 DEBUG(4,("printer driver directory: [%s]\n", path));
7557 r->directory_name = path;
7562 /****************************************************************
7563 _spoolss_GetPrinterDriverDirectory
7564 ****************************************************************/
7566 WERROR _spoolss_GetPrinterDriverDirectory(pipes_struct *p,
7567 struct spoolss_GetPrinterDriverDirectory *r)
7571 /* that's an [in out] buffer */
7573 if (!r->in.buffer && (r->in.offered != 0)) {
7574 return WERR_INVALID_PARAM;
7577 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
7582 /* r->in.level is ignored */
7584 werror = getprinterdriverdir_level_1(p->mem_ctx,
7587 &r->out.info->info1);
7588 if (!W_ERROR_IS_OK(werror)) {
7589 TALLOC_FREE(r->out.info);
7593 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
7594 r->out.info, r->in.level);
7595 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7597 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7600 /****************************************************************
7601 _spoolss_EnumPrinterData
7602 ****************************************************************/
7604 WERROR _spoolss_EnumPrinterData(pipes_struct *p,
7605 struct spoolss_EnumPrinterData *r)
7608 struct spoolss_EnumPrinterDataEx r2;
7610 struct spoolss_PrinterEnumValues *info, *val = NULL;
7613 r2.in.handle = r->in.handle;
7614 r2.in.key_name = "PrinterDriverData";
7616 r2.out.count = &count;
7617 r2.out.info = &info;
7618 r2.out.needed = &needed;
7620 result = _spoolss_EnumPrinterDataEx(p, &r2);
7621 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
7622 r2.in.offered = needed;
7623 result = _spoolss_EnumPrinterDataEx(p, &r2);
7625 if (!W_ERROR_IS_OK(result)) {
7630 * The NT machine wants to know the biggest size of value and data
7632 * cf: MSDN EnumPrinterData remark section
7635 if (!r->in.value_offered && !r->in.data_offered) {
7636 uint32_t biggest_valuesize = 0;
7637 uint32_t biggest_datasize = 0;
7640 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
7642 for (i=0; i<count; i++) {
7644 name_length = strlen(info[i].value_name);
7645 if (strlen(info[i].value_name) > biggest_valuesize) {
7646 biggest_valuesize = name_length;
7649 if (info[i].data_length > biggest_datasize) {
7650 biggest_datasize = info[i].data_length;
7653 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
7657 /* the value is an UNICODE string but real_value_size is the length
7658 in bytes including the trailing 0 */
7660 *r->out.value_needed = 2 * (1 + biggest_valuesize);
7661 *r->out.data_needed = biggest_datasize;
7663 DEBUG(6,("final values: [%d], [%d]\n",
7664 *r->out.value_needed, *r->out.data_needed));
7669 if (r->in.enum_index < count) {
7670 val = &info[r->in.enum_index];
7674 /* out_value should default to "" or else NT4 has
7675 problems unmarshalling the response */
7677 if (r->in.value_offered) {
7678 *r->out.value_needed = 1;
7679 r->out.value_name = talloc_strdup(r, "");
7680 if (!r->out.value_name) {
7684 r->out.value_name = NULL;
7685 *r->out.value_needed = 0;
7688 /* the data is counted in bytes */
7690 *r->out.data_needed = r->in.data_offered;
7692 result = WERR_NO_MORE_ITEMS;
7696 * - counted in bytes in the request
7697 * - counted in UNICODE chars in the max reply
7698 * - counted in bytes in the real size
7700 * take a pause *before* coding not *during* coding
7704 if (r->in.value_offered) {
7705 r->out.value_name = talloc_strdup(r, val->value_name);
7706 if (!r->out.value_name) {
7709 *r->out.value_needed = val->value_name_len;
7711 r->out.value_name = NULL;
7712 *r->out.value_needed = 0;
7717 *r->out.type = val->type;
7719 /* data - counted in bytes */
7722 * See the section "Dynamically Typed Query Parameters"
7726 if (r->out.data && val->data && val->data->data &&
7727 val->data_length && r->in.data_offered) {
7728 memcpy(r->out.data, val->data->data,
7729 MIN(val->data_length,r->in.data_offered));
7732 *r->out.data_needed = val->data_length;
7740 /****************************************************************
7741 _spoolss_SetPrinterData
7742 ****************************************************************/
7744 WERROR _spoolss_SetPrinterData(pipes_struct *p,
7745 struct spoolss_SetPrinterData *r)
7747 struct spoolss_SetPrinterDataEx r2;
7749 r2.in.handle = r->in.handle;
7750 r2.in.key_name = "PrinterDriverData";
7751 r2.in.value_name = r->in.value_name;
7752 r2.in.type = r->in.type;
7753 r2.in.data = r->in.data;
7754 r2.in.offered = r->in.offered;
7756 return _spoolss_SetPrinterDataEx(p, &r2);
7759 /****************************************************************
7760 _spoolss_ResetPrinter
7761 ****************************************************************/
7763 WERROR _spoolss_ResetPrinter(pipes_struct *p,
7764 struct spoolss_ResetPrinter *r)
7766 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7769 DEBUG(5,("_spoolss_ResetPrinter\n"));
7772 * All we do is to check to see if the handle and queue is valid.
7773 * This call really doesn't mean anything to us because we only
7774 * support RAW printing. --jerry
7778 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
7779 OUR_HANDLE(r->in.handle)));
7783 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
7787 /* blindly return success */
7791 /****************************************************************
7792 _spoolss_DeletePrinterData
7793 ****************************************************************/
7795 WERROR _spoolss_DeletePrinterData(pipes_struct *p,
7796 struct spoolss_DeletePrinterData *r)
7798 struct spoolss_DeletePrinterDataEx r2;
7800 r2.in.handle = r->in.handle;
7801 r2.in.key_name = "PrinterDriverData";
7802 r2.in.value_name = r->in.value_name;
7804 return _spoolss_DeletePrinterDataEx(p, &r2);
7807 /****************************************************************
7809 ****************************************************************/
7811 WERROR _spoolss_AddForm(pipes_struct *p,
7812 struct spoolss_AddForm *r)
7814 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
7816 WERROR status = WERR_OK;
7817 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7819 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7821 DEBUG(5,("_spoolss_AddForm\n"));
7824 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
7825 OUR_HANDLE(r->in.handle)));
7829 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
7830 and not a printer admin, then fail */
7832 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7833 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7834 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7835 p->server_info->info3->base.domain.string,
7837 p->server_info->ptok,
7838 lp_printer_admin(snum))) {
7839 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
7840 return WERR_ACCESS_DENIED;
7843 switch (form->flags) {
7844 case SPOOLSS_FORM_USER:
7845 case SPOOLSS_FORM_BUILTIN:
7846 case SPOOLSS_FORM_PRINTER:
7849 return WERR_INVALID_PARAM;
7852 status = winreg_printer_addform1(p->mem_ctx, p->server_info, form);
7853 if (!W_ERROR_IS_OK(status)) {
7858 * ChangeID must always be set if this is a printer
7860 if (Printer->printer_type == SPLHND_PRINTER) {
7861 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7865 status = winreg_printer_update_changeid(p->mem_ctx,
7867 lp_const_servicename(snum));
7868 if (!W_ERROR_IS_OK(status)) {
7876 /****************************************************************
7878 ****************************************************************/
7880 WERROR _spoolss_DeleteForm(pipes_struct *p,
7881 struct spoolss_DeleteForm *r)
7883 const char *form_name = r->in.form_name;
7884 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7886 WERROR status = WERR_OK;
7887 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7889 DEBUG(5,("_spoolss_DeleteForm\n"));
7892 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
7893 OUR_HANDLE(r->in.handle)));
7897 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7898 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7899 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7900 p->server_info->info3->base.domain.string,
7902 p->server_info->ptok,
7903 lp_printer_admin(snum))) {
7904 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
7905 return WERR_ACCESS_DENIED;
7908 status = winreg_printer_deleteform1(p->mem_ctx,
7911 if (!W_ERROR_IS_OK(status)) {
7916 * ChangeID must always be set if this is a printer
7918 if (Printer->printer_type == SPLHND_PRINTER) {
7919 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7923 status = winreg_printer_update_changeid(p->mem_ctx,
7925 lp_const_servicename(snum));
7926 if (!W_ERROR_IS_OK(status)) {
7934 /****************************************************************
7936 ****************************************************************/
7938 WERROR _spoolss_SetForm(pipes_struct *p,
7939 struct spoolss_SetForm *r)
7941 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
7942 const char *form_name = r->in.form_name;
7944 WERROR status = WERR_OK;
7945 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7947 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7949 DEBUG(5,("_spoolss_SetForm\n"));
7952 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
7953 OUR_HANDLE(r->in.handle)));
7957 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
7958 and not a printer admin, then fail */
7960 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7961 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7962 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7963 p->server_info->info3->base.domain.string,
7965 p->server_info->ptok,
7966 lp_printer_admin(snum))) {
7967 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
7968 return WERR_ACCESS_DENIED;
7971 status = winreg_printer_setform1(p->mem_ctx,
7975 if (!W_ERROR_IS_OK(status)) {
7980 * ChangeID must always be set if this is a printer
7982 if (Printer->printer_type == SPLHND_PRINTER) {
7983 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7987 status = winreg_printer_update_changeid(p->mem_ctx,
7989 lp_const_servicename(snum));
7990 if (!W_ERROR_IS_OK(status)) {
7998 /****************************************************************************
7999 fill_print_processor1
8000 ****************************************************************************/
8002 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8003 struct spoolss_PrintProcessorInfo1 *r,
8004 const char *print_processor_name)
8006 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8007 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8012 /****************************************************************************
8013 enumprintprocessors level 1.
8014 ****************************************************************************/
8016 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8017 union spoolss_PrintProcessorInfo **info_p,
8020 union spoolss_PrintProcessorInfo *info;
8023 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8024 W_ERROR_HAVE_NO_MEMORY(info);
8028 result = fill_print_processor1(info, &info[0].info1, "winprint");
8029 if (!W_ERROR_IS_OK(result)) {
8034 if (!W_ERROR_IS_OK(result)) {
8045 /****************************************************************
8046 _spoolss_EnumPrintProcessors
8047 ****************************************************************/
8049 WERROR _spoolss_EnumPrintProcessors(pipes_struct *p,
8050 struct spoolss_EnumPrintProcessors *r)
8054 /* that's an [in out] buffer */
8056 if (!r->in.buffer && (r->in.offered != 0)) {
8057 return WERR_INVALID_PARAM;
8060 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8063 * Enumerate the print processors ...
8065 * Just reply with "winprint", to keep NT happy
8066 * and I can use my nice printer checker.
8071 *r->out.info = NULL;
8073 switch (r->in.level) {
8075 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8079 return WERR_UNKNOWN_LEVEL;
8082 if (!W_ERROR_IS_OK(result)) {
8086 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8087 spoolss_EnumPrintProcessors,
8088 *r->out.info, r->in.level,
8090 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8091 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8093 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8096 /****************************************************************************
8097 fill_printprocdatatype1
8098 ****************************************************************************/
8100 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8101 struct spoolss_PrintProcDataTypesInfo1 *r,
8102 const char *name_array)
8104 r->name_array = talloc_strdup(mem_ctx, name_array);
8105 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8110 /****************************************************************************
8111 enumprintprocdatatypes level 1.
8112 ****************************************************************************/
8114 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8115 union spoolss_PrintProcDataTypesInfo **info_p,
8119 union spoolss_PrintProcDataTypesInfo *info;
8121 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8122 W_ERROR_HAVE_NO_MEMORY(info);
8126 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8127 if (!W_ERROR_IS_OK(result)) {
8132 if (!W_ERROR_IS_OK(result)) {
8143 /****************************************************************
8144 _spoolss_EnumPrintProcDataTypes
8145 ****************************************************************/
8147 WERROR _spoolss_EnumPrintProcDataTypes(pipes_struct *p,
8148 struct spoolss_EnumPrintProcDataTypes *r)
8152 /* that's an [in out] buffer */
8154 if (!r->in.buffer && (r->in.offered != 0)) {
8155 return WERR_INVALID_PARAM;
8158 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8162 *r->out.info = NULL;
8164 switch (r->in.level) {
8166 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8170 return WERR_UNKNOWN_LEVEL;
8173 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8174 spoolss_EnumPrintProcDataTypes,
8175 *r->out.info, r->in.level,
8177 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8178 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8180 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8183 /****************************************************************************
8185 ****************************************************************************/
8187 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8188 struct spoolss_MonitorInfo1 *r,
8189 const char *monitor_name)
8191 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8192 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8197 /****************************************************************************
8199 ****************************************************************************/
8201 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8202 struct spoolss_MonitorInfo2 *r,
8203 const char *monitor_name,
8204 const char *environment,
8205 const char *dll_name)
8207 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8208 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8209 r->environment = talloc_strdup(mem_ctx, environment);
8210 W_ERROR_HAVE_NO_MEMORY(r->environment);
8211 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8212 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8217 /****************************************************************************
8218 enumprintmonitors level 1.
8219 ****************************************************************************/
8221 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8222 union spoolss_MonitorInfo **info_p,
8225 union spoolss_MonitorInfo *info;
8226 WERROR result = WERR_OK;
8228 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8229 W_ERROR_HAVE_NO_MEMORY(info);
8233 result = fill_monitor_1(info, &info[0].info1,
8235 if (!W_ERROR_IS_OK(result)) {
8239 result = fill_monitor_1(info, &info[1].info1,
8241 if (!W_ERROR_IS_OK(result)) {
8246 if (!W_ERROR_IS_OK(result)) {
8257 /****************************************************************************
8258 enumprintmonitors level 2.
8259 ****************************************************************************/
8261 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8262 union spoolss_MonitorInfo **info_p,
8265 union spoolss_MonitorInfo *info;
8266 WERROR result = WERR_OK;
8268 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8269 W_ERROR_HAVE_NO_MEMORY(info);
8273 result = fill_monitor_2(info, &info[0].info2,
8275 "Windows NT X86", /* FIXME */
8277 if (!W_ERROR_IS_OK(result)) {
8281 result = fill_monitor_2(info, &info[1].info2,
8283 "Windows NT X86", /* FIXME */
8285 if (!W_ERROR_IS_OK(result)) {
8290 if (!W_ERROR_IS_OK(result)) {
8301 /****************************************************************
8302 _spoolss_EnumMonitors
8303 ****************************************************************/
8305 WERROR _spoolss_EnumMonitors(pipes_struct *p,
8306 struct spoolss_EnumMonitors *r)
8310 /* that's an [in out] buffer */
8312 if (!r->in.buffer && (r->in.offered != 0)) {
8313 return WERR_INVALID_PARAM;
8316 DEBUG(5,("_spoolss_EnumMonitors\n"));
8319 * Enumerate the print monitors ...
8321 * Just reply with "Local Port", to keep NT happy
8322 * and I can use my nice printer checker.
8327 *r->out.info = NULL;
8329 switch (r->in.level) {
8331 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8335 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8339 return WERR_UNKNOWN_LEVEL;
8342 if (!W_ERROR_IS_OK(result)) {
8346 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8347 spoolss_EnumMonitors,
8348 *r->out.info, r->in.level,
8350 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8351 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8353 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8356 /****************************************************************************
8357 ****************************************************************************/
8359 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8360 const print_queue_struct *queue,
8361 int count, int snum,
8362 struct spoolss_PrinterInfo2 *pinfo2,
8364 struct spoolss_JobInfo1 *r)
8369 for (i=0; i<count; i++) {
8370 if (queue[i].job == (int)jobid) {
8376 if (found == false) {
8377 /* NT treats not found as bad param... yet another bad choice */
8378 return WERR_INVALID_PARAM;
8381 return fill_job_info1(mem_ctx,
8389 /****************************************************************************
8390 ****************************************************************************/
8392 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8393 const print_queue_struct *queue,
8394 int count, int snum,
8395 struct spoolss_PrinterInfo2 *pinfo2,
8397 struct spoolss_JobInfo2 *r)
8401 struct spoolss_DeviceMode *devmode;
8404 for (i=0; i<count; i++) {
8405 if (queue[i].job == (int)jobid) {
8411 if (found == false) {
8412 /* NT treats not found as bad param... yet another bad
8414 return WERR_INVALID_PARAM;
8418 * if the print job does not have a DEVMODE associated with it,
8419 * just use the one for the printer. A NULL devicemode is not
8420 * a failure condition
8423 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8425 result = spoolss_create_default_devmode(mem_ctx,
8426 pinfo2->printername,
8428 if (!W_ERROR_IS_OK(result)) {
8429 DEBUG(3, ("Can't proceed w/o a devmode!"));
8434 return fill_job_info2(mem_ctx,
8443 /****************************************************************
8445 ****************************************************************/
8447 WERROR _spoolss_GetJob(pipes_struct *p,
8448 struct spoolss_GetJob *r)
8450 WERROR result = WERR_OK;
8451 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8454 print_queue_struct *queue = NULL;
8455 print_status_struct prt_status;
8457 /* that's an [in out] buffer */
8459 if (!r->in.buffer && (r->in.offered != 0)) {
8460 return WERR_INVALID_PARAM;
8463 DEBUG(5,("_spoolss_GetJob\n"));
8467 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8471 result = winreg_get_printer(p->mem_ctx, p->server_info, NULL,
8472 lp_servicename(snum), &pinfo2);
8473 if (!W_ERROR_IS_OK(result)) {
8477 count = print_queue_status(snum, &queue, &prt_status);
8479 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8480 count, prt_status.status, prt_status.message));
8482 switch (r->in.level) {
8484 result = getjob_level_1(p->mem_ctx,
8485 queue, count, snum, pinfo2,
8486 r->in.job_id, &r->out.info->info1);
8489 result = getjob_level_2(p->mem_ctx,
8490 queue, count, snum, pinfo2,
8491 r->in.job_id, &r->out.info->info2);
8494 result = WERR_UNKNOWN_LEVEL;
8499 TALLOC_FREE(pinfo2);
8501 if (!W_ERROR_IS_OK(result)) {
8502 TALLOC_FREE(r->out.info);
8506 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
8508 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8510 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8513 /****************************************************************
8514 _spoolss_GetPrinterDataEx
8515 ****************************************************************/
8517 WERROR _spoolss_GetPrinterDataEx(pipes_struct *p,
8518 struct spoolss_GetPrinterDataEx *r)
8521 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8522 const char *printer;
8524 WERROR result = WERR_OK;
8526 enum winreg_Type val_type;
8531 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8533 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8534 r->in.key_name, r->in.value_name));
8536 /* in case of problem, return some default values */
8539 *r->out.type = REG_NONE;
8542 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8543 OUR_HANDLE(r->in.handle)));
8544 result = WERR_BADFID;
8548 /* Is the handle to a printer or to the server? */
8550 if (Printer->printer_type == SPLHND_SERVER) {
8552 union spoolss_PrinterData data;
8554 result = getprinterdata_printer_server(p->mem_ctx,
8558 if (!W_ERROR_IS_OK(result)) {
8562 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
8563 *r->out.type, &data);
8564 if (!W_ERROR_IS_OK(result)) {
8568 *r->out.needed = blob.length;
8570 if (r->in.offered >= *r->out.needed) {
8571 memcpy(r->out.data, blob.data, blob.length);
8574 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8577 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8580 printer = lp_const_servicename(snum);
8582 /* check to see if the keyname is valid */
8583 if (!strlen(r->in.key_name)) {
8584 return WERR_INVALID_PARAM;
8587 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
8588 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
8589 strequal(r->in.value_name, "ChangeId")) {
8590 *r->out.type = REG_DWORD;
8592 if (r->in.offered >= *r->out.needed) {
8593 uint32_t changeid = 0;
8595 result = winreg_printer_get_changeid(p->mem_ctx,
8599 if (!W_ERROR_IS_OK(result)) {
8603 SIVAL(r->out.data, 0, changeid);
8609 result = winreg_get_printer_dataex(p->mem_ctx,
8617 if (!W_ERROR_IS_OK(result)) {
8621 *r->out.needed = val_size;
8622 *r->out.type = val_type;
8624 if (r->in.offered >= *r->out.needed) {
8625 memcpy(r->out.data, val_data, val_size);
8629 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
8630 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
8632 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8635 /****************************************************************
8636 _spoolss_SetPrinterDataEx
8637 ****************************************************************/
8639 WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
8640 struct spoolss_SetPrinterDataEx *r)
8642 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8644 WERROR result = WERR_OK;
8645 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8648 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
8650 /* From MSDN documentation of SetPrinterDataEx: pass request to
8651 SetPrinterData if key is "PrinterDriverData" */
8654 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8655 OUR_HANDLE(r->in.handle)));
8659 if (Printer->printer_type == SPLHND_SERVER) {
8660 DEBUG(10,("_spoolss_SetPrinterDataEx: "
8661 "Not implemented for server handles yet\n"));
8662 return WERR_INVALID_PARAM;
8665 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8670 * Access check : NT returns "access denied" if you make a
8671 * SetPrinterData call without the necessary privildge.
8672 * we were originally returning OK if nothing changed
8673 * which made Win2k issue **a lot** of SetPrinterData
8674 * when connecting to a printer --jerry
8677 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8678 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
8679 "change denied by handle access permissions\n"));
8680 return WERR_ACCESS_DENIED;
8683 result = winreg_get_printer(Printer, p->server_info,
8684 Printer->servername,
8685 lp_servicename(snum),
8687 if (!W_ERROR_IS_OK(result)) {
8691 /* check for OID in valuename */
8693 oid_string = strchr(r->in.value_name, ',');
8699 /* save the registry data */
8701 result = winreg_set_printer_dataex(p->mem_ctx,
8710 if (W_ERROR_IS_OK(result)) {
8711 /* save the OID if one was specified */
8713 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
8714 r->in.key_name, SPOOL_OID_KEY);
8716 result = WERR_NOMEM;
8721 * I'm not checking the status here on purpose. Don't know
8722 * if this is right, but I'm returning the status from the
8723 * previous set_printer_dataex() call. I have no idea if
8724 * this is right. --jerry
8726 winreg_set_printer_dataex(p->mem_ctx,
8732 (uint8_t *) oid_string,
8733 strlen(oid_string) + 1);
8736 result = winreg_printer_update_changeid(p->mem_ctx,
8738 lp_const_servicename(snum));
8743 talloc_free(pinfo2);
8747 /****************************************************************
8748 _spoolss_DeletePrinterDataEx
8749 ****************************************************************/
8751 WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
8752 struct spoolss_DeletePrinterDataEx *r)
8754 const char *printer;
8756 WERROR status = WERR_OK;
8757 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8759 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
8762 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
8763 "Invalid handle (%s:%u:%u).\n",
8764 OUR_HANDLE(r->in.handle)));
8768 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8769 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
8770 "printer properties change denied by handle\n"));
8771 return WERR_ACCESS_DENIED;
8774 if (!r->in.value_name || !r->in.key_name) {
8778 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8781 printer = lp_const_servicename(snum);
8783 status = winreg_delete_printer_dataex(p->mem_ctx,
8788 if (W_ERROR_IS_OK(status)) {
8789 status = winreg_printer_update_changeid(p->mem_ctx,
8797 /****************************************************************
8798 _spoolss_EnumPrinterKey
8799 ****************************************************************/
8801 WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
8802 struct spoolss_EnumPrinterKey *r)
8805 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8807 WERROR result = WERR_BADFILE;
8808 const char **array = NULL;
8811 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
8814 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
8815 OUR_HANDLE(r->in.handle)));
8819 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8823 result = winreg_enum_printer_key(p->mem_ctx,
8825 lp_const_servicename(snum),
8829 if (!W_ERROR_IS_OK(result)) {
8833 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
8834 result = WERR_NOMEM;
8838 *r->out._ndr_size = r->in.offered / 2;
8839 *r->out.needed = blob.length;
8841 if (r->in.offered < *r->out.needed) {
8842 result = WERR_MORE_DATA;
8845 r->out.key_buffer->string_array = array;
8849 if (!W_ERROR_IS_OK(result)) {
8851 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8859 /****************************************************************
8860 _spoolss_DeletePrinterKey
8861 ****************************************************************/
8863 WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
8864 struct spoolss_DeletePrinterKey *r)
8866 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8869 const char *printer;
8871 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
8874 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
8875 OUR_HANDLE(r->in.handle)));
8879 /* if keyname == NULL, return error */
8880 if ( !r->in.key_name )
8881 return WERR_INVALID_PARAM;
8883 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8887 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8888 DEBUG(3, ("_spoolss_DeletePrinterKey: "
8889 "printer properties change denied by handle\n"));
8890 return WERR_ACCESS_DENIED;
8893 printer = lp_const_servicename(snum);
8895 /* delete the key and all subkeys */
8896 status = winreg_delete_printer_key(p->mem_ctx,
8900 if (W_ERROR_IS_OK(status)) {
8901 status = winreg_printer_update_changeid(p->mem_ctx,
8909 /****************************************************************
8910 _spoolss_EnumPrinterDataEx
8911 ****************************************************************/
8913 WERROR _spoolss_EnumPrinterDataEx(pipes_struct *p,
8914 struct spoolss_EnumPrinterDataEx *r)
8917 struct spoolss_PrinterEnumValues *info = NULL;
8918 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8922 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
8926 *r->out.info = NULL;
8929 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
8930 OUR_HANDLE(r->in.handle)));
8935 * first check for a keyname of NULL or "". Win2k seems to send
8936 * this a lot and we should send back WERR_INVALID_PARAM
8937 * no need to spend time looking up the printer in this case.
8941 if (!strlen(r->in.key_name)) {
8942 result = WERR_INVALID_PARAM;
8946 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8950 /* now look for a match on the key name */
8951 result = winreg_enum_printer_dataex(p->mem_ctx,
8953 lp_const_servicename(snum),
8957 if (!W_ERROR_IS_OK(result)) {
8961 #if 0 /* FIXME - gd */
8962 /* housekeeping information in the reply */
8964 /* Fix from Martin Zielinski <mz@seh.de> - ensure
8965 * the hand marshalled container size is a multiple
8966 * of 4 bytes for RPC alignment.
8970 needed += 4-(needed % 4);
8973 *r->out.count = count;
8974 *r->out.info = info;
8977 if (!W_ERROR_IS_OK(result)) {
8981 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
8982 spoolss_EnumPrinterDataEx,
8985 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8986 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
8988 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8991 /****************************************************************************
8992 ****************************************************************************/
8994 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
8995 const char *servername,
8996 const char *environment,
8997 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9002 werr = compose_spoolss_server_path(mem_ctx,
9005 SPOOLSS_PRTPROCS_PATH,
9007 if (!W_ERROR_IS_OK(werr)) {
9011 DEBUG(4,("print processor directory: [%s]\n", path));
9013 r->directory_name = path;
9018 /****************************************************************
9019 _spoolss_GetPrintProcessorDirectory
9020 ****************************************************************/
9022 WERROR _spoolss_GetPrintProcessorDirectory(pipes_struct *p,
9023 struct spoolss_GetPrintProcessorDirectory *r)
9027 /* that's an [in out] buffer */
9029 if (!r->in.buffer && (r->in.offered != 0)) {
9030 return WERR_INVALID_PARAM;
9033 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9038 /* r->in.level is ignored */
9040 /* We always should reply with a local print processor directory so that
9041 * users are not forced to have a [prnproc$] share on the Samba spoolss
9042 * server - Guenther */
9044 result = getprintprocessordirectory_level_1(p->mem_ctx,
9045 NULL, /* r->in.server */
9047 &r->out.info->info1);
9048 if (!W_ERROR_IS_OK(result)) {
9049 TALLOC_FREE(r->out.info);
9053 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9054 r->out.info, r->in.level);
9055 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9057 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9060 /*******************************************************************
9061 ********************************************************************/
9063 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9064 const char *dllname)
9066 enum ndr_err_code ndr_err;
9067 struct spoolss_MonitorUi ui;
9069 ui.dll_name = dllname;
9071 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9072 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9073 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9074 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9076 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9079 /*******************************************************************
9080 Streams the monitor UI DLL name in UNICODE
9081 *******************************************************************/
9083 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9084 NT_USER_TOKEN *token, DATA_BLOB *in,
9085 DATA_BLOB *out, uint32_t *needed)
9087 const char *dllname = "tcpmonui.dll";
9089 *needed = (strlen(dllname)+1) * 2;
9091 if (out->length < *needed) {
9092 return WERR_INSUFFICIENT_BUFFER;
9095 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9102 /*******************************************************************
9103 ********************************************************************/
9105 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9106 struct spoolss_PortData1 *port1,
9107 const DATA_BLOB *buf)
9109 enum ndr_err_code ndr_err;
9110 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9111 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9112 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9113 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9115 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9118 /*******************************************************************
9119 ********************************************************************/
9121 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9122 struct spoolss_PortData2 *port2,
9123 const DATA_BLOB *buf)
9125 enum ndr_err_code ndr_err;
9126 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9127 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9128 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9129 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9131 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9134 /*******************************************************************
9135 Create a new TCP/IP port
9136 *******************************************************************/
9138 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9139 NT_USER_TOKEN *token, DATA_BLOB *in,
9140 DATA_BLOB *out, uint32_t *needed)
9142 struct spoolss_PortData1 port1;
9143 struct spoolss_PortData2 port2;
9144 char *device_uri = NULL;
9147 const char *portname;
9148 const char *hostaddress;
9150 uint32_t port_number;
9153 /* peek for spoolss_PortData version */
9155 if (!in || (in->length < (128 + 4))) {
9156 return WERR_GENERAL_FAILURE;
9159 version = IVAL(in->data, 128);
9165 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9169 portname = port1.portname;
9170 hostaddress = port1.hostaddress;
9171 queue = port1.queue;
9172 protocol = port1.protocol;
9173 port_number = port1.port_number;
9179 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9183 portname = port2.portname;
9184 hostaddress = port2.hostaddress;
9185 queue = port2.queue;
9186 protocol = port2.protocol;
9187 port_number = port2.port_number;
9191 DEBUG(1,("xcvtcp_addport: "
9192 "unknown version of port_data: %d\n", version));
9193 return WERR_UNKNOWN_PORT;
9196 /* create the device URI and call the add_port_hook() */
9199 case PROTOCOL_RAWTCP_TYPE:
9200 device_uri = talloc_asprintf(mem_ctx,
9201 "socket://%s:%d/", hostaddress,
9205 case PROTOCOL_LPR_TYPE:
9206 device_uri = talloc_asprintf(mem_ctx,
9207 "lpr://%s/%s", hostaddress, queue );
9211 return WERR_UNKNOWN_PORT;
9218 return add_port_hook(mem_ctx, token, portname, device_uri);
9221 /*******************************************************************
9222 *******************************************************************/
9224 struct xcv_api_table xcvtcp_cmds[] = {
9225 { "MonitorUI", xcvtcp_monitorui },
9226 { "AddPort", xcvtcp_addport},
9230 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9231 NT_USER_TOKEN *token, const char *command,
9238 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9240 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9241 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9242 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9245 return WERR_BADFUNC;
9248 /*******************************************************************
9249 *******************************************************************/
9250 #if 0 /* don't support management using the "Local Port" monitor */
9252 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9253 NT_USER_TOKEN *token, DATA_BLOB *in,
9254 DATA_BLOB *out, uint32_t *needed)
9256 const char *dllname = "localui.dll";
9258 *needed = (strlen(dllname)+1) * 2;
9260 if (out->length < *needed) {
9261 return WERR_INSUFFICIENT_BUFFER;
9264 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9271 /*******************************************************************
9272 *******************************************************************/
9274 struct xcv_api_table xcvlocal_cmds[] = {
9275 { "MonitorUI", xcvlocal_monitorui },
9279 struct xcv_api_table xcvlocal_cmds[] = {
9286 /*******************************************************************
9287 *******************************************************************/
9289 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9290 NT_USER_TOKEN *token, const char *command,
9291 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9296 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9298 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9299 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9300 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9302 return WERR_BADFUNC;
9305 /****************************************************************
9307 ****************************************************************/
9309 WERROR _spoolss_XcvData(pipes_struct *p,
9310 struct spoolss_XcvData *r)
9312 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9313 DATA_BLOB out_data = data_blob_null;
9317 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9318 OUR_HANDLE(r->in.handle)));
9322 /* Has to be a handle to the TCP/IP port monitor */
9324 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9325 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9329 /* requires administrative access to the server */
9331 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9332 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9333 return WERR_ACCESS_DENIED;
9336 /* Allocate the outgoing buffer */
9338 if (r->in.out_data_size) {
9339 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9340 if (out_data.data == NULL) {
9345 switch ( Printer->printer_type ) {
9346 case SPLHND_PORTMON_TCP:
9347 werror = process_xcvtcp_command(p->mem_ctx,
9348 p->server_info->ptok,
9349 r->in.function_name,
9350 &r->in.in_data, &out_data,
9353 case SPLHND_PORTMON_LOCAL:
9354 werror = process_xcvlocal_command(p->mem_ctx,
9355 p->server_info->ptok,
9356 r->in.function_name,
9357 &r->in.in_data, &out_data,
9361 werror = WERR_INVALID_PRINT_MONITOR;
9364 if (!W_ERROR_IS_OK(werror)) {
9368 *r->out.status_code = 0;
9370 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9371 memcpy(r->out.out_data, out_data.data,
9372 MIN(r->in.out_data_size, out_data.length));
9378 /****************************************************************
9379 _spoolss_AddPrintProcessor
9380 ****************************************************************/
9382 WERROR _spoolss_AddPrintProcessor(pipes_struct *p,
9383 struct spoolss_AddPrintProcessor *r)
9385 /* for now, just indicate success and ignore the add. We'll
9386 automatically set the winprint processor for printer
9387 entries later. Used to debug the LexMark Optra S 1855 PCL
9393 /****************************************************************
9395 ****************************************************************/
9397 WERROR _spoolss_AddPort(pipes_struct *p,
9398 struct spoolss_AddPort *r)
9400 /* do what w2k3 does */
9402 return WERR_NOT_SUPPORTED;
9405 /****************************************************************
9406 _spoolss_GetPrinterDriver
9407 ****************************************************************/
9409 WERROR _spoolss_GetPrinterDriver(pipes_struct *p,
9410 struct spoolss_GetPrinterDriver *r)
9412 p->rng_fault_state = true;
9413 return WERR_NOT_SUPPORTED;
9416 /****************************************************************
9417 _spoolss_ReadPrinter
9418 ****************************************************************/
9420 WERROR _spoolss_ReadPrinter(pipes_struct *p,
9421 struct spoolss_ReadPrinter *r)
9423 p->rng_fault_state = true;
9424 return WERR_NOT_SUPPORTED;
9427 /****************************************************************
9428 _spoolss_WaitForPrinterChange
9429 ****************************************************************/
9431 WERROR _spoolss_WaitForPrinterChange(pipes_struct *p,
9432 struct spoolss_WaitForPrinterChange *r)
9434 p->rng_fault_state = true;
9435 return WERR_NOT_SUPPORTED;
9438 /****************************************************************
9439 _spoolss_ConfigurePort
9440 ****************************************************************/
9442 WERROR _spoolss_ConfigurePort(pipes_struct *p,
9443 struct spoolss_ConfigurePort *r)
9445 p->rng_fault_state = true;
9446 return WERR_NOT_SUPPORTED;
9449 /****************************************************************
9451 ****************************************************************/
9453 WERROR _spoolss_DeletePort(pipes_struct *p,
9454 struct spoolss_DeletePort *r)
9456 p->rng_fault_state = true;
9457 return WERR_NOT_SUPPORTED;
9460 /****************************************************************
9461 _spoolss_CreatePrinterIC
9462 ****************************************************************/
9464 WERROR _spoolss_CreatePrinterIC(pipes_struct *p,
9465 struct spoolss_CreatePrinterIC *r)
9467 p->rng_fault_state = true;
9468 return WERR_NOT_SUPPORTED;
9471 /****************************************************************
9472 _spoolss_PlayGDIScriptOnPrinterIC
9473 ****************************************************************/
9475 WERROR _spoolss_PlayGDIScriptOnPrinterIC(pipes_struct *p,
9476 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9478 p->rng_fault_state = true;
9479 return WERR_NOT_SUPPORTED;
9482 /****************************************************************
9483 _spoolss_DeletePrinterIC
9484 ****************************************************************/
9486 WERROR _spoolss_DeletePrinterIC(pipes_struct *p,
9487 struct spoolss_DeletePrinterIC *r)
9489 p->rng_fault_state = true;
9490 return WERR_NOT_SUPPORTED;
9493 /****************************************************************
9494 _spoolss_AddPrinterConnection
9495 ****************************************************************/
9497 WERROR _spoolss_AddPrinterConnection(pipes_struct *p,
9498 struct spoolss_AddPrinterConnection *r)
9500 p->rng_fault_state = true;
9501 return WERR_NOT_SUPPORTED;
9504 /****************************************************************
9505 _spoolss_DeletePrinterConnection
9506 ****************************************************************/
9508 WERROR _spoolss_DeletePrinterConnection(pipes_struct *p,
9509 struct spoolss_DeletePrinterConnection *r)
9511 p->rng_fault_state = true;
9512 return WERR_NOT_SUPPORTED;
9515 /****************************************************************
9516 _spoolss_PrinterMessageBox
9517 ****************************************************************/
9519 WERROR _spoolss_PrinterMessageBox(pipes_struct *p,
9520 struct spoolss_PrinterMessageBox *r)
9522 p->rng_fault_state = true;
9523 return WERR_NOT_SUPPORTED;
9526 /****************************************************************
9528 ****************************************************************/
9530 WERROR _spoolss_AddMonitor(pipes_struct *p,
9531 struct spoolss_AddMonitor *r)
9533 p->rng_fault_state = true;
9534 return WERR_NOT_SUPPORTED;
9537 /****************************************************************
9538 _spoolss_DeleteMonitor
9539 ****************************************************************/
9541 WERROR _spoolss_DeleteMonitor(pipes_struct *p,
9542 struct spoolss_DeleteMonitor *r)
9544 p->rng_fault_state = true;
9545 return WERR_NOT_SUPPORTED;
9548 /****************************************************************
9549 _spoolss_DeletePrintProcessor
9550 ****************************************************************/
9552 WERROR _spoolss_DeletePrintProcessor(pipes_struct *p,
9553 struct spoolss_DeletePrintProcessor *r)
9555 p->rng_fault_state = true;
9556 return WERR_NOT_SUPPORTED;
9559 /****************************************************************
9560 _spoolss_AddPrintProvidor
9561 ****************************************************************/
9563 WERROR _spoolss_AddPrintProvidor(pipes_struct *p,
9564 struct spoolss_AddPrintProvidor *r)
9566 p->rng_fault_state = true;
9567 return WERR_NOT_SUPPORTED;
9570 /****************************************************************
9571 _spoolss_DeletePrintProvidor
9572 ****************************************************************/
9574 WERROR _spoolss_DeletePrintProvidor(pipes_struct *p,
9575 struct spoolss_DeletePrintProvidor *r)
9577 p->rng_fault_state = true;
9578 return WERR_NOT_SUPPORTED;
9581 /****************************************************************
9582 _spoolss_FindFirstPrinterChangeNotification
9583 ****************************************************************/
9585 WERROR _spoolss_FindFirstPrinterChangeNotification(pipes_struct *p,
9586 struct spoolss_FindFirstPrinterChangeNotification *r)
9588 p->rng_fault_state = true;
9589 return WERR_NOT_SUPPORTED;
9592 /****************************************************************
9593 _spoolss_FindNextPrinterChangeNotification
9594 ****************************************************************/
9596 WERROR _spoolss_FindNextPrinterChangeNotification(pipes_struct *p,
9597 struct spoolss_FindNextPrinterChangeNotification *r)
9599 p->rng_fault_state = true;
9600 return WERR_NOT_SUPPORTED;
9603 /****************************************************************
9604 _spoolss_RouterFindFirstPrinterChangeNotificationOld
9605 ****************************************************************/
9607 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(pipes_struct *p,
9608 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
9610 p->rng_fault_state = true;
9611 return WERR_NOT_SUPPORTED;
9614 /****************************************************************
9615 _spoolss_ReplyOpenPrinter
9616 ****************************************************************/
9618 WERROR _spoolss_ReplyOpenPrinter(pipes_struct *p,
9619 struct spoolss_ReplyOpenPrinter *r)
9621 p->rng_fault_state = true;
9622 return WERR_NOT_SUPPORTED;
9625 /****************************************************************
9626 _spoolss_RouterReplyPrinter
9627 ****************************************************************/
9629 WERROR _spoolss_RouterReplyPrinter(pipes_struct *p,
9630 struct spoolss_RouterReplyPrinter *r)
9632 p->rng_fault_state = true;
9633 return WERR_NOT_SUPPORTED;
9636 /****************************************************************
9637 _spoolss_ReplyClosePrinter
9638 ****************************************************************/
9640 WERROR _spoolss_ReplyClosePrinter(pipes_struct *p,
9641 struct spoolss_ReplyClosePrinter *r)
9643 p->rng_fault_state = true;
9644 return WERR_NOT_SUPPORTED;
9647 /****************************************************************
9649 ****************************************************************/
9651 WERROR _spoolss_AddPortEx(pipes_struct *p,
9652 struct spoolss_AddPortEx *r)
9654 p->rng_fault_state = true;
9655 return WERR_NOT_SUPPORTED;
9658 /****************************************************************
9659 _spoolss_RouterFindFirstPrinterChangeNotification
9660 ****************************************************************/
9662 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(pipes_struct *p,
9663 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
9665 p->rng_fault_state = true;
9666 return WERR_NOT_SUPPORTED;
9669 /****************************************************************
9670 _spoolss_SpoolerInit
9671 ****************************************************************/
9673 WERROR _spoolss_SpoolerInit(pipes_struct *p,
9674 struct spoolss_SpoolerInit *r)
9676 p->rng_fault_state = true;
9677 return WERR_NOT_SUPPORTED;
9680 /****************************************************************
9681 _spoolss_ResetPrinterEx
9682 ****************************************************************/
9684 WERROR _spoolss_ResetPrinterEx(pipes_struct *p,
9685 struct spoolss_ResetPrinterEx *r)
9687 p->rng_fault_state = true;
9688 return WERR_NOT_SUPPORTED;
9691 /****************************************************************
9692 _spoolss_RouterReplyPrinterEx
9693 ****************************************************************/
9695 WERROR _spoolss_RouterReplyPrinterEx(pipes_struct *p,
9696 struct spoolss_RouterReplyPrinterEx *r)
9698 p->rng_fault_state = true;
9699 return WERR_NOT_SUPPORTED;
9702 /****************************************************************
9704 ****************************************************************/
9706 WERROR _spoolss_44(pipes_struct *p,
9707 struct spoolss_44 *r)
9709 p->rng_fault_state = true;
9710 return WERR_NOT_SUPPORTED;
9713 /****************************************************************
9715 ****************************************************************/
9717 WERROR _spoolss_47(pipes_struct *p,
9718 struct spoolss_47 *r)
9720 p->rng_fault_state = true;
9721 return WERR_NOT_SUPPORTED;
9724 /****************************************************************
9726 ****************************************************************/
9728 WERROR _spoolss_4a(pipes_struct *p,
9729 struct spoolss_4a *r)
9731 p->rng_fault_state = true;
9732 return WERR_NOT_SUPPORTED;
9735 /****************************************************************
9737 ****************************************************************/
9739 WERROR _spoolss_4b(pipes_struct *p,
9740 struct spoolss_4b *r)
9742 p->rng_fault_state = true;
9743 return WERR_NOT_SUPPORTED;
9746 /****************************************************************
9748 ****************************************************************/
9750 WERROR _spoolss_4c(pipes_struct *p,
9751 struct spoolss_4c *r)
9753 p->rng_fault_state = true;
9754 return WERR_NOT_SUPPORTED;
9757 /****************************************************************
9759 ****************************************************************/
9761 WERROR _spoolss_53(pipes_struct *p,
9762 struct spoolss_53 *r)
9764 p->rng_fault_state = true;
9765 return WERR_NOT_SUPPORTED;
9768 /****************************************************************
9770 ****************************************************************/
9772 WERROR _spoolss_55(pipes_struct *p,
9773 struct spoolss_55 *r)
9775 p->rng_fault_state = true;
9776 return WERR_NOT_SUPPORTED;
9779 /****************************************************************
9781 ****************************************************************/
9783 WERROR _spoolss_56(pipes_struct *p,
9784 struct spoolss_56 *r)
9786 p->rng_fault_state = true;
9787 return WERR_NOT_SUPPORTED;
9790 /****************************************************************
9792 ****************************************************************/
9794 WERROR _spoolss_57(pipes_struct *p,
9795 struct spoolss_57 *r)
9797 p->rng_fault_state = true;
9798 return WERR_NOT_SUPPORTED;
9801 /****************************************************************
9803 ****************************************************************/
9805 WERROR _spoolss_5a(pipes_struct *p,
9806 struct spoolss_5a *r)
9808 p->rng_fault_state = true;
9809 return WERR_NOT_SUPPORTED;
9812 /****************************************************************
9814 ****************************************************************/
9816 WERROR _spoolss_5b(pipes_struct *p,
9817 struct spoolss_5b *r)
9819 p->rng_fault_state = true;
9820 return WERR_NOT_SUPPORTED;
9823 /****************************************************************
9825 ****************************************************************/
9827 WERROR _spoolss_5c(pipes_struct *p,
9828 struct spoolss_5c *r)
9830 p->rng_fault_state = true;
9831 return WERR_NOT_SUPPORTED;
9834 /****************************************************************
9836 ****************************************************************/
9838 WERROR _spoolss_5d(pipes_struct *p,
9839 struct spoolss_5d *r)
9841 p->rng_fault_state = true;
9842 return WERR_NOT_SUPPORTED;
9845 /****************************************************************
9847 ****************************************************************/
9849 WERROR _spoolss_5e(pipes_struct *p,
9850 struct spoolss_5e *r)
9852 p->rng_fault_state = true;
9853 return WERR_NOT_SUPPORTED;
9856 /****************************************************************
9858 ****************************************************************/
9860 WERROR _spoolss_5f(pipes_struct *p,
9861 struct spoolss_5f *r)
9863 p->rng_fault_state = true;
9864 return WERR_NOT_SUPPORTED;
9867 /****************************************************************
9869 ****************************************************************/
9871 WERROR _spoolss_60(pipes_struct *p,
9872 struct spoolss_60 *r)
9874 p->rng_fault_state = true;
9875 return WERR_NOT_SUPPORTED;
9878 /****************************************************************
9880 ****************************************************************/
9882 WERROR _spoolss_61(pipes_struct *p,
9883 struct spoolss_61 *r)
9885 p->rng_fault_state = true;
9886 return WERR_NOT_SUPPORTED;
9889 /****************************************************************
9891 ****************************************************************/
9893 WERROR _spoolss_62(pipes_struct *p,
9894 struct spoolss_62 *r)
9896 p->rng_fault_state = true;
9897 return WERR_NOT_SUPPORTED;
9900 /****************************************************************
9902 ****************************************************************/
9904 WERROR _spoolss_63(pipes_struct *p,
9905 struct spoolss_63 *r)
9907 p->rng_fault_state = true;
9908 return WERR_NOT_SUPPORTED;
9911 /****************************************************************
9913 ****************************************************************/
9915 WERROR _spoolss_64(pipes_struct *p,
9916 struct spoolss_64 *r)
9918 p->rng_fault_state = true;
9919 return WERR_NOT_SUPPORTED;
9922 /****************************************************************
9924 ****************************************************************/
9926 WERROR _spoolss_65(pipes_struct *p,
9927 struct spoolss_65 *r)
9929 p->rng_fault_state = true;
9930 return WERR_NOT_SUPPORTED;
9933 /****************************************************************
9934 _spoolss_GetCorePrinterDrivers
9935 ****************************************************************/
9937 WERROR _spoolss_GetCorePrinterDrivers(pipes_struct *p,
9938 struct spoolss_GetCorePrinterDrivers *r)
9940 p->rng_fault_state = true;
9941 return WERR_NOT_SUPPORTED;
9944 /****************************************************************
9946 ****************************************************************/
9948 WERROR _spoolss_67(pipes_struct *p,
9949 struct spoolss_67 *r)
9951 p->rng_fault_state = true;
9952 return WERR_NOT_SUPPORTED;
9955 /****************************************************************
9956 _spoolss_GetPrinterDriverPackagePath
9957 ****************************************************************/
9959 WERROR _spoolss_GetPrinterDriverPackagePath(pipes_struct *p,
9960 struct spoolss_GetPrinterDriverPackagePath *r)
9962 p->rng_fault_state = true;
9963 return WERR_NOT_SUPPORTED;
9966 /****************************************************************
9968 ****************************************************************/
9970 WERROR _spoolss_69(pipes_struct *p,
9971 struct spoolss_69 *r)
9973 p->rng_fault_state = true;
9974 return WERR_NOT_SUPPORTED;
9977 /****************************************************************
9979 ****************************************************************/
9981 WERROR _spoolss_6a(pipes_struct *p,
9982 struct spoolss_6a *r)
9984 p->rng_fault_state = true;
9985 return WERR_NOT_SUPPORTED;
9988 /****************************************************************
9990 ****************************************************************/
9992 WERROR _spoolss_6b(pipes_struct *p,
9993 struct spoolss_6b *r)
9995 p->rng_fault_state = true;
9996 return WERR_NOT_SUPPORTED;
9999 /****************************************************************
10001 ****************************************************************/
10003 WERROR _spoolss_6c(pipes_struct *p,
10004 struct spoolss_6c *r)
10006 p->rng_fault_state = true;
10007 return WERR_NOT_SUPPORTED;
10010 /****************************************************************
10012 ****************************************************************/
10014 WERROR _spoolss_6d(pipes_struct *p,
10015 struct spoolss_6d *r)
10017 p->rng_fault_state = true;
10018 return WERR_NOT_SUPPORTED;