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(msg_ctx, 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(server_messaging_context(), snum,
1410 printer = printer->next;
1416 /****************************************************************
1417 _spoolss_OpenPrinter
1418 ****************************************************************/
1420 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1421 struct spoolss_OpenPrinter *r)
1423 struct spoolss_OpenPrinterEx e;
1426 ZERO_STRUCT(e.in.userlevel);
1428 e.in.printername = r->in.printername;
1429 e.in.datatype = r->in.datatype;
1430 e.in.devmode_ctr = r->in.devmode_ctr;
1431 e.in.access_mask = r->in.access_mask;
1434 e.out.handle = r->out.handle;
1436 werr = _spoolss_OpenPrinterEx(p, &e);
1438 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1439 /* OpenPrinterEx returns this for a bad
1440 * printer name. We must return WERR_INVALID_PRINTER_NAME
1443 werr = WERR_INVALID_PRINTER_NAME;
1449 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1450 struct spoolss_DeviceMode *orig,
1451 struct spoolss_DeviceMode **dest)
1453 struct spoolss_DeviceMode *dm;
1455 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1460 /* copy all values, then duplicate strings and structs */
1463 dm->devicename = talloc_strdup(dm, orig->devicename);
1464 if (!dm->devicename) {
1467 dm->formname = talloc_strdup(dm, orig->formname);
1468 if (!dm->formname) {
1471 if (orig->driverextra_data.data) {
1472 dm->driverextra_data.data =
1473 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1474 orig->driverextra_data.length);
1475 if (!dm->driverextra_data.data) {
1484 /****************************************************************
1485 _spoolss_OpenPrinterEx
1486 ****************************************************************/
1488 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1489 struct spoolss_OpenPrinterEx *r)
1492 Printer_entry *Printer=NULL;
1494 if (!r->in.printername) {
1495 return WERR_INVALID_PARAM;
1498 /* some sanity check because you can open a printer or a print server */
1499 /* aka: \\server\printer or \\server */
1501 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1503 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1504 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1505 " for printer %s\n", r->in.printername));
1506 ZERO_STRUCTP(r->out.handle);
1507 return WERR_INVALID_PARAM;
1510 Printer = find_printer_index_by_hnd(p, r->out.handle);
1512 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1513 "handle we created for printer %s\n", r->in.printername));
1514 close_printer_handle(p, r->out.handle);
1515 ZERO_STRUCTP(r->out.handle);
1516 return WERR_INVALID_PARAM;
1520 * First case: the user is opening the print server:
1522 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1523 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1525 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1526 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1527 * or if the user is listed in the smb.conf printer admin parameter.
1529 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1530 * client view printer folder, but does not show the MSAPW.
1532 * Note: this test needs code to check access rights here too. Jeremy
1533 * could you look at this?
1535 * Second case: the user is opening a printer:
1536 * NT doesn't let us connect to a printer if the connecting user
1537 * doesn't have print permission.
1539 * Third case: user is opening a Port Monitor
1540 * access checks same as opening a handle to the print server.
1543 switch (Printer->printer_type )
1546 case SPLHND_PORTMON_TCP:
1547 case SPLHND_PORTMON_LOCAL:
1548 /* Printserver handles use global struct... */
1552 /* Map standard access rights to object specific access rights */
1554 se_map_standard(&r->in.access_mask,
1555 &printserver_std_mapping);
1557 /* Deny any object specific bits that don't apply to print
1558 servers (i.e printer and job specific bits) */
1560 r->in.access_mask &= SEC_MASK_SPECIFIC;
1562 if (r->in.access_mask &
1563 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1564 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1565 close_printer_handle(p, r->out.handle);
1566 ZERO_STRUCTP(r->out.handle);
1567 return WERR_ACCESS_DENIED;
1570 /* Allow admin access */
1572 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1574 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1576 if (!lp_ms_add_printer_wizard()) {
1577 close_printer_handle(p, r->out.handle);
1578 ZERO_STRUCTP(r->out.handle);
1579 return WERR_ACCESS_DENIED;
1582 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1583 and not a printer admin, then fail */
1585 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1586 !user_has_privileges(p->server_info->ptok,
1588 !token_contains_name_in_list(
1589 uidtoname(p->server_info->utok.uid),
1590 p->server_info->info3->base.domain.string,
1592 p->server_info->ptok,
1593 lp_printer_admin(snum))) {
1594 close_printer_handle(p, r->out.handle);
1595 ZERO_STRUCTP(r->out.handle);
1596 return WERR_ACCESS_DENIED;
1599 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1603 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1606 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1607 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1609 /* We fall through to return WERR_OK */
1612 case SPLHND_PRINTER:
1613 /* NT doesn't let us connect to a printer if the connecting user
1614 doesn't have print permission. */
1616 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1617 close_printer_handle(p, r->out.handle);
1618 ZERO_STRUCTP(r->out.handle);
1622 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1623 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1626 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1628 /* map an empty access mask to the minimum access mask */
1629 if (r->in.access_mask == 0x0)
1630 r->in.access_mask = PRINTER_ACCESS_USE;
1633 * If we are not serving the printer driver for this printer,
1634 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1635 * will keep NT clients happy --jerry
1638 if (lp_use_client_driver(snum)
1639 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1641 r->in.access_mask = PRINTER_ACCESS_USE;
1644 /* check smb.conf parameters and the the sec_desc */
1646 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1647 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1648 ZERO_STRUCTP(r->out.handle);
1649 return WERR_ACCESS_DENIED;
1652 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1653 p->server_info->ptok, snum) ||
1654 !print_access_check(p->server_info, p->msg_ctx, snum,
1655 r->in.access_mask)) {
1656 DEBUG(3, ("access DENIED for printer open\n"));
1657 close_printer_handle(p, r->out.handle);
1658 ZERO_STRUCTP(r->out.handle);
1659 return WERR_ACCESS_DENIED;
1662 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1663 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1664 close_printer_handle(p, r->out.handle);
1665 ZERO_STRUCTP(r->out.handle);
1666 return WERR_ACCESS_DENIED;
1669 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1670 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1672 r->in.access_mask = PRINTER_ACCESS_USE;
1674 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1675 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1677 winreg_create_printer(p->mem_ctx,
1680 Printer->servername,
1681 lp_const_servicename(snum));
1686 /* sanity check to prevent programmer error */
1687 ZERO_STRUCTP(r->out.handle);
1691 Printer->access_granted = r->in.access_mask;
1694 * If the client sent a devmode in the OpenPrinter() call, then
1695 * save it here in case we get a job submission on this handle
1698 if ((Printer->printer_type != SPLHND_SERVER) &&
1699 r->in.devmode_ctr.devmode) {
1700 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1704 #if 0 /* JERRY -- I'm doubtful this is really effective */
1705 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1706 optimization in Windows 2000 clients --jerry */
1708 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1709 && (RA_WIN2K == get_remote_arch()) )
1711 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1712 sys_usleep( 500000 );
1719 /****************************************************************
1720 _spoolss_ClosePrinter
1721 ****************************************************************/
1723 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1724 struct spoolss_ClosePrinter *r)
1726 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1728 if (Printer && Printer->document_started) {
1729 struct spoolss_EndDocPrinter e;
1731 e.in.handle = r->in.handle;
1733 _spoolss_EndDocPrinter(p, &e);
1736 if (!close_printer_handle(p, r->in.handle))
1739 /* clear the returned printer handle. Observed behavior
1740 from Win2k server. Don't think this really matters.
1741 Previous code just copied the value of the closed
1744 ZERO_STRUCTP(r->out.handle);
1749 /****************************************************************
1750 _spoolss_DeletePrinter
1751 ****************************************************************/
1753 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1754 struct spoolss_DeletePrinter *r)
1756 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1760 if (Printer && Printer->document_started) {
1761 struct spoolss_EndDocPrinter e;
1763 e.in.handle = r->in.handle;
1765 _spoolss_EndDocPrinter(p, &e);
1768 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
1769 winreg_delete_printer_key(p->mem_ctx,
1772 lp_const_servicename(snum),
1776 result = delete_printer_handle(p, r->in.handle);
1781 /*******************************************************************
1782 * static function to lookup the version id corresponding to an
1783 * long architecture string
1784 ******************************************************************/
1786 static const struct print_architecture_table_node archi_table[]= {
1788 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1789 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1790 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1791 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
1792 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
1793 {"Windows IA64", SPL_ARCH_IA64, 3 },
1794 {"Windows x64", SPL_ARCH_X64, 3 },
1798 static int get_version_id(const char *arch)
1802 for (i=0; archi_table[i].long_archi != NULL; i++)
1804 if (strcmp(arch, archi_table[i].long_archi) == 0)
1805 return (archi_table[i].version);
1811 /****************************************************************
1812 _spoolss_DeletePrinterDriver
1813 ****************************************************************/
1815 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
1816 struct spoolss_DeletePrinterDriver *r)
1819 struct spoolss_DriverInfo8 *info = NULL;
1820 struct spoolss_DriverInfo8 *info_win2k = NULL;
1823 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1825 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1826 and not a printer admin, then fail */
1828 if ( (p->server_info->utok.uid != sec_initial_uid())
1829 && !user_has_privileges(p->server_info->ptok, &se_printop )
1830 && !token_contains_name_in_list(
1831 uidtoname(p->server_info->utok.uid),
1832 p->server_info->info3->base.domain.string,
1834 p->server_info->ptok,
1835 lp_printer_admin(-1)) )
1837 return WERR_ACCESS_DENIED;
1840 /* check that we have a valid driver name first */
1842 if ((version = get_version_id(r->in.architecture)) == -1)
1843 return WERR_INVALID_ENVIRONMENT;
1845 status = winreg_get_driver(p->mem_ctx, p->server_info, p->msg_ctx,
1846 r->in.architecture, r->in.driver,
1848 if (!W_ERROR_IS_OK(status)) {
1849 /* try for Win2k driver if "Windows NT x86" */
1851 if ( version == 2 ) {
1854 status = winreg_get_driver(p->mem_ctx, p->server_info,
1859 if (!W_ERROR_IS_OK(status)) {
1860 status = WERR_UNKNOWN_PRINTER_DRIVER;
1864 /* otherwise it was a failure */
1866 status = WERR_UNKNOWN_PRINTER_DRIVER;
1872 if (printer_driver_in_use(p->mem_ctx, p->server_info, p->msg_ctx,
1874 status = WERR_PRINTER_DRIVER_IN_USE;
1879 status = winreg_get_driver(p->mem_ctx, p->server_info,
1882 r->in.driver, 3, &info_win2k);
1883 if (W_ERROR_IS_OK(status)) {
1884 /* if we get to here, we now have 2 driver info structures to remove */
1885 /* remove the Win2k driver first*/
1887 status = winreg_del_driver(p->mem_ctx,
1891 talloc_free(info_win2k);
1893 /* this should not have failed---if it did, report to client */
1894 if (!W_ERROR_IS_OK(status)) {
1900 status = winreg_del_driver(p->mem_ctx, p->server_info, p->msg_ctx,
1909 /****************************************************************
1910 _spoolss_DeletePrinterDriverEx
1911 ****************************************************************/
1913 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
1914 struct spoolss_DeletePrinterDriverEx *r)
1916 struct spoolss_DriverInfo8 *info = NULL;
1917 struct spoolss_DriverInfo8 *info_win2k = NULL;
1921 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1923 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1924 and not a printer admin, then fail */
1926 if ( (p->server_info->utok.uid != sec_initial_uid())
1927 && !user_has_privileges(p->server_info->ptok, &se_printop )
1928 && !token_contains_name_in_list(
1929 uidtoname(p->server_info->utok.uid),
1930 p->server_info->info3->base.domain.string,
1932 p->server_info->ptok, lp_printer_admin(-1)) )
1934 return WERR_ACCESS_DENIED;
1937 /* check that we have a valid driver name first */
1938 if ((version = get_version_id(r->in.architecture)) == -1) {
1939 /* this is what NT returns */
1940 return WERR_INVALID_ENVIRONMENT;
1943 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
1944 version = r->in.version;
1946 status = winreg_get_driver(p->mem_ctx, p->server_info,
1947 p->msg_ctx, r->in.architecture,
1948 r->in.driver, version, &info);
1949 if (!W_ERROR_IS_OK(status)) {
1950 status = WERR_UNKNOWN_PRINTER_DRIVER;
1953 * if the client asked for a specific version,
1954 * or this is something other than Windows NT x86,
1958 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
1961 /* try for Win2k driver if "Windows NT x86" */
1964 status = winreg_get_driver(info, p->server_info, p->msg_ctx,
1968 if (!W_ERROR_IS_OK(status)) {
1969 status = WERR_UNKNOWN_PRINTER_DRIVER;
1974 if (printer_driver_in_use(info, p->server_info, p->msg_ctx, info)) {
1975 status = WERR_PRINTER_DRIVER_IN_USE;
1980 * we have a couple of cases to consider.
1981 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
1982 * then the delete should fail if **any** files overlap with
1984 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
1985 * non-overlapping files
1986 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
1987 * is set, the do not delete any files
1988 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
1991 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
1993 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
1996 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
1997 printer_driver_files_in_use(info, p->server_info, p->msg_ctx,
1999 /* no idea of the correct error here */
2000 status = WERR_ACCESS_DENIED;
2005 /* also check for W32X86/3 if necessary; maybe we already have? */
2007 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2008 status = winreg_get_driver(info, p->server_info, p->msg_ctx,
2010 r->in.driver, 3, &info_win2k);
2011 if (W_ERROR_IS_OK(status)) {
2014 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2015 printer_driver_files_in_use(info, p->server_info,
2018 /* no idea of the correct error here */
2019 talloc_free(info_win2k);
2020 status = WERR_ACCESS_DENIED;
2024 /* if we get to here, we now have 2 driver info structures to remove */
2025 /* remove the Win2k driver first*/
2027 status = winreg_del_driver(info, p->server_info,
2028 p->msg_ctx, info_win2k, 3);
2030 /* this should not have failed---if it did, report to client */
2032 if (!W_ERROR_IS_OK(status)) {
2037 * now delete any associated files if delete_files is
2038 * true. Even if this part failes, we return succes
2039 * because the driver doesn not exist any more
2042 delete_driver_files(p->server_info,
2048 status = winreg_del_driver(info, p->server_info, p->msg_ctx, info,
2050 if (!W_ERROR_IS_OK(status)) {
2055 * now delete any associated files if delete_files is
2056 * true. Even if this part failes, we return succes
2057 * because the driver doesn not exist any more
2060 delete_driver_files(p->server_info, info);
2069 /********************************************************************
2070 GetPrinterData on a printer server Handle.
2071 ********************************************************************/
2073 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2075 enum winreg_Type *type,
2076 union spoolss_PrinterData *data)
2078 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2080 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2086 if (!StrCaseCmp(value, "BeepEnabled")) {
2092 if (!StrCaseCmp(value, "EventLog")) {
2094 /* formally was 0x1b */
2099 if (!StrCaseCmp(value, "NetPopup")) {
2105 if (!StrCaseCmp(value, "MajorVersion")) {
2108 /* Windows NT 4.0 seems to not allow uploading of drivers
2109 to a server that reports 0x3 as the MajorVersion.
2110 need to investigate more how Win2k gets around this .
2113 if (RA_WINNT == get_remote_arch()) {
2122 if (!StrCaseCmp(value, "MinorVersion")) {
2129 * uint32_t size = 0x114
2130 * uint32_t major = 5
2131 * uint32_t minor = [0|1]
2132 * uint32_t build = [2195|2600]
2133 * extra unicode string = e.g. "Service Pack 3"
2135 if (!StrCaseCmp(value, "OSVersion")) {
2137 enum ndr_err_code ndr_err;
2138 struct spoolss_OSVersion os;
2140 os.major = 5; /* Windows 2000 == 5.0 */
2142 os.build = 2195; /* build */
2143 os.extra_string = ""; /* leave extra string empty */
2145 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2146 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2147 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2148 return WERR_GENERAL_FAILURE;
2152 data->binary = blob;
2158 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2161 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2162 W_ERROR_HAVE_NO_MEMORY(data->string);
2167 if (!StrCaseCmp(value, "Architecture")) {
2169 data->string = talloc_strdup(mem_ctx,
2170 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2171 W_ERROR_HAVE_NO_MEMORY(data->string);
2176 if (!StrCaseCmp(value, "DsPresent")) {
2179 /* only show the publish check box if we are a
2180 member of a AD domain */
2182 if (lp_security() == SEC_ADS) {
2190 if (!StrCaseCmp(value, "DNSMachineName")) {
2191 const char *hostname = get_mydnsfullname();
2194 return WERR_BADFILE;
2198 data->string = talloc_strdup(mem_ctx, hostname);
2199 W_ERROR_HAVE_NO_MEMORY(data->string);
2206 return WERR_INVALID_PARAM;
2209 /****************************************************************
2210 _spoolss_GetPrinterData
2211 ****************************************************************/
2213 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2214 struct spoolss_GetPrinterData *r)
2216 struct spoolss_GetPrinterDataEx r2;
2218 r2.in.handle = r->in.handle;
2219 r2.in.key_name = "PrinterDriverData";
2220 r2.in.value_name = r->in.value_name;
2221 r2.in.offered = r->in.offered;
2222 r2.out.type = r->out.type;
2223 r2.out.data = r->out.data;
2224 r2.out.needed = r->out.needed;
2226 return _spoolss_GetPrinterDataEx(p, &r2);
2229 /*********************************************************
2230 Connect to the client machine.
2231 **********************************************************/
2233 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2234 struct sockaddr_storage *client_ss, const char *remote_machine)
2237 struct cli_state *the_cli;
2238 struct sockaddr_storage rm_addr;
2239 char addr[INET6_ADDRSTRLEN];
2241 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2242 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2244 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2245 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2248 print_sockaddr(addr, sizeof(addr), &rm_addr);
2250 rm_addr = *client_ss;
2251 print_sockaddr(addr, sizeof(addr), &rm_addr);
2252 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2256 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2257 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2262 /* setup the connection */
2263 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2264 &rm_addr, 0, "IPC$", "IPC",
2268 0, lp_client_signing(), NULL );
2270 if ( !NT_STATUS_IS_OK( ret ) ) {
2271 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2276 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2277 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2278 cli_shutdown(the_cli);
2283 * Ok - we have an anonymous connection to the IPC$ share.
2284 * Now start the NT Domain stuff :-).
2287 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2288 if (!NT_STATUS_IS_OK(ret)) {
2289 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2290 remote_machine, nt_errstr(ret)));
2291 cli_shutdown(the_cli);
2298 /***************************************************************************
2299 Connect to the client.
2300 ****************************************************************************/
2302 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2303 uint32_t localprinter, uint32_t type,
2304 struct policy_handle *handle,
2305 struct sockaddr_storage *client_ss,
2306 struct messaging_context *msg_ctx)
2312 * If it's the first connection, contact the client
2313 * and connect to the IPC$ share anonymously
2315 if (smb_connections==0) {
2316 fstring unix_printer;
2318 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2320 if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ss, unix_printer ))
2323 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2324 receive_notify2_message_list);
2325 /* Tell the connections db we're now interested in printer
2326 * notify messages. */
2327 serverid_register_msg_flags(messaging_server_id(msg_ctx),
2328 true, FLAG_MSG_PRINT_NOTIFY);
2332 * Tell the specific printing tdb we want messages for this printer
2333 * by registering our PID.
2336 if (!print_notify_register_pid(snum))
2337 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2341 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2349 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2350 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2351 win_errstr(result)));
2353 return (W_ERROR_IS_OK(result));
2356 /****************************************************************
2357 ****************************************************************/
2359 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2360 const struct spoolss_NotifyOption *r)
2362 struct spoolss_NotifyOption *option;
2369 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2376 if (!option->count) {
2380 option->types = talloc_zero_array(option,
2381 struct spoolss_NotifyOptionType, option->count);
2382 if (!option->types) {
2383 talloc_free(option);
2387 for (i=0; i < option->count; i++) {
2388 option->types[i] = r->types[i];
2390 if (option->types[i].count) {
2391 option->types[i].fields = talloc_zero_array(option,
2392 union spoolss_Field, option->types[i].count);
2393 if (!option->types[i].fields) {
2394 talloc_free(option);
2397 for (k=0; k<option->types[i].count; k++) {
2398 option->types[i].fields[k] =
2399 r->types[i].fields[k];
2407 /****************************************************************
2408 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2410 * before replying OK: status=0 a rpc call is made to the workstation
2411 * asking ReplyOpenPrinter
2413 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2414 * called from api_spoolss_rffpcnex
2415 ****************************************************************/
2417 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2418 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2421 struct spoolss_NotifyOption *option = r->in.notify_options;
2422 struct sockaddr_storage client_ss;
2424 /* store the notify value in the printer struct */
2426 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2429 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2430 "Invalid handle (%s:%u:%u).\n",
2431 OUR_HANDLE(r->in.handle)));
2435 Printer->notify.flags = r->in.flags;
2436 Printer->notify.options = r->in.options;
2437 Printer->notify.printerlocal = r->in.printer_local;
2438 Printer->notify.msg_ctx = p->msg_ctx;
2440 TALLOC_FREE(Printer->notify.option);
2441 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2443 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2445 /* Connect to the client machine and send a ReplyOpenPrinter */
2447 if ( Printer->printer_type == SPLHND_SERVER)
2449 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2450 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2453 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2454 "client_address is %s\n", p->client_address));
2456 if (!interpret_string_addr(&client_ss, p->client_address,
2458 return WERR_SERVER_UNAVAILABLE;
2461 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2462 Printer->notify.printerlocal, 1,
2463 &Printer->notify.client_hnd,
2464 &client_ss, p->msg_ctx))
2465 return WERR_SERVER_UNAVAILABLE;
2467 Printer->notify.client_connected = true;
2472 /*******************************************************************
2473 * fill a notify_info_data with the servername
2474 ********************************************************************/
2476 static void spoolss_notify_server_name(int snum,
2477 struct spoolss_Notify *data,
2478 print_queue_struct *queue,
2479 struct spoolss_PrinterInfo2 *pinfo2,
2480 TALLOC_CTX *mem_ctx)
2482 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2485 /*******************************************************************
2486 * fill a notify_info_data with the printername (not including the servername).
2487 ********************************************************************/
2489 static void spoolss_notify_printer_name(int snum,
2490 struct spoolss_Notify *data,
2491 print_queue_struct *queue,
2492 struct spoolss_PrinterInfo2 *pinfo2,
2493 TALLOC_CTX *mem_ctx)
2495 /* the notify name should not contain the \\server\ part */
2496 const char *p = strrchr(pinfo2->printername, '\\');
2499 p = pinfo2->printername;
2504 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2507 /*******************************************************************
2508 * fill a notify_info_data with the servicename
2509 ********************************************************************/
2511 static void spoolss_notify_share_name(int snum,
2512 struct spoolss_Notify *data,
2513 print_queue_struct *queue,
2514 struct spoolss_PrinterInfo2 *pinfo2,
2515 TALLOC_CTX *mem_ctx)
2517 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2520 /*******************************************************************
2521 * fill a notify_info_data with the port name
2522 ********************************************************************/
2524 static void spoolss_notify_port_name(int snum,
2525 struct spoolss_Notify *data,
2526 print_queue_struct *queue,
2527 struct spoolss_PrinterInfo2 *pinfo2,
2528 TALLOC_CTX *mem_ctx)
2530 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2533 /*******************************************************************
2534 * fill a notify_info_data with the printername
2535 * but it doesn't exist, have to see what to do
2536 ********************************************************************/
2538 static void spoolss_notify_driver_name(int snum,
2539 struct spoolss_Notify *data,
2540 print_queue_struct *queue,
2541 struct spoolss_PrinterInfo2 *pinfo2,
2542 TALLOC_CTX *mem_ctx)
2544 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2547 /*******************************************************************
2548 * fill a notify_info_data with the comment
2549 ********************************************************************/
2551 static void spoolss_notify_comment(int snum,
2552 struct spoolss_Notify *data,
2553 print_queue_struct *queue,
2554 struct spoolss_PrinterInfo2 *pinfo2,
2555 TALLOC_CTX *mem_ctx)
2559 if (*pinfo2->comment == '\0') {
2560 p = lp_comment(snum);
2562 p = pinfo2->comment;
2565 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2568 /*******************************************************************
2569 * fill a notify_info_data with the comment
2570 * location = "Room 1, floor 2, building 3"
2571 ********************************************************************/
2573 static void spoolss_notify_location(int snum,
2574 struct spoolss_Notify *data,
2575 print_queue_struct *queue,
2576 struct spoolss_PrinterInfo2 *pinfo2,
2577 TALLOC_CTX *mem_ctx)
2579 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
2582 /*******************************************************************
2583 * fill a notify_info_data with the device mode
2584 * jfm:xxxx don't to it for know but that's a real problem !!!
2585 ********************************************************************/
2587 static void spoolss_notify_devmode(int snum,
2588 struct spoolss_Notify *data,
2589 print_queue_struct *queue,
2590 struct spoolss_PrinterInfo2 *pinfo2,
2591 TALLOC_CTX *mem_ctx)
2593 /* for a dummy implementation we have to zero the fields */
2594 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2597 /*******************************************************************
2598 * fill a notify_info_data with the separator file name
2599 ********************************************************************/
2601 static void spoolss_notify_sepfile(int snum,
2602 struct spoolss_Notify *data,
2603 print_queue_struct *queue,
2604 struct spoolss_PrinterInfo2 *pinfo2,
2605 TALLOC_CTX *mem_ctx)
2607 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2610 /*******************************************************************
2611 * fill a notify_info_data with the print processor
2612 * jfm:xxxx return always winprint to indicate we don't do anything to it
2613 ********************************************************************/
2615 static void spoolss_notify_print_processor(int snum,
2616 struct spoolss_Notify *data,
2617 print_queue_struct *queue,
2618 struct spoolss_PrinterInfo2 *pinfo2,
2619 TALLOC_CTX *mem_ctx)
2621 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2624 /*******************************************************************
2625 * fill a notify_info_data with the print processor options
2626 * jfm:xxxx send an empty string
2627 ********************************************************************/
2629 static void spoolss_notify_parameters(int snum,
2630 struct spoolss_Notify *data,
2631 print_queue_struct *queue,
2632 struct spoolss_PrinterInfo2 *pinfo2,
2633 TALLOC_CTX *mem_ctx)
2635 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2638 /*******************************************************************
2639 * fill a notify_info_data with the data type
2640 * jfm:xxxx always send RAW as data type
2641 ********************************************************************/
2643 static void spoolss_notify_datatype(int snum,
2644 struct spoolss_Notify *data,
2645 print_queue_struct *queue,
2646 struct spoolss_PrinterInfo2 *pinfo2,
2647 TALLOC_CTX *mem_ctx)
2649 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2652 /*******************************************************************
2653 * fill a notify_info_data with the security descriptor
2654 * jfm:xxxx send an null pointer to say no security desc
2655 * have to implement security before !
2656 ********************************************************************/
2658 static void spoolss_notify_security_desc(int snum,
2659 struct spoolss_Notify *data,
2660 print_queue_struct *queue,
2661 struct spoolss_PrinterInfo2 *pinfo2,
2662 TALLOC_CTX *mem_ctx)
2664 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2667 /*******************************************************************
2668 * fill a notify_info_data with the attributes
2669 * jfm:xxxx a samba printer is always shared
2670 ********************************************************************/
2672 static void spoolss_notify_attributes(int snum,
2673 struct spoolss_Notify *data,
2674 print_queue_struct *queue,
2675 struct spoolss_PrinterInfo2 *pinfo2,
2676 TALLOC_CTX *mem_ctx)
2678 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2681 /*******************************************************************
2682 * fill a notify_info_data with the priority
2683 ********************************************************************/
2685 static void spoolss_notify_priority(int snum,
2686 struct spoolss_Notify *data,
2687 print_queue_struct *queue,
2688 struct spoolss_PrinterInfo2 *pinfo2,
2689 TALLOC_CTX *mem_ctx)
2691 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2694 /*******************************************************************
2695 * fill a notify_info_data with the default priority
2696 ********************************************************************/
2698 static void spoolss_notify_default_priority(int snum,
2699 struct spoolss_Notify *data,
2700 print_queue_struct *queue,
2701 struct spoolss_PrinterInfo2 *pinfo2,
2702 TALLOC_CTX *mem_ctx)
2704 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
2707 /*******************************************************************
2708 * fill a notify_info_data with the start time
2709 ********************************************************************/
2711 static void spoolss_notify_start_time(int snum,
2712 struct spoolss_Notify *data,
2713 print_queue_struct *queue,
2714 struct spoolss_PrinterInfo2 *pinfo2,
2715 TALLOC_CTX *mem_ctx)
2717 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
2720 /*******************************************************************
2721 * fill a notify_info_data with the until time
2722 ********************************************************************/
2724 static void spoolss_notify_until_time(int snum,
2725 struct spoolss_Notify *data,
2726 print_queue_struct *queue,
2727 struct spoolss_PrinterInfo2 *pinfo2,
2728 TALLOC_CTX *mem_ctx)
2730 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
2733 /*******************************************************************
2734 * fill a notify_info_data with the status
2735 ********************************************************************/
2737 static void spoolss_notify_status(int snum,
2738 struct spoolss_Notify *data,
2739 print_queue_struct *queue,
2740 struct spoolss_PrinterInfo2 *pinfo2,
2741 TALLOC_CTX *mem_ctx)
2743 print_status_struct status;
2745 print_queue_length(server_messaging_context(), snum, &status);
2746 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
2749 /*******************************************************************
2750 * fill a notify_info_data with the number of jobs queued
2751 ********************************************************************/
2753 static void spoolss_notify_cjobs(int snum,
2754 struct spoolss_Notify *data,
2755 print_queue_struct *queue,
2756 struct spoolss_PrinterInfo2 *pinfo2,
2757 TALLOC_CTX *mem_ctx)
2759 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
2760 data, print_queue_length(server_messaging_context(), snum,
2764 /*******************************************************************
2765 * fill a notify_info_data with the average ppm
2766 ********************************************************************/
2768 static void spoolss_notify_average_ppm(int snum,
2769 struct spoolss_Notify *data,
2770 print_queue_struct *queue,
2771 struct spoolss_PrinterInfo2 *pinfo2,
2772 TALLOC_CTX *mem_ctx)
2774 /* always respond 8 pages per minutes */
2775 /* a little hard ! */
2776 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
2779 /*******************************************************************
2780 * fill a notify_info_data with username
2781 ********************************************************************/
2783 static void spoolss_notify_username(int snum,
2784 struct spoolss_Notify *data,
2785 print_queue_struct *queue,
2786 struct spoolss_PrinterInfo2 *pinfo2,
2787 TALLOC_CTX *mem_ctx)
2789 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
2792 /*******************************************************************
2793 * fill a notify_info_data with job status
2794 ********************************************************************/
2796 static void spoolss_notify_job_status(int snum,
2797 struct spoolss_Notify *data,
2798 print_queue_struct *queue,
2799 struct spoolss_PrinterInfo2 *pinfo2,
2800 TALLOC_CTX *mem_ctx)
2802 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
2805 /*******************************************************************
2806 * fill a notify_info_data with job name
2807 ********************************************************************/
2809 static void spoolss_notify_job_name(int snum,
2810 struct spoolss_Notify *data,
2811 print_queue_struct *queue,
2812 struct spoolss_PrinterInfo2 *pinfo2,
2813 TALLOC_CTX *mem_ctx)
2815 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
2818 /*******************************************************************
2819 * fill a notify_info_data with job status
2820 ********************************************************************/
2822 static void spoolss_notify_job_status_string(int snum,
2823 struct spoolss_Notify *data,
2824 print_queue_struct *queue,
2825 struct spoolss_PrinterInfo2 *pinfo2,
2826 TALLOC_CTX *mem_ctx)
2829 * Now we're returning job status codes we just return a "" here. JRA.
2834 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
2837 switch (queue->status) {
2842 p = ""; /* NT provides the paused string */
2851 #endif /* NO LONGER NEEDED. */
2853 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2856 /*******************************************************************
2857 * fill a notify_info_data with job time
2858 ********************************************************************/
2860 static void spoolss_notify_job_time(int snum,
2861 struct spoolss_Notify *data,
2862 print_queue_struct *queue,
2863 struct spoolss_PrinterInfo2 *pinfo2,
2864 TALLOC_CTX *mem_ctx)
2866 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2869 /*******************************************************************
2870 * fill a notify_info_data with job size
2871 ********************************************************************/
2873 static void spoolss_notify_job_size(int snum,
2874 struct spoolss_Notify *data,
2875 print_queue_struct *queue,
2876 struct spoolss_PrinterInfo2 *pinfo2,
2877 TALLOC_CTX *mem_ctx)
2879 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
2882 /*******************************************************************
2883 * fill a notify_info_data with page info
2884 ********************************************************************/
2885 static void spoolss_notify_total_pages(int snum,
2886 struct spoolss_Notify *data,
2887 print_queue_struct *queue,
2888 struct spoolss_PrinterInfo2 *pinfo2,
2889 TALLOC_CTX *mem_ctx)
2891 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
2894 /*******************************************************************
2895 * fill a notify_info_data with pages printed info.
2896 ********************************************************************/
2897 static void spoolss_notify_pages_printed(int snum,
2898 struct spoolss_Notify *data,
2899 print_queue_struct *queue,
2900 struct spoolss_PrinterInfo2 *pinfo2,
2901 TALLOC_CTX *mem_ctx)
2903 /* Add code when back-end tracks this */
2904 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2907 /*******************************************************************
2908 Fill a notify_info_data with job position.
2909 ********************************************************************/
2911 static void spoolss_notify_job_position(int snum,
2912 struct spoolss_Notify *data,
2913 print_queue_struct *queue,
2914 struct spoolss_PrinterInfo2 *pinfo2,
2915 TALLOC_CTX *mem_ctx)
2917 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
2920 /*******************************************************************
2921 Fill a notify_info_data with submitted time.
2922 ********************************************************************/
2924 static void spoolss_notify_submitted_time(int snum,
2925 struct spoolss_Notify *data,
2926 print_queue_struct *queue,
2927 struct spoolss_PrinterInfo2 *pinfo2,
2928 TALLOC_CTX *mem_ctx)
2930 data->data.string.string = NULL;
2931 data->data.string.size = 0;
2933 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
2934 &data->data.string.string,
2935 &data->data.string.size);
2939 struct s_notify_info_data_table
2941 enum spoolss_NotifyType type;
2944 enum spoolss_NotifyTable variable_type;
2945 void (*fn) (int snum, struct spoolss_Notify *data,
2946 print_queue_struct *queue,
2947 struct spoolss_PrinterInfo2 *pinfo2,
2948 TALLOC_CTX *mem_ctx);
2951 /* A table describing the various print notification constants and
2952 whether the notification data is a pointer to a variable sized
2953 buffer, a one value uint32_t or a two value uint32_t. */
2955 static const struct s_notify_info_data_table notify_info_data_table[] =
2957 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2958 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2959 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
2960 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2961 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2962 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
2963 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
2964 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2965 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
2966 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2967 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2968 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2969 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
2970 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
2971 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2972 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
2973 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2974 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2975 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
2976 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
2977 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
2978 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
2979 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
2980 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2981 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
2982 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2983 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2984 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2985 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2986 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2987 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2988 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2989 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2990 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2991 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2992 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2993 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
2994 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
2995 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
2996 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
2997 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2998 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
2999 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3000 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3001 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3002 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3003 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3004 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3005 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3008 /*******************************************************************
3009 Return the variable_type of info_data structure.
3010 ********************************************************************/
3012 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3017 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3018 if ( (notify_info_data_table[i].type == type) &&
3019 (notify_info_data_table[i].field == field) ) {
3020 return notify_info_data_table[i].variable_type;
3024 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3029 /****************************************************************************
3030 ****************************************************************************/
3032 static bool search_notify(enum spoolss_NotifyType type,
3038 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3039 if (notify_info_data_table[i].type == type &&
3040 notify_info_data_table[i].field == field &&
3041 notify_info_data_table[i].fn != NULL) {
3050 /****************************************************************************
3051 ****************************************************************************/
3053 static void construct_info_data(struct spoolss_Notify *info_data,
3054 enum spoolss_NotifyType type,
3055 uint16_t field, int id)
3057 info_data->type = type;
3058 info_data->field.field = field;
3059 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3060 info_data->job_id = id;
3063 /*******************************************************************
3065 * fill a notify_info struct with info asked
3067 ********************************************************************/
3069 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3070 struct spoolss_NotifyInfo *info,
3071 struct spoolss_PrinterInfo2 *pinfo2,
3073 const struct spoolss_NotifyOptionType *option_type,
3075 TALLOC_CTX *mem_ctx)
3078 enum spoolss_NotifyType type;
3081 struct spoolss_Notify *current_data;
3082 print_queue_struct *queue=NULL;
3084 type = option_type->type;
3086 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3087 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3088 option_type->count, lp_servicename(snum)));
3090 for(field_num=0; field_num < option_type->count; field_num++) {
3091 field = option_type->fields[field_num].field;
3093 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3095 if (!search_notify(type, field, &j) )
3098 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3099 struct spoolss_Notify,
3101 if (info->notifies == NULL) {
3102 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3106 current_data = &info->notifies[info->count];
3108 construct_info_data(current_data, type, field, id);
3110 DEBUG(10, ("construct_notify_printer_info: "
3111 "calling [%s] snum=%d printername=[%s])\n",
3112 notify_info_data_table[j].name, snum,
3113 pinfo2->printername));
3115 notify_info_data_table[j].fn(snum, current_data, queue,
3124 /*******************************************************************
3126 * fill a notify_info struct with info asked
3128 ********************************************************************/
3130 static bool construct_notify_jobs_info(print_queue_struct *queue,
3131 struct spoolss_NotifyInfo *info,
3132 struct spoolss_PrinterInfo2 *pinfo2,
3134 const struct spoolss_NotifyOptionType *option_type,
3136 TALLOC_CTX *mem_ctx)
3139 enum spoolss_NotifyType type;
3141 struct spoolss_Notify *current_data;
3143 DEBUG(4,("construct_notify_jobs_info\n"));
3145 type = option_type->type;
3147 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3148 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3149 option_type->count));
3151 for(field_num=0; field_num<option_type->count; field_num++) {
3152 field = option_type->fields[field_num].field;
3154 if (!search_notify(type, field, &j) )
3157 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3158 struct spoolss_Notify,
3160 if (info->notifies == NULL) {
3161 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3165 current_data=&(info->notifies[info->count]);
3167 construct_info_data(current_data, type, field, id);
3168 notify_info_data_table[j].fn(snum, current_data, queue,
3177 * JFM: The enumeration is not that simple, it's even non obvious.
3179 * let's take an example: I want to monitor the PRINTER SERVER for
3180 * the printer's name and the number of jobs currently queued.
3181 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3182 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3184 * I have 3 printers on the back of my server.
3186 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3189 * 1 printer 1 name 1
3190 * 2 printer 1 cjob 1
3191 * 3 printer 2 name 2
3192 * 4 printer 2 cjob 2
3193 * 5 printer 3 name 3
3194 * 6 printer 3 name 3
3196 * that's the print server case, the printer case is even worse.
3199 /*******************************************************************
3201 * enumerate all printers on the printserver
3202 * fill a notify_info struct with info asked
3204 ********************************************************************/
3206 static WERROR printserver_notify_info(struct pipes_struct *p,
3207 struct policy_handle *hnd,
3208 struct spoolss_NotifyInfo *info,
3209 TALLOC_CTX *mem_ctx)
3212 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3213 int n_services=lp_numservices();
3215 struct spoolss_NotifyOption *option;
3216 struct spoolss_NotifyOptionType option_type;
3217 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3220 DEBUG(4,("printserver_notify_info\n"));
3225 option = Printer->notify.option;
3228 info->notifies = NULL;
3231 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3232 sending a ffpcn() request first */
3237 for (i=0; i<option->count; i++) {
3238 option_type = option->types[i];
3240 if (option_type.type != PRINTER_NOTIFY_TYPE)
3243 for (snum = 0; snum < n_services; snum++) {
3244 if (!lp_browseable(snum) ||
3245 !lp_snum_ok(snum) ||
3246 !lp_print_ok(snum)) {
3247 continue; /* skip */
3250 /* Maybe we should use the SYSTEM server_info here... */
3251 result = winreg_get_printer(mem_ctx, p->server_info,
3253 Printer->servername,
3254 lp_servicename(snum),
3256 if (!W_ERROR_IS_OK(result)) {
3257 DEBUG(4, ("printserver_notify_info: "
3258 "Failed to get printer [%s]\n",
3259 lp_servicename(snum)));
3264 construct_notify_printer_info(Printer, info,
3269 TALLOC_FREE(pinfo2);
3275 * Debugging information, don't delete.
3278 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3279 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3280 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3282 for (i=0; i<info->count; i++) {
3283 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3284 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3285 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3292 /*******************************************************************
3294 * fill a notify_info struct with info asked
3296 ********************************************************************/
3298 static WERROR printer_notify_info(struct pipes_struct *p,
3299 struct policy_handle *hnd,
3300 struct spoolss_NotifyInfo *info,
3301 TALLOC_CTX *mem_ctx)
3304 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3307 struct spoolss_NotifyOption *option;
3308 struct spoolss_NotifyOptionType option_type;
3310 print_queue_struct *queue=NULL;
3311 print_status_struct status;
3312 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3315 DEBUG(4,("printer_notify_info\n"));
3320 option = Printer->notify.option;
3324 info->notifies = NULL;
3327 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3328 sending a ffpcn() request first */
3333 get_printer_snum(p, hnd, &snum, NULL);
3335 /* Maybe we should use the SYSTEM server_info here... */
3336 result = winreg_get_printer(mem_ctx, p->server_info, p->msg_ctx,
3337 Printer->servername,
3338 lp_servicename(snum), &pinfo2);
3339 if (!W_ERROR_IS_OK(result)) {
3343 for (i=0; i<option->count; i++) {
3344 option_type = option->types[i];
3346 switch (option_type.type) {
3347 case PRINTER_NOTIFY_TYPE:
3348 if (construct_notify_printer_info(Printer, info,
3356 case JOB_NOTIFY_TYPE:
3358 count = print_queue_status(p->msg_ctx, snum, &queue,
3361 for (j=0; j<count; j++) {
3362 construct_notify_jobs_info(&queue[j], info,
3375 * Debugging information, don't delete.
3378 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3379 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3380 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3382 for (i=0; i<info->count; i++) {
3383 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3384 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3385 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3389 talloc_free(pinfo2);
3393 /****************************************************************
3394 _spoolss_RouterRefreshPrinterChangeNotify
3395 ****************************************************************/
3397 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3398 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3400 struct spoolss_NotifyInfo *info;
3402 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
3403 WERROR result = WERR_BADFID;
3405 /* we always have a spoolss_NotifyInfo struct */
3406 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3408 result = WERR_NOMEM;
3412 *r->out.info = info;
3415 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3416 "Invalid handle (%s:%u:%u).\n",
3417 OUR_HANDLE(r->in.handle)));
3421 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3424 * We are now using the change value, and
3425 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3426 * I don't have a global notification system, I'm sending back all the
3427 * informations even when _NOTHING_ has changed.
3430 /* We need to keep track of the change value to send back in
3431 RRPCN replies otherwise our updates are ignored. */
3433 Printer->notify.fnpcn = true;
3435 if (Printer->notify.client_connected) {
3436 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3437 "Saving change value in request [%x]\n",
3439 Printer->notify.change = r->in.change_low;
3442 /* just ignore the spoolss_NotifyOption */
3444 switch (Printer->printer_type) {
3446 result = printserver_notify_info(p, r->in.handle,
3450 case SPLHND_PRINTER:
3451 result = printer_notify_info(p, r->in.handle,
3456 Printer->notify.fnpcn = false;
3462 /********************************************************************
3463 * construct_printer_info_0
3464 * fill a printer_info_0 struct
3465 ********************************************************************/
3467 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3468 struct auth_serversupplied_info *server_info,
3469 struct messaging_context *msg_ctx,
3470 struct spoolss_PrinterInfo2 *info2,
3471 struct spoolss_PrinterInfo0 *r,
3475 counter_printer_0 *session_counter;
3476 struct timeval setuptime;
3477 print_status_struct status;
3479 r->printername = talloc_strdup(mem_ctx, info2->printername);
3480 W_ERROR_HAVE_NO_MEMORY(r->printername);
3482 r->servername = talloc_strdup(mem_ctx, info2->servername);
3483 W_ERROR_HAVE_NO_MEMORY(r->servername);
3485 count = print_queue_length(msg_ctx, snum, &status);
3487 /* check if we already have a counter for this printer */
3488 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3489 if (session_counter->snum == snum)
3493 /* it's the first time, add it to the list */
3494 if (session_counter == NULL) {
3495 session_counter = SMB_MALLOC_P(counter_printer_0);
3496 W_ERROR_HAVE_NO_MEMORY(session_counter);
3497 ZERO_STRUCTP(session_counter);
3498 session_counter->snum = snum;
3499 session_counter->counter = 0;
3500 DLIST_ADD(counter_list, session_counter);
3504 session_counter->counter++;
3510 get_startup_time(&setuptime);
3511 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3514 * the global_counter should be stored in a TDB as it's common to all the clients
3515 * and should be zeroed on samba startup
3517 r->global_counter = session_counter->counter;
3519 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3520 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3521 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3522 r->free_build = SPOOLSS_RELEASE_BUILD;
3524 r->max_spooling = 0;
3525 r->session_counter = session_counter->counter;
3526 r->num_error_out_of_paper = 0x0;
3527 r->num_error_not_ready = 0x0; /* number of print failure */
3529 r->number_of_processors = 0x1;
3530 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3531 r->high_part_total_bytes = 0x0;
3533 /* ChangeID in milliseconds*/
3534 winreg_printer_get_changeid(mem_ctx, server_info, msg_ctx,
3535 info2->sharename, &r->change_id);
3537 r->last_error = WERR_OK;
3538 r->status = nt_printq_status(status.status);
3539 r->enumerate_network_printers = 0x0;
3540 r->c_setprinter = 0x0;
3541 r->processor_architecture = 0x0;
3542 r->processor_level = 0x6; /* 6 ???*/
3551 /********************************************************************
3552 * construct_printer_info1
3553 * fill a spoolss_PrinterInfo1 struct
3554 ********************************************************************/
3556 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3557 const struct spoolss_PrinterInfo2 *info2,
3559 struct spoolss_PrinterInfo1 *r,
3564 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3568 W_ERROR_HAVE_NO_MEMORY(r->description);
3570 if (info2->comment == NULL || info2->comment[0] == '\0') {
3571 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3573 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3575 W_ERROR_HAVE_NO_MEMORY(r->comment);
3577 r->name = talloc_strdup(mem_ctx, info2->printername);
3578 W_ERROR_HAVE_NO_MEMORY(r->name);
3583 /********************************************************************
3584 * construct_printer_info2
3585 * fill a spoolss_PrinterInfo2 struct
3586 ********************************************************************/
3588 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3589 const struct spoolss_PrinterInfo2 *info2,
3590 struct spoolss_PrinterInfo2 *r,
3594 print_status_struct status;
3596 count = print_queue_length(server_messaging_context(), snum, &status);
3598 r->servername = talloc_strdup(mem_ctx, info2->servername);
3599 W_ERROR_HAVE_NO_MEMORY(r->servername);
3600 r->printername = talloc_strdup(mem_ctx, info2->printername);
3601 W_ERROR_HAVE_NO_MEMORY(r->printername);
3602 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3603 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3604 r->portname = talloc_strdup(mem_ctx, info2->portname);
3605 W_ERROR_HAVE_NO_MEMORY(r->portname);
3606 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
3607 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3609 if (info2->comment[0] == '\0') {
3610 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3612 r->comment = talloc_strdup(mem_ctx, info2->comment);
3614 W_ERROR_HAVE_NO_MEMORY(r->comment);
3616 r->location = talloc_strdup(mem_ctx, info2->location);
3617 W_ERROR_HAVE_NO_MEMORY(r->location);
3618 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
3619 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3620 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
3621 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3622 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
3623 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3624 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
3625 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3627 r->attributes = info2->attributes;
3629 r->priority = info2->priority;
3630 r->defaultpriority = info2->defaultpriority;
3631 r->starttime = info2->starttime;
3632 r->untiltime = info2->untiltime;
3633 r->status = nt_printq_status(status.status);
3635 r->averageppm = info2->averageppm;
3637 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3639 DEBUG(8,("Returning NULL Devicemode!\n"));
3644 if (info2->secdesc != NULL) {
3645 /* don't use talloc_steal() here unless you do a deep steal of all
3646 the SEC_DESC members */
3648 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3654 /********************************************************************
3655 * construct_printer_info3
3656 * fill a spoolss_PrinterInfo3 struct
3657 ********************************************************************/
3659 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3660 const struct spoolss_PrinterInfo2 *info2,
3661 struct spoolss_PrinterInfo3 *r,
3664 /* These are the components of the SD we are returning. */
3666 if (info2->secdesc != NULL) {
3667 /* don't use talloc_steal() here unless you do a deep steal of all
3668 the SEC_DESC members */
3670 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3671 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3677 /********************************************************************
3678 * construct_printer_info4
3679 * fill a spoolss_PrinterInfo4 struct
3680 ********************************************************************/
3682 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
3683 const struct spoolss_PrinterInfo2 *info2,
3684 struct spoolss_PrinterInfo4 *r,
3687 r->printername = talloc_strdup(mem_ctx, info2->printername);
3688 W_ERROR_HAVE_NO_MEMORY(r->printername);
3689 r->servername = talloc_strdup(mem_ctx, info2->servername);
3690 W_ERROR_HAVE_NO_MEMORY(r->servername);
3692 r->attributes = info2->attributes;
3697 /********************************************************************
3698 * construct_printer_info5
3699 * fill a spoolss_PrinterInfo5 struct
3700 ********************************************************************/
3702 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
3703 const struct spoolss_PrinterInfo2 *info2,
3704 struct spoolss_PrinterInfo5 *r,
3707 r->printername = talloc_strdup(mem_ctx, info2->printername);
3708 W_ERROR_HAVE_NO_MEMORY(r->printername);
3709 r->portname = talloc_strdup(mem_ctx, info2->portname);
3710 W_ERROR_HAVE_NO_MEMORY(r->portname);
3712 r->attributes = info2->attributes;
3714 /* these two are not used by NT+ according to MSDN */
3715 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
3716 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
3721 /********************************************************************
3722 * construct_printer_info_6
3723 * fill a spoolss_PrinterInfo6 struct
3724 ********************************************************************/
3726 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
3727 const struct spoolss_PrinterInfo2 *info2,
3728 struct spoolss_PrinterInfo6 *r,
3732 print_status_struct status;
3734 count = print_queue_length(server_messaging_context(), snum, &status);
3736 r->status = nt_printq_status(status.status);
3741 /********************************************************************
3742 * construct_printer_info7
3743 * fill a spoolss_PrinterInfo7 struct
3744 ********************************************************************/
3746 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
3747 struct messaging_context *msg_ctx,
3748 Printer_entry *print_hnd,
3749 struct spoolss_PrinterInfo7 *r,
3752 struct auth_serversupplied_info *server_info;
3756 status = make_server_info_system(mem_ctx, &server_info);
3757 if (!NT_STATUS_IS_OK(status)) {
3758 DEBUG(0, ("construct_printer_info7: "
3759 "Could not create system server_info\n"));
3763 if (is_printer_published(mem_ctx, server_info, msg_ctx,
3764 print_hnd->servername,
3765 lp_servicename(snum), &guid, NULL)) {
3766 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
3767 r->action = DSPRINT_PUBLISH;
3769 r->guid = talloc_strdup(mem_ctx, "");
3770 r->action = DSPRINT_UNPUBLISH;
3772 W_ERROR_HAVE_NO_MEMORY(r->guid);
3774 TALLOC_FREE(server_info);
3778 /********************************************************************
3779 * construct_printer_info8
3780 * fill a spoolss_PrinterInfo8 struct
3781 ********************************************************************/
3783 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
3784 const struct spoolss_PrinterInfo2 *info2,
3785 struct spoolss_DeviceModeInfo *r,
3788 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3790 DEBUG(8,("Returning NULL Devicemode!\n"));
3797 /********************************************************************
3798 ********************************************************************/
3800 static bool snum_is_shared_printer(int snum)
3802 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
3805 /********************************************************************
3806 Spoolss_enumprinters.
3807 ********************************************************************/
3809 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
3810 struct auth_serversupplied_info *server_info,
3811 struct messaging_context *msg_ctx,
3814 union spoolss_PrinterInfo **info_p,
3818 int n_services = lp_numservices();
3819 union spoolss_PrinterInfo *info = NULL;
3821 WERROR result = WERR_OK;
3826 for (snum = 0; snum < n_services; snum++) {
3828 const char *printer;
3829 struct spoolss_PrinterInfo2 *info2;
3831 if (!snum_is_shared_printer(snum)) {
3835 printer = lp_const_servicename(snum);
3837 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
3840 result = winreg_create_printer(mem_ctx,
3845 if (!W_ERROR_IS_OK(result)) {
3849 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
3850 union spoolss_PrinterInfo,
3853 result = WERR_NOMEM;
3857 result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
3858 NULL, printer, &info2);
3859 if (!W_ERROR_IS_OK(result)) {
3865 result = construct_printer_info0(info, server_info,
3867 &info[count].info0, snum);
3870 result = construct_printer_info1(info, info2, flags,
3871 &info[count].info1, snum);
3874 result = construct_printer_info2(info, info2,
3875 &info[count].info2, snum);
3878 result = construct_printer_info4(info, info2,
3879 &info[count].info4, snum);
3882 result = construct_printer_info5(info, info2,
3883 &info[count].info5, snum);
3887 result = WERR_UNKNOWN_LEVEL;
3891 if (!W_ERROR_IS_OK(result)) {
3902 if (!W_ERROR_IS_OK(result)) {
3912 /********************************************************************
3913 * handle enumeration of printers at level 0
3914 ********************************************************************/
3916 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
3917 struct auth_serversupplied_info *server_info,
3918 struct messaging_context *msg_ctx,
3920 const char *servername,
3921 union spoolss_PrinterInfo **info,
3924 DEBUG(4,("enum_all_printers_info_0\n"));
3926 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
3927 0, flags, info, count);
3931 /********************************************************************
3932 ********************************************************************/
3934 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
3935 struct auth_serversupplied_info *server_info,
3936 struct messaging_context *msg_ctx,
3938 union spoolss_PrinterInfo **info,
3941 DEBUG(4,("enum_all_printers_info_1\n"));
3943 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
3944 1, flags, info, count);
3947 /********************************************************************
3948 enum_all_printers_info_1_local.
3949 *********************************************************************/
3951 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
3952 struct auth_serversupplied_info *server_info,
3953 struct messaging_context *msg_ctx,
3954 union spoolss_PrinterInfo **info,
3957 DEBUG(4,("enum_all_printers_info_1_local\n"));
3959 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
3960 PRINTER_ENUM_ICON8, info, count);
3963 /********************************************************************
3964 enum_all_printers_info_1_name.
3965 *********************************************************************/
3967 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
3968 struct auth_serversupplied_info *server_info,
3969 struct messaging_context *msg_ctx,
3971 union spoolss_PrinterInfo **info,
3974 const char *s = name;
3976 DEBUG(4,("enum_all_printers_info_1_name\n"));
3978 if ((name[0] == '\\') && (name[1] == '\\')) {
3982 if (!is_myname_or_ipaddr(s)) {
3983 return WERR_INVALID_NAME;
3986 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
3987 PRINTER_ENUM_ICON8, info, count);
3990 /********************************************************************
3991 enum_all_printers_info_1_network.
3992 *********************************************************************/
3994 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
3995 struct auth_serversupplied_info *server_info,
3996 struct messaging_context *msg_ctx,
3998 union spoolss_PrinterInfo **info,
4001 const char *s = name;
4003 DEBUG(4,("enum_all_printers_info_1_network\n"));
4005 /* If we respond to a enum_printers level 1 on our name with flags
4006 set to PRINTER_ENUM_REMOTE with a list of printers then these
4007 printers incorrectly appear in the APW browse list.
4008 Specifically the printers for the server appear at the workgroup
4009 level where all the other servers in the domain are
4010 listed. Windows responds to this call with a
4011 WERR_CAN_NOT_COMPLETE so we should do the same. */
4013 if (name[0] == '\\' && name[1] == '\\') {
4017 if (is_myname_or_ipaddr(s)) {
4018 return WERR_CAN_NOT_COMPLETE;
4021 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4022 PRINTER_ENUM_NAME, info, count);
4025 /********************************************************************
4026 * api_spoolss_enumprinters
4028 * called from api_spoolss_enumprinters (see this to understand)
4029 ********************************************************************/
4031 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4032 struct auth_serversupplied_info *server_info,
4033 struct messaging_context *msg_ctx,
4034 union spoolss_PrinterInfo **info,
4037 DEBUG(4,("enum_all_printers_info_2\n"));
4039 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4043 /********************************************************************
4044 * handle enumeration of printers at level 1
4045 ********************************************************************/
4047 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4048 struct auth_serversupplied_info *server_info,
4049 struct messaging_context *msg_ctx,
4052 union spoolss_PrinterInfo **info,
4055 /* Not all the flags are equals */
4057 if (flags & PRINTER_ENUM_LOCAL) {
4058 return enum_all_printers_info_1_local(mem_ctx, server_info,
4059 msg_ctx, info, count);
4062 if (flags & PRINTER_ENUM_NAME) {
4063 return enum_all_printers_info_1_name(mem_ctx, server_info,
4064 msg_ctx, name, info,
4068 if (flags & PRINTER_ENUM_NETWORK) {
4069 return enum_all_printers_info_1_network(mem_ctx, server_info,
4070 msg_ctx, name, info,
4074 return WERR_OK; /* NT4sp5 does that */
4077 /********************************************************************
4078 * handle enumeration of printers at level 2
4079 ********************************************************************/
4081 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4082 struct auth_serversupplied_info *server_info,
4083 struct messaging_context *msg_ctx,
4085 const char *servername,
4086 union spoolss_PrinterInfo **info,
4089 if (flags & PRINTER_ENUM_LOCAL) {
4090 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4094 if (flags & PRINTER_ENUM_NAME) {
4095 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4096 return WERR_INVALID_NAME;
4099 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4103 if (flags & PRINTER_ENUM_REMOTE) {
4104 return WERR_UNKNOWN_LEVEL;
4110 /********************************************************************
4111 * handle enumeration of printers at level 4
4112 ********************************************************************/
4114 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4115 struct auth_serversupplied_info *server_info,
4116 struct messaging_context *msg_ctx,
4118 const char *servername,
4119 union spoolss_PrinterInfo **info,
4122 DEBUG(4,("enum_all_printers_info_4\n"));
4124 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4125 4, flags, info, count);
4129 /********************************************************************
4130 * handle enumeration of printers at level 5
4131 ********************************************************************/
4133 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4134 struct auth_serversupplied_info *server_info,
4135 struct messaging_context *msg_ctx,
4137 const char *servername,
4138 union spoolss_PrinterInfo **info,
4141 DEBUG(4,("enum_all_printers_info_5\n"));
4143 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4144 5, flags, info, count);
4147 /****************************************************************
4148 _spoolss_EnumPrinters
4149 ****************************************************************/
4151 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4152 struct spoolss_EnumPrinters *r)
4154 const char *name = NULL;
4157 /* that's an [in out] buffer */
4159 if (!r->in.buffer && (r->in.offered != 0)) {
4160 return WERR_INVALID_PARAM;
4163 DEBUG(4,("_spoolss_EnumPrinters\n"));
4167 *r->out.info = NULL;
4171 * flags==PRINTER_ENUM_NAME
4172 * if name=="" then enumerates all printers
4173 * if name!="" then enumerate the printer
4174 * flags==PRINTER_ENUM_REMOTE
4175 * name is NULL, enumerate printers
4176 * Level 2: name!="" enumerates printers, name can't be NULL
4177 * Level 3: doesn't exist
4178 * Level 4: does a local registry lookup
4179 * Level 5: same as Level 2
4183 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4184 W_ERROR_HAVE_NO_MEMORY(name);
4187 switch (r->in.level) {
4189 result = enumprinters_level0(p->mem_ctx, p->server_info,
4190 p->msg_ctx, r->in.flags, name,
4191 r->out.info, r->out.count);
4194 result = enumprinters_level1(p->mem_ctx, p->server_info,
4195 p->msg_ctx, r->in.flags, name,
4196 r->out.info, r->out.count);
4199 result = enumprinters_level2(p->mem_ctx, p->server_info,
4200 p->msg_ctx, r->in.flags, name,
4201 r->out.info, r->out.count);
4204 result = enumprinters_level4(p->mem_ctx, p->server_info,
4205 p->msg_ctx, r->in.flags, name,
4206 r->out.info, r->out.count);
4209 result = enumprinters_level5(p->mem_ctx, p->server_info,
4210 p->msg_ctx, r->in.flags, name,
4211 r->out.info, r->out.count);
4214 return WERR_UNKNOWN_LEVEL;
4217 if (!W_ERROR_IS_OK(result)) {
4221 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4222 spoolss_EnumPrinters,
4223 *r->out.info, r->in.level,
4225 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4226 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4228 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4231 /****************************************************************
4233 ****************************************************************/
4235 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4236 struct spoolss_GetPrinter *r)
4238 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4239 struct spoolss_PrinterInfo2 *info2 = NULL;
4240 WERROR result = WERR_OK;
4241 const char *servername = NULL;
4244 /* that's an [in out] buffer */
4246 if (!r->in.buffer && (r->in.offered != 0)) {
4247 return WERR_INVALID_PARAM;
4252 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4256 if (Printer != NULL || Printer->servername != NULL) {
4257 servername = Printer->servername;
4260 result = winreg_get_printer(p->mem_ctx,
4264 lp_const_servicename(snum),
4266 if (!W_ERROR_IS_OK(result)) {
4270 switch (r->in.level) {
4272 result = construct_printer_info0(p->mem_ctx, p->server_info,
4274 &r->out.info->info0, snum);
4277 result = construct_printer_info1(p->mem_ctx, info2,
4279 &r->out.info->info1, snum);
4282 result = construct_printer_info2(p->mem_ctx, info2,
4283 &r->out.info->info2, snum);
4286 result = construct_printer_info3(p->mem_ctx, info2,
4287 &r->out.info->info3, snum);
4290 result = construct_printer_info4(p->mem_ctx, info2,
4291 &r->out.info->info4, snum);
4294 result = construct_printer_info5(p->mem_ctx, info2,
4295 &r->out.info->info5, snum);
4298 result = construct_printer_info6(p->mem_ctx, info2,
4299 &r->out.info->info6, snum);
4302 result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
4304 &r->out.info->info7, snum);
4307 result = construct_printer_info8(p->mem_ctx, info2,
4308 &r->out.info->info8, snum);
4311 result = WERR_UNKNOWN_LEVEL;
4315 if (!W_ERROR_IS_OK(result)) {
4316 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4317 r->in.level, win_errstr(result)));
4318 TALLOC_FREE(r->out.info);
4322 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4323 r->out.info, r->in.level);
4324 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4326 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4329 /********************************************************************
4330 ********************************************************************/
4332 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4334 if (in && strlen(in)) { \
4335 out = talloc_strdup(mem_ctx, in); \
4337 out = talloc_strdup(mem_ctx, ""); \
4339 W_ERROR_HAVE_NO_MEMORY(out); \
4342 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4344 if (in && strlen(in)) { \
4345 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4347 out = talloc_strdup(mem_ctx, ""); \
4349 W_ERROR_HAVE_NO_MEMORY(out); \
4352 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4353 const char **string_array,
4354 const char ***presult,
4355 const char *cservername,
4359 int i, num_strings = 0;
4360 const char **array = NULL;
4362 if (string_array == NULL) {
4363 return WERR_INVALID_PARAMETER;;
4366 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4367 const char *str = NULL;
4369 if (cservername == NULL || arch == NULL) {
4370 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4372 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4375 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4382 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4383 &array, &num_strings);
4393 /********************************************************************
4394 * fill a spoolss_DriverInfo1 struct
4395 ********************************************************************/
4397 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4398 struct spoolss_DriverInfo1 *r,
4399 const struct spoolss_DriverInfo8 *driver,
4400 const char *servername)
4402 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4403 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4408 /********************************************************************
4409 * fill a spoolss_DriverInfo2 struct
4410 ********************************************************************/
4412 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4413 struct spoolss_DriverInfo2 *r,
4414 const struct spoolss_DriverInfo8 *driver,
4415 const char *servername)
4418 const char *cservername = canon_servername(servername);
4420 r->version = driver->version;
4422 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4423 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4424 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4425 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4427 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4428 driver->architecture,
4430 driver->driver_path,
4433 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4434 driver->architecture,
4439 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4440 driver->architecture,
4442 driver->config_file,
4448 /********************************************************************
4449 * fill a spoolss_DriverInfo3 struct
4450 ********************************************************************/
4452 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4453 struct spoolss_DriverInfo3 *r,
4454 const struct spoolss_DriverInfo8 *driver,
4455 const char *servername)
4457 const char *cservername = canon_servername(servername);
4459 r->version = driver->version;
4461 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4462 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4463 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4464 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4466 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4467 driver->architecture,
4469 driver->driver_path,
4472 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4473 driver->architecture,
4478 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4479 driver->architecture,
4481 driver->config_file,
4484 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4485 driver->architecture,
4490 FILL_DRIVER_STRING(mem_ctx,
4491 driver->monitor_name,
4494 FILL_DRIVER_STRING(mem_ctx,
4495 driver->default_datatype,
4496 r->default_datatype);
4498 return string_array_from_driver_info(mem_ctx,
4499 driver->dependent_files,
4500 &r->dependent_files,
4502 driver->architecture,
4506 /********************************************************************
4507 * fill a spoolss_DriverInfo4 struct
4508 ********************************************************************/
4510 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4511 struct spoolss_DriverInfo4 *r,
4512 const struct spoolss_DriverInfo8 *driver,
4513 const char *servername)
4515 const char *cservername = canon_servername(servername);
4518 r->version = driver->version;
4520 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4521 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4522 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4523 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4525 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4526 driver->architecture,
4528 driver->driver_path,
4531 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4532 driver->architecture,
4537 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4538 driver->architecture,
4540 driver->config_file,
4543 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4544 driver->architecture,
4549 result = string_array_from_driver_info(mem_ctx,
4550 driver->dependent_files,
4551 &r->dependent_files,
4553 driver->architecture,
4555 if (!W_ERROR_IS_OK(result)) {
4559 FILL_DRIVER_STRING(mem_ctx,
4560 driver->monitor_name,
4563 FILL_DRIVER_STRING(mem_ctx,
4564 driver->default_datatype,
4565 r->default_datatype);
4568 result = string_array_from_driver_info(mem_ctx,
4569 driver->previous_names,
4576 /********************************************************************
4577 * fill a spoolss_DriverInfo5 struct
4578 ********************************************************************/
4580 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4581 struct spoolss_DriverInfo5 *r,
4582 const struct spoolss_DriverInfo8 *driver,
4583 const char *servername)
4585 const char *cservername = canon_servername(servername);
4587 r->version = driver->version;
4589 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4590 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4591 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4592 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4594 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4595 driver->architecture,
4597 driver->driver_path,
4600 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4601 driver->architecture,
4606 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4607 driver->architecture,
4609 driver->config_file,
4612 r->driver_attributes = 0;
4613 r->config_version = 0;
4614 r->driver_version = 0;
4618 /********************************************************************
4619 * fill a spoolss_DriverInfo6 struct
4620 ********************************************************************/
4622 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4623 struct spoolss_DriverInfo6 *r,
4624 const struct spoolss_DriverInfo8 *driver,
4625 const char *servername)
4627 const char *cservername = canon_servername(servername);
4630 r->version = driver->version;
4632 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4633 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4634 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4635 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4637 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4638 driver->architecture,
4640 driver->driver_path,
4643 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4644 driver->architecture,
4649 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4650 driver->architecture,
4652 driver->config_file,
4655 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4656 driver->architecture,
4661 FILL_DRIVER_STRING(mem_ctx,
4662 driver->monitor_name,
4665 FILL_DRIVER_STRING(mem_ctx,
4666 driver->default_datatype,
4667 r->default_datatype);
4669 result = string_array_from_driver_info(mem_ctx,
4670 driver->dependent_files,
4671 &r->dependent_files,
4673 driver->architecture,
4675 if (!W_ERROR_IS_OK(result)) {
4679 result = string_array_from_driver_info(mem_ctx,
4680 driver->previous_names,
4683 if (!W_ERROR_IS_OK(result)) {
4687 r->driver_date = driver->driver_date;
4688 r->driver_version = driver->driver_version;
4690 FILL_DRIVER_STRING(mem_ctx,
4691 driver->manufacturer_name,
4692 r->manufacturer_name);
4693 FILL_DRIVER_STRING(mem_ctx,
4694 driver->manufacturer_url,
4695 r->manufacturer_url);
4696 FILL_DRIVER_STRING(mem_ctx,
4697 driver->hardware_id,
4699 FILL_DRIVER_STRING(mem_ctx,
4706 /********************************************************************
4707 * fill a spoolss_DriverInfo8 struct
4708 ********************************************************************/
4710 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
4711 struct spoolss_DriverInfo8 *r,
4712 const struct spoolss_DriverInfo8 *driver,
4713 const char *servername)
4715 const char *cservername = canon_servername(servername);
4718 r->version = driver->version;
4720 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4721 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4722 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4723 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4725 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4726 driver->architecture,
4728 driver->driver_path,
4731 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4732 driver->architecture,
4737 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4738 driver->architecture,
4740 driver->config_file,
4743 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4744 driver->architecture,
4749 FILL_DRIVER_STRING(mem_ctx,
4750 driver->monitor_name,
4753 FILL_DRIVER_STRING(mem_ctx,
4754 driver->default_datatype,
4755 r->default_datatype);
4757 result = string_array_from_driver_info(mem_ctx,
4758 driver->dependent_files,
4759 &r->dependent_files,
4761 driver->architecture,
4763 if (!W_ERROR_IS_OK(result)) {
4767 result = string_array_from_driver_info(mem_ctx,
4768 driver->previous_names,
4771 if (!W_ERROR_IS_OK(result)) {
4775 r->driver_date = driver->driver_date;
4776 r->driver_version = driver->driver_version;
4778 FILL_DRIVER_STRING(mem_ctx,
4779 driver->manufacturer_name,
4780 r->manufacturer_name);
4781 FILL_DRIVER_STRING(mem_ctx,
4782 driver->manufacturer_url,
4783 r->manufacturer_url);
4784 FILL_DRIVER_STRING(mem_ctx,
4785 driver->hardware_id,
4787 FILL_DRIVER_STRING(mem_ctx,
4791 FILL_DRIVER_STRING(mem_ctx,
4792 driver->print_processor,
4793 r->print_processor);
4794 FILL_DRIVER_STRING(mem_ctx,
4795 driver->vendor_setup,
4798 result = string_array_from_driver_info(mem_ctx,
4799 driver->color_profiles,
4802 if (!W_ERROR_IS_OK(result)) {
4806 FILL_DRIVER_STRING(mem_ctx,
4810 r->printer_driver_attributes = driver->printer_driver_attributes;
4812 result = string_array_from_driver_info(mem_ctx,
4813 driver->core_driver_dependencies,
4814 &r->core_driver_dependencies,
4816 if (!W_ERROR_IS_OK(result)) {
4820 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
4821 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
4826 #if 0 /* disabled until marshalling issues are resolved - gd */
4827 /********************************************************************
4828 ********************************************************************/
4830 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
4831 struct spoolss_DriverFileInfo *r,
4832 const char *cservername,
4833 const char *file_name,
4834 enum spoolss_DriverFileType file_type,
4835 uint32_t file_version)
4837 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
4838 cservername, file_name);
4839 W_ERROR_HAVE_NO_MEMORY(r->file_name);
4840 r->file_type = file_type;
4841 r->file_version = file_version;
4846 /********************************************************************
4847 ********************************************************************/
4849 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
4850 const struct spoolss_DriverInfo8 *driver,
4851 const char *cservername,
4852 struct spoolss_DriverFileInfo **info_p,
4855 struct spoolss_DriverFileInfo *info = NULL;
4863 if (strlen(driver->driver_path)) {
4864 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4865 struct spoolss_DriverFileInfo,
4867 W_ERROR_HAVE_NO_MEMORY(info);
4868 result = fill_spoolss_DriverFileInfo(info,
4871 driver->driver_path,
4872 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
4874 W_ERROR_NOT_OK_RETURN(result);
4878 if (strlen(driver->config_file)) {
4879 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4880 struct spoolss_DriverFileInfo,
4882 W_ERROR_HAVE_NO_MEMORY(info);
4883 result = fill_spoolss_DriverFileInfo(info,
4886 driver->config_file,
4887 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
4889 W_ERROR_NOT_OK_RETURN(result);
4893 if (strlen(driver->data_file)) {
4894 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4895 struct spoolss_DriverFileInfo,
4897 W_ERROR_HAVE_NO_MEMORY(info);
4898 result = fill_spoolss_DriverFileInfo(info,
4902 SPOOLSS_DRIVER_FILE_TYPE_DATA,
4904 W_ERROR_NOT_OK_RETURN(result);
4908 if (strlen(driver->help_file)) {
4909 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4910 struct spoolss_DriverFileInfo,
4912 W_ERROR_HAVE_NO_MEMORY(info);
4913 result = fill_spoolss_DriverFileInfo(info,
4917 SPOOLSS_DRIVER_FILE_TYPE_HELP,
4919 W_ERROR_NOT_OK_RETURN(result);
4923 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
4924 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4925 struct spoolss_DriverFileInfo,
4927 W_ERROR_HAVE_NO_MEMORY(info);
4928 result = fill_spoolss_DriverFileInfo(info,
4931 driver->dependent_files[i],
4932 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
4934 W_ERROR_NOT_OK_RETURN(result);
4944 /********************************************************************
4945 * fill a spoolss_DriverInfo101 struct
4946 ********************************************************************/
4948 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
4949 struct spoolss_DriverInfo101 *r,
4950 const struct spoolss_DriverInfo8 *driver,
4951 const char *servername)
4953 const char *cservername = canon_servername(servername);
4956 r->version = driver->version;
4958 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4959 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4960 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4961 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4963 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
4967 if (!W_ERROR_IS_OK(result)) {
4971 FILL_DRIVER_STRING(mem_ctx,
4972 driver->monitor_name,
4975 FILL_DRIVER_STRING(mem_ctx,
4976 driver->default_datatype,
4977 r->default_datatype);
4979 result = string_array_from_driver_info(mem_ctx,
4980 driver->previous_names,
4983 if (!W_ERROR_IS_OK(result)) {
4987 r->driver_date = driver->driver_date;
4988 r->driver_version = driver->driver_version;
4990 FILL_DRIVER_STRING(mem_ctx,
4991 driver->manufacturer_name,
4992 r->manufacturer_name);
4993 FILL_DRIVER_STRING(mem_ctx,
4994 driver->manufacturer_url,
4995 r->manufacturer_url);
4996 FILL_DRIVER_STRING(mem_ctx,
4997 driver->hardware_id,
4999 FILL_DRIVER_STRING(mem_ctx,
5006 /********************************************************************
5007 ********************************************************************/
5009 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5010 struct auth_serversupplied_info *server_info,
5011 struct messaging_context *msg_ctx,
5013 union spoolss_DriverInfo *r,
5015 const char *servername,
5016 const char *architecture,
5019 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5020 struct spoolss_DriverInfo8 *driver;
5023 result = winreg_get_printer(mem_ctx,
5027 lp_const_servicename(snum),
5030 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5031 win_errstr(result)));
5033 if (!W_ERROR_IS_OK(result)) {
5034 return WERR_INVALID_PRINTER_NAME;
5037 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5039 pinfo2->drivername, version, &driver);
5041 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5042 win_errstr(result)));
5044 if (!W_ERROR_IS_OK(result)) {
5046 * Is this a W2k client ?
5050 talloc_free(pinfo2);
5051 return WERR_UNKNOWN_PRINTER_DRIVER;
5054 /* Yes - try again with a WinNT driver. */
5056 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5060 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5061 win_errstr(result)));
5062 if (!W_ERROR_IS_OK(result)) {
5063 talloc_free(pinfo2);
5064 return WERR_UNKNOWN_PRINTER_DRIVER;
5070 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5073 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5076 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5079 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5082 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5085 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5088 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5090 #if 0 /* disabled until marshalling issues are resolved - gd */
5092 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5096 result = WERR_UNKNOWN_LEVEL;
5100 talloc_free(pinfo2);
5101 talloc_free(driver);
5106 /****************************************************************
5107 _spoolss_GetPrinterDriver2
5108 ****************************************************************/
5110 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5111 struct spoolss_GetPrinterDriver2 *r)
5113 Printer_entry *printer;
5118 /* that's an [in out] buffer */
5120 if (!r->in.buffer && (r->in.offered != 0)) {
5121 return WERR_INVALID_PARAM;
5124 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5126 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5127 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5128 return WERR_INVALID_PRINTER_NAME;
5132 *r->out.server_major_version = 0;
5133 *r->out.server_minor_version = 0;
5135 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5139 result = construct_printer_driver_info_level(p->mem_ctx,
5142 r->in.level, r->out.info,
5143 snum, printer->servername,
5145 r->in.client_major_version);
5146 if (!W_ERROR_IS_OK(result)) {
5147 TALLOC_FREE(r->out.info);
5151 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5152 r->out.info, r->in.level);
5153 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5155 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5159 /****************************************************************
5160 _spoolss_StartPagePrinter
5161 ****************************************************************/
5163 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5164 struct spoolss_StartPagePrinter *r)
5166 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5169 DEBUG(3,("_spoolss_StartPagePrinter: "
5170 "Error in startpageprinter printer handle\n"));
5174 Printer->page_started = true;
5178 /****************************************************************
5179 _spoolss_EndPagePrinter
5180 ****************************************************************/
5182 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5183 struct spoolss_EndPagePrinter *r)
5187 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5190 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5191 OUR_HANDLE(r->in.handle)));
5195 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5198 Printer->page_started = false;
5199 print_job_endpage(snum, Printer->jobid);
5204 /****************************************************************
5205 _spoolss_StartDocPrinter
5206 ****************************************************************/
5208 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5209 struct spoolss_StartDocPrinter *r)
5211 struct spoolss_DocumentInfo1 *info_1;
5213 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5217 DEBUG(2,("_spoolss_StartDocPrinter: "
5218 "Invalid handle (%s:%u:%u)\n",
5219 OUR_HANDLE(r->in.handle)));
5223 if (Printer->jobid) {
5224 DEBUG(2, ("_spoolss_StartDocPrinter: "
5225 "StartDocPrinter called twice! "
5226 "(existing jobid = %d)\n", Printer->jobid));
5227 return WERR_INVALID_HANDLE;
5230 if (r->in.level != 1) {
5231 return WERR_UNKNOWN_LEVEL;
5234 info_1 = r->in.info.info1;
5237 * a nice thing with NT is it doesn't listen to what you tell it.
5238 * when asked to send _only_ RAW datas, it tries to send datas
5241 * So I add checks like in NT Server ...
5244 if (info_1->datatype) {
5245 if (strcmp(info_1->datatype, "RAW") != 0) {
5247 return WERR_INVALID_DATATYPE;
5251 /* get the share number of the printer */
5252 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5256 werr = print_job_start(p->server_info, p->msg_ctx, snum,
5257 info_1->document_name, info_1->output_file,
5258 Printer->devmode, &Printer->jobid);
5260 /* An error occured in print_job_start() so return an appropriate
5263 if (!W_ERROR_IS_OK(werr)) {
5267 Printer->document_started = true;
5268 *r->out.job_id = Printer->jobid;
5273 /****************************************************************
5274 _spoolss_EndDocPrinter
5275 ****************************************************************/
5277 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5278 struct spoolss_EndDocPrinter *r)
5280 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5285 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5286 OUR_HANDLE(r->in.handle)));
5290 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5294 Printer->document_started = false;
5295 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5296 if (!NT_STATUS_IS_OK(status)) {
5297 DEBUG(2, ("_spoolss_EndDocPrinter: "
5298 "print_job_end failed [%s]\n",
5299 nt_errstr(status)));
5303 return ntstatus_to_werror(status);
5306 /****************************************************************
5307 _spoolss_WritePrinter
5308 ****************************************************************/
5310 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5311 struct spoolss_WritePrinter *r)
5313 ssize_t buffer_written;
5315 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5318 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5319 OUR_HANDLE(r->in.handle)));
5320 *r->out.num_written = r->in._data_size;
5324 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5327 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5328 buffer_written = print_job_write(snum, Printer->jobid,
5329 (const char *)r->in.data.data,
5331 (size_t)r->in._data_size);
5332 if (buffer_written == (ssize_t)-1) {
5333 *r->out.num_written = 0;
5334 if (errno == ENOSPC)
5335 return WERR_NO_SPOOL_SPACE;
5337 return WERR_ACCESS_DENIED;
5340 *r->out.num_written = r->in._data_size;
5345 /********************************************************************
5346 * api_spoolss_getprinter
5347 * called from the spoolss dispatcher
5349 ********************************************************************/
5351 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5352 struct pipes_struct *p)
5355 WERROR errcode = WERR_BADFUNC;
5356 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5359 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5360 OUR_HANDLE(handle)));
5364 if (!get_printer_snum(p, handle, &snum, NULL))
5368 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5369 errcode = print_queue_pause(p->server_info, p->msg_ctx, snum);
5371 case SPOOLSS_PRINTER_CONTROL_RESUME:
5372 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5373 errcode = print_queue_resume(p->server_info, p->msg_ctx, snum);
5375 case SPOOLSS_PRINTER_CONTROL_PURGE:
5376 errcode = print_queue_purge(p->server_info, p->msg_ctx, snum);
5379 return WERR_UNKNOWN_LEVEL;
5386 /****************************************************************
5387 _spoolss_AbortPrinter
5388 * From MSDN: "Deletes printer's spool file if printer is configured
5390 ****************************************************************/
5392 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5393 struct spoolss_AbortPrinter *r)
5395 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5397 WERROR errcode = WERR_OK;
5400 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5401 OUR_HANDLE(r->in.handle)));
5405 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5408 if (!Printer->document_started) {
5409 return WERR_SPL_NO_STARTDOC;
5412 errcode = print_job_delete(p->server_info, p->msg_ctx, snum,
5418 /********************************************************************
5419 * called by spoolss_api_setprinter
5420 * when updating a printer description
5421 ********************************************************************/
5423 static WERROR update_printer_sec(struct policy_handle *handle,
5424 struct pipes_struct *p,
5425 struct sec_desc_buf *secdesc_ctr)
5427 struct spoolss_security_descriptor *new_secdesc = NULL;
5428 struct spoolss_security_descriptor *old_secdesc = NULL;
5429 const char *printer;
5433 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5435 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5436 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5437 OUR_HANDLE(handle)));
5439 result = WERR_BADFID;
5443 if (secdesc_ctr == NULL) {
5444 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5445 result = WERR_INVALID_PARAM;
5448 printer = lp_const_servicename(snum);
5450 /* Check the user has permissions to change the security
5451 descriptor. By experimentation with two NT machines, the user
5452 requires Full Access to the printer to change security
5455 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5456 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5457 result = WERR_ACCESS_DENIED;
5461 /* NT seems to like setting the security descriptor even though
5462 nothing may have actually changed. */
5463 result = winreg_get_printer_secdesc(p->mem_ctx,
5468 if (!W_ERROR_IS_OK(result)) {
5469 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5470 result = WERR_BADFID;
5474 if (DEBUGLEVEL >= 10) {
5475 struct security_acl *the_acl;
5478 the_acl = old_secdesc->dacl;
5479 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5480 printer, the_acl->num_aces));
5482 for (i = 0; i < the_acl->num_aces; i++) {
5483 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5484 &the_acl->aces[i].trustee),
5485 the_acl->aces[i].access_mask));
5488 the_acl = secdesc_ctr->sd->dacl;
5491 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5492 printer, the_acl->num_aces));
5494 for (i = 0; i < the_acl->num_aces; i++) {
5495 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5496 &the_acl->aces[i].trustee),
5497 the_acl->aces[i].access_mask));
5500 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5504 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
5505 if (new_secdesc == NULL) {
5506 result = WERR_NOMEM;
5510 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
5515 result = winreg_set_printer_secdesc(p->mem_ctx,
5525 /********************************************************************
5526 Canonicalize printer info from a client
5527 ********************************************************************/
5529 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
5530 struct spoolss_SetPrinterInfo2 *info2,
5533 fstring printername;
5536 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5537 "portname=%s drivername=%s comment=%s location=%s\n",
5538 info2->servername, info2->printername, info2->sharename,
5539 info2->portname, info2->drivername, info2->comment,
5542 /* we force some elements to "correct" values */
5543 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
5544 if (info2->servername == NULL) {
5547 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
5548 if (info2->sharename == NULL) {
5552 /* check to see if we allow printername != sharename */
5553 if (lp_force_printername(snum)) {
5554 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5555 global_myname(), info2->sharename);
5557 /* make sure printername is in \\server\printername format */
5558 fstrcpy(printername, info2->printername);
5560 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5561 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5565 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5566 global_myname(), p);
5568 if (info2->printername == NULL) {
5572 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5573 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5578 /****************************************************************************
5579 ****************************************************************************/
5581 static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri)
5583 char *cmd = lp_addport_cmd();
5584 char *command = NULL;
5586 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5587 bool is_print_op = false;
5590 return WERR_ACCESS_DENIED;
5593 command = talloc_asprintf(ctx,
5594 "%s \"%s\" \"%s\"", cmd, portname, uri );
5600 is_print_op = user_has_privileges( token, &se_printop );
5602 DEBUG(10,("Running [%s]\n", command));
5604 /********* BEGIN SePrintOperatorPrivilege **********/
5609 ret = smbrun(command, NULL);
5614 /********* END SePrintOperatorPrivilege **********/
5616 DEBUGADD(10,("returned [%d]\n", ret));
5618 TALLOC_FREE(command);
5621 return WERR_ACCESS_DENIED;
5627 /****************************************************************************
5628 ****************************************************************************/
5630 static bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
5631 struct spoolss_SetPrinterInfo2 *info2,
5632 const char *remote_machine,
5633 struct messaging_context *msg_ctx)
5635 char *cmd = lp_addprinter_cmd();
5637 char *command = NULL;
5641 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5642 bool is_print_op = false;
5644 if (!remote_machine) {
5648 command = talloc_asprintf(ctx,
5649 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5650 cmd, info2->printername, info2->sharename,
5651 info2->portname, info2->drivername,
5652 info2->location, info2->comment, remote_machine);
5658 is_print_op = user_has_privileges( token, &se_printop );
5660 DEBUG(10,("Running [%s]\n", command));
5662 /********* BEGIN SePrintOperatorPrivilege **********/
5667 if ( (ret = smbrun(command, &fd)) == 0 ) {
5668 /* Tell everyone we updated smb.conf. */
5669 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5675 /********* END SePrintOperatorPrivilege **********/
5677 DEBUGADD(10,("returned [%d]\n", ret));
5679 TALLOC_FREE(command);
5687 /* reload our services immediately */
5689 reload_services(msg_ctx, false);
5693 /* Get lines and convert them back to dos-codepage */
5694 qlines = fd_lines_load(fd, &numlines, 0, NULL);
5695 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
5698 /* Set the portname to what the script says the portname should be. */
5699 /* but don't require anything to be return from the script exit a good error code */
5702 /* Set the portname to what the script says the portname should be. */
5703 info2->portname = talloc_strdup(ctx, qlines[0]);
5704 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
5707 TALLOC_FREE(qlines);
5711 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
5712 struct auth_serversupplied_info *server_info,
5713 struct messaging_context *msg_ctx,
5715 struct spoolss_SetPrinterInfo2 *printer,
5716 struct spoolss_PrinterInfo2 *old_printer)
5718 bool force_update = (old_printer == NULL);
5719 const char *dnsdomname;
5720 const char *longname;
5721 const char *uncname;
5722 const char *spooling;
5724 WERROR result = WERR_OK;
5726 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
5727 push_reg_sz(mem_ctx, &buffer, printer->drivername);
5728 winreg_set_printer_dataex(mem_ctx,
5732 SPOOL_DSSPOOLER_KEY,
5733 SPOOL_REG_DRIVERNAME,
5738 if (!force_update) {
5739 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
5740 printer->drivername));
5742 notify_printer_driver(server_event_context(), msg_ctx,
5743 snum, printer->drivername);
5747 if (force_update || !strequal(printer->comment, old_printer->comment)) {
5748 push_reg_sz(mem_ctx, &buffer, printer->comment);
5749 winreg_set_printer_dataex(mem_ctx,
5753 SPOOL_DSSPOOLER_KEY,
5754 SPOOL_REG_DESCRIPTION,
5759 if (!force_update) {
5760 notify_printer_comment(server_event_context(), msg_ctx,
5761 snum, printer->comment);
5765 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
5766 push_reg_sz(mem_ctx, &buffer, printer->sharename);
5767 winreg_set_printer_dataex(mem_ctx,
5771 SPOOL_DSSPOOLER_KEY,
5772 SPOOL_REG_PRINTSHARENAME,
5777 if (!force_update) {
5778 notify_printer_sharename(server_event_context(),
5780 snum, printer->sharename);
5784 if (force_update || !strequal(printer->printername, old_printer->printername)) {
5787 p = strrchr(printer->printername, '\\' );
5791 p = printer->printername;
5794 push_reg_sz(mem_ctx, &buffer, p);
5795 winreg_set_printer_dataex(mem_ctx,
5799 SPOOL_DSSPOOLER_KEY,
5800 SPOOL_REG_PRINTERNAME,
5805 if (!force_update) {
5806 notify_printer_printername(snum, p);
5810 if (force_update || !strequal(printer->portname, old_printer->portname)) {
5811 push_reg_sz(mem_ctx, &buffer, printer->portname);
5812 winreg_set_printer_dataex(mem_ctx,
5816 SPOOL_DSSPOOLER_KEY,
5822 if (!force_update) {
5823 notify_printer_port(snum, printer->portname);
5827 if (force_update || !strequal(printer->location, old_printer->location)) {
5828 push_reg_sz(mem_ctx, &buffer, printer->location);
5829 winreg_set_printer_dataex(mem_ctx,
5833 SPOOL_DSSPOOLER_KEY,
5839 if (!force_update) {
5840 notify_printer_location(snum, printer->location);
5844 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
5845 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
5846 winreg_set_printer_dataex(mem_ctx,
5850 SPOOL_DSSPOOLER_KEY,
5851 SPOOL_REG_PRINTSEPARATORFILE,
5856 if (!force_update) {
5857 notify_printer_location(snum, printer->location);
5861 if (force_update || printer->starttime != old_printer->starttime) {
5862 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5863 SIVAL(buffer.data, 0, printer->starttime);
5864 winreg_set_printer_dataex(mem_ctx,
5868 SPOOL_DSSPOOLER_KEY,
5869 SPOOL_REG_PRINTSTARTTIME,
5875 if (force_update || printer->untiltime != old_printer->untiltime) {
5876 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5877 SIVAL(buffer.data, 0, printer->untiltime);
5878 winreg_set_printer_dataex(mem_ctx,
5882 SPOOL_DSSPOOLER_KEY,
5883 SPOOL_REG_PRINTENDTIME,
5889 if (force_update || printer->priority != old_printer->priority) {
5890 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5891 SIVAL(buffer.data, 0, printer->priority);
5892 winreg_set_printer_dataex(mem_ctx,
5896 SPOOL_DSSPOOLER_KEY,
5903 if (force_update || printer->attributes != old_printer->attributes) {
5904 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5905 SIVAL(buffer.data, 0, (printer->attributes &
5906 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
5907 winreg_set_printer_dataex(mem_ctx,
5911 SPOOL_DSSPOOLER_KEY,
5912 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
5917 switch (printer->attributes & 0x3) {
5919 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
5922 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
5925 spooling = SPOOL_REGVAL_PRINTDIRECT;
5928 spooling = "unknown";
5930 push_reg_sz(mem_ctx, &buffer, spooling);
5931 winreg_set_printer_dataex(mem_ctx,
5935 SPOOL_DSSPOOLER_KEY,
5936 SPOOL_REG_PRINTSPOOLING,
5942 push_reg_sz(mem_ctx, &buffer, global_myname());
5943 winreg_set_printer_dataex(mem_ctx,
5947 SPOOL_DSSPOOLER_KEY,
5948 SPOOL_REG_SHORTSERVERNAME,
5953 dnsdomname = get_mydnsfullname();
5954 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
5955 longname = talloc_strdup(mem_ctx, dnsdomname);
5957 longname = talloc_strdup(mem_ctx, global_myname());
5959 if (longname == NULL) {
5960 result = WERR_NOMEM;
5964 push_reg_sz(mem_ctx, &buffer, longname);
5965 winreg_set_printer_dataex(mem_ctx,
5969 SPOOL_DSSPOOLER_KEY,
5970 SPOOL_REG_SERVERNAME,
5975 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5976 global_myname(), printer->sharename);
5977 push_reg_sz(mem_ctx, &buffer, uncname);
5978 winreg_set_printer_dataex(mem_ctx,
5982 SPOOL_DSSPOOLER_KEY,
5992 /********************************************************************
5993 * Called by spoolss_api_setprinter
5994 * when updating a printer description.
5995 ********************************************************************/
5997 static WERROR update_printer(struct pipes_struct *p,
5998 struct policy_handle *handle,
5999 struct spoolss_SetPrinterInfoCtr *info_ctr,
6000 struct spoolss_DeviceMode *devmode)
6002 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6003 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6004 struct spoolss_PrinterInfo2 *old_printer;
6005 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6006 const char *servername = NULL;
6008 WERROR result = WERR_OK;
6009 TALLOC_CTX *tmp_ctx;
6011 DEBUG(8,("update_printer\n"));
6013 tmp_ctx = talloc_new(p->mem_ctx);
6014 if (tmp_ctx == NULL) {
6019 result = WERR_BADFID;
6023 if (!get_printer_snum(p, handle, &snum, NULL)) {
6024 result = WERR_BADFID;
6028 if (Printer != NULL || Printer->servername != NULL) {
6029 servername = Printer->servername;
6032 result = winreg_get_printer(tmp_ctx,
6036 lp_const_servicename(snum),
6038 if (!W_ERROR_IS_OK(result)) {
6039 result = WERR_BADFID;
6043 /* Do sanity check on the requested changes for Samba */
6044 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6045 result = WERR_INVALID_PARAM;
6049 /* FIXME!!! If the driver has changed we really should verify that
6050 it is installed before doing much else --jerry */
6052 /* Check calling user has permission to update printer description */
6053 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6054 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6055 result = WERR_ACCESS_DENIED;
6059 /* Call addprinter hook */
6060 /* Check changes to see if this is really needed */
6062 if (*lp_addprinter_cmd() &&
6063 (!strequal(printer->drivername, old_printer->drivername) ||
6064 !strequal(printer->comment, old_printer->comment) ||
6065 !strequal(printer->portname, old_printer->portname) ||
6066 !strequal(printer->location, old_printer->location)) )
6068 /* add_printer_hook() will call reload_services() */
6069 if (!add_printer_hook(tmp_ctx, p->server_info->ptok,
6070 printer, p->client_address,
6072 result = WERR_ACCESS_DENIED;
6077 update_dsspooler(tmp_ctx,
6084 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6086 if (devmode == NULL) {
6087 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6089 result = winreg_update_printer(tmp_ctx,
6099 talloc_free(tmp_ctx);
6104 /****************************************************************************
6105 ****************************************************************************/
6106 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6107 struct policy_handle *handle,
6108 struct spoolss_SetPrinterInfo7 *info7)
6111 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6114 Printer_entry *Printer;
6116 if ( lp_security() != SEC_ADS ) {
6117 return WERR_UNKNOWN_LEVEL;
6120 Printer = find_printer_index_by_hnd(p, handle);
6122 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6127 if (!get_printer_snum(p, handle, &snum, NULL))
6130 result = winreg_get_printer(p->mem_ctx, p->server_info, p->msg_ctx,
6131 Printer->servername,
6132 lp_servicename(snum), &pinfo2);
6133 if (!W_ERROR_IS_OK(result)) {
6137 nt_printer_publish(pinfo2, p->server_info, p->msg_ctx, pinfo2,
6140 TALLOC_FREE(pinfo2);
6143 return WERR_UNKNOWN_LEVEL;
6147 /********************************************************************
6148 ********************************************************************/
6150 static WERROR update_printer_devmode(struct pipes_struct *p,
6151 struct policy_handle *handle,
6152 struct spoolss_DeviceMode *devmode)
6155 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6156 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6158 DEBUG(8,("update_printer_devmode\n"));
6164 if (!get_printer_snum(p, handle, &snum, NULL)) {
6168 /* Check calling user has permission to update printer description */
6169 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6170 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6171 return WERR_ACCESS_DENIED;
6174 return winreg_update_printer(p->mem_ctx,
6177 lp_const_servicename(snum),
6185 /****************************************************************
6187 ****************************************************************/
6189 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6190 struct spoolss_SetPrinter *r)
6194 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6197 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6198 OUR_HANDLE(r->in.handle)));
6202 /* check the level */
6203 switch (r->in.info_ctr->level) {
6205 return control_printer(r->in.handle, r->in.command, p);
6207 result = update_printer(p, r->in.handle,
6209 r->in.devmode_ctr->devmode);
6210 if (!W_ERROR_IS_OK(result))
6212 if (r->in.secdesc_ctr->sd)
6213 result = update_printer_sec(r->in.handle, p,
6217 return update_printer_sec(r->in.handle, p,
6220 return publish_or_unpublish_printer(p, r->in.handle,
6221 r->in.info_ctr->info.info7);
6223 return update_printer_devmode(p, r->in.handle,
6224 r->in.devmode_ctr->devmode);
6226 return WERR_UNKNOWN_LEVEL;
6230 /****************************************************************
6231 _spoolss_FindClosePrinterNotify
6232 ****************************************************************/
6234 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6235 struct spoolss_FindClosePrinterNotify *r)
6237 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6240 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6241 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6245 if (Printer->notify.client_connected == true) {
6248 if ( Printer->printer_type == SPLHND_SERVER)
6250 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6251 !get_printer_snum(p, r->in.handle, &snum, NULL) )
6254 srv_spoolss_replycloseprinter(
6255 snum, &Printer->notify.client_hnd, p->msg_ctx);
6258 Printer->notify.flags=0;
6259 Printer->notify.options=0;
6260 Printer->notify.localmachine[0]='\0';
6261 Printer->notify.printerlocal=0;
6262 TALLOC_FREE(Printer->notify.option);
6263 Printer->notify.client_connected = false;
6268 /****************************************************************
6270 ****************************************************************/
6272 WERROR _spoolss_AddJob(struct pipes_struct *p,
6273 struct spoolss_AddJob *r)
6275 if (!r->in.buffer && (r->in.offered != 0)) {
6276 return WERR_INVALID_PARAM;
6279 /* this is what a NT server returns for AddJob. AddJob must fail on
6280 * non-local printers */
6282 if (r->in.level != 1) {
6283 return WERR_UNKNOWN_LEVEL;
6286 return WERR_INVALID_PARAM;
6289 /****************************************************************************
6291 ****************************************************************************/
6293 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6294 struct spoolss_JobInfo1 *r,
6295 const print_queue_struct *queue,
6296 int position, int snum,
6297 struct spoolss_PrinterInfo2 *pinfo2)
6301 t = gmtime(&queue->time);
6303 r->job_id = queue->job;
6305 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6306 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6307 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6308 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6309 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6310 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6311 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6312 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6313 r->data_type = talloc_strdup(mem_ctx, "RAW");
6314 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6315 r->text_status = talloc_strdup(mem_ctx, "");
6316 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6318 r->status = nt_printj_status(queue->status);
6319 r->priority = queue->priority;
6320 r->position = position;
6321 r->total_pages = queue->page_count;
6322 r->pages_printed = 0; /* ??? */
6324 init_systemtime(&r->submitted, t);
6329 /****************************************************************************
6331 ****************************************************************************/
6333 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6334 struct spoolss_JobInfo2 *r,
6335 const print_queue_struct *queue,
6336 int position, int snum,
6337 struct spoolss_PrinterInfo2 *pinfo2,
6338 struct spoolss_DeviceMode *devmode)
6342 t = gmtime(&queue->time);
6344 r->job_id = queue->job;
6346 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6347 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6348 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6349 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6350 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6351 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6352 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6353 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6354 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6355 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6356 r->data_type = talloc_strdup(mem_ctx, "RAW");
6357 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6358 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6359 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6360 r->parameters = talloc_strdup(mem_ctx, "");
6361 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6362 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6363 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6365 r->devmode = devmode;
6367 r->text_status = talloc_strdup(mem_ctx, "");
6368 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6372 r->status = nt_printj_status(queue->status);
6373 r->priority = queue->priority;
6374 r->position = position;
6377 r->total_pages = queue->page_count;
6378 r->size = queue->size;
6379 init_systemtime(&r->submitted, t);
6381 r->pages_printed = 0; /* ??? */
6386 /****************************************************************************
6388 ****************************************************************************/
6390 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6391 struct spoolss_JobInfo3 *r,
6392 const print_queue_struct *queue,
6393 const print_queue_struct *next_queue,
6394 int position, int snum,
6395 struct spoolss_PrinterInfo2 *pinfo2)
6397 r->job_id = queue->job;
6400 r->next_job_id = next_queue->job;
6407 /****************************************************************************
6408 Enumjobs at level 1.
6409 ****************************************************************************/
6411 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6412 const print_queue_struct *queue,
6413 uint32_t num_queues, int snum,
6414 struct spoolss_PrinterInfo2 *pinfo2,
6415 union spoolss_JobInfo **info_p,
6418 union spoolss_JobInfo *info;
6420 WERROR result = WERR_OK;
6422 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6423 W_ERROR_HAVE_NO_MEMORY(info);
6425 *count = num_queues;
6427 for (i=0; i<*count; i++) {
6428 result = fill_job_info1(info,
6434 if (!W_ERROR_IS_OK(result)) {
6440 if (!W_ERROR_IS_OK(result)) {
6451 /****************************************************************************
6452 Enumjobs at level 2.
6453 ****************************************************************************/
6455 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6456 const print_queue_struct *queue,
6457 uint32_t num_queues, int snum,
6458 struct spoolss_PrinterInfo2 *pinfo2,
6459 union spoolss_JobInfo **info_p,
6462 union spoolss_JobInfo *info;
6464 WERROR result = WERR_OK;
6466 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6467 W_ERROR_HAVE_NO_MEMORY(info);
6469 *count = num_queues;
6471 for (i=0; i<*count; i++) {
6472 struct spoolss_DeviceMode *devmode;
6474 result = spoolss_create_default_devmode(info,
6475 pinfo2->printername,
6477 if (!W_ERROR_IS_OK(result)) {
6478 DEBUG(3, ("Can't proceed w/o a devmode!"));
6482 result = fill_job_info2(info,
6489 if (!W_ERROR_IS_OK(result)) {
6495 if (!W_ERROR_IS_OK(result)) {
6506 /****************************************************************************
6507 Enumjobs at level 3.
6508 ****************************************************************************/
6510 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6511 const print_queue_struct *queue,
6512 uint32_t num_queues, int snum,
6513 struct spoolss_PrinterInfo2 *pinfo2,
6514 union spoolss_JobInfo **info_p,
6517 union spoolss_JobInfo *info;
6519 WERROR result = WERR_OK;
6521 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6522 W_ERROR_HAVE_NO_MEMORY(info);
6524 *count = num_queues;
6526 for (i=0; i<*count; i++) {
6527 const print_queue_struct *next_queue = NULL;
6530 next_queue = &queue[i+1];
6533 result = fill_job_info3(info,
6540 if (!W_ERROR_IS_OK(result)) {
6546 if (!W_ERROR_IS_OK(result)) {
6557 /****************************************************************
6559 ****************************************************************/
6561 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
6562 struct spoolss_EnumJobs *r)
6565 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6567 print_status_struct prt_status;
6568 print_queue_struct *queue = NULL;
6571 /* that's an [in out] buffer */
6573 if (!r->in.buffer && (r->in.offered != 0)) {
6574 return WERR_INVALID_PARAM;
6577 DEBUG(4,("_spoolss_EnumJobs\n"));
6581 *r->out.info = NULL;
6583 /* lookup the printer snum and tdb entry */
6585 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6589 result = winreg_get_printer(p->mem_ctx, p->server_info, p->msg_ctx,
6590 NULL, lp_servicename(snum), &pinfo2);
6591 if (!W_ERROR_IS_OK(result)) {
6595 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
6596 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6597 count, prt_status.status, prt_status.message));
6601 TALLOC_FREE(pinfo2);
6605 switch (r->in.level) {
6607 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6608 pinfo2, r->out.info, r->out.count);
6611 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6612 pinfo2, r->out.info, r->out.count);
6615 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
6616 pinfo2, r->out.info, r->out.count);
6619 result = WERR_UNKNOWN_LEVEL;
6624 TALLOC_FREE(pinfo2);
6626 if (!W_ERROR_IS_OK(result)) {
6630 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6632 *r->out.info, r->in.level,
6634 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6635 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6637 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6640 /****************************************************************
6641 _spoolss_ScheduleJob
6642 ****************************************************************/
6644 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
6645 struct spoolss_ScheduleJob *r)
6650 /****************************************************************
6651 ****************************************************************/
6653 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
6654 const char *printer_name,
6656 struct spoolss_SetJobInfo1 *r)
6660 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
6664 if (strequal(old_doc_name, r->document_name)) {
6668 if (!print_job_set_name(printer_name, job_id, r->document_name)) {
6675 /****************************************************************
6677 ****************************************************************/
6679 WERROR _spoolss_SetJob(struct pipes_struct *p,
6680 struct spoolss_SetJob *r)
6683 WERROR errcode = WERR_BADFUNC;
6685 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6689 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6690 return WERR_INVALID_PRINTER_NAME;
6693 switch (r->in.command) {
6694 case SPOOLSS_JOB_CONTROL_CANCEL:
6695 case SPOOLSS_JOB_CONTROL_DELETE:
6696 errcode = print_job_delete(p->server_info, p->msg_ctx,
6697 snum, r->in.job_id);
6698 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
6702 case SPOOLSS_JOB_CONTROL_PAUSE:
6703 if (print_job_pause(p->server_info, p->msg_ctx,
6704 snum, r->in.job_id, &errcode)) {
6708 case SPOOLSS_JOB_CONTROL_RESTART:
6709 case SPOOLSS_JOB_CONTROL_RESUME:
6710 if (print_job_resume(p->server_info, p->msg_ctx,
6711 snum, r->in.job_id, &errcode)) {
6719 return WERR_UNKNOWN_LEVEL;
6722 if (!W_ERROR_IS_OK(errcode)) {
6726 if (r->in.ctr == NULL) {
6730 switch (r->in.ctr->level) {
6732 errcode = spoolss_setjob_1(p->mem_ctx, lp_const_servicename(snum),
6734 r->in.ctr->info.info1);
6740 return WERR_UNKNOWN_LEVEL;
6746 /****************************************************************************
6747 Enumerates all printer drivers by level and architecture.
6748 ****************************************************************************/
6750 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
6751 struct auth_serversupplied_info *server_info,
6752 struct messaging_context *msg_ctx,
6753 const char *servername,
6754 const char *architecture,
6756 union spoolss_DriverInfo **info_p,
6761 struct spoolss_DriverInfo8 *driver;
6762 union spoolss_DriverInfo *info = NULL;
6764 WERROR result = WERR_OK;
6765 uint32_t num_drivers;
6766 const char **drivers;
6771 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6772 result = winreg_get_driver_list(mem_ctx, server_info, msg_ctx,
6773 architecture, version,
6774 &num_drivers, &drivers);
6775 if (!W_ERROR_IS_OK(result)) {
6778 DEBUG(4, ("we have:[%d] drivers in environment"
6779 " [%s] and version [%d]\n",
6780 num_drivers, architecture, version));
6782 if (num_drivers != 0) {
6783 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6784 union spoolss_DriverInfo,
6785 count + num_drivers);
6787 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
6788 "failed to enlarge driver info buffer!\n"));
6789 result = WERR_NOMEM;
6794 for (i = 0; i < num_drivers; i++) {
6795 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
6797 result = winreg_get_driver(mem_ctx, server_info,
6799 architecture, drivers[i],
6801 if (!W_ERROR_IS_OK(result)) {
6807 result = fill_printer_driver_info1(info, &info[count+i].info1,
6808 driver, servername);
6811 result = fill_printer_driver_info2(info, &info[count+i].info2,
6812 driver, servername);
6815 result = fill_printer_driver_info3(info, &info[count+i].info3,
6816 driver, servername);
6819 result = fill_printer_driver_info4(info, &info[count+i].info4,
6820 driver, servername);
6823 result = fill_printer_driver_info5(info, &info[count+i].info5,
6824 driver, servername);
6827 result = fill_printer_driver_info6(info, &info[count+i].info6,
6828 driver, servername);
6831 result = fill_printer_driver_info8(info, &info[count+i].info8,
6832 driver, servername);
6835 result = WERR_UNKNOWN_LEVEL;
6839 TALLOC_FREE(driver);
6841 if (!W_ERROR_IS_OK(result)) {
6846 count += num_drivers;
6847 TALLOC_FREE(drivers);
6851 TALLOC_FREE(drivers);
6853 if (!W_ERROR_IS_OK(result)) {
6864 /****************************************************************************
6865 Enumerates all printer drivers by level.
6866 ****************************************************************************/
6868 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
6869 struct auth_serversupplied_info *server_info,
6870 struct messaging_context *msg_ctx,
6871 const char *servername,
6872 const char *architecture,
6874 union spoolss_DriverInfo **info_p,
6878 WERROR result = WERR_OK;
6880 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
6882 for (a=0; archi_table[a].long_archi != NULL; a++) {
6884 union spoolss_DriverInfo *info = NULL;
6887 result = enumprinterdrivers_level_by_architecture(mem_ctx,
6891 archi_table[a].long_archi,
6895 if (!W_ERROR_IS_OK(result)) {
6899 for (i=0; i < count; i++) {
6900 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
6901 info[i], info_p, count_p);
6908 return enumprinterdrivers_level_by_architecture(mem_ctx,
6918 /****************************************************************
6919 _spoolss_EnumPrinterDrivers
6920 ****************************************************************/
6922 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
6923 struct spoolss_EnumPrinterDrivers *r)
6925 const char *cservername;
6928 /* that's an [in out] buffer */
6930 if (!r->in.buffer && (r->in.offered != 0)) {
6931 return WERR_INVALID_PARAM;
6934 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
6938 *r->out.info = NULL;
6940 cservername = canon_servername(r->in.server);
6942 if (!is_myname_or_ipaddr(cservername)) {
6943 return WERR_UNKNOWN_PRINTER_DRIVER;
6946 result = enumprinterdrivers_level(p->mem_ctx,
6954 if (!W_ERROR_IS_OK(result)) {
6958 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6959 spoolss_EnumPrinterDrivers,
6960 *r->out.info, r->in.level,
6962 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6963 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6965 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6968 /****************************************************************
6970 ****************************************************************/
6972 WERROR _spoolss_EnumForms(struct pipes_struct *p,
6973 struct spoolss_EnumForms *r)
6979 *r->out.info = NULL;
6981 /* that's an [in out] buffer */
6983 if (!r->in.buffer && (r->in.offered != 0) ) {
6984 return WERR_INVALID_PARAM;
6987 DEBUG(4,("_spoolss_EnumForms\n"));
6988 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6989 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6991 switch (r->in.level) {
6993 result = winreg_printer_enumforms1(p->mem_ctx,
7000 result = WERR_UNKNOWN_LEVEL;
7004 if (!W_ERROR_IS_OK(result)) {
7008 if (*r->out.count == 0) {
7009 return WERR_NO_MORE_ITEMS;
7012 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7014 *r->out.info, r->in.level,
7016 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7017 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7019 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7022 /****************************************************************
7024 ****************************************************************/
7026 WERROR _spoolss_GetForm(struct pipes_struct *p,
7027 struct spoolss_GetForm *r)
7031 /* that's an [in out] buffer */
7033 if (!r->in.buffer && (r->in.offered != 0)) {
7034 return WERR_INVALID_PARAM;
7037 DEBUG(4,("_spoolss_GetForm\n"));
7038 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7039 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7041 switch (r->in.level) {
7043 result = winreg_printer_getform1(p->mem_ctx,
7047 &r->out.info->info1);
7050 result = WERR_UNKNOWN_LEVEL;
7054 if (!W_ERROR_IS_OK(result)) {
7055 TALLOC_FREE(r->out.info);
7059 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7060 r->out.info, r->in.level);
7061 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7063 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7066 /****************************************************************************
7067 ****************************************************************************/
7069 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7070 struct spoolss_PortInfo1 *r,
7073 r->port_name = talloc_strdup(mem_ctx, name);
7074 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7079 /****************************************************************************
7080 TODO: This probably needs distinguish between TCP/IP and Local ports
7082 ****************************************************************************/
7084 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7085 struct spoolss_PortInfo2 *r,
7088 r->port_name = talloc_strdup(mem_ctx, name);
7089 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7091 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7092 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7094 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7095 W_ERROR_HAVE_NO_MEMORY(r->description);
7097 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7104 /****************************************************************************
7105 wrapper around the enumer ports command
7106 ****************************************************************************/
7108 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7110 char *cmd = lp_enumports_cmd();
7111 char **qlines = NULL;
7112 char *command = NULL;
7120 /* if no hook then just fill in the default port */
7123 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7126 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7127 TALLOC_FREE(qlines);
7134 /* we have a valid enumport command */
7136 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7141 DEBUG(10,("Running [%s]\n", command));
7142 ret = smbrun(command, &fd);
7143 DEBUG(10,("Returned [%d]\n", ret));
7144 TALLOC_FREE(command);
7149 return WERR_ACCESS_DENIED;
7153 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7154 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7164 /****************************************************************************
7166 ****************************************************************************/
7168 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7169 union spoolss_PortInfo **info_p,
7172 union spoolss_PortInfo *info = NULL;
7174 WERROR result = WERR_OK;
7175 char **qlines = NULL;
7178 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7179 if (!W_ERROR_IS_OK(result)) {
7184 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7186 DEBUG(10,("Returning WERR_NOMEM\n"));
7187 result = WERR_NOMEM;
7191 for (i=0; i<numlines; i++) {
7192 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7193 result = fill_port_1(info, &info[i].info1, qlines[i]);
7194 if (!W_ERROR_IS_OK(result)) {
7199 TALLOC_FREE(qlines);
7202 if (!W_ERROR_IS_OK(result)) {
7204 TALLOC_FREE(qlines);
7216 /****************************************************************************
7218 ****************************************************************************/
7220 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7221 union spoolss_PortInfo **info_p,
7224 union spoolss_PortInfo *info = NULL;
7226 WERROR result = WERR_OK;
7227 char **qlines = NULL;
7230 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7231 if (!W_ERROR_IS_OK(result)) {
7236 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7238 DEBUG(10,("Returning WERR_NOMEM\n"));
7239 result = WERR_NOMEM;
7243 for (i=0; i<numlines; i++) {
7244 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7245 result = fill_port_2(info, &info[i].info2, qlines[i]);
7246 if (!W_ERROR_IS_OK(result)) {
7251 TALLOC_FREE(qlines);
7254 if (!W_ERROR_IS_OK(result)) {
7256 TALLOC_FREE(qlines);
7268 /****************************************************************
7270 ****************************************************************/
7272 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
7273 struct spoolss_EnumPorts *r)
7277 /* that's an [in out] buffer */
7279 if (!r->in.buffer && (r->in.offered != 0)) {
7280 return WERR_INVALID_PARAM;
7283 DEBUG(4,("_spoolss_EnumPorts\n"));
7287 *r->out.info = NULL;
7289 switch (r->in.level) {
7291 result = enumports_level_1(p->mem_ctx, r->out.info,
7295 result = enumports_level_2(p->mem_ctx, r->out.info,
7299 return WERR_UNKNOWN_LEVEL;
7302 if (!W_ERROR_IS_OK(result)) {
7306 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7308 *r->out.info, r->in.level,
7310 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7311 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7313 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7316 /****************************************************************************
7317 ****************************************************************************/
7319 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
7321 struct spoolss_SetPrinterInfoCtr *info_ctr,
7322 struct spoolss_DeviceMode *devmode,
7323 struct security_descriptor *secdesc,
7324 struct spoolss_UserLevelCtr *user_ctr,
7325 struct policy_handle *handle)
7327 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7328 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7330 WERROR err = WERR_OK;
7332 /* samba does not have a concept of local, non-shared printers yet, so
7333 * make sure we always setup sharename - gd */
7334 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7335 (info2->printername != NULL && info2->printername[0] != '\0')) {
7336 DEBUG(5, ("spoolss_addprinterex_level_2: "
7337 "no sharename has been set, setting printername %s as sharename\n",
7338 info2->printername));
7339 info2->sharename = info2->printername;
7342 /* check to see if the printer already exists */
7343 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7344 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7346 return WERR_PRINTER_ALREADY_EXISTS;
7349 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7350 if ((snum = print_queue_snum(info2->printername)) != -1) {
7351 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7352 info2->printername));
7353 return WERR_PRINTER_ALREADY_EXISTS;
7357 /* validate printer info struct */
7358 if (!info2->printername || strlen(info2->printername) == 0) {
7359 return WERR_INVALID_PRINTER_NAME;
7361 if (!info2->portname || strlen(info2->portname) == 0) {
7362 return WERR_UNKNOWN_PORT;
7364 if (!info2->drivername || strlen(info2->drivername) == 0) {
7365 return WERR_UNKNOWN_PRINTER_DRIVER;
7367 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7368 return WERR_UNKNOWN_PRINTPROCESSOR;
7371 /* FIXME!!! smbd should check to see if the driver is installed before
7372 trying to add a printer like this --jerry */
7374 if (*lp_addprinter_cmd() ) {
7375 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7376 info2, p->client_address,
7378 return WERR_ACCESS_DENIED;
7381 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7382 "smb.conf parameter \"addprinter command\" is defined. This"
7383 "parameter must exist for this call to succeed\n",
7384 info2->sharename ));
7387 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7388 return WERR_ACCESS_DENIED;
7391 /* you must be a printer admin to add a new printer */
7392 if (!print_access_check(p->server_info, p->msg_ctx, snum,
7393 PRINTER_ACCESS_ADMINISTER)) {
7394 return WERR_ACCESS_DENIED;
7398 * Do sanity check on the requested changes for Samba.
7401 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7402 return WERR_INVALID_PARAM;
7405 if (devmode == NULL) {
7406 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7409 update_dsspooler(p->mem_ctx,
7416 err = winreg_update_printer(p->mem_ctx,
7424 if (!W_ERROR_IS_OK(err)) {
7428 if (!open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER)) {
7429 /* Handle open failed - remove addition. */
7430 ZERO_STRUCTP(handle);
7431 return WERR_ACCESS_DENIED;
7437 /****************************************************************
7438 _spoolss_AddPrinterEx
7439 ****************************************************************/
7441 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
7442 struct spoolss_AddPrinterEx *r)
7444 switch (r->in.info_ctr->level) {
7446 /* we don't handle yet */
7447 /* but I know what to do ... */
7448 return WERR_UNKNOWN_LEVEL;
7450 return spoolss_addprinterex_level_2(p, r->in.server,
7452 r->in.devmode_ctr->devmode,
7453 r->in.secdesc_ctr->sd,
7454 r->in.userlevel_ctr,
7457 return WERR_UNKNOWN_LEVEL;
7461 /****************************************************************
7463 ****************************************************************/
7465 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
7466 struct spoolss_AddPrinter *r)
7468 struct spoolss_AddPrinterEx a;
7469 struct spoolss_UserLevelCtr userlevel_ctr;
7471 ZERO_STRUCT(userlevel_ctr);
7473 userlevel_ctr.level = 1;
7475 a.in.server = r->in.server;
7476 a.in.info_ctr = r->in.info_ctr;
7477 a.in.devmode_ctr = r->in.devmode_ctr;
7478 a.in.secdesc_ctr = r->in.secdesc_ctr;
7479 a.in.userlevel_ctr = &userlevel_ctr;
7480 a.out.handle = r->out.handle;
7482 return _spoolss_AddPrinterEx(p, &a);
7485 /****************************************************************
7486 _spoolss_AddPrinterDriverEx
7487 ****************************************************************/
7489 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
7490 struct spoolss_AddPrinterDriverEx *r)
7492 WERROR err = WERR_OK;
7493 const char *driver_name = NULL;
7498 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7499 fn = "_spoolss_AddPrinterDriver";
7501 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7502 fn = "_spoolss_AddPrinterDriverEx";
7505 return WERR_INVALID_PARAM;
7509 * we only support the semantics of AddPrinterDriver()
7510 * i.e. only copy files that are newer than existing ones
7513 if (r->in.flags == 0) {
7514 return WERR_INVALID_PARAM;
7517 if (r->in.flags != APD_COPY_NEW_FILES) {
7518 return WERR_ACCESS_DENIED;
7522 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7523 /* Clever hack from Martin Zielinski <mz@seh.de>
7524 * to allow downgrade from level 8 (Vista).
7526 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7527 r->in.info_ctr->level));
7528 return WERR_UNKNOWN_LEVEL;
7531 DEBUG(5,("Cleaning driver's information\n"));
7532 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
7533 if (!W_ERROR_IS_OK(err))
7536 DEBUG(5,("Moving driver to final destination\n"));
7537 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7542 err = winreg_add_driver(p->mem_ctx, p->server_info, p->msg_ctx,
7543 r->in.info_ctr, &driver_name, &version);
7544 if (!W_ERROR_IS_OK(err)) {
7549 * I think this is where he DrvUpgradePrinter() hook would be
7550 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7551 * server. Right now, we just need to send ourselves a message
7552 * to update each printer bound to this driver. --jerry
7555 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
7556 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7564 /****************************************************************
7565 _spoolss_AddPrinterDriver
7566 ****************************************************************/
7568 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
7569 struct spoolss_AddPrinterDriver *r)
7571 struct spoolss_AddPrinterDriverEx a;
7573 switch (r->in.info_ctr->level) {
7580 return WERR_UNKNOWN_LEVEL;
7583 a.in.servername = r->in.servername;
7584 a.in.info_ctr = r->in.info_ctr;
7585 a.in.flags = APD_COPY_NEW_FILES;
7587 return _spoolss_AddPrinterDriverEx(p, &a);
7590 /****************************************************************************
7591 ****************************************************************************/
7593 struct _spoolss_paths {
7599 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7601 static const struct _spoolss_paths spoolss_paths[]= {
7602 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7603 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7606 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7607 const char *servername,
7608 const char *environment,
7612 const char *pservername = NULL;
7613 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7614 const char *short_archi;
7618 /* environment may be empty */
7619 if (environment && strlen(environment)) {
7620 long_archi = environment;
7623 /* servername may be empty */
7624 if (servername && strlen(servername)) {
7625 pservername = canon_servername(servername);
7627 if (!is_myname_or_ipaddr(pservername)) {
7628 return WERR_INVALID_PARAM;
7632 if (!(short_archi = get_short_archi(long_archi))) {
7633 return WERR_INVALID_ENVIRONMENT;
7636 switch (component) {
7637 case SPOOLSS_PRTPROCS_PATH:
7638 case SPOOLSS_DRIVER_PATH:
7640 *path = talloc_asprintf(mem_ctx,
7643 spoolss_paths[component].share,
7646 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7647 SPOOLSS_DEFAULT_SERVER_PATH,
7648 spoolss_paths[component].dir,
7653 return WERR_INVALID_PARAM;
7663 /****************************************************************************
7664 ****************************************************************************/
7666 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7667 const char *servername,
7668 const char *environment,
7669 struct spoolss_DriverDirectoryInfo1 *r)
7674 werr = compose_spoolss_server_path(mem_ctx,
7677 SPOOLSS_DRIVER_PATH,
7679 if (!W_ERROR_IS_OK(werr)) {
7683 DEBUG(4,("printer driver directory: [%s]\n", path));
7685 r->directory_name = path;
7690 /****************************************************************
7691 _spoolss_GetPrinterDriverDirectory
7692 ****************************************************************/
7694 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
7695 struct spoolss_GetPrinterDriverDirectory *r)
7699 /* that's an [in out] buffer */
7701 if (!r->in.buffer && (r->in.offered != 0)) {
7702 return WERR_INVALID_PARAM;
7705 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
7710 /* r->in.level is ignored */
7712 werror = getprinterdriverdir_level_1(p->mem_ctx,
7715 &r->out.info->info1);
7716 if (!W_ERROR_IS_OK(werror)) {
7717 TALLOC_FREE(r->out.info);
7721 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
7722 r->out.info, r->in.level);
7723 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7725 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7728 /****************************************************************
7729 _spoolss_EnumPrinterData
7730 ****************************************************************/
7732 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
7733 struct spoolss_EnumPrinterData *r)
7736 struct spoolss_EnumPrinterDataEx r2;
7738 struct spoolss_PrinterEnumValues *info, *val = NULL;
7741 r2.in.handle = r->in.handle;
7742 r2.in.key_name = "PrinterDriverData";
7744 r2.out.count = &count;
7745 r2.out.info = &info;
7746 r2.out.needed = &needed;
7748 result = _spoolss_EnumPrinterDataEx(p, &r2);
7749 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
7750 r2.in.offered = needed;
7751 result = _spoolss_EnumPrinterDataEx(p, &r2);
7753 if (!W_ERROR_IS_OK(result)) {
7758 * The NT machine wants to know the biggest size of value and data
7760 * cf: MSDN EnumPrinterData remark section
7763 if (!r->in.value_offered && !r->in.data_offered) {
7764 uint32_t biggest_valuesize = 0;
7765 uint32_t biggest_datasize = 0;
7768 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
7770 for (i=0; i<count; i++) {
7772 name_length = strlen(info[i].value_name);
7773 if (strlen(info[i].value_name) > biggest_valuesize) {
7774 biggest_valuesize = name_length;
7777 if (info[i].data_length > biggest_datasize) {
7778 biggest_datasize = info[i].data_length;
7781 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
7785 /* the value is an UNICODE string but real_value_size is the length
7786 in bytes including the trailing 0 */
7788 *r->out.value_needed = 2 * (1 + biggest_valuesize);
7789 *r->out.data_needed = biggest_datasize;
7791 DEBUG(6,("final values: [%d], [%d]\n",
7792 *r->out.value_needed, *r->out.data_needed));
7797 if (r->in.enum_index < count) {
7798 val = &info[r->in.enum_index];
7802 /* out_value should default to "" or else NT4 has
7803 problems unmarshalling the response */
7805 if (r->in.value_offered) {
7806 *r->out.value_needed = 1;
7807 r->out.value_name = talloc_strdup(r, "");
7808 if (!r->out.value_name) {
7812 r->out.value_name = NULL;
7813 *r->out.value_needed = 0;
7816 /* the data is counted in bytes */
7818 *r->out.data_needed = r->in.data_offered;
7820 result = WERR_NO_MORE_ITEMS;
7824 * - counted in bytes in the request
7825 * - counted in UNICODE chars in the max reply
7826 * - counted in bytes in the real size
7828 * take a pause *before* coding not *during* coding
7832 if (r->in.value_offered) {
7833 r->out.value_name = talloc_strdup(r, val->value_name);
7834 if (!r->out.value_name) {
7837 *r->out.value_needed = val->value_name_len;
7839 r->out.value_name = NULL;
7840 *r->out.value_needed = 0;
7845 *r->out.type = val->type;
7847 /* data - counted in bytes */
7850 * See the section "Dynamically Typed Query Parameters"
7854 if (r->out.data && val->data && val->data->data &&
7855 val->data_length && r->in.data_offered) {
7856 memcpy(r->out.data, val->data->data,
7857 MIN(val->data_length,r->in.data_offered));
7860 *r->out.data_needed = val->data_length;
7868 /****************************************************************
7869 _spoolss_SetPrinterData
7870 ****************************************************************/
7872 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
7873 struct spoolss_SetPrinterData *r)
7875 struct spoolss_SetPrinterDataEx r2;
7877 r2.in.handle = r->in.handle;
7878 r2.in.key_name = "PrinterDriverData";
7879 r2.in.value_name = r->in.value_name;
7880 r2.in.type = r->in.type;
7881 r2.in.data = r->in.data;
7882 r2.in.offered = r->in.offered;
7884 return _spoolss_SetPrinterDataEx(p, &r2);
7887 /****************************************************************
7888 _spoolss_ResetPrinter
7889 ****************************************************************/
7891 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
7892 struct spoolss_ResetPrinter *r)
7894 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7897 DEBUG(5,("_spoolss_ResetPrinter\n"));
7900 * All we do is to check to see if the handle and queue is valid.
7901 * This call really doesn't mean anything to us because we only
7902 * support RAW printing. --jerry
7906 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
7907 OUR_HANDLE(r->in.handle)));
7911 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
7915 /* blindly return success */
7919 /****************************************************************
7920 _spoolss_DeletePrinterData
7921 ****************************************************************/
7923 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
7924 struct spoolss_DeletePrinterData *r)
7926 struct spoolss_DeletePrinterDataEx r2;
7928 r2.in.handle = r->in.handle;
7929 r2.in.key_name = "PrinterDriverData";
7930 r2.in.value_name = r->in.value_name;
7932 return _spoolss_DeletePrinterDataEx(p, &r2);
7935 /****************************************************************
7937 ****************************************************************/
7939 WERROR _spoolss_AddForm(struct pipes_struct *p,
7940 struct spoolss_AddForm *r)
7942 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
7944 WERROR status = WERR_OK;
7945 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7947 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7949 DEBUG(5,("_spoolss_AddForm\n"));
7952 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
7953 OUR_HANDLE(r->in.handle)));
7957 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
7958 and not a printer admin, then fail */
7960 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7961 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7962 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7963 p->server_info->info3->base.domain.string,
7965 p->server_info->ptok,
7966 lp_printer_admin(snum))) {
7967 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
7968 return WERR_ACCESS_DENIED;
7971 switch (form->flags) {
7972 case SPOOLSS_FORM_USER:
7973 case SPOOLSS_FORM_BUILTIN:
7974 case SPOOLSS_FORM_PRINTER:
7977 return WERR_INVALID_PARAM;
7980 status = winreg_printer_addform1(p->mem_ctx, p->server_info,
7982 if (!W_ERROR_IS_OK(status)) {
7987 * ChangeID must always be set if this is a printer
7989 if (Printer->printer_type == SPLHND_PRINTER) {
7990 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7994 status = winreg_printer_update_changeid(p->mem_ctx,
7997 lp_const_servicename(snum));
7998 if (!W_ERROR_IS_OK(status)) {
8006 /****************************************************************
8008 ****************************************************************/
8010 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8011 struct spoolss_DeleteForm *r)
8013 const char *form_name = r->in.form_name;
8014 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8016 WERROR status = WERR_OK;
8017 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8019 DEBUG(5,("_spoolss_DeleteForm\n"));
8022 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8023 OUR_HANDLE(r->in.handle)));
8027 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8028 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8029 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8030 p->server_info->info3->base.domain.string,
8032 p->server_info->ptok,
8033 lp_printer_admin(snum))) {
8034 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8035 return WERR_ACCESS_DENIED;
8038 status = winreg_printer_deleteform1(p->mem_ctx,
8042 if (!W_ERROR_IS_OK(status)) {
8047 * ChangeID must always be set if this is a printer
8049 if (Printer->printer_type == SPLHND_PRINTER) {
8050 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8054 status = winreg_printer_update_changeid(p->mem_ctx,
8057 lp_const_servicename(snum));
8058 if (!W_ERROR_IS_OK(status)) {
8066 /****************************************************************
8068 ****************************************************************/
8070 WERROR _spoolss_SetForm(struct pipes_struct *p,
8071 struct spoolss_SetForm *r)
8073 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8074 const char *form_name = r->in.form_name;
8076 WERROR status = WERR_OK;
8077 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8079 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8081 DEBUG(5,("_spoolss_SetForm\n"));
8084 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8085 OUR_HANDLE(r->in.handle)));
8089 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8090 and not a printer admin, then fail */
8092 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8093 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8094 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8095 p->server_info->info3->base.domain.string,
8097 p->server_info->ptok,
8098 lp_printer_admin(snum))) {
8099 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8100 return WERR_ACCESS_DENIED;
8103 status = winreg_printer_setform1(p->mem_ctx,
8108 if (!W_ERROR_IS_OK(status)) {
8113 * ChangeID must always be set if this is a printer
8115 if (Printer->printer_type == SPLHND_PRINTER) {
8116 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8120 status = winreg_printer_update_changeid(p->mem_ctx,
8123 lp_const_servicename(snum));
8124 if (!W_ERROR_IS_OK(status)) {
8132 /****************************************************************************
8133 fill_print_processor1
8134 ****************************************************************************/
8136 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8137 struct spoolss_PrintProcessorInfo1 *r,
8138 const char *print_processor_name)
8140 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8141 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8146 /****************************************************************************
8147 enumprintprocessors level 1.
8148 ****************************************************************************/
8150 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8151 union spoolss_PrintProcessorInfo **info_p,
8154 union spoolss_PrintProcessorInfo *info;
8157 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8158 W_ERROR_HAVE_NO_MEMORY(info);
8162 result = fill_print_processor1(info, &info[0].info1, "winprint");
8163 if (!W_ERROR_IS_OK(result)) {
8168 if (!W_ERROR_IS_OK(result)) {
8179 /****************************************************************
8180 _spoolss_EnumPrintProcessors
8181 ****************************************************************/
8183 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8184 struct spoolss_EnumPrintProcessors *r)
8188 /* that's an [in out] buffer */
8190 if (!r->in.buffer && (r->in.offered != 0)) {
8191 return WERR_INVALID_PARAM;
8194 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8197 * Enumerate the print processors ...
8199 * Just reply with "winprint", to keep NT happy
8200 * and I can use my nice printer checker.
8205 *r->out.info = NULL;
8207 switch (r->in.level) {
8209 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8213 return WERR_UNKNOWN_LEVEL;
8216 if (!W_ERROR_IS_OK(result)) {
8220 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8221 spoolss_EnumPrintProcessors,
8222 *r->out.info, r->in.level,
8224 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8225 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8227 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8230 /****************************************************************************
8231 fill_printprocdatatype1
8232 ****************************************************************************/
8234 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8235 struct spoolss_PrintProcDataTypesInfo1 *r,
8236 const char *name_array)
8238 r->name_array = talloc_strdup(mem_ctx, name_array);
8239 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8244 /****************************************************************************
8245 enumprintprocdatatypes level 1.
8246 ****************************************************************************/
8248 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8249 union spoolss_PrintProcDataTypesInfo **info_p,
8253 union spoolss_PrintProcDataTypesInfo *info;
8255 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8256 W_ERROR_HAVE_NO_MEMORY(info);
8260 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8261 if (!W_ERROR_IS_OK(result)) {
8266 if (!W_ERROR_IS_OK(result)) {
8277 /****************************************************************
8278 _spoolss_EnumPrintProcDataTypes
8279 ****************************************************************/
8281 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
8282 struct spoolss_EnumPrintProcDataTypes *r)
8286 /* that's an [in out] buffer */
8288 if (!r->in.buffer && (r->in.offered != 0)) {
8289 return WERR_INVALID_PARAM;
8292 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8296 *r->out.info = NULL;
8298 switch (r->in.level) {
8300 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8304 return WERR_UNKNOWN_LEVEL;
8307 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8308 spoolss_EnumPrintProcDataTypes,
8309 *r->out.info, r->in.level,
8311 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8312 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8314 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8317 /****************************************************************************
8319 ****************************************************************************/
8321 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8322 struct spoolss_MonitorInfo1 *r,
8323 const char *monitor_name)
8325 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8326 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8331 /****************************************************************************
8333 ****************************************************************************/
8335 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8336 struct spoolss_MonitorInfo2 *r,
8337 const char *monitor_name,
8338 const char *environment,
8339 const char *dll_name)
8341 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8342 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8343 r->environment = talloc_strdup(mem_ctx, environment);
8344 W_ERROR_HAVE_NO_MEMORY(r->environment);
8345 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8346 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8351 /****************************************************************************
8352 enumprintmonitors level 1.
8353 ****************************************************************************/
8355 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8356 union spoolss_MonitorInfo **info_p,
8359 union spoolss_MonitorInfo *info;
8360 WERROR result = WERR_OK;
8362 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8363 W_ERROR_HAVE_NO_MEMORY(info);
8367 result = fill_monitor_1(info, &info[0].info1,
8369 if (!W_ERROR_IS_OK(result)) {
8373 result = fill_monitor_1(info, &info[1].info1,
8375 if (!W_ERROR_IS_OK(result)) {
8380 if (!W_ERROR_IS_OK(result)) {
8391 /****************************************************************************
8392 enumprintmonitors level 2.
8393 ****************************************************************************/
8395 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8396 union spoolss_MonitorInfo **info_p,
8399 union spoolss_MonitorInfo *info;
8400 WERROR result = WERR_OK;
8402 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8403 W_ERROR_HAVE_NO_MEMORY(info);
8407 result = fill_monitor_2(info, &info[0].info2,
8409 "Windows NT X86", /* FIXME */
8411 if (!W_ERROR_IS_OK(result)) {
8415 result = fill_monitor_2(info, &info[1].info2,
8417 "Windows NT X86", /* FIXME */
8419 if (!W_ERROR_IS_OK(result)) {
8424 if (!W_ERROR_IS_OK(result)) {
8435 /****************************************************************
8436 _spoolss_EnumMonitors
8437 ****************************************************************/
8439 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
8440 struct spoolss_EnumMonitors *r)
8444 /* that's an [in out] buffer */
8446 if (!r->in.buffer && (r->in.offered != 0)) {
8447 return WERR_INVALID_PARAM;
8450 DEBUG(5,("_spoolss_EnumMonitors\n"));
8453 * Enumerate the print monitors ...
8455 * Just reply with "Local Port", to keep NT happy
8456 * and I can use my nice printer checker.
8461 *r->out.info = NULL;
8463 switch (r->in.level) {
8465 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8469 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8473 return WERR_UNKNOWN_LEVEL;
8476 if (!W_ERROR_IS_OK(result)) {
8480 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8481 spoolss_EnumMonitors,
8482 *r->out.info, r->in.level,
8484 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8485 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8487 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8490 /****************************************************************************
8491 ****************************************************************************/
8493 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8494 const print_queue_struct *queue,
8495 int count, int snum,
8496 struct spoolss_PrinterInfo2 *pinfo2,
8498 struct spoolss_JobInfo1 *r)
8503 for (i=0; i<count; i++) {
8504 if (queue[i].job == (int)jobid) {
8510 if (found == false) {
8511 /* NT treats not found as bad param... yet another bad choice */
8512 return WERR_INVALID_PARAM;
8515 return fill_job_info1(mem_ctx,
8523 /****************************************************************************
8524 ****************************************************************************/
8526 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8527 const print_queue_struct *queue,
8528 int count, int snum,
8529 struct spoolss_PrinterInfo2 *pinfo2,
8531 struct spoolss_JobInfo2 *r)
8535 struct spoolss_DeviceMode *devmode;
8538 for (i=0; i<count; i++) {
8539 if (queue[i].job == (int)jobid) {
8545 if (found == false) {
8546 /* NT treats not found as bad param... yet another bad
8548 return WERR_INVALID_PARAM;
8552 * if the print job does not have a DEVMODE associated with it,
8553 * just use the one for the printer. A NULL devicemode is not
8554 * a failure condition
8557 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8559 result = spoolss_create_default_devmode(mem_ctx,
8560 pinfo2->printername,
8562 if (!W_ERROR_IS_OK(result)) {
8563 DEBUG(3, ("Can't proceed w/o a devmode!"));
8568 return fill_job_info2(mem_ctx,
8577 /****************************************************************
8579 ****************************************************************/
8581 WERROR _spoolss_GetJob(struct pipes_struct *p,
8582 struct spoolss_GetJob *r)
8584 WERROR result = WERR_OK;
8585 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8588 print_queue_struct *queue = NULL;
8589 print_status_struct prt_status;
8591 /* that's an [in out] buffer */
8593 if (!r->in.buffer && (r->in.offered != 0)) {
8594 return WERR_INVALID_PARAM;
8597 DEBUG(5,("_spoolss_GetJob\n"));
8601 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8605 result = winreg_get_printer(p->mem_ctx, p->server_info, p->msg_ctx,
8606 NULL, lp_servicename(snum), &pinfo2);
8607 if (!W_ERROR_IS_OK(result)) {
8611 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
8613 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8614 count, prt_status.status, prt_status.message));
8616 switch (r->in.level) {
8618 result = getjob_level_1(p->mem_ctx,
8619 queue, count, snum, pinfo2,
8620 r->in.job_id, &r->out.info->info1);
8623 result = getjob_level_2(p->mem_ctx,
8624 queue, count, snum, pinfo2,
8625 r->in.job_id, &r->out.info->info2);
8628 result = WERR_UNKNOWN_LEVEL;
8633 TALLOC_FREE(pinfo2);
8635 if (!W_ERROR_IS_OK(result)) {
8636 TALLOC_FREE(r->out.info);
8640 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
8642 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8644 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8647 /****************************************************************
8648 _spoolss_GetPrinterDataEx
8649 ****************************************************************/
8651 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
8652 struct spoolss_GetPrinterDataEx *r)
8655 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8656 const char *printer;
8658 WERROR result = WERR_OK;
8660 enum winreg_Type val_type;
8665 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8667 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8668 r->in.key_name, r->in.value_name));
8670 /* in case of problem, return some default values */
8673 *r->out.type = REG_NONE;
8676 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8677 OUR_HANDLE(r->in.handle)));
8678 result = WERR_BADFID;
8682 /* Is the handle to a printer or to the server? */
8684 if (Printer->printer_type == SPLHND_SERVER) {
8686 union spoolss_PrinterData data;
8688 result = getprinterdata_printer_server(p->mem_ctx,
8692 if (!W_ERROR_IS_OK(result)) {
8696 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
8697 *r->out.type, &data);
8698 if (!W_ERROR_IS_OK(result)) {
8702 *r->out.needed = blob.length;
8704 if (r->in.offered >= *r->out.needed) {
8705 memcpy(r->out.data, blob.data, blob.length);
8708 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8711 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8714 printer = lp_const_servicename(snum);
8716 /* check to see if the keyname is valid */
8717 if (!strlen(r->in.key_name)) {
8718 return WERR_INVALID_PARAM;
8721 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
8722 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
8723 strequal(r->in.value_name, "ChangeId")) {
8724 *r->out.type = REG_DWORD;
8726 if (r->in.offered >= *r->out.needed) {
8727 uint32_t changeid = 0;
8729 result = winreg_printer_get_changeid(p->mem_ctx,
8734 if (!W_ERROR_IS_OK(result)) {
8738 SIVAL(r->out.data, 0, changeid);
8744 result = winreg_get_printer_dataex(p->mem_ctx,
8753 if (!W_ERROR_IS_OK(result)) {
8757 *r->out.needed = val_size;
8758 *r->out.type = val_type;
8760 if (r->in.offered >= *r->out.needed) {
8761 memcpy(r->out.data, val_data, val_size);
8765 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
8766 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
8768 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8771 /****************************************************************
8772 _spoolss_SetPrinterDataEx
8773 ****************************************************************/
8775 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
8776 struct spoolss_SetPrinterDataEx *r)
8778 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8780 WERROR result = WERR_OK;
8781 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8784 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
8786 /* From MSDN documentation of SetPrinterDataEx: pass request to
8787 SetPrinterData if key is "PrinterDriverData" */
8790 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8791 OUR_HANDLE(r->in.handle)));
8795 if (Printer->printer_type == SPLHND_SERVER) {
8796 DEBUG(10,("_spoolss_SetPrinterDataEx: "
8797 "Not implemented for server handles yet\n"));
8798 return WERR_INVALID_PARAM;
8801 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8806 * Access check : NT returns "access denied" if you make a
8807 * SetPrinterData call without the necessary privildge.
8808 * we were originally returning OK if nothing changed
8809 * which made Win2k issue **a lot** of SetPrinterData
8810 * when connecting to a printer --jerry
8813 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8814 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
8815 "change denied by handle access permissions\n"));
8816 return WERR_ACCESS_DENIED;
8819 result = winreg_get_printer(Printer, p->server_info, p->msg_ctx,
8820 Printer->servername,
8821 lp_servicename(snum),
8823 if (!W_ERROR_IS_OK(result)) {
8827 /* check for OID in valuename */
8829 oid_string = strchr(r->in.value_name, ',');
8835 /* save the registry data */
8837 result = winreg_set_printer_dataex(p->mem_ctx,
8847 if (W_ERROR_IS_OK(result)) {
8848 /* save the OID if one was specified */
8850 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
8851 r->in.key_name, SPOOL_OID_KEY);
8853 result = WERR_NOMEM;
8858 * I'm not checking the status here on purpose. Don't know
8859 * if this is right, but I'm returning the status from the
8860 * previous set_printer_dataex() call. I have no idea if
8861 * this is right. --jerry
8863 winreg_set_printer_dataex(p->mem_ctx,
8870 (uint8_t *) oid_string,
8871 strlen(oid_string) + 1);
8874 result = winreg_printer_update_changeid(p->mem_ctx,
8877 lp_const_servicename(snum));
8882 talloc_free(pinfo2);
8886 /****************************************************************
8887 _spoolss_DeletePrinterDataEx
8888 ****************************************************************/
8890 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
8891 struct spoolss_DeletePrinterDataEx *r)
8893 const char *printer;
8895 WERROR status = WERR_OK;
8896 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8898 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
8901 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
8902 "Invalid handle (%s:%u:%u).\n",
8903 OUR_HANDLE(r->in.handle)));
8907 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8908 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
8909 "printer properties change denied by handle\n"));
8910 return WERR_ACCESS_DENIED;
8913 if (!r->in.value_name || !r->in.key_name) {
8917 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8920 printer = lp_const_servicename(snum);
8922 status = winreg_delete_printer_dataex(p->mem_ctx,
8928 if (W_ERROR_IS_OK(status)) {
8929 status = winreg_printer_update_changeid(p->mem_ctx,
8938 /****************************************************************
8939 _spoolss_EnumPrinterKey
8940 ****************************************************************/
8942 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
8943 struct spoolss_EnumPrinterKey *r)
8946 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8948 WERROR result = WERR_BADFILE;
8949 const char **array = NULL;
8952 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
8955 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
8956 OUR_HANDLE(r->in.handle)));
8960 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8964 result = winreg_enum_printer_key(p->mem_ctx,
8967 lp_const_servicename(snum),
8971 if (!W_ERROR_IS_OK(result)) {
8975 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
8976 result = WERR_NOMEM;
8980 *r->out._ndr_size = r->in.offered / 2;
8981 *r->out.needed = blob.length;
8983 if (r->in.offered < *r->out.needed) {
8984 result = WERR_MORE_DATA;
8987 r->out.key_buffer->string_array = array;
8991 if (!W_ERROR_IS_OK(result)) {
8993 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9001 /****************************************************************
9002 _spoolss_DeletePrinterKey
9003 ****************************************************************/
9005 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9006 struct spoolss_DeletePrinterKey *r)
9008 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9011 const char *printer;
9013 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9016 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9017 OUR_HANDLE(r->in.handle)));
9021 /* if keyname == NULL, return error */
9022 if ( !r->in.key_name )
9023 return WERR_INVALID_PARAM;
9025 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9029 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9030 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9031 "printer properties change denied by handle\n"));
9032 return WERR_ACCESS_DENIED;
9035 printer = lp_const_servicename(snum);
9037 /* delete the key and all subkeys */
9038 status = winreg_delete_printer_key(p->mem_ctx,
9043 if (W_ERROR_IS_OK(status)) {
9044 status = winreg_printer_update_changeid(p->mem_ctx,
9053 /****************************************************************
9054 _spoolss_EnumPrinterDataEx
9055 ****************************************************************/
9057 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9058 struct spoolss_EnumPrinterDataEx *r)
9061 struct spoolss_PrinterEnumValues *info = NULL;
9062 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9066 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9070 *r->out.info = NULL;
9073 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9074 OUR_HANDLE(r->in.handle)));
9079 * first check for a keyname of NULL or "". Win2k seems to send
9080 * this a lot and we should send back WERR_INVALID_PARAM
9081 * no need to spend time looking up the printer in this case.
9085 if (!strlen(r->in.key_name)) {
9086 result = WERR_INVALID_PARAM;
9090 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9094 /* now look for a match on the key name */
9095 result = winreg_enum_printer_dataex(p->mem_ctx,
9098 lp_const_servicename(snum),
9102 if (!W_ERROR_IS_OK(result)) {
9106 #if 0 /* FIXME - gd */
9107 /* housekeeping information in the reply */
9109 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9110 * the hand marshalled container size is a multiple
9111 * of 4 bytes for RPC alignment.
9115 needed += 4-(needed % 4);
9118 *r->out.count = count;
9119 *r->out.info = info;
9122 if (!W_ERROR_IS_OK(result)) {
9126 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9127 spoolss_EnumPrinterDataEx,
9130 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9131 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9133 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9136 /****************************************************************************
9137 ****************************************************************************/
9139 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9140 const char *servername,
9141 const char *environment,
9142 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9147 werr = compose_spoolss_server_path(mem_ctx,
9150 SPOOLSS_PRTPROCS_PATH,
9152 if (!W_ERROR_IS_OK(werr)) {
9156 DEBUG(4,("print processor directory: [%s]\n", path));
9158 r->directory_name = path;
9163 /****************************************************************
9164 _spoolss_GetPrintProcessorDirectory
9165 ****************************************************************/
9167 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
9168 struct spoolss_GetPrintProcessorDirectory *r)
9172 /* that's an [in out] buffer */
9174 if (!r->in.buffer && (r->in.offered != 0)) {
9175 return WERR_INVALID_PARAM;
9178 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9183 /* r->in.level is ignored */
9185 /* We always should reply with a local print processor directory so that
9186 * users are not forced to have a [prnproc$] share on the Samba spoolss
9187 * server - Guenther */
9189 result = getprintprocessordirectory_level_1(p->mem_ctx,
9190 NULL, /* r->in.server */
9192 &r->out.info->info1);
9193 if (!W_ERROR_IS_OK(result)) {
9194 TALLOC_FREE(r->out.info);
9198 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9199 r->out.info, r->in.level);
9200 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9202 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9205 /*******************************************************************
9206 ********************************************************************/
9208 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9209 const char *dllname)
9211 enum ndr_err_code ndr_err;
9212 struct spoolss_MonitorUi ui;
9214 ui.dll_name = dllname;
9216 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9217 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9218 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9219 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9221 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9224 /*******************************************************************
9225 Streams the monitor UI DLL name in UNICODE
9226 *******************************************************************/
9228 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9229 NT_USER_TOKEN *token, DATA_BLOB *in,
9230 DATA_BLOB *out, uint32_t *needed)
9232 const char *dllname = "tcpmonui.dll";
9234 *needed = (strlen(dllname)+1) * 2;
9236 if (out->length < *needed) {
9237 return WERR_INSUFFICIENT_BUFFER;
9240 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9247 /*******************************************************************
9248 ********************************************************************/
9250 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9251 struct spoolss_PortData1 *port1,
9252 const DATA_BLOB *buf)
9254 enum ndr_err_code ndr_err;
9255 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9256 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9257 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9258 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9260 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9263 /*******************************************************************
9264 ********************************************************************/
9266 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9267 struct spoolss_PortData2 *port2,
9268 const DATA_BLOB *buf)
9270 enum ndr_err_code ndr_err;
9271 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9272 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9273 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9274 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9276 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9279 /*******************************************************************
9280 Create a new TCP/IP port
9281 *******************************************************************/
9283 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9284 NT_USER_TOKEN *token, DATA_BLOB *in,
9285 DATA_BLOB *out, uint32_t *needed)
9287 struct spoolss_PortData1 port1;
9288 struct spoolss_PortData2 port2;
9289 char *device_uri = NULL;
9292 const char *portname;
9293 const char *hostaddress;
9295 uint32_t port_number;
9298 /* peek for spoolss_PortData version */
9300 if (!in || (in->length < (128 + 4))) {
9301 return WERR_GENERAL_FAILURE;
9304 version = IVAL(in->data, 128);
9310 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9314 portname = port1.portname;
9315 hostaddress = port1.hostaddress;
9316 queue = port1.queue;
9317 protocol = port1.protocol;
9318 port_number = port1.port_number;
9324 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9328 portname = port2.portname;
9329 hostaddress = port2.hostaddress;
9330 queue = port2.queue;
9331 protocol = port2.protocol;
9332 port_number = port2.port_number;
9336 DEBUG(1,("xcvtcp_addport: "
9337 "unknown version of port_data: %d\n", version));
9338 return WERR_UNKNOWN_PORT;
9341 /* create the device URI and call the add_port_hook() */
9344 case PROTOCOL_RAWTCP_TYPE:
9345 device_uri = talloc_asprintf(mem_ctx,
9346 "socket://%s:%d/", hostaddress,
9350 case PROTOCOL_LPR_TYPE:
9351 device_uri = talloc_asprintf(mem_ctx,
9352 "lpr://%s/%s", hostaddress, queue );
9356 return WERR_UNKNOWN_PORT;
9363 return add_port_hook(mem_ctx, token, portname, device_uri);
9366 /*******************************************************************
9367 *******************************************************************/
9369 struct xcv_api_table xcvtcp_cmds[] = {
9370 { "MonitorUI", xcvtcp_monitorui },
9371 { "AddPort", xcvtcp_addport},
9375 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9376 NT_USER_TOKEN *token, const char *command,
9383 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9385 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9386 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9387 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9390 return WERR_BADFUNC;
9393 /*******************************************************************
9394 *******************************************************************/
9395 #if 0 /* don't support management using the "Local Port" monitor */
9397 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9398 NT_USER_TOKEN *token, DATA_BLOB *in,
9399 DATA_BLOB *out, uint32_t *needed)
9401 const char *dllname = "localui.dll";
9403 *needed = (strlen(dllname)+1) * 2;
9405 if (out->length < *needed) {
9406 return WERR_INSUFFICIENT_BUFFER;
9409 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9416 /*******************************************************************
9417 *******************************************************************/
9419 struct xcv_api_table xcvlocal_cmds[] = {
9420 { "MonitorUI", xcvlocal_monitorui },
9424 struct xcv_api_table xcvlocal_cmds[] = {
9431 /*******************************************************************
9432 *******************************************************************/
9434 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9435 NT_USER_TOKEN *token, const char *command,
9436 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9441 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9443 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9444 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9445 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9447 return WERR_BADFUNC;
9450 /****************************************************************
9452 ****************************************************************/
9454 WERROR _spoolss_XcvData(struct pipes_struct *p,
9455 struct spoolss_XcvData *r)
9457 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9458 DATA_BLOB out_data = data_blob_null;
9462 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9463 OUR_HANDLE(r->in.handle)));
9467 /* Has to be a handle to the TCP/IP port monitor */
9469 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9470 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9474 /* requires administrative access to the server */
9476 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9477 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9478 return WERR_ACCESS_DENIED;
9481 /* Allocate the outgoing buffer */
9483 if (r->in.out_data_size) {
9484 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9485 if (out_data.data == NULL) {
9490 switch ( Printer->printer_type ) {
9491 case SPLHND_PORTMON_TCP:
9492 werror = process_xcvtcp_command(p->mem_ctx,
9493 p->server_info->ptok,
9494 r->in.function_name,
9495 &r->in.in_data, &out_data,
9498 case SPLHND_PORTMON_LOCAL:
9499 werror = process_xcvlocal_command(p->mem_ctx,
9500 p->server_info->ptok,
9501 r->in.function_name,
9502 &r->in.in_data, &out_data,
9506 werror = WERR_INVALID_PRINT_MONITOR;
9509 if (!W_ERROR_IS_OK(werror)) {
9513 *r->out.status_code = 0;
9515 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9516 memcpy(r->out.out_data, out_data.data,
9517 MIN(r->in.out_data_size, out_data.length));
9523 /****************************************************************
9524 _spoolss_AddPrintProcessor
9525 ****************************************************************/
9527 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
9528 struct spoolss_AddPrintProcessor *r)
9530 /* for now, just indicate success and ignore the add. We'll
9531 automatically set the winprint processor for printer
9532 entries later. Used to debug the LexMark Optra S 1855 PCL
9538 /****************************************************************
9540 ****************************************************************/
9542 WERROR _spoolss_AddPort(struct pipes_struct *p,
9543 struct spoolss_AddPort *r)
9545 /* do what w2k3 does */
9547 return WERR_NOT_SUPPORTED;
9550 /****************************************************************
9551 _spoolss_GetPrinterDriver
9552 ****************************************************************/
9554 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
9555 struct spoolss_GetPrinterDriver *r)
9557 p->rng_fault_state = true;
9558 return WERR_NOT_SUPPORTED;
9561 /****************************************************************
9562 _spoolss_ReadPrinter
9563 ****************************************************************/
9565 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
9566 struct spoolss_ReadPrinter *r)
9568 p->rng_fault_state = true;
9569 return WERR_NOT_SUPPORTED;
9572 /****************************************************************
9573 _spoolss_WaitForPrinterChange
9574 ****************************************************************/
9576 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
9577 struct spoolss_WaitForPrinterChange *r)
9579 p->rng_fault_state = true;
9580 return WERR_NOT_SUPPORTED;
9583 /****************************************************************
9584 _spoolss_ConfigurePort
9585 ****************************************************************/
9587 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
9588 struct spoolss_ConfigurePort *r)
9590 p->rng_fault_state = true;
9591 return WERR_NOT_SUPPORTED;
9594 /****************************************************************
9596 ****************************************************************/
9598 WERROR _spoolss_DeletePort(struct pipes_struct *p,
9599 struct spoolss_DeletePort *r)
9601 p->rng_fault_state = true;
9602 return WERR_NOT_SUPPORTED;
9605 /****************************************************************
9606 _spoolss_CreatePrinterIC
9607 ****************************************************************/
9609 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
9610 struct spoolss_CreatePrinterIC *r)
9612 p->rng_fault_state = true;
9613 return WERR_NOT_SUPPORTED;
9616 /****************************************************************
9617 _spoolss_PlayGDIScriptOnPrinterIC
9618 ****************************************************************/
9620 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
9621 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9623 p->rng_fault_state = true;
9624 return WERR_NOT_SUPPORTED;
9627 /****************************************************************
9628 _spoolss_DeletePrinterIC
9629 ****************************************************************/
9631 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
9632 struct spoolss_DeletePrinterIC *r)
9634 p->rng_fault_state = true;
9635 return WERR_NOT_SUPPORTED;
9638 /****************************************************************
9639 _spoolss_AddPrinterConnection
9640 ****************************************************************/
9642 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
9643 struct spoolss_AddPrinterConnection *r)
9645 p->rng_fault_state = true;
9646 return WERR_NOT_SUPPORTED;
9649 /****************************************************************
9650 _spoolss_DeletePrinterConnection
9651 ****************************************************************/
9653 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
9654 struct spoolss_DeletePrinterConnection *r)
9656 p->rng_fault_state = true;
9657 return WERR_NOT_SUPPORTED;
9660 /****************************************************************
9661 _spoolss_PrinterMessageBox
9662 ****************************************************************/
9664 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
9665 struct spoolss_PrinterMessageBox *r)
9667 p->rng_fault_state = true;
9668 return WERR_NOT_SUPPORTED;
9671 /****************************************************************
9673 ****************************************************************/
9675 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
9676 struct spoolss_AddMonitor *r)
9678 p->rng_fault_state = true;
9679 return WERR_NOT_SUPPORTED;
9682 /****************************************************************
9683 _spoolss_DeleteMonitor
9684 ****************************************************************/
9686 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
9687 struct spoolss_DeleteMonitor *r)
9689 p->rng_fault_state = true;
9690 return WERR_NOT_SUPPORTED;
9693 /****************************************************************
9694 _spoolss_DeletePrintProcessor
9695 ****************************************************************/
9697 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
9698 struct spoolss_DeletePrintProcessor *r)
9700 p->rng_fault_state = true;
9701 return WERR_NOT_SUPPORTED;
9704 /****************************************************************
9705 _spoolss_AddPrintProvidor
9706 ****************************************************************/
9708 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
9709 struct spoolss_AddPrintProvidor *r)
9711 p->rng_fault_state = true;
9712 return WERR_NOT_SUPPORTED;
9715 /****************************************************************
9716 _spoolss_DeletePrintProvidor
9717 ****************************************************************/
9719 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
9720 struct spoolss_DeletePrintProvidor *r)
9722 p->rng_fault_state = true;
9723 return WERR_NOT_SUPPORTED;
9726 /****************************************************************
9727 _spoolss_FindFirstPrinterChangeNotification
9728 ****************************************************************/
9730 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
9731 struct spoolss_FindFirstPrinterChangeNotification *r)
9733 p->rng_fault_state = true;
9734 return WERR_NOT_SUPPORTED;
9737 /****************************************************************
9738 _spoolss_FindNextPrinterChangeNotification
9739 ****************************************************************/
9741 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
9742 struct spoolss_FindNextPrinterChangeNotification *r)
9744 p->rng_fault_state = true;
9745 return WERR_NOT_SUPPORTED;
9748 /****************************************************************
9749 _spoolss_RouterFindFirstPrinterChangeNotificationOld
9750 ****************************************************************/
9752 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
9753 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
9755 p->rng_fault_state = true;
9756 return WERR_NOT_SUPPORTED;
9759 /****************************************************************
9760 _spoolss_ReplyOpenPrinter
9761 ****************************************************************/
9763 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
9764 struct spoolss_ReplyOpenPrinter *r)
9766 p->rng_fault_state = true;
9767 return WERR_NOT_SUPPORTED;
9770 /****************************************************************
9771 _spoolss_RouterReplyPrinter
9772 ****************************************************************/
9774 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
9775 struct spoolss_RouterReplyPrinter *r)
9777 p->rng_fault_state = true;
9778 return WERR_NOT_SUPPORTED;
9781 /****************************************************************
9782 _spoolss_ReplyClosePrinter
9783 ****************************************************************/
9785 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
9786 struct spoolss_ReplyClosePrinter *r)
9788 p->rng_fault_state = true;
9789 return WERR_NOT_SUPPORTED;
9792 /****************************************************************
9794 ****************************************************************/
9796 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
9797 struct spoolss_AddPortEx *r)
9799 p->rng_fault_state = true;
9800 return WERR_NOT_SUPPORTED;
9803 /****************************************************************
9804 _spoolss_RouterFindFirstPrinterChangeNotification
9805 ****************************************************************/
9807 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
9808 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
9810 p->rng_fault_state = true;
9811 return WERR_NOT_SUPPORTED;
9814 /****************************************************************
9815 _spoolss_SpoolerInit
9816 ****************************************************************/
9818 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
9819 struct spoolss_SpoolerInit *r)
9821 p->rng_fault_state = true;
9822 return WERR_NOT_SUPPORTED;
9825 /****************************************************************
9826 _spoolss_ResetPrinterEx
9827 ****************************************************************/
9829 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
9830 struct spoolss_ResetPrinterEx *r)
9832 p->rng_fault_state = true;
9833 return WERR_NOT_SUPPORTED;
9836 /****************************************************************
9837 _spoolss_RouterReplyPrinterEx
9838 ****************************************************************/
9840 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
9841 struct spoolss_RouterReplyPrinterEx *r)
9843 p->rng_fault_state = true;
9844 return WERR_NOT_SUPPORTED;
9847 /****************************************************************
9849 ****************************************************************/
9851 WERROR _spoolss_44(struct pipes_struct *p,
9852 struct spoolss_44 *r)
9854 p->rng_fault_state = true;
9855 return WERR_NOT_SUPPORTED;
9858 /****************************************************************
9860 ****************************************************************/
9862 WERROR _spoolss_47(struct pipes_struct *p,
9863 struct spoolss_47 *r)
9865 p->rng_fault_state = true;
9866 return WERR_NOT_SUPPORTED;
9869 /****************************************************************
9871 ****************************************************************/
9873 WERROR _spoolss_4a(struct pipes_struct *p,
9874 struct spoolss_4a *r)
9876 p->rng_fault_state = true;
9877 return WERR_NOT_SUPPORTED;
9880 /****************************************************************
9882 ****************************************************************/
9884 WERROR _spoolss_4b(struct pipes_struct *p,
9885 struct spoolss_4b *r)
9887 p->rng_fault_state = true;
9888 return WERR_NOT_SUPPORTED;
9891 /****************************************************************
9893 ****************************************************************/
9895 WERROR _spoolss_4c(struct pipes_struct *p,
9896 struct spoolss_4c *r)
9898 p->rng_fault_state = true;
9899 return WERR_NOT_SUPPORTED;
9902 /****************************************************************
9904 ****************************************************************/
9906 WERROR _spoolss_53(struct pipes_struct *p,
9907 struct spoolss_53 *r)
9909 p->rng_fault_state = true;
9910 return WERR_NOT_SUPPORTED;
9913 /****************************************************************
9915 ****************************************************************/
9917 WERROR _spoolss_55(struct pipes_struct *p,
9918 struct spoolss_55 *r)
9920 p->rng_fault_state = true;
9921 return WERR_NOT_SUPPORTED;
9924 /****************************************************************
9926 ****************************************************************/
9928 WERROR _spoolss_56(struct pipes_struct *p,
9929 struct spoolss_56 *r)
9931 p->rng_fault_state = true;
9932 return WERR_NOT_SUPPORTED;
9935 /****************************************************************
9937 ****************************************************************/
9939 WERROR _spoolss_57(struct pipes_struct *p,
9940 struct spoolss_57 *r)
9942 p->rng_fault_state = true;
9943 return WERR_NOT_SUPPORTED;
9946 /****************************************************************
9948 ****************************************************************/
9950 WERROR _spoolss_5a(struct pipes_struct *p,
9951 struct spoolss_5a *r)
9953 p->rng_fault_state = true;
9954 return WERR_NOT_SUPPORTED;
9957 /****************************************************************
9959 ****************************************************************/
9961 WERROR _spoolss_5b(struct pipes_struct *p,
9962 struct spoolss_5b *r)
9964 p->rng_fault_state = true;
9965 return WERR_NOT_SUPPORTED;
9968 /****************************************************************
9970 ****************************************************************/
9972 WERROR _spoolss_5c(struct pipes_struct *p,
9973 struct spoolss_5c *r)
9975 p->rng_fault_state = true;
9976 return WERR_NOT_SUPPORTED;
9979 /****************************************************************
9981 ****************************************************************/
9983 WERROR _spoolss_5d(struct pipes_struct *p,
9984 struct spoolss_5d *r)
9986 p->rng_fault_state = true;
9987 return WERR_NOT_SUPPORTED;
9990 /****************************************************************
9992 ****************************************************************/
9994 WERROR _spoolss_5e(struct pipes_struct *p,
9995 struct spoolss_5e *r)
9997 p->rng_fault_state = true;
9998 return WERR_NOT_SUPPORTED;
10001 /****************************************************************
10003 ****************************************************************/
10005 WERROR _spoolss_5f(struct pipes_struct *p,
10006 struct spoolss_5f *r)
10008 p->rng_fault_state = true;
10009 return WERR_NOT_SUPPORTED;
10012 /****************************************************************
10014 ****************************************************************/
10016 WERROR _spoolss_60(struct pipes_struct *p,
10017 struct spoolss_60 *r)
10019 p->rng_fault_state = true;
10020 return WERR_NOT_SUPPORTED;
10023 /****************************************************************
10025 ****************************************************************/
10027 WERROR _spoolss_61(struct pipes_struct *p,
10028 struct spoolss_61 *r)
10030 p->rng_fault_state = true;
10031 return WERR_NOT_SUPPORTED;
10034 /****************************************************************
10036 ****************************************************************/
10038 WERROR _spoolss_62(struct pipes_struct *p,
10039 struct spoolss_62 *r)
10041 p->rng_fault_state = true;
10042 return WERR_NOT_SUPPORTED;
10045 /****************************************************************
10047 ****************************************************************/
10049 WERROR _spoolss_63(struct pipes_struct *p,
10050 struct spoolss_63 *r)
10052 p->rng_fault_state = true;
10053 return WERR_NOT_SUPPORTED;
10056 /****************************************************************
10058 ****************************************************************/
10060 WERROR _spoolss_64(struct pipes_struct *p,
10061 struct spoolss_64 *r)
10063 p->rng_fault_state = true;
10064 return WERR_NOT_SUPPORTED;
10067 /****************************************************************
10069 ****************************************************************/
10071 WERROR _spoolss_65(struct pipes_struct *p,
10072 struct spoolss_65 *r)
10074 p->rng_fault_state = true;
10075 return WERR_NOT_SUPPORTED;
10078 /****************************************************************
10079 _spoolss_GetCorePrinterDrivers
10080 ****************************************************************/
10082 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10083 struct spoolss_GetCorePrinterDrivers *r)
10085 p->rng_fault_state = true;
10086 return WERR_NOT_SUPPORTED;
10089 /****************************************************************
10091 ****************************************************************/
10093 WERROR _spoolss_67(struct pipes_struct *p,
10094 struct spoolss_67 *r)
10096 p->rng_fault_state = true;
10097 return WERR_NOT_SUPPORTED;
10100 /****************************************************************
10101 _spoolss_GetPrinterDriverPackagePath
10102 ****************************************************************/
10104 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10105 struct spoolss_GetPrinterDriverPackagePath *r)
10107 p->rng_fault_state = true;
10108 return WERR_NOT_SUPPORTED;
10111 /****************************************************************
10113 ****************************************************************/
10115 WERROR _spoolss_69(struct pipes_struct *p,
10116 struct spoolss_69 *r)
10118 p->rng_fault_state = true;
10119 return WERR_NOT_SUPPORTED;
10122 /****************************************************************
10124 ****************************************************************/
10126 WERROR _spoolss_6a(struct pipes_struct *p,
10127 struct spoolss_6a *r)
10129 p->rng_fault_state = true;
10130 return WERR_NOT_SUPPORTED;
10133 /****************************************************************
10135 ****************************************************************/
10137 WERROR _spoolss_6b(struct pipes_struct *p,
10138 struct spoolss_6b *r)
10140 p->rng_fault_state = true;
10141 return WERR_NOT_SUPPORTED;
10144 /****************************************************************
10146 ****************************************************************/
10148 WERROR _spoolss_6c(struct pipes_struct *p,
10149 struct spoolss_6c *r)
10151 p->rng_fault_state = true;
10152 return WERR_NOT_SUPPORTED;
10155 /****************************************************************
10157 ****************************************************************/
10159 WERROR _spoolss_6d(struct pipes_struct *p,
10160 struct spoolss_6d *r)
10162 p->rng_fault_state = true;
10163 return WERR_NOT_SUPPORTED;