2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Jeremy Allison 2001-2002,
8 * Copyright (C) Gerald Carter 2000-2004,
9 * Copyright (C) Tim Potter 2001-2002.
10 * Copyright (C) Guenther Deschner 2009-2010.
11 * Copyright (C) Andreas Schneider 2010.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
28 up, all the errors returned are DOS errors, not NT status codes. */
31 #include "nt_printing.h"
32 #include "srv_spoolss_util.h"
33 #include "../librpc/gen_ndr/srv_spoolss.h"
34 #include "../librpc/gen_ndr/cli_spoolss.h"
35 #include "rpc_client/init_spoolss.h"
36 #include "librpc/gen_ndr/messaging.h"
37 #include "librpc/gen_ndr/ndr_security.h"
39 #include "registry/reg_objects.h"
40 #include "include/printing.h"
42 #include "../librpc/gen_ndr/netlogon.h"
44 /* macros stolen from s4 spoolss server */
45 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
46 ((info)?ndr_size_##fn(info, level, 0):0)
48 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
49 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
51 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
52 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
54 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
57 #define DBGC_CLASS DBGC_RPC_SRV
59 static Printer_entry *printers_list;
61 typedef struct _counter_printer_0 {
62 struct _counter_printer_0 *next;
63 struct _counter_printer_0 *prev;
69 static counter_printer_0 *counter_list;
71 static struct rpc_pipe_client *notify_cli_pipe; /* print notify back-channel pipe handle*/
72 static uint32_t smb_connections = 0;
75 /* Map generic permissions to printer object specific permissions */
77 const struct standard_mapping printer_std_mapping = {
84 /* Map generic permissions to print server object specific permissions */
86 const struct standard_mapping printserver_std_mapping = {
93 /* API table for Xcv Monitor functions */
95 struct xcv_api_table {
97 WERROR(*fn) (TALLOC_CTX *mem_ctx, NT_USER_TOKEN *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
100 /********************************************************************
101 * Canonicalize servername.
102 ********************************************************************/
104 static const char *canon_servername(const char *servername)
106 const char *pservername = servername;
107 while (*pservername == '\\') {
113 /* translate between internal status numbers and NT status numbers */
114 static int nt_printj_status(int v)
120 return JOB_STATUS_PAUSED;
122 return JOB_STATUS_SPOOLING;
124 return JOB_STATUS_PRINTING;
126 return JOB_STATUS_ERROR;
128 return JOB_STATUS_DELETING;
130 return JOB_STATUS_OFFLINE;
132 return JOB_STATUS_PAPEROUT;
134 return JOB_STATUS_PRINTED;
136 return JOB_STATUS_DELETED;
138 return JOB_STATUS_BLOCKED_DEVQ;
139 case LPQ_USER_INTERVENTION:
140 return JOB_STATUS_USER_INTERVENTION;
145 static int nt_printq_status(int v)
149 return PRINTER_STATUS_PAUSED;
158 /***************************************************************************
159 Disconnect from the client
160 ****************************************************************************/
162 static void srv_spoolss_replycloseprinter(
163 int snum, struct policy_handle *handle,
164 struct messaging_context *msg_ctx)
170 * Tell the specific printing tdb we no longer want messages for this printer
171 * by deregistering our PID.
174 if (!print_notify_deregister_pid(snum))
175 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
177 /* weird if the test succeeds !!! */
178 if (smb_connections==0) {
179 DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
183 status = rpccli_spoolss_ReplyClosePrinter(notify_cli_pipe, talloc_tos(),
186 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
187 DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
188 win_errstr(result)));
190 /* if it's the last connection, deconnect the IPC$ share */
191 if (smb_connections==1) {
193 cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) );
195 * The above call shuts down the pipe also.
197 notify_cli_pipe = NULL;
199 if (msg_ctx != NULL) {
200 messaging_deregister(msg_ctx, MSG_PRINTER_NOTIFY2,
204 * Tell the serverid.tdb we're no longer
205 * interested in printer notify messages.
208 serverid_register_msg_flags(
209 messaging_server_id(msg_ctx),
210 false, FLAG_MSG_PRINT_NOTIFY);
217 /****************************************************************************
218 Functions to free a printer entry datastruct.
219 ****************************************************************************/
221 static int printer_entry_destructor(Printer_entry *Printer)
223 if (Printer->notify.client_connected == true) {
226 if ( Printer->printer_type == SPLHND_SERVER) {
228 srv_spoolss_replycloseprinter(
229 snum, &Printer->notify.client_hnd,
230 Printer->notify.msg_ctx);
231 } else if (Printer->printer_type == SPLHND_PRINTER) {
232 snum = print_queue_snum(Printer->sharename);
234 srv_spoolss_replycloseprinter(
235 snum, &Printer->notify.client_hnd,
236 Printer->notify.msg_ctx);
240 Printer->notify.flags=0;
241 Printer->notify.options=0;
242 Printer->notify.localmachine[0]='\0';
243 Printer->notify.printerlocal=0;
244 TALLOC_FREE(Printer->notify.option);
245 Printer->notify.client_connected = false;
247 TALLOC_FREE(Printer->devmode);
249 /* Remove from the internal list. */
250 DLIST_REMOVE(printers_list, Printer);
254 /****************************************************************************
255 find printer index by handle
256 ****************************************************************************/
258 static Printer_entry *find_printer_index_by_hnd(struct pipes_struct *p,
259 struct policy_handle *hnd)
261 Printer_entry *find_printer = NULL;
263 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
264 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
271 /****************************************************************************
272 Close printer index by handle.
273 ****************************************************************************/
275 static bool close_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
277 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
280 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
285 close_policy_hnd(p, hnd);
290 /****************************************************************************
291 Delete a printer given a handle.
292 ****************************************************************************/
294 static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
295 const char *sharename,
296 struct messaging_context *msg_ctx)
298 char *cmd = lp_deleteprinter_cmd();
299 char *command = NULL;
301 SE_PRIV se_printop = SE_PRINT_OPERATOR;
302 bool is_print_op = false;
304 /* can't fail if we don't try */
309 command = talloc_asprintf(ctx,
316 is_print_op = user_has_privileges( token, &se_printop );
318 DEBUG(10,("Running [%s]\n", command));
320 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
325 if ( (ret = smbrun(command, NULL)) == 0 ) {
326 /* Tell everyone we updated smb.conf. */
327 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
333 /********** END SePrintOperatorPrivlege BLOCK **********/
335 DEBUGADD(10,("returned [%d]\n", ret));
337 TALLOC_FREE(command);
340 return WERR_BADFID; /* What to return here? */
342 /* go ahead and re-read the services immediately */
344 reload_services(false);
347 if ( lp_servicenumber( sharename ) > 0 )
348 return WERR_ACCESS_DENIED;
353 /****************************************************************************
354 Delete a printer given a handle.
355 ****************************************************************************/
357 static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
359 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
363 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
369 * It turns out that Windows allows delete printer on a handle
370 * opened by an admin user, then used on a pipe handle created
371 * by an anonymous user..... but they're working on security.... riiight !
375 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
376 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
377 return WERR_ACCESS_DENIED;
380 /* this does not need a become root since the access check has been
381 done on the handle already */
383 result = winreg_delete_printer_key(p->mem_ctx, p->server_info,
384 p->msg_ctx, Printer->sharename, "");
385 if (!W_ERROR_IS_OK(result)) {
386 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
390 return delete_printer_hook(p->mem_ctx, p->server_info->ptok,
391 Printer->sharename, p->msg_ctx);
394 /****************************************************************************
395 Return the snum of a printer corresponding to an handle.
396 ****************************************************************************/
398 static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
399 int *number, struct share_params **params)
401 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
404 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
409 switch (Printer->printer_type) {
411 DEBUG(4,("short name:%s\n", Printer->sharename));
412 *number = print_queue_snum(Printer->sharename);
413 return (*number != -1);
421 /****************************************************************************
422 Set printer handle type.
423 Check if it's \\server or \\server\printer
424 ****************************************************************************/
426 static bool set_printer_hnd_printertype(Printer_entry *Printer, const char *handlename)
428 DEBUG(3,("Setting printer type=%s\n", handlename));
430 if ( strlen(handlename) < 3 ) {
431 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", handlename));
435 /* it's a print server */
436 if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
437 DEBUGADD(4,("Printer is a print server\n"));
438 Printer->printer_type = SPLHND_SERVER;
440 /* it's a printer (set_printer_hnd_name() will handle port monitors */
442 DEBUGADD(4,("Printer is a printer\n"));
443 Printer->printer_type = SPLHND_PRINTER;
449 /****************************************************************************
450 Set printer handle name.. Accept names like \\server, \\server\printer,
451 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
452 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
453 XcvDataPort() interface.
454 ****************************************************************************/
456 static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
457 struct auth_serversupplied_info *server_info,
458 struct messaging_context *msg_ctx,
459 Printer_entry *Printer,
460 const char *handlename)
463 int n_services=lp_numservices();
465 const char *printername;
466 const char *servername = NULL;
469 struct spoolss_PrinterInfo2 *info2 = NULL;
472 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
473 (unsigned long)strlen(handlename)));
475 aprinter = CONST_DISCARD(char *, handlename);
476 if ( *handlename == '\\' ) {
477 servername = canon_servername(handlename);
478 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
482 if (!is_myname_or_ipaddr(servername)) {
486 fstrcpy(Printer->servername, servername);
489 if (Printer->printer_type == SPLHND_SERVER) {
493 if (Printer->printer_type != SPLHND_PRINTER) {
497 DEBUGADD(5, ("searching for [%s]\n", aprinter));
499 /* check for the Port Monitor Interface */
500 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
501 Printer->printer_type = SPLHND_PORTMON_TCP;
502 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
505 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
506 Printer->printer_type = SPLHND_PORTMON_LOCAL;
507 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
511 /* Search all sharenames first as this is easier than pulling
512 the printer_info_2 off of disk. Don't use find_service() since
513 that calls out to map_username() */
515 /* do another loop to look for printernames */
516 for (snum = 0; !found && snum < n_services; snum++) {
517 const char *printer = lp_const_servicename(snum);
519 /* no point going on if this is not a printer */
520 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
524 /* ignore [printers] share */
525 if (strequal(printer, "printers")) {
529 fstrcpy(sname, printer);
530 if (strequal(aprinter, printer)) {
535 /* no point looking up the printer object if
536 we aren't allowing printername != sharename */
537 if (lp_force_printername(snum)) {
541 result = winreg_get_printer(mem_ctx,
547 if ( !W_ERROR_IS_OK(result) ) {
548 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
549 sname, win_errstr(result)));
553 printername = strrchr(info2->printername, '\\');
554 if (printername == NULL) {
555 printername = info2->printername;
560 if (strequal(printername, aprinter)) {
565 DEBUGADD(10, ("printername: %s\n", printername));
571 DEBUGADD(4,("Printer not found\n"));
575 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
577 fstrcpy(Printer->sharename, sname);
582 /****************************************************************************
583 Find first available printer slot. creates a printer handle for you.
584 ****************************************************************************/
586 static bool open_printer_hnd(struct pipes_struct *p, struct policy_handle *hnd,
587 const char *name, uint32_t access_granted)
589 Printer_entry *new_printer;
591 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
593 new_printer = TALLOC_ZERO_P(NULL, Printer_entry);
594 if (new_printer == NULL) {
597 talloc_set_destructor(new_printer, printer_entry_destructor);
599 if (!create_policy_hnd(p, hnd, new_printer)) {
600 TALLOC_FREE(new_printer);
604 /* Add to the internal list. */
605 DLIST_ADD(printers_list, new_printer);
607 new_printer->notify.option=NULL;
609 if (!set_printer_hnd_printertype(new_printer, name)) {
610 close_printer_handle(p, hnd);
614 if (!set_printer_hnd_name(p->mem_ctx, p->server_info, p->msg_ctx,
615 new_printer, name)) {
616 close_printer_handle(p, hnd);
620 new_printer->access_granted = access_granted;
622 DEBUG(5, ("%d printer handles active\n",
623 (int)num_pipe_handles(p)));
628 /***************************************************************************
629 check to see if the client motify handle is monitoring the notification
630 given by (notify_type, notify_field).
631 **************************************************************************/
633 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
634 uint16_t notify_field)
639 static bool is_monitoring_event(Printer_entry *p, uint16_t notify_type,
640 uint16_t notify_field)
642 struct spoolss_NotifyOption *option = p->notify.option;
646 * Flags should always be zero when the change notify
647 * is registered by the client's spooler. A user Win32 app
648 * might use the flags though instead of the NOTIFY_OPTION_INFO
657 return is_monitoring_event_flags(
658 p->notify.flags, notify_type, notify_field);
660 for (i = 0; i < option->count; i++) {
662 /* Check match for notify_type */
664 if (option->types[i].type != notify_type)
667 /* Check match for field */
669 for (j = 0; j < option->types[i].count; j++) {
670 if (option->types[i].fields[j].field == notify_field) {
676 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
677 p->servername, p->sharename, notify_type, notify_field));
682 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
683 _data->data.integer[0] = _integer; \
684 _data->data.integer[1] = 0;
687 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
688 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
689 if (!_data->data.string.string) {\
690 _data->data.string.size = 0; \
692 _data->data.string.size = strlen_m_term(_p) * 2;
694 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
695 _data->data.devmode.devmode = _devmode;
697 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
698 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
699 if (!_data->data.sd.sd) { \
700 _data->data.sd.sd_size = 0; \
702 _data->data.sd.sd_size = \
703 ndr_size_security_descriptor(_data->data.sd.sd, 0);
705 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
710 struct spoolss_Time st;
714 if (!init_systemtime(&st, t)) {
718 p = talloc_array(mem_ctx, char, len);
724 * Systemtime must be linearized as a set of UINT16's.
725 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
728 SSVAL(p, 0, st.year);
729 SSVAL(p, 2, st.month);
730 SSVAL(p, 4, st.day_of_week);
732 SSVAL(p, 8, st.hour);
733 SSVAL(p, 10, st.minute);
734 SSVAL(p, 12, st.second);
735 SSVAL(p, 14, st.millisecond);
741 /* Convert a notification message to a struct spoolss_Notify */
743 static void notify_one_value(struct spoolss_notify_msg *msg,
744 struct spoolss_Notify *data,
747 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
750 static void notify_string(struct spoolss_notify_msg *msg,
751 struct spoolss_Notify *data,
754 /* The length of the message includes the trailing \0 */
756 data->data.string.size = msg->len * 2;
757 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
758 if (!data->data.string.string) {
759 data->data.string.size = 0;
764 static void notify_system_time(struct spoolss_notify_msg *msg,
765 struct spoolss_Notify *data,
768 data->data.string.string = NULL;
769 data->data.string.size = 0;
771 if (msg->len != sizeof(time_t)) {
772 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
777 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
778 &data->data.string.string,
779 &data->data.string.size);
782 struct notify2_message_table {
784 void (*fn)(struct spoolss_notify_msg *msg,
785 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
788 static struct notify2_message_table printer_notify_table[] = {
789 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
790 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
791 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
792 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
793 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
794 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
795 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
796 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
797 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
798 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
799 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
800 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
801 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
802 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
803 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
804 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
805 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
806 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
807 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
810 static struct notify2_message_table job_notify_table[] = {
811 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
812 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
813 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
814 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
815 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
816 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
817 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
818 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
819 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
820 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
821 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
822 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
823 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
824 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
825 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
826 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
827 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
828 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
829 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
830 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
831 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
832 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
833 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
834 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
838 /***********************************************************************
839 Allocate talloc context for container object
840 **********************************************************************/
842 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
847 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
852 /***********************************************************************
853 release all allocated memory and zero out structure
854 **********************************************************************/
856 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
862 talloc_destroy(ctr->ctx);
869 /***********************************************************************
870 **********************************************************************/
872 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
880 /***********************************************************************
881 **********************************************************************/
883 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
885 if ( !ctr || !ctr->msg_groups )
888 if ( idx >= ctr->num_groups )
891 return &ctr->msg_groups[idx];
895 /***********************************************************************
896 How many groups of change messages do we have ?
897 **********************************************************************/
899 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
904 return ctr->num_groups;
907 /***********************************************************************
908 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
909 **********************************************************************/
911 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
913 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
914 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
915 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
921 /* loop over all groups looking for a matching printer name */
923 for ( i=0; i<ctr->num_groups; i++ ) {
924 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
928 /* add a new group? */
930 if ( i == ctr->num_groups ) {
933 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
934 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
937 ctr->msg_groups = groups;
939 /* clear the new entry and set the printer name */
941 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
942 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
945 /* add the change messages; 'i' is the correct index now regardless */
947 msg_grp = &ctr->msg_groups[i];
951 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
952 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
955 msg_grp->msgs = msg_list;
957 new_slot = msg_grp->num_msgs-1;
958 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
960 /* need to allocate own copy of data */
963 msg_grp->msgs[new_slot].notify.data = (char *)
964 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
966 return ctr->num_groups;
969 static void construct_info_data(struct spoolss_Notify *info_data,
970 enum spoolss_NotifyType type,
971 uint16_t field, int id);
973 /***********************************************************************
974 Send a change notication message on all handles which have a call
976 **********************************************************************/
978 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
981 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
982 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
983 SPOOLSS_NOTIFY_MSG *messages;
984 int sending_msg_count;
987 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
991 messages = msg_group->msgs;
994 DEBUG(5,("send_notify2_changes() called with no messages!\n"));
998 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
1000 /* loop over all printers */
1002 for (p = printers_list; p; p = p->next) {
1003 struct spoolss_Notify *notifies;
1008 /* Is there notification on this handle? */
1010 if ( !p->notify.client_connected )
1013 DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
1015 /* For this printer? Print servers always receive
1018 if ( ( p->printer_type == SPLHND_PRINTER ) &&
1019 ( !strequal(msg_group->printername, p->sharename) ) )
1022 DEBUG(10,("Our printer\n"));
1024 /* allocate the max entries possible */
1026 notifies = TALLOC_ZERO_ARRAY(mem_ctx, struct spoolss_Notify, msg_group->num_msgs);
1031 /* build the array of change notifications */
1033 sending_msg_count = 0;
1035 for ( i=0; i<msg_group->num_msgs; i++ ) {
1036 SPOOLSS_NOTIFY_MSG *msg = &messages[i];
1038 /* Are we monitoring this event? */
1040 if (!is_monitoring_event(p, msg->type, msg->field))
1043 sending_msg_count++;
1046 DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
1047 msg->type, msg->field, p->sharename));
1050 * if the is a printer notification handle and not a job notification
1051 * type, then set the id to 0. Other wise just use what was specified
1054 * When registering change notification on a print server handle
1055 * we always need to send back the id (snum) matching the printer
1056 * for which the change took place. For change notify registered
1057 * on a printer handle, this does not matter and the id should be 0.
1062 if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
1068 /* Convert unix jobid to smb jobid */
1070 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1071 id = sysjob_to_jobid(msg->id);
1074 DEBUG(3, ("no such unix jobid %d\n", msg->id));
1079 construct_info_data( ¬ifies[count], msg->type, msg->field, id );
1082 case PRINTER_NOTIFY_TYPE:
1083 if ( printer_notify_table[msg->field].fn )
1084 printer_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1087 case JOB_NOTIFY_TYPE:
1088 if ( job_notify_table[msg->field].fn )
1089 job_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1093 DEBUG(5, ("Unknown notification type %d\n", msg->type));
1100 if ( sending_msg_count ) {
1103 union spoolss_ReplyPrinterInfo info;
1104 struct spoolss_NotifyInfo info0;
1105 uint32_t reply_result;
1107 info0.version = 0x2;
1108 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1109 info0.count = count;
1110 info0.notifies = notifies;
1112 info.info0 = &info0;
1114 status = rpccli_spoolss_RouterReplyPrinterEx(notify_cli_pipe, mem_ctx,
1115 &p->notify.client_hnd,
1116 p->notify.change, /* color */
1119 0, /* reply_type, must be 0 */
1122 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1123 DEBUG(1,("RouterReplyPrinterEx to client: %s failed: %s\n",
1124 notify_cli_pipe->srv_name_slash,
1127 switch (reply_result) {
1130 case PRINTER_NOTIFY_INFO_DISCARDED:
1131 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1132 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1141 DEBUG(8,("send_notify2_changes: Exit...\n"));
1145 /***********************************************************************
1146 **********************************************************************/
1148 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1151 uint32_t tv_sec, tv_usec;
1154 /* Unpack message */
1156 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1159 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1161 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1164 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1165 &msg->notify.value[0], &msg->notify.value[1]);
1167 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1168 &msg->len, &msg->notify.data);
1170 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1171 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1173 tv->tv_sec = tv_sec;
1174 tv->tv_usec = tv_usec;
1177 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1178 msg->notify.value[1]));
1180 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1185 /********************************************************************
1186 Receive a notify2 message list
1187 ********************************************************************/
1189 static void receive_notify2_message_list(struct messaging_context *msg,
1192 struct server_id server_id,
1195 size_t msg_count, i;
1196 char *buf = (char *)data->data;
1199 SPOOLSS_NOTIFY_MSG notify;
1200 SPOOLSS_NOTIFY_MSG_CTR messages;
1203 if (data->length < 4) {
1204 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1208 msg_count = IVAL(buf, 0);
1211 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1213 if (msg_count == 0) {
1214 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1218 /* initialize the container */
1220 ZERO_STRUCT( messages );
1221 notify_msg_ctr_init( &messages );
1224 * build message groups for each printer identified
1225 * in a change_notify msg. Remember that a PCN message
1226 * includes the handle returned for the srv_spoolss_replyopenprinter()
1227 * call. Therefore messages are grouped according to printer handle.
1230 for ( i=0; i<msg_count; i++ ) {
1231 struct timeval msg_tv;
1233 if (msg_ptr + 4 - buf > data->length) {
1234 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1238 msg_len = IVAL(msg_ptr,0);
1241 if (msg_ptr + msg_len - buf > data->length) {
1242 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1246 /* unpack messages */
1248 ZERO_STRUCT( notify );
1249 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1252 /* add to correct list in container */
1254 notify_msg_ctr_addmsg( &messages, ¬ify );
1256 /* free memory that might have been allocated by notify2_unpack_msg() */
1258 if ( notify.len != 0 )
1259 SAFE_FREE( notify.notify.data );
1262 /* process each group of messages */
1264 num_groups = notify_msg_ctr_numgroups( &messages );
1265 for ( i=0; i<num_groups; i++ )
1266 send_notify2_changes( &messages, i );
1271 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1272 (uint32_t)msg_count ));
1274 notify_msg_ctr_destroy( &messages );
1279 /********************************************************************
1280 Send a message to ourself about new driver being installed
1281 so we can upgrade the information for each printer bound to this
1283 ********************************************************************/
1285 static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
1286 struct messaging_context *msg_ctx)
1288 int len = strlen(drivername);
1293 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1296 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
1297 MSG_PRINTER_DRVUPGRADE,
1298 (uint8_t *)drivername, len+1);
1303 /**********************************************************************
1304 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1305 over all printers, upgrading ones as necessary
1306 **********************************************************************/
1308 void do_drv_upgrade_printer(struct messaging_context *msg,
1311 struct server_id server_id,
1314 TALLOC_CTX *tmp_ctx;
1315 struct auth_serversupplied_info *server_info = NULL;
1316 struct spoolss_PrinterInfo2 *pinfo2;
1319 const char *drivername;
1321 int n_services = lp_numservices();
1324 tmp_ctx = talloc_new(NULL);
1325 if (!tmp_ctx) return;
1327 status = make_server_info_system(tmp_ctx, &server_info);
1328 if (!NT_STATUS_IS_OK(status)) {
1329 DEBUG(0, ("do_drv_upgrade_printer: "
1330 "Could not create system server_info\n"));
1334 len = MIN(data->length,sizeof(drivername)-1);
1335 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, len);
1337 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1341 DEBUG(10, ("do_drv_upgrade_printer: "
1342 "Got message for new driver [%s]\n", drivername));
1344 /* Iterate the printer list */
1346 for (snum = 0; snum < n_services; snum++) {
1347 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1351 result = winreg_get_printer(tmp_ctx, server_info, msg,
1353 lp_const_servicename(snum),
1356 if (!W_ERROR_IS_OK(result)) {
1360 if (!pinfo2->drivername) {
1364 if (strcmp(drivername, pinfo2->drivername) != 0) {
1368 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1370 /* all we care about currently is the change_id */
1371 result = winreg_printer_update_changeid(tmp_ctx,
1374 pinfo2->printername);
1376 if (!W_ERROR_IS_OK(result)) {
1377 DEBUG(3, ("do_drv_upgrade_printer: "
1378 "Failed to update changeid [%s]\n",
1379 win_errstr(result)));
1385 talloc_free(tmp_ctx);
1388 /********************************************************************
1389 Update the cache for all printq's with a registered client
1391 ********************************************************************/
1393 void update_monitored_printq_cache( void )
1395 Printer_entry *printer = printers_list;
1398 /* loop through all printers and update the cache where
1399 client_connected == true */
1402 if ( (printer->printer_type == SPLHND_PRINTER)
1403 && printer->notify.client_connected )
1405 snum = print_queue_snum(printer->sharename);
1406 print_queue_status( snum, NULL, NULL );
1409 printer = printer->next;
1415 /****************************************************************
1416 _spoolss_OpenPrinter
1417 ****************************************************************/
1419 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1420 struct spoolss_OpenPrinter *r)
1422 struct spoolss_OpenPrinterEx e;
1425 ZERO_STRUCT(e.in.userlevel);
1427 e.in.printername = r->in.printername;
1428 e.in.datatype = r->in.datatype;
1429 e.in.devmode_ctr = r->in.devmode_ctr;
1430 e.in.access_mask = r->in.access_mask;
1433 e.out.handle = r->out.handle;
1435 werr = _spoolss_OpenPrinterEx(p, &e);
1437 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1438 /* OpenPrinterEx returns this for a bad
1439 * printer name. We must return WERR_INVALID_PRINTER_NAME
1442 werr = WERR_INVALID_PRINTER_NAME;
1448 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1449 struct spoolss_DeviceMode *orig,
1450 struct spoolss_DeviceMode **dest)
1452 struct spoolss_DeviceMode *dm;
1454 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1459 /* copy all values, then duplicate strings and structs */
1462 dm->devicename = talloc_strdup(dm, orig->devicename);
1463 if (!dm->devicename) {
1466 dm->formname = talloc_strdup(dm, orig->formname);
1467 if (!dm->formname) {
1470 if (orig->driverextra_data.data) {
1471 dm->driverextra_data.data =
1472 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1473 orig->driverextra_data.length);
1474 if (!dm->driverextra_data.data) {
1483 /****************************************************************
1484 _spoolss_OpenPrinterEx
1485 ****************************************************************/
1487 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1488 struct spoolss_OpenPrinterEx *r)
1491 Printer_entry *Printer=NULL;
1493 if (!r->in.printername) {
1494 return WERR_INVALID_PARAM;
1497 /* some sanity check because you can open a printer or a print server */
1498 /* aka: \\server\printer or \\server */
1500 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1502 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1503 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1504 " for printer %s\n", r->in.printername));
1505 ZERO_STRUCTP(r->out.handle);
1506 return WERR_INVALID_PARAM;
1509 Printer = find_printer_index_by_hnd(p, r->out.handle);
1511 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1512 "handle we created for printer %s\n", r->in.printername));
1513 close_printer_handle(p, r->out.handle);
1514 ZERO_STRUCTP(r->out.handle);
1515 return WERR_INVALID_PARAM;
1519 * First case: the user is opening the print server:
1521 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1522 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1524 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1525 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1526 * or if the user is listed in the smb.conf printer admin parameter.
1528 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1529 * client view printer folder, but does not show the MSAPW.
1531 * Note: this test needs code to check access rights here too. Jeremy
1532 * could you look at this?
1534 * Second case: the user is opening a printer:
1535 * NT doesn't let us connect to a printer if the connecting user
1536 * doesn't have print permission.
1538 * Third case: user is opening a Port Monitor
1539 * access checks same as opening a handle to the print server.
1542 switch (Printer->printer_type )
1545 case SPLHND_PORTMON_TCP:
1546 case SPLHND_PORTMON_LOCAL:
1547 /* Printserver handles use global struct... */
1551 /* Map standard access rights to object specific access rights */
1553 se_map_standard(&r->in.access_mask,
1554 &printserver_std_mapping);
1556 /* Deny any object specific bits that don't apply to print
1557 servers (i.e printer and job specific bits) */
1559 r->in.access_mask &= SEC_MASK_SPECIFIC;
1561 if (r->in.access_mask &
1562 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1563 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1564 close_printer_handle(p, r->out.handle);
1565 ZERO_STRUCTP(r->out.handle);
1566 return WERR_ACCESS_DENIED;
1569 /* Allow admin access */
1571 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1573 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1575 if (!lp_ms_add_printer_wizard()) {
1576 close_printer_handle(p, r->out.handle);
1577 ZERO_STRUCTP(r->out.handle);
1578 return WERR_ACCESS_DENIED;
1581 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1582 and not a printer admin, then fail */
1584 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1585 !user_has_privileges(p->server_info->ptok,
1587 !token_contains_name_in_list(
1588 uidtoname(p->server_info->utok.uid),
1589 p->server_info->info3->base.domain.string,
1591 p->server_info->ptok,
1592 lp_printer_admin(snum))) {
1593 close_printer_handle(p, r->out.handle);
1594 ZERO_STRUCTP(r->out.handle);
1595 return WERR_ACCESS_DENIED;
1598 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1602 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1605 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1606 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1608 /* We fall through to return WERR_OK */
1611 case SPLHND_PRINTER:
1612 /* NT doesn't let us connect to a printer if the connecting user
1613 doesn't have print permission. */
1615 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1616 close_printer_handle(p, r->out.handle);
1617 ZERO_STRUCTP(r->out.handle);
1621 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1622 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1625 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1627 /* map an empty access mask to the minimum access mask */
1628 if (r->in.access_mask == 0x0)
1629 r->in.access_mask = PRINTER_ACCESS_USE;
1632 * If we are not serving the printer driver for this printer,
1633 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1634 * will keep NT clients happy --jerry
1637 if (lp_use_client_driver(snum)
1638 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1640 r->in.access_mask = PRINTER_ACCESS_USE;
1643 /* check smb.conf parameters and the the sec_desc */
1645 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1646 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1647 ZERO_STRUCTP(r->out.handle);
1648 return WERR_ACCESS_DENIED;
1651 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1652 p->server_info->ptok, snum) ||
1653 !print_access_check(p->server_info, snum,
1654 r->in.access_mask)) {
1655 DEBUG(3, ("access DENIED for printer open\n"));
1656 close_printer_handle(p, r->out.handle);
1657 ZERO_STRUCTP(r->out.handle);
1658 return WERR_ACCESS_DENIED;
1661 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1662 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1663 close_printer_handle(p, r->out.handle);
1664 ZERO_STRUCTP(r->out.handle);
1665 return WERR_ACCESS_DENIED;
1668 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1669 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1671 r->in.access_mask = PRINTER_ACCESS_USE;
1673 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1674 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1676 winreg_create_printer(p->mem_ctx,
1679 Printer->servername,
1680 lp_const_servicename(snum));
1685 /* sanity check to prevent programmer error */
1686 ZERO_STRUCTP(r->out.handle);
1690 Printer->access_granted = r->in.access_mask;
1693 * If the client sent a devmode in the OpenPrinter() call, then
1694 * save it here in case we get a job submission on this handle
1697 if ((Printer->printer_type != SPLHND_SERVER) &&
1698 r->in.devmode_ctr.devmode) {
1699 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1703 #if 0 /* JERRY -- I'm doubtful this is really effective */
1704 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1705 optimization in Windows 2000 clients --jerry */
1707 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1708 && (RA_WIN2K == get_remote_arch()) )
1710 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1711 sys_usleep( 500000 );
1718 /****************************************************************
1719 _spoolss_ClosePrinter
1720 ****************************************************************/
1722 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1723 struct spoolss_ClosePrinter *r)
1725 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1727 if (Printer && Printer->document_started) {
1728 struct spoolss_EndDocPrinter e;
1730 e.in.handle = r->in.handle;
1732 _spoolss_EndDocPrinter(p, &e);
1735 if (!close_printer_handle(p, r->in.handle))
1738 /* clear the returned printer handle. Observed behavior
1739 from Win2k server. Don't think this really matters.
1740 Previous code just copied the value of the closed
1743 ZERO_STRUCTP(r->out.handle);
1748 /****************************************************************
1749 _spoolss_DeletePrinter
1750 ****************************************************************/
1752 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1753 struct spoolss_DeletePrinter *r)
1755 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1759 if (Printer && Printer->document_started) {
1760 struct spoolss_EndDocPrinter e;
1762 e.in.handle = r->in.handle;
1764 _spoolss_EndDocPrinter(p, &e);
1767 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
1768 winreg_delete_printer_key(p->mem_ctx,
1771 lp_const_servicename(snum),
1775 result = delete_printer_handle(p, r->in.handle);
1780 /*******************************************************************
1781 * static function to lookup the version id corresponding to an
1782 * long architecture string
1783 ******************************************************************/
1785 static const struct print_architecture_table_node archi_table[]= {
1787 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1788 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1789 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1790 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
1791 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
1792 {"Windows IA64", SPL_ARCH_IA64, 3 },
1793 {"Windows x64", SPL_ARCH_X64, 3 },
1797 static int get_version_id(const char *arch)
1801 for (i=0; archi_table[i].long_archi != NULL; i++)
1803 if (strcmp(arch, archi_table[i].long_archi) == 0)
1804 return (archi_table[i].version);
1810 /****************************************************************
1811 _spoolss_DeletePrinterDriver
1812 ****************************************************************/
1814 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
1815 struct spoolss_DeletePrinterDriver *r)
1818 struct spoolss_DriverInfo8 *info = NULL;
1819 struct spoolss_DriverInfo8 *info_win2k = NULL;
1822 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1824 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1825 and not a printer admin, then fail */
1827 if ( (p->server_info->utok.uid != sec_initial_uid())
1828 && !user_has_privileges(p->server_info->ptok, &se_printop )
1829 && !token_contains_name_in_list(
1830 uidtoname(p->server_info->utok.uid),
1831 p->server_info->info3->base.domain.string,
1833 p->server_info->ptok,
1834 lp_printer_admin(-1)) )
1836 return WERR_ACCESS_DENIED;
1839 /* check that we have a valid driver name first */
1841 if ((version = get_version_id(r->in.architecture)) == -1)
1842 return WERR_INVALID_ENVIRONMENT;
1844 status = winreg_get_driver(p->mem_ctx, p->server_info, p->msg_ctx,
1845 r->in.architecture, r->in.driver,
1847 if (!W_ERROR_IS_OK(status)) {
1848 /* try for Win2k driver if "Windows NT x86" */
1850 if ( version == 2 ) {
1853 status = winreg_get_driver(p->mem_ctx, p->server_info,
1858 if (!W_ERROR_IS_OK(status)) {
1859 status = WERR_UNKNOWN_PRINTER_DRIVER;
1863 /* otherwise it was a failure */
1865 status = WERR_UNKNOWN_PRINTER_DRIVER;
1871 if (printer_driver_in_use(p->mem_ctx, p->server_info, info)) {
1872 status = WERR_PRINTER_DRIVER_IN_USE;
1877 status = winreg_get_driver(p->mem_ctx, p->server_info,
1880 r->in.driver, 3, &info_win2k);
1881 if (W_ERROR_IS_OK(status)) {
1882 /* if we get to here, we now have 2 driver info structures to remove */
1883 /* remove the Win2k driver first*/
1885 status = winreg_del_driver(p->mem_ctx,
1889 talloc_free(info_win2k);
1891 /* this should not have failed---if it did, report to client */
1892 if (!W_ERROR_IS_OK(status)) {
1898 status = winreg_del_driver(p->mem_ctx, p->server_info, p->msg_ctx,
1907 /****************************************************************
1908 _spoolss_DeletePrinterDriverEx
1909 ****************************************************************/
1911 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
1912 struct spoolss_DeletePrinterDriverEx *r)
1914 struct spoolss_DriverInfo8 *info = NULL;
1915 struct spoolss_DriverInfo8 *info_win2k = NULL;
1919 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1921 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1922 and not a printer admin, then fail */
1924 if ( (p->server_info->utok.uid != sec_initial_uid())
1925 && !user_has_privileges(p->server_info->ptok, &se_printop )
1926 && !token_contains_name_in_list(
1927 uidtoname(p->server_info->utok.uid),
1928 p->server_info->info3->base.domain.string,
1930 p->server_info->ptok, lp_printer_admin(-1)) )
1932 return WERR_ACCESS_DENIED;
1935 /* check that we have a valid driver name first */
1936 if ((version = get_version_id(r->in.architecture)) == -1) {
1937 /* this is what NT returns */
1938 return WERR_INVALID_ENVIRONMENT;
1941 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
1942 version = r->in.version;
1944 status = winreg_get_driver(p->mem_ctx, p->server_info,
1945 p->msg_ctx, r->in.architecture,
1946 r->in.driver, version, &info);
1947 if (!W_ERROR_IS_OK(status)) {
1948 status = WERR_UNKNOWN_PRINTER_DRIVER;
1951 * if the client asked for a specific version,
1952 * or this is something other than Windows NT x86,
1956 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
1959 /* try for Win2k driver if "Windows NT x86" */
1962 status = winreg_get_driver(info, p->server_info, p->msg_ctx,
1966 if (!W_ERROR_IS_OK(status)) {
1967 status = WERR_UNKNOWN_PRINTER_DRIVER;
1972 if (printer_driver_in_use(info, p->server_info, info)) {
1973 status = WERR_PRINTER_DRIVER_IN_USE;
1978 * we have a couple of cases to consider.
1979 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
1980 * then the delete should fail if **any** files overlap with
1982 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
1983 * non-overlapping files
1984 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
1985 * is set, the do not delete any files
1986 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
1989 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
1991 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
1994 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
1995 printer_driver_files_in_use(info, p->server_info, info)) {
1996 /* no idea of the correct error here */
1997 status = WERR_ACCESS_DENIED;
2002 /* also check for W32X86/3 if necessary; maybe we already have? */
2004 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2005 status = winreg_get_driver(info, p->server_info, p->msg_ctx,
2007 r->in.driver, 3, &info_win2k);
2008 if (W_ERROR_IS_OK(status)) {
2011 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2012 printer_driver_files_in_use(info, p->server_info,
2014 /* no idea of the correct error here */
2015 talloc_free(info_win2k);
2016 status = WERR_ACCESS_DENIED;
2020 /* if we get to here, we now have 2 driver info structures to remove */
2021 /* remove the Win2k driver first*/
2023 status = winreg_del_driver(info, p->server_info,
2024 p->msg_ctx, info_win2k, 3);
2026 /* this should not have failed---if it did, report to client */
2028 if (!W_ERROR_IS_OK(status)) {
2033 * now delete any associated files if delete_files is
2034 * true. Even if this part failes, we return succes
2035 * because the driver doesn not exist any more
2038 delete_driver_files(p->server_info,
2044 status = winreg_del_driver(info, p->server_info, p->msg_ctx, info,
2046 if (!W_ERROR_IS_OK(status)) {
2051 * now delete any associated files if delete_files is
2052 * true. Even if this part failes, we return succes
2053 * because the driver doesn not exist any more
2056 delete_driver_files(p->server_info, info);
2065 /********************************************************************
2066 GetPrinterData on a printer server Handle.
2067 ********************************************************************/
2069 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2071 enum winreg_Type *type,
2072 union spoolss_PrinterData *data)
2074 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2076 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2082 if (!StrCaseCmp(value, "BeepEnabled")) {
2088 if (!StrCaseCmp(value, "EventLog")) {
2090 /* formally was 0x1b */
2095 if (!StrCaseCmp(value, "NetPopup")) {
2101 if (!StrCaseCmp(value, "MajorVersion")) {
2104 /* Windows NT 4.0 seems to not allow uploading of drivers
2105 to a server that reports 0x3 as the MajorVersion.
2106 need to investigate more how Win2k gets around this .
2109 if (RA_WINNT == get_remote_arch()) {
2118 if (!StrCaseCmp(value, "MinorVersion")) {
2125 * uint32_t size = 0x114
2126 * uint32_t major = 5
2127 * uint32_t minor = [0|1]
2128 * uint32_t build = [2195|2600]
2129 * extra unicode string = e.g. "Service Pack 3"
2131 if (!StrCaseCmp(value, "OSVersion")) {
2133 enum ndr_err_code ndr_err;
2134 struct spoolss_OSVersion os;
2136 os.major = 5; /* Windows 2000 == 5.0 */
2138 os.build = 2195; /* build */
2139 os.extra_string = ""; /* leave extra string empty */
2141 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2142 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2143 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2144 return WERR_GENERAL_FAILURE;
2148 data->binary = blob;
2154 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2157 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2158 W_ERROR_HAVE_NO_MEMORY(data->string);
2163 if (!StrCaseCmp(value, "Architecture")) {
2165 data->string = talloc_strdup(mem_ctx,
2166 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2167 W_ERROR_HAVE_NO_MEMORY(data->string);
2172 if (!StrCaseCmp(value, "DsPresent")) {
2175 /* only show the publish check box if we are a
2176 member of a AD domain */
2178 if (lp_security() == SEC_ADS) {
2186 if (!StrCaseCmp(value, "DNSMachineName")) {
2187 const char *hostname = get_mydnsfullname();
2190 return WERR_BADFILE;
2194 data->string = talloc_strdup(mem_ctx, hostname);
2195 W_ERROR_HAVE_NO_MEMORY(data->string);
2202 return WERR_INVALID_PARAM;
2205 /****************************************************************
2206 _spoolss_GetPrinterData
2207 ****************************************************************/
2209 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2210 struct spoolss_GetPrinterData *r)
2212 struct spoolss_GetPrinterDataEx r2;
2214 r2.in.handle = r->in.handle;
2215 r2.in.key_name = "PrinterDriverData";
2216 r2.in.value_name = r->in.value_name;
2217 r2.in.offered = r->in.offered;
2218 r2.out.type = r->out.type;
2219 r2.out.data = r->out.data;
2220 r2.out.needed = r->out.needed;
2222 return _spoolss_GetPrinterDataEx(p, &r2);
2225 /*********************************************************
2226 Connect to the client machine.
2227 **********************************************************/
2229 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2230 struct sockaddr_storage *client_ss, const char *remote_machine)
2233 struct cli_state *the_cli;
2234 struct sockaddr_storage rm_addr;
2235 char addr[INET6_ADDRSTRLEN];
2237 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2238 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2240 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2241 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2244 print_sockaddr(addr, sizeof(addr), &rm_addr);
2246 rm_addr = *client_ss;
2247 print_sockaddr(addr, sizeof(addr), &rm_addr);
2248 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2252 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2253 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2258 /* setup the connection */
2259 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2260 &rm_addr, 0, "IPC$", "IPC",
2264 0, lp_client_signing(), NULL );
2266 if ( !NT_STATUS_IS_OK( ret ) ) {
2267 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2272 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2273 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2274 cli_shutdown(the_cli);
2279 * Ok - we have an anonymous connection to the IPC$ share.
2280 * Now start the NT Domain stuff :-).
2283 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2284 if (!NT_STATUS_IS_OK(ret)) {
2285 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2286 remote_machine, nt_errstr(ret)));
2287 cli_shutdown(the_cli);
2294 /***************************************************************************
2295 Connect to the client.
2296 ****************************************************************************/
2298 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2299 uint32_t localprinter, uint32_t type,
2300 struct policy_handle *handle,
2301 struct sockaddr_storage *client_ss,
2302 struct messaging_context *msg_ctx)
2308 * If it's the first connection, contact the client
2309 * and connect to the IPC$ share anonymously
2311 if (smb_connections==0) {
2312 fstring unix_printer;
2314 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2316 if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ss, unix_printer ))
2319 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2320 receive_notify2_message_list);
2321 /* Tell the connections db we're now interested in printer
2322 * notify messages. */
2323 serverid_register_msg_flags(messaging_server_id(msg_ctx),
2324 true, FLAG_MSG_PRINT_NOTIFY);
2328 * Tell the specific printing tdb we want messages for this printer
2329 * by registering our PID.
2332 if (!print_notify_register_pid(snum))
2333 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2337 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2345 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2346 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2347 win_errstr(result)));
2349 return (W_ERROR_IS_OK(result));
2352 /****************************************************************
2353 ****************************************************************/
2355 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2356 const struct spoolss_NotifyOption *r)
2358 struct spoolss_NotifyOption *option;
2365 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2372 if (!option->count) {
2376 option->types = talloc_zero_array(option,
2377 struct spoolss_NotifyOptionType, option->count);
2378 if (!option->types) {
2379 talloc_free(option);
2383 for (i=0; i < option->count; i++) {
2384 option->types[i] = r->types[i];
2386 if (option->types[i].count) {
2387 option->types[i].fields = talloc_zero_array(option,
2388 union spoolss_Field, option->types[i].count);
2389 if (!option->types[i].fields) {
2390 talloc_free(option);
2393 for (k=0; k<option->types[i].count; k++) {
2394 option->types[i].fields[k] =
2395 r->types[i].fields[k];
2403 /****************************************************************
2404 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2406 * before replying OK: status=0 a rpc call is made to the workstation
2407 * asking ReplyOpenPrinter
2409 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2410 * called from api_spoolss_rffpcnex
2411 ****************************************************************/
2413 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2414 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2417 struct spoolss_NotifyOption *option = r->in.notify_options;
2418 struct sockaddr_storage client_ss;
2420 /* store the notify value in the printer struct */
2422 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2425 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2426 "Invalid handle (%s:%u:%u).\n",
2427 OUR_HANDLE(r->in.handle)));
2431 Printer->notify.flags = r->in.flags;
2432 Printer->notify.options = r->in.options;
2433 Printer->notify.printerlocal = r->in.printer_local;
2434 Printer->notify.msg_ctx = p->msg_ctx;
2436 TALLOC_FREE(Printer->notify.option);
2437 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2439 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2441 /* Connect to the client machine and send a ReplyOpenPrinter */
2443 if ( Printer->printer_type == SPLHND_SERVER)
2445 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2446 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2449 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2450 "client_address is %s\n", p->client_address));
2452 if (!interpret_string_addr(&client_ss, p->client_address,
2454 return WERR_SERVER_UNAVAILABLE;
2457 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2458 Printer->notify.printerlocal, 1,
2459 &Printer->notify.client_hnd,
2460 &client_ss, p->msg_ctx))
2461 return WERR_SERVER_UNAVAILABLE;
2463 Printer->notify.client_connected = true;
2468 /*******************************************************************
2469 * fill a notify_info_data with the servername
2470 ********************************************************************/
2472 static void spoolss_notify_server_name(int snum,
2473 struct spoolss_Notify *data,
2474 print_queue_struct *queue,
2475 struct spoolss_PrinterInfo2 *pinfo2,
2476 TALLOC_CTX *mem_ctx)
2478 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2481 /*******************************************************************
2482 * fill a notify_info_data with the printername (not including the servername).
2483 ********************************************************************/
2485 static void spoolss_notify_printer_name(int snum,
2486 struct spoolss_Notify *data,
2487 print_queue_struct *queue,
2488 struct spoolss_PrinterInfo2 *pinfo2,
2489 TALLOC_CTX *mem_ctx)
2491 /* the notify name should not contain the \\server\ part */
2492 const char *p = strrchr(pinfo2->printername, '\\');
2495 p = pinfo2->printername;
2500 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2503 /*******************************************************************
2504 * fill a notify_info_data with the servicename
2505 ********************************************************************/
2507 static void spoolss_notify_share_name(int snum,
2508 struct spoolss_Notify *data,
2509 print_queue_struct *queue,
2510 struct spoolss_PrinterInfo2 *pinfo2,
2511 TALLOC_CTX *mem_ctx)
2513 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2516 /*******************************************************************
2517 * fill a notify_info_data with the port name
2518 ********************************************************************/
2520 static void spoolss_notify_port_name(int snum,
2521 struct spoolss_Notify *data,
2522 print_queue_struct *queue,
2523 struct spoolss_PrinterInfo2 *pinfo2,
2524 TALLOC_CTX *mem_ctx)
2526 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2529 /*******************************************************************
2530 * fill a notify_info_data with the printername
2531 * but it doesn't exist, have to see what to do
2532 ********************************************************************/
2534 static void spoolss_notify_driver_name(int snum,
2535 struct spoolss_Notify *data,
2536 print_queue_struct *queue,
2537 struct spoolss_PrinterInfo2 *pinfo2,
2538 TALLOC_CTX *mem_ctx)
2540 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2543 /*******************************************************************
2544 * fill a notify_info_data with the comment
2545 ********************************************************************/
2547 static void spoolss_notify_comment(int snum,
2548 struct spoolss_Notify *data,
2549 print_queue_struct *queue,
2550 struct spoolss_PrinterInfo2 *pinfo2,
2551 TALLOC_CTX *mem_ctx)
2555 if (*pinfo2->comment == '\0') {
2556 p = lp_comment(snum);
2558 p = pinfo2->comment;
2561 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2564 /*******************************************************************
2565 * fill a notify_info_data with the comment
2566 * location = "Room 1, floor 2, building 3"
2567 ********************************************************************/
2569 static void spoolss_notify_location(int snum,
2570 struct spoolss_Notify *data,
2571 print_queue_struct *queue,
2572 struct spoolss_PrinterInfo2 *pinfo2,
2573 TALLOC_CTX *mem_ctx)
2575 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
2578 /*******************************************************************
2579 * fill a notify_info_data with the device mode
2580 * jfm:xxxx don't to it for know but that's a real problem !!!
2581 ********************************************************************/
2583 static void spoolss_notify_devmode(int snum,
2584 struct spoolss_Notify *data,
2585 print_queue_struct *queue,
2586 struct spoolss_PrinterInfo2 *pinfo2,
2587 TALLOC_CTX *mem_ctx)
2589 /* for a dummy implementation we have to zero the fields */
2590 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2593 /*******************************************************************
2594 * fill a notify_info_data with the separator file name
2595 ********************************************************************/
2597 static void spoolss_notify_sepfile(int snum,
2598 struct spoolss_Notify *data,
2599 print_queue_struct *queue,
2600 struct spoolss_PrinterInfo2 *pinfo2,
2601 TALLOC_CTX *mem_ctx)
2603 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2606 /*******************************************************************
2607 * fill a notify_info_data with the print processor
2608 * jfm:xxxx return always winprint to indicate we don't do anything to it
2609 ********************************************************************/
2611 static void spoolss_notify_print_processor(int snum,
2612 struct spoolss_Notify *data,
2613 print_queue_struct *queue,
2614 struct spoolss_PrinterInfo2 *pinfo2,
2615 TALLOC_CTX *mem_ctx)
2617 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2620 /*******************************************************************
2621 * fill a notify_info_data with the print processor options
2622 * jfm:xxxx send an empty string
2623 ********************************************************************/
2625 static void spoolss_notify_parameters(int snum,
2626 struct spoolss_Notify *data,
2627 print_queue_struct *queue,
2628 struct spoolss_PrinterInfo2 *pinfo2,
2629 TALLOC_CTX *mem_ctx)
2631 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2634 /*******************************************************************
2635 * fill a notify_info_data with the data type
2636 * jfm:xxxx always send RAW as data type
2637 ********************************************************************/
2639 static void spoolss_notify_datatype(int snum,
2640 struct spoolss_Notify *data,
2641 print_queue_struct *queue,
2642 struct spoolss_PrinterInfo2 *pinfo2,
2643 TALLOC_CTX *mem_ctx)
2645 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2648 /*******************************************************************
2649 * fill a notify_info_data with the security descriptor
2650 * jfm:xxxx send an null pointer to say no security desc
2651 * have to implement security before !
2652 ********************************************************************/
2654 static void spoolss_notify_security_desc(int snum,
2655 struct spoolss_Notify *data,
2656 print_queue_struct *queue,
2657 struct spoolss_PrinterInfo2 *pinfo2,
2658 TALLOC_CTX *mem_ctx)
2660 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2663 /*******************************************************************
2664 * fill a notify_info_data with the attributes
2665 * jfm:xxxx a samba printer is always shared
2666 ********************************************************************/
2668 static void spoolss_notify_attributes(int snum,
2669 struct spoolss_Notify *data,
2670 print_queue_struct *queue,
2671 struct spoolss_PrinterInfo2 *pinfo2,
2672 TALLOC_CTX *mem_ctx)
2674 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2677 /*******************************************************************
2678 * fill a notify_info_data with the priority
2679 ********************************************************************/
2681 static void spoolss_notify_priority(int snum,
2682 struct spoolss_Notify *data,
2683 print_queue_struct *queue,
2684 struct spoolss_PrinterInfo2 *pinfo2,
2685 TALLOC_CTX *mem_ctx)
2687 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2690 /*******************************************************************
2691 * fill a notify_info_data with the default priority
2692 ********************************************************************/
2694 static void spoolss_notify_default_priority(int snum,
2695 struct spoolss_Notify *data,
2696 print_queue_struct *queue,
2697 struct spoolss_PrinterInfo2 *pinfo2,
2698 TALLOC_CTX *mem_ctx)
2700 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
2703 /*******************************************************************
2704 * fill a notify_info_data with the start time
2705 ********************************************************************/
2707 static void spoolss_notify_start_time(int snum,
2708 struct spoolss_Notify *data,
2709 print_queue_struct *queue,
2710 struct spoolss_PrinterInfo2 *pinfo2,
2711 TALLOC_CTX *mem_ctx)
2713 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
2716 /*******************************************************************
2717 * fill a notify_info_data with the until time
2718 ********************************************************************/
2720 static void spoolss_notify_until_time(int snum,
2721 struct spoolss_Notify *data,
2722 print_queue_struct *queue,
2723 struct spoolss_PrinterInfo2 *pinfo2,
2724 TALLOC_CTX *mem_ctx)
2726 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
2729 /*******************************************************************
2730 * fill a notify_info_data with the status
2731 ********************************************************************/
2733 static void spoolss_notify_status(int snum,
2734 struct spoolss_Notify *data,
2735 print_queue_struct *queue,
2736 struct spoolss_PrinterInfo2 *pinfo2,
2737 TALLOC_CTX *mem_ctx)
2739 print_status_struct status;
2741 print_queue_length(snum, &status);
2742 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
2745 /*******************************************************************
2746 * fill a notify_info_data with the number of jobs queued
2747 ********************************************************************/
2749 static void spoolss_notify_cjobs(int snum,
2750 struct spoolss_Notify *data,
2751 print_queue_struct *queue,
2752 struct spoolss_PrinterInfo2 *pinfo2,
2753 TALLOC_CTX *mem_ctx)
2755 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
2758 /*******************************************************************
2759 * fill a notify_info_data with the average ppm
2760 ********************************************************************/
2762 static void spoolss_notify_average_ppm(int snum,
2763 struct spoolss_Notify *data,
2764 print_queue_struct *queue,
2765 struct spoolss_PrinterInfo2 *pinfo2,
2766 TALLOC_CTX *mem_ctx)
2768 /* always respond 8 pages per minutes */
2769 /* a little hard ! */
2770 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
2773 /*******************************************************************
2774 * fill a notify_info_data with username
2775 ********************************************************************/
2777 static void spoolss_notify_username(int snum,
2778 struct spoolss_Notify *data,
2779 print_queue_struct *queue,
2780 struct spoolss_PrinterInfo2 *pinfo2,
2781 TALLOC_CTX *mem_ctx)
2783 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
2786 /*******************************************************************
2787 * fill a notify_info_data with job status
2788 ********************************************************************/
2790 static void spoolss_notify_job_status(int snum,
2791 struct spoolss_Notify *data,
2792 print_queue_struct *queue,
2793 struct spoolss_PrinterInfo2 *pinfo2,
2794 TALLOC_CTX *mem_ctx)
2796 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
2799 /*******************************************************************
2800 * fill a notify_info_data with job name
2801 ********************************************************************/
2803 static void spoolss_notify_job_name(int snum,
2804 struct spoolss_Notify *data,
2805 print_queue_struct *queue,
2806 struct spoolss_PrinterInfo2 *pinfo2,
2807 TALLOC_CTX *mem_ctx)
2809 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
2812 /*******************************************************************
2813 * fill a notify_info_data with job status
2814 ********************************************************************/
2816 static void spoolss_notify_job_status_string(int snum,
2817 struct spoolss_Notify *data,
2818 print_queue_struct *queue,
2819 struct spoolss_PrinterInfo2 *pinfo2,
2820 TALLOC_CTX *mem_ctx)
2823 * Now we're returning job status codes we just return a "" here. JRA.
2828 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
2831 switch (queue->status) {
2836 p = ""; /* NT provides the paused string */
2845 #endif /* NO LONGER NEEDED. */
2847 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2850 /*******************************************************************
2851 * fill a notify_info_data with job time
2852 ********************************************************************/
2854 static void spoolss_notify_job_time(int snum,
2855 struct spoolss_Notify *data,
2856 print_queue_struct *queue,
2857 struct spoolss_PrinterInfo2 *pinfo2,
2858 TALLOC_CTX *mem_ctx)
2860 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2863 /*******************************************************************
2864 * fill a notify_info_data with job size
2865 ********************************************************************/
2867 static void spoolss_notify_job_size(int snum,
2868 struct spoolss_Notify *data,
2869 print_queue_struct *queue,
2870 struct spoolss_PrinterInfo2 *pinfo2,
2871 TALLOC_CTX *mem_ctx)
2873 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
2876 /*******************************************************************
2877 * fill a notify_info_data with page info
2878 ********************************************************************/
2879 static void spoolss_notify_total_pages(int snum,
2880 struct spoolss_Notify *data,
2881 print_queue_struct *queue,
2882 struct spoolss_PrinterInfo2 *pinfo2,
2883 TALLOC_CTX *mem_ctx)
2885 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
2888 /*******************************************************************
2889 * fill a notify_info_data with pages printed info.
2890 ********************************************************************/
2891 static void spoolss_notify_pages_printed(int snum,
2892 struct spoolss_Notify *data,
2893 print_queue_struct *queue,
2894 struct spoolss_PrinterInfo2 *pinfo2,
2895 TALLOC_CTX *mem_ctx)
2897 /* Add code when back-end tracks this */
2898 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2901 /*******************************************************************
2902 Fill a notify_info_data with job position.
2903 ********************************************************************/
2905 static void spoolss_notify_job_position(int snum,
2906 struct spoolss_Notify *data,
2907 print_queue_struct *queue,
2908 struct spoolss_PrinterInfo2 *pinfo2,
2909 TALLOC_CTX *mem_ctx)
2911 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
2914 /*******************************************************************
2915 Fill a notify_info_data with submitted time.
2916 ********************************************************************/
2918 static void spoolss_notify_submitted_time(int snum,
2919 struct spoolss_Notify *data,
2920 print_queue_struct *queue,
2921 struct spoolss_PrinterInfo2 *pinfo2,
2922 TALLOC_CTX *mem_ctx)
2924 data->data.string.string = NULL;
2925 data->data.string.size = 0;
2927 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
2928 &data->data.string.string,
2929 &data->data.string.size);
2933 struct s_notify_info_data_table
2935 enum spoolss_NotifyType type;
2938 enum spoolss_NotifyTable variable_type;
2939 void (*fn) (int snum, struct spoolss_Notify *data,
2940 print_queue_struct *queue,
2941 struct spoolss_PrinterInfo2 *pinfo2,
2942 TALLOC_CTX *mem_ctx);
2945 /* A table describing the various print notification constants and
2946 whether the notification data is a pointer to a variable sized
2947 buffer, a one value uint32_t or a two value uint32_t. */
2949 static const struct s_notify_info_data_table notify_info_data_table[] =
2951 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2952 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2953 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
2954 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2955 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2956 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
2957 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
2958 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2959 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
2960 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2961 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2962 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2963 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
2964 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
2965 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2966 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
2967 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2968 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2969 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
2970 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
2971 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
2972 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
2973 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
2974 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2975 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
2976 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2977 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2978 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2979 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2980 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2981 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2982 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2983 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2984 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2985 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2986 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2987 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
2988 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
2989 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
2990 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
2991 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2992 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
2993 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
2994 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2995 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2996 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
2997 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
2998 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
2999 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3002 /*******************************************************************
3003 Return the variable_type of info_data structure.
3004 ********************************************************************/
3006 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3011 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3012 if ( (notify_info_data_table[i].type == type) &&
3013 (notify_info_data_table[i].field == field) ) {
3014 return notify_info_data_table[i].variable_type;
3018 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3023 /****************************************************************************
3024 ****************************************************************************/
3026 static bool search_notify(enum spoolss_NotifyType type,
3032 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3033 if (notify_info_data_table[i].type == type &&
3034 notify_info_data_table[i].field == field &&
3035 notify_info_data_table[i].fn != NULL) {
3044 /****************************************************************************
3045 ****************************************************************************/
3047 static void construct_info_data(struct spoolss_Notify *info_data,
3048 enum spoolss_NotifyType type,
3049 uint16_t field, int id)
3051 info_data->type = type;
3052 info_data->field.field = field;
3053 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3054 info_data->job_id = id;
3057 /*******************************************************************
3059 * fill a notify_info struct with info asked
3061 ********************************************************************/
3063 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3064 struct spoolss_NotifyInfo *info,
3065 struct spoolss_PrinterInfo2 *pinfo2,
3067 const struct spoolss_NotifyOptionType *option_type,
3069 TALLOC_CTX *mem_ctx)
3072 enum spoolss_NotifyType type;
3075 struct spoolss_Notify *current_data;
3076 print_queue_struct *queue=NULL;
3078 type = option_type->type;
3080 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3081 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3082 option_type->count, lp_servicename(snum)));
3084 for(field_num=0; field_num < option_type->count; field_num++) {
3085 field = option_type->fields[field_num].field;
3087 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3089 if (!search_notify(type, field, &j) )
3092 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3093 struct spoolss_Notify,
3095 if (info->notifies == NULL) {
3096 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3100 current_data = &info->notifies[info->count];
3102 construct_info_data(current_data, type, field, id);
3104 DEBUG(10, ("construct_notify_printer_info: "
3105 "calling [%s] snum=%d printername=[%s])\n",
3106 notify_info_data_table[j].name, snum,
3107 pinfo2->printername));
3109 notify_info_data_table[j].fn(snum, current_data, queue,
3118 /*******************************************************************
3120 * fill a notify_info struct with info asked
3122 ********************************************************************/
3124 static bool construct_notify_jobs_info(print_queue_struct *queue,
3125 struct spoolss_NotifyInfo *info,
3126 struct spoolss_PrinterInfo2 *pinfo2,
3128 const struct spoolss_NotifyOptionType *option_type,
3130 TALLOC_CTX *mem_ctx)
3133 enum spoolss_NotifyType type;
3135 struct spoolss_Notify *current_data;
3137 DEBUG(4,("construct_notify_jobs_info\n"));
3139 type = option_type->type;
3141 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3142 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3143 option_type->count));
3145 for(field_num=0; field_num<option_type->count; field_num++) {
3146 field = option_type->fields[field_num].field;
3148 if (!search_notify(type, field, &j) )
3151 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3152 struct spoolss_Notify,
3154 if (info->notifies == NULL) {
3155 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3159 current_data=&(info->notifies[info->count]);
3161 construct_info_data(current_data, type, field, id);
3162 notify_info_data_table[j].fn(snum, current_data, queue,
3171 * JFM: The enumeration is not that simple, it's even non obvious.
3173 * let's take an example: I want to monitor the PRINTER SERVER for
3174 * the printer's name and the number of jobs currently queued.
3175 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3176 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3178 * I have 3 printers on the back of my server.
3180 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3183 * 1 printer 1 name 1
3184 * 2 printer 1 cjob 1
3185 * 3 printer 2 name 2
3186 * 4 printer 2 cjob 2
3187 * 5 printer 3 name 3
3188 * 6 printer 3 name 3
3190 * that's the print server case, the printer case is even worse.
3193 /*******************************************************************
3195 * enumerate all printers on the printserver
3196 * fill a notify_info struct with info asked
3198 ********************************************************************/
3200 static WERROR printserver_notify_info(struct pipes_struct *p,
3201 struct policy_handle *hnd,
3202 struct spoolss_NotifyInfo *info,
3203 TALLOC_CTX *mem_ctx)
3206 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3207 int n_services=lp_numservices();
3209 struct spoolss_NotifyOption *option;
3210 struct spoolss_NotifyOptionType option_type;
3211 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3214 DEBUG(4,("printserver_notify_info\n"));
3219 option = Printer->notify.option;
3222 info->notifies = NULL;
3225 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3226 sending a ffpcn() request first */
3231 for (i=0; i<option->count; i++) {
3232 option_type = option->types[i];
3234 if (option_type.type != PRINTER_NOTIFY_TYPE)
3237 for (snum = 0; snum < n_services; snum++) {
3238 if (!lp_browseable(snum) ||
3239 !lp_snum_ok(snum) ||
3240 !lp_print_ok(snum)) {
3241 continue; /* skip */
3244 /* Maybe we should use the SYSTEM server_info here... */
3245 result = winreg_get_printer(mem_ctx, p->server_info,
3247 Printer->servername,
3248 lp_servicename(snum),
3250 if (!W_ERROR_IS_OK(result)) {
3251 DEBUG(4, ("printserver_notify_info: "
3252 "Failed to get printer [%s]\n",
3253 lp_servicename(snum)));
3258 construct_notify_printer_info(Printer, info,
3263 TALLOC_FREE(pinfo2);
3269 * Debugging information, don't delete.
3272 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3273 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3274 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3276 for (i=0; i<info->count; i++) {
3277 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3278 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3279 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3286 /*******************************************************************
3288 * fill a notify_info struct with info asked
3290 ********************************************************************/
3292 static WERROR printer_notify_info(struct pipes_struct *p,
3293 struct policy_handle *hnd,
3294 struct spoolss_NotifyInfo *info,
3295 TALLOC_CTX *mem_ctx)
3298 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3301 struct spoolss_NotifyOption *option;
3302 struct spoolss_NotifyOptionType option_type;
3304 print_queue_struct *queue=NULL;
3305 print_status_struct status;
3306 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3309 DEBUG(4,("printer_notify_info\n"));
3314 option = Printer->notify.option;
3318 info->notifies = NULL;
3321 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3322 sending a ffpcn() request first */
3327 get_printer_snum(p, hnd, &snum, NULL);
3329 /* Maybe we should use the SYSTEM server_info here... */
3330 result = winreg_get_printer(mem_ctx, p->server_info, p->msg_ctx,
3331 Printer->servername,
3332 lp_servicename(snum), &pinfo2);
3333 if (!W_ERROR_IS_OK(result)) {
3337 for (i=0; i<option->count; i++) {
3338 option_type = option->types[i];
3340 switch (option_type.type) {
3341 case PRINTER_NOTIFY_TYPE:
3342 if (construct_notify_printer_info(Printer, info,
3350 case JOB_NOTIFY_TYPE:
3352 count = print_queue_status(snum, &queue, &status);
3354 for (j=0; j<count; j++) {
3355 construct_notify_jobs_info(&queue[j], info,
3368 * Debugging information, don't delete.
3371 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3372 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3373 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3375 for (i=0; i<info->count; i++) {
3376 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3377 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3378 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3382 talloc_free(pinfo2);
3386 /****************************************************************
3387 _spoolss_RouterRefreshPrinterChangeNotify
3388 ****************************************************************/
3390 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3391 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3393 struct spoolss_NotifyInfo *info;
3395 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
3396 WERROR result = WERR_BADFID;
3398 /* we always have a spoolss_NotifyInfo struct */
3399 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3401 result = WERR_NOMEM;
3405 *r->out.info = info;
3408 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3409 "Invalid handle (%s:%u:%u).\n",
3410 OUR_HANDLE(r->in.handle)));
3414 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3417 * We are now using the change value, and
3418 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3419 * I don't have a global notification system, I'm sending back all the
3420 * informations even when _NOTHING_ has changed.
3423 /* We need to keep track of the change value to send back in
3424 RRPCN replies otherwise our updates are ignored. */
3426 Printer->notify.fnpcn = true;
3428 if (Printer->notify.client_connected) {
3429 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3430 "Saving change value in request [%x]\n",
3432 Printer->notify.change = r->in.change_low;
3435 /* just ignore the spoolss_NotifyOption */
3437 switch (Printer->printer_type) {
3439 result = printserver_notify_info(p, r->in.handle,
3443 case SPLHND_PRINTER:
3444 result = printer_notify_info(p, r->in.handle,
3449 Printer->notify.fnpcn = false;
3455 /********************************************************************
3456 * construct_printer_info_0
3457 * fill a printer_info_0 struct
3458 ********************************************************************/
3460 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3461 struct auth_serversupplied_info *server_info,
3462 struct messaging_context *msg_ctx,
3463 struct spoolss_PrinterInfo2 *info2,
3464 struct spoolss_PrinterInfo0 *r,
3468 counter_printer_0 *session_counter;
3469 struct timeval setuptime;
3470 print_status_struct status;
3472 r->printername = talloc_strdup(mem_ctx, info2->printername);
3473 W_ERROR_HAVE_NO_MEMORY(r->printername);
3475 r->servername = talloc_strdup(mem_ctx, info2->servername);
3476 W_ERROR_HAVE_NO_MEMORY(r->servername);
3478 count = print_queue_length(snum, &status);
3480 /* check if we already have a counter for this printer */
3481 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3482 if (session_counter->snum == snum)
3486 /* it's the first time, add it to the list */
3487 if (session_counter == NULL) {
3488 session_counter = SMB_MALLOC_P(counter_printer_0);
3489 W_ERROR_HAVE_NO_MEMORY(session_counter);
3490 ZERO_STRUCTP(session_counter);
3491 session_counter->snum = snum;
3492 session_counter->counter = 0;
3493 DLIST_ADD(counter_list, session_counter);
3497 session_counter->counter++;
3503 get_startup_time(&setuptime);
3504 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3507 * the global_counter should be stored in a TDB as it's common to all the clients
3508 * and should be zeroed on samba startup
3510 r->global_counter = session_counter->counter;
3512 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3513 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3514 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3515 r->free_build = SPOOLSS_RELEASE_BUILD;
3517 r->max_spooling = 0;
3518 r->session_counter = session_counter->counter;
3519 r->num_error_out_of_paper = 0x0;
3520 r->num_error_not_ready = 0x0; /* number of print failure */
3522 r->number_of_processors = 0x1;
3523 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3524 r->high_part_total_bytes = 0x0;
3526 /* ChangeID in milliseconds*/
3527 winreg_printer_get_changeid(mem_ctx, server_info, msg_ctx,
3528 info2->sharename, &r->change_id);
3530 r->last_error = WERR_OK;
3531 r->status = nt_printq_status(status.status);
3532 r->enumerate_network_printers = 0x0;
3533 r->c_setprinter = 0x0;
3534 r->processor_architecture = 0x0;
3535 r->processor_level = 0x6; /* 6 ???*/
3544 /********************************************************************
3545 * construct_printer_info1
3546 * fill a spoolss_PrinterInfo1 struct
3547 ********************************************************************/
3549 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3550 const struct spoolss_PrinterInfo2 *info2,
3552 struct spoolss_PrinterInfo1 *r,
3557 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3561 W_ERROR_HAVE_NO_MEMORY(r->description);
3563 if (info2->comment == NULL || info2->comment[0] == '\0') {
3564 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3566 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3568 W_ERROR_HAVE_NO_MEMORY(r->comment);
3570 r->name = talloc_strdup(mem_ctx, info2->printername);
3571 W_ERROR_HAVE_NO_MEMORY(r->name);
3576 /********************************************************************
3577 * construct_printer_info2
3578 * fill a spoolss_PrinterInfo2 struct
3579 ********************************************************************/
3581 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3582 const struct spoolss_PrinterInfo2 *info2,
3583 struct spoolss_PrinterInfo2 *r,
3587 print_status_struct status;
3589 count = print_queue_length(snum, &status);
3591 r->servername = talloc_strdup(mem_ctx, info2->servername);
3592 W_ERROR_HAVE_NO_MEMORY(r->servername);
3593 r->printername = talloc_strdup(mem_ctx, info2->printername);
3594 W_ERROR_HAVE_NO_MEMORY(r->printername);
3595 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3596 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3597 r->portname = talloc_strdup(mem_ctx, info2->portname);
3598 W_ERROR_HAVE_NO_MEMORY(r->portname);
3599 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
3600 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3602 if (info2->comment[0] == '\0') {
3603 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3605 r->comment = talloc_strdup(mem_ctx, info2->comment);
3607 W_ERROR_HAVE_NO_MEMORY(r->comment);
3609 r->location = talloc_strdup(mem_ctx, info2->location);
3610 W_ERROR_HAVE_NO_MEMORY(r->location);
3611 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
3612 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3613 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
3614 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3615 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
3616 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3617 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
3618 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3620 r->attributes = info2->attributes;
3622 r->priority = info2->priority;
3623 r->defaultpriority = info2->defaultpriority;
3624 r->starttime = info2->starttime;
3625 r->untiltime = info2->untiltime;
3626 r->status = nt_printq_status(status.status);
3628 r->averageppm = info2->averageppm;
3630 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3632 DEBUG(8,("Returning NULL Devicemode!\n"));
3637 if (info2->secdesc != NULL) {
3638 /* don't use talloc_steal() here unless you do a deep steal of all
3639 the SEC_DESC members */
3641 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3647 /********************************************************************
3648 * construct_printer_info3
3649 * fill a spoolss_PrinterInfo3 struct
3650 ********************************************************************/
3652 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3653 const struct spoolss_PrinterInfo2 *info2,
3654 struct spoolss_PrinterInfo3 *r,
3657 /* These are the components of the SD we are returning. */
3659 if (info2->secdesc != NULL) {
3660 /* don't use talloc_steal() here unless you do a deep steal of all
3661 the SEC_DESC members */
3663 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3664 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3670 /********************************************************************
3671 * construct_printer_info4
3672 * fill a spoolss_PrinterInfo4 struct
3673 ********************************************************************/
3675 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
3676 const struct spoolss_PrinterInfo2 *info2,
3677 struct spoolss_PrinterInfo4 *r,
3680 r->printername = talloc_strdup(mem_ctx, info2->printername);
3681 W_ERROR_HAVE_NO_MEMORY(r->printername);
3682 r->servername = talloc_strdup(mem_ctx, info2->servername);
3683 W_ERROR_HAVE_NO_MEMORY(r->servername);
3685 r->attributes = info2->attributes;
3690 /********************************************************************
3691 * construct_printer_info5
3692 * fill a spoolss_PrinterInfo5 struct
3693 ********************************************************************/
3695 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
3696 const struct spoolss_PrinterInfo2 *info2,
3697 struct spoolss_PrinterInfo5 *r,
3700 r->printername = talloc_strdup(mem_ctx, info2->printername);
3701 W_ERROR_HAVE_NO_MEMORY(r->printername);
3702 r->portname = talloc_strdup(mem_ctx, info2->portname);
3703 W_ERROR_HAVE_NO_MEMORY(r->portname);
3705 r->attributes = info2->attributes;
3707 /* these two are not used by NT+ according to MSDN */
3708 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
3709 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
3714 /********************************************************************
3715 * construct_printer_info_6
3716 * fill a spoolss_PrinterInfo6 struct
3717 ********************************************************************/
3719 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
3720 const struct spoolss_PrinterInfo2 *info2,
3721 struct spoolss_PrinterInfo6 *r,
3725 print_status_struct status;
3727 count = print_queue_length(snum, &status);
3729 r->status = nt_printq_status(status.status);
3734 /********************************************************************
3735 * construct_printer_info7
3736 * fill a spoolss_PrinterInfo7 struct
3737 ********************************************************************/
3739 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
3740 Printer_entry *print_hnd,
3741 struct spoolss_PrinterInfo7 *r,
3744 struct auth_serversupplied_info *server_info;
3748 status = make_server_info_system(mem_ctx, &server_info);
3749 if (!NT_STATUS_IS_OK(status)) {
3750 DEBUG(0, ("construct_printer_info7: "
3751 "Could not create system server_info\n"));
3755 if (is_printer_published(mem_ctx, server_info, print_hnd->servername,
3756 lp_servicename(snum), &guid, NULL)) {
3757 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
3758 r->action = DSPRINT_PUBLISH;
3760 r->guid = talloc_strdup(mem_ctx, "");
3761 r->action = DSPRINT_UNPUBLISH;
3763 W_ERROR_HAVE_NO_MEMORY(r->guid);
3765 TALLOC_FREE(server_info);
3769 /********************************************************************
3770 * construct_printer_info8
3771 * fill a spoolss_PrinterInfo8 struct
3772 ********************************************************************/
3774 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
3775 const struct spoolss_PrinterInfo2 *info2,
3776 struct spoolss_DeviceModeInfo *r,
3779 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3781 DEBUG(8,("Returning NULL Devicemode!\n"));
3788 /********************************************************************
3789 ********************************************************************/
3791 static bool snum_is_shared_printer(int snum)
3793 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
3796 /********************************************************************
3797 Spoolss_enumprinters.
3798 ********************************************************************/
3800 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
3801 struct auth_serversupplied_info *server_info,
3802 struct messaging_context *msg_ctx,
3805 union spoolss_PrinterInfo **info_p,
3809 int n_services = lp_numservices();
3810 union spoolss_PrinterInfo *info = NULL;
3812 WERROR result = WERR_OK;
3817 for (snum = 0; snum < n_services; snum++) {
3819 const char *printer;
3820 struct spoolss_PrinterInfo2 *info2;
3822 if (!snum_is_shared_printer(snum)) {
3826 printer = lp_const_servicename(snum);
3828 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
3831 result = winreg_create_printer(mem_ctx,
3836 if (!W_ERROR_IS_OK(result)) {
3840 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
3841 union spoolss_PrinterInfo,
3844 result = WERR_NOMEM;
3848 result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
3849 NULL, printer, &info2);
3850 if (!W_ERROR_IS_OK(result)) {
3856 result = construct_printer_info0(info, server_info,
3858 &info[count].info0, snum);
3861 result = construct_printer_info1(info, info2, flags,
3862 &info[count].info1, snum);
3865 result = construct_printer_info2(info, info2,
3866 &info[count].info2, snum);
3869 result = construct_printer_info4(info, info2,
3870 &info[count].info4, snum);
3873 result = construct_printer_info5(info, info2,
3874 &info[count].info5, snum);
3878 result = WERR_UNKNOWN_LEVEL;
3882 if (!W_ERROR_IS_OK(result)) {
3893 if (!W_ERROR_IS_OK(result)) {
3903 /********************************************************************
3904 * handle enumeration of printers at level 0
3905 ********************************************************************/
3907 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
3908 struct auth_serversupplied_info *server_info,
3909 struct messaging_context *msg_ctx,
3911 const char *servername,
3912 union spoolss_PrinterInfo **info,
3915 DEBUG(4,("enum_all_printers_info_0\n"));
3917 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
3918 0, flags, info, count);
3922 /********************************************************************
3923 ********************************************************************/
3925 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
3926 struct auth_serversupplied_info *server_info,
3927 struct messaging_context *msg_ctx,
3929 union spoolss_PrinterInfo **info,
3932 DEBUG(4,("enum_all_printers_info_1\n"));
3934 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
3935 1, flags, info, count);
3938 /********************************************************************
3939 enum_all_printers_info_1_local.
3940 *********************************************************************/
3942 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
3943 struct auth_serversupplied_info *server_info,
3944 struct messaging_context *msg_ctx,
3945 union spoolss_PrinterInfo **info,
3948 DEBUG(4,("enum_all_printers_info_1_local\n"));
3950 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
3951 PRINTER_ENUM_ICON8, info, count);
3954 /********************************************************************
3955 enum_all_printers_info_1_name.
3956 *********************************************************************/
3958 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
3959 struct auth_serversupplied_info *server_info,
3960 struct messaging_context *msg_ctx,
3962 union spoolss_PrinterInfo **info,
3965 const char *s = name;
3967 DEBUG(4,("enum_all_printers_info_1_name\n"));
3969 if ((name[0] == '\\') && (name[1] == '\\')) {
3973 if (!is_myname_or_ipaddr(s)) {
3974 return WERR_INVALID_NAME;
3977 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
3978 PRINTER_ENUM_ICON8, info, count);
3981 /********************************************************************
3982 enum_all_printers_info_1_network.
3983 *********************************************************************/
3985 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
3986 struct auth_serversupplied_info *server_info,
3987 struct messaging_context *msg_ctx,
3989 union spoolss_PrinterInfo **info,
3992 const char *s = name;
3994 DEBUG(4,("enum_all_printers_info_1_network\n"));
3996 /* If we respond to a enum_printers level 1 on our name with flags
3997 set to PRINTER_ENUM_REMOTE with a list of printers then these
3998 printers incorrectly appear in the APW browse list.
3999 Specifically the printers for the server appear at the workgroup
4000 level where all the other servers in the domain are
4001 listed. Windows responds to this call with a
4002 WERR_CAN_NOT_COMPLETE so we should do the same. */
4004 if (name[0] == '\\' && name[1] == '\\') {
4008 if (is_myname_or_ipaddr(s)) {
4009 return WERR_CAN_NOT_COMPLETE;
4012 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4013 PRINTER_ENUM_NAME, info, count);
4016 /********************************************************************
4017 * api_spoolss_enumprinters
4019 * called from api_spoolss_enumprinters (see this to understand)
4020 ********************************************************************/
4022 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4023 struct auth_serversupplied_info *server_info,
4024 struct messaging_context *msg_ctx,
4025 union spoolss_PrinterInfo **info,
4028 DEBUG(4,("enum_all_printers_info_2\n"));
4030 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4034 /********************************************************************
4035 * handle enumeration of printers at level 1
4036 ********************************************************************/
4038 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4039 struct auth_serversupplied_info *server_info,
4040 struct messaging_context *msg_ctx,
4043 union spoolss_PrinterInfo **info,
4046 /* Not all the flags are equals */
4048 if (flags & PRINTER_ENUM_LOCAL) {
4049 return enum_all_printers_info_1_local(mem_ctx, server_info,
4050 msg_ctx, info, count);
4053 if (flags & PRINTER_ENUM_NAME) {
4054 return enum_all_printers_info_1_name(mem_ctx, server_info,
4055 msg_ctx, name, info,
4059 if (flags & PRINTER_ENUM_NETWORK) {
4060 return enum_all_printers_info_1_network(mem_ctx, server_info,
4061 msg_ctx, name, info,
4065 return WERR_OK; /* NT4sp5 does that */
4068 /********************************************************************
4069 * handle enumeration of printers at level 2
4070 ********************************************************************/
4072 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4073 struct auth_serversupplied_info *server_info,
4075 const char *servername,
4076 union spoolss_PrinterInfo **info,
4079 if (flags & PRINTER_ENUM_LOCAL) {
4080 return enum_all_printers_info_2(mem_ctx, server_info,
4081 smbd_messaging_context(),
4085 if (flags & PRINTER_ENUM_NAME) {
4086 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4087 return WERR_INVALID_NAME;
4090 return enum_all_printers_info_2(mem_ctx, server_info,
4091 smbd_messaging_context(),
4095 if (flags & PRINTER_ENUM_REMOTE) {
4096 return WERR_UNKNOWN_LEVEL;
4102 /********************************************************************
4103 * handle enumeration of printers at level 4
4104 ********************************************************************/
4106 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4107 struct auth_serversupplied_info *server_info,
4109 const char *servername,
4110 union spoolss_PrinterInfo **info,
4113 DEBUG(4,("enum_all_printers_info_4\n"));
4115 return enum_all_printers_info_level(mem_ctx, server_info,
4116 smbd_messaging_context(),
4117 4, flags, info, count);
4121 /********************************************************************
4122 * handle enumeration of printers at level 5
4123 ********************************************************************/
4125 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4126 struct auth_serversupplied_info *server_info,
4128 const char *servername,
4129 union spoolss_PrinterInfo **info,
4132 DEBUG(4,("enum_all_printers_info_5\n"));
4134 return enum_all_printers_info_level(mem_ctx, server_info,
4135 smbd_messaging_context(),
4136 5, flags, info, count);
4139 /****************************************************************
4140 _spoolss_EnumPrinters
4141 ****************************************************************/
4143 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4144 struct spoolss_EnumPrinters *r)
4146 const char *name = NULL;
4149 /* that's an [in out] buffer */
4151 if (!r->in.buffer && (r->in.offered != 0)) {
4152 return WERR_INVALID_PARAM;
4155 DEBUG(4,("_spoolss_EnumPrinters\n"));
4159 *r->out.info = NULL;
4163 * flags==PRINTER_ENUM_NAME
4164 * if name=="" then enumerates all printers
4165 * if name!="" then enumerate the printer
4166 * flags==PRINTER_ENUM_REMOTE
4167 * name is NULL, enumerate printers
4168 * Level 2: name!="" enumerates printers, name can't be NULL
4169 * Level 3: doesn't exist
4170 * Level 4: does a local registry lookup
4171 * Level 5: same as Level 2
4175 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4176 W_ERROR_HAVE_NO_MEMORY(name);
4179 switch (r->in.level) {
4181 result = enumprinters_level0(p->mem_ctx, p->server_info,
4182 p->msg_ctx, r->in.flags, name,
4183 r->out.info, r->out.count);
4186 result = enumprinters_level1(p->mem_ctx, p->server_info,
4187 p->msg_ctx, r->in.flags, name,
4188 r->out.info, r->out.count);
4191 result = enumprinters_level2(p->mem_ctx, p->server_info,
4193 r->out.info, r->out.count);
4196 result = enumprinters_level4(p->mem_ctx, p->server_info,
4198 r->out.info, r->out.count);
4201 result = enumprinters_level5(p->mem_ctx, p->server_info,
4203 r->out.info, r->out.count);
4206 return WERR_UNKNOWN_LEVEL;
4209 if (!W_ERROR_IS_OK(result)) {
4213 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4214 spoolss_EnumPrinters,
4215 *r->out.info, r->in.level,
4217 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4218 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4220 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4223 /****************************************************************
4225 ****************************************************************/
4227 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4228 struct spoolss_GetPrinter *r)
4230 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4231 struct spoolss_PrinterInfo2 *info2 = NULL;
4232 WERROR result = WERR_OK;
4233 const char *servername = NULL;
4236 /* that's an [in out] buffer */
4238 if (!r->in.buffer && (r->in.offered != 0)) {
4239 return WERR_INVALID_PARAM;
4244 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4248 if (Printer != NULL || Printer->servername != NULL) {
4249 servername = Printer->servername;
4252 result = winreg_get_printer(p->mem_ctx,
4256 lp_const_servicename(snum),
4258 if (!W_ERROR_IS_OK(result)) {
4262 switch (r->in.level) {
4264 result = construct_printer_info0(p->mem_ctx, p->server_info,
4266 &r->out.info->info0, snum);
4269 result = construct_printer_info1(p->mem_ctx, info2,
4271 &r->out.info->info1, snum);
4274 result = construct_printer_info2(p->mem_ctx, info2,
4275 &r->out.info->info2, snum);
4278 result = construct_printer_info3(p->mem_ctx, info2,
4279 &r->out.info->info3, snum);
4282 result = construct_printer_info4(p->mem_ctx, info2,
4283 &r->out.info->info4, snum);
4286 result = construct_printer_info5(p->mem_ctx, info2,
4287 &r->out.info->info5, snum);
4290 result = construct_printer_info6(p->mem_ctx, info2,
4291 &r->out.info->info6, snum);
4294 result = construct_printer_info7(p->mem_ctx, Printer,
4295 &r->out.info->info7, snum);
4298 result = construct_printer_info8(p->mem_ctx, info2,
4299 &r->out.info->info8, snum);
4302 result = WERR_UNKNOWN_LEVEL;
4306 if (!W_ERROR_IS_OK(result)) {
4307 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4308 r->in.level, win_errstr(result)));
4309 TALLOC_FREE(r->out.info);
4313 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4314 r->out.info, r->in.level);
4315 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4317 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4320 /********************************************************************
4321 ********************************************************************/
4323 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4325 if (in && strlen(in)) { \
4326 out = talloc_strdup(mem_ctx, in); \
4328 out = talloc_strdup(mem_ctx, ""); \
4330 W_ERROR_HAVE_NO_MEMORY(out); \
4333 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4335 if (in && strlen(in)) { \
4336 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4338 out = talloc_strdup(mem_ctx, ""); \
4340 W_ERROR_HAVE_NO_MEMORY(out); \
4343 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4344 const char **string_array,
4345 const char ***presult,
4346 const char *cservername,
4350 int i, num_strings = 0;
4351 const char **array = NULL;
4353 if (string_array == NULL) {
4354 return WERR_INVALID_PARAMETER;;
4357 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4358 const char *str = NULL;
4360 if (cservername == NULL || arch == NULL) {
4361 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4363 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4366 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4373 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4374 &array, &num_strings);
4384 /********************************************************************
4385 * fill a spoolss_DriverInfo1 struct
4386 ********************************************************************/
4388 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4389 struct spoolss_DriverInfo1 *r,
4390 const struct spoolss_DriverInfo8 *driver,
4391 const char *servername)
4393 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4394 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4399 /********************************************************************
4400 * fill a spoolss_DriverInfo2 struct
4401 ********************************************************************/
4403 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4404 struct spoolss_DriverInfo2 *r,
4405 const struct spoolss_DriverInfo8 *driver,
4406 const char *servername)
4409 const char *cservername = canon_servername(servername);
4411 r->version = driver->version;
4413 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4414 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4415 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4416 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4418 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4419 driver->architecture,
4421 driver->driver_path,
4424 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4425 driver->architecture,
4430 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4431 driver->architecture,
4433 driver->config_file,
4439 /********************************************************************
4440 * fill a spoolss_DriverInfo3 struct
4441 ********************************************************************/
4443 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4444 struct spoolss_DriverInfo3 *r,
4445 const struct spoolss_DriverInfo8 *driver,
4446 const char *servername)
4448 const char *cservername = canon_servername(servername);
4450 r->version = driver->version;
4452 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4453 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4454 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4455 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4457 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4458 driver->architecture,
4460 driver->driver_path,
4463 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4464 driver->architecture,
4469 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4470 driver->architecture,
4472 driver->config_file,
4475 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4476 driver->architecture,
4481 FILL_DRIVER_STRING(mem_ctx,
4482 driver->monitor_name,
4485 FILL_DRIVER_STRING(mem_ctx,
4486 driver->default_datatype,
4487 r->default_datatype);
4489 return string_array_from_driver_info(mem_ctx,
4490 driver->dependent_files,
4491 &r->dependent_files,
4493 driver->architecture,
4497 /********************************************************************
4498 * fill a spoolss_DriverInfo4 struct
4499 ********************************************************************/
4501 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4502 struct spoolss_DriverInfo4 *r,
4503 const struct spoolss_DriverInfo8 *driver,
4504 const char *servername)
4506 const char *cservername = canon_servername(servername);
4509 r->version = driver->version;
4511 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4512 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4513 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4514 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4516 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4517 driver->architecture,
4519 driver->driver_path,
4522 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4523 driver->architecture,
4528 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4529 driver->architecture,
4531 driver->config_file,
4534 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4535 driver->architecture,
4540 result = string_array_from_driver_info(mem_ctx,
4541 driver->dependent_files,
4542 &r->dependent_files,
4544 driver->architecture,
4546 if (!W_ERROR_IS_OK(result)) {
4550 FILL_DRIVER_STRING(mem_ctx,
4551 driver->monitor_name,
4554 FILL_DRIVER_STRING(mem_ctx,
4555 driver->default_datatype,
4556 r->default_datatype);
4559 result = string_array_from_driver_info(mem_ctx,
4560 driver->previous_names,
4567 /********************************************************************
4568 * fill a spoolss_DriverInfo5 struct
4569 ********************************************************************/
4571 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4572 struct spoolss_DriverInfo5 *r,
4573 const struct spoolss_DriverInfo8 *driver,
4574 const char *servername)
4576 const char *cservername = canon_servername(servername);
4578 r->version = driver->version;
4580 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4581 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4582 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4583 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4585 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4586 driver->architecture,
4588 driver->driver_path,
4591 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4592 driver->architecture,
4597 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4598 driver->architecture,
4600 driver->config_file,
4603 r->driver_attributes = 0;
4604 r->config_version = 0;
4605 r->driver_version = 0;
4609 /********************************************************************
4610 * fill a spoolss_DriverInfo6 struct
4611 ********************************************************************/
4613 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4614 struct spoolss_DriverInfo6 *r,
4615 const struct spoolss_DriverInfo8 *driver,
4616 const char *servername)
4618 const char *cservername = canon_servername(servername);
4621 r->version = driver->version;
4623 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4624 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4625 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4626 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4628 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4629 driver->architecture,
4631 driver->driver_path,
4634 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4635 driver->architecture,
4640 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4641 driver->architecture,
4643 driver->config_file,
4646 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4647 driver->architecture,
4652 FILL_DRIVER_STRING(mem_ctx,
4653 driver->monitor_name,
4656 FILL_DRIVER_STRING(mem_ctx,
4657 driver->default_datatype,
4658 r->default_datatype);
4660 result = string_array_from_driver_info(mem_ctx,
4661 driver->dependent_files,
4662 &r->dependent_files,
4664 driver->architecture,
4666 if (!W_ERROR_IS_OK(result)) {
4670 result = string_array_from_driver_info(mem_ctx,
4671 driver->previous_names,
4674 if (!W_ERROR_IS_OK(result)) {
4678 r->driver_date = driver->driver_date;
4679 r->driver_version = driver->driver_version;
4681 FILL_DRIVER_STRING(mem_ctx,
4682 driver->manufacturer_name,
4683 r->manufacturer_name);
4684 FILL_DRIVER_STRING(mem_ctx,
4685 driver->manufacturer_url,
4686 r->manufacturer_url);
4687 FILL_DRIVER_STRING(mem_ctx,
4688 driver->hardware_id,
4690 FILL_DRIVER_STRING(mem_ctx,
4697 /********************************************************************
4698 * fill a spoolss_DriverInfo8 struct
4699 ********************************************************************/
4701 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
4702 struct spoolss_DriverInfo8 *r,
4703 const struct spoolss_DriverInfo8 *driver,
4704 const char *servername)
4706 const char *cservername = canon_servername(servername);
4709 r->version = driver->version;
4711 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4712 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4713 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4714 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4716 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4717 driver->architecture,
4719 driver->driver_path,
4722 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4723 driver->architecture,
4728 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4729 driver->architecture,
4731 driver->config_file,
4734 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4735 driver->architecture,
4740 FILL_DRIVER_STRING(mem_ctx,
4741 driver->monitor_name,
4744 FILL_DRIVER_STRING(mem_ctx,
4745 driver->default_datatype,
4746 r->default_datatype);
4748 result = string_array_from_driver_info(mem_ctx,
4749 driver->dependent_files,
4750 &r->dependent_files,
4752 driver->architecture,
4754 if (!W_ERROR_IS_OK(result)) {
4758 result = string_array_from_driver_info(mem_ctx,
4759 driver->previous_names,
4762 if (!W_ERROR_IS_OK(result)) {
4766 r->driver_date = driver->driver_date;
4767 r->driver_version = driver->driver_version;
4769 FILL_DRIVER_STRING(mem_ctx,
4770 driver->manufacturer_name,
4771 r->manufacturer_name);
4772 FILL_DRIVER_STRING(mem_ctx,
4773 driver->manufacturer_url,
4774 r->manufacturer_url);
4775 FILL_DRIVER_STRING(mem_ctx,
4776 driver->hardware_id,
4778 FILL_DRIVER_STRING(mem_ctx,
4782 FILL_DRIVER_STRING(mem_ctx,
4783 driver->print_processor,
4784 r->print_processor);
4785 FILL_DRIVER_STRING(mem_ctx,
4786 driver->vendor_setup,
4789 result = string_array_from_driver_info(mem_ctx,
4790 driver->color_profiles,
4793 if (!W_ERROR_IS_OK(result)) {
4797 FILL_DRIVER_STRING(mem_ctx,
4801 r->printer_driver_attributes = driver->printer_driver_attributes;
4803 result = string_array_from_driver_info(mem_ctx,
4804 driver->core_driver_dependencies,
4805 &r->core_driver_dependencies,
4807 if (!W_ERROR_IS_OK(result)) {
4811 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
4812 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
4817 #if 0 /* disabled until marshalling issues are resolved - gd */
4818 /********************************************************************
4819 ********************************************************************/
4821 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
4822 struct spoolss_DriverFileInfo *r,
4823 const char *cservername,
4824 const char *file_name,
4825 enum spoolss_DriverFileType file_type,
4826 uint32_t file_version)
4828 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
4829 cservername, file_name);
4830 W_ERROR_HAVE_NO_MEMORY(r->file_name);
4831 r->file_type = file_type;
4832 r->file_version = file_version;
4837 /********************************************************************
4838 ********************************************************************/
4840 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
4841 const struct spoolss_DriverInfo8 *driver,
4842 const char *cservername,
4843 struct spoolss_DriverFileInfo **info_p,
4846 struct spoolss_DriverFileInfo *info = NULL;
4854 if (strlen(driver->driver_path)) {
4855 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4856 struct spoolss_DriverFileInfo,
4858 W_ERROR_HAVE_NO_MEMORY(info);
4859 result = fill_spoolss_DriverFileInfo(info,
4862 driver->driver_path,
4863 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
4865 W_ERROR_NOT_OK_RETURN(result);
4869 if (strlen(driver->config_file)) {
4870 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4871 struct spoolss_DriverFileInfo,
4873 W_ERROR_HAVE_NO_MEMORY(info);
4874 result = fill_spoolss_DriverFileInfo(info,
4877 driver->config_file,
4878 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
4880 W_ERROR_NOT_OK_RETURN(result);
4884 if (strlen(driver->data_file)) {
4885 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4886 struct spoolss_DriverFileInfo,
4888 W_ERROR_HAVE_NO_MEMORY(info);
4889 result = fill_spoolss_DriverFileInfo(info,
4893 SPOOLSS_DRIVER_FILE_TYPE_DATA,
4895 W_ERROR_NOT_OK_RETURN(result);
4899 if (strlen(driver->help_file)) {
4900 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4901 struct spoolss_DriverFileInfo,
4903 W_ERROR_HAVE_NO_MEMORY(info);
4904 result = fill_spoolss_DriverFileInfo(info,
4908 SPOOLSS_DRIVER_FILE_TYPE_HELP,
4910 W_ERROR_NOT_OK_RETURN(result);
4914 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
4915 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4916 struct spoolss_DriverFileInfo,
4918 W_ERROR_HAVE_NO_MEMORY(info);
4919 result = fill_spoolss_DriverFileInfo(info,
4922 driver->dependent_files[i],
4923 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
4925 W_ERROR_NOT_OK_RETURN(result);
4935 /********************************************************************
4936 * fill a spoolss_DriverInfo101 struct
4937 ********************************************************************/
4939 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
4940 struct spoolss_DriverInfo101 *r,
4941 const struct spoolss_DriverInfo8 *driver,
4942 const char *servername)
4944 const char *cservername = canon_servername(servername);
4947 r->version = driver->version;
4949 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4950 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4951 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4952 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4954 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
4958 if (!W_ERROR_IS_OK(result)) {
4962 FILL_DRIVER_STRING(mem_ctx,
4963 driver->monitor_name,
4966 FILL_DRIVER_STRING(mem_ctx,
4967 driver->default_datatype,
4968 r->default_datatype);
4970 result = string_array_from_driver_info(mem_ctx,
4971 driver->previous_names,
4974 if (!W_ERROR_IS_OK(result)) {
4978 r->driver_date = driver->driver_date;
4979 r->driver_version = driver->driver_version;
4981 FILL_DRIVER_STRING(mem_ctx,
4982 driver->manufacturer_name,
4983 r->manufacturer_name);
4984 FILL_DRIVER_STRING(mem_ctx,
4985 driver->manufacturer_url,
4986 r->manufacturer_url);
4987 FILL_DRIVER_STRING(mem_ctx,
4988 driver->hardware_id,
4990 FILL_DRIVER_STRING(mem_ctx,
4997 /********************************************************************
4998 ********************************************************************/
5000 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5001 struct auth_serversupplied_info *server_info,
5003 union spoolss_DriverInfo *r,
5005 const char *servername,
5006 const char *architecture,
5009 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5010 struct spoolss_DriverInfo8 *driver;
5013 result = winreg_get_printer(mem_ctx,
5015 smbd_messaging_context(),
5017 lp_const_servicename(snum),
5020 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5021 win_errstr(result)));
5023 if (!W_ERROR_IS_OK(result)) {
5024 return WERR_INVALID_PRINTER_NAME;
5027 result = winreg_get_driver(mem_ctx, server_info,
5028 smbd_messaging_context(),
5030 pinfo2->drivername, version, &driver);
5032 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5033 win_errstr(result)));
5035 if (!W_ERROR_IS_OK(result)) {
5037 * Is this a W2k client ?
5041 talloc_free(pinfo2);
5042 return WERR_UNKNOWN_PRINTER_DRIVER;
5045 /* Yes - try again with a WinNT driver. */
5047 result = winreg_get_driver(mem_ctx, server_info,
5048 smbd_messaging_context(),
5052 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5053 win_errstr(result)));
5054 if (!W_ERROR_IS_OK(result)) {
5055 talloc_free(pinfo2);
5056 return WERR_UNKNOWN_PRINTER_DRIVER;
5062 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5065 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5068 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5071 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5074 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5077 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5080 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5082 #if 0 /* disabled until marshalling issues are resolved - gd */
5084 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5088 result = WERR_UNKNOWN_LEVEL;
5092 talloc_free(pinfo2);
5093 talloc_free(driver);
5098 /****************************************************************
5099 _spoolss_GetPrinterDriver2
5100 ****************************************************************/
5102 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5103 struct spoolss_GetPrinterDriver2 *r)
5105 Printer_entry *printer;
5110 /* that's an [in out] buffer */
5112 if (!r->in.buffer && (r->in.offered != 0)) {
5113 return WERR_INVALID_PARAM;
5116 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5118 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5119 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5120 return WERR_INVALID_PRINTER_NAME;
5124 *r->out.server_major_version = 0;
5125 *r->out.server_minor_version = 0;
5127 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5131 result = construct_printer_driver_info_level(p->mem_ctx, p->server_info,
5132 r->in.level, r->out.info,
5133 snum, printer->servername,
5135 r->in.client_major_version);
5136 if (!W_ERROR_IS_OK(result)) {
5137 TALLOC_FREE(r->out.info);
5141 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5142 r->out.info, r->in.level);
5143 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5145 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5149 /****************************************************************
5150 _spoolss_StartPagePrinter
5151 ****************************************************************/
5153 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5154 struct spoolss_StartPagePrinter *r)
5156 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5159 DEBUG(3,("_spoolss_StartPagePrinter: "
5160 "Error in startpageprinter printer handle\n"));
5164 Printer->page_started = true;
5168 /****************************************************************
5169 _spoolss_EndPagePrinter
5170 ****************************************************************/
5172 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5173 struct spoolss_EndPagePrinter *r)
5177 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5180 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5181 OUR_HANDLE(r->in.handle)));
5185 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5188 Printer->page_started = false;
5189 print_job_endpage(snum, Printer->jobid);
5194 /****************************************************************
5195 _spoolss_StartDocPrinter
5196 ****************************************************************/
5198 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5199 struct spoolss_StartDocPrinter *r)
5201 struct spoolss_DocumentInfo1 *info_1;
5203 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5207 DEBUG(2,("_spoolss_StartDocPrinter: "
5208 "Invalid handle (%s:%u:%u)\n",
5209 OUR_HANDLE(r->in.handle)));
5213 if (Printer->jobid) {
5214 DEBUG(2, ("_spoolss_StartDocPrinter: "
5215 "StartDocPrinter called twice! "
5216 "(existing jobid = %d)\n", Printer->jobid));
5217 return WERR_INVALID_HANDLE;
5220 if (r->in.level != 1) {
5221 return WERR_UNKNOWN_LEVEL;
5224 info_1 = r->in.info.info1;
5227 * a nice thing with NT is it doesn't listen to what you tell it.
5228 * when asked to send _only_ RAW datas, it tries to send datas
5231 * So I add checks like in NT Server ...
5234 if (info_1->datatype) {
5235 if (strcmp(info_1->datatype, "RAW") != 0) {
5237 return WERR_INVALID_DATATYPE;
5241 /* get the share number of the printer */
5242 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5246 werr = print_job_start(p->server_info, snum,
5247 info_1->document_name, info_1->output_file,
5248 Printer->devmode, &Printer->jobid);
5250 /* An error occured in print_job_start() so return an appropriate
5253 if (!W_ERROR_IS_OK(werr)) {
5257 Printer->document_started = true;
5258 *r->out.job_id = Printer->jobid;
5263 /****************************************************************
5264 _spoolss_EndDocPrinter
5265 ****************************************************************/
5267 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5268 struct spoolss_EndDocPrinter *r)
5270 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5275 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5276 OUR_HANDLE(r->in.handle)));
5280 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5284 Printer->document_started = false;
5285 status = print_job_end(snum, Printer->jobid, NORMAL_CLOSE);
5286 if (!NT_STATUS_IS_OK(status)) {
5287 DEBUG(2, ("_spoolss_EndDocPrinter: "
5288 "print_job_end failed [%s]\n",
5289 nt_errstr(status)));
5293 return ntstatus_to_werror(status);
5296 /****************************************************************
5297 _spoolss_WritePrinter
5298 ****************************************************************/
5300 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5301 struct spoolss_WritePrinter *r)
5303 ssize_t buffer_written;
5305 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5308 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5309 OUR_HANDLE(r->in.handle)));
5310 *r->out.num_written = r->in._data_size;
5314 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5317 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5318 buffer_written = print_job_write(snum, Printer->jobid,
5319 (const char *)r->in.data.data,
5321 (size_t)r->in._data_size);
5322 if (buffer_written == (ssize_t)-1) {
5323 *r->out.num_written = 0;
5324 if (errno == ENOSPC)
5325 return WERR_NO_SPOOL_SPACE;
5327 return WERR_ACCESS_DENIED;
5330 *r->out.num_written = r->in._data_size;
5335 /********************************************************************
5336 * api_spoolss_getprinter
5337 * called from the spoolss dispatcher
5339 ********************************************************************/
5341 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5342 struct pipes_struct *p)
5345 WERROR errcode = WERR_BADFUNC;
5346 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5349 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5350 OUR_HANDLE(handle)));
5354 if (!get_printer_snum(p, handle, &snum, NULL))
5358 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5359 errcode = print_queue_pause(p->server_info, snum);
5361 case SPOOLSS_PRINTER_CONTROL_RESUME:
5362 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5363 errcode = print_queue_resume(p->server_info, snum);
5365 case SPOOLSS_PRINTER_CONTROL_PURGE:
5366 errcode = print_queue_purge(p->server_info, snum);
5369 return WERR_UNKNOWN_LEVEL;
5376 /****************************************************************
5377 _spoolss_AbortPrinter
5378 * From MSDN: "Deletes printer's spool file if printer is configured
5380 ****************************************************************/
5382 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5383 struct spoolss_AbortPrinter *r)
5385 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5387 WERROR errcode = WERR_OK;
5390 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5391 OUR_HANDLE(r->in.handle)));
5395 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5398 if (!Printer->document_started) {
5399 return WERR_SPL_NO_STARTDOC;
5402 errcode = print_job_delete(p->server_info, snum, Printer->jobid);
5407 /********************************************************************
5408 * called by spoolss_api_setprinter
5409 * when updating a printer description
5410 ********************************************************************/
5412 static WERROR update_printer_sec(struct policy_handle *handle,
5413 struct pipes_struct *p,
5414 struct sec_desc_buf *secdesc_ctr)
5416 struct spoolss_security_descriptor *new_secdesc = NULL;
5417 struct spoolss_security_descriptor *old_secdesc = NULL;
5418 const char *printer;
5422 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5424 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5425 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5426 OUR_HANDLE(handle)));
5428 result = WERR_BADFID;
5432 if (secdesc_ctr == NULL) {
5433 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5434 result = WERR_INVALID_PARAM;
5437 printer = lp_const_servicename(snum);
5439 /* Check the user has permissions to change the security
5440 descriptor. By experimentation with two NT machines, the user
5441 requires Full Access to the printer to change security
5444 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5445 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5446 result = WERR_ACCESS_DENIED;
5450 /* NT seems to like setting the security descriptor even though
5451 nothing may have actually changed. */
5452 result = winreg_get_printer_secdesc(p->mem_ctx,
5457 if (!W_ERROR_IS_OK(result)) {
5458 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5459 result = WERR_BADFID;
5463 if (DEBUGLEVEL >= 10) {
5464 struct security_acl *the_acl;
5467 the_acl = old_secdesc->dacl;
5468 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5469 printer, the_acl->num_aces));
5471 for (i = 0; i < the_acl->num_aces; i++) {
5472 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5473 &the_acl->aces[i].trustee),
5474 the_acl->aces[i].access_mask));
5477 the_acl = secdesc_ctr->sd->dacl;
5480 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5481 printer, the_acl->num_aces));
5483 for (i = 0; i < the_acl->num_aces; i++) {
5484 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5485 &the_acl->aces[i].trustee),
5486 the_acl->aces[i].access_mask));
5489 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5493 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
5494 if (new_secdesc == NULL) {
5495 result = WERR_NOMEM;
5499 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
5504 result = winreg_set_printer_secdesc(p->mem_ctx,
5514 /********************************************************************
5515 Canonicalize printer info from a client
5516 ********************************************************************/
5518 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
5519 struct spoolss_SetPrinterInfo2 *info2,
5522 fstring printername;
5525 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5526 "portname=%s drivername=%s comment=%s location=%s\n",
5527 info2->servername, info2->printername, info2->sharename,
5528 info2->portname, info2->drivername, info2->comment,
5531 /* we force some elements to "correct" values */
5532 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
5533 if (info2->servername == NULL) {
5536 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
5537 if (info2->sharename == NULL) {
5541 /* check to see if we allow printername != sharename */
5542 if (lp_force_printername(snum)) {
5543 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5544 global_myname(), info2->sharename);
5546 /* make sure printername is in \\server\printername format */
5547 fstrcpy(printername, info2->printername);
5549 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5550 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5554 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5555 global_myname(), p);
5557 if (info2->printername == NULL) {
5561 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5562 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5567 /****************************************************************************
5568 ****************************************************************************/
5570 static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri)
5572 char *cmd = lp_addport_cmd();
5573 char *command = NULL;
5575 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5576 bool is_print_op = false;
5579 return WERR_ACCESS_DENIED;
5582 command = talloc_asprintf(ctx,
5583 "%s \"%s\" \"%s\"", cmd, portname, uri );
5589 is_print_op = user_has_privileges( token, &se_printop );
5591 DEBUG(10,("Running [%s]\n", command));
5593 /********* BEGIN SePrintOperatorPrivilege **********/
5598 ret = smbrun(command, NULL);
5603 /********* END SePrintOperatorPrivilege **********/
5605 DEBUGADD(10,("returned [%d]\n", ret));
5607 TALLOC_FREE(command);
5610 return WERR_ACCESS_DENIED;
5616 /****************************************************************************
5617 ****************************************************************************/
5619 static bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
5620 struct spoolss_SetPrinterInfo2 *info2,
5621 const char *remote_machine,
5622 struct messaging_context *msg_ctx)
5624 char *cmd = lp_addprinter_cmd();
5626 char *command = NULL;
5630 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5631 bool is_print_op = false;
5633 if (!remote_machine) {
5637 command = talloc_asprintf(ctx,
5638 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5639 cmd, info2->printername, info2->sharename,
5640 info2->portname, info2->drivername,
5641 info2->location, info2->comment, remote_machine);
5647 is_print_op = user_has_privileges( token, &se_printop );
5649 DEBUG(10,("Running [%s]\n", command));
5651 /********* BEGIN SePrintOperatorPrivilege **********/
5656 if ( (ret = smbrun(command, &fd)) == 0 ) {
5657 /* Tell everyone we updated smb.conf. */
5658 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5664 /********* END SePrintOperatorPrivilege **********/
5666 DEBUGADD(10,("returned [%d]\n", ret));
5668 TALLOC_FREE(command);
5676 /* reload our services immediately */
5678 reload_services(false);
5682 /* Get lines and convert them back to dos-codepage */
5683 qlines = fd_lines_load(fd, &numlines, 0, NULL);
5684 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
5687 /* Set the portname to what the script says the portname should be. */
5688 /* but don't require anything to be return from the script exit a good error code */
5691 /* Set the portname to what the script says the portname should be. */
5692 info2->portname = talloc_strdup(ctx, qlines[0]);
5693 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
5696 TALLOC_FREE(qlines);
5700 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
5701 struct auth_serversupplied_info *server_info,
5703 struct spoolss_SetPrinterInfo2 *printer,
5704 struct spoolss_PrinterInfo2 *old_printer)
5706 bool force_update = (old_printer == NULL);
5707 const char *dnsdomname;
5708 const char *longname;
5709 const char *uncname;
5710 const char *spooling;
5712 WERROR result = WERR_OK;
5714 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
5715 push_reg_sz(mem_ctx, &buffer, printer->drivername);
5716 winreg_set_printer_dataex(mem_ctx,
5718 smbd_messaging_context(),
5720 SPOOL_DSSPOOLER_KEY,
5721 SPOOL_REG_DRIVERNAME,
5726 if (!force_update) {
5727 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
5728 printer->drivername));
5730 notify_printer_driver(snum, printer->drivername);
5734 if (force_update || !strequal(printer->comment, old_printer->comment)) {
5735 push_reg_sz(mem_ctx, &buffer, printer->comment);
5736 winreg_set_printer_dataex(mem_ctx,
5738 smbd_messaging_context(),
5740 SPOOL_DSSPOOLER_KEY,
5741 SPOOL_REG_DESCRIPTION,
5746 if (!force_update) {
5747 notify_printer_comment(snum, printer->comment);
5751 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
5752 push_reg_sz(mem_ctx, &buffer, printer->sharename);
5753 winreg_set_printer_dataex(mem_ctx,
5755 smbd_messaging_context(),
5757 SPOOL_DSSPOOLER_KEY,
5758 SPOOL_REG_PRINTSHARENAME,
5763 if (!force_update) {
5764 notify_printer_sharename(snum, printer->sharename);
5768 if (force_update || !strequal(printer->printername, old_printer->printername)) {
5771 p = strrchr(printer->printername, '\\' );
5775 p = printer->printername;
5778 push_reg_sz(mem_ctx, &buffer, p);
5779 winreg_set_printer_dataex(mem_ctx,
5781 smbd_messaging_context(),
5783 SPOOL_DSSPOOLER_KEY,
5784 SPOOL_REG_PRINTERNAME,
5789 if (!force_update) {
5790 notify_printer_printername(snum, p);
5794 if (force_update || !strequal(printer->portname, old_printer->portname)) {
5795 push_reg_sz(mem_ctx, &buffer, printer->portname);
5796 winreg_set_printer_dataex(mem_ctx,
5798 smbd_messaging_context(),
5800 SPOOL_DSSPOOLER_KEY,
5806 if (!force_update) {
5807 notify_printer_port(snum, printer->portname);
5811 if (force_update || !strequal(printer->location, old_printer->location)) {
5812 push_reg_sz(mem_ctx, &buffer, printer->location);
5813 winreg_set_printer_dataex(mem_ctx,
5815 smbd_messaging_context(),
5817 SPOOL_DSSPOOLER_KEY,
5823 if (!force_update) {
5824 notify_printer_location(snum, printer->location);
5828 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
5829 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
5830 winreg_set_printer_dataex(mem_ctx,
5832 smbd_messaging_context(),
5834 SPOOL_DSSPOOLER_KEY,
5835 SPOOL_REG_PRINTSEPARATORFILE,
5840 if (!force_update) {
5841 notify_printer_location(snum, printer->location);
5845 if (force_update || printer->starttime != old_printer->starttime) {
5846 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5847 SIVAL(buffer.data, 0, printer->starttime);
5848 winreg_set_printer_dataex(mem_ctx,
5850 smbd_messaging_context(),
5852 SPOOL_DSSPOOLER_KEY,
5853 SPOOL_REG_PRINTSTARTTIME,
5859 if (force_update || printer->untiltime != old_printer->untiltime) {
5860 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5861 SIVAL(buffer.data, 0, printer->untiltime);
5862 winreg_set_printer_dataex(mem_ctx,
5864 smbd_messaging_context(),
5866 SPOOL_DSSPOOLER_KEY,
5867 SPOOL_REG_PRINTENDTIME,
5873 if (force_update || printer->priority != old_printer->priority) {
5874 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5875 SIVAL(buffer.data, 0, printer->priority);
5876 winreg_set_printer_dataex(mem_ctx,
5878 smbd_messaging_context(),
5880 SPOOL_DSSPOOLER_KEY,
5887 if (force_update || printer->attributes != old_printer->attributes) {
5888 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5889 SIVAL(buffer.data, 0, (printer->attributes &
5890 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
5891 winreg_set_printer_dataex(mem_ctx,
5893 smbd_messaging_context(),
5895 SPOOL_DSSPOOLER_KEY,
5896 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
5901 switch (printer->attributes & 0x3) {
5903 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
5906 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
5909 spooling = SPOOL_REGVAL_PRINTDIRECT;
5912 spooling = "unknown";
5914 push_reg_sz(mem_ctx, &buffer, spooling);
5915 winreg_set_printer_dataex(mem_ctx,
5917 smbd_messaging_context(),
5919 SPOOL_DSSPOOLER_KEY,
5920 SPOOL_REG_PRINTSPOOLING,
5926 push_reg_sz(mem_ctx, &buffer, global_myname());
5927 winreg_set_printer_dataex(mem_ctx,
5929 smbd_messaging_context(),
5931 SPOOL_DSSPOOLER_KEY,
5932 SPOOL_REG_SHORTSERVERNAME,
5937 dnsdomname = get_mydnsfullname();
5938 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
5939 longname = talloc_strdup(mem_ctx, dnsdomname);
5941 longname = talloc_strdup(mem_ctx, global_myname());
5943 if (longname == NULL) {
5944 result = WERR_NOMEM;
5948 push_reg_sz(mem_ctx, &buffer, longname);
5949 winreg_set_printer_dataex(mem_ctx,
5951 smbd_messaging_context(),
5953 SPOOL_DSSPOOLER_KEY,
5954 SPOOL_REG_SERVERNAME,
5959 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5960 global_myname(), printer->sharename);
5961 push_reg_sz(mem_ctx, &buffer, uncname);
5962 winreg_set_printer_dataex(mem_ctx,
5964 smbd_messaging_context(),
5966 SPOOL_DSSPOOLER_KEY,
5976 /********************************************************************
5977 * Called by spoolss_api_setprinter
5978 * when updating a printer description.
5979 ********************************************************************/
5981 static WERROR update_printer(struct pipes_struct *p,
5982 struct policy_handle *handle,
5983 struct spoolss_SetPrinterInfoCtr *info_ctr,
5984 struct spoolss_DeviceMode *devmode)
5986 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
5987 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
5988 struct spoolss_PrinterInfo2 *old_printer;
5989 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5990 const char *servername = NULL;
5992 WERROR result = WERR_OK;
5993 TALLOC_CTX *tmp_ctx;
5995 DEBUG(8,("update_printer\n"));
5997 tmp_ctx = talloc_new(p->mem_ctx);
5998 if (tmp_ctx == NULL) {
6003 result = WERR_BADFID;
6007 if (!get_printer_snum(p, handle, &snum, NULL)) {
6008 result = WERR_BADFID;
6012 if (Printer != NULL || Printer->servername != NULL) {
6013 servername = Printer->servername;
6016 result = winreg_get_printer(tmp_ctx,
6020 lp_const_servicename(snum),
6022 if (!W_ERROR_IS_OK(result)) {
6023 result = WERR_BADFID;
6027 /* Do sanity check on the requested changes for Samba */
6028 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6029 result = WERR_INVALID_PARAM;
6033 /* FIXME!!! If the driver has changed we really should verify that
6034 it is installed before doing much else --jerry */
6036 /* Check calling user has permission to update printer description */
6037 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6038 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6039 result = WERR_ACCESS_DENIED;
6043 /* Call addprinter hook */
6044 /* Check changes to see if this is really needed */
6046 if (*lp_addprinter_cmd() &&
6047 (!strequal(printer->drivername, old_printer->drivername) ||
6048 !strequal(printer->comment, old_printer->comment) ||
6049 !strequal(printer->portname, old_printer->portname) ||
6050 !strequal(printer->location, old_printer->location)) )
6052 /* add_printer_hook() will call reload_services() */
6053 if (!add_printer_hook(tmp_ctx, p->server_info->ptok,
6054 printer, p->client_address,
6056 result = WERR_ACCESS_DENIED;
6061 update_dsspooler(tmp_ctx,
6067 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6069 if (devmode == NULL) {
6070 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6072 result = winreg_update_printer(tmp_ctx,
6082 talloc_free(tmp_ctx);
6087 /****************************************************************************
6088 ****************************************************************************/
6089 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6090 struct policy_handle *handle,
6091 struct spoolss_SetPrinterInfo7 *info7)
6094 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6097 Printer_entry *Printer;
6099 if ( lp_security() != SEC_ADS ) {
6100 return WERR_UNKNOWN_LEVEL;
6103 Printer = find_printer_index_by_hnd(p, handle);
6105 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6110 if (!get_printer_snum(p, handle, &snum, NULL))
6113 result = winreg_get_printer(p->mem_ctx, p->server_info, p->msg_ctx,
6114 Printer->servername,
6115 lp_servicename(snum), &pinfo2);
6116 if (!W_ERROR_IS_OK(result)) {
6120 nt_printer_publish(pinfo2, p->server_info, pinfo2, info7->action);
6122 TALLOC_FREE(pinfo2);
6125 return WERR_UNKNOWN_LEVEL;
6129 /********************************************************************
6130 ********************************************************************/
6132 static WERROR update_printer_devmode(struct pipes_struct *p,
6133 struct policy_handle *handle,
6134 struct spoolss_DeviceMode *devmode)
6137 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6138 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6140 DEBUG(8,("update_printer_devmode\n"));
6146 if (!get_printer_snum(p, handle, &snum, NULL)) {
6150 /* Check calling user has permission to update printer description */
6151 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6152 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6153 return WERR_ACCESS_DENIED;
6156 return winreg_update_printer(p->mem_ctx,
6159 lp_const_servicename(snum),
6167 /****************************************************************
6169 ****************************************************************/
6171 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6172 struct spoolss_SetPrinter *r)
6176 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6179 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6180 OUR_HANDLE(r->in.handle)));
6184 /* check the level */
6185 switch (r->in.info_ctr->level) {
6187 return control_printer(r->in.handle, r->in.command, p);
6189 result = update_printer(p, r->in.handle,
6191 r->in.devmode_ctr->devmode);
6192 if (!W_ERROR_IS_OK(result))
6194 if (r->in.secdesc_ctr->sd)
6195 result = update_printer_sec(r->in.handle, p,
6199 return update_printer_sec(r->in.handle, p,
6202 return publish_or_unpublish_printer(p, r->in.handle,
6203 r->in.info_ctr->info.info7);
6205 return update_printer_devmode(p, r->in.handle,
6206 r->in.devmode_ctr->devmode);
6208 return WERR_UNKNOWN_LEVEL;
6212 /****************************************************************
6213 _spoolss_FindClosePrinterNotify
6214 ****************************************************************/
6216 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6217 struct spoolss_FindClosePrinterNotify *r)
6219 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6222 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6223 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6227 if (Printer->notify.client_connected == true) {
6230 if ( Printer->printer_type == SPLHND_SERVER)
6232 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6233 !get_printer_snum(p, r->in.handle, &snum, NULL) )
6236 srv_spoolss_replycloseprinter(
6237 snum, &Printer->notify.client_hnd, p->msg_ctx);
6240 Printer->notify.flags=0;
6241 Printer->notify.options=0;
6242 Printer->notify.localmachine[0]='\0';
6243 Printer->notify.printerlocal=0;
6244 TALLOC_FREE(Printer->notify.option);
6245 Printer->notify.client_connected = false;
6250 /****************************************************************
6252 ****************************************************************/
6254 WERROR _spoolss_AddJob(struct pipes_struct *p,
6255 struct spoolss_AddJob *r)
6257 if (!r->in.buffer && (r->in.offered != 0)) {
6258 return WERR_INVALID_PARAM;
6261 /* this is what a NT server returns for AddJob. AddJob must fail on
6262 * non-local printers */
6264 if (r->in.level != 1) {
6265 return WERR_UNKNOWN_LEVEL;
6268 return WERR_INVALID_PARAM;
6271 /****************************************************************************
6273 ****************************************************************************/
6275 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6276 struct spoolss_JobInfo1 *r,
6277 const print_queue_struct *queue,
6278 int position, int snum,
6279 struct spoolss_PrinterInfo2 *pinfo2)
6283 t = gmtime(&queue->time);
6285 r->job_id = queue->job;
6287 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6288 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6289 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6290 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6291 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6292 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6293 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6294 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6295 r->data_type = talloc_strdup(mem_ctx, "RAW");
6296 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6297 r->text_status = talloc_strdup(mem_ctx, "");
6298 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6300 r->status = nt_printj_status(queue->status);
6301 r->priority = queue->priority;
6302 r->position = position;
6303 r->total_pages = queue->page_count;
6304 r->pages_printed = 0; /* ??? */
6306 init_systemtime(&r->submitted, t);
6311 /****************************************************************************
6313 ****************************************************************************/
6315 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6316 struct spoolss_JobInfo2 *r,
6317 const print_queue_struct *queue,
6318 int position, int snum,
6319 struct spoolss_PrinterInfo2 *pinfo2,
6320 struct spoolss_DeviceMode *devmode)
6324 t = gmtime(&queue->time);
6326 r->job_id = queue->job;
6328 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6329 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6330 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6331 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6332 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6333 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6334 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6335 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6336 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6337 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6338 r->data_type = talloc_strdup(mem_ctx, "RAW");
6339 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6340 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6341 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6342 r->parameters = talloc_strdup(mem_ctx, "");
6343 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6344 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6345 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6347 r->devmode = devmode;
6349 r->text_status = talloc_strdup(mem_ctx, "");
6350 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6354 r->status = nt_printj_status(queue->status);
6355 r->priority = queue->priority;
6356 r->position = position;
6359 r->total_pages = queue->page_count;
6360 r->size = queue->size;
6361 init_systemtime(&r->submitted, t);
6363 r->pages_printed = 0; /* ??? */
6368 /****************************************************************************
6370 ****************************************************************************/
6372 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6373 struct spoolss_JobInfo3 *r,
6374 const print_queue_struct *queue,
6375 const print_queue_struct *next_queue,
6376 int position, int snum,
6377 struct spoolss_PrinterInfo2 *pinfo2)
6379 r->job_id = queue->job;
6382 r->next_job_id = next_queue->job;
6389 /****************************************************************************
6390 Enumjobs at level 1.
6391 ****************************************************************************/
6393 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6394 const print_queue_struct *queue,
6395 uint32_t num_queues, int snum,
6396 struct spoolss_PrinterInfo2 *pinfo2,
6397 union spoolss_JobInfo **info_p,
6400 union spoolss_JobInfo *info;
6402 WERROR result = WERR_OK;
6404 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6405 W_ERROR_HAVE_NO_MEMORY(info);
6407 *count = num_queues;
6409 for (i=0; i<*count; i++) {
6410 result = fill_job_info1(info,
6416 if (!W_ERROR_IS_OK(result)) {
6422 if (!W_ERROR_IS_OK(result)) {
6433 /****************************************************************************
6434 Enumjobs at level 2.
6435 ****************************************************************************/
6437 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6438 const print_queue_struct *queue,
6439 uint32_t num_queues, int snum,
6440 struct spoolss_PrinterInfo2 *pinfo2,
6441 union spoolss_JobInfo **info_p,
6444 union spoolss_JobInfo *info;
6446 WERROR result = WERR_OK;
6448 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6449 W_ERROR_HAVE_NO_MEMORY(info);
6451 *count = num_queues;
6453 for (i=0; i<*count; i++) {
6454 struct spoolss_DeviceMode *devmode;
6456 result = spoolss_create_default_devmode(info,
6457 pinfo2->printername,
6459 if (!W_ERROR_IS_OK(result)) {
6460 DEBUG(3, ("Can't proceed w/o a devmode!"));
6464 result = fill_job_info2(info,
6471 if (!W_ERROR_IS_OK(result)) {
6477 if (!W_ERROR_IS_OK(result)) {
6488 /****************************************************************************
6489 Enumjobs at level 3.
6490 ****************************************************************************/
6492 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6493 const print_queue_struct *queue,
6494 uint32_t num_queues, int snum,
6495 struct spoolss_PrinterInfo2 *pinfo2,
6496 union spoolss_JobInfo **info_p,
6499 union spoolss_JobInfo *info;
6501 WERROR result = WERR_OK;
6503 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6504 W_ERROR_HAVE_NO_MEMORY(info);
6506 *count = num_queues;
6508 for (i=0; i<*count; i++) {
6509 const print_queue_struct *next_queue = NULL;
6512 next_queue = &queue[i+1];
6515 result = fill_job_info3(info,
6522 if (!W_ERROR_IS_OK(result)) {
6528 if (!W_ERROR_IS_OK(result)) {
6539 /****************************************************************
6541 ****************************************************************/
6543 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
6544 struct spoolss_EnumJobs *r)
6547 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6549 print_status_struct prt_status;
6550 print_queue_struct *queue = NULL;
6553 /* that's an [in out] buffer */
6555 if (!r->in.buffer && (r->in.offered != 0)) {
6556 return WERR_INVALID_PARAM;
6559 DEBUG(4,("_spoolss_EnumJobs\n"));
6563 *r->out.info = NULL;
6565 /* lookup the printer snum and tdb entry */
6567 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6571 result = winreg_get_printer(p->mem_ctx, p->server_info, p->msg_ctx,
6572 NULL, lp_servicename(snum), &pinfo2);
6573 if (!W_ERROR_IS_OK(result)) {
6577 count = print_queue_status(snum, &queue, &prt_status);
6578 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6579 count, prt_status.status, prt_status.message));
6583 TALLOC_FREE(pinfo2);
6587 switch (r->in.level) {
6589 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6590 pinfo2, r->out.info, r->out.count);
6593 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6594 pinfo2, r->out.info, r->out.count);
6597 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
6598 pinfo2, r->out.info, r->out.count);
6601 result = WERR_UNKNOWN_LEVEL;
6606 TALLOC_FREE(pinfo2);
6608 if (!W_ERROR_IS_OK(result)) {
6612 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6614 *r->out.info, r->in.level,
6616 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6617 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6619 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6622 /****************************************************************
6623 _spoolss_ScheduleJob
6624 ****************************************************************/
6626 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
6627 struct spoolss_ScheduleJob *r)
6632 /****************************************************************
6633 ****************************************************************/
6635 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
6636 const char *printer_name,
6638 struct spoolss_SetJobInfo1 *r)
6642 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
6646 if (strequal(old_doc_name, r->document_name)) {
6650 if (!print_job_set_name(printer_name, job_id, r->document_name)) {
6657 /****************************************************************
6659 ****************************************************************/
6661 WERROR _spoolss_SetJob(struct pipes_struct *p,
6662 struct spoolss_SetJob *r)
6665 WERROR errcode = WERR_BADFUNC;
6667 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6671 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6672 return WERR_INVALID_PRINTER_NAME;
6675 switch (r->in.command) {
6676 case SPOOLSS_JOB_CONTROL_CANCEL:
6677 case SPOOLSS_JOB_CONTROL_DELETE:
6678 errcode = print_job_delete(p->server_info,
6679 snum, r->in.job_id);
6680 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
6684 case SPOOLSS_JOB_CONTROL_PAUSE:
6685 if (print_job_pause(p->server_info, snum, r->in.job_id, &errcode)) {
6689 case SPOOLSS_JOB_CONTROL_RESTART:
6690 case SPOOLSS_JOB_CONTROL_RESUME:
6691 if (print_job_resume(p->server_info, snum, r->in.job_id, &errcode)) {
6699 return WERR_UNKNOWN_LEVEL;
6702 if (!W_ERROR_IS_OK(errcode)) {
6706 if (r->in.ctr == NULL) {
6710 switch (r->in.ctr->level) {
6712 errcode = spoolss_setjob_1(p->mem_ctx, lp_const_servicename(snum),
6714 r->in.ctr->info.info1);
6720 return WERR_UNKNOWN_LEVEL;
6726 /****************************************************************************
6727 Enumerates all printer drivers by level and architecture.
6728 ****************************************************************************/
6730 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
6731 struct auth_serversupplied_info *server_info,
6732 const char *servername,
6733 const char *architecture,
6735 union spoolss_DriverInfo **info_p,
6740 struct spoolss_DriverInfo8 *driver;
6741 union spoolss_DriverInfo *info = NULL;
6743 WERROR result = WERR_OK;
6744 uint32_t num_drivers;
6745 const char **drivers;
6750 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6751 result = winreg_get_driver_list(mem_ctx, server_info,
6752 smbd_messaging_context(),
6753 architecture, version,
6754 &num_drivers, &drivers);
6755 if (!W_ERROR_IS_OK(result)) {
6758 DEBUG(4, ("we have:[%d] drivers in environment"
6759 " [%s] and version [%d]\n",
6760 num_drivers, architecture, version));
6762 if (num_drivers != 0) {
6763 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6764 union spoolss_DriverInfo,
6765 count + num_drivers);
6767 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
6768 "failed to enlarge driver info buffer!\n"));
6769 result = WERR_NOMEM;
6774 for (i = 0; i < num_drivers; i++) {
6775 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
6777 result = winreg_get_driver(mem_ctx, server_info,
6778 smbd_messaging_context(),
6779 architecture, drivers[i],
6781 if (!W_ERROR_IS_OK(result)) {
6787 result = fill_printer_driver_info1(info, &info[count+i].info1,
6788 driver, servername);
6791 result = fill_printer_driver_info2(info, &info[count+i].info2,
6792 driver, servername);
6795 result = fill_printer_driver_info3(info, &info[count+i].info3,
6796 driver, servername);
6799 result = fill_printer_driver_info4(info, &info[count+i].info4,
6800 driver, servername);
6803 result = fill_printer_driver_info5(info, &info[count+i].info5,
6804 driver, servername);
6807 result = fill_printer_driver_info6(info, &info[count+i].info6,
6808 driver, servername);
6811 result = fill_printer_driver_info8(info, &info[count+i].info8,
6812 driver, servername);
6815 result = WERR_UNKNOWN_LEVEL;
6819 TALLOC_FREE(driver);
6821 if (!W_ERROR_IS_OK(result)) {
6826 count += num_drivers;
6827 TALLOC_FREE(drivers);
6831 TALLOC_FREE(drivers);
6833 if (!W_ERROR_IS_OK(result)) {
6844 /****************************************************************************
6845 Enumerates all printer drivers by level.
6846 ****************************************************************************/
6848 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
6849 struct auth_serversupplied_info *server_info,
6850 const char *servername,
6851 const char *architecture,
6853 union spoolss_DriverInfo **info_p,
6857 WERROR result = WERR_OK;
6859 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
6861 for (a=0; archi_table[a].long_archi != NULL; a++) {
6863 union spoolss_DriverInfo *info = NULL;
6866 result = enumprinterdrivers_level_by_architecture(mem_ctx,
6869 archi_table[a].long_archi,
6873 if (!W_ERROR_IS_OK(result)) {
6877 for (i=0; i < count; i++) {
6878 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
6879 info[i], info_p, count_p);
6886 return enumprinterdrivers_level_by_architecture(mem_ctx,
6895 /****************************************************************
6896 _spoolss_EnumPrinterDrivers
6897 ****************************************************************/
6899 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
6900 struct spoolss_EnumPrinterDrivers *r)
6902 const char *cservername;
6905 /* that's an [in out] buffer */
6907 if (!r->in.buffer && (r->in.offered != 0)) {
6908 return WERR_INVALID_PARAM;
6911 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
6915 *r->out.info = NULL;
6917 cservername = canon_servername(r->in.server);
6919 if (!is_myname_or_ipaddr(cservername)) {
6920 return WERR_UNKNOWN_PRINTER_DRIVER;
6923 result = enumprinterdrivers_level(p->mem_ctx,
6930 if (!W_ERROR_IS_OK(result)) {
6934 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6935 spoolss_EnumPrinterDrivers,
6936 *r->out.info, r->in.level,
6938 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6939 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6941 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6944 /****************************************************************
6946 ****************************************************************/
6948 WERROR _spoolss_EnumForms(struct pipes_struct *p,
6949 struct spoolss_EnumForms *r)
6955 *r->out.info = NULL;
6957 /* that's an [in out] buffer */
6959 if (!r->in.buffer && (r->in.offered != 0) ) {
6960 return WERR_INVALID_PARAM;
6963 DEBUG(4,("_spoolss_EnumForms\n"));
6964 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6965 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6967 switch (r->in.level) {
6969 result = winreg_printer_enumforms1(p->mem_ctx,
6976 result = WERR_UNKNOWN_LEVEL;
6980 if (!W_ERROR_IS_OK(result)) {
6984 if (*r->out.count == 0) {
6985 return WERR_NO_MORE_ITEMS;
6988 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6990 *r->out.info, r->in.level,
6992 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6993 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6995 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6998 /****************************************************************
7000 ****************************************************************/
7002 WERROR _spoolss_GetForm(struct pipes_struct *p,
7003 struct spoolss_GetForm *r)
7007 /* that's an [in out] buffer */
7009 if (!r->in.buffer && (r->in.offered != 0)) {
7010 return WERR_INVALID_PARAM;
7013 DEBUG(4,("_spoolss_GetForm\n"));
7014 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7015 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7017 switch (r->in.level) {
7019 result = winreg_printer_getform1(p->mem_ctx,
7023 &r->out.info->info1);
7026 result = WERR_UNKNOWN_LEVEL;
7030 if (!W_ERROR_IS_OK(result)) {
7031 TALLOC_FREE(r->out.info);
7035 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7036 r->out.info, r->in.level);
7037 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7039 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7042 /****************************************************************************
7043 ****************************************************************************/
7045 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7046 struct spoolss_PortInfo1 *r,
7049 r->port_name = talloc_strdup(mem_ctx, name);
7050 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7055 /****************************************************************************
7056 TODO: This probably needs distinguish between TCP/IP and Local ports
7058 ****************************************************************************/
7060 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7061 struct spoolss_PortInfo2 *r,
7064 r->port_name = talloc_strdup(mem_ctx, name);
7065 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7067 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7068 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7070 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7071 W_ERROR_HAVE_NO_MEMORY(r->description);
7073 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7080 /****************************************************************************
7081 wrapper around the enumer ports command
7082 ****************************************************************************/
7084 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7086 char *cmd = lp_enumports_cmd();
7087 char **qlines = NULL;
7088 char *command = NULL;
7096 /* if no hook then just fill in the default port */
7099 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7102 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7103 TALLOC_FREE(qlines);
7110 /* we have a valid enumport command */
7112 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7117 DEBUG(10,("Running [%s]\n", command));
7118 ret = smbrun(command, &fd);
7119 DEBUG(10,("Returned [%d]\n", ret));
7120 TALLOC_FREE(command);
7125 return WERR_ACCESS_DENIED;
7129 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7130 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7140 /****************************************************************************
7142 ****************************************************************************/
7144 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7145 union spoolss_PortInfo **info_p,
7148 union spoolss_PortInfo *info = NULL;
7150 WERROR result = WERR_OK;
7151 char **qlines = NULL;
7154 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7155 if (!W_ERROR_IS_OK(result)) {
7160 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7162 DEBUG(10,("Returning WERR_NOMEM\n"));
7163 result = WERR_NOMEM;
7167 for (i=0; i<numlines; i++) {
7168 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7169 result = fill_port_1(info, &info[i].info1, qlines[i]);
7170 if (!W_ERROR_IS_OK(result)) {
7175 TALLOC_FREE(qlines);
7178 if (!W_ERROR_IS_OK(result)) {
7180 TALLOC_FREE(qlines);
7192 /****************************************************************************
7194 ****************************************************************************/
7196 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7197 union spoolss_PortInfo **info_p,
7200 union spoolss_PortInfo *info = NULL;
7202 WERROR result = WERR_OK;
7203 char **qlines = NULL;
7206 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7207 if (!W_ERROR_IS_OK(result)) {
7212 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7214 DEBUG(10,("Returning WERR_NOMEM\n"));
7215 result = WERR_NOMEM;
7219 for (i=0; i<numlines; i++) {
7220 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7221 result = fill_port_2(info, &info[i].info2, qlines[i]);
7222 if (!W_ERROR_IS_OK(result)) {
7227 TALLOC_FREE(qlines);
7230 if (!W_ERROR_IS_OK(result)) {
7232 TALLOC_FREE(qlines);
7244 /****************************************************************
7246 ****************************************************************/
7248 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
7249 struct spoolss_EnumPorts *r)
7253 /* that's an [in out] buffer */
7255 if (!r->in.buffer && (r->in.offered != 0)) {
7256 return WERR_INVALID_PARAM;
7259 DEBUG(4,("_spoolss_EnumPorts\n"));
7263 *r->out.info = NULL;
7265 switch (r->in.level) {
7267 result = enumports_level_1(p->mem_ctx, r->out.info,
7271 result = enumports_level_2(p->mem_ctx, r->out.info,
7275 return WERR_UNKNOWN_LEVEL;
7278 if (!W_ERROR_IS_OK(result)) {
7282 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7284 *r->out.info, r->in.level,
7286 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7287 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7289 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7292 /****************************************************************************
7293 ****************************************************************************/
7295 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
7297 struct spoolss_SetPrinterInfoCtr *info_ctr,
7298 struct spoolss_DeviceMode *devmode,
7299 struct security_descriptor *secdesc,
7300 struct spoolss_UserLevelCtr *user_ctr,
7301 struct policy_handle *handle)
7303 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7304 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7306 WERROR err = WERR_OK;
7308 /* samba does not have a concept of local, non-shared printers yet, so
7309 * make sure we always setup sharename - gd */
7310 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7311 (info2->printername != NULL && info2->printername[0] != '\0')) {
7312 DEBUG(5, ("spoolss_addprinterex_level_2: "
7313 "no sharename has been set, setting printername %s as sharename\n",
7314 info2->printername));
7315 info2->sharename = info2->printername;
7318 /* check to see if the printer already exists */
7319 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7320 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7322 return WERR_PRINTER_ALREADY_EXISTS;
7325 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7326 if ((snum = print_queue_snum(info2->printername)) != -1) {
7327 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7328 info2->printername));
7329 return WERR_PRINTER_ALREADY_EXISTS;
7333 /* validate printer info struct */
7334 if (!info2->printername || strlen(info2->printername) == 0) {
7335 return WERR_INVALID_PRINTER_NAME;
7337 if (!info2->portname || strlen(info2->portname) == 0) {
7338 return WERR_UNKNOWN_PORT;
7340 if (!info2->drivername || strlen(info2->drivername) == 0) {
7341 return WERR_UNKNOWN_PRINTER_DRIVER;
7343 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7344 return WERR_UNKNOWN_PRINTPROCESSOR;
7347 /* FIXME!!! smbd should check to see if the driver is installed before
7348 trying to add a printer like this --jerry */
7350 if (*lp_addprinter_cmd() ) {
7351 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7352 info2, p->client_address,
7354 return WERR_ACCESS_DENIED;
7357 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7358 "smb.conf parameter \"addprinter command\" is defined. This"
7359 "parameter must exist for this call to succeed\n",
7360 info2->sharename ));
7363 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7364 return WERR_ACCESS_DENIED;
7367 /* you must be a printer admin to add a new printer */
7368 if (!print_access_check(p->server_info, snum, PRINTER_ACCESS_ADMINISTER)) {
7369 return WERR_ACCESS_DENIED;
7373 * Do sanity check on the requested changes for Samba.
7376 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7377 return WERR_INVALID_PARAM;
7380 if (devmode == NULL) {
7381 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7384 update_dsspooler(p->mem_ctx,
7390 err = winreg_update_printer(p->mem_ctx,
7398 if (!W_ERROR_IS_OK(err)) {
7402 if (!open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER)) {
7403 /* Handle open failed - remove addition. */
7404 ZERO_STRUCTP(handle);
7405 return WERR_ACCESS_DENIED;
7411 /****************************************************************
7412 _spoolss_AddPrinterEx
7413 ****************************************************************/
7415 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
7416 struct spoolss_AddPrinterEx *r)
7418 switch (r->in.info_ctr->level) {
7420 /* we don't handle yet */
7421 /* but I know what to do ... */
7422 return WERR_UNKNOWN_LEVEL;
7424 return spoolss_addprinterex_level_2(p, r->in.server,
7426 r->in.devmode_ctr->devmode,
7427 r->in.secdesc_ctr->sd,
7428 r->in.userlevel_ctr,
7431 return WERR_UNKNOWN_LEVEL;
7435 /****************************************************************
7437 ****************************************************************/
7439 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
7440 struct spoolss_AddPrinter *r)
7442 struct spoolss_AddPrinterEx a;
7443 struct spoolss_UserLevelCtr userlevel_ctr;
7445 ZERO_STRUCT(userlevel_ctr);
7447 userlevel_ctr.level = 1;
7449 a.in.server = r->in.server;
7450 a.in.info_ctr = r->in.info_ctr;
7451 a.in.devmode_ctr = r->in.devmode_ctr;
7452 a.in.secdesc_ctr = r->in.secdesc_ctr;
7453 a.in.userlevel_ctr = &userlevel_ctr;
7454 a.out.handle = r->out.handle;
7456 return _spoolss_AddPrinterEx(p, &a);
7459 /****************************************************************
7460 _spoolss_AddPrinterDriverEx
7461 ****************************************************************/
7463 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
7464 struct spoolss_AddPrinterDriverEx *r)
7466 WERROR err = WERR_OK;
7467 const char *driver_name = NULL;
7472 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7473 fn = "_spoolss_AddPrinterDriver";
7475 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7476 fn = "_spoolss_AddPrinterDriverEx";
7479 return WERR_INVALID_PARAM;
7483 * we only support the semantics of AddPrinterDriver()
7484 * i.e. only copy files that are newer than existing ones
7487 if (r->in.flags == 0) {
7488 return WERR_INVALID_PARAM;
7491 if (r->in.flags != APD_COPY_NEW_FILES) {
7492 return WERR_ACCESS_DENIED;
7496 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7497 /* Clever hack from Martin Zielinski <mz@seh.de>
7498 * to allow downgrade from level 8 (Vista).
7500 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7501 r->in.info_ctr->level));
7502 return WERR_UNKNOWN_LEVEL;
7505 DEBUG(5,("Cleaning driver's information\n"));
7506 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
7507 if (!W_ERROR_IS_OK(err))
7510 DEBUG(5,("Moving driver to final destination\n"));
7511 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7516 err = winreg_add_driver(p->mem_ctx, p->server_info, p->msg_ctx,
7517 r->in.info_ctr, &driver_name, &version);
7518 if (!W_ERROR_IS_OK(err)) {
7523 * I think this is where he DrvUpgradePrinter() hook would be
7524 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7525 * server. Right now, we just need to send ourselves a message
7526 * to update each printer bound to this driver. --jerry
7529 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
7530 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7538 /****************************************************************
7539 _spoolss_AddPrinterDriver
7540 ****************************************************************/
7542 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
7543 struct spoolss_AddPrinterDriver *r)
7545 struct spoolss_AddPrinterDriverEx a;
7547 switch (r->in.info_ctr->level) {
7554 return WERR_UNKNOWN_LEVEL;
7557 a.in.servername = r->in.servername;
7558 a.in.info_ctr = r->in.info_ctr;
7559 a.in.flags = APD_COPY_NEW_FILES;
7561 return _spoolss_AddPrinterDriverEx(p, &a);
7564 /****************************************************************************
7565 ****************************************************************************/
7567 struct _spoolss_paths {
7573 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7575 static const struct _spoolss_paths spoolss_paths[]= {
7576 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7577 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7580 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7581 const char *servername,
7582 const char *environment,
7586 const char *pservername = NULL;
7587 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7588 const char *short_archi;
7592 /* environment may be empty */
7593 if (environment && strlen(environment)) {
7594 long_archi = environment;
7597 /* servername may be empty */
7598 if (servername && strlen(servername)) {
7599 pservername = canon_servername(servername);
7601 if (!is_myname_or_ipaddr(pservername)) {
7602 return WERR_INVALID_PARAM;
7606 if (!(short_archi = get_short_archi(long_archi))) {
7607 return WERR_INVALID_ENVIRONMENT;
7610 switch (component) {
7611 case SPOOLSS_PRTPROCS_PATH:
7612 case SPOOLSS_DRIVER_PATH:
7614 *path = talloc_asprintf(mem_ctx,
7617 spoolss_paths[component].share,
7620 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7621 SPOOLSS_DEFAULT_SERVER_PATH,
7622 spoolss_paths[component].dir,
7627 return WERR_INVALID_PARAM;
7637 /****************************************************************************
7638 ****************************************************************************/
7640 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7641 const char *servername,
7642 const char *environment,
7643 struct spoolss_DriverDirectoryInfo1 *r)
7648 werr = compose_spoolss_server_path(mem_ctx,
7651 SPOOLSS_DRIVER_PATH,
7653 if (!W_ERROR_IS_OK(werr)) {
7657 DEBUG(4,("printer driver directory: [%s]\n", path));
7659 r->directory_name = path;
7664 /****************************************************************
7665 _spoolss_GetPrinterDriverDirectory
7666 ****************************************************************/
7668 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
7669 struct spoolss_GetPrinterDriverDirectory *r)
7673 /* that's an [in out] buffer */
7675 if (!r->in.buffer && (r->in.offered != 0)) {
7676 return WERR_INVALID_PARAM;
7679 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
7684 /* r->in.level is ignored */
7686 werror = getprinterdriverdir_level_1(p->mem_ctx,
7689 &r->out.info->info1);
7690 if (!W_ERROR_IS_OK(werror)) {
7691 TALLOC_FREE(r->out.info);
7695 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
7696 r->out.info, r->in.level);
7697 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7699 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7702 /****************************************************************
7703 _spoolss_EnumPrinterData
7704 ****************************************************************/
7706 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
7707 struct spoolss_EnumPrinterData *r)
7710 struct spoolss_EnumPrinterDataEx r2;
7712 struct spoolss_PrinterEnumValues *info, *val = NULL;
7715 r2.in.handle = r->in.handle;
7716 r2.in.key_name = "PrinterDriverData";
7718 r2.out.count = &count;
7719 r2.out.info = &info;
7720 r2.out.needed = &needed;
7722 result = _spoolss_EnumPrinterDataEx(p, &r2);
7723 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
7724 r2.in.offered = needed;
7725 result = _spoolss_EnumPrinterDataEx(p, &r2);
7727 if (!W_ERROR_IS_OK(result)) {
7732 * The NT machine wants to know the biggest size of value and data
7734 * cf: MSDN EnumPrinterData remark section
7737 if (!r->in.value_offered && !r->in.data_offered) {
7738 uint32_t biggest_valuesize = 0;
7739 uint32_t biggest_datasize = 0;
7742 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
7744 for (i=0; i<count; i++) {
7746 name_length = strlen(info[i].value_name);
7747 if (strlen(info[i].value_name) > biggest_valuesize) {
7748 biggest_valuesize = name_length;
7751 if (info[i].data_length > biggest_datasize) {
7752 biggest_datasize = info[i].data_length;
7755 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
7759 /* the value is an UNICODE string but real_value_size is the length
7760 in bytes including the trailing 0 */
7762 *r->out.value_needed = 2 * (1 + biggest_valuesize);
7763 *r->out.data_needed = biggest_datasize;
7765 DEBUG(6,("final values: [%d], [%d]\n",
7766 *r->out.value_needed, *r->out.data_needed));
7771 if (r->in.enum_index < count) {
7772 val = &info[r->in.enum_index];
7776 /* out_value should default to "" or else NT4 has
7777 problems unmarshalling the response */
7779 if (r->in.value_offered) {
7780 *r->out.value_needed = 1;
7781 r->out.value_name = talloc_strdup(r, "");
7782 if (!r->out.value_name) {
7786 r->out.value_name = NULL;
7787 *r->out.value_needed = 0;
7790 /* the data is counted in bytes */
7792 *r->out.data_needed = r->in.data_offered;
7794 result = WERR_NO_MORE_ITEMS;
7798 * - counted in bytes in the request
7799 * - counted in UNICODE chars in the max reply
7800 * - counted in bytes in the real size
7802 * take a pause *before* coding not *during* coding
7806 if (r->in.value_offered) {
7807 r->out.value_name = talloc_strdup(r, val->value_name);
7808 if (!r->out.value_name) {
7811 *r->out.value_needed = val->value_name_len;
7813 r->out.value_name = NULL;
7814 *r->out.value_needed = 0;
7819 *r->out.type = val->type;
7821 /* data - counted in bytes */
7824 * See the section "Dynamically Typed Query Parameters"
7828 if (r->out.data && val->data && val->data->data &&
7829 val->data_length && r->in.data_offered) {
7830 memcpy(r->out.data, val->data->data,
7831 MIN(val->data_length,r->in.data_offered));
7834 *r->out.data_needed = val->data_length;
7842 /****************************************************************
7843 _spoolss_SetPrinterData
7844 ****************************************************************/
7846 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
7847 struct spoolss_SetPrinterData *r)
7849 struct spoolss_SetPrinterDataEx r2;
7851 r2.in.handle = r->in.handle;
7852 r2.in.key_name = "PrinterDriverData";
7853 r2.in.value_name = r->in.value_name;
7854 r2.in.type = r->in.type;
7855 r2.in.data = r->in.data;
7856 r2.in.offered = r->in.offered;
7858 return _spoolss_SetPrinterDataEx(p, &r2);
7861 /****************************************************************
7862 _spoolss_ResetPrinter
7863 ****************************************************************/
7865 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
7866 struct spoolss_ResetPrinter *r)
7868 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7871 DEBUG(5,("_spoolss_ResetPrinter\n"));
7874 * All we do is to check to see if the handle and queue is valid.
7875 * This call really doesn't mean anything to us because we only
7876 * support RAW printing. --jerry
7880 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
7881 OUR_HANDLE(r->in.handle)));
7885 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
7889 /* blindly return success */
7893 /****************************************************************
7894 _spoolss_DeletePrinterData
7895 ****************************************************************/
7897 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
7898 struct spoolss_DeletePrinterData *r)
7900 struct spoolss_DeletePrinterDataEx r2;
7902 r2.in.handle = r->in.handle;
7903 r2.in.key_name = "PrinterDriverData";
7904 r2.in.value_name = r->in.value_name;
7906 return _spoolss_DeletePrinterDataEx(p, &r2);
7909 /****************************************************************
7911 ****************************************************************/
7913 WERROR _spoolss_AddForm(struct pipes_struct *p,
7914 struct spoolss_AddForm *r)
7916 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
7918 WERROR status = WERR_OK;
7919 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7921 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7923 DEBUG(5,("_spoolss_AddForm\n"));
7926 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
7927 OUR_HANDLE(r->in.handle)));
7931 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
7932 and not a printer admin, then fail */
7934 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7935 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7936 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7937 p->server_info->info3->base.domain.string,
7939 p->server_info->ptok,
7940 lp_printer_admin(snum))) {
7941 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
7942 return WERR_ACCESS_DENIED;
7945 switch (form->flags) {
7946 case SPOOLSS_FORM_USER:
7947 case SPOOLSS_FORM_BUILTIN:
7948 case SPOOLSS_FORM_PRINTER:
7951 return WERR_INVALID_PARAM;
7954 status = winreg_printer_addform1(p->mem_ctx, p->server_info,
7956 if (!W_ERROR_IS_OK(status)) {
7961 * ChangeID must always be set if this is a printer
7963 if (Printer->printer_type == SPLHND_PRINTER) {
7964 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7968 status = winreg_printer_update_changeid(p->mem_ctx,
7971 lp_const_servicename(snum));
7972 if (!W_ERROR_IS_OK(status)) {
7980 /****************************************************************
7982 ****************************************************************/
7984 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
7985 struct spoolss_DeleteForm *r)
7987 const char *form_name = r->in.form_name;
7988 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7990 WERROR status = WERR_OK;
7991 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7993 DEBUG(5,("_spoolss_DeleteForm\n"));
7996 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
7997 OUR_HANDLE(r->in.handle)));
8001 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8002 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8003 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8004 p->server_info->info3->base.domain.string,
8006 p->server_info->ptok,
8007 lp_printer_admin(snum))) {
8008 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8009 return WERR_ACCESS_DENIED;
8012 status = winreg_printer_deleteform1(p->mem_ctx,
8016 if (!W_ERROR_IS_OK(status)) {
8021 * ChangeID must always be set if this is a printer
8023 if (Printer->printer_type == SPLHND_PRINTER) {
8024 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8028 status = winreg_printer_update_changeid(p->mem_ctx,
8031 lp_const_servicename(snum));
8032 if (!W_ERROR_IS_OK(status)) {
8040 /****************************************************************
8042 ****************************************************************/
8044 WERROR _spoolss_SetForm(struct pipes_struct *p,
8045 struct spoolss_SetForm *r)
8047 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8048 const char *form_name = r->in.form_name;
8050 WERROR status = WERR_OK;
8051 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8053 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8055 DEBUG(5,("_spoolss_SetForm\n"));
8058 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8059 OUR_HANDLE(r->in.handle)));
8063 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8064 and not a printer admin, then fail */
8066 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8067 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8068 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8069 p->server_info->info3->base.domain.string,
8071 p->server_info->ptok,
8072 lp_printer_admin(snum))) {
8073 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8074 return WERR_ACCESS_DENIED;
8077 status = winreg_printer_setform1(p->mem_ctx,
8082 if (!W_ERROR_IS_OK(status)) {
8087 * ChangeID must always be set if this is a printer
8089 if (Printer->printer_type == SPLHND_PRINTER) {
8090 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8094 status = winreg_printer_update_changeid(p->mem_ctx,
8097 lp_const_servicename(snum));
8098 if (!W_ERROR_IS_OK(status)) {
8106 /****************************************************************************
8107 fill_print_processor1
8108 ****************************************************************************/
8110 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8111 struct spoolss_PrintProcessorInfo1 *r,
8112 const char *print_processor_name)
8114 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8115 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8120 /****************************************************************************
8121 enumprintprocessors level 1.
8122 ****************************************************************************/
8124 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8125 union spoolss_PrintProcessorInfo **info_p,
8128 union spoolss_PrintProcessorInfo *info;
8131 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8132 W_ERROR_HAVE_NO_MEMORY(info);
8136 result = fill_print_processor1(info, &info[0].info1, "winprint");
8137 if (!W_ERROR_IS_OK(result)) {
8142 if (!W_ERROR_IS_OK(result)) {
8153 /****************************************************************
8154 _spoolss_EnumPrintProcessors
8155 ****************************************************************/
8157 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8158 struct spoolss_EnumPrintProcessors *r)
8162 /* that's an [in out] buffer */
8164 if (!r->in.buffer && (r->in.offered != 0)) {
8165 return WERR_INVALID_PARAM;
8168 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8171 * Enumerate the print processors ...
8173 * Just reply with "winprint", to keep NT happy
8174 * and I can use my nice printer checker.
8179 *r->out.info = NULL;
8181 switch (r->in.level) {
8183 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8187 return WERR_UNKNOWN_LEVEL;
8190 if (!W_ERROR_IS_OK(result)) {
8194 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8195 spoolss_EnumPrintProcessors,
8196 *r->out.info, r->in.level,
8198 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8199 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8201 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8204 /****************************************************************************
8205 fill_printprocdatatype1
8206 ****************************************************************************/
8208 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8209 struct spoolss_PrintProcDataTypesInfo1 *r,
8210 const char *name_array)
8212 r->name_array = talloc_strdup(mem_ctx, name_array);
8213 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8218 /****************************************************************************
8219 enumprintprocdatatypes level 1.
8220 ****************************************************************************/
8222 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8223 union spoolss_PrintProcDataTypesInfo **info_p,
8227 union spoolss_PrintProcDataTypesInfo *info;
8229 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8230 W_ERROR_HAVE_NO_MEMORY(info);
8234 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8235 if (!W_ERROR_IS_OK(result)) {
8240 if (!W_ERROR_IS_OK(result)) {
8251 /****************************************************************
8252 _spoolss_EnumPrintProcDataTypes
8253 ****************************************************************/
8255 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
8256 struct spoolss_EnumPrintProcDataTypes *r)
8260 /* that's an [in out] buffer */
8262 if (!r->in.buffer && (r->in.offered != 0)) {
8263 return WERR_INVALID_PARAM;
8266 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8270 *r->out.info = NULL;
8272 switch (r->in.level) {
8274 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8278 return WERR_UNKNOWN_LEVEL;
8281 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8282 spoolss_EnumPrintProcDataTypes,
8283 *r->out.info, r->in.level,
8285 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8286 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8288 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8291 /****************************************************************************
8293 ****************************************************************************/
8295 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8296 struct spoolss_MonitorInfo1 *r,
8297 const char *monitor_name)
8299 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8300 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8305 /****************************************************************************
8307 ****************************************************************************/
8309 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8310 struct spoolss_MonitorInfo2 *r,
8311 const char *monitor_name,
8312 const char *environment,
8313 const char *dll_name)
8315 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8316 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8317 r->environment = talloc_strdup(mem_ctx, environment);
8318 W_ERROR_HAVE_NO_MEMORY(r->environment);
8319 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8320 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8325 /****************************************************************************
8326 enumprintmonitors level 1.
8327 ****************************************************************************/
8329 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8330 union spoolss_MonitorInfo **info_p,
8333 union spoolss_MonitorInfo *info;
8334 WERROR result = WERR_OK;
8336 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8337 W_ERROR_HAVE_NO_MEMORY(info);
8341 result = fill_monitor_1(info, &info[0].info1,
8343 if (!W_ERROR_IS_OK(result)) {
8347 result = fill_monitor_1(info, &info[1].info1,
8349 if (!W_ERROR_IS_OK(result)) {
8354 if (!W_ERROR_IS_OK(result)) {
8365 /****************************************************************************
8366 enumprintmonitors level 2.
8367 ****************************************************************************/
8369 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8370 union spoolss_MonitorInfo **info_p,
8373 union spoolss_MonitorInfo *info;
8374 WERROR result = WERR_OK;
8376 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8377 W_ERROR_HAVE_NO_MEMORY(info);
8381 result = fill_monitor_2(info, &info[0].info2,
8383 "Windows NT X86", /* FIXME */
8385 if (!W_ERROR_IS_OK(result)) {
8389 result = fill_monitor_2(info, &info[1].info2,
8391 "Windows NT X86", /* FIXME */
8393 if (!W_ERROR_IS_OK(result)) {
8398 if (!W_ERROR_IS_OK(result)) {
8409 /****************************************************************
8410 _spoolss_EnumMonitors
8411 ****************************************************************/
8413 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
8414 struct spoolss_EnumMonitors *r)
8418 /* that's an [in out] buffer */
8420 if (!r->in.buffer && (r->in.offered != 0)) {
8421 return WERR_INVALID_PARAM;
8424 DEBUG(5,("_spoolss_EnumMonitors\n"));
8427 * Enumerate the print monitors ...
8429 * Just reply with "Local Port", to keep NT happy
8430 * and I can use my nice printer checker.
8435 *r->out.info = NULL;
8437 switch (r->in.level) {
8439 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8443 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8447 return WERR_UNKNOWN_LEVEL;
8450 if (!W_ERROR_IS_OK(result)) {
8454 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8455 spoolss_EnumMonitors,
8456 *r->out.info, r->in.level,
8458 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8459 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8461 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8464 /****************************************************************************
8465 ****************************************************************************/
8467 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8468 const print_queue_struct *queue,
8469 int count, int snum,
8470 struct spoolss_PrinterInfo2 *pinfo2,
8472 struct spoolss_JobInfo1 *r)
8477 for (i=0; i<count; i++) {
8478 if (queue[i].job == (int)jobid) {
8484 if (found == false) {
8485 /* NT treats not found as bad param... yet another bad choice */
8486 return WERR_INVALID_PARAM;
8489 return fill_job_info1(mem_ctx,
8497 /****************************************************************************
8498 ****************************************************************************/
8500 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8501 const print_queue_struct *queue,
8502 int count, int snum,
8503 struct spoolss_PrinterInfo2 *pinfo2,
8505 struct spoolss_JobInfo2 *r)
8509 struct spoolss_DeviceMode *devmode;
8512 for (i=0; i<count; i++) {
8513 if (queue[i].job == (int)jobid) {
8519 if (found == false) {
8520 /* NT treats not found as bad param... yet another bad
8522 return WERR_INVALID_PARAM;
8526 * if the print job does not have a DEVMODE associated with it,
8527 * just use the one for the printer. A NULL devicemode is not
8528 * a failure condition
8531 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8533 result = spoolss_create_default_devmode(mem_ctx,
8534 pinfo2->printername,
8536 if (!W_ERROR_IS_OK(result)) {
8537 DEBUG(3, ("Can't proceed w/o a devmode!"));
8542 return fill_job_info2(mem_ctx,
8551 /****************************************************************
8553 ****************************************************************/
8555 WERROR _spoolss_GetJob(struct pipes_struct *p,
8556 struct spoolss_GetJob *r)
8558 WERROR result = WERR_OK;
8559 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8562 print_queue_struct *queue = NULL;
8563 print_status_struct prt_status;
8565 /* that's an [in out] buffer */
8567 if (!r->in.buffer && (r->in.offered != 0)) {
8568 return WERR_INVALID_PARAM;
8571 DEBUG(5,("_spoolss_GetJob\n"));
8575 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8579 result = winreg_get_printer(p->mem_ctx, p->server_info, p->msg_ctx,
8580 NULL, lp_servicename(snum), &pinfo2);
8581 if (!W_ERROR_IS_OK(result)) {
8585 count = print_queue_status(snum, &queue, &prt_status);
8587 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8588 count, prt_status.status, prt_status.message));
8590 switch (r->in.level) {
8592 result = getjob_level_1(p->mem_ctx,
8593 queue, count, snum, pinfo2,
8594 r->in.job_id, &r->out.info->info1);
8597 result = getjob_level_2(p->mem_ctx,
8598 queue, count, snum, pinfo2,
8599 r->in.job_id, &r->out.info->info2);
8602 result = WERR_UNKNOWN_LEVEL;
8607 TALLOC_FREE(pinfo2);
8609 if (!W_ERROR_IS_OK(result)) {
8610 TALLOC_FREE(r->out.info);
8614 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
8616 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8618 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8621 /****************************************************************
8622 _spoolss_GetPrinterDataEx
8623 ****************************************************************/
8625 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
8626 struct spoolss_GetPrinterDataEx *r)
8629 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8630 const char *printer;
8632 WERROR result = WERR_OK;
8634 enum winreg_Type val_type;
8639 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8641 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8642 r->in.key_name, r->in.value_name));
8644 /* in case of problem, return some default values */
8647 *r->out.type = REG_NONE;
8650 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8651 OUR_HANDLE(r->in.handle)));
8652 result = WERR_BADFID;
8656 /* Is the handle to a printer or to the server? */
8658 if (Printer->printer_type == SPLHND_SERVER) {
8660 union spoolss_PrinterData data;
8662 result = getprinterdata_printer_server(p->mem_ctx,
8666 if (!W_ERROR_IS_OK(result)) {
8670 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
8671 *r->out.type, &data);
8672 if (!W_ERROR_IS_OK(result)) {
8676 *r->out.needed = blob.length;
8678 if (r->in.offered >= *r->out.needed) {
8679 memcpy(r->out.data, blob.data, blob.length);
8682 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8685 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8688 printer = lp_const_servicename(snum);
8690 /* check to see if the keyname is valid */
8691 if (!strlen(r->in.key_name)) {
8692 return WERR_INVALID_PARAM;
8695 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
8696 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
8697 strequal(r->in.value_name, "ChangeId")) {
8698 *r->out.type = REG_DWORD;
8700 if (r->in.offered >= *r->out.needed) {
8701 uint32_t changeid = 0;
8703 result = winreg_printer_get_changeid(p->mem_ctx,
8708 if (!W_ERROR_IS_OK(result)) {
8712 SIVAL(r->out.data, 0, changeid);
8718 result = winreg_get_printer_dataex(p->mem_ctx,
8727 if (!W_ERROR_IS_OK(result)) {
8731 *r->out.needed = val_size;
8732 *r->out.type = val_type;
8734 if (r->in.offered >= *r->out.needed) {
8735 memcpy(r->out.data, val_data, val_size);
8739 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
8740 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
8742 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8745 /****************************************************************
8746 _spoolss_SetPrinterDataEx
8747 ****************************************************************/
8749 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
8750 struct spoolss_SetPrinterDataEx *r)
8752 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8754 WERROR result = WERR_OK;
8755 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8758 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
8760 /* From MSDN documentation of SetPrinterDataEx: pass request to
8761 SetPrinterData if key is "PrinterDriverData" */
8764 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8765 OUR_HANDLE(r->in.handle)));
8769 if (Printer->printer_type == SPLHND_SERVER) {
8770 DEBUG(10,("_spoolss_SetPrinterDataEx: "
8771 "Not implemented for server handles yet\n"));
8772 return WERR_INVALID_PARAM;
8775 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8780 * Access check : NT returns "access denied" if you make a
8781 * SetPrinterData call without the necessary privildge.
8782 * we were originally returning OK if nothing changed
8783 * which made Win2k issue **a lot** of SetPrinterData
8784 * when connecting to a printer --jerry
8787 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8788 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
8789 "change denied by handle access permissions\n"));
8790 return WERR_ACCESS_DENIED;
8793 result = winreg_get_printer(Printer, p->server_info, p->msg_ctx,
8794 Printer->servername,
8795 lp_servicename(snum),
8797 if (!W_ERROR_IS_OK(result)) {
8801 /* check for OID in valuename */
8803 oid_string = strchr(r->in.value_name, ',');
8809 /* save the registry data */
8811 result = winreg_set_printer_dataex(p->mem_ctx,
8821 if (W_ERROR_IS_OK(result)) {
8822 /* save the OID if one was specified */
8824 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
8825 r->in.key_name, SPOOL_OID_KEY);
8827 result = WERR_NOMEM;
8832 * I'm not checking the status here on purpose. Don't know
8833 * if this is right, but I'm returning the status from the
8834 * previous set_printer_dataex() call. I have no idea if
8835 * this is right. --jerry
8837 winreg_set_printer_dataex(p->mem_ctx,
8844 (uint8_t *) oid_string,
8845 strlen(oid_string) + 1);
8848 result = winreg_printer_update_changeid(p->mem_ctx,
8851 lp_const_servicename(snum));
8856 talloc_free(pinfo2);
8860 /****************************************************************
8861 _spoolss_DeletePrinterDataEx
8862 ****************************************************************/
8864 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
8865 struct spoolss_DeletePrinterDataEx *r)
8867 const char *printer;
8869 WERROR status = WERR_OK;
8870 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8872 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
8875 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
8876 "Invalid handle (%s:%u:%u).\n",
8877 OUR_HANDLE(r->in.handle)));
8881 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8882 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
8883 "printer properties change denied by handle\n"));
8884 return WERR_ACCESS_DENIED;
8887 if (!r->in.value_name || !r->in.key_name) {
8891 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8894 printer = lp_const_servicename(snum);
8896 status = winreg_delete_printer_dataex(p->mem_ctx,
8902 if (W_ERROR_IS_OK(status)) {
8903 status = winreg_printer_update_changeid(p->mem_ctx,
8912 /****************************************************************
8913 _spoolss_EnumPrinterKey
8914 ****************************************************************/
8916 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
8917 struct spoolss_EnumPrinterKey *r)
8920 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8922 WERROR result = WERR_BADFILE;
8923 const char **array = NULL;
8926 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
8929 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
8930 OUR_HANDLE(r->in.handle)));
8934 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8938 result = winreg_enum_printer_key(p->mem_ctx,
8941 lp_const_servicename(snum),
8945 if (!W_ERROR_IS_OK(result)) {
8949 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
8950 result = WERR_NOMEM;
8954 *r->out._ndr_size = r->in.offered / 2;
8955 *r->out.needed = blob.length;
8957 if (r->in.offered < *r->out.needed) {
8958 result = WERR_MORE_DATA;
8961 r->out.key_buffer->string_array = array;
8965 if (!W_ERROR_IS_OK(result)) {
8967 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8975 /****************************************************************
8976 _spoolss_DeletePrinterKey
8977 ****************************************************************/
8979 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
8980 struct spoolss_DeletePrinterKey *r)
8982 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8985 const char *printer;
8987 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
8990 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
8991 OUR_HANDLE(r->in.handle)));
8995 /* if keyname == NULL, return error */
8996 if ( !r->in.key_name )
8997 return WERR_INVALID_PARAM;
8999 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9003 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9004 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9005 "printer properties change denied by handle\n"));
9006 return WERR_ACCESS_DENIED;
9009 printer = lp_const_servicename(snum);
9011 /* delete the key and all subkeys */
9012 status = winreg_delete_printer_key(p->mem_ctx,
9017 if (W_ERROR_IS_OK(status)) {
9018 status = winreg_printer_update_changeid(p->mem_ctx,
9027 /****************************************************************
9028 _spoolss_EnumPrinterDataEx
9029 ****************************************************************/
9031 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9032 struct spoolss_EnumPrinterDataEx *r)
9035 struct spoolss_PrinterEnumValues *info = NULL;
9036 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9040 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9044 *r->out.info = NULL;
9047 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9048 OUR_HANDLE(r->in.handle)));
9053 * first check for a keyname of NULL or "". Win2k seems to send
9054 * this a lot and we should send back WERR_INVALID_PARAM
9055 * no need to spend time looking up the printer in this case.
9059 if (!strlen(r->in.key_name)) {
9060 result = WERR_INVALID_PARAM;
9064 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9068 /* now look for a match on the key name */
9069 result = winreg_enum_printer_dataex(p->mem_ctx,
9072 lp_const_servicename(snum),
9076 if (!W_ERROR_IS_OK(result)) {
9080 #if 0 /* FIXME - gd */
9081 /* housekeeping information in the reply */
9083 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9084 * the hand marshalled container size is a multiple
9085 * of 4 bytes for RPC alignment.
9089 needed += 4-(needed % 4);
9092 *r->out.count = count;
9093 *r->out.info = info;
9096 if (!W_ERROR_IS_OK(result)) {
9100 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9101 spoolss_EnumPrinterDataEx,
9104 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9105 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9107 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9110 /****************************************************************************
9111 ****************************************************************************/
9113 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9114 const char *servername,
9115 const char *environment,
9116 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9121 werr = compose_spoolss_server_path(mem_ctx,
9124 SPOOLSS_PRTPROCS_PATH,
9126 if (!W_ERROR_IS_OK(werr)) {
9130 DEBUG(4,("print processor directory: [%s]\n", path));
9132 r->directory_name = path;
9137 /****************************************************************
9138 _spoolss_GetPrintProcessorDirectory
9139 ****************************************************************/
9141 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
9142 struct spoolss_GetPrintProcessorDirectory *r)
9146 /* that's an [in out] buffer */
9148 if (!r->in.buffer && (r->in.offered != 0)) {
9149 return WERR_INVALID_PARAM;
9152 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9157 /* r->in.level is ignored */
9159 /* We always should reply with a local print processor directory so that
9160 * users are not forced to have a [prnproc$] share on the Samba spoolss
9161 * server - Guenther */
9163 result = getprintprocessordirectory_level_1(p->mem_ctx,
9164 NULL, /* r->in.server */
9166 &r->out.info->info1);
9167 if (!W_ERROR_IS_OK(result)) {
9168 TALLOC_FREE(r->out.info);
9172 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9173 r->out.info, r->in.level);
9174 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9176 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9179 /*******************************************************************
9180 ********************************************************************/
9182 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9183 const char *dllname)
9185 enum ndr_err_code ndr_err;
9186 struct spoolss_MonitorUi ui;
9188 ui.dll_name = dllname;
9190 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9191 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9192 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9193 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9195 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9198 /*******************************************************************
9199 Streams the monitor UI DLL name in UNICODE
9200 *******************************************************************/
9202 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9203 NT_USER_TOKEN *token, DATA_BLOB *in,
9204 DATA_BLOB *out, uint32_t *needed)
9206 const char *dllname = "tcpmonui.dll";
9208 *needed = (strlen(dllname)+1) * 2;
9210 if (out->length < *needed) {
9211 return WERR_INSUFFICIENT_BUFFER;
9214 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9221 /*******************************************************************
9222 ********************************************************************/
9224 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9225 struct spoolss_PortData1 *port1,
9226 const DATA_BLOB *buf)
9228 enum ndr_err_code ndr_err;
9229 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9230 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9231 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9232 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9234 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9237 /*******************************************************************
9238 ********************************************************************/
9240 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9241 struct spoolss_PortData2 *port2,
9242 const DATA_BLOB *buf)
9244 enum ndr_err_code ndr_err;
9245 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9246 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9247 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9248 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9250 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9253 /*******************************************************************
9254 Create a new TCP/IP port
9255 *******************************************************************/
9257 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9258 NT_USER_TOKEN *token, DATA_BLOB *in,
9259 DATA_BLOB *out, uint32_t *needed)
9261 struct spoolss_PortData1 port1;
9262 struct spoolss_PortData2 port2;
9263 char *device_uri = NULL;
9266 const char *portname;
9267 const char *hostaddress;
9269 uint32_t port_number;
9272 /* peek for spoolss_PortData version */
9274 if (!in || (in->length < (128 + 4))) {
9275 return WERR_GENERAL_FAILURE;
9278 version = IVAL(in->data, 128);
9284 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9288 portname = port1.portname;
9289 hostaddress = port1.hostaddress;
9290 queue = port1.queue;
9291 protocol = port1.protocol;
9292 port_number = port1.port_number;
9298 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9302 portname = port2.portname;
9303 hostaddress = port2.hostaddress;
9304 queue = port2.queue;
9305 protocol = port2.protocol;
9306 port_number = port2.port_number;
9310 DEBUG(1,("xcvtcp_addport: "
9311 "unknown version of port_data: %d\n", version));
9312 return WERR_UNKNOWN_PORT;
9315 /* create the device URI and call the add_port_hook() */
9318 case PROTOCOL_RAWTCP_TYPE:
9319 device_uri = talloc_asprintf(mem_ctx,
9320 "socket://%s:%d/", hostaddress,
9324 case PROTOCOL_LPR_TYPE:
9325 device_uri = talloc_asprintf(mem_ctx,
9326 "lpr://%s/%s", hostaddress, queue );
9330 return WERR_UNKNOWN_PORT;
9337 return add_port_hook(mem_ctx, token, portname, device_uri);
9340 /*******************************************************************
9341 *******************************************************************/
9343 struct xcv_api_table xcvtcp_cmds[] = {
9344 { "MonitorUI", xcvtcp_monitorui },
9345 { "AddPort", xcvtcp_addport},
9349 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9350 NT_USER_TOKEN *token, const char *command,
9357 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9359 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9360 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9361 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9364 return WERR_BADFUNC;
9367 /*******************************************************************
9368 *******************************************************************/
9369 #if 0 /* don't support management using the "Local Port" monitor */
9371 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9372 NT_USER_TOKEN *token, DATA_BLOB *in,
9373 DATA_BLOB *out, uint32_t *needed)
9375 const char *dllname = "localui.dll";
9377 *needed = (strlen(dllname)+1) * 2;
9379 if (out->length < *needed) {
9380 return WERR_INSUFFICIENT_BUFFER;
9383 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9390 /*******************************************************************
9391 *******************************************************************/
9393 struct xcv_api_table xcvlocal_cmds[] = {
9394 { "MonitorUI", xcvlocal_monitorui },
9398 struct xcv_api_table xcvlocal_cmds[] = {
9405 /*******************************************************************
9406 *******************************************************************/
9408 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9409 NT_USER_TOKEN *token, const char *command,
9410 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9415 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9417 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9418 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9419 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9421 return WERR_BADFUNC;
9424 /****************************************************************
9426 ****************************************************************/
9428 WERROR _spoolss_XcvData(struct pipes_struct *p,
9429 struct spoolss_XcvData *r)
9431 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9432 DATA_BLOB out_data = data_blob_null;
9436 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9437 OUR_HANDLE(r->in.handle)));
9441 /* Has to be a handle to the TCP/IP port monitor */
9443 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9444 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9448 /* requires administrative access to the server */
9450 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9451 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9452 return WERR_ACCESS_DENIED;
9455 /* Allocate the outgoing buffer */
9457 if (r->in.out_data_size) {
9458 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9459 if (out_data.data == NULL) {
9464 switch ( Printer->printer_type ) {
9465 case SPLHND_PORTMON_TCP:
9466 werror = process_xcvtcp_command(p->mem_ctx,
9467 p->server_info->ptok,
9468 r->in.function_name,
9469 &r->in.in_data, &out_data,
9472 case SPLHND_PORTMON_LOCAL:
9473 werror = process_xcvlocal_command(p->mem_ctx,
9474 p->server_info->ptok,
9475 r->in.function_name,
9476 &r->in.in_data, &out_data,
9480 werror = WERR_INVALID_PRINT_MONITOR;
9483 if (!W_ERROR_IS_OK(werror)) {
9487 *r->out.status_code = 0;
9489 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9490 memcpy(r->out.out_data, out_data.data,
9491 MIN(r->in.out_data_size, out_data.length));
9497 /****************************************************************
9498 _spoolss_AddPrintProcessor
9499 ****************************************************************/
9501 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
9502 struct spoolss_AddPrintProcessor *r)
9504 /* for now, just indicate success and ignore the add. We'll
9505 automatically set the winprint processor for printer
9506 entries later. Used to debug the LexMark Optra S 1855 PCL
9512 /****************************************************************
9514 ****************************************************************/
9516 WERROR _spoolss_AddPort(struct pipes_struct *p,
9517 struct spoolss_AddPort *r)
9519 /* do what w2k3 does */
9521 return WERR_NOT_SUPPORTED;
9524 /****************************************************************
9525 _spoolss_GetPrinterDriver
9526 ****************************************************************/
9528 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
9529 struct spoolss_GetPrinterDriver *r)
9531 p->rng_fault_state = true;
9532 return WERR_NOT_SUPPORTED;
9535 /****************************************************************
9536 _spoolss_ReadPrinter
9537 ****************************************************************/
9539 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
9540 struct spoolss_ReadPrinter *r)
9542 p->rng_fault_state = true;
9543 return WERR_NOT_SUPPORTED;
9546 /****************************************************************
9547 _spoolss_WaitForPrinterChange
9548 ****************************************************************/
9550 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
9551 struct spoolss_WaitForPrinterChange *r)
9553 p->rng_fault_state = true;
9554 return WERR_NOT_SUPPORTED;
9557 /****************************************************************
9558 _spoolss_ConfigurePort
9559 ****************************************************************/
9561 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
9562 struct spoolss_ConfigurePort *r)
9564 p->rng_fault_state = true;
9565 return WERR_NOT_SUPPORTED;
9568 /****************************************************************
9570 ****************************************************************/
9572 WERROR _spoolss_DeletePort(struct pipes_struct *p,
9573 struct spoolss_DeletePort *r)
9575 p->rng_fault_state = true;
9576 return WERR_NOT_SUPPORTED;
9579 /****************************************************************
9580 _spoolss_CreatePrinterIC
9581 ****************************************************************/
9583 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
9584 struct spoolss_CreatePrinterIC *r)
9586 p->rng_fault_state = true;
9587 return WERR_NOT_SUPPORTED;
9590 /****************************************************************
9591 _spoolss_PlayGDIScriptOnPrinterIC
9592 ****************************************************************/
9594 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
9595 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9597 p->rng_fault_state = true;
9598 return WERR_NOT_SUPPORTED;
9601 /****************************************************************
9602 _spoolss_DeletePrinterIC
9603 ****************************************************************/
9605 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
9606 struct spoolss_DeletePrinterIC *r)
9608 p->rng_fault_state = true;
9609 return WERR_NOT_SUPPORTED;
9612 /****************************************************************
9613 _spoolss_AddPrinterConnection
9614 ****************************************************************/
9616 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
9617 struct spoolss_AddPrinterConnection *r)
9619 p->rng_fault_state = true;
9620 return WERR_NOT_SUPPORTED;
9623 /****************************************************************
9624 _spoolss_DeletePrinterConnection
9625 ****************************************************************/
9627 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
9628 struct spoolss_DeletePrinterConnection *r)
9630 p->rng_fault_state = true;
9631 return WERR_NOT_SUPPORTED;
9634 /****************************************************************
9635 _spoolss_PrinterMessageBox
9636 ****************************************************************/
9638 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
9639 struct spoolss_PrinterMessageBox *r)
9641 p->rng_fault_state = true;
9642 return WERR_NOT_SUPPORTED;
9645 /****************************************************************
9647 ****************************************************************/
9649 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
9650 struct spoolss_AddMonitor *r)
9652 p->rng_fault_state = true;
9653 return WERR_NOT_SUPPORTED;
9656 /****************************************************************
9657 _spoolss_DeleteMonitor
9658 ****************************************************************/
9660 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
9661 struct spoolss_DeleteMonitor *r)
9663 p->rng_fault_state = true;
9664 return WERR_NOT_SUPPORTED;
9667 /****************************************************************
9668 _spoolss_DeletePrintProcessor
9669 ****************************************************************/
9671 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
9672 struct spoolss_DeletePrintProcessor *r)
9674 p->rng_fault_state = true;
9675 return WERR_NOT_SUPPORTED;
9678 /****************************************************************
9679 _spoolss_AddPrintProvidor
9680 ****************************************************************/
9682 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
9683 struct spoolss_AddPrintProvidor *r)
9685 p->rng_fault_state = true;
9686 return WERR_NOT_SUPPORTED;
9689 /****************************************************************
9690 _spoolss_DeletePrintProvidor
9691 ****************************************************************/
9693 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
9694 struct spoolss_DeletePrintProvidor *r)
9696 p->rng_fault_state = true;
9697 return WERR_NOT_SUPPORTED;
9700 /****************************************************************
9701 _spoolss_FindFirstPrinterChangeNotification
9702 ****************************************************************/
9704 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
9705 struct spoolss_FindFirstPrinterChangeNotification *r)
9707 p->rng_fault_state = true;
9708 return WERR_NOT_SUPPORTED;
9711 /****************************************************************
9712 _spoolss_FindNextPrinterChangeNotification
9713 ****************************************************************/
9715 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
9716 struct spoolss_FindNextPrinterChangeNotification *r)
9718 p->rng_fault_state = true;
9719 return WERR_NOT_SUPPORTED;
9722 /****************************************************************
9723 _spoolss_RouterFindFirstPrinterChangeNotificationOld
9724 ****************************************************************/
9726 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
9727 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
9729 p->rng_fault_state = true;
9730 return WERR_NOT_SUPPORTED;
9733 /****************************************************************
9734 _spoolss_ReplyOpenPrinter
9735 ****************************************************************/
9737 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
9738 struct spoolss_ReplyOpenPrinter *r)
9740 p->rng_fault_state = true;
9741 return WERR_NOT_SUPPORTED;
9744 /****************************************************************
9745 _spoolss_RouterReplyPrinter
9746 ****************************************************************/
9748 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
9749 struct spoolss_RouterReplyPrinter *r)
9751 p->rng_fault_state = true;
9752 return WERR_NOT_SUPPORTED;
9755 /****************************************************************
9756 _spoolss_ReplyClosePrinter
9757 ****************************************************************/
9759 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
9760 struct spoolss_ReplyClosePrinter *r)
9762 p->rng_fault_state = true;
9763 return WERR_NOT_SUPPORTED;
9766 /****************************************************************
9768 ****************************************************************/
9770 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
9771 struct spoolss_AddPortEx *r)
9773 p->rng_fault_state = true;
9774 return WERR_NOT_SUPPORTED;
9777 /****************************************************************
9778 _spoolss_RouterFindFirstPrinterChangeNotification
9779 ****************************************************************/
9781 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
9782 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
9784 p->rng_fault_state = true;
9785 return WERR_NOT_SUPPORTED;
9788 /****************************************************************
9789 _spoolss_SpoolerInit
9790 ****************************************************************/
9792 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
9793 struct spoolss_SpoolerInit *r)
9795 p->rng_fault_state = true;
9796 return WERR_NOT_SUPPORTED;
9799 /****************************************************************
9800 _spoolss_ResetPrinterEx
9801 ****************************************************************/
9803 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
9804 struct spoolss_ResetPrinterEx *r)
9806 p->rng_fault_state = true;
9807 return WERR_NOT_SUPPORTED;
9810 /****************************************************************
9811 _spoolss_RouterReplyPrinterEx
9812 ****************************************************************/
9814 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
9815 struct spoolss_RouterReplyPrinterEx *r)
9817 p->rng_fault_state = true;
9818 return WERR_NOT_SUPPORTED;
9821 /****************************************************************
9823 ****************************************************************/
9825 WERROR _spoolss_44(struct pipes_struct *p,
9826 struct spoolss_44 *r)
9828 p->rng_fault_state = true;
9829 return WERR_NOT_SUPPORTED;
9832 /****************************************************************
9834 ****************************************************************/
9836 WERROR _spoolss_47(struct pipes_struct *p,
9837 struct spoolss_47 *r)
9839 p->rng_fault_state = true;
9840 return WERR_NOT_SUPPORTED;
9843 /****************************************************************
9845 ****************************************************************/
9847 WERROR _spoolss_4a(struct pipes_struct *p,
9848 struct spoolss_4a *r)
9850 p->rng_fault_state = true;
9851 return WERR_NOT_SUPPORTED;
9854 /****************************************************************
9856 ****************************************************************/
9858 WERROR _spoolss_4b(struct pipes_struct *p,
9859 struct spoolss_4b *r)
9861 p->rng_fault_state = true;
9862 return WERR_NOT_SUPPORTED;
9865 /****************************************************************
9867 ****************************************************************/
9869 WERROR _spoolss_4c(struct pipes_struct *p,
9870 struct spoolss_4c *r)
9872 p->rng_fault_state = true;
9873 return WERR_NOT_SUPPORTED;
9876 /****************************************************************
9878 ****************************************************************/
9880 WERROR _spoolss_53(struct pipes_struct *p,
9881 struct spoolss_53 *r)
9883 p->rng_fault_state = true;
9884 return WERR_NOT_SUPPORTED;
9887 /****************************************************************
9889 ****************************************************************/
9891 WERROR _spoolss_55(struct pipes_struct *p,
9892 struct spoolss_55 *r)
9894 p->rng_fault_state = true;
9895 return WERR_NOT_SUPPORTED;
9898 /****************************************************************
9900 ****************************************************************/
9902 WERROR _spoolss_56(struct pipes_struct *p,
9903 struct spoolss_56 *r)
9905 p->rng_fault_state = true;
9906 return WERR_NOT_SUPPORTED;
9909 /****************************************************************
9911 ****************************************************************/
9913 WERROR _spoolss_57(struct pipes_struct *p,
9914 struct spoolss_57 *r)
9916 p->rng_fault_state = true;
9917 return WERR_NOT_SUPPORTED;
9920 /****************************************************************
9922 ****************************************************************/
9924 WERROR _spoolss_5a(struct pipes_struct *p,
9925 struct spoolss_5a *r)
9927 p->rng_fault_state = true;
9928 return WERR_NOT_SUPPORTED;
9931 /****************************************************************
9933 ****************************************************************/
9935 WERROR _spoolss_5b(struct pipes_struct *p,
9936 struct spoolss_5b *r)
9938 p->rng_fault_state = true;
9939 return WERR_NOT_SUPPORTED;
9942 /****************************************************************
9944 ****************************************************************/
9946 WERROR _spoolss_5c(struct pipes_struct *p,
9947 struct spoolss_5c *r)
9949 p->rng_fault_state = true;
9950 return WERR_NOT_SUPPORTED;
9953 /****************************************************************
9955 ****************************************************************/
9957 WERROR _spoolss_5d(struct pipes_struct *p,
9958 struct spoolss_5d *r)
9960 p->rng_fault_state = true;
9961 return WERR_NOT_SUPPORTED;
9964 /****************************************************************
9966 ****************************************************************/
9968 WERROR _spoolss_5e(struct pipes_struct *p,
9969 struct spoolss_5e *r)
9971 p->rng_fault_state = true;
9972 return WERR_NOT_SUPPORTED;
9975 /****************************************************************
9977 ****************************************************************/
9979 WERROR _spoolss_5f(struct pipes_struct *p,
9980 struct spoolss_5f *r)
9982 p->rng_fault_state = true;
9983 return WERR_NOT_SUPPORTED;
9986 /****************************************************************
9988 ****************************************************************/
9990 WERROR _spoolss_60(struct pipes_struct *p,
9991 struct spoolss_60 *r)
9993 p->rng_fault_state = true;
9994 return WERR_NOT_SUPPORTED;
9997 /****************************************************************
9999 ****************************************************************/
10001 WERROR _spoolss_61(struct pipes_struct *p,
10002 struct spoolss_61 *r)
10004 p->rng_fault_state = true;
10005 return WERR_NOT_SUPPORTED;
10008 /****************************************************************
10010 ****************************************************************/
10012 WERROR _spoolss_62(struct pipes_struct *p,
10013 struct spoolss_62 *r)
10015 p->rng_fault_state = true;
10016 return WERR_NOT_SUPPORTED;
10019 /****************************************************************
10021 ****************************************************************/
10023 WERROR _spoolss_63(struct pipes_struct *p,
10024 struct spoolss_63 *r)
10026 p->rng_fault_state = true;
10027 return WERR_NOT_SUPPORTED;
10030 /****************************************************************
10032 ****************************************************************/
10034 WERROR _spoolss_64(struct pipes_struct *p,
10035 struct spoolss_64 *r)
10037 p->rng_fault_state = true;
10038 return WERR_NOT_SUPPORTED;
10041 /****************************************************************
10043 ****************************************************************/
10045 WERROR _spoolss_65(struct pipes_struct *p,
10046 struct spoolss_65 *r)
10048 p->rng_fault_state = true;
10049 return WERR_NOT_SUPPORTED;
10052 /****************************************************************
10053 _spoolss_GetCorePrinterDrivers
10054 ****************************************************************/
10056 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10057 struct spoolss_GetCorePrinterDrivers *r)
10059 p->rng_fault_state = true;
10060 return WERR_NOT_SUPPORTED;
10063 /****************************************************************
10065 ****************************************************************/
10067 WERROR _spoolss_67(struct pipes_struct *p,
10068 struct spoolss_67 *r)
10070 p->rng_fault_state = true;
10071 return WERR_NOT_SUPPORTED;
10074 /****************************************************************
10075 _spoolss_GetPrinterDriverPackagePath
10076 ****************************************************************/
10078 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10079 struct spoolss_GetPrinterDriverPackagePath *r)
10081 p->rng_fault_state = true;
10082 return WERR_NOT_SUPPORTED;
10085 /****************************************************************
10087 ****************************************************************/
10089 WERROR _spoolss_69(struct pipes_struct *p,
10090 struct spoolss_69 *r)
10092 p->rng_fault_state = true;
10093 return WERR_NOT_SUPPORTED;
10096 /****************************************************************
10098 ****************************************************************/
10100 WERROR _spoolss_6a(struct pipes_struct *p,
10101 struct spoolss_6a *r)
10103 p->rng_fault_state = true;
10104 return WERR_NOT_SUPPORTED;
10107 /****************************************************************
10109 ****************************************************************/
10111 WERROR _spoolss_6b(struct pipes_struct *p,
10112 struct spoolss_6b *r)
10114 p->rng_fault_state = true;
10115 return WERR_NOT_SUPPORTED;
10118 /****************************************************************
10120 ****************************************************************/
10122 WERROR _spoolss_6c(struct pipes_struct *p,
10123 struct spoolss_6c *r)
10125 p->rng_fault_state = true;
10126 return WERR_NOT_SUPPORTED;
10129 /****************************************************************
10131 ****************************************************************/
10133 WERROR _spoolss_6d(struct pipes_struct *p,
10134 struct spoolss_6d *r)
10136 p->rng_fault_state = true;
10137 return WERR_NOT_SUPPORTED;