2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Jeremy Allison 2001-2002,
8 * Copyright (C) Gerald Carter 2000-2004,
9 * Copyright (C) Tim Potter 2001-2002.
10 * Copyright (C) Guenther Deschner 2009-2010.
11 * Copyright (C) Andreas Schneider 2010.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
28 up, all the errors returned are DOS errors, not NT status codes. */
31 #include "nt_printing.h"
32 #include "srv_spoolss_util.h"
33 #include "../librpc/gen_ndr/srv_spoolss.h"
34 #include "../librpc/gen_ndr/cli_spoolss.h"
35 #include "rpc_client/init_spoolss.h"
36 #include "librpc/gen_ndr/messaging.h"
37 #include "librpc/gen_ndr/ndr_security.h"
39 #include "registry/reg_objects.h"
40 #include "include/printing.h"
42 #include "../librpc/gen_ndr/netlogon.h"
44 /* macros stolen from s4 spoolss server */
45 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
46 ((info)?ndr_size_##fn(info, level, 0):0)
48 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
49 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
51 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
52 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
54 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
57 #define DBGC_CLASS DBGC_RPC_SRV
59 static Printer_entry *printers_list;
61 typedef struct _counter_printer_0 {
62 struct _counter_printer_0 *next;
63 struct _counter_printer_0 *prev;
69 static counter_printer_0 *counter_list;
71 static struct rpc_pipe_client *notify_cli_pipe; /* print notify back-channel pipe handle*/
72 static uint32_t smb_connections = 0;
75 /* Map generic permissions to printer object specific permissions */
77 const struct standard_mapping printer_std_mapping = {
84 /* Map generic permissions to print server object specific permissions */
86 const struct standard_mapping printserver_std_mapping = {
93 /* API table for Xcv Monitor functions */
95 struct xcv_api_table {
97 WERROR(*fn) (TALLOC_CTX *mem_ctx, NT_USER_TOKEN *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
100 /********************************************************************
101 * Canonicalize servername.
102 ********************************************************************/
104 static const char *canon_servername(const char *servername)
106 const char *pservername = servername;
107 while (*pservername == '\\') {
113 /* translate between internal status numbers and NT status numbers */
114 static int nt_printj_status(int v)
120 return JOB_STATUS_PAUSED;
122 return JOB_STATUS_SPOOLING;
124 return JOB_STATUS_PRINTING;
126 return JOB_STATUS_ERROR;
128 return JOB_STATUS_DELETING;
130 return JOB_STATUS_OFFLINE;
132 return JOB_STATUS_PAPEROUT;
134 return JOB_STATUS_PRINTED;
136 return JOB_STATUS_DELETED;
138 return JOB_STATUS_BLOCKED_DEVQ;
139 case LPQ_USER_INTERVENTION:
140 return JOB_STATUS_USER_INTERVENTION;
145 static int nt_printq_status(int v)
149 return PRINTER_STATUS_PAUSED;
158 /***************************************************************************
159 Disconnect from the client
160 ****************************************************************************/
162 static void srv_spoolss_replycloseprinter(
163 int snum, struct policy_handle *handle,
164 struct messaging_context *msg_ctx)
170 * Tell the specific printing tdb we no longer want messages for this printer
171 * by deregistering our PID.
174 if (!print_notify_deregister_pid(snum))
175 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
177 /* weird if the test succeeds !!! */
178 if (smb_connections==0) {
179 DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
183 status = rpccli_spoolss_ReplyClosePrinter(notify_cli_pipe, talloc_tos(),
186 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
187 DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
188 win_errstr(result)));
190 /* if it's the last connection, deconnect the IPC$ share */
191 if (smb_connections==1) {
193 cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) );
195 * The above call shuts down the pipe also.
197 notify_cli_pipe = NULL;
199 if (msg_ctx != NULL) {
200 messaging_deregister(msg_ctx, MSG_PRINTER_NOTIFY2,
204 * Tell the serverid.tdb we're no longer
205 * interested in printer notify messages.
208 serverid_register_msg_flags(
209 messaging_server_id(msg_ctx),
210 false, FLAG_MSG_PRINT_NOTIFY);
217 /****************************************************************************
218 Functions to free a printer entry datastruct.
219 ****************************************************************************/
221 static int printer_entry_destructor(Printer_entry *Printer)
223 if (Printer->notify.client_connected == true) {
226 if ( Printer->printer_type == SPLHND_SERVER) {
228 srv_spoolss_replycloseprinter(
229 snum, &Printer->notify.client_hnd,
230 Printer->notify.msg_ctx);
231 } else if (Printer->printer_type == SPLHND_PRINTER) {
232 snum = print_queue_snum(Printer->sharename);
234 srv_spoolss_replycloseprinter(
235 snum, &Printer->notify.client_hnd,
236 Printer->notify.msg_ctx);
240 Printer->notify.flags=0;
241 Printer->notify.options=0;
242 Printer->notify.localmachine[0]='\0';
243 Printer->notify.printerlocal=0;
244 TALLOC_FREE(Printer->notify.option);
245 Printer->notify.client_connected = false;
247 TALLOC_FREE(Printer->devmode);
249 /* Remove from the internal list. */
250 DLIST_REMOVE(printers_list, Printer);
254 /****************************************************************************
255 find printer index by handle
256 ****************************************************************************/
258 static Printer_entry *find_printer_index_by_hnd(struct pipes_struct *p,
259 struct policy_handle *hnd)
261 Printer_entry *find_printer = NULL;
263 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
264 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
271 /****************************************************************************
272 Close printer index by handle.
273 ****************************************************************************/
275 static bool close_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
277 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
280 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
285 close_policy_hnd(p, hnd);
290 /****************************************************************************
291 Delete a printer given a handle.
292 ****************************************************************************/
294 static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
295 const char *sharename,
296 struct messaging_context *msg_ctx)
298 char *cmd = lp_deleteprinter_cmd();
299 char *command = NULL;
301 SE_PRIV se_printop = SE_PRINT_OPERATOR;
302 bool is_print_op = false;
304 /* can't fail if we don't try */
309 command = talloc_asprintf(ctx,
316 is_print_op = user_has_privileges( token, &se_printop );
318 DEBUG(10,("Running [%s]\n", command));
320 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
325 if ( (ret = smbrun(command, NULL)) == 0 ) {
326 /* Tell everyone we updated smb.conf. */
327 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
333 /********** END SePrintOperatorPrivlege BLOCK **********/
335 DEBUGADD(10,("returned [%d]\n", ret));
337 TALLOC_FREE(command);
340 return WERR_BADFID; /* What to return here? */
342 /* go ahead and re-read the services immediately */
344 reload_services(false);
347 if ( lp_servicenumber( sharename ) > 0 )
348 return WERR_ACCESS_DENIED;
353 /****************************************************************************
354 Delete a printer given a handle.
355 ****************************************************************************/
357 static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
359 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
363 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
369 * It turns out that Windows allows delete printer on a handle
370 * opened by an admin user, then used on a pipe handle created
371 * by an anonymous user..... but they're working on security.... riiight !
375 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
376 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
377 return WERR_ACCESS_DENIED;
380 /* this does not need a become root since the access check has been
381 done on the handle already */
383 result = winreg_delete_printer_key(p->mem_ctx, p->server_info,
384 p->msg_ctx, Printer->sharename, "");
385 if (!W_ERROR_IS_OK(result)) {
386 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
390 return delete_printer_hook(p->mem_ctx, p->server_info->ptok,
391 Printer->sharename, p->msg_ctx);
394 /****************************************************************************
395 Return the snum of a printer corresponding to an handle.
396 ****************************************************************************/
398 static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
399 int *number, struct share_params **params)
401 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
404 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
409 switch (Printer->printer_type) {
411 DEBUG(4,("short name:%s\n", Printer->sharename));
412 *number = print_queue_snum(Printer->sharename);
413 return (*number != -1);
421 /****************************************************************************
422 Set printer handle type.
423 Check if it's \\server or \\server\printer
424 ****************************************************************************/
426 static bool set_printer_hnd_printertype(Printer_entry *Printer, const char *handlename)
428 DEBUG(3,("Setting printer type=%s\n", handlename));
430 if ( strlen(handlename) < 3 ) {
431 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", handlename));
435 /* it's a print server */
436 if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
437 DEBUGADD(4,("Printer is a print server\n"));
438 Printer->printer_type = SPLHND_SERVER;
440 /* it's a printer (set_printer_hnd_name() will handle port monitors */
442 DEBUGADD(4,("Printer is a printer\n"));
443 Printer->printer_type = SPLHND_PRINTER;
449 /****************************************************************************
450 Set printer handle name.. Accept names like \\server, \\server\printer,
451 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
452 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
453 XcvDataPort() interface.
454 ****************************************************************************/
456 static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
457 struct auth_serversupplied_info *server_info,
458 struct messaging_context *msg_ctx,
459 Printer_entry *Printer,
460 const char *handlename)
463 int n_services=lp_numservices();
465 const char *printername;
466 const char *servername = NULL;
469 struct spoolss_PrinterInfo2 *info2 = NULL;
472 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
473 (unsigned long)strlen(handlename)));
475 aprinter = CONST_DISCARD(char *, handlename);
476 if ( *handlename == '\\' ) {
477 servername = canon_servername(handlename);
478 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
482 if (!is_myname_or_ipaddr(servername)) {
486 fstrcpy(Printer->servername, servername);
489 if (Printer->printer_type == SPLHND_SERVER) {
493 if (Printer->printer_type != SPLHND_PRINTER) {
497 DEBUGADD(5, ("searching for [%s]\n", aprinter));
499 /* check for the Port Monitor Interface */
500 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
501 Printer->printer_type = SPLHND_PORTMON_TCP;
502 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
505 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
506 Printer->printer_type = SPLHND_PORTMON_LOCAL;
507 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
511 /* Search all sharenames first as this is easier than pulling
512 the printer_info_2 off of disk. Don't use find_service() since
513 that calls out to map_username() */
515 /* do another loop to look for printernames */
516 for (snum = 0; !found && snum < n_services; snum++) {
517 const char *printer = lp_const_servicename(snum);
519 /* no point going on if this is not a printer */
520 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
524 /* ignore [printers] share */
525 if (strequal(printer, "printers")) {
529 fstrcpy(sname, printer);
530 if (strequal(aprinter, printer)) {
535 /* no point looking up the printer object if
536 we aren't allowing printername != sharename */
537 if (lp_force_printername(snum)) {
541 result = winreg_get_printer(mem_ctx,
547 if ( !W_ERROR_IS_OK(result) ) {
548 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
549 sname, win_errstr(result)));
553 printername = strrchr(info2->printername, '\\');
554 if (printername == NULL) {
555 printername = info2->printername;
560 if (strequal(printername, aprinter)) {
565 DEBUGADD(10, ("printername: %s\n", printername));
571 DEBUGADD(4,("Printer not found\n"));
575 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
577 fstrcpy(Printer->sharename, sname);
582 /****************************************************************************
583 Find first available printer slot. creates a printer handle for you.
584 ****************************************************************************/
586 static bool open_printer_hnd(struct pipes_struct *p, struct policy_handle *hnd,
587 const char *name, uint32_t access_granted)
589 Printer_entry *new_printer;
591 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
593 new_printer = TALLOC_ZERO_P(NULL, Printer_entry);
594 if (new_printer == NULL) {
597 talloc_set_destructor(new_printer, printer_entry_destructor);
599 if (!create_policy_hnd(p, hnd, new_printer)) {
600 TALLOC_FREE(new_printer);
604 /* Add to the internal list. */
605 DLIST_ADD(printers_list, new_printer);
607 new_printer->notify.option=NULL;
609 if (!set_printer_hnd_printertype(new_printer, name)) {
610 close_printer_handle(p, hnd);
614 if (!set_printer_hnd_name(p->mem_ctx, p->server_info, p->msg_ctx,
615 new_printer, name)) {
616 close_printer_handle(p, hnd);
620 new_printer->access_granted = access_granted;
622 DEBUG(5, ("%d printer handles active\n",
623 (int)num_pipe_handles(p)));
628 /***************************************************************************
629 check to see if the client motify handle is monitoring the notification
630 given by (notify_type, notify_field).
631 **************************************************************************/
633 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
634 uint16_t notify_field)
639 static bool is_monitoring_event(Printer_entry *p, uint16_t notify_type,
640 uint16_t notify_field)
642 struct spoolss_NotifyOption *option = p->notify.option;
646 * Flags should always be zero when the change notify
647 * is registered by the client's spooler. A user Win32 app
648 * might use the flags though instead of the NOTIFY_OPTION_INFO
657 return is_monitoring_event_flags(
658 p->notify.flags, notify_type, notify_field);
660 for (i = 0; i < option->count; i++) {
662 /* Check match for notify_type */
664 if (option->types[i].type != notify_type)
667 /* Check match for field */
669 for (j = 0; j < option->types[i].count; j++) {
670 if (option->types[i].fields[j].field == notify_field) {
676 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
677 p->servername, p->sharename, notify_type, notify_field));
682 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
683 _data->data.integer[0] = _integer; \
684 _data->data.integer[1] = 0;
687 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
688 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
689 if (!_data->data.string.string) {\
690 _data->data.string.size = 0; \
692 _data->data.string.size = strlen_m_term(_p) * 2;
694 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
695 _data->data.devmode.devmode = _devmode;
697 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
698 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
699 if (!_data->data.sd.sd) { \
700 _data->data.sd.sd_size = 0; \
702 _data->data.sd.sd_size = \
703 ndr_size_security_descriptor(_data->data.sd.sd, 0);
705 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
710 struct spoolss_Time st;
714 if (!init_systemtime(&st, t)) {
718 p = talloc_array(mem_ctx, char, len);
724 * Systemtime must be linearized as a set of UINT16's.
725 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
728 SSVAL(p, 0, st.year);
729 SSVAL(p, 2, st.month);
730 SSVAL(p, 4, st.day_of_week);
732 SSVAL(p, 8, st.hour);
733 SSVAL(p, 10, st.minute);
734 SSVAL(p, 12, st.second);
735 SSVAL(p, 14, st.millisecond);
741 /* Convert a notification message to a struct spoolss_Notify */
743 static void notify_one_value(struct spoolss_notify_msg *msg,
744 struct spoolss_Notify *data,
747 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
750 static void notify_string(struct spoolss_notify_msg *msg,
751 struct spoolss_Notify *data,
754 /* The length of the message includes the trailing \0 */
756 data->data.string.size = msg->len * 2;
757 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
758 if (!data->data.string.string) {
759 data->data.string.size = 0;
764 static void notify_system_time(struct spoolss_notify_msg *msg,
765 struct spoolss_Notify *data,
768 data->data.string.string = NULL;
769 data->data.string.size = 0;
771 if (msg->len != sizeof(time_t)) {
772 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
777 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
778 &data->data.string.string,
779 &data->data.string.size);
782 struct notify2_message_table {
784 void (*fn)(struct spoolss_notify_msg *msg,
785 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
788 static struct notify2_message_table printer_notify_table[] = {
789 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
790 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
791 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
792 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
793 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
794 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
795 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
796 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
797 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
798 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
799 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
800 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
801 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
802 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
803 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
804 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
805 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
806 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
807 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
810 static struct notify2_message_table job_notify_table[] = {
811 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
812 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
813 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
814 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
815 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
816 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
817 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
818 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
819 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
820 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
821 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
822 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
823 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
824 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
825 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
826 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
827 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
828 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
829 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
830 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
831 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
832 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
833 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
834 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
838 /***********************************************************************
839 Allocate talloc context for container object
840 **********************************************************************/
842 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
847 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
852 /***********************************************************************
853 release all allocated memory and zero out structure
854 **********************************************************************/
856 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
862 talloc_destroy(ctr->ctx);
869 /***********************************************************************
870 **********************************************************************/
872 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
880 /***********************************************************************
881 **********************************************************************/
883 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
885 if ( !ctr || !ctr->msg_groups )
888 if ( idx >= ctr->num_groups )
891 return &ctr->msg_groups[idx];
895 /***********************************************************************
896 How many groups of change messages do we have ?
897 **********************************************************************/
899 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
904 return ctr->num_groups;
907 /***********************************************************************
908 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
909 **********************************************************************/
911 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
913 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
914 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
915 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
921 /* loop over all groups looking for a matching printer name */
923 for ( i=0; i<ctr->num_groups; i++ ) {
924 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
928 /* add a new group? */
930 if ( i == ctr->num_groups ) {
933 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
934 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
937 ctr->msg_groups = groups;
939 /* clear the new entry and set the printer name */
941 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
942 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
945 /* add the change messages; 'i' is the correct index now regardless */
947 msg_grp = &ctr->msg_groups[i];
951 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
952 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
955 msg_grp->msgs = msg_list;
957 new_slot = msg_grp->num_msgs-1;
958 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
960 /* need to allocate own copy of data */
963 msg_grp->msgs[new_slot].notify.data = (char *)
964 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
966 return ctr->num_groups;
969 static void construct_info_data(struct spoolss_Notify *info_data,
970 enum spoolss_NotifyType type,
971 uint16_t field, int id);
973 /***********************************************************************
974 Send a change notication message on all handles which have a call
976 **********************************************************************/
978 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
981 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
982 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
983 SPOOLSS_NOTIFY_MSG *messages;
984 int sending_msg_count;
987 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
991 messages = msg_group->msgs;
994 DEBUG(5,("send_notify2_changes() called with no messages!\n"));
998 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
1000 /* loop over all printers */
1002 for (p = printers_list; p; p = p->next) {
1003 struct spoolss_Notify *notifies;
1008 /* Is there notification on this handle? */
1010 if ( !p->notify.client_connected )
1013 DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
1015 /* For this printer? Print servers always receive
1018 if ( ( p->printer_type == SPLHND_PRINTER ) &&
1019 ( !strequal(msg_group->printername, p->sharename) ) )
1022 DEBUG(10,("Our printer\n"));
1024 /* allocate the max entries possible */
1026 notifies = TALLOC_ZERO_ARRAY(mem_ctx, struct spoolss_Notify, msg_group->num_msgs);
1031 /* build the array of change notifications */
1033 sending_msg_count = 0;
1035 for ( i=0; i<msg_group->num_msgs; i++ ) {
1036 SPOOLSS_NOTIFY_MSG *msg = &messages[i];
1038 /* Are we monitoring this event? */
1040 if (!is_monitoring_event(p, msg->type, msg->field))
1043 sending_msg_count++;
1046 DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
1047 msg->type, msg->field, p->sharename));
1050 * if the is a printer notification handle and not a job notification
1051 * type, then set the id to 0. Other wise just use what was specified
1054 * When registering change notification on a print server handle
1055 * we always need to send back the id (snum) matching the printer
1056 * for which the change took place. For change notify registered
1057 * on a printer handle, this does not matter and the id should be 0.
1062 if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
1068 /* Convert unix jobid to smb jobid */
1070 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1071 id = sysjob_to_jobid(msg->id);
1074 DEBUG(3, ("no such unix jobid %d\n", msg->id));
1079 construct_info_data( ¬ifies[count], msg->type, msg->field, id );
1082 case PRINTER_NOTIFY_TYPE:
1083 if ( printer_notify_table[msg->field].fn )
1084 printer_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1087 case JOB_NOTIFY_TYPE:
1088 if ( job_notify_table[msg->field].fn )
1089 job_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1093 DEBUG(5, ("Unknown notification type %d\n", msg->type));
1100 if ( sending_msg_count ) {
1103 union spoolss_ReplyPrinterInfo info;
1104 struct spoolss_NotifyInfo info0;
1105 uint32_t reply_result;
1107 info0.version = 0x2;
1108 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1109 info0.count = count;
1110 info0.notifies = notifies;
1112 info.info0 = &info0;
1114 status = rpccli_spoolss_RouterReplyPrinterEx(notify_cli_pipe, mem_ctx,
1115 &p->notify.client_hnd,
1116 p->notify.change, /* color */
1119 0, /* reply_type, must be 0 */
1122 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1123 DEBUG(1,("RouterReplyPrinterEx to client: %s failed: %s\n",
1124 notify_cli_pipe->srv_name_slash,
1127 switch (reply_result) {
1130 case PRINTER_NOTIFY_INFO_DISCARDED:
1131 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1132 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1141 DEBUG(8,("send_notify2_changes: Exit...\n"));
1145 /***********************************************************************
1146 **********************************************************************/
1148 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1151 uint32_t tv_sec, tv_usec;
1154 /* Unpack message */
1156 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1159 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1161 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1164 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1165 &msg->notify.value[0], &msg->notify.value[1]);
1167 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1168 &msg->len, &msg->notify.data);
1170 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1171 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1173 tv->tv_sec = tv_sec;
1174 tv->tv_usec = tv_usec;
1177 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1178 msg->notify.value[1]));
1180 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1185 /********************************************************************
1186 Receive a notify2 message list
1187 ********************************************************************/
1189 static void receive_notify2_message_list(struct messaging_context *msg,
1192 struct server_id server_id,
1195 size_t msg_count, i;
1196 char *buf = (char *)data->data;
1199 SPOOLSS_NOTIFY_MSG notify;
1200 SPOOLSS_NOTIFY_MSG_CTR messages;
1203 if (data->length < 4) {
1204 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1208 msg_count = IVAL(buf, 0);
1211 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1213 if (msg_count == 0) {
1214 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1218 /* initialize the container */
1220 ZERO_STRUCT( messages );
1221 notify_msg_ctr_init( &messages );
1224 * build message groups for each printer identified
1225 * in a change_notify msg. Remember that a PCN message
1226 * includes the handle returned for the srv_spoolss_replyopenprinter()
1227 * call. Therefore messages are grouped according to printer handle.
1230 for ( i=0; i<msg_count; i++ ) {
1231 struct timeval msg_tv;
1233 if (msg_ptr + 4 - buf > data->length) {
1234 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1238 msg_len = IVAL(msg_ptr,0);
1241 if (msg_ptr + msg_len - buf > data->length) {
1242 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1246 /* unpack messages */
1248 ZERO_STRUCT( notify );
1249 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1252 /* add to correct list in container */
1254 notify_msg_ctr_addmsg( &messages, ¬ify );
1256 /* free memory that might have been allocated by notify2_unpack_msg() */
1258 if ( notify.len != 0 )
1259 SAFE_FREE( notify.notify.data );
1262 /* process each group of messages */
1264 num_groups = notify_msg_ctr_numgroups( &messages );
1265 for ( i=0; i<num_groups; i++ )
1266 send_notify2_changes( &messages, i );
1271 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1272 (uint32_t)msg_count ));
1274 notify_msg_ctr_destroy( &messages );
1279 /********************************************************************
1280 Send a message to ourself about new driver being installed
1281 so we can upgrade the information for each printer bound to this
1283 ********************************************************************/
1285 static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
1286 struct messaging_context *msg_ctx)
1288 int len = strlen(drivername);
1293 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1296 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
1297 MSG_PRINTER_DRVUPGRADE,
1298 (uint8_t *)drivername, len+1);
1303 /**********************************************************************
1304 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1305 over all printers, upgrading ones as necessary
1306 **********************************************************************/
1308 void do_drv_upgrade_printer(struct messaging_context *msg,
1311 struct server_id server_id,
1314 TALLOC_CTX *tmp_ctx;
1315 struct auth_serversupplied_info *server_info = NULL;
1316 struct spoolss_PrinterInfo2 *pinfo2;
1319 const char *drivername;
1321 int n_services = lp_numservices();
1324 tmp_ctx = talloc_new(NULL);
1325 if (!tmp_ctx) return;
1327 status = make_server_info_system(tmp_ctx, &server_info);
1328 if (!NT_STATUS_IS_OK(status)) {
1329 DEBUG(0, ("do_drv_upgrade_printer: "
1330 "Could not create system server_info\n"));
1334 len = MIN(data->length,sizeof(drivername)-1);
1335 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, len);
1337 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1341 DEBUG(10, ("do_drv_upgrade_printer: "
1342 "Got message for new driver [%s]\n", drivername));
1344 /* Iterate the printer list */
1346 for (snum = 0; snum < n_services; snum++) {
1347 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1351 result = winreg_get_printer(tmp_ctx, server_info, msg,
1353 lp_const_servicename(snum),
1356 if (!W_ERROR_IS_OK(result)) {
1360 if (!pinfo2->drivername) {
1364 if (strcmp(drivername, pinfo2->drivername) != 0) {
1368 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1370 /* all we care about currently is the change_id */
1371 result = winreg_printer_update_changeid(tmp_ctx,
1374 pinfo2->printername);
1376 if (!W_ERROR_IS_OK(result)) {
1377 DEBUG(3, ("do_drv_upgrade_printer: "
1378 "Failed to update changeid [%s]\n",
1379 win_errstr(result)));
1385 talloc_free(tmp_ctx);
1388 /********************************************************************
1389 Update the cache for all printq's with a registered client
1391 ********************************************************************/
1393 void update_monitored_printq_cache( void )
1395 Printer_entry *printer = printers_list;
1398 /* loop through all printers and update the cache where
1399 client_connected == true */
1402 if ( (printer->printer_type == SPLHND_PRINTER)
1403 && printer->notify.client_connected )
1405 snum = print_queue_snum(printer->sharename);
1406 print_queue_status( snum, NULL, NULL );
1409 printer = printer->next;
1415 /****************************************************************
1416 _spoolss_OpenPrinter
1417 ****************************************************************/
1419 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1420 struct spoolss_OpenPrinter *r)
1422 struct spoolss_OpenPrinterEx e;
1425 ZERO_STRUCT(e.in.userlevel);
1427 e.in.printername = r->in.printername;
1428 e.in.datatype = r->in.datatype;
1429 e.in.devmode_ctr = r->in.devmode_ctr;
1430 e.in.access_mask = r->in.access_mask;
1433 e.out.handle = r->out.handle;
1435 werr = _spoolss_OpenPrinterEx(p, &e);
1437 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1438 /* OpenPrinterEx returns this for a bad
1439 * printer name. We must return WERR_INVALID_PRINTER_NAME
1442 werr = WERR_INVALID_PRINTER_NAME;
1448 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1449 struct spoolss_DeviceMode *orig,
1450 struct spoolss_DeviceMode **dest)
1452 struct spoolss_DeviceMode *dm;
1454 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1459 /* copy all values, then duplicate strings and structs */
1462 dm->devicename = talloc_strdup(dm, orig->devicename);
1463 if (!dm->devicename) {
1466 dm->formname = talloc_strdup(dm, orig->formname);
1467 if (!dm->formname) {
1470 if (orig->driverextra_data.data) {
1471 dm->driverextra_data.data =
1472 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1473 orig->driverextra_data.length);
1474 if (!dm->driverextra_data.data) {
1483 /****************************************************************
1484 _spoolss_OpenPrinterEx
1485 ****************************************************************/
1487 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1488 struct spoolss_OpenPrinterEx *r)
1491 Printer_entry *Printer=NULL;
1493 if (!r->in.printername) {
1494 return WERR_INVALID_PARAM;
1497 /* some sanity check because you can open a printer or a print server */
1498 /* aka: \\server\printer or \\server */
1500 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1502 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1503 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1504 " for printer %s\n", r->in.printername));
1505 ZERO_STRUCTP(r->out.handle);
1506 return WERR_INVALID_PARAM;
1509 Printer = find_printer_index_by_hnd(p, r->out.handle);
1511 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1512 "handle we created for printer %s\n", r->in.printername));
1513 close_printer_handle(p, r->out.handle);
1514 ZERO_STRUCTP(r->out.handle);
1515 return WERR_INVALID_PARAM;
1519 * First case: the user is opening the print server:
1521 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1522 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1524 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1525 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1526 * or if the user is listed in the smb.conf printer admin parameter.
1528 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1529 * client view printer folder, but does not show the MSAPW.
1531 * Note: this test needs code to check access rights here too. Jeremy
1532 * could you look at this?
1534 * Second case: the user is opening a printer:
1535 * NT doesn't let us connect to a printer if the connecting user
1536 * doesn't have print permission.
1538 * Third case: user is opening a Port Monitor
1539 * access checks same as opening a handle to the print server.
1542 switch (Printer->printer_type )
1545 case SPLHND_PORTMON_TCP:
1546 case SPLHND_PORTMON_LOCAL:
1547 /* Printserver handles use global struct... */
1551 /* Map standard access rights to object specific access rights */
1553 se_map_standard(&r->in.access_mask,
1554 &printserver_std_mapping);
1556 /* Deny any object specific bits that don't apply to print
1557 servers (i.e printer and job specific bits) */
1559 r->in.access_mask &= SEC_MASK_SPECIFIC;
1561 if (r->in.access_mask &
1562 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1563 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1564 close_printer_handle(p, r->out.handle);
1565 ZERO_STRUCTP(r->out.handle);
1566 return WERR_ACCESS_DENIED;
1569 /* Allow admin access */
1571 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1573 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1575 if (!lp_ms_add_printer_wizard()) {
1576 close_printer_handle(p, r->out.handle);
1577 ZERO_STRUCTP(r->out.handle);
1578 return WERR_ACCESS_DENIED;
1581 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1582 and not a printer admin, then fail */
1584 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1585 !user_has_privileges(p->server_info->ptok,
1587 !token_contains_name_in_list(
1588 uidtoname(p->server_info->utok.uid),
1589 p->server_info->info3->base.domain.string,
1591 p->server_info->ptok,
1592 lp_printer_admin(snum))) {
1593 close_printer_handle(p, r->out.handle);
1594 ZERO_STRUCTP(r->out.handle);
1595 return WERR_ACCESS_DENIED;
1598 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1602 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1605 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1606 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1608 /* We fall through to return WERR_OK */
1611 case SPLHND_PRINTER:
1612 /* NT doesn't let us connect to a printer if the connecting user
1613 doesn't have print permission. */
1615 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1616 close_printer_handle(p, r->out.handle);
1617 ZERO_STRUCTP(r->out.handle);
1621 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1622 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1625 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1627 /* map an empty access mask to the minimum access mask */
1628 if (r->in.access_mask == 0x0)
1629 r->in.access_mask = PRINTER_ACCESS_USE;
1632 * If we are not serving the printer driver for this printer,
1633 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1634 * will keep NT clients happy --jerry
1637 if (lp_use_client_driver(snum)
1638 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1640 r->in.access_mask = PRINTER_ACCESS_USE;
1643 /* check smb.conf parameters and the the sec_desc */
1645 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1646 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1647 ZERO_STRUCTP(r->out.handle);
1648 return WERR_ACCESS_DENIED;
1651 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1652 p->server_info->ptok, snum) ||
1653 !print_access_check(p->server_info, p->msg_ctx, snum,
1654 r->in.access_mask)) {
1655 DEBUG(3, ("access DENIED for printer open\n"));
1656 close_printer_handle(p, r->out.handle);
1657 ZERO_STRUCTP(r->out.handle);
1658 return WERR_ACCESS_DENIED;
1661 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1662 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1663 close_printer_handle(p, r->out.handle);
1664 ZERO_STRUCTP(r->out.handle);
1665 return WERR_ACCESS_DENIED;
1668 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1669 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1671 r->in.access_mask = PRINTER_ACCESS_USE;
1673 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1674 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1676 winreg_create_printer(p->mem_ctx,
1679 Printer->servername,
1680 lp_const_servicename(snum));
1685 /* sanity check to prevent programmer error */
1686 ZERO_STRUCTP(r->out.handle);
1690 Printer->access_granted = r->in.access_mask;
1693 * If the client sent a devmode in the OpenPrinter() call, then
1694 * save it here in case we get a job submission on this handle
1697 if ((Printer->printer_type != SPLHND_SERVER) &&
1698 r->in.devmode_ctr.devmode) {
1699 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1703 #if 0 /* JERRY -- I'm doubtful this is really effective */
1704 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1705 optimization in Windows 2000 clients --jerry */
1707 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1708 && (RA_WIN2K == get_remote_arch()) )
1710 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1711 sys_usleep( 500000 );
1718 /****************************************************************
1719 _spoolss_ClosePrinter
1720 ****************************************************************/
1722 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1723 struct spoolss_ClosePrinter *r)
1725 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1727 if (Printer && Printer->document_started) {
1728 struct spoolss_EndDocPrinter e;
1730 e.in.handle = r->in.handle;
1732 _spoolss_EndDocPrinter(p, &e);
1735 if (!close_printer_handle(p, r->in.handle))
1738 /* clear the returned printer handle. Observed behavior
1739 from Win2k server. Don't think this really matters.
1740 Previous code just copied the value of the closed
1743 ZERO_STRUCTP(r->out.handle);
1748 /****************************************************************
1749 _spoolss_DeletePrinter
1750 ****************************************************************/
1752 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1753 struct spoolss_DeletePrinter *r)
1755 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1759 if (Printer && Printer->document_started) {
1760 struct spoolss_EndDocPrinter e;
1762 e.in.handle = r->in.handle;
1764 _spoolss_EndDocPrinter(p, &e);
1767 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
1768 winreg_delete_printer_key(p->mem_ctx,
1771 lp_const_servicename(snum),
1775 result = delete_printer_handle(p, r->in.handle);
1780 /*******************************************************************
1781 * static function to lookup the version id corresponding to an
1782 * long architecture string
1783 ******************************************************************/
1785 static const struct print_architecture_table_node archi_table[]= {
1787 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1788 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1789 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1790 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
1791 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
1792 {"Windows IA64", SPL_ARCH_IA64, 3 },
1793 {"Windows x64", SPL_ARCH_X64, 3 },
1797 static int get_version_id(const char *arch)
1801 for (i=0; archi_table[i].long_archi != NULL; i++)
1803 if (strcmp(arch, archi_table[i].long_archi) == 0)
1804 return (archi_table[i].version);
1810 /****************************************************************
1811 _spoolss_DeletePrinterDriver
1812 ****************************************************************/
1814 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
1815 struct spoolss_DeletePrinterDriver *r)
1818 struct spoolss_DriverInfo8 *info = NULL;
1819 struct spoolss_DriverInfo8 *info_win2k = NULL;
1822 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1824 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1825 and not a printer admin, then fail */
1827 if ( (p->server_info->utok.uid != sec_initial_uid())
1828 && !user_has_privileges(p->server_info->ptok, &se_printop )
1829 && !token_contains_name_in_list(
1830 uidtoname(p->server_info->utok.uid),
1831 p->server_info->info3->base.domain.string,
1833 p->server_info->ptok,
1834 lp_printer_admin(-1)) )
1836 return WERR_ACCESS_DENIED;
1839 /* check that we have a valid driver name first */
1841 if ((version = get_version_id(r->in.architecture)) == -1)
1842 return WERR_INVALID_ENVIRONMENT;
1844 status = winreg_get_driver(p->mem_ctx, p->server_info, p->msg_ctx,
1845 r->in.architecture, r->in.driver,
1847 if (!W_ERROR_IS_OK(status)) {
1848 /* try for Win2k driver if "Windows NT x86" */
1850 if ( version == 2 ) {
1853 status = winreg_get_driver(p->mem_ctx, p->server_info,
1858 if (!W_ERROR_IS_OK(status)) {
1859 status = WERR_UNKNOWN_PRINTER_DRIVER;
1863 /* otherwise it was a failure */
1865 status = WERR_UNKNOWN_PRINTER_DRIVER;
1871 if (printer_driver_in_use(p->mem_ctx, p->server_info, p->msg_ctx,
1873 status = WERR_PRINTER_DRIVER_IN_USE;
1878 status = winreg_get_driver(p->mem_ctx, p->server_info,
1881 r->in.driver, 3, &info_win2k);
1882 if (W_ERROR_IS_OK(status)) {
1883 /* if we get to here, we now have 2 driver info structures to remove */
1884 /* remove the Win2k driver first*/
1886 status = winreg_del_driver(p->mem_ctx,
1890 talloc_free(info_win2k);
1892 /* this should not have failed---if it did, report to client */
1893 if (!W_ERROR_IS_OK(status)) {
1899 status = winreg_del_driver(p->mem_ctx, p->server_info, p->msg_ctx,
1908 /****************************************************************
1909 _spoolss_DeletePrinterDriverEx
1910 ****************************************************************/
1912 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
1913 struct spoolss_DeletePrinterDriverEx *r)
1915 struct spoolss_DriverInfo8 *info = NULL;
1916 struct spoolss_DriverInfo8 *info_win2k = NULL;
1920 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1922 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1923 and not a printer admin, then fail */
1925 if ( (p->server_info->utok.uid != sec_initial_uid())
1926 && !user_has_privileges(p->server_info->ptok, &se_printop )
1927 && !token_contains_name_in_list(
1928 uidtoname(p->server_info->utok.uid),
1929 p->server_info->info3->base.domain.string,
1931 p->server_info->ptok, lp_printer_admin(-1)) )
1933 return WERR_ACCESS_DENIED;
1936 /* check that we have a valid driver name first */
1937 if ((version = get_version_id(r->in.architecture)) == -1) {
1938 /* this is what NT returns */
1939 return WERR_INVALID_ENVIRONMENT;
1942 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
1943 version = r->in.version;
1945 status = winreg_get_driver(p->mem_ctx, p->server_info,
1946 p->msg_ctx, r->in.architecture,
1947 r->in.driver, version, &info);
1948 if (!W_ERROR_IS_OK(status)) {
1949 status = WERR_UNKNOWN_PRINTER_DRIVER;
1952 * if the client asked for a specific version,
1953 * or this is something other than Windows NT x86,
1957 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
1960 /* try for Win2k driver if "Windows NT x86" */
1963 status = winreg_get_driver(info, p->server_info, p->msg_ctx,
1967 if (!W_ERROR_IS_OK(status)) {
1968 status = WERR_UNKNOWN_PRINTER_DRIVER;
1973 if (printer_driver_in_use(info, p->server_info, p->msg_ctx, info)) {
1974 status = WERR_PRINTER_DRIVER_IN_USE;
1979 * we have a couple of cases to consider.
1980 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
1981 * then the delete should fail if **any** files overlap with
1983 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
1984 * non-overlapping files
1985 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
1986 * is set, the do not delete any files
1987 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
1990 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
1992 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
1995 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
1996 printer_driver_files_in_use(info, p->server_info, p->msg_ctx,
1998 /* no idea of the correct error here */
1999 status = WERR_ACCESS_DENIED;
2004 /* also check for W32X86/3 if necessary; maybe we already have? */
2006 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2007 status = winreg_get_driver(info, p->server_info, p->msg_ctx,
2009 r->in.driver, 3, &info_win2k);
2010 if (W_ERROR_IS_OK(status)) {
2013 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2014 printer_driver_files_in_use(info, p->server_info,
2017 /* no idea of the correct error here */
2018 talloc_free(info_win2k);
2019 status = WERR_ACCESS_DENIED;
2023 /* if we get to here, we now have 2 driver info structures to remove */
2024 /* remove the Win2k driver first*/
2026 status = winreg_del_driver(info, p->server_info,
2027 p->msg_ctx, info_win2k, 3);
2029 /* this should not have failed---if it did, report to client */
2031 if (!W_ERROR_IS_OK(status)) {
2036 * now delete any associated files if delete_files is
2037 * true. Even if this part failes, we return succes
2038 * because the driver doesn not exist any more
2041 delete_driver_files(p->server_info,
2047 status = winreg_del_driver(info, p->server_info, p->msg_ctx, info,
2049 if (!W_ERROR_IS_OK(status)) {
2054 * now delete any associated files if delete_files is
2055 * true. Even if this part failes, we return succes
2056 * because the driver doesn not exist any more
2059 delete_driver_files(p->server_info, info);
2068 /********************************************************************
2069 GetPrinterData on a printer server Handle.
2070 ********************************************************************/
2072 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2074 enum winreg_Type *type,
2075 union spoolss_PrinterData *data)
2077 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2079 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2085 if (!StrCaseCmp(value, "BeepEnabled")) {
2091 if (!StrCaseCmp(value, "EventLog")) {
2093 /* formally was 0x1b */
2098 if (!StrCaseCmp(value, "NetPopup")) {
2104 if (!StrCaseCmp(value, "MajorVersion")) {
2107 /* Windows NT 4.0 seems to not allow uploading of drivers
2108 to a server that reports 0x3 as the MajorVersion.
2109 need to investigate more how Win2k gets around this .
2112 if (RA_WINNT == get_remote_arch()) {
2121 if (!StrCaseCmp(value, "MinorVersion")) {
2128 * uint32_t size = 0x114
2129 * uint32_t major = 5
2130 * uint32_t minor = [0|1]
2131 * uint32_t build = [2195|2600]
2132 * extra unicode string = e.g. "Service Pack 3"
2134 if (!StrCaseCmp(value, "OSVersion")) {
2136 enum ndr_err_code ndr_err;
2137 struct spoolss_OSVersion os;
2139 os.major = 5; /* Windows 2000 == 5.0 */
2141 os.build = 2195; /* build */
2142 os.extra_string = ""; /* leave extra string empty */
2144 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2145 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2146 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2147 return WERR_GENERAL_FAILURE;
2151 data->binary = blob;
2157 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2160 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2161 W_ERROR_HAVE_NO_MEMORY(data->string);
2166 if (!StrCaseCmp(value, "Architecture")) {
2168 data->string = talloc_strdup(mem_ctx,
2169 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2170 W_ERROR_HAVE_NO_MEMORY(data->string);
2175 if (!StrCaseCmp(value, "DsPresent")) {
2178 /* only show the publish check box if we are a
2179 member of a AD domain */
2181 if (lp_security() == SEC_ADS) {
2189 if (!StrCaseCmp(value, "DNSMachineName")) {
2190 const char *hostname = get_mydnsfullname();
2193 return WERR_BADFILE;
2197 data->string = talloc_strdup(mem_ctx, hostname);
2198 W_ERROR_HAVE_NO_MEMORY(data->string);
2205 return WERR_INVALID_PARAM;
2208 /****************************************************************
2209 _spoolss_GetPrinterData
2210 ****************************************************************/
2212 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2213 struct spoolss_GetPrinterData *r)
2215 struct spoolss_GetPrinterDataEx r2;
2217 r2.in.handle = r->in.handle;
2218 r2.in.key_name = "PrinterDriverData";
2219 r2.in.value_name = r->in.value_name;
2220 r2.in.offered = r->in.offered;
2221 r2.out.type = r->out.type;
2222 r2.out.data = r->out.data;
2223 r2.out.needed = r->out.needed;
2225 return _spoolss_GetPrinterDataEx(p, &r2);
2228 /*********************************************************
2229 Connect to the client machine.
2230 **********************************************************/
2232 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2233 struct sockaddr_storage *client_ss, const char *remote_machine)
2236 struct cli_state *the_cli;
2237 struct sockaddr_storage rm_addr;
2238 char addr[INET6_ADDRSTRLEN];
2240 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2241 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2243 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2244 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2247 print_sockaddr(addr, sizeof(addr), &rm_addr);
2249 rm_addr = *client_ss;
2250 print_sockaddr(addr, sizeof(addr), &rm_addr);
2251 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2255 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2256 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2261 /* setup the connection */
2262 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2263 &rm_addr, 0, "IPC$", "IPC",
2267 0, lp_client_signing(), NULL );
2269 if ( !NT_STATUS_IS_OK( ret ) ) {
2270 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2275 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2276 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2277 cli_shutdown(the_cli);
2282 * Ok - we have an anonymous connection to the IPC$ share.
2283 * Now start the NT Domain stuff :-).
2286 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2287 if (!NT_STATUS_IS_OK(ret)) {
2288 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2289 remote_machine, nt_errstr(ret)));
2290 cli_shutdown(the_cli);
2297 /***************************************************************************
2298 Connect to the client.
2299 ****************************************************************************/
2301 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2302 uint32_t localprinter, uint32_t type,
2303 struct policy_handle *handle,
2304 struct sockaddr_storage *client_ss,
2305 struct messaging_context *msg_ctx)
2311 * If it's the first connection, contact the client
2312 * and connect to the IPC$ share anonymously
2314 if (smb_connections==0) {
2315 fstring unix_printer;
2317 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2319 if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ss, unix_printer ))
2322 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2323 receive_notify2_message_list);
2324 /* Tell the connections db we're now interested in printer
2325 * notify messages. */
2326 serverid_register_msg_flags(messaging_server_id(msg_ctx),
2327 true, FLAG_MSG_PRINT_NOTIFY);
2331 * Tell the specific printing tdb we want messages for this printer
2332 * by registering our PID.
2335 if (!print_notify_register_pid(snum))
2336 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2340 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2348 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2349 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2350 win_errstr(result)));
2352 return (W_ERROR_IS_OK(result));
2355 /****************************************************************
2356 ****************************************************************/
2358 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2359 const struct spoolss_NotifyOption *r)
2361 struct spoolss_NotifyOption *option;
2368 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2375 if (!option->count) {
2379 option->types = talloc_zero_array(option,
2380 struct spoolss_NotifyOptionType, option->count);
2381 if (!option->types) {
2382 talloc_free(option);
2386 for (i=0; i < option->count; i++) {
2387 option->types[i] = r->types[i];
2389 if (option->types[i].count) {
2390 option->types[i].fields = talloc_zero_array(option,
2391 union spoolss_Field, option->types[i].count);
2392 if (!option->types[i].fields) {
2393 talloc_free(option);
2396 for (k=0; k<option->types[i].count; k++) {
2397 option->types[i].fields[k] =
2398 r->types[i].fields[k];
2406 /****************************************************************
2407 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2409 * before replying OK: status=0 a rpc call is made to the workstation
2410 * asking ReplyOpenPrinter
2412 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2413 * called from api_spoolss_rffpcnex
2414 ****************************************************************/
2416 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2417 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2420 struct spoolss_NotifyOption *option = r->in.notify_options;
2421 struct sockaddr_storage client_ss;
2423 /* store the notify value in the printer struct */
2425 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2428 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2429 "Invalid handle (%s:%u:%u).\n",
2430 OUR_HANDLE(r->in.handle)));
2434 Printer->notify.flags = r->in.flags;
2435 Printer->notify.options = r->in.options;
2436 Printer->notify.printerlocal = r->in.printer_local;
2437 Printer->notify.msg_ctx = p->msg_ctx;
2439 TALLOC_FREE(Printer->notify.option);
2440 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2442 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2444 /* Connect to the client machine and send a ReplyOpenPrinter */
2446 if ( Printer->printer_type == SPLHND_SERVER)
2448 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2449 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2452 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2453 "client_address is %s\n", p->client_address));
2455 if (!interpret_string_addr(&client_ss, p->client_address,
2457 return WERR_SERVER_UNAVAILABLE;
2460 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2461 Printer->notify.printerlocal, 1,
2462 &Printer->notify.client_hnd,
2463 &client_ss, p->msg_ctx))
2464 return WERR_SERVER_UNAVAILABLE;
2466 Printer->notify.client_connected = true;
2471 /*******************************************************************
2472 * fill a notify_info_data with the servername
2473 ********************************************************************/
2475 static void spoolss_notify_server_name(int snum,
2476 struct spoolss_Notify *data,
2477 print_queue_struct *queue,
2478 struct spoolss_PrinterInfo2 *pinfo2,
2479 TALLOC_CTX *mem_ctx)
2481 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2484 /*******************************************************************
2485 * fill a notify_info_data with the printername (not including the servername).
2486 ********************************************************************/
2488 static void spoolss_notify_printer_name(int snum,
2489 struct spoolss_Notify *data,
2490 print_queue_struct *queue,
2491 struct spoolss_PrinterInfo2 *pinfo2,
2492 TALLOC_CTX *mem_ctx)
2494 /* the notify name should not contain the \\server\ part */
2495 const char *p = strrchr(pinfo2->printername, '\\');
2498 p = pinfo2->printername;
2503 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2506 /*******************************************************************
2507 * fill a notify_info_data with the servicename
2508 ********************************************************************/
2510 static void spoolss_notify_share_name(int snum,
2511 struct spoolss_Notify *data,
2512 print_queue_struct *queue,
2513 struct spoolss_PrinterInfo2 *pinfo2,
2514 TALLOC_CTX *mem_ctx)
2516 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2519 /*******************************************************************
2520 * fill a notify_info_data with the port name
2521 ********************************************************************/
2523 static void spoolss_notify_port_name(int snum,
2524 struct spoolss_Notify *data,
2525 print_queue_struct *queue,
2526 struct spoolss_PrinterInfo2 *pinfo2,
2527 TALLOC_CTX *mem_ctx)
2529 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2532 /*******************************************************************
2533 * fill a notify_info_data with the printername
2534 * but it doesn't exist, have to see what to do
2535 ********************************************************************/
2537 static void spoolss_notify_driver_name(int snum,
2538 struct spoolss_Notify *data,
2539 print_queue_struct *queue,
2540 struct spoolss_PrinterInfo2 *pinfo2,
2541 TALLOC_CTX *mem_ctx)
2543 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2546 /*******************************************************************
2547 * fill a notify_info_data with the comment
2548 ********************************************************************/
2550 static void spoolss_notify_comment(int snum,
2551 struct spoolss_Notify *data,
2552 print_queue_struct *queue,
2553 struct spoolss_PrinterInfo2 *pinfo2,
2554 TALLOC_CTX *mem_ctx)
2558 if (*pinfo2->comment == '\0') {
2559 p = lp_comment(snum);
2561 p = pinfo2->comment;
2564 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2567 /*******************************************************************
2568 * fill a notify_info_data with the comment
2569 * location = "Room 1, floor 2, building 3"
2570 ********************************************************************/
2572 static void spoolss_notify_location(int snum,
2573 struct spoolss_Notify *data,
2574 print_queue_struct *queue,
2575 struct spoolss_PrinterInfo2 *pinfo2,
2576 TALLOC_CTX *mem_ctx)
2578 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
2581 /*******************************************************************
2582 * fill a notify_info_data with the device mode
2583 * jfm:xxxx don't to it for know but that's a real problem !!!
2584 ********************************************************************/
2586 static void spoolss_notify_devmode(int snum,
2587 struct spoolss_Notify *data,
2588 print_queue_struct *queue,
2589 struct spoolss_PrinterInfo2 *pinfo2,
2590 TALLOC_CTX *mem_ctx)
2592 /* for a dummy implementation we have to zero the fields */
2593 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2596 /*******************************************************************
2597 * fill a notify_info_data with the separator file name
2598 ********************************************************************/
2600 static void spoolss_notify_sepfile(int snum,
2601 struct spoolss_Notify *data,
2602 print_queue_struct *queue,
2603 struct spoolss_PrinterInfo2 *pinfo2,
2604 TALLOC_CTX *mem_ctx)
2606 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2609 /*******************************************************************
2610 * fill a notify_info_data with the print processor
2611 * jfm:xxxx return always winprint to indicate we don't do anything to it
2612 ********************************************************************/
2614 static void spoolss_notify_print_processor(int snum,
2615 struct spoolss_Notify *data,
2616 print_queue_struct *queue,
2617 struct spoolss_PrinterInfo2 *pinfo2,
2618 TALLOC_CTX *mem_ctx)
2620 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2623 /*******************************************************************
2624 * fill a notify_info_data with the print processor options
2625 * jfm:xxxx send an empty string
2626 ********************************************************************/
2628 static void spoolss_notify_parameters(int snum,
2629 struct spoolss_Notify *data,
2630 print_queue_struct *queue,
2631 struct spoolss_PrinterInfo2 *pinfo2,
2632 TALLOC_CTX *mem_ctx)
2634 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2637 /*******************************************************************
2638 * fill a notify_info_data with the data type
2639 * jfm:xxxx always send RAW as data type
2640 ********************************************************************/
2642 static void spoolss_notify_datatype(int snum,
2643 struct spoolss_Notify *data,
2644 print_queue_struct *queue,
2645 struct spoolss_PrinterInfo2 *pinfo2,
2646 TALLOC_CTX *mem_ctx)
2648 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2651 /*******************************************************************
2652 * fill a notify_info_data with the security descriptor
2653 * jfm:xxxx send an null pointer to say no security desc
2654 * have to implement security before !
2655 ********************************************************************/
2657 static void spoolss_notify_security_desc(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_SECDESC(data, pinfo2->secdesc);
2666 /*******************************************************************
2667 * fill a notify_info_data with the attributes
2668 * jfm:xxxx a samba printer is always shared
2669 ********************************************************************/
2671 static void spoolss_notify_attributes(int snum,
2672 struct spoolss_Notify *data,
2673 print_queue_struct *queue,
2674 struct spoolss_PrinterInfo2 *pinfo2,
2675 TALLOC_CTX *mem_ctx)
2677 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2680 /*******************************************************************
2681 * fill a notify_info_data with the priority
2682 ********************************************************************/
2684 static void spoolss_notify_priority(int snum,
2685 struct spoolss_Notify *data,
2686 print_queue_struct *queue,
2687 struct spoolss_PrinterInfo2 *pinfo2,
2688 TALLOC_CTX *mem_ctx)
2690 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2693 /*******************************************************************
2694 * fill a notify_info_data with the default priority
2695 ********************************************************************/
2697 static void spoolss_notify_default_priority(int snum,
2698 struct spoolss_Notify *data,
2699 print_queue_struct *queue,
2700 struct spoolss_PrinterInfo2 *pinfo2,
2701 TALLOC_CTX *mem_ctx)
2703 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
2706 /*******************************************************************
2707 * fill a notify_info_data with the start time
2708 ********************************************************************/
2710 static void spoolss_notify_start_time(int snum,
2711 struct spoolss_Notify *data,
2712 print_queue_struct *queue,
2713 struct spoolss_PrinterInfo2 *pinfo2,
2714 TALLOC_CTX *mem_ctx)
2716 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
2719 /*******************************************************************
2720 * fill a notify_info_data with the until time
2721 ********************************************************************/
2723 static void spoolss_notify_until_time(int snum,
2724 struct spoolss_Notify *data,
2725 print_queue_struct *queue,
2726 struct spoolss_PrinterInfo2 *pinfo2,
2727 TALLOC_CTX *mem_ctx)
2729 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
2732 /*******************************************************************
2733 * fill a notify_info_data with the status
2734 ********************************************************************/
2736 static void spoolss_notify_status(int snum,
2737 struct spoolss_Notify *data,
2738 print_queue_struct *queue,
2739 struct spoolss_PrinterInfo2 *pinfo2,
2740 TALLOC_CTX *mem_ctx)
2742 print_status_struct status;
2744 print_queue_length(snum, &status);
2745 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
2748 /*******************************************************************
2749 * fill a notify_info_data with the number of jobs queued
2750 ********************************************************************/
2752 static void spoolss_notify_cjobs(int snum,
2753 struct spoolss_Notify *data,
2754 print_queue_struct *queue,
2755 struct spoolss_PrinterInfo2 *pinfo2,
2756 TALLOC_CTX *mem_ctx)
2758 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
2761 /*******************************************************************
2762 * fill a notify_info_data with the average ppm
2763 ********************************************************************/
2765 static void spoolss_notify_average_ppm(int snum,
2766 struct spoolss_Notify *data,
2767 print_queue_struct *queue,
2768 struct spoolss_PrinterInfo2 *pinfo2,
2769 TALLOC_CTX *mem_ctx)
2771 /* always respond 8 pages per minutes */
2772 /* a little hard ! */
2773 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
2776 /*******************************************************************
2777 * fill a notify_info_data with username
2778 ********************************************************************/
2780 static void spoolss_notify_username(int snum,
2781 struct spoolss_Notify *data,
2782 print_queue_struct *queue,
2783 struct spoolss_PrinterInfo2 *pinfo2,
2784 TALLOC_CTX *mem_ctx)
2786 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
2789 /*******************************************************************
2790 * fill a notify_info_data with job status
2791 ********************************************************************/
2793 static void spoolss_notify_job_status(int snum,
2794 struct spoolss_Notify *data,
2795 print_queue_struct *queue,
2796 struct spoolss_PrinterInfo2 *pinfo2,
2797 TALLOC_CTX *mem_ctx)
2799 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
2802 /*******************************************************************
2803 * fill a notify_info_data with job name
2804 ********************************************************************/
2806 static void spoolss_notify_job_name(int snum,
2807 struct spoolss_Notify *data,
2808 print_queue_struct *queue,
2809 struct spoolss_PrinterInfo2 *pinfo2,
2810 TALLOC_CTX *mem_ctx)
2812 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
2815 /*******************************************************************
2816 * fill a notify_info_data with job status
2817 ********************************************************************/
2819 static void spoolss_notify_job_status_string(int snum,
2820 struct spoolss_Notify *data,
2821 print_queue_struct *queue,
2822 struct spoolss_PrinterInfo2 *pinfo2,
2823 TALLOC_CTX *mem_ctx)
2826 * Now we're returning job status codes we just return a "" here. JRA.
2831 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
2834 switch (queue->status) {
2839 p = ""; /* NT provides the paused string */
2848 #endif /* NO LONGER NEEDED. */
2850 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2853 /*******************************************************************
2854 * fill a notify_info_data with job time
2855 ********************************************************************/
2857 static void spoolss_notify_job_time(int snum,
2858 struct spoolss_Notify *data,
2859 print_queue_struct *queue,
2860 struct spoolss_PrinterInfo2 *pinfo2,
2861 TALLOC_CTX *mem_ctx)
2863 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2866 /*******************************************************************
2867 * fill a notify_info_data with job size
2868 ********************************************************************/
2870 static void spoolss_notify_job_size(int snum,
2871 struct spoolss_Notify *data,
2872 print_queue_struct *queue,
2873 struct spoolss_PrinterInfo2 *pinfo2,
2874 TALLOC_CTX *mem_ctx)
2876 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
2879 /*******************************************************************
2880 * fill a notify_info_data with page info
2881 ********************************************************************/
2882 static void spoolss_notify_total_pages(int snum,
2883 struct spoolss_Notify *data,
2884 print_queue_struct *queue,
2885 struct spoolss_PrinterInfo2 *pinfo2,
2886 TALLOC_CTX *mem_ctx)
2888 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
2891 /*******************************************************************
2892 * fill a notify_info_data with pages printed info.
2893 ********************************************************************/
2894 static void spoolss_notify_pages_printed(int snum,
2895 struct spoolss_Notify *data,
2896 print_queue_struct *queue,
2897 struct spoolss_PrinterInfo2 *pinfo2,
2898 TALLOC_CTX *mem_ctx)
2900 /* Add code when back-end tracks this */
2901 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2904 /*******************************************************************
2905 Fill a notify_info_data with job position.
2906 ********************************************************************/
2908 static void spoolss_notify_job_position(int snum,
2909 struct spoolss_Notify *data,
2910 print_queue_struct *queue,
2911 struct spoolss_PrinterInfo2 *pinfo2,
2912 TALLOC_CTX *mem_ctx)
2914 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
2917 /*******************************************************************
2918 Fill a notify_info_data with submitted time.
2919 ********************************************************************/
2921 static void spoolss_notify_submitted_time(int snum,
2922 struct spoolss_Notify *data,
2923 print_queue_struct *queue,
2924 struct spoolss_PrinterInfo2 *pinfo2,
2925 TALLOC_CTX *mem_ctx)
2927 data->data.string.string = NULL;
2928 data->data.string.size = 0;
2930 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
2931 &data->data.string.string,
2932 &data->data.string.size);
2936 struct s_notify_info_data_table
2938 enum spoolss_NotifyType type;
2941 enum spoolss_NotifyTable variable_type;
2942 void (*fn) (int snum, struct spoolss_Notify *data,
2943 print_queue_struct *queue,
2944 struct spoolss_PrinterInfo2 *pinfo2,
2945 TALLOC_CTX *mem_ctx);
2948 /* A table describing the various print notification constants and
2949 whether the notification data is a pointer to a variable sized
2950 buffer, a one value uint32_t or a two value uint32_t. */
2952 static const struct s_notify_info_data_table notify_info_data_table[] =
2954 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2955 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2956 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
2957 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2958 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2959 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
2960 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
2961 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2962 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
2963 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2964 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2965 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2966 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
2967 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
2968 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2969 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
2970 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2971 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2972 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
2973 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
2974 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
2975 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
2976 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
2977 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2978 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
2979 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2980 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2981 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2982 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2983 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2984 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2985 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2986 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2987 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2988 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2989 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2990 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
2991 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
2992 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
2993 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
2994 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2995 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
2996 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
2997 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2998 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2999 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3000 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3001 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3002 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3005 /*******************************************************************
3006 Return the variable_type of info_data structure.
3007 ********************************************************************/
3009 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3014 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3015 if ( (notify_info_data_table[i].type == type) &&
3016 (notify_info_data_table[i].field == field) ) {
3017 return notify_info_data_table[i].variable_type;
3021 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3026 /****************************************************************************
3027 ****************************************************************************/
3029 static bool search_notify(enum spoolss_NotifyType type,
3035 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3036 if (notify_info_data_table[i].type == type &&
3037 notify_info_data_table[i].field == field &&
3038 notify_info_data_table[i].fn != NULL) {
3047 /****************************************************************************
3048 ****************************************************************************/
3050 static void construct_info_data(struct spoolss_Notify *info_data,
3051 enum spoolss_NotifyType type,
3052 uint16_t field, int id)
3054 info_data->type = type;
3055 info_data->field.field = field;
3056 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3057 info_data->job_id = id;
3060 /*******************************************************************
3062 * fill a notify_info struct with info asked
3064 ********************************************************************/
3066 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3067 struct spoolss_NotifyInfo *info,
3068 struct spoolss_PrinterInfo2 *pinfo2,
3070 const struct spoolss_NotifyOptionType *option_type,
3072 TALLOC_CTX *mem_ctx)
3075 enum spoolss_NotifyType type;
3078 struct spoolss_Notify *current_data;
3079 print_queue_struct *queue=NULL;
3081 type = option_type->type;
3083 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3084 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3085 option_type->count, lp_servicename(snum)));
3087 for(field_num=0; field_num < option_type->count; field_num++) {
3088 field = option_type->fields[field_num].field;
3090 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3092 if (!search_notify(type, field, &j) )
3095 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3096 struct spoolss_Notify,
3098 if (info->notifies == NULL) {
3099 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3103 current_data = &info->notifies[info->count];
3105 construct_info_data(current_data, type, field, id);
3107 DEBUG(10, ("construct_notify_printer_info: "
3108 "calling [%s] snum=%d printername=[%s])\n",
3109 notify_info_data_table[j].name, snum,
3110 pinfo2->printername));
3112 notify_info_data_table[j].fn(snum, current_data, queue,
3121 /*******************************************************************
3123 * fill a notify_info struct with info asked
3125 ********************************************************************/
3127 static bool construct_notify_jobs_info(print_queue_struct *queue,
3128 struct spoolss_NotifyInfo *info,
3129 struct spoolss_PrinterInfo2 *pinfo2,
3131 const struct spoolss_NotifyOptionType *option_type,
3133 TALLOC_CTX *mem_ctx)
3136 enum spoolss_NotifyType type;
3138 struct spoolss_Notify *current_data;
3140 DEBUG(4,("construct_notify_jobs_info\n"));
3142 type = option_type->type;
3144 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3145 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3146 option_type->count));
3148 for(field_num=0; field_num<option_type->count; field_num++) {
3149 field = option_type->fields[field_num].field;
3151 if (!search_notify(type, field, &j) )
3154 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3155 struct spoolss_Notify,
3157 if (info->notifies == NULL) {
3158 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3162 current_data=&(info->notifies[info->count]);
3164 construct_info_data(current_data, type, field, id);
3165 notify_info_data_table[j].fn(snum, current_data, queue,
3174 * JFM: The enumeration is not that simple, it's even non obvious.
3176 * let's take an example: I want to monitor the PRINTER SERVER for
3177 * the printer's name and the number of jobs currently queued.
3178 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3179 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3181 * I have 3 printers on the back of my server.
3183 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3186 * 1 printer 1 name 1
3187 * 2 printer 1 cjob 1
3188 * 3 printer 2 name 2
3189 * 4 printer 2 cjob 2
3190 * 5 printer 3 name 3
3191 * 6 printer 3 name 3
3193 * that's the print server case, the printer case is even worse.
3196 /*******************************************************************
3198 * enumerate all printers on the printserver
3199 * fill a notify_info struct with info asked
3201 ********************************************************************/
3203 static WERROR printserver_notify_info(struct pipes_struct *p,
3204 struct policy_handle *hnd,
3205 struct spoolss_NotifyInfo *info,
3206 TALLOC_CTX *mem_ctx)
3209 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3210 int n_services=lp_numservices();
3212 struct spoolss_NotifyOption *option;
3213 struct spoolss_NotifyOptionType option_type;
3214 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3217 DEBUG(4,("printserver_notify_info\n"));
3222 option = Printer->notify.option;
3225 info->notifies = NULL;
3228 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3229 sending a ffpcn() request first */
3234 for (i=0; i<option->count; i++) {
3235 option_type = option->types[i];
3237 if (option_type.type != PRINTER_NOTIFY_TYPE)
3240 for (snum = 0; snum < n_services; snum++) {
3241 if (!lp_browseable(snum) ||
3242 !lp_snum_ok(snum) ||
3243 !lp_print_ok(snum)) {
3244 continue; /* skip */
3247 /* Maybe we should use the SYSTEM server_info here... */
3248 result = winreg_get_printer(mem_ctx, p->server_info,
3250 Printer->servername,
3251 lp_servicename(snum),
3253 if (!W_ERROR_IS_OK(result)) {
3254 DEBUG(4, ("printserver_notify_info: "
3255 "Failed to get printer [%s]\n",
3256 lp_servicename(snum)));
3261 construct_notify_printer_info(Printer, info,
3266 TALLOC_FREE(pinfo2);
3272 * Debugging information, don't delete.
3275 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3276 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3277 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3279 for (i=0; i<info->count; i++) {
3280 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3281 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3282 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3289 /*******************************************************************
3291 * fill a notify_info struct with info asked
3293 ********************************************************************/
3295 static WERROR printer_notify_info(struct pipes_struct *p,
3296 struct policy_handle *hnd,
3297 struct spoolss_NotifyInfo *info,
3298 TALLOC_CTX *mem_ctx)
3301 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3304 struct spoolss_NotifyOption *option;
3305 struct spoolss_NotifyOptionType option_type;
3307 print_queue_struct *queue=NULL;
3308 print_status_struct status;
3309 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3312 DEBUG(4,("printer_notify_info\n"));
3317 option = Printer->notify.option;
3321 info->notifies = NULL;
3324 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3325 sending a ffpcn() request first */
3330 get_printer_snum(p, hnd, &snum, NULL);
3332 /* Maybe we should use the SYSTEM server_info here... */
3333 result = winreg_get_printer(mem_ctx, p->server_info, p->msg_ctx,
3334 Printer->servername,
3335 lp_servicename(snum), &pinfo2);
3336 if (!W_ERROR_IS_OK(result)) {
3340 for (i=0; i<option->count; i++) {
3341 option_type = option->types[i];
3343 switch (option_type.type) {
3344 case PRINTER_NOTIFY_TYPE:
3345 if (construct_notify_printer_info(Printer, info,
3353 case JOB_NOTIFY_TYPE:
3355 count = print_queue_status(snum, &queue, &status);
3357 for (j=0; j<count; j++) {
3358 construct_notify_jobs_info(&queue[j], info,
3371 * Debugging information, don't delete.
3374 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3375 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3376 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3378 for (i=0; i<info->count; i++) {
3379 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3380 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3381 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3385 talloc_free(pinfo2);
3389 /****************************************************************
3390 _spoolss_RouterRefreshPrinterChangeNotify
3391 ****************************************************************/
3393 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3394 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3396 struct spoolss_NotifyInfo *info;
3398 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
3399 WERROR result = WERR_BADFID;
3401 /* we always have a spoolss_NotifyInfo struct */
3402 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3404 result = WERR_NOMEM;
3408 *r->out.info = info;
3411 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3412 "Invalid handle (%s:%u:%u).\n",
3413 OUR_HANDLE(r->in.handle)));
3417 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3420 * We are now using the change value, and
3421 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3422 * I don't have a global notification system, I'm sending back all the
3423 * informations even when _NOTHING_ has changed.
3426 /* We need to keep track of the change value to send back in
3427 RRPCN replies otherwise our updates are ignored. */
3429 Printer->notify.fnpcn = true;
3431 if (Printer->notify.client_connected) {
3432 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3433 "Saving change value in request [%x]\n",
3435 Printer->notify.change = r->in.change_low;
3438 /* just ignore the spoolss_NotifyOption */
3440 switch (Printer->printer_type) {
3442 result = printserver_notify_info(p, r->in.handle,
3446 case SPLHND_PRINTER:
3447 result = printer_notify_info(p, r->in.handle,
3452 Printer->notify.fnpcn = false;
3458 /********************************************************************
3459 * construct_printer_info_0
3460 * fill a printer_info_0 struct
3461 ********************************************************************/
3463 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3464 struct auth_serversupplied_info *server_info,
3465 struct messaging_context *msg_ctx,
3466 struct spoolss_PrinterInfo2 *info2,
3467 struct spoolss_PrinterInfo0 *r,
3471 counter_printer_0 *session_counter;
3472 struct timeval setuptime;
3473 print_status_struct status;
3475 r->printername = talloc_strdup(mem_ctx, info2->printername);
3476 W_ERROR_HAVE_NO_MEMORY(r->printername);
3478 r->servername = talloc_strdup(mem_ctx, info2->servername);
3479 W_ERROR_HAVE_NO_MEMORY(r->servername);
3481 count = print_queue_length(snum, &status);
3483 /* check if we already have a counter for this printer */
3484 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3485 if (session_counter->snum == snum)
3489 /* it's the first time, add it to the list */
3490 if (session_counter == NULL) {
3491 session_counter = SMB_MALLOC_P(counter_printer_0);
3492 W_ERROR_HAVE_NO_MEMORY(session_counter);
3493 ZERO_STRUCTP(session_counter);
3494 session_counter->snum = snum;
3495 session_counter->counter = 0;
3496 DLIST_ADD(counter_list, session_counter);
3500 session_counter->counter++;
3506 get_startup_time(&setuptime);
3507 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3510 * the global_counter should be stored in a TDB as it's common to all the clients
3511 * and should be zeroed on samba startup
3513 r->global_counter = session_counter->counter;
3515 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3516 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3517 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3518 r->free_build = SPOOLSS_RELEASE_BUILD;
3520 r->max_spooling = 0;
3521 r->session_counter = session_counter->counter;
3522 r->num_error_out_of_paper = 0x0;
3523 r->num_error_not_ready = 0x0; /* number of print failure */
3525 r->number_of_processors = 0x1;
3526 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3527 r->high_part_total_bytes = 0x0;
3529 /* ChangeID in milliseconds*/
3530 winreg_printer_get_changeid(mem_ctx, server_info, msg_ctx,
3531 info2->sharename, &r->change_id);
3533 r->last_error = WERR_OK;
3534 r->status = nt_printq_status(status.status);
3535 r->enumerate_network_printers = 0x0;
3536 r->c_setprinter = 0x0;
3537 r->processor_architecture = 0x0;
3538 r->processor_level = 0x6; /* 6 ???*/
3547 /********************************************************************
3548 * construct_printer_info1
3549 * fill a spoolss_PrinterInfo1 struct
3550 ********************************************************************/
3552 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3553 const struct spoolss_PrinterInfo2 *info2,
3555 struct spoolss_PrinterInfo1 *r,
3560 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3564 W_ERROR_HAVE_NO_MEMORY(r->description);
3566 if (info2->comment == NULL || info2->comment[0] == '\0') {
3567 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3569 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3571 W_ERROR_HAVE_NO_MEMORY(r->comment);
3573 r->name = talloc_strdup(mem_ctx, info2->printername);
3574 W_ERROR_HAVE_NO_MEMORY(r->name);
3579 /********************************************************************
3580 * construct_printer_info2
3581 * fill a spoolss_PrinterInfo2 struct
3582 ********************************************************************/
3584 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3585 const struct spoolss_PrinterInfo2 *info2,
3586 struct spoolss_PrinterInfo2 *r,
3590 print_status_struct status;
3592 count = print_queue_length(snum, &status);
3594 r->servername = talloc_strdup(mem_ctx, info2->servername);
3595 W_ERROR_HAVE_NO_MEMORY(r->servername);
3596 r->printername = talloc_strdup(mem_ctx, info2->printername);
3597 W_ERROR_HAVE_NO_MEMORY(r->printername);
3598 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3599 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3600 r->portname = talloc_strdup(mem_ctx, info2->portname);
3601 W_ERROR_HAVE_NO_MEMORY(r->portname);
3602 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
3603 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3605 if (info2->comment[0] == '\0') {
3606 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3608 r->comment = talloc_strdup(mem_ctx, info2->comment);
3610 W_ERROR_HAVE_NO_MEMORY(r->comment);
3612 r->location = talloc_strdup(mem_ctx, info2->location);
3613 W_ERROR_HAVE_NO_MEMORY(r->location);
3614 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
3615 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3616 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
3617 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3618 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
3619 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3620 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
3621 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3623 r->attributes = info2->attributes;
3625 r->priority = info2->priority;
3626 r->defaultpriority = info2->defaultpriority;
3627 r->starttime = info2->starttime;
3628 r->untiltime = info2->untiltime;
3629 r->status = nt_printq_status(status.status);
3631 r->averageppm = info2->averageppm;
3633 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3635 DEBUG(8,("Returning NULL Devicemode!\n"));
3640 if (info2->secdesc != NULL) {
3641 /* don't use talloc_steal() here unless you do a deep steal of all
3642 the SEC_DESC members */
3644 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3650 /********************************************************************
3651 * construct_printer_info3
3652 * fill a spoolss_PrinterInfo3 struct
3653 ********************************************************************/
3655 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3656 const struct spoolss_PrinterInfo2 *info2,
3657 struct spoolss_PrinterInfo3 *r,
3660 /* These are the components of the SD we are returning. */
3662 if (info2->secdesc != NULL) {
3663 /* don't use talloc_steal() here unless you do a deep steal of all
3664 the SEC_DESC members */
3666 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3667 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3673 /********************************************************************
3674 * construct_printer_info4
3675 * fill a spoolss_PrinterInfo4 struct
3676 ********************************************************************/
3678 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
3679 const struct spoolss_PrinterInfo2 *info2,
3680 struct spoolss_PrinterInfo4 *r,
3683 r->printername = talloc_strdup(mem_ctx, info2->printername);
3684 W_ERROR_HAVE_NO_MEMORY(r->printername);
3685 r->servername = talloc_strdup(mem_ctx, info2->servername);
3686 W_ERROR_HAVE_NO_MEMORY(r->servername);
3688 r->attributes = info2->attributes;
3693 /********************************************************************
3694 * construct_printer_info5
3695 * fill a spoolss_PrinterInfo5 struct
3696 ********************************************************************/
3698 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
3699 const struct spoolss_PrinterInfo2 *info2,
3700 struct spoolss_PrinterInfo5 *r,
3703 r->printername = talloc_strdup(mem_ctx, info2->printername);
3704 W_ERROR_HAVE_NO_MEMORY(r->printername);
3705 r->portname = talloc_strdup(mem_ctx, info2->portname);
3706 W_ERROR_HAVE_NO_MEMORY(r->portname);
3708 r->attributes = info2->attributes;
3710 /* these two are not used by NT+ according to MSDN */
3711 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
3712 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
3717 /********************************************************************
3718 * construct_printer_info_6
3719 * fill a spoolss_PrinterInfo6 struct
3720 ********************************************************************/
3722 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
3723 const struct spoolss_PrinterInfo2 *info2,
3724 struct spoolss_PrinterInfo6 *r,
3728 print_status_struct status;
3730 count = print_queue_length(snum, &status);
3732 r->status = nt_printq_status(status.status);
3737 /********************************************************************
3738 * construct_printer_info7
3739 * fill a spoolss_PrinterInfo7 struct
3740 ********************************************************************/
3742 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
3743 Printer_entry *print_hnd,
3744 struct spoolss_PrinterInfo7 *r,
3747 struct auth_serversupplied_info *server_info;
3751 status = make_server_info_system(mem_ctx, &server_info);
3752 if (!NT_STATUS_IS_OK(status)) {
3753 DEBUG(0, ("construct_printer_info7: "
3754 "Could not create system server_info\n"));
3758 if (is_printer_published(mem_ctx, server_info, print_hnd->servername,
3759 lp_servicename(snum), &guid, NULL)) {
3760 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
3761 r->action = DSPRINT_PUBLISH;
3763 r->guid = talloc_strdup(mem_ctx, "");
3764 r->action = DSPRINT_UNPUBLISH;
3766 W_ERROR_HAVE_NO_MEMORY(r->guid);
3768 TALLOC_FREE(server_info);
3772 /********************************************************************
3773 * construct_printer_info8
3774 * fill a spoolss_PrinterInfo8 struct
3775 ********************************************************************/
3777 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
3778 const struct spoolss_PrinterInfo2 *info2,
3779 struct spoolss_DeviceModeInfo *r,
3782 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3784 DEBUG(8,("Returning NULL Devicemode!\n"));
3791 /********************************************************************
3792 ********************************************************************/
3794 static bool snum_is_shared_printer(int snum)
3796 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
3799 /********************************************************************
3800 Spoolss_enumprinters.
3801 ********************************************************************/
3803 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
3804 struct auth_serversupplied_info *server_info,
3805 struct messaging_context *msg_ctx,
3808 union spoolss_PrinterInfo **info_p,
3812 int n_services = lp_numservices();
3813 union spoolss_PrinterInfo *info = NULL;
3815 WERROR result = WERR_OK;
3820 for (snum = 0; snum < n_services; snum++) {
3822 const char *printer;
3823 struct spoolss_PrinterInfo2 *info2;
3825 if (!snum_is_shared_printer(snum)) {
3829 printer = lp_const_servicename(snum);
3831 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
3834 result = winreg_create_printer(mem_ctx,
3839 if (!W_ERROR_IS_OK(result)) {
3843 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
3844 union spoolss_PrinterInfo,
3847 result = WERR_NOMEM;
3851 result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
3852 NULL, printer, &info2);
3853 if (!W_ERROR_IS_OK(result)) {
3859 result = construct_printer_info0(info, server_info,
3861 &info[count].info0, snum);
3864 result = construct_printer_info1(info, info2, flags,
3865 &info[count].info1, snum);
3868 result = construct_printer_info2(info, info2,
3869 &info[count].info2, snum);
3872 result = construct_printer_info4(info, info2,
3873 &info[count].info4, snum);
3876 result = construct_printer_info5(info, info2,
3877 &info[count].info5, snum);
3881 result = WERR_UNKNOWN_LEVEL;
3885 if (!W_ERROR_IS_OK(result)) {
3896 if (!W_ERROR_IS_OK(result)) {
3906 /********************************************************************
3907 * handle enumeration of printers at level 0
3908 ********************************************************************/
3910 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
3911 struct auth_serversupplied_info *server_info,
3912 struct messaging_context *msg_ctx,
3914 const char *servername,
3915 union spoolss_PrinterInfo **info,
3918 DEBUG(4,("enum_all_printers_info_0\n"));
3920 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
3921 0, flags, info, count);
3925 /********************************************************************
3926 ********************************************************************/
3928 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
3929 struct auth_serversupplied_info *server_info,
3930 struct messaging_context *msg_ctx,
3932 union spoolss_PrinterInfo **info,
3935 DEBUG(4,("enum_all_printers_info_1\n"));
3937 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
3938 1, flags, info, count);
3941 /********************************************************************
3942 enum_all_printers_info_1_local.
3943 *********************************************************************/
3945 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
3946 struct auth_serversupplied_info *server_info,
3947 struct messaging_context *msg_ctx,
3948 union spoolss_PrinterInfo **info,
3951 DEBUG(4,("enum_all_printers_info_1_local\n"));
3953 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
3954 PRINTER_ENUM_ICON8, info, count);
3957 /********************************************************************
3958 enum_all_printers_info_1_name.
3959 *********************************************************************/
3961 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
3962 struct auth_serversupplied_info *server_info,
3963 struct messaging_context *msg_ctx,
3965 union spoolss_PrinterInfo **info,
3968 const char *s = name;
3970 DEBUG(4,("enum_all_printers_info_1_name\n"));
3972 if ((name[0] == '\\') && (name[1] == '\\')) {
3976 if (!is_myname_or_ipaddr(s)) {
3977 return WERR_INVALID_NAME;
3980 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
3981 PRINTER_ENUM_ICON8, info, count);
3984 /********************************************************************
3985 enum_all_printers_info_1_network.
3986 *********************************************************************/
3988 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
3989 struct auth_serversupplied_info *server_info,
3990 struct messaging_context *msg_ctx,
3992 union spoolss_PrinterInfo **info,
3995 const char *s = name;
3997 DEBUG(4,("enum_all_printers_info_1_network\n"));
3999 /* If we respond to a enum_printers level 1 on our name with flags
4000 set to PRINTER_ENUM_REMOTE with a list of printers then these
4001 printers incorrectly appear in the APW browse list.
4002 Specifically the printers for the server appear at the workgroup
4003 level where all the other servers in the domain are
4004 listed. Windows responds to this call with a
4005 WERR_CAN_NOT_COMPLETE so we should do the same. */
4007 if (name[0] == '\\' && name[1] == '\\') {
4011 if (is_myname_or_ipaddr(s)) {
4012 return WERR_CAN_NOT_COMPLETE;
4015 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4016 PRINTER_ENUM_NAME, info, count);
4019 /********************************************************************
4020 * api_spoolss_enumprinters
4022 * called from api_spoolss_enumprinters (see this to understand)
4023 ********************************************************************/
4025 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4026 struct auth_serversupplied_info *server_info,
4027 struct messaging_context *msg_ctx,
4028 union spoolss_PrinterInfo **info,
4031 DEBUG(4,("enum_all_printers_info_2\n"));
4033 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4037 /********************************************************************
4038 * handle enumeration of printers at level 1
4039 ********************************************************************/
4041 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4042 struct auth_serversupplied_info *server_info,
4043 struct messaging_context *msg_ctx,
4046 union spoolss_PrinterInfo **info,
4049 /* Not all the flags are equals */
4051 if (flags & PRINTER_ENUM_LOCAL) {
4052 return enum_all_printers_info_1_local(mem_ctx, server_info,
4053 msg_ctx, info, count);
4056 if (flags & PRINTER_ENUM_NAME) {
4057 return enum_all_printers_info_1_name(mem_ctx, server_info,
4058 msg_ctx, name, info,
4062 if (flags & PRINTER_ENUM_NETWORK) {
4063 return enum_all_printers_info_1_network(mem_ctx, server_info,
4064 msg_ctx, name, info,
4068 return WERR_OK; /* NT4sp5 does that */
4071 /********************************************************************
4072 * handle enumeration of printers at level 2
4073 ********************************************************************/
4075 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4076 struct auth_serversupplied_info *server_info,
4077 struct messaging_context *msg_ctx,
4079 const char *servername,
4080 union spoolss_PrinterInfo **info,
4083 if (flags & PRINTER_ENUM_LOCAL) {
4084 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4088 if (flags & PRINTER_ENUM_NAME) {
4089 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4090 return WERR_INVALID_NAME;
4093 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4097 if (flags & PRINTER_ENUM_REMOTE) {
4098 return WERR_UNKNOWN_LEVEL;
4104 /********************************************************************
4105 * handle enumeration of printers at level 4
4106 ********************************************************************/
4108 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4109 struct auth_serversupplied_info *server_info,
4110 struct messaging_context *msg_ctx,
4112 const char *servername,
4113 union spoolss_PrinterInfo **info,
4116 DEBUG(4,("enum_all_printers_info_4\n"));
4118 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4119 4, flags, info, count);
4123 /********************************************************************
4124 * handle enumeration of printers at level 5
4125 ********************************************************************/
4127 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4128 struct auth_serversupplied_info *server_info,
4129 struct messaging_context *msg_ctx,
4131 const char *servername,
4132 union spoolss_PrinterInfo **info,
4135 DEBUG(4,("enum_all_printers_info_5\n"));
4137 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4138 5, flags, info, count);
4141 /****************************************************************
4142 _spoolss_EnumPrinters
4143 ****************************************************************/
4145 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4146 struct spoolss_EnumPrinters *r)
4148 const char *name = NULL;
4151 /* that's an [in out] buffer */
4153 if (!r->in.buffer && (r->in.offered != 0)) {
4154 return WERR_INVALID_PARAM;
4157 DEBUG(4,("_spoolss_EnumPrinters\n"));
4161 *r->out.info = NULL;
4165 * flags==PRINTER_ENUM_NAME
4166 * if name=="" then enumerates all printers
4167 * if name!="" then enumerate the printer
4168 * flags==PRINTER_ENUM_REMOTE
4169 * name is NULL, enumerate printers
4170 * Level 2: name!="" enumerates printers, name can't be NULL
4171 * Level 3: doesn't exist
4172 * Level 4: does a local registry lookup
4173 * Level 5: same as Level 2
4177 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4178 W_ERROR_HAVE_NO_MEMORY(name);
4181 switch (r->in.level) {
4183 result = enumprinters_level0(p->mem_ctx, p->server_info,
4184 p->msg_ctx, r->in.flags, name,
4185 r->out.info, r->out.count);
4188 result = enumprinters_level1(p->mem_ctx, p->server_info,
4189 p->msg_ctx, r->in.flags, name,
4190 r->out.info, r->out.count);
4193 result = enumprinters_level2(p->mem_ctx, p->server_info,
4194 p->msg_ctx, r->in.flags, name,
4195 r->out.info, r->out.count);
4198 result = enumprinters_level4(p->mem_ctx, p->server_info,
4199 p->msg_ctx, r->in.flags, name,
4200 r->out.info, r->out.count);
4203 result = enumprinters_level5(p->mem_ctx, p->server_info,
4204 p->msg_ctx, r->in.flags, name,
4205 r->out.info, r->out.count);
4208 return WERR_UNKNOWN_LEVEL;
4211 if (!W_ERROR_IS_OK(result)) {
4215 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4216 spoolss_EnumPrinters,
4217 *r->out.info, r->in.level,
4219 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4220 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4222 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4225 /****************************************************************
4227 ****************************************************************/
4229 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4230 struct spoolss_GetPrinter *r)
4232 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4233 struct spoolss_PrinterInfo2 *info2 = NULL;
4234 WERROR result = WERR_OK;
4235 const char *servername = NULL;
4238 /* that's an [in out] buffer */
4240 if (!r->in.buffer && (r->in.offered != 0)) {
4241 return WERR_INVALID_PARAM;
4246 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4250 if (Printer != NULL || Printer->servername != NULL) {
4251 servername = Printer->servername;
4254 result = winreg_get_printer(p->mem_ctx,
4258 lp_const_servicename(snum),
4260 if (!W_ERROR_IS_OK(result)) {
4264 switch (r->in.level) {
4266 result = construct_printer_info0(p->mem_ctx, p->server_info,
4268 &r->out.info->info0, snum);
4271 result = construct_printer_info1(p->mem_ctx, info2,
4273 &r->out.info->info1, snum);
4276 result = construct_printer_info2(p->mem_ctx, info2,
4277 &r->out.info->info2, snum);
4280 result = construct_printer_info3(p->mem_ctx, info2,
4281 &r->out.info->info3, snum);
4284 result = construct_printer_info4(p->mem_ctx, info2,
4285 &r->out.info->info4, snum);
4288 result = construct_printer_info5(p->mem_ctx, info2,
4289 &r->out.info->info5, snum);
4292 result = construct_printer_info6(p->mem_ctx, info2,
4293 &r->out.info->info6, snum);
4296 result = construct_printer_info7(p->mem_ctx, Printer,
4297 &r->out.info->info7, snum);
4300 result = construct_printer_info8(p->mem_ctx, info2,
4301 &r->out.info->info8, snum);
4304 result = WERR_UNKNOWN_LEVEL;
4308 if (!W_ERROR_IS_OK(result)) {
4309 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4310 r->in.level, win_errstr(result)));
4311 TALLOC_FREE(r->out.info);
4315 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4316 r->out.info, r->in.level);
4317 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4319 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4322 /********************************************************************
4323 ********************************************************************/
4325 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4327 if (in && strlen(in)) { \
4328 out = talloc_strdup(mem_ctx, in); \
4330 out = talloc_strdup(mem_ctx, ""); \
4332 W_ERROR_HAVE_NO_MEMORY(out); \
4335 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4337 if (in && strlen(in)) { \
4338 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4340 out = talloc_strdup(mem_ctx, ""); \
4342 W_ERROR_HAVE_NO_MEMORY(out); \
4345 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4346 const char **string_array,
4347 const char ***presult,
4348 const char *cservername,
4352 int i, num_strings = 0;
4353 const char **array = NULL;
4355 if (string_array == NULL) {
4356 return WERR_INVALID_PARAMETER;;
4359 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4360 const char *str = NULL;
4362 if (cservername == NULL || arch == NULL) {
4363 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4365 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4368 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4375 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4376 &array, &num_strings);
4386 /********************************************************************
4387 * fill a spoolss_DriverInfo1 struct
4388 ********************************************************************/
4390 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4391 struct spoolss_DriverInfo1 *r,
4392 const struct spoolss_DriverInfo8 *driver,
4393 const char *servername)
4395 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4396 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4401 /********************************************************************
4402 * fill a spoolss_DriverInfo2 struct
4403 ********************************************************************/
4405 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4406 struct spoolss_DriverInfo2 *r,
4407 const struct spoolss_DriverInfo8 *driver,
4408 const char *servername)
4411 const char *cservername = canon_servername(servername);
4413 r->version = driver->version;
4415 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4416 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4417 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4418 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4420 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4421 driver->architecture,
4423 driver->driver_path,
4426 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4427 driver->architecture,
4432 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4433 driver->architecture,
4435 driver->config_file,
4441 /********************************************************************
4442 * fill a spoolss_DriverInfo3 struct
4443 ********************************************************************/
4445 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4446 struct spoolss_DriverInfo3 *r,
4447 const struct spoolss_DriverInfo8 *driver,
4448 const char *servername)
4450 const char *cservername = canon_servername(servername);
4452 r->version = driver->version;
4454 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4455 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4456 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4457 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4459 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4460 driver->architecture,
4462 driver->driver_path,
4465 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4466 driver->architecture,
4471 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4472 driver->architecture,
4474 driver->config_file,
4477 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4478 driver->architecture,
4483 FILL_DRIVER_STRING(mem_ctx,
4484 driver->monitor_name,
4487 FILL_DRIVER_STRING(mem_ctx,
4488 driver->default_datatype,
4489 r->default_datatype);
4491 return string_array_from_driver_info(mem_ctx,
4492 driver->dependent_files,
4493 &r->dependent_files,
4495 driver->architecture,
4499 /********************************************************************
4500 * fill a spoolss_DriverInfo4 struct
4501 ********************************************************************/
4503 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4504 struct spoolss_DriverInfo4 *r,
4505 const struct spoolss_DriverInfo8 *driver,
4506 const char *servername)
4508 const char *cservername = canon_servername(servername);
4511 r->version = driver->version;
4513 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4514 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4515 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4516 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4518 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4519 driver->architecture,
4521 driver->driver_path,
4524 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4525 driver->architecture,
4530 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4531 driver->architecture,
4533 driver->config_file,
4536 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4537 driver->architecture,
4542 result = string_array_from_driver_info(mem_ctx,
4543 driver->dependent_files,
4544 &r->dependent_files,
4546 driver->architecture,
4548 if (!W_ERROR_IS_OK(result)) {
4552 FILL_DRIVER_STRING(mem_ctx,
4553 driver->monitor_name,
4556 FILL_DRIVER_STRING(mem_ctx,
4557 driver->default_datatype,
4558 r->default_datatype);
4561 result = string_array_from_driver_info(mem_ctx,
4562 driver->previous_names,
4569 /********************************************************************
4570 * fill a spoolss_DriverInfo5 struct
4571 ********************************************************************/
4573 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4574 struct spoolss_DriverInfo5 *r,
4575 const struct spoolss_DriverInfo8 *driver,
4576 const char *servername)
4578 const char *cservername = canon_servername(servername);
4580 r->version = driver->version;
4582 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4583 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4584 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4585 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4587 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4588 driver->architecture,
4590 driver->driver_path,
4593 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4594 driver->architecture,
4599 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4600 driver->architecture,
4602 driver->config_file,
4605 r->driver_attributes = 0;
4606 r->config_version = 0;
4607 r->driver_version = 0;
4611 /********************************************************************
4612 * fill a spoolss_DriverInfo6 struct
4613 ********************************************************************/
4615 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4616 struct spoolss_DriverInfo6 *r,
4617 const struct spoolss_DriverInfo8 *driver,
4618 const char *servername)
4620 const char *cservername = canon_servername(servername);
4623 r->version = driver->version;
4625 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4626 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4627 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4628 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4630 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4631 driver->architecture,
4633 driver->driver_path,
4636 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4637 driver->architecture,
4642 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4643 driver->architecture,
4645 driver->config_file,
4648 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4649 driver->architecture,
4654 FILL_DRIVER_STRING(mem_ctx,
4655 driver->monitor_name,
4658 FILL_DRIVER_STRING(mem_ctx,
4659 driver->default_datatype,
4660 r->default_datatype);
4662 result = string_array_from_driver_info(mem_ctx,
4663 driver->dependent_files,
4664 &r->dependent_files,
4666 driver->architecture,
4668 if (!W_ERROR_IS_OK(result)) {
4672 result = string_array_from_driver_info(mem_ctx,
4673 driver->previous_names,
4676 if (!W_ERROR_IS_OK(result)) {
4680 r->driver_date = driver->driver_date;
4681 r->driver_version = driver->driver_version;
4683 FILL_DRIVER_STRING(mem_ctx,
4684 driver->manufacturer_name,
4685 r->manufacturer_name);
4686 FILL_DRIVER_STRING(mem_ctx,
4687 driver->manufacturer_url,
4688 r->manufacturer_url);
4689 FILL_DRIVER_STRING(mem_ctx,
4690 driver->hardware_id,
4692 FILL_DRIVER_STRING(mem_ctx,
4699 /********************************************************************
4700 * fill a spoolss_DriverInfo8 struct
4701 ********************************************************************/
4703 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
4704 struct spoolss_DriverInfo8 *r,
4705 const struct spoolss_DriverInfo8 *driver,
4706 const char *servername)
4708 const char *cservername = canon_servername(servername);
4711 r->version = driver->version;
4713 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4714 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4715 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4716 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4718 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4719 driver->architecture,
4721 driver->driver_path,
4724 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4725 driver->architecture,
4730 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4731 driver->architecture,
4733 driver->config_file,
4736 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4737 driver->architecture,
4742 FILL_DRIVER_STRING(mem_ctx,
4743 driver->monitor_name,
4746 FILL_DRIVER_STRING(mem_ctx,
4747 driver->default_datatype,
4748 r->default_datatype);
4750 result = string_array_from_driver_info(mem_ctx,
4751 driver->dependent_files,
4752 &r->dependent_files,
4754 driver->architecture,
4756 if (!W_ERROR_IS_OK(result)) {
4760 result = string_array_from_driver_info(mem_ctx,
4761 driver->previous_names,
4764 if (!W_ERROR_IS_OK(result)) {
4768 r->driver_date = driver->driver_date;
4769 r->driver_version = driver->driver_version;
4771 FILL_DRIVER_STRING(mem_ctx,
4772 driver->manufacturer_name,
4773 r->manufacturer_name);
4774 FILL_DRIVER_STRING(mem_ctx,
4775 driver->manufacturer_url,
4776 r->manufacturer_url);
4777 FILL_DRIVER_STRING(mem_ctx,
4778 driver->hardware_id,
4780 FILL_DRIVER_STRING(mem_ctx,
4784 FILL_DRIVER_STRING(mem_ctx,
4785 driver->print_processor,
4786 r->print_processor);
4787 FILL_DRIVER_STRING(mem_ctx,
4788 driver->vendor_setup,
4791 result = string_array_from_driver_info(mem_ctx,
4792 driver->color_profiles,
4795 if (!W_ERROR_IS_OK(result)) {
4799 FILL_DRIVER_STRING(mem_ctx,
4803 r->printer_driver_attributes = driver->printer_driver_attributes;
4805 result = string_array_from_driver_info(mem_ctx,
4806 driver->core_driver_dependencies,
4807 &r->core_driver_dependencies,
4809 if (!W_ERROR_IS_OK(result)) {
4813 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
4814 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
4819 #if 0 /* disabled until marshalling issues are resolved - gd */
4820 /********************************************************************
4821 ********************************************************************/
4823 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
4824 struct spoolss_DriverFileInfo *r,
4825 const char *cservername,
4826 const char *file_name,
4827 enum spoolss_DriverFileType file_type,
4828 uint32_t file_version)
4830 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
4831 cservername, file_name);
4832 W_ERROR_HAVE_NO_MEMORY(r->file_name);
4833 r->file_type = file_type;
4834 r->file_version = file_version;
4839 /********************************************************************
4840 ********************************************************************/
4842 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
4843 const struct spoolss_DriverInfo8 *driver,
4844 const char *cservername,
4845 struct spoolss_DriverFileInfo **info_p,
4848 struct spoolss_DriverFileInfo *info = NULL;
4856 if (strlen(driver->driver_path)) {
4857 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4858 struct spoolss_DriverFileInfo,
4860 W_ERROR_HAVE_NO_MEMORY(info);
4861 result = fill_spoolss_DriverFileInfo(info,
4864 driver->driver_path,
4865 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
4867 W_ERROR_NOT_OK_RETURN(result);
4871 if (strlen(driver->config_file)) {
4872 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4873 struct spoolss_DriverFileInfo,
4875 W_ERROR_HAVE_NO_MEMORY(info);
4876 result = fill_spoolss_DriverFileInfo(info,
4879 driver->config_file,
4880 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
4882 W_ERROR_NOT_OK_RETURN(result);
4886 if (strlen(driver->data_file)) {
4887 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4888 struct spoolss_DriverFileInfo,
4890 W_ERROR_HAVE_NO_MEMORY(info);
4891 result = fill_spoolss_DriverFileInfo(info,
4895 SPOOLSS_DRIVER_FILE_TYPE_DATA,
4897 W_ERROR_NOT_OK_RETURN(result);
4901 if (strlen(driver->help_file)) {
4902 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4903 struct spoolss_DriverFileInfo,
4905 W_ERROR_HAVE_NO_MEMORY(info);
4906 result = fill_spoolss_DriverFileInfo(info,
4910 SPOOLSS_DRIVER_FILE_TYPE_HELP,
4912 W_ERROR_NOT_OK_RETURN(result);
4916 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
4917 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4918 struct spoolss_DriverFileInfo,
4920 W_ERROR_HAVE_NO_MEMORY(info);
4921 result = fill_spoolss_DriverFileInfo(info,
4924 driver->dependent_files[i],
4925 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
4927 W_ERROR_NOT_OK_RETURN(result);
4937 /********************************************************************
4938 * fill a spoolss_DriverInfo101 struct
4939 ********************************************************************/
4941 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
4942 struct spoolss_DriverInfo101 *r,
4943 const struct spoolss_DriverInfo8 *driver,
4944 const char *servername)
4946 const char *cservername = canon_servername(servername);
4949 r->version = driver->version;
4951 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4952 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4953 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4954 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4956 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
4960 if (!W_ERROR_IS_OK(result)) {
4964 FILL_DRIVER_STRING(mem_ctx,
4965 driver->monitor_name,
4968 FILL_DRIVER_STRING(mem_ctx,
4969 driver->default_datatype,
4970 r->default_datatype);
4972 result = string_array_from_driver_info(mem_ctx,
4973 driver->previous_names,
4976 if (!W_ERROR_IS_OK(result)) {
4980 r->driver_date = driver->driver_date;
4981 r->driver_version = driver->driver_version;
4983 FILL_DRIVER_STRING(mem_ctx,
4984 driver->manufacturer_name,
4985 r->manufacturer_name);
4986 FILL_DRIVER_STRING(mem_ctx,
4987 driver->manufacturer_url,
4988 r->manufacturer_url);
4989 FILL_DRIVER_STRING(mem_ctx,
4990 driver->hardware_id,
4992 FILL_DRIVER_STRING(mem_ctx,
4999 /********************************************************************
5000 ********************************************************************/
5002 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5003 struct auth_serversupplied_info *server_info,
5004 struct messaging_context *msg_ctx,
5006 union spoolss_DriverInfo *r,
5008 const char *servername,
5009 const char *architecture,
5012 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5013 struct spoolss_DriverInfo8 *driver;
5016 result = winreg_get_printer(mem_ctx,
5020 lp_const_servicename(snum),
5023 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5024 win_errstr(result)));
5026 if (!W_ERROR_IS_OK(result)) {
5027 return WERR_INVALID_PRINTER_NAME;
5030 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5032 pinfo2->drivername, version, &driver);
5034 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5035 win_errstr(result)));
5037 if (!W_ERROR_IS_OK(result)) {
5039 * Is this a W2k client ?
5043 talloc_free(pinfo2);
5044 return WERR_UNKNOWN_PRINTER_DRIVER;
5047 /* Yes - try again with a WinNT driver. */
5049 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5053 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5054 win_errstr(result)));
5055 if (!W_ERROR_IS_OK(result)) {
5056 talloc_free(pinfo2);
5057 return WERR_UNKNOWN_PRINTER_DRIVER;
5063 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5066 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5069 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5072 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5075 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5078 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5081 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5083 #if 0 /* disabled until marshalling issues are resolved - gd */
5085 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5089 result = WERR_UNKNOWN_LEVEL;
5093 talloc_free(pinfo2);
5094 talloc_free(driver);
5099 /****************************************************************
5100 _spoolss_GetPrinterDriver2
5101 ****************************************************************/
5103 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5104 struct spoolss_GetPrinterDriver2 *r)
5106 Printer_entry *printer;
5111 /* that's an [in out] buffer */
5113 if (!r->in.buffer && (r->in.offered != 0)) {
5114 return WERR_INVALID_PARAM;
5117 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5119 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5120 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5121 return WERR_INVALID_PRINTER_NAME;
5125 *r->out.server_major_version = 0;
5126 *r->out.server_minor_version = 0;
5128 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5132 result = construct_printer_driver_info_level(p->mem_ctx,
5135 r->in.level, r->out.info,
5136 snum, printer->servername,
5138 r->in.client_major_version);
5139 if (!W_ERROR_IS_OK(result)) {
5140 TALLOC_FREE(r->out.info);
5144 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5145 r->out.info, r->in.level);
5146 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5148 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5152 /****************************************************************
5153 _spoolss_StartPagePrinter
5154 ****************************************************************/
5156 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5157 struct spoolss_StartPagePrinter *r)
5159 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5162 DEBUG(3,("_spoolss_StartPagePrinter: "
5163 "Error in startpageprinter printer handle\n"));
5167 Printer->page_started = true;
5171 /****************************************************************
5172 _spoolss_EndPagePrinter
5173 ****************************************************************/
5175 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5176 struct spoolss_EndPagePrinter *r)
5180 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5183 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5184 OUR_HANDLE(r->in.handle)));
5188 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5191 Printer->page_started = false;
5192 print_job_endpage(snum, Printer->jobid);
5197 /****************************************************************
5198 _spoolss_StartDocPrinter
5199 ****************************************************************/
5201 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5202 struct spoolss_StartDocPrinter *r)
5204 struct spoolss_DocumentInfo1 *info_1;
5206 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5210 DEBUG(2,("_spoolss_StartDocPrinter: "
5211 "Invalid handle (%s:%u:%u)\n",
5212 OUR_HANDLE(r->in.handle)));
5216 if (Printer->jobid) {
5217 DEBUG(2, ("_spoolss_StartDocPrinter: "
5218 "StartDocPrinter called twice! "
5219 "(existing jobid = %d)\n", Printer->jobid));
5220 return WERR_INVALID_HANDLE;
5223 if (r->in.level != 1) {
5224 return WERR_UNKNOWN_LEVEL;
5227 info_1 = r->in.info.info1;
5230 * a nice thing with NT is it doesn't listen to what you tell it.
5231 * when asked to send _only_ RAW datas, it tries to send datas
5234 * So I add checks like in NT Server ...
5237 if (info_1->datatype) {
5238 if (strcmp(info_1->datatype, "RAW") != 0) {
5240 return WERR_INVALID_DATATYPE;
5244 /* get the share number of the printer */
5245 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5249 werr = print_job_start(p->server_info, snum,
5250 info_1->document_name, info_1->output_file,
5251 Printer->devmode, &Printer->jobid);
5253 /* An error occured in print_job_start() so return an appropriate
5256 if (!W_ERROR_IS_OK(werr)) {
5260 Printer->document_started = true;
5261 *r->out.job_id = Printer->jobid;
5266 /****************************************************************
5267 _spoolss_EndDocPrinter
5268 ****************************************************************/
5270 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5271 struct spoolss_EndDocPrinter *r)
5273 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5278 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5279 OUR_HANDLE(r->in.handle)));
5283 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5287 Printer->document_started = false;
5288 status = print_job_end(snum, Printer->jobid, NORMAL_CLOSE);
5289 if (!NT_STATUS_IS_OK(status)) {
5290 DEBUG(2, ("_spoolss_EndDocPrinter: "
5291 "print_job_end failed [%s]\n",
5292 nt_errstr(status)));
5296 return ntstatus_to_werror(status);
5299 /****************************************************************
5300 _spoolss_WritePrinter
5301 ****************************************************************/
5303 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5304 struct spoolss_WritePrinter *r)
5306 ssize_t buffer_written;
5308 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5311 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5312 OUR_HANDLE(r->in.handle)));
5313 *r->out.num_written = r->in._data_size;
5317 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5320 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5321 buffer_written = print_job_write(snum, Printer->jobid,
5322 (const char *)r->in.data.data,
5324 (size_t)r->in._data_size);
5325 if (buffer_written == (ssize_t)-1) {
5326 *r->out.num_written = 0;
5327 if (errno == ENOSPC)
5328 return WERR_NO_SPOOL_SPACE;
5330 return WERR_ACCESS_DENIED;
5333 *r->out.num_written = r->in._data_size;
5338 /********************************************************************
5339 * api_spoolss_getprinter
5340 * called from the spoolss dispatcher
5342 ********************************************************************/
5344 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5345 struct pipes_struct *p)
5348 WERROR errcode = WERR_BADFUNC;
5349 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5352 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5353 OUR_HANDLE(handle)));
5357 if (!get_printer_snum(p, handle, &snum, NULL))
5361 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5362 errcode = print_queue_pause(p->server_info, snum);
5364 case SPOOLSS_PRINTER_CONTROL_RESUME:
5365 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5366 errcode = print_queue_resume(p->server_info, snum);
5368 case SPOOLSS_PRINTER_CONTROL_PURGE:
5369 errcode = print_queue_purge(p->server_info, snum);
5372 return WERR_UNKNOWN_LEVEL;
5379 /****************************************************************
5380 _spoolss_AbortPrinter
5381 * From MSDN: "Deletes printer's spool file if printer is configured
5383 ****************************************************************/
5385 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5386 struct spoolss_AbortPrinter *r)
5388 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5390 WERROR errcode = WERR_OK;
5393 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5394 OUR_HANDLE(r->in.handle)));
5398 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5401 if (!Printer->document_started) {
5402 return WERR_SPL_NO_STARTDOC;
5405 errcode = print_job_delete(p->server_info, snum, Printer->jobid);
5410 /********************************************************************
5411 * called by spoolss_api_setprinter
5412 * when updating a printer description
5413 ********************************************************************/
5415 static WERROR update_printer_sec(struct policy_handle *handle,
5416 struct pipes_struct *p,
5417 struct sec_desc_buf *secdesc_ctr)
5419 struct spoolss_security_descriptor *new_secdesc = NULL;
5420 struct spoolss_security_descriptor *old_secdesc = NULL;
5421 const char *printer;
5425 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5427 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5428 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5429 OUR_HANDLE(handle)));
5431 result = WERR_BADFID;
5435 if (secdesc_ctr == NULL) {
5436 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5437 result = WERR_INVALID_PARAM;
5440 printer = lp_const_servicename(snum);
5442 /* Check the user has permissions to change the security
5443 descriptor. By experimentation with two NT machines, the user
5444 requires Full Access to the printer to change security
5447 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5448 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5449 result = WERR_ACCESS_DENIED;
5453 /* NT seems to like setting the security descriptor even though
5454 nothing may have actually changed. */
5455 result = winreg_get_printer_secdesc(p->mem_ctx,
5460 if (!W_ERROR_IS_OK(result)) {
5461 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5462 result = WERR_BADFID;
5466 if (DEBUGLEVEL >= 10) {
5467 struct security_acl *the_acl;
5470 the_acl = old_secdesc->dacl;
5471 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5472 printer, the_acl->num_aces));
5474 for (i = 0; i < the_acl->num_aces; i++) {
5475 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5476 &the_acl->aces[i].trustee),
5477 the_acl->aces[i].access_mask));
5480 the_acl = secdesc_ctr->sd->dacl;
5483 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5484 printer, the_acl->num_aces));
5486 for (i = 0; i < the_acl->num_aces; i++) {
5487 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5488 &the_acl->aces[i].trustee),
5489 the_acl->aces[i].access_mask));
5492 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5496 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
5497 if (new_secdesc == NULL) {
5498 result = WERR_NOMEM;
5502 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
5507 result = winreg_set_printer_secdesc(p->mem_ctx,
5517 /********************************************************************
5518 Canonicalize printer info from a client
5519 ********************************************************************/
5521 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
5522 struct spoolss_SetPrinterInfo2 *info2,
5525 fstring printername;
5528 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5529 "portname=%s drivername=%s comment=%s location=%s\n",
5530 info2->servername, info2->printername, info2->sharename,
5531 info2->portname, info2->drivername, info2->comment,
5534 /* we force some elements to "correct" values */
5535 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
5536 if (info2->servername == NULL) {
5539 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
5540 if (info2->sharename == NULL) {
5544 /* check to see if we allow printername != sharename */
5545 if (lp_force_printername(snum)) {
5546 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5547 global_myname(), info2->sharename);
5549 /* make sure printername is in \\server\printername format */
5550 fstrcpy(printername, info2->printername);
5552 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5553 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5557 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5558 global_myname(), p);
5560 if (info2->printername == NULL) {
5564 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5565 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5570 /****************************************************************************
5571 ****************************************************************************/
5573 static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri)
5575 char *cmd = lp_addport_cmd();
5576 char *command = NULL;
5578 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5579 bool is_print_op = false;
5582 return WERR_ACCESS_DENIED;
5585 command = talloc_asprintf(ctx,
5586 "%s \"%s\" \"%s\"", cmd, portname, uri );
5592 is_print_op = user_has_privileges( token, &se_printop );
5594 DEBUG(10,("Running [%s]\n", command));
5596 /********* BEGIN SePrintOperatorPrivilege **********/
5601 ret = smbrun(command, NULL);
5606 /********* END SePrintOperatorPrivilege **********/
5608 DEBUGADD(10,("returned [%d]\n", ret));
5610 TALLOC_FREE(command);
5613 return WERR_ACCESS_DENIED;
5619 /****************************************************************************
5620 ****************************************************************************/
5622 static bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
5623 struct spoolss_SetPrinterInfo2 *info2,
5624 const char *remote_machine,
5625 struct messaging_context *msg_ctx)
5627 char *cmd = lp_addprinter_cmd();
5629 char *command = NULL;
5633 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5634 bool is_print_op = false;
5636 if (!remote_machine) {
5640 command = talloc_asprintf(ctx,
5641 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5642 cmd, info2->printername, info2->sharename,
5643 info2->portname, info2->drivername,
5644 info2->location, info2->comment, remote_machine);
5650 is_print_op = user_has_privileges( token, &se_printop );
5652 DEBUG(10,("Running [%s]\n", command));
5654 /********* BEGIN SePrintOperatorPrivilege **********/
5659 if ( (ret = smbrun(command, &fd)) == 0 ) {
5660 /* Tell everyone we updated smb.conf. */
5661 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5667 /********* END SePrintOperatorPrivilege **********/
5669 DEBUGADD(10,("returned [%d]\n", ret));
5671 TALLOC_FREE(command);
5679 /* reload our services immediately */
5681 reload_services(false);
5685 /* Get lines and convert them back to dos-codepage */
5686 qlines = fd_lines_load(fd, &numlines, 0, NULL);
5687 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
5690 /* Set the portname to what the script says the portname should be. */
5691 /* but don't require anything to be return from the script exit a good error code */
5694 /* Set the portname to what the script says the portname should be. */
5695 info2->portname = talloc_strdup(ctx, qlines[0]);
5696 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
5699 TALLOC_FREE(qlines);
5703 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
5704 struct auth_serversupplied_info *server_info,
5705 struct messaging_context *msg_ctx,
5707 struct spoolss_SetPrinterInfo2 *printer,
5708 struct spoolss_PrinterInfo2 *old_printer)
5710 bool force_update = (old_printer == NULL);
5711 const char *dnsdomname;
5712 const char *longname;
5713 const char *uncname;
5714 const char *spooling;
5716 WERROR result = WERR_OK;
5718 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
5719 push_reg_sz(mem_ctx, &buffer, printer->drivername);
5720 winreg_set_printer_dataex(mem_ctx,
5724 SPOOL_DSSPOOLER_KEY,
5725 SPOOL_REG_DRIVERNAME,
5730 if (!force_update) {
5731 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
5732 printer->drivername));
5734 notify_printer_driver(snum, printer->drivername);
5738 if (force_update || !strequal(printer->comment, old_printer->comment)) {
5739 push_reg_sz(mem_ctx, &buffer, printer->comment);
5740 winreg_set_printer_dataex(mem_ctx,
5744 SPOOL_DSSPOOLER_KEY,
5745 SPOOL_REG_DESCRIPTION,
5750 if (!force_update) {
5751 notify_printer_comment(snum, printer->comment);
5755 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
5756 push_reg_sz(mem_ctx, &buffer, printer->sharename);
5757 winreg_set_printer_dataex(mem_ctx,
5761 SPOOL_DSSPOOLER_KEY,
5762 SPOOL_REG_PRINTSHARENAME,
5767 if (!force_update) {
5768 notify_printer_sharename(snum, printer->sharename);
5772 if (force_update || !strequal(printer->printername, old_printer->printername)) {
5775 p = strrchr(printer->printername, '\\' );
5779 p = printer->printername;
5782 push_reg_sz(mem_ctx, &buffer, p);
5783 winreg_set_printer_dataex(mem_ctx,
5787 SPOOL_DSSPOOLER_KEY,
5788 SPOOL_REG_PRINTERNAME,
5793 if (!force_update) {
5794 notify_printer_printername(snum, p);
5798 if (force_update || !strequal(printer->portname, old_printer->portname)) {
5799 push_reg_sz(mem_ctx, &buffer, printer->portname);
5800 winreg_set_printer_dataex(mem_ctx,
5804 SPOOL_DSSPOOLER_KEY,
5810 if (!force_update) {
5811 notify_printer_port(snum, printer->portname);
5815 if (force_update || !strequal(printer->location, old_printer->location)) {
5816 push_reg_sz(mem_ctx, &buffer, printer->location);
5817 winreg_set_printer_dataex(mem_ctx,
5821 SPOOL_DSSPOOLER_KEY,
5827 if (!force_update) {
5828 notify_printer_location(snum, printer->location);
5832 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
5833 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
5834 winreg_set_printer_dataex(mem_ctx,
5838 SPOOL_DSSPOOLER_KEY,
5839 SPOOL_REG_PRINTSEPARATORFILE,
5844 if (!force_update) {
5845 notify_printer_location(snum, printer->location);
5849 if (force_update || printer->starttime != old_printer->starttime) {
5850 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5851 SIVAL(buffer.data, 0, printer->starttime);
5852 winreg_set_printer_dataex(mem_ctx,
5856 SPOOL_DSSPOOLER_KEY,
5857 SPOOL_REG_PRINTSTARTTIME,
5863 if (force_update || printer->untiltime != old_printer->untiltime) {
5864 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5865 SIVAL(buffer.data, 0, printer->untiltime);
5866 winreg_set_printer_dataex(mem_ctx,
5870 SPOOL_DSSPOOLER_KEY,
5871 SPOOL_REG_PRINTENDTIME,
5877 if (force_update || printer->priority != old_printer->priority) {
5878 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5879 SIVAL(buffer.data, 0, printer->priority);
5880 winreg_set_printer_dataex(mem_ctx,
5884 SPOOL_DSSPOOLER_KEY,
5891 if (force_update || printer->attributes != old_printer->attributes) {
5892 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5893 SIVAL(buffer.data, 0, (printer->attributes &
5894 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
5895 winreg_set_printer_dataex(mem_ctx,
5899 SPOOL_DSSPOOLER_KEY,
5900 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
5905 switch (printer->attributes & 0x3) {
5907 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
5910 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
5913 spooling = SPOOL_REGVAL_PRINTDIRECT;
5916 spooling = "unknown";
5918 push_reg_sz(mem_ctx, &buffer, spooling);
5919 winreg_set_printer_dataex(mem_ctx,
5923 SPOOL_DSSPOOLER_KEY,
5924 SPOOL_REG_PRINTSPOOLING,
5930 push_reg_sz(mem_ctx, &buffer, global_myname());
5931 winreg_set_printer_dataex(mem_ctx,
5935 SPOOL_DSSPOOLER_KEY,
5936 SPOOL_REG_SHORTSERVERNAME,
5941 dnsdomname = get_mydnsfullname();
5942 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
5943 longname = talloc_strdup(mem_ctx, dnsdomname);
5945 longname = talloc_strdup(mem_ctx, global_myname());
5947 if (longname == NULL) {
5948 result = WERR_NOMEM;
5952 push_reg_sz(mem_ctx, &buffer, longname);
5953 winreg_set_printer_dataex(mem_ctx,
5957 SPOOL_DSSPOOLER_KEY,
5958 SPOOL_REG_SERVERNAME,
5963 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5964 global_myname(), printer->sharename);
5965 push_reg_sz(mem_ctx, &buffer, uncname);
5966 winreg_set_printer_dataex(mem_ctx,
5970 SPOOL_DSSPOOLER_KEY,
5980 /********************************************************************
5981 * Called by spoolss_api_setprinter
5982 * when updating a printer description.
5983 ********************************************************************/
5985 static WERROR update_printer(struct pipes_struct *p,
5986 struct policy_handle *handle,
5987 struct spoolss_SetPrinterInfoCtr *info_ctr,
5988 struct spoolss_DeviceMode *devmode)
5990 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
5991 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
5992 struct spoolss_PrinterInfo2 *old_printer;
5993 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5994 const char *servername = NULL;
5996 WERROR result = WERR_OK;
5997 TALLOC_CTX *tmp_ctx;
5999 DEBUG(8,("update_printer\n"));
6001 tmp_ctx = talloc_new(p->mem_ctx);
6002 if (tmp_ctx == NULL) {
6007 result = WERR_BADFID;
6011 if (!get_printer_snum(p, handle, &snum, NULL)) {
6012 result = WERR_BADFID;
6016 if (Printer != NULL || Printer->servername != NULL) {
6017 servername = Printer->servername;
6020 result = winreg_get_printer(tmp_ctx,
6024 lp_const_servicename(snum),
6026 if (!W_ERROR_IS_OK(result)) {
6027 result = WERR_BADFID;
6031 /* Do sanity check on the requested changes for Samba */
6032 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6033 result = WERR_INVALID_PARAM;
6037 /* FIXME!!! If the driver has changed we really should verify that
6038 it is installed before doing much else --jerry */
6040 /* Check calling user has permission to update printer description */
6041 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6042 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6043 result = WERR_ACCESS_DENIED;
6047 /* Call addprinter hook */
6048 /* Check changes to see if this is really needed */
6050 if (*lp_addprinter_cmd() &&
6051 (!strequal(printer->drivername, old_printer->drivername) ||
6052 !strequal(printer->comment, old_printer->comment) ||
6053 !strequal(printer->portname, old_printer->portname) ||
6054 !strequal(printer->location, old_printer->location)) )
6056 /* add_printer_hook() will call reload_services() */
6057 if (!add_printer_hook(tmp_ctx, p->server_info->ptok,
6058 printer, p->client_address,
6060 result = WERR_ACCESS_DENIED;
6065 update_dsspooler(tmp_ctx,
6072 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6074 if (devmode == NULL) {
6075 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6077 result = winreg_update_printer(tmp_ctx,
6087 talloc_free(tmp_ctx);
6092 /****************************************************************************
6093 ****************************************************************************/
6094 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6095 struct policy_handle *handle,
6096 struct spoolss_SetPrinterInfo7 *info7)
6099 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6102 Printer_entry *Printer;
6104 if ( lp_security() != SEC_ADS ) {
6105 return WERR_UNKNOWN_LEVEL;
6108 Printer = find_printer_index_by_hnd(p, handle);
6110 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6115 if (!get_printer_snum(p, handle, &snum, NULL))
6118 result = winreg_get_printer(p->mem_ctx, p->server_info, p->msg_ctx,
6119 Printer->servername,
6120 lp_servicename(snum), &pinfo2);
6121 if (!W_ERROR_IS_OK(result)) {
6125 nt_printer_publish(pinfo2, p->server_info, p->msg_ctx, pinfo2,
6128 TALLOC_FREE(pinfo2);
6131 return WERR_UNKNOWN_LEVEL;
6135 /********************************************************************
6136 ********************************************************************/
6138 static WERROR update_printer_devmode(struct pipes_struct *p,
6139 struct policy_handle *handle,
6140 struct spoolss_DeviceMode *devmode)
6143 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6144 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6146 DEBUG(8,("update_printer_devmode\n"));
6152 if (!get_printer_snum(p, handle, &snum, NULL)) {
6156 /* Check calling user has permission to update printer description */
6157 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6158 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6159 return WERR_ACCESS_DENIED;
6162 return winreg_update_printer(p->mem_ctx,
6165 lp_const_servicename(snum),
6173 /****************************************************************
6175 ****************************************************************/
6177 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6178 struct spoolss_SetPrinter *r)
6182 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6185 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6186 OUR_HANDLE(r->in.handle)));
6190 /* check the level */
6191 switch (r->in.info_ctr->level) {
6193 return control_printer(r->in.handle, r->in.command, p);
6195 result = update_printer(p, r->in.handle,
6197 r->in.devmode_ctr->devmode);
6198 if (!W_ERROR_IS_OK(result))
6200 if (r->in.secdesc_ctr->sd)
6201 result = update_printer_sec(r->in.handle, p,
6205 return update_printer_sec(r->in.handle, p,
6208 return publish_or_unpublish_printer(p, r->in.handle,
6209 r->in.info_ctr->info.info7);
6211 return update_printer_devmode(p, r->in.handle,
6212 r->in.devmode_ctr->devmode);
6214 return WERR_UNKNOWN_LEVEL;
6218 /****************************************************************
6219 _spoolss_FindClosePrinterNotify
6220 ****************************************************************/
6222 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6223 struct spoolss_FindClosePrinterNotify *r)
6225 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6228 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6229 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6233 if (Printer->notify.client_connected == true) {
6236 if ( Printer->printer_type == SPLHND_SERVER)
6238 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6239 !get_printer_snum(p, r->in.handle, &snum, NULL) )
6242 srv_spoolss_replycloseprinter(
6243 snum, &Printer->notify.client_hnd, p->msg_ctx);
6246 Printer->notify.flags=0;
6247 Printer->notify.options=0;
6248 Printer->notify.localmachine[0]='\0';
6249 Printer->notify.printerlocal=0;
6250 TALLOC_FREE(Printer->notify.option);
6251 Printer->notify.client_connected = false;
6256 /****************************************************************
6258 ****************************************************************/
6260 WERROR _spoolss_AddJob(struct pipes_struct *p,
6261 struct spoolss_AddJob *r)
6263 if (!r->in.buffer && (r->in.offered != 0)) {
6264 return WERR_INVALID_PARAM;
6267 /* this is what a NT server returns for AddJob. AddJob must fail on
6268 * non-local printers */
6270 if (r->in.level != 1) {
6271 return WERR_UNKNOWN_LEVEL;
6274 return WERR_INVALID_PARAM;
6277 /****************************************************************************
6279 ****************************************************************************/
6281 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6282 struct spoolss_JobInfo1 *r,
6283 const print_queue_struct *queue,
6284 int position, int snum,
6285 struct spoolss_PrinterInfo2 *pinfo2)
6289 t = gmtime(&queue->time);
6291 r->job_id = queue->job;
6293 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6294 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6295 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6296 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6297 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6298 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6299 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6300 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6301 r->data_type = talloc_strdup(mem_ctx, "RAW");
6302 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6303 r->text_status = talloc_strdup(mem_ctx, "");
6304 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6306 r->status = nt_printj_status(queue->status);
6307 r->priority = queue->priority;
6308 r->position = position;
6309 r->total_pages = queue->page_count;
6310 r->pages_printed = 0; /* ??? */
6312 init_systemtime(&r->submitted, t);
6317 /****************************************************************************
6319 ****************************************************************************/
6321 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6322 struct spoolss_JobInfo2 *r,
6323 const print_queue_struct *queue,
6324 int position, int snum,
6325 struct spoolss_PrinterInfo2 *pinfo2,
6326 struct spoolss_DeviceMode *devmode)
6330 t = gmtime(&queue->time);
6332 r->job_id = queue->job;
6334 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6335 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6336 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6337 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6338 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6339 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6340 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6341 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6342 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6343 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6344 r->data_type = talloc_strdup(mem_ctx, "RAW");
6345 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6346 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6347 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6348 r->parameters = talloc_strdup(mem_ctx, "");
6349 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6350 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6351 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6353 r->devmode = devmode;
6355 r->text_status = talloc_strdup(mem_ctx, "");
6356 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6360 r->status = nt_printj_status(queue->status);
6361 r->priority = queue->priority;
6362 r->position = position;
6365 r->total_pages = queue->page_count;
6366 r->size = queue->size;
6367 init_systemtime(&r->submitted, t);
6369 r->pages_printed = 0; /* ??? */
6374 /****************************************************************************
6376 ****************************************************************************/
6378 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6379 struct spoolss_JobInfo3 *r,
6380 const print_queue_struct *queue,
6381 const print_queue_struct *next_queue,
6382 int position, int snum,
6383 struct spoolss_PrinterInfo2 *pinfo2)
6385 r->job_id = queue->job;
6388 r->next_job_id = next_queue->job;
6395 /****************************************************************************
6396 Enumjobs at level 1.
6397 ****************************************************************************/
6399 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6400 const print_queue_struct *queue,
6401 uint32_t num_queues, int snum,
6402 struct spoolss_PrinterInfo2 *pinfo2,
6403 union spoolss_JobInfo **info_p,
6406 union spoolss_JobInfo *info;
6408 WERROR result = WERR_OK;
6410 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6411 W_ERROR_HAVE_NO_MEMORY(info);
6413 *count = num_queues;
6415 for (i=0; i<*count; i++) {
6416 result = fill_job_info1(info,
6422 if (!W_ERROR_IS_OK(result)) {
6428 if (!W_ERROR_IS_OK(result)) {
6439 /****************************************************************************
6440 Enumjobs at level 2.
6441 ****************************************************************************/
6443 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6444 const print_queue_struct *queue,
6445 uint32_t num_queues, int snum,
6446 struct spoolss_PrinterInfo2 *pinfo2,
6447 union spoolss_JobInfo **info_p,
6450 union spoolss_JobInfo *info;
6452 WERROR result = WERR_OK;
6454 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6455 W_ERROR_HAVE_NO_MEMORY(info);
6457 *count = num_queues;
6459 for (i=0; i<*count; i++) {
6460 struct spoolss_DeviceMode *devmode;
6462 result = spoolss_create_default_devmode(info,
6463 pinfo2->printername,
6465 if (!W_ERROR_IS_OK(result)) {
6466 DEBUG(3, ("Can't proceed w/o a devmode!"));
6470 result = fill_job_info2(info,
6477 if (!W_ERROR_IS_OK(result)) {
6483 if (!W_ERROR_IS_OK(result)) {
6494 /****************************************************************************
6495 Enumjobs at level 3.
6496 ****************************************************************************/
6498 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6499 const print_queue_struct *queue,
6500 uint32_t num_queues, int snum,
6501 struct spoolss_PrinterInfo2 *pinfo2,
6502 union spoolss_JobInfo **info_p,
6505 union spoolss_JobInfo *info;
6507 WERROR result = WERR_OK;
6509 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6510 W_ERROR_HAVE_NO_MEMORY(info);
6512 *count = num_queues;
6514 for (i=0; i<*count; i++) {
6515 const print_queue_struct *next_queue = NULL;
6518 next_queue = &queue[i+1];
6521 result = fill_job_info3(info,
6528 if (!W_ERROR_IS_OK(result)) {
6534 if (!W_ERROR_IS_OK(result)) {
6545 /****************************************************************
6547 ****************************************************************/
6549 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
6550 struct spoolss_EnumJobs *r)
6553 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6555 print_status_struct prt_status;
6556 print_queue_struct *queue = NULL;
6559 /* that's an [in out] buffer */
6561 if (!r->in.buffer && (r->in.offered != 0)) {
6562 return WERR_INVALID_PARAM;
6565 DEBUG(4,("_spoolss_EnumJobs\n"));
6569 *r->out.info = NULL;
6571 /* lookup the printer snum and tdb entry */
6573 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6577 result = winreg_get_printer(p->mem_ctx, p->server_info, p->msg_ctx,
6578 NULL, lp_servicename(snum), &pinfo2);
6579 if (!W_ERROR_IS_OK(result)) {
6583 count = print_queue_status(snum, &queue, &prt_status);
6584 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6585 count, prt_status.status, prt_status.message));
6589 TALLOC_FREE(pinfo2);
6593 switch (r->in.level) {
6595 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6596 pinfo2, r->out.info, r->out.count);
6599 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6600 pinfo2, r->out.info, r->out.count);
6603 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
6604 pinfo2, r->out.info, r->out.count);
6607 result = WERR_UNKNOWN_LEVEL;
6612 TALLOC_FREE(pinfo2);
6614 if (!W_ERROR_IS_OK(result)) {
6618 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6620 *r->out.info, r->in.level,
6622 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6623 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6625 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6628 /****************************************************************
6629 _spoolss_ScheduleJob
6630 ****************************************************************/
6632 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
6633 struct spoolss_ScheduleJob *r)
6638 /****************************************************************
6639 ****************************************************************/
6641 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
6642 const char *printer_name,
6644 struct spoolss_SetJobInfo1 *r)
6648 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
6652 if (strequal(old_doc_name, r->document_name)) {
6656 if (!print_job_set_name(printer_name, job_id, r->document_name)) {
6663 /****************************************************************
6665 ****************************************************************/
6667 WERROR _spoolss_SetJob(struct pipes_struct *p,
6668 struct spoolss_SetJob *r)
6671 WERROR errcode = WERR_BADFUNC;
6673 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6677 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6678 return WERR_INVALID_PRINTER_NAME;
6681 switch (r->in.command) {
6682 case SPOOLSS_JOB_CONTROL_CANCEL:
6683 case SPOOLSS_JOB_CONTROL_DELETE:
6684 errcode = print_job_delete(p->server_info,
6685 snum, r->in.job_id);
6686 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
6690 case SPOOLSS_JOB_CONTROL_PAUSE:
6691 if (print_job_pause(p->server_info, snum, r->in.job_id, &errcode)) {
6695 case SPOOLSS_JOB_CONTROL_RESTART:
6696 case SPOOLSS_JOB_CONTROL_RESUME:
6697 if (print_job_resume(p->server_info, snum, r->in.job_id, &errcode)) {
6705 return WERR_UNKNOWN_LEVEL;
6708 if (!W_ERROR_IS_OK(errcode)) {
6712 if (r->in.ctr == NULL) {
6716 switch (r->in.ctr->level) {
6718 errcode = spoolss_setjob_1(p->mem_ctx, lp_const_servicename(snum),
6720 r->in.ctr->info.info1);
6726 return WERR_UNKNOWN_LEVEL;
6732 /****************************************************************************
6733 Enumerates all printer drivers by level and architecture.
6734 ****************************************************************************/
6736 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
6737 struct auth_serversupplied_info *server_info,
6738 struct messaging_context *msg_ctx,
6739 const char *servername,
6740 const char *architecture,
6742 union spoolss_DriverInfo **info_p,
6747 struct spoolss_DriverInfo8 *driver;
6748 union spoolss_DriverInfo *info = NULL;
6750 WERROR result = WERR_OK;
6751 uint32_t num_drivers;
6752 const char **drivers;
6757 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6758 result = winreg_get_driver_list(mem_ctx, server_info, msg_ctx,
6759 architecture, version,
6760 &num_drivers, &drivers);
6761 if (!W_ERROR_IS_OK(result)) {
6764 DEBUG(4, ("we have:[%d] drivers in environment"
6765 " [%s] and version [%d]\n",
6766 num_drivers, architecture, version));
6768 if (num_drivers != 0) {
6769 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6770 union spoolss_DriverInfo,
6771 count + num_drivers);
6773 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
6774 "failed to enlarge driver info buffer!\n"));
6775 result = WERR_NOMEM;
6780 for (i = 0; i < num_drivers; i++) {
6781 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
6783 result = winreg_get_driver(mem_ctx, server_info,
6785 architecture, drivers[i],
6787 if (!W_ERROR_IS_OK(result)) {
6793 result = fill_printer_driver_info1(info, &info[count+i].info1,
6794 driver, servername);
6797 result = fill_printer_driver_info2(info, &info[count+i].info2,
6798 driver, servername);
6801 result = fill_printer_driver_info3(info, &info[count+i].info3,
6802 driver, servername);
6805 result = fill_printer_driver_info4(info, &info[count+i].info4,
6806 driver, servername);
6809 result = fill_printer_driver_info5(info, &info[count+i].info5,
6810 driver, servername);
6813 result = fill_printer_driver_info6(info, &info[count+i].info6,
6814 driver, servername);
6817 result = fill_printer_driver_info8(info, &info[count+i].info8,
6818 driver, servername);
6821 result = WERR_UNKNOWN_LEVEL;
6825 TALLOC_FREE(driver);
6827 if (!W_ERROR_IS_OK(result)) {
6832 count += num_drivers;
6833 TALLOC_FREE(drivers);
6837 TALLOC_FREE(drivers);
6839 if (!W_ERROR_IS_OK(result)) {
6850 /****************************************************************************
6851 Enumerates all printer drivers by level.
6852 ****************************************************************************/
6854 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
6855 struct auth_serversupplied_info *server_info,
6856 struct messaging_context *msg_ctx,
6857 const char *servername,
6858 const char *architecture,
6860 union spoolss_DriverInfo **info_p,
6864 WERROR result = WERR_OK;
6866 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
6868 for (a=0; archi_table[a].long_archi != NULL; a++) {
6870 union spoolss_DriverInfo *info = NULL;
6873 result = enumprinterdrivers_level_by_architecture(mem_ctx,
6877 archi_table[a].long_archi,
6881 if (!W_ERROR_IS_OK(result)) {
6885 for (i=0; i < count; i++) {
6886 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
6887 info[i], info_p, count_p);
6894 return enumprinterdrivers_level_by_architecture(mem_ctx,
6904 /****************************************************************
6905 _spoolss_EnumPrinterDrivers
6906 ****************************************************************/
6908 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
6909 struct spoolss_EnumPrinterDrivers *r)
6911 const char *cservername;
6914 /* that's an [in out] buffer */
6916 if (!r->in.buffer && (r->in.offered != 0)) {
6917 return WERR_INVALID_PARAM;
6920 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
6924 *r->out.info = NULL;
6926 cservername = canon_servername(r->in.server);
6928 if (!is_myname_or_ipaddr(cservername)) {
6929 return WERR_UNKNOWN_PRINTER_DRIVER;
6932 result = enumprinterdrivers_level(p->mem_ctx,
6940 if (!W_ERROR_IS_OK(result)) {
6944 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6945 spoolss_EnumPrinterDrivers,
6946 *r->out.info, r->in.level,
6948 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6949 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6951 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6954 /****************************************************************
6956 ****************************************************************/
6958 WERROR _spoolss_EnumForms(struct pipes_struct *p,
6959 struct spoolss_EnumForms *r)
6965 *r->out.info = NULL;
6967 /* that's an [in out] buffer */
6969 if (!r->in.buffer && (r->in.offered != 0) ) {
6970 return WERR_INVALID_PARAM;
6973 DEBUG(4,("_spoolss_EnumForms\n"));
6974 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6975 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6977 switch (r->in.level) {
6979 result = winreg_printer_enumforms1(p->mem_ctx,
6986 result = WERR_UNKNOWN_LEVEL;
6990 if (!W_ERROR_IS_OK(result)) {
6994 if (*r->out.count == 0) {
6995 return WERR_NO_MORE_ITEMS;
6998 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7000 *r->out.info, r->in.level,
7002 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7003 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7005 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7008 /****************************************************************
7010 ****************************************************************/
7012 WERROR _spoolss_GetForm(struct pipes_struct *p,
7013 struct spoolss_GetForm *r)
7017 /* that's an [in out] buffer */
7019 if (!r->in.buffer && (r->in.offered != 0)) {
7020 return WERR_INVALID_PARAM;
7023 DEBUG(4,("_spoolss_GetForm\n"));
7024 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7025 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7027 switch (r->in.level) {
7029 result = winreg_printer_getform1(p->mem_ctx,
7033 &r->out.info->info1);
7036 result = WERR_UNKNOWN_LEVEL;
7040 if (!W_ERROR_IS_OK(result)) {
7041 TALLOC_FREE(r->out.info);
7045 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7046 r->out.info, r->in.level);
7047 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7049 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7052 /****************************************************************************
7053 ****************************************************************************/
7055 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7056 struct spoolss_PortInfo1 *r,
7059 r->port_name = talloc_strdup(mem_ctx, name);
7060 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7065 /****************************************************************************
7066 TODO: This probably needs distinguish between TCP/IP and Local ports
7068 ****************************************************************************/
7070 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7071 struct spoolss_PortInfo2 *r,
7074 r->port_name = talloc_strdup(mem_ctx, name);
7075 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7077 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7078 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7080 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7081 W_ERROR_HAVE_NO_MEMORY(r->description);
7083 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7090 /****************************************************************************
7091 wrapper around the enumer ports command
7092 ****************************************************************************/
7094 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7096 char *cmd = lp_enumports_cmd();
7097 char **qlines = NULL;
7098 char *command = NULL;
7106 /* if no hook then just fill in the default port */
7109 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7112 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7113 TALLOC_FREE(qlines);
7120 /* we have a valid enumport command */
7122 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7127 DEBUG(10,("Running [%s]\n", command));
7128 ret = smbrun(command, &fd);
7129 DEBUG(10,("Returned [%d]\n", ret));
7130 TALLOC_FREE(command);
7135 return WERR_ACCESS_DENIED;
7139 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7140 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7150 /****************************************************************************
7152 ****************************************************************************/
7154 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7155 union spoolss_PortInfo **info_p,
7158 union spoolss_PortInfo *info = NULL;
7160 WERROR result = WERR_OK;
7161 char **qlines = NULL;
7164 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7165 if (!W_ERROR_IS_OK(result)) {
7170 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7172 DEBUG(10,("Returning WERR_NOMEM\n"));
7173 result = WERR_NOMEM;
7177 for (i=0; i<numlines; i++) {
7178 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7179 result = fill_port_1(info, &info[i].info1, qlines[i]);
7180 if (!W_ERROR_IS_OK(result)) {
7185 TALLOC_FREE(qlines);
7188 if (!W_ERROR_IS_OK(result)) {
7190 TALLOC_FREE(qlines);
7202 /****************************************************************************
7204 ****************************************************************************/
7206 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7207 union spoolss_PortInfo **info_p,
7210 union spoolss_PortInfo *info = NULL;
7212 WERROR result = WERR_OK;
7213 char **qlines = NULL;
7216 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7217 if (!W_ERROR_IS_OK(result)) {
7222 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7224 DEBUG(10,("Returning WERR_NOMEM\n"));
7225 result = WERR_NOMEM;
7229 for (i=0; i<numlines; i++) {
7230 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7231 result = fill_port_2(info, &info[i].info2, qlines[i]);
7232 if (!W_ERROR_IS_OK(result)) {
7237 TALLOC_FREE(qlines);
7240 if (!W_ERROR_IS_OK(result)) {
7242 TALLOC_FREE(qlines);
7254 /****************************************************************
7256 ****************************************************************/
7258 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
7259 struct spoolss_EnumPorts *r)
7263 /* that's an [in out] buffer */
7265 if (!r->in.buffer && (r->in.offered != 0)) {
7266 return WERR_INVALID_PARAM;
7269 DEBUG(4,("_spoolss_EnumPorts\n"));
7273 *r->out.info = NULL;
7275 switch (r->in.level) {
7277 result = enumports_level_1(p->mem_ctx, r->out.info,
7281 result = enumports_level_2(p->mem_ctx, r->out.info,
7285 return WERR_UNKNOWN_LEVEL;
7288 if (!W_ERROR_IS_OK(result)) {
7292 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7294 *r->out.info, r->in.level,
7296 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7297 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7299 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7302 /****************************************************************************
7303 ****************************************************************************/
7305 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
7307 struct spoolss_SetPrinterInfoCtr *info_ctr,
7308 struct spoolss_DeviceMode *devmode,
7309 struct security_descriptor *secdesc,
7310 struct spoolss_UserLevelCtr *user_ctr,
7311 struct policy_handle *handle)
7313 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7314 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7316 WERROR err = WERR_OK;
7318 /* samba does not have a concept of local, non-shared printers yet, so
7319 * make sure we always setup sharename - gd */
7320 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7321 (info2->printername != NULL && info2->printername[0] != '\0')) {
7322 DEBUG(5, ("spoolss_addprinterex_level_2: "
7323 "no sharename has been set, setting printername %s as sharename\n",
7324 info2->printername));
7325 info2->sharename = info2->printername;
7328 /* check to see if the printer already exists */
7329 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7330 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7332 return WERR_PRINTER_ALREADY_EXISTS;
7335 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7336 if ((snum = print_queue_snum(info2->printername)) != -1) {
7337 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7338 info2->printername));
7339 return WERR_PRINTER_ALREADY_EXISTS;
7343 /* validate printer info struct */
7344 if (!info2->printername || strlen(info2->printername) == 0) {
7345 return WERR_INVALID_PRINTER_NAME;
7347 if (!info2->portname || strlen(info2->portname) == 0) {
7348 return WERR_UNKNOWN_PORT;
7350 if (!info2->drivername || strlen(info2->drivername) == 0) {
7351 return WERR_UNKNOWN_PRINTER_DRIVER;
7353 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7354 return WERR_UNKNOWN_PRINTPROCESSOR;
7357 /* FIXME!!! smbd should check to see if the driver is installed before
7358 trying to add a printer like this --jerry */
7360 if (*lp_addprinter_cmd() ) {
7361 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7362 info2, p->client_address,
7364 return WERR_ACCESS_DENIED;
7367 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7368 "smb.conf parameter \"addprinter command\" is defined. This"
7369 "parameter must exist for this call to succeed\n",
7370 info2->sharename ));
7373 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7374 return WERR_ACCESS_DENIED;
7377 /* you must be a printer admin to add a new printer */
7378 if (!print_access_check(p->server_info, p->msg_ctx, snum,
7379 PRINTER_ACCESS_ADMINISTER)) {
7380 return WERR_ACCESS_DENIED;
7384 * Do sanity check on the requested changes for Samba.
7387 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7388 return WERR_INVALID_PARAM;
7391 if (devmode == NULL) {
7392 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7395 update_dsspooler(p->mem_ctx,
7402 err = winreg_update_printer(p->mem_ctx,
7410 if (!W_ERROR_IS_OK(err)) {
7414 if (!open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER)) {
7415 /* Handle open failed - remove addition. */
7416 ZERO_STRUCTP(handle);
7417 return WERR_ACCESS_DENIED;
7423 /****************************************************************
7424 _spoolss_AddPrinterEx
7425 ****************************************************************/
7427 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
7428 struct spoolss_AddPrinterEx *r)
7430 switch (r->in.info_ctr->level) {
7432 /* we don't handle yet */
7433 /* but I know what to do ... */
7434 return WERR_UNKNOWN_LEVEL;
7436 return spoolss_addprinterex_level_2(p, r->in.server,
7438 r->in.devmode_ctr->devmode,
7439 r->in.secdesc_ctr->sd,
7440 r->in.userlevel_ctr,
7443 return WERR_UNKNOWN_LEVEL;
7447 /****************************************************************
7449 ****************************************************************/
7451 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
7452 struct spoolss_AddPrinter *r)
7454 struct spoolss_AddPrinterEx a;
7455 struct spoolss_UserLevelCtr userlevel_ctr;
7457 ZERO_STRUCT(userlevel_ctr);
7459 userlevel_ctr.level = 1;
7461 a.in.server = r->in.server;
7462 a.in.info_ctr = r->in.info_ctr;
7463 a.in.devmode_ctr = r->in.devmode_ctr;
7464 a.in.secdesc_ctr = r->in.secdesc_ctr;
7465 a.in.userlevel_ctr = &userlevel_ctr;
7466 a.out.handle = r->out.handle;
7468 return _spoolss_AddPrinterEx(p, &a);
7471 /****************************************************************
7472 _spoolss_AddPrinterDriverEx
7473 ****************************************************************/
7475 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
7476 struct spoolss_AddPrinterDriverEx *r)
7478 WERROR err = WERR_OK;
7479 const char *driver_name = NULL;
7484 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7485 fn = "_spoolss_AddPrinterDriver";
7487 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7488 fn = "_spoolss_AddPrinterDriverEx";
7491 return WERR_INVALID_PARAM;
7495 * we only support the semantics of AddPrinterDriver()
7496 * i.e. only copy files that are newer than existing ones
7499 if (r->in.flags == 0) {
7500 return WERR_INVALID_PARAM;
7503 if (r->in.flags != APD_COPY_NEW_FILES) {
7504 return WERR_ACCESS_DENIED;
7508 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7509 /* Clever hack from Martin Zielinski <mz@seh.de>
7510 * to allow downgrade from level 8 (Vista).
7512 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7513 r->in.info_ctr->level));
7514 return WERR_UNKNOWN_LEVEL;
7517 DEBUG(5,("Cleaning driver's information\n"));
7518 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
7519 if (!W_ERROR_IS_OK(err))
7522 DEBUG(5,("Moving driver to final destination\n"));
7523 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7528 err = winreg_add_driver(p->mem_ctx, p->server_info, p->msg_ctx,
7529 r->in.info_ctr, &driver_name, &version);
7530 if (!W_ERROR_IS_OK(err)) {
7535 * I think this is where he DrvUpgradePrinter() hook would be
7536 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7537 * server. Right now, we just need to send ourselves a message
7538 * to update each printer bound to this driver. --jerry
7541 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
7542 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7550 /****************************************************************
7551 _spoolss_AddPrinterDriver
7552 ****************************************************************/
7554 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
7555 struct spoolss_AddPrinterDriver *r)
7557 struct spoolss_AddPrinterDriverEx a;
7559 switch (r->in.info_ctr->level) {
7566 return WERR_UNKNOWN_LEVEL;
7569 a.in.servername = r->in.servername;
7570 a.in.info_ctr = r->in.info_ctr;
7571 a.in.flags = APD_COPY_NEW_FILES;
7573 return _spoolss_AddPrinterDriverEx(p, &a);
7576 /****************************************************************************
7577 ****************************************************************************/
7579 struct _spoolss_paths {
7585 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7587 static const struct _spoolss_paths spoolss_paths[]= {
7588 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7589 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7592 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7593 const char *servername,
7594 const char *environment,
7598 const char *pservername = NULL;
7599 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7600 const char *short_archi;
7604 /* environment may be empty */
7605 if (environment && strlen(environment)) {
7606 long_archi = environment;
7609 /* servername may be empty */
7610 if (servername && strlen(servername)) {
7611 pservername = canon_servername(servername);
7613 if (!is_myname_or_ipaddr(pservername)) {
7614 return WERR_INVALID_PARAM;
7618 if (!(short_archi = get_short_archi(long_archi))) {
7619 return WERR_INVALID_ENVIRONMENT;
7622 switch (component) {
7623 case SPOOLSS_PRTPROCS_PATH:
7624 case SPOOLSS_DRIVER_PATH:
7626 *path = talloc_asprintf(mem_ctx,
7629 spoolss_paths[component].share,
7632 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7633 SPOOLSS_DEFAULT_SERVER_PATH,
7634 spoolss_paths[component].dir,
7639 return WERR_INVALID_PARAM;
7649 /****************************************************************************
7650 ****************************************************************************/
7652 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7653 const char *servername,
7654 const char *environment,
7655 struct spoolss_DriverDirectoryInfo1 *r)
7660 werr = compose_spoolss_server_path(mem_ctx,
7663 SPOOLSS_DRIVER_PATH,
7665 if (!W_ERROR_IS_OK(werr)) {
7669 DEBUG(4,("printer driver directory: [%s]\n", path));
7671 r->directory_name = path;
7676 /****************************************************************
7677 _spoolss_GetPrinterDriverDirectory
7678 ****************************************************************/
7680 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
7681 struct spoolss_GetPrinterDriverDirectory *r)
7685 /* that's an [in out] buffer */
7687 if (!r->in.buffer && (r->in.offered != 0)) {
7688 return WERR_INVALID_PARAM;
7691 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
7696 /* r->in.level is ignored */
7698 werror = getprinterdriverdir_level_1(p->mem_ctx,
7701 &r->out.info->info1);
7702 if (!W_ERROR_IS_OK(werror)) {
7703 TALLOC_FREE(r->out.info);
7707 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
7708 r->out.info, r->in.level);
7709 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7711 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7714 /****************************************************************
7715 _spoolss_EnumPrinterData
7716 ****************************************************************/
7718 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
7719 struct spoolss_EnumPrinterData *r)
7722 struct spoolss_EnumPrinterDataEx r2;
7724 struct spoolss_PrinterEnumValues *info, *val = NULL;
7727 r2.in.handle = r->in.handle;
7728 r2.in.key_name = "PrinterDriverData";
7730 r2.out.count = &count;
7731 r2.out.info = &info;
7732 r2.out.needed = &needed;
7734 result = _spoolss_EnumPrinterDataEx(p, &r2);
7735 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
7736 r2.in.offered = needed;
7737 result = _spoolss_EnumPrinterDataEx(p, &r2);
7739 if (!W_ERROR_IS_OK(result)) {
7744 * The NT machine wants to know the biggest size of value and data
7746 * cf: MSDN EnumPrinterData remark section
7749 if (!r->in.value_offered && !r->in.data_offered) {
7750 uint32_t biggest_valuesize = 0;
7751 uint32_t biggest_datasize = 0;
7754 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
7756 for (i=0; i<count; i++) {
7758 name_length = strlen(info[i].value_name);
7759 if (strlen(info[i].value_name) > biggest_valuesize) {
7760 biggest_valuesize = name_length;
7763 if (info[i].data_length > biggest_datasize) {
7764 biggest_datasize = info[i].data_length;
7767 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
7771 /* the value is an UNICODE string but real_value_size is the length
7772 in bytes including the trailing 0 */
7774 *r->out.value_needed = 2 * (1 + biggest_valuesize);
7775 *r->out.data_needed = biggest_datasize;
7777 DEBUG(6,("final values: [%d], [%d]\n",
7778 *r->out.value_needed, *r->out.data_needed));
7783 if (r->in.enum_index < count) {
7784 val = &info[r->in.enum_index];
7788 /* out_value should default to "" or else NT4 has
7789 problems unmarshalling the response */
7791 if (r->in.value_offered) {
7792 *r->out.value_needed = 1;
7793 r->out.value_name = talloc_strdup(r, "");
7794 if (!r->out.value_name) {
7798 r->out.value_name = NULL;
7799 *r->out.value_needed = 0;
7802 /* the data is counted in bytes */
7804 *r->out.data_needed = r->in.data_offered;
7806 result = WERR_NO_MORE_ITEMS;
7810 * - counted in bytes in the request
7811 * - counted in UNICODE chars in the max reply
7812 * - counted in bytes in the real size
7814 * take a pause *before* coding not *during* coding
7818 if (r->in.value_offered) {
7819 r->out.value_name = talloc_strdup(r, val->value_name);
7820 if (!r->out.value_name) {
7823 *r->out.value_needed = val->value_name_len;
7825 r->out.value_name = NULL;
7826 *r->out.value_needed = 0;
7831 *r->out.type = val->type;
7833 /* data - counted in bytes */
7836 * See the section "Dynamically Typed Query Parameters"
7840 if (r->out.data && val->data && val->data->data &&
7841 val->data_length && r->in.data_offered) {
7842 memcpy(r->out.data, val->data->data,
7843 MIN(val->data_length,r->in.data_offered));
7846 *r->out.data_needed = val->data_length;
7854 /****************************************************************
7855 _spoolss_SetPrinterData
7856 ****************************************************************/
7858 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
7859 struct spoolss_SetPrinterData *r)
7861 struct spoolss_SetPrinterDataEx r2;
7863 r2.in.handle = r->in.handle;
7864 r2.in.key_name = "PrinterDriverData";
7865 r2.in.value_name = r->in.value_name;
7866 r2.in.type = r->in.type;
7867 r2.in.data = r->in.data;
7868 r2.in.offered = r->in.offered;
7870 return _spoolss_SetPrinterDataEx(p, &r2);
7873 /****************************************************************
7874 _spoolss_ResetPrinter
7875 ****************************************************************/
7877 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
7878 struct spoolss_ResetPrinter *r)
7880 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7883 DEBUG(5,("_spoolss_ResetPrinter\n"));
7886 * All we do is to check to see if the handle and queue is valid.
7887 * This call really doesn't mean anything to us because we only
7888 * support RAW printing. --jerry
7892 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
7893 OUR_HANDLE(r->in.handle)));
7897 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
7901 /* blindly return success */
7905 /****************************************************************
7906 _spoolss_DeletePrinterData
7907 ****************************************************************/
7909 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
7910 struct spoolss_DeletePrinterData *r)
7912 struct spoolss_DeletePrinterDataEx r2;
7914 r2.in.handle = r->in.handle;
7915 r2.in.key_name = "PrinterDriverData";
7916 r2.in.value_name = r->in.value_name;
7918 return _spoolss_DeletePrinterDataEx(p, &r2);
7921 /****************************************************************
7923 ****************************************************************/
7925 WERROR _spoolss_AddForm(struct pipes_struct *p,
7926 struct spoolss_AddForm *r)
7928 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
7930 WERROR status = WERR_OK;
7931 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7933 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7935 DEBUG(5,("_spoolss_AddForm\n"));
7938 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
7939 OUR_HANDLE(r->in.handle)));
7943 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
7944 and not a printer admin, then fail */
7946 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7947 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7948 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7949 p->server_info->info3->base.domain.string,
7951 p->server_info->ptok,
7952 lp_printer_admin(snum))) {
7953 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
7954 return WERR_ACCESS_DENIED;
7957 switch (form->flags) {
7958 case SPOOLSS_FORM_USER:
7959 case SPOOLSS_FORM_BUILTIN:
7960 case SPOOLSS_FORM_PRINTER:
7963 return WERR_INVALID_PARAM;
7966 status = winreg_printer_addform1(p->mem_ctx, p->server_info,
7968 if (!W_ERROR_IS_OK(status)) {
7973 * ChangeID must always be set if this is a printer
7975 if (Printer->printer_type == SPLHND_PRINTER) {
7976 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7980 status = winreg_printer_update_changeid(p->mem_ctx,
7983 lp_const_servicename(snum));
7984 if (!W_ERROR_IS_OK(status)) {
7992 /****************************************************************
7994 ****************************************************************/
7996 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
7997 struct spoolss_DeleteForm *r)
7999 const char *form_name = r->in.form_name;
8000 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8002 WERROR status = WERR_OK;
8003 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8005 DEBUG(5,("_spoolss_DeleteForm\n"));
8008 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8009 OUR_HANDLE(r->in.handle)));
8013 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8014 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8015 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8016 p->server_info->info3->base.domain.string,
8018 p->server_info->ptok,
8019 lp_printer_admin(snum))) {
8020 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8021 return WERR_ACCESS_DENIED;
8024 status = winreg_printer_deleteform1(p->mem_ctx,
8028 if (!W_ERROR_IS_OK(status)) {
8033 * ChangeID must always be set if this is a printer
8035 if (Printer->printer_type == SPLHND_PRINTER) {
8036 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8040 status = winreg_printer_update_changeid(p->mem_ctx,
8043 lp_const_servicename(snum));
8044 if (!W_ERROR_IS_OK(status)) {
8052 /****************************************************************
8054 ****************************************************************/
8056 WERROR _spoolss_SetForm(struct pipes_struct *p,
8057 struct spoolss_SetForm *r)
8059 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8060 const char *form_name = r->in.form_name;
8062 WERROR status = WERR_OK;
8063 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8065 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8067 DEBUG(5,("_spoolss_SetForm\n"));
8070 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8071 OUR_HANDLE(r->in.handle)));
8075 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8076 and not a printer admin, then fail */
8078 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8079 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8080 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8081 p->server_info->info3->base.domain.string,
8083 p->server_info->ptok,
8084 lp_printer_admin(snum))) {
8085 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8086 return WERR_ACCESS_DENIED;
8089 status = winreg_printer_setform1(p->mem_ctx,
8094 if (!W_ERROR_IS_OK(status)) {
8099 * ChangeID must always be set if this is a printer
8101 if (Printer->printer_type == SPLHND_PRINTER) {
8102 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8106 status = winreg_printer_update_changeid(p->mem_ctx,
8109 lp_const_servicename(snum));
8110 if (!W_ERROR_IS_OK(status)) {
8118 /****************************************************************************
8119 fill_print_processor1
8120 ****************************************************************************/
8122 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8123 struct spoolss_PrintProcessorInfo1 *r,
8124 const char *print_processor_name)
8126 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8127 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8132 /****************************************************************************
8133 enumprintprocessors level 1.
8134 ****************************************************************************/
8136 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8137 union spoolss_PrintProcessorInfo **info_p,
8140 union spoolss_PrintProcessorInfo *info;
8143 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8144 W_ERROR_HAVE_NO_MEMORY(info);
8148 result = fill_print_processor1(info, &info[0].info1, "winprint");
8149 if (!W_ERROR_IS_OK(result)) {
8154 if (!W_ERROR_IS_OK(result)) {
8165 /****************************************************************
8166 _spoolss_EnumPrintProcessors
8167 ****************************************************************/
8169 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8170 struct spoolss_EnumPrintProcessors *r)
8174 /* that's an [in out] buffer */
8176 if (!r->in.buffer && (r->in.offered != 0)) {
8177 return WERR_INVALID_PARAM;
8180 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8183 * Enumerate the print processors ...
8185 * Just reply with "winprint", to keep NT happy
8186 * and I can use my nice printer checker.
8191 *r->out.info = NULL;
8193 switch (r->in.level) {
8195 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8199 return WERR_UNKNOWN_LEVEL;
8202 if (!W_ERROR_IS_OK(result)) {
8206 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8207 spoolss_EnumPrintProcessors,
8208 *r->out.info, r->in.level,
8210 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8211 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8213 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8216 /****************************************************************************
8217 fill_printprocdatatype1
8218 ****************************************************************************/
8220 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8221 struct spoolss_PrintProcDataTypesInfo1 *r,
8222 const char *name_array)
8224 r->name_array = talloc_strdup(mem_ctx, name_array);
8225 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8230 /****************************************************************************
8231 enumprintprocdatatypes level 1.
8232 ****************************************************************************/
8234 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8235 union spoolss_PrintProcDataTypesInfo **info_p,
8239 union spoolss_PrintProcDataTypesInfo *info;
8241 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8242 W_ERROR_HAVE_NO_MEMORY(info);
8246 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8247 if (!W_ERROR_IS_OK(result)) {
8252 if (!W_ERROR_IS_OK(result)) {
8263 /****************************************************************
8264 _spoolss_EnumPrintProcDataTypes
8265 ****************************************************************/
8267 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
8268 struct spoolss_EnumPrintProcDataTypes *r)
8272 /* that's an [in out] buffer */
8274 if (!r->in.buffer && (r->in.offered != 0)) {
8275 return WERR_INVALID_PARAM;
8278 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8282 *r->out.info = NULL;
8284 switch (r->in.level) {
8286 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8290 return WERR_UNKNOWN_LEVEL;
8293 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8294 spoolss_EnumPrintProcDataTypes,
8295 *r->out.info, r->in.level,
8297 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8298 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8300 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8303 /****************************************************************************
8305 ****************************************************************************/
8307 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8308 struct spoolss_MonitorInfo1 *r,
8309 const char *monitor_name)
8311 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8312 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8317 /****************************************************************************
8319 ****************************************************************************/
8321 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8322 struct spoolss_MonitorInfo2 *r,
8323 const char *monitor_name,
8324 const char *environment,
8325 const char *dll_name)
8327 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8328 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8329 r->environment = talloc_strdup(mem_ctx, environment);
8330 W_ERROR_HAVE_NO_MEMORY(r->environment);
8331 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8332 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8337 /****************************************************************************
8338 enumprintmonitors level 1.
8339 ****************************************************************************/
8341 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8342 union spoolss_MonitorInfo **info_p,
8345 union spoolss_MonitorInfo *info;
8346 WERROR result = WERR_OK;
8348 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8349 W_ERROR_HAVE_NO_MEMORY(info);
8353 result = fill_monitor_1(info, &info[0].info1,
8355 if (!W_ERROR_IS_OK(result)) {
8359 result = fill_monitor_1(info, &info[1].info1,
8361 if (!W_ERROR_IS_OK(result)) {
8366 if (!W_ERROR_IS_OK(result)) {
8377 /****************************************************************************
8378 enumprintmonitors level 2.
8379 ****************************************************************************/
8381 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8382 union spoolss_MonitorInfo **info_p,
8385 union spoolss_MonitorInfo *info;
8386 WERROR result = WERR_OK;
8388 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8389 W_ERROR_HAVE_NO_MEMORY(info);
8393 result = fill_monitor_2(info, &info[0].info2,
8395 "Windows NT X86", /* FIXME */
8397 if (!W_ERROR_IS_OK(result)) {
8401 result = fill_monitor_2(info, &info[1].info2,
8403 "Windows NT X86", /* FIXME */
8405 if (!W_ERROR_IS_OK(result)) {
8410 if (!W_ERROR_IS_OK(result)) {
8421 /****************************************************************
8422 _spoolss_EnumMonitors
8423 ****************************************************************/
8425 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
8426 struct spoolss_EnumMonitors *r)
8430 /* that's an [in out] buffer */
8432 if (!r->in.buffer && (r->in.offered != 0)) {
8433 return WERR_INVALID_PARAM;
8436 DEBUG(5,("_spoolss_EnumMonitors\n"));
8439 * Enumerate the print monitors ...
8441 * Just reply with "Local Port", to keep NT happy
8442 * and I can use my nice printer checker.
8447 *r->out.info = NULL;
8449 switch (r->in.level) {
8451 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8455 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8459 return WERR_UNKNOWN_LEVEL;
8462 if (!W_ERROR_IS_OK(result)) {
8466 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8467 spoolss_EnumMonitors,
8468 *r->out.info, r->in.level,
8470 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8471 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8473 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8476 /****************************************************************************
8477 ****************************************************************************/
8479 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8480 const print_queue_struct *queue,
8481 int count, int snum,
8482 struct spoolss_PrinterInfo2 *pinfo2,
8484 struct spoolss_JobInfo1 *r)
8489 for (i=0; i<count; i++) {
8490 if (queue[i].job == (int)jobid) {
8496 if (found == false) {
8497 /* NT treats not found as bad param... yet another bad choice */
8498 return WERR_INVALID_PARAM;
8501 return fill_job_info1(mem_ctx,
8509 /****************************************************************************
8510 ****************************************************************************/
8512 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8513 const print_queue_struct *queue,
8514 int count, int snum,
8515 struct spoolss_PrinterInfo2 *pinfo2,
8517 struct spoolss_JobInfo2 *r)
8521 struct spoolss_DeviceMode *devmode;
8524 for (i=0; i<count; i++) {
8525 if (queue[i].job == (int)jobid) {
8531 if (found == false) {
8532 /* NT treats not found as bad param... yet another bad
8534 return WERR_INVALID_PARAM;
8538 * if the print job does not have a DEVMODE associated with it,
8539 * just use the one for the printer. A NULL devicemode is not
8540 * a failure condition
8543 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8545 result = spoolss_create_default_devmode(mem_ctx,
8546 pinfo2->printername,
8548 if (!W_ERROR_IS_OK(result)) {
8549 DEBUG(3, ("Can't proceed w/o a devmode!"));
8554 return fill_job_info2(mem_ctx,
8563 /****************************************************************
8565 ****************************************************************/
8567 WERROR _spoolss_GetJob(struct pipes_struct *p,
8568 struct spoolss_GetJob *r)
8570 WERROR result = WERR_OK;
8571 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8574 print_queue_struct *queue = NULL;
8575 print_status_struct prt_status;
8577 /* that's an [in out] buffer */
8579 if (!r->in.buffer && (r->in.offered != 0)) {
8580 return WERR_INVALID_PARAM;
8583 DEBUG(5,("_spoolss_GetJob\n"));
8587 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8591 result = winreg_get_printer(p->mem_ctx, p->server_info, p->msg_ctx,
8592 NULL, lp_servicename(snum), &pinfo2);
8593 if (!W_ERROR_IS_OK(result)) {
8597 count = print_queue_status(snum, &queue, &prt_status);
8599 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8600 count, prt_status.status, prt_status.message));
8602 switch (r->in.level) {
8604 result = getjob_level_1(p->mem_ctx,
8605 queue, count, snum, pinfo2,
8606 r->in.job_id, &r->out.info->info1);
8609 result = getjob_level_2(p->mem_ctx,
8610 queue, count, snum, pinfo2,
8611 r->in.job_id, &r->out.info->info2);
8614 result = WERR_UNKNOWN_LEVEL;
8619 TALLOC_FREE(pinfo2);
8621 if (!W_ERROR_IS_OK(result)) {
8622 TALLOC_FREE(r->out.info);
8626 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
8628 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8630 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8633 /****************************************************************
8634 _spoolss_GetPrinterDataEx
8635 ****************************************************************/
8637 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
8638 struct spoolss_GetPrinterDataEx *r)
8641 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8642 const char *printer;
8644 WERROR result = WERR_OK;
8646 enum winreg_Type val_type;
8651 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8653 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8654 r->in.key_name, r->in.value_name));
8656 /* in case of problem, return some default values */
8659 *r->out.type = REG_NONE;
8662 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8663 OUR_HANDLE(r->in.handle)));
8664 result = WERR_BADFID;
8668 /* Is the handle to a printer or to the server? */
8670 if (Printer->printer_type == SPLHND_SERVER) {
8672 union spoolss_PrinterData data;
8674 result = getprinterdata_printer_server(p->mem_ctx,
8678 if (!W_ERROR_IS_OK(result)) {
8682 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
8683 *r->out.type, &data);
8684 if (!W_ERROR_IS_OK(result)) {
8688 *r->out.needed = blob.length;
8690 if (r->in.offered >= *r->out.needed) {
8691 memcpy(r->out.data, blob.data, blob.length);
8694 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8697 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8700 printer = lp_const_servicename(snum);
8702 /* check to see if the keyname is valid */
8703 if (!strlen(r->in.key_name)) {
8704 return WERR_INVALID_PARAM;
8707 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
8708 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
8709 strequal(r->in.value_name, "ChangeId")) {
8710 *r->out.type = REG_DWORD;
8712 if (r->in.offered >= *r->out.needed) {
8713 uint32_t changeid = 0;
8715 result = winreg_printer_get_changeid(p->mem_ctx,
8720 if (!W_ERROR_IS_OK(result)) {
8724 SIVAL(r->out.data, 0, changeid);
8730 result = winreg_get_printer_dataex(p->mem_ctx,
8739 if (!W_ERROR_IS_OK(result)) {
8743 *r->out.needed = val_size;
8744 *r->out.type = val_type;
8746 if (r->in.offered >= *r->out.needed) {
8747 memcpy(r->out.data, val_data, val_size);
8751 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
8752 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
8754 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8757 /****************************************************************
8758 _spoolss_SetPrinterDataEx
8759 ****************************************************************/
8761 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
8762 struct spoolss_SetPrinterDataEx *r)
8764 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8766 WERROR result = WERR_OK;
8767 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8770 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
8772 /* From MSDN documentation of SetPrinterDataEx: pass request to
8773 SetPrinterData if key is "PrinterDriverData" */
8776 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8777 OUR_HANDLE(r->in.handle)));
8781 if (Printer->printer_type == SPLHND_SERVER) {
8782 DEBUG(10,("_spoolss_SetPrinterDataEx: "
8783 "Not implemented for server handles yet\n"));
8784 return WERR_INVALID_PARAM;
8787 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8792 * Access check : NT returns "access denied" if you make a
8793 * SetPrinterData call without the necessary privildge.
8794 * we were originally returning OK if nothing changed
8795 * which made Win2k issue **a lot** of SetPrinterData
8796 * when connecting to a printer --jerry
8799 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8800 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
8801 "change denied by handle access permissions\n"));
8802 return WERR_ACCESS_DENIED;
8805 result = winreg_get_printer(Printer, p->server_info, p->msg_ctx,
8806 Printer->servername,
8807 lp_servicename(snum),
8809 if (!W_ERROR_IS_OK(result)) {
8813 /* check for OID in valuename */
8815 oid_string = strchr(r->in.value_name, ',');
8821 /* save the registry data */
8823 result = winreg_set_printer_dataex(p->mem_ctx,
8833 if (W_ERROR_IS_OK(result)) {
8834 /* save the OID if one was specified */
8836 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
8837 r->in.key_name, SPOOL_OID_KEY);
8839 result = WERR_NOMEM;
8844 * I'm not checking the status here on purpose. Don't know
8845 * if this is right, but I'm returning the status from the
8846 * previous set_printer_dataex() call. I have no idea if
8847 * this is right. --jerry
8849 winreg_set_printer_dataex(p->mem_ctx,
8856 (uint8_t *) oid_string,
8857 strlen(oid_string) + 1);
8860 result = winreg_printer_update_changeid(p->mem_ctx,
8863 lp_const_servicename(snum));
8868 talloc_free(pinfo2);
8872 /****************************************************************
8873 _spoolss_DeletePrinterDataEx
8874 ****************************************************************/
8876 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
8877 struct spoolss_DeletePrinterDataEx *r)
8879 const char *printer;
8881 WERROR status = WERR_OK;
8882 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8884 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
8887 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
8888 "Invalid handle (%s:%u:%u).\n",
8889 OUR_HANDLE(r->in.handle)));
8893 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8894 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
8895 "printer properties change denied by handle\n"));
8896 return WERR_ACCESS_DENIED;
8899 if (!r->in.value_name || !r->in.key_name) {
8903 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8906 printer = lp_const_servicename(snum);
8908 status = winreg_delete_printer_dataex(p->mem_ctx,
8914 if (W_ERROR_IS_OK(status)) {
8915 status = winreg_printer_update_changeid(p->mem_ctx,
8924 /****************************************************************
8925 _spoolss_EnumPrinterKey
8926 ****************************************************************/
8928 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
8929 struct spoolss_EnumPrinterKey *r)
8932 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8934 WERROR result = WERR_BADFILE;
8935 const char **array = NULL;
8938 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
8941 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
8942 OUR_HANDLE(r->in.handle)));
8946 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8950 result = winreg_enum_printer_key(p->mem_ctx,
8953 lp_const_servicename(snum),
8957 if (!W_ERROR_IS_OK(result)) {
8961 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
8962 result = WERR_NOMEM;
8966 *r->out._ndr_size = r->in.offered / 2;
8967 *r->out.needed = blob.length;
8969 if (r->in.offered < *r->out.needed) {
8970 result = WERR_MORE_DATA;
8973 r->out.key_buffer->string_array = array;
8977 if (!W_ERROR_IS_OK(result)) {
8979 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8987 /****************************************************************
8988 _spoolss_DeletePrinterKey
8989 ****************************************************************/
8991 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
8992 struct spoolss_DeletePrinterKey *r)
8994 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8997 const char *printer;
8999 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9002 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9003 OUR_HANDLE(r->in.handle)));
9007 /* if keyname == NULL, return error */
9008 if ( !r->in.key_name )
9009 return WERR_INVALID_PARAM;
9011 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9015 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9016 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9017 "printer properties change denied by handle\n"));
9018 return WERR_ACCESS_DENIED;
9021 printer = lp_const_servicename(snum);
9023 /* delete the key and all subkeys */
9024 status = winreg_delete_printer_key(p->mem_ctx,
9029 if (W_ERROR_IS_OK(status)) {
9030 status = winreg_printer_update_changeid(p->mem_ctx,
9039 /****************************************************************
9040 _spoolss_EnumPrinterDataEx
9041 ****************************************************************/
9043 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9044 struct spoolss_EnumPrinterDataEx *r)
9047 struct spoolss_PrinterEnumValues *info = NULL;
9048 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9052 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9056 *r->out.info = NULL;
9059 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9060 OUR_HANDLE(r->in.handle)));
9065 * first check for a keyname of NULL or "". Win2k seems to send
9066 * this a lot and we should send back WERR_INVALID_PARAM
9067 * no need to spend time looking up the printer in this case.
9071 if (!strlen(r->in.key_name)) {
9072 result = WERR_INVALID_PARAM;
9076 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9080 /* now look for a match on the key name */
9081 result = winreg_enum_printer_dataex(p->mem_ctx,
9084 lp_const_servicename(snum),
9088 if (!W_ERROR_IS_OK(result)) {
9092 #if 0 /* FIXME - gd */
9093 /* housekeeping information in the reply */
9095 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9096 * the hand marshalled container size is a multiple
9097 * of 4 bytes for RPC alignment.
9101 needed += 4-(needed % 4);
9104 *r->out.count = count;
9105 *r->out.info = info;
9108 if (!W_ERROR_IS_OK(result)) {
9112 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9113 spoolss_EnumPrinterDataEx,
9116 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9117 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9119 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9122 /****************************************************************************
9123 ****************************************************************************/
9125 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9126 const char *servername,
9127 const char *environment,
9128 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9133 werr = compose_spoolss_server_path(mem_ctx,
9136 SPOOLSS_PRTPROCS_PATH,
9138 if (!W_ERROR_IS_OK(werr)) {
9142 DEBUG(4,("print processor directory: [%s]\n", path));
9144 r->directory_name = path;
9149 /****************************************************************
9150 _spoolss_GetPrintProcessorDirectory
9151 ****************************************************************/
9153 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
9154 struct spoolss_GetPrintProcessorDirectory *r)
9158 /* that's an [in out] buffer */
9160 if (!r->in.buffer && (r->in.offered != 0)) {
9161 return WERR_INVALID_PARAM;
9164 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9169 /* r->in.level is ignored */
9171 /* We always should reply with a local print processor directory so that
9172 * users are not forced to have a [prnproc$] share on the Samba spoolss
9173 * server - Guenther */
9175 result = getprintprocessordirectory_level_1(p->mem_ctx,
9176 NULL, /* r->in.server */
9178 &r->out.info->info1);
9179 if (!W_ERROR_IS_OK(result)) {
9180 TALLOC_FREE(r->out.info);
9184 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9185 r->out.info, r->in.level);
9186 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9188 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9191 /*******************************************************************
9192 ********************************************************************/
9194 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9195 const char *dllname)
9197 enum ndr_err_code ndr_err;
9198 struct spoolss_MonitorUi ui;
9200 ui.dll_name = dllname;
9202 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9203 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9204 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9205 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9207 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9210 /*******************************************************************
9211 Streams the monitor UI DLL name in UNICODE
9212 *******************************************************************/
9214 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9215 NT_USER_TOKEN *token, DATA_BLOB *in,
9216 DATA_BLOB *out, uint32_t *needed)
9218 const char *dllname = "tcpmonui.dll";
9220 *needed = (strlen(dllname)+1) * 2;
9222 if (out->length < *needed) {
9223 return WERR_INSUFFICIENT_BUFFER;
9226 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9233 /*******************************************************************
9234 ********************************************************************/
9236 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9237 struct spoolss_PortData1 *port1,
9238 const DATA_BLOB *buf)
9240 enum ndr_err_code ndr_err;
9241 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9242 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9243 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9244 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9246 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9249 /*******************************************************************
9250 ********************************************************************/
9252 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9253 struct spoolss_PortData2 *port2,
9254 const DATA_BLOB *buf)
9256 enum ndr_err_code ndr_err;
9257 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9258 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9259 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9260 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9262 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9265 /*******************************************************************
9266 Create a new TCP/IP port
9267 *******************************************************************/
9269 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9270 NT_USER_TOKEN *token, DATA_BLOB *in,
9271 DATA_BLOB *out, uint32_t *needed)
9273 struct spoolss_PortData1 port1;
9274 struct spoolss_PortData2 port2;
9275 char *device_uri = NULL;
9278 const char *portname;
9279 const char *hostaddress;
9281 uint32_t port_number;
9284 /* peek for spoolss_PortData version */
9286 if (!in || (in->length < (128 + 4))) {
9287 return WERR_GENERAL_FAILURE;
9290 version = IVAL(in->data, 128);
9296 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9300 portname = port1.portname;
9301 hostaddress = port1.hostaddress;
9302 queue = port1.queue;
9303 protocol = port1.protocol;
9304 port_number = port1.port_number;
9310 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9314 portname = port2.portname;
9315 hostaddress = port2.hostaddress;
9316 queue = port2.queue;
9317 protocol = port2.protocol;
9318 port_number = port2.port_number;
9322 DEBUG(1,("xcvtcp_addport: "
9323 "unknown version of port_data: %d\n", version));
9324 return WERR_UNKNOWN_PORT;
9327 /* create the device URI and call the add_port_hook() */
9330 case PROTOCOL_RAWTCP_TYPE:
9331 device_uri = talloc_asprintf(mem_ctx,
9332 "socket://%s:%d/", hostaddress,
9336 case PROTOCOL_LPR_TYPE:
9337 device_uri = talloc_asprintf(mem_ctx,
9338 "lpr://%s/%s", hostaddress, queue );
9342 return WERR_UNKNOWN_PORT;
9349 return add_port_hook(mem_ctx, token, portname, device_uri);
9352 /*******************************************************************
9353 *******************************************************************/
9355 struct xcv_api_table xcvtcp_cmds[] = {
9356 { "MonitorUI", xcvtcp_monitorui },
9357 { "AddPort", xcvtcp_addport},
9361 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9362 NT_USER_TOKEN *token, const char *command,
9369 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9371 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9372 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9373 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9376 return WERR_BADFUNC;
9379 /*******************************************************************
9380 *******************************************************************/
9381 #if 0 /* don't support management using the "Local Port" monitor */
9383 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9384 NT_USER_TOKEN *token, DATA_BLOB *in,
9385 DATA_BLOB *out, uint32_t *needed)
9387 const char *dllname = "localui.dll";
9389 *needed = (strlen(dllname)+1) * 2;
9391 if (out->length < *needed) {
9392 return WERR_INSUFFICIENT_BUFFER;
9395 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9402 /*******************************************************************
9403 *******************************************************************/
9405 struct xcv_api_table xcvlocal_cmds[] = {
9406 { "MonitorUI", xcvlocal_monitorui },
9410 struct xcv_api_table xcvlocal_cmds[] = {
9417 /*******************************************************************
9418 *******************************************************************/
9420 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9421 NT_USER_TOKEN *token, const char *command,
9422 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9427 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9429 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9430 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9431 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9433 return WERR_BADFUNC;
9436 /****************************************************************
9438 ****************************************************************/
9440 WERROR _spoolss_XcvData(struct pipes_struct *p,
9441 struct spoolss_XcvData *r)
9443 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9444 DATA_BLOB out_data = data_blob_null;
9448 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9449 OUR_HANDLE(r->in.handle)));
9453 /* Has to be a handle to the TCP/IP port monitor */
9455 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9456 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9460 /* requires administrative access to the server */
9462 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9463 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9464 return WERR_ACCESS_DENIED;
9467 /* Allocate the outgoing buffer */
9469 if (r->in.out_data_size) {
9470 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9471 if (out_data.data == NULL) {
9476 switch ( Printer->printer_type ) {
9477 case SPLHND_PORTMON_TCP:
9478 werror = process_xcvtcp_command(p->mem_ctx,
9479 p->server_info->ptok,
9480 r->in.function_name,
9481 &r->in.in_data, &out_data,
9484 case SPLHND_PORTMON_LOCAL:
9485 werror = process_xcvlocal_command(p->mem_ctx,
9486 p->server_info->ptok,
9487 r->in.function_name,
9488 &r->in.in_data, &out_data,
9492 werror = WERR_INVALID_PRINT_MONITOR;
9495 if (!W_ERROR_IS_OK(werror)) {
9499 *r->out.status_code = 0;
9501 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9502 memcpy(r->out.out_data, out_data.data,
9503 MIN(r->in.out_data_size, out_data.length));
9509 /****************************************************************
9510 _spoolss_AddPrintProcessor
9511 ****************************************************************/
9513 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
9514 struct spoolss_AddPrintProcessor *r)
9516 /* for now, just indicate success and ignore the add. We'll
9517 automatically set the winprint processor for printer
9518 entries later. Used to debug the LexMark Optra S 1855 PCL
9524 /****************************************************************
9526 ****************************************************************/
9528 WERROR _spoolss_AddPort(struct pipes_struct *p,
9529 struct spoolss_AddPort *r)
9531 /* do what w2k3 does */
9533 return WERR_NOT_SUPPORTED;
9536 /****************************************************************
9537 _spoolss_GetPrinterDriver
9538 ****************************************************************/
9540 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
9541 struct spoolss_GetPrinterDriver *r)
9543 p->rng_fault_state = true;
9544 return WERR_NOT_SUPPORTED;
9547 /****************************************************************
9548 _spoolss_ReadPrinter
9549 ****************************************************************/
9551 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
9552 struct spoolss_ReadPrinter *r)
9554 p->rng_fault_state = true;
9555 return WERR_NOT_SUPPORTED;
9558 /****************************************************************
9559 _spoolss_WaitForPrinterChange
9560 ****************************************************************/
9562 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
9563 struct spoolss_WaitForPrinterChange *r)
9565 p->rng_fault_state = true;
9566 return WERR_NOT_SUPPORTED;
9569 /****************************************************************
9570 _spoolss_ConfigurePort
9571 ****************************************************************/
9573 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
9574 struct spoolss_ConfigurePort *r)
9576 p->rng_fault_state = true;
9577 return WERR_NOT_SUPPORTED;
9580 /****************************************************************
9582 ****************************************************************/
9584 WERROR _spoolss_DeletePort(struct pipes_struct *p,
9585 struct spoolss_DeletePort *r)
9587 p->rng_fault_state = true;
9588 return WERR_NOT_SUPPORTED;
9591 /****************************************************************
9592 _spoolss_CreatePrinterIC
9593 ****************************************************************/
9595 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
9596 struct spoolss_CreatePrinterIC *r)
9598 p->rng_fault_state = true;
9599 return WERR_NOT_SUPPORTED;
9602 /****************************************************************
9603 _spoolss_PlayGDIScriptOnPrinterIC
9604 ****************************************************************/
9606 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
9607 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9609 p->rng_fault_state = true;
9610 return WERR_NOT_SUPPORTED;
9613 /****************************************************************
9614 _spoolss_DeletePrinterIC
9615 ****************************************************************/
9617 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
9618 struct spoolss_DeletePrinterIC *r)
9620 p->rng_fault_state = true;
9621 return WERR_NOT_SUPPORTED;
9624 /****************************************************************
9625 _spoolss_AddPrinterConnection
9626 ****************************************************************/
9628 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
9629 struct spoolss_AddPrinterConnection *r)
9631 p->rng_fault_state = true;
9632 return WERR_NOT_SUPPORTED;
9635 /****************************************************************
9636 _spoolss_DeletePrinterConnection
9637 ****************************************************************/
9639 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
9640 struct spoolss_DeletePrinterConnection *r)
9642 p->rng_fault_state = true;
9643 return WERR_NOT_SUPPORTED;
9646 /****************************************************************
9647 _spoolss_PrinterMessageBox
9648 ****************************************************************/
9650 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
9651 struct spoolss_PrinterMessageBox *r)
9653 p->rng_fault_state = true;
9654 return WERR_NOT_SUPPORTED;
9657 /****************************************************************
9659 ****************************************************************/
9661 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
9662 struct spoolss_AddMonitor *r)
9664 p->rng_fault_state = true;
9665 return WERR_NOT_SUPPORTED;
9668 /****************************************************************
9669 _spoolss_DeleteMonitor
9670 ****************************************************************/
9672 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
9673 struct spoolss_DeleteMonitor *r)
9675 p->rng_fault_state = true;
9676 return WERR_NOT_SUPPORTED;
9679 /****************************************************************
9680 _spoolss_DeletePrintProcessor
9681 ****************************************************************/
9683 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
9684 struct spoolss_DeletePrintProcessor *r)
9686 p->rng_fault_state = true;
9687 return WERR_NOT_SUPPORTED;
9690 /****************************************************************
9691 _spoolss_AddPrintProvidor
9692 ****************************************************************/
9694 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
9695 struct spoolss_AddPrintProvidor *r)
9697 p->rng_fault_state = true;
9698 return WERR_NOT_SUPPORTED;
9701 /****************************************************************
9702 _spoolss_DeletePrintProvidor
9703 ****************************************************************/
9705 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
9706 struct spoolss_DeletePrintProvidor *r)
9708 p->rng_fault_state = true;
9709 return WERR_NOT_SUPPORTED;
9712 /****************************************************************
9713 _spoolss_FindFirstPrinterChangeNotification
9714 ****************************************************************/
9716 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
9717 struct spoolss_FindFirstPrinterChangeNotification *r)
9719 p->rng_fault_state = true;
9720 return WERR_NOT_SUPPORTED;
9723 /****************************************************************
9724 _spoolss_FindNextPrinterChangeNotification
9725 ****************************************************************/
9727 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
9728 struct spoolss_FindNextPrinterChangeNotification *r)
9730 p->rng_fault_state = true;
9731 return WERR_NOT_SUPPORTED;
9734 /****************************************************************
9735 _spoolss_RouterFindFirstPrinterChangeNotificationOld
9736 ****************************************************************/
9738 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
9739 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
9741 p->rng_fault_state = true;
9742 return WERR_NOT_SUPPORTED;
9745 /****************************************************************
9746 _spoolss_ReplyOpenPrinter
9747 ****************************************************************/
9749 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
9750 struct spoolss_ReplyOpenPrinter *r)
9752 p->rng_fault_state = true;
9753 return WERR_NOT_SUPPORTED;
9756 /****************************************************************
9757 _spoolss_RouterReplyPrinter
9758 ****************************************************************/
9760 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
9761 struct spoolss_RouterReplyPrinter *r)
9763 p->rng_fault_state = true;
9764 return WERR_NOT_SUPPORTED;
9767 /****************************************************************
9768 _spoolss_ReplyClosePrinter
9769 ****************************************************************/
9771 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
9772 struct spoolss_ReplyClosePrinter *r)
9774 p->rng_fault_state = true;
9775 return WERR_NOT_SUPPORTED;
9778 /****************************************************************
9780 ****************************************************************/
9782 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
9783 struct spoolss_AddPortEx *r)
9785 p->rng_fault_state = true;
9786 return WERR_NOT_SUPPORTED;
9789 /****************************************************************
9790 _spoolss_RouterFindFirstPrinterChangeNotification
9791 ****************************************************************/
9793 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
9794 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
9796 p->rng_fault_state = true;
9797 return WERR_NOT_SUPPORTED;
9800 /****************************************************************
9801 _spoolss_SpoolerInit
9802 ****************************************************************/
9804 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
9805 struct spoolss_SpoolerInit *r)
9807 p->rng_fault_state = true;
9808 return WERR_NOT_SUPPORTED;
9811 /****************************************************************
9812 _spoolss_ResetPrinterEx
9813 ****************************************************************/
9815 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
9816 struct spoolss_ResetPrinterEx *r)
9818 p->rng_fault_state = true;
9819 return WERR_NOT_SUPPORTED;
9822 /****************************************************************
9823 _spoolss_RouterReplyPrinterEx
9824 ****************************************************************/
9826 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
9827 struct spoolss_RouterReplyPrinterEx *r)
9829 p->rng_fault_state = true;
9830 return WERR_NOT_SUPPORTED;
9833 /****************************************************************
9835 ****************************************************************/
9837 WERROR _spoolss_44(struct pipes_struct *p,
9838 struct spoolss_44 *r)
9840 p->rng_fault_state = true;
9841 return WERR_NOT_SUPPORTED;
9844 /****************************************************************
9846 ****************************************************************/
9848 WERROR _spoolss_47(struct pipes_struct *p,
9849 struct spoolss_47 *r)
9851 p->rng_fault_state = true;
9852 return WERR_NOT_SUPPORTED;
9855 /****************************************************************
9857 ****************************************************************/
9859 WERROR _spoolss_4a(struct pipes_struct *p,
9860 struct spoolss_4a *r)
9862 p->rng_fault_state = true;
9863 return WERR_NOT_SUPPORTED;
9866 /****************************************************************
9868 ****************************************************************/
9870 WERROR _spoolss_4b(struct pipes_struct *p,
9871 struct spoolss_4b *r)
9873 p->rng_fault_state = true;
9874 return WERR_NOT_SUPPORTED;
9877 /****************************************************************
9879 ****************************************************************/
9881 WERROR _spoolss_4c(struct pipes_struct *p,
9882 struct spoolss_4c *r)
9884 p->rng_fault_state = true;
9885 return WERR_NOT_SUPPORTED;
9888 /****************************************************************
9890 ****************************************************************/
9892 WERROR _spoolss_53(struct pipes_struct *p,
9893 struct spoolss_53 *r)
9895 p->rng_fault_state = true;
9896 return WERR_NOT_SUPPORTED;
9899 /****************************************************************
9901 ****************************************************************/
9903 WERROR _spoolss_55(struct pipes_struct *p,
9904 struct spoolss_55 *r)
9906 p->rng_fault_state = true;
9907 return WERR_NOT_SUPPORTED;
9910 /****************************************************************
9912 ****************************************************************/
9914 WERROR _spoolss_56(struct pipes_struct *p,
9915 struct spoolss_56 *r)
9917 p->rng_fault_state = true;
9918 return WERR_NOT_SUPPORTED;
9921 /****************************************************************
9923 ****************************************************************/
9925 WERROR _spoolss_57(struct pipes_struct *p,
9926 struct spoolss_57 *r)
9928 p->rng_fault_state = true;
9929 return WERR_NOT_SUPPORTED;
9932 /****************************************************************
9934 ****************************************************************/
9936 WERROR _spoolss_5a(struct pipes_struct *p,
9937 struct spoolss_5a *r)
9939 p->rng_fault_state = true;
9940 return WERR_NOT_SUPPORTED;
9943 /****************************************************************
9945 ****************************************************************/
9947 WERROR _spoolss_5b(struct pipes_struct *p,
9948 struct spoolss_5b *r)
9950 p->rng_fault_state = true;
9951 return WERR_NOT_SUPPORTED;
9954 /****************************************************************
9956 ****************************************************************/
9958 WERROR _spoolss_5c(struct pipes_struct *p,
9959 struct spoolss_5c *r)
9961 p->rng_fault_state = true;
9962 return WERR_NOT_SUPPORTED;
9965 /****************************************************************
9967 ****************************************************************/
9969 WERROR _spoolss_5d(struct pipes_struct *p,
9970 struct spoolss_5d *r)
9972 p->rng_fault_state = true;
9973 return WERR_NOT_SUPPORTED;
9976 /****************************************************************
9978 ****************************************************************/
9980 WERROR _spoolss_5e(struct pipes_struct *p,
9981 struct spoolss_5e *r)
9983 p->rng_fault_state = true;
9984 return WERR_NOT_SUPPORTED;
9987 /****************************************************************
9989 ****************************************************************/
9991 WERROR _spoolss_5f(struct pipes_struct *p,
9992 struct spoolss_5f *r)
9994 p->rng_fault_state = true;
9995 return WERR_NOT_SUPPORTED;
9998 /****************************************************************
10000 ****************************************************************/
10002 WERROR _spoolss_60(struct pipes_struct *p,
10003 struct spoolss_60 *r)
10005 p->rng_fault_state = true;
10006 return WERR_NOT_SUPPORTED;
10009 /****************************************************************
10011 ****************************************************************/
10013 WERROR _spoolss_61(struct pipes_struct *p,
10014 struct spoolss_61 *r)
10016 p->rng_fault_state = true;
10017 return WERR_NOT_SUPPORTED;
10020 /****************************************************************
10022 ****************************************************************/
10024 WERROR _spoolss_62(struct pipes_struct *p,
10025 struct spoolss_62 *r)
10027 p->rng_fault_state = true;
10028 return WERR_NOT_SUPPORTED;
10031 /****************************************************************
10033 ****************************************************************/
10035 WERROR _spoolss_63(struct pipes_struct *p,
10036 struct spoolss_63 *r)
10038 p->rng_fault_state = true;
10039 return WERR_NOT_SUPPORTED;
10042 /****************************************************************
10044 ****************************************************************/
10046 WERROR _spoolss_64(struct pipes_struct *p,
10047 struct spoolss_64 *r)
10049 p->rng_fault_state = true;
10050 return WERR_NOT_SUPPORTED;
10053 /****************************************************************
10055 ****************************************************************/
10057 WERROR _spoolss_65(struct pipes_struct *p,
10058 struct spoolss_65 *r)
10060 p->rng_fault_state = true;
10061 return WERR_NOT_SUPPORTED;
10064 /****************************************************************
10065 _spoolss_GetCorePrinterDrivers
10066 ****************************************************************/
10068 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10069 struct spoolss_GetCorePrinterDrivers *r)
10071 p->rng_fault_state = true;
10072 return WERR_NOT_SUPPORTED;
10075 /****************************************************************
10077 ****************************************************************/
10079 WERROR _spoolss_67(struct pipes_struct *p,
10080 struct spoolss_67 *r)
10082 p->rng_fault_state = true;
10083 return WERR_NOT_SUPPORTED;
10086 /****************************************************************
10087 _spoolss_GetPrinterDriverPackagePath
10088 ****************************************************************/
10090 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10091 struct spoolss_GetPrinterDriverPackagePath *r)
10093 p->rng_fault_state = true;
10094 return WERR_NOT_SUPPORTED;
10097 /****************************************************************
10099 ****************************************************************/
10101 WERROR _spoolss_69(struct pipes_struct *p,
10102 struct spoolss_69 *r)
10104 p->rng_fault_state = true;
10105 return WERR_NOT_SUPPORTED;
10108 /****************************************************************
10110 ****************************************************************/
10112 WERROR _spoolss_6a(struct pipes_struct *p,
10113 struct spoolss_6a *r)
10115 p->rng_fault_state = true;
10116 return WERR_NOT_SUPPORTED;
10119 /****************************************************************
10121 ****************************************************************/
10123 WERROR _spoolss_6b(struct pipes_struct *p,
10124 struct spoolss_6b *r)
10126 p->rng_fault_state = true;
10127 return WERR_NOT_SUPPORTED;
10130 /****************************************************************
10132 ****************************************************************/
10134 WERROR _spoolss_6c(struct pipes_struct *p,
10135 struct spoolss_6c *r)
10137 p->rng_fault_state = true;
10138 return WERR_NOT_SUPPORTED;
10141 /****************************************************************
10143 ****************************************************************/
10145 WERROR _spoolss_6d(struct pipes_struct *p,
10146 struct spoolss_6d *r)
10148 p->rng_fault_state = true;
10149 return WERR_NOT_SUPPORTED;