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.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
27 up, all the errors returned are DOS errors, not NT status codes. */
30 #include "srv_spoolss_util.h"
31 #include "../librpc/gen_ndr/srv_spoolss.h"
32 #include "../librpc/gen_ndr/cli_spoolss.h"
33 #include "rpc_client/init_spoolss.h"
34 #include "librpc/gen_ndr/messaging.h"
36 #include "registry/reg_objects.h"
38 /* macros stolen from s4 spoolss server */
39 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
40 ((info)?ndr_size_##fn(info, level, 0):0)
42 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
43 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
45 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
46 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
48 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
51 extern userdom_struct current_user_info;
54 #define DBGC_CLASS DBGC_RPC_SRV
56 #ifndef MAX_OPEN_PRINTER_EXS
57 #define MAX_OPEN_PRINTER_EXS 50
60 #define MAGIC_DISPLAY_FREQUENCY 0xfade2bad
62 static Printer_entry *printers_list;
64 typedef struct _counter_printer_0 {
65 struct _counter_printer_0 *next;
66 struct _counter_printer_0 *prev;
72 static counter_printer_0 *counter_list;
74 static struct rpc_pipe_client *notify_cli_pipe; /* print notify back-channel pipe handle*/
75 static uint32_t smb_connections = 0;
78 /* in printing/nt_printing.c */
80 extern struct standard_mapping printer_std_mapping, printserver_std_mapping;
82 /* API table for Xcv Monitor functions */
84 struct xcv_api_table {
86 WERROR(*fn) (TALLOC_CTX *mem_ctx, NT_USER_TOKEN *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
89 /********************************************************************
90 * Canonicalize servername.
91 ********************************************************************/
93 static const char *canon_servername(const char *servername)
95 const char *pservername = servername;
96 while (*pservername == '\\') {
102 /* translate between internal status numbers and NT status numbers */
103 static int nt_printj_status(int v)
109 return JOB_STATUS_PAUSED;
111 return JOB_STATUS_SPOOLING;
113 return JOB_STATUS_PRINTING;
115 return JOB_STATUS_ERROR;
117 return JOB_STATUS_DELETING;
119 return JOB_STATUS_OFFLINE;
121 return JOB_STATUS_PAPEROUT;
123 return JOB_STATUS_PRINTED;
125 return JOB_STATUS_DELETED;
127 return JOB_STATUS_BLOCKED_DEVQ;
128 case LPQ_USER_INTERVENTION:
129 return JOB_STATUS_USER_INTERVENTION;
134 static int nt_printq_status(int v)
138 return PRINTER_STATUS_PAUSED;
147 /***************************************************************************
148 Disconnect from the client
149 ****************************************************************************/
151 static void srv_spoolss_replycloseprinter(int snum, struct policy_handle *handle)
157 * Tell the specific printing tdb we no longer want messages for this printer
158 * by deregistering our PID.
161 if (!print_notify_deregister_pid(snum))
162 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
164 /* weird if the test succeds !!! */
165 if (smb_connections==0) {
166 DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
170 status = rpccli_spoolss_ReplyClosePrinter(notify_cli_pipe, talloc_tos(),
173 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
174 DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
175 win_errstr(result)));
177 /* if it's the last connection, deconnect the IPC$ share */
178 if (smb_connections==1) {
180 cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) );
181 notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */
183 messaging_deregister(smbd_messaging_context(),
184 MSG_PRINTER_NOTIFY2, NULL);
186 /* Tell the connections db we're no longer interested in
187 * printer notify messages. */
189 serverid_register_msg_flags(
190 messaging_server_id(smbd_messaging_context()),
191 false, FLAG_MSG_PRINT_NOTIFY);
197 /****************************************************************************
198 Functions to free a printer entry datastruct.
199 ****************************************************************************/
201 static int printer_entry_destructor(Printer_entry *Printer)
203 if (Printer->notify.client_connected == true) {
206 if ( Printer->printer_type == SPLHND_SERVER) {
208 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
209 } else if (Printer->printer_type == SPLHND_PRINTER) {
210 snum = print_queue_snum(Printer->sharename);
212 srv_spoolss_replycloseprinter(snum,
213 &Printer->notify.client_hnd);
217 Printer->notify.flags=0;
218 Printer->notify.options=0;
219 Printer->notify.localmachine[0]='\0';
220 Printer->notify.printerlocal=0;
221 TALLOC_FREE(Printer->notify.option);
222 Printer->notify.client_connected = false;
224 TALLOC_FREE(Printer->devmode);
225 free_a_printer( &Printer->printer_info, 2 );
227 /* Remove from the internal list. */
228 DLIST_REMOVE(printers_list, Printer);
232 /****************************************************************************
233 find printer index by handle
234 ****************************************************************************/
236 static Printer_entry *find_printer_index_by_hnd(pipes_struct *p,
237 struct policy_handle *hnd)
239 Printer_entry *find_printer = NULL;
241 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
242 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
249 /****************************************************************************
250 Close printer index by handle.
251 ****************************************************************************/
253 static bool close_printer_handle(pipes_struct *p, struct policy_handle *hnd)
255 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
258 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
263 close_policy_hnd(p, hnd);
268 /****************************************************************************
269 Delete a printer given a handle.
270 ****************************************************************************/
272 static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *sharename)
274 char *cmd = lp_deleteprinter_cmd();
275 char *command = NULL;
277 SE_PRIV se_printop = SE_PRINT_OPERATOR;
278 bool is_print_op = false;
280 /* can't fail if we don't try */
285 command = talloc_asprintf(ctx,
292 is_print_op = user_has_privileges( token, &se_printop );
294 DEBUG(10,("Running [%s]\n", command));
296 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
301 if ( (ret = smbrun(command, NULL)) == 0 ) {
302 /* Tell everyone we updated smb.conf. */
303 message_send_all(smbd_messaging_context(),
304 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
310 /********** END SePrintOperatorPrivlege BLOCK **********/
312 DEBUGADD(10,("returned [%d]\n", ret));
314 TALLOC_FREE(command);
317 return WERR_BADFID; /* What to return here? */
319 /* go ahead and re-read the services immediately */
321 reload_services(false);
324 if ( lp_servicenumber( sharename ) > 0 )
325 return WERR_ACCESS_DENIED;
330 /****************************************************************************
331 Delete a printer given a handle.
332 ****************************************************************************/
334 static WERROR delete_printer_handle(pipes_struct *p, struct policy_handle *hnd)
336 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
339 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
345 * It turns out that Windows allows delete printer on a handle
346 * opened by an admin user, then used on a pipe handle created
347 * by an anonymous user..... but they're working on security.... riiight !
351 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
352 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
353 return WERR_ACCESS_DENIED;
356 /* this does not need a become root since the access check has been
357 done on the handle already */
359 if (del_a_printer( Printer->sharename ) != 0) {
360 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
364 return delete_printer_hook(p->mem_ctx, p->server_info->ptok,
365 Printer->sharename );
368 /****************************************************************************
369 Return the snum of a printer corresponding to an handle.
370 ****************************************************************************/
372 static bool get_printer_snum(pipes_struct *p, struct policy_handle *hnd,
373 int *number, struct share_params **params)
375 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
378 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
383 switch (Printer->printer_type) {
385 DEBUG(4,("short name:%s\n", Printer->sharename));
386 *number = print_queue_snum(Printer->sharename);
387 return (*number != -1);
395 /****************************************************************************
396 Set printer handle type.
397 Check if it's \\server or \\server\printer
398 ****************************************************************************/
400 static bool set_printer_hnd_printertype(Printer_entry *Printer, const char *handlename)
402 DEBUG(3,("Setting printer type=%s\n", handlename));
404 if ( strlen(handlename) < 3 ) {
405 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", handlename));
409 /* it's a print server */
410 if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
411 DEBUGADD(4,("Printer is a print server\n"));
412 Printer->printer_type = SPLHND_SERVER;
414 /* it's a printer (set_printer_hnd_name() will handle port monitors */
416 DEBUGADD(4,("Printer is a printer\n"));
417 Printer->printer_type = SPLHND_PRINTER;
423 /****************************************************************************
424 Set printer handle name.. Accept names like \\server, \\server\printer,
425 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
426 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
427 XcvDataPort() interface.
428 ****************************************************************************/
430 static bool set_printer_hnd_name(Printer_entry *Printer, const char *handlename)
433 int n_services=lp_numservices();
434 char *aprinter, *printername;
435 const char *servername;
438 NT_PRINTER_INFO_LEVEL *printer = NULL;
441 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
442 (unsigned long)strlen(handlename)));
444 aprinter = CONST_DISCARD(char *, handlename);
445 if ( *handlename == '\\' ) {
446 servername = canon_servername(handlename);
447 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
452 servername = global_myname();
455 /* save the servername to fill in replies on this handle */
457 if ( !is_myname_or_ipaddr( servername ) )
460 fstrcpy( Printer->servername, servername );
462 if ( Printer->printer_type == SPLHND_SERVER )
465 if ( Printer->printer_type != SPLHND_PRINTER )
468 DEBUGADD(5, ("searching for [%s]\n", aprinter ));
470 /* check for the Port Monitor Interface */
472 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
473 Printer->printer_type = SPLHND_PORTMON_TCP;
474 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
477 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
478 Printer->printer_type = SPLHND_PORTMON_LOCAL;
479 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
483 /* Search all sharenames first as this is easier than pulling
484 the printer_info_2 off of disk. Don't use find_service() since
485 that calls out to map_username() */
487 /* do another loop to look for printernames */
489 for (snum=0; !found && snum<n_services; snum++) {
491 /* no point going on if this is not a printer */
493 if ( !(lp_snum_ok(snum) && lp_print_ok(snum)) )
496 fstrcpy(sname, lp_servicename(snum));
497 if ( strequal( aprinter, sname ) ) {
502 /* no point looking up the printer object if
503 we aren't allowing printername != sharename */
505 if ( lp_force_printername(snum) )
508 fstrcpy(sname, lp_servicename(snum));
512 /* This call doesn't fill in the location or comment from
513 * a CUPS server for efficiency with large numbers of printers.
517 result = get_a_printer_search( NULL, &printer, 2, sname );
518 if ( !W_ERROR_IS_OK(result) ) {
519 DEBUG(0,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
520 sname, win_errstr(result)));
524 /* printername is always returned as \\server\printername */
525 if ( !(printername = strchr_m(&printer->info_2->printername[2], '\\')) ) {
526 DEBUG(0,("set_printer_hnd_name: info2->printername in wrong format! [%s]\n",
527 printer->info_2->printername));
528 free_a_printer( &printer, 2);
534 if ( strequal(printername, aprinter) ) {
535 free_a_printer( &printer, 2);
540 DEBUGADD(10, ("printername: %s\n", printername));
542 free_a_printer( &printer, 2);
545 free_a_printer( &printer, 2);
548 DEBUGADD(4,("Printer not found\n"));
552 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
554 fstrcpy(Printer->sharename, sname);
559 /****************************************************************************
560 Find first available printer slot. creates a printer handle for you.
561 ****************************************************************************/
563 static bool open_printer_hnd(pipes_struct *p, struct policy_handle *hnd,
564 const char *name, uint32_t access_granted)
566 Printer_entry *new_printer;
568 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
570 new_printer = TALLOC_ZERO_P(NULL, Printer_entry);
571 if (new_printer == NULL) {
574 talloc_set_destructor(new_printer, printer_entry_destructor);
576 if (!create_policy_hnd(p, hnd, new_printer)) {
577 TALLOC_FREE(new_printer);
581 /* Add to the internal list. */
582 DLIST_ADD(printers_list, new_printer);
584 new_printer->notify.option=NULL;
586 if (!set_printer_hnd_printertype(new_printer, name)) {
587 close_printer_handle(p, hnd);
591 if (!set_printer_hnd_name(new_printer, name)) {
592 close_printer_handle(p, hnd);
596 new_printer->access_granted = access_granted;
598 DEBUG(5, ("%d printer handles active\n",
599 (int)num_pipe_handles(p)));
604 /***************************************************************************
605 check to see if the client motify handle is monitoring the notification
606 given by (notify_type, notify_field).
607 **************************************************************************/
609 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
610 uint16_t notify_field)
615 static bool is_monitoring_event(Printer_entry *p, uint16_t notify_type,
616 uint16_t notify_field)
618 struct spoolss_NotifyOption *option = p->notify.option;
622 * Flags should always be zero when the change notify
623 * is registered by the client's spooler. A user Win32 app
624 * might use the flags though instead of the NOTIFY_OPTION_INFO
633 return is_monitoring_event_flags(
634 p->notify.flags, notify_type, notify_field);
636 for (i = 0; i < option->count; i++) {
638 /* Check match for notify_type */
640 if (option->types[i].type != notify_type)
643 /* Check match for field */
645 for (j = 0; j < option->types[i].count; j++) {
646 if (option->types[i].fields[j].field == notify_field) {
652 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
653 p->servername, p->sharename, notify_type, notify_field));
658 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
659 _data->data.integer[0] = _integer; \
660 _data->data.integer[1] = 0;
663 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
664 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
665 if (!_data->data.string.string) {\
666 _data->data.string.size = 0; \
668 _data->data.string.size = strlen_m_term(_p) * 2;
670 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
671 _data->data.devmode.devmode = _devmode;
673 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _size, _sd) \
674 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
675 if (!_data->data.sd.sd) { \
676 _data->data.sd.sd_size = 0; \
678 _data->data.sd.sd_size = _size;
680 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
685 struct spoolss_Time st;
689 if (!init_systemtime(&st, t)) {
693 p = talloc_array(mem_ctx, char, len);
699 * Systemtime must be linearized as a set of UINT16's.
700 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
703 SSVAL(p, 0, st.year);
704 SSVAL(p, 2, st.month);
705 SSVAL(p, 4, st.day_of_week);
707 SSVAL(p, 8, st.hour);
708 SSVAL(p, 10, st.minute);
709 SSVAL(p, 12, st.second);
710 SSVAL(p, 14, st.millisecond);
716 /* Convert a notification message to a struct spoolss_Notify */
718 static void notify_one_value(struct spoolss_notify_msg *msg,
719 struct spoolss_Notify *data,
722 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
725 static void notify_string(struct spoolss_notify_msg *msg,
726 struct spoolss_Notify *data,
729 /* The length of the message includes the trailing \0 */
731 data->data.string.size = msg->len * 2;
732 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
733 if (!data->data.string.string) {
734 data->data.string.size = 0;
739 static void notify_system_time(struct spoolss_notify_msg *msg,
740 struct spoolss_Notify *data,
743 data->data.string.string = NULL;
744 data->data.string.size = 0;
746 if (msg->len != sizeof(time_t)) {
747 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
752 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
753 &data->data.string.string,
754 &data->data.string.size);
757 struct notify2_message_table {
759 void (*fn)(struct spoolss_notify_msg *msg,
760 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
763 static struct notify2_message_table printer_notify_table[] = {
764 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
765 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
766 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
767 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
768 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
769 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
770 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
771 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
772 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
773 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
774 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
775 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
776 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
777 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
778 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
779 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
780 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
781 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
782 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
785 static struct notify2_message_table job_notify_table[] = {
786 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
787 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
788 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
789 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
790 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
791 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
792 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
793 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
794 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
795 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
796 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
797 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
798 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
799 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
800 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
801 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
802 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
803 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
804 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
805 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
806 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
807 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
808 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
809 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
813 /***********************************************************************
814 Allocate talloc context for container object
815 **********************************************************************/
817 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
822 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
827 /***********************************************************************
828 release all allocated memory and zero out structure
829 **********************************************************************/
831 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
837 talloc_destroy(ctr->ctx);
844 /***********************************************************************
845 **********************************************************************/
847 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
855 /***********************************************************************
856 **********************************************************************/
858 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
860 if ( !ctr || !ctr->msg_groups )
863 if ( idx >= ctr->num_groups )
866 return &ctr->msg_groups[idx];
870 /***********************************************************************
871 How many groups of change messages do we have ?
872 **********************************************************************/
874 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
879 return ctr->num_groups;
882 /***********************************************************************
883 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
884 **********************************************************************/
886 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
888 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
889 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
890 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
896 /* loop over all groups looking for a matching printer name */
898 for ( i=0; i<ctr->num_groups; i++ ) {
899 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
903 /* add a new group? */
905 if ( i == ctr->num_groups ) {
908 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
909 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
912 ctr->msg_groups = groups;
914 /* clear the new entry and set the printer name */
916 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
917 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
920 /* add the change messages; 'i' is the correct index now regardless */
922 msg_grp = &ctr->msg_groups[i];
926 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
927 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
930 msg_grp->msgs = msg_list;
932 new_slot = msg_grp->num_msgs-1;
933 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
935 /* need to allocate own copy of data */
938 msg_grp->msgs[new_slot].notify.data = (char *)
939 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
941 return ctr->num_groups;
944 void construct_info_data(struct spoolss_Notify *info_data,
945 enum spoolss_NotifyType type,
949 /***********************************************************************
950 Send a change notication message on all handles which have a call
952 **********************************************************************/
954 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
957 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
958 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
959 SPOOLSS_NOTIFY_MSG *messages;
960 int sending_msg_count;
963 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
967 messages = msg_group->msgs;
970 DEBUG(5,("send_notify2_changes() called with no messages!\n"));
974 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
976 /* loop over all printers */
978 for (p = printers_list; p; p = p->next) {
979 struct spoolss_Notify *notifies;
984 /* Is there notification on this handle? */
986 if ( !p->notify.client_connected )
989 DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
991 /* For this printer? Print servers always receive
994 if ( ( p->printer_type == SPLHND_PRINTER ) &&
995 ( !strequal(msg_group->printername, p->sharename) ) )
998 DEBUG(10,("Our printer\n"));
1000 /* allocate the max entries possible */
1002 notifies = TALLOC_ZERO_ARRAY(mem_ctx, struct spoolss_Notify, msg_group->num_msgs);
1007 /* build the array of change notifications */
1009 sending_msg_count = 0;
1011 for ( i=0; i<msg_group->num_msgs; i++ ) {
1012 SPOOLSS_NOTIFY_MSG *msg = &messages[i];
1014 /* Are we monitoring this event? */
1016 if (!is_monitoring_event(p, msg->type, msg->field))
1019 sending_msg_count++;
1022 DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
1023 msg->type, msg->field, p->sharename));
1026 * if the is a printer notification handle and not a job notification
1027 * type, then set the id to 0. Other wise just use what was specified
1030 * When registering change notification on a print server handle
1031 * we always need to send back the id (snum) matching the printer
1032 * for which the change took place. For change notify registered
1033 * on a printer handle, this does not matter and the id should be 0.
1038 if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
1044 /* Convert unix jobid to smb jobid */
1046 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1047 id = sysjob_to_jobid(msg->id);
1050 DEBUG(3, ("no such unix jobid %d\n", msg->id));
1055 construct_info_data( ¬ifies[count], msg->type, msg->field, id );
1058 case PRINTER_NOTIFY_TYPE:
1059 if ( printer_notify_table[msg->field].fn )
1060 printer_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1063 case JOB_NOTIFY_TYPE:
1064 if ( job_notify_table[msg->field].fn )
1065 job_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1069 DEBUG(5, ("Unknown notification type %d\n", msg->type));
1076 if ( sending_msg_count ) {
1079 union spoolss_ReplyPrinterInfo info;
1080 struct spoolss_NotifyInfo info0;
1081 uint32_t reply_result;
1083 info0.version = 0x2;
1084 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1085 info0.count = count;
1086 info0.notifies = notifies;
1088 info.info0 = &info0;
1090 status = rpccli_spoolss_RouterReplyPrinterEx(notify_cli_pipe, mem_ctx,
1091 &p->notify.client_hnd,
1092 p->notify.change, /* color */
1095 0, /* reply_type, must be 0 */
1098 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1099 DEBUG(1,("RouterReplyPrinterEx to client: %s failed: %s\n",
1100 notify_cli_pipe->srv_name_slash,
1103 switch (reply_result) {
1106 case PRINTER_NOTIFY_INFO_DISCARDED:
1107 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1108 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1117 DEBUG(8,("send_notify2_changes: Exit...\n"));
1121 /***********************************************************************
1122 **********************************************************************/
1124 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1127 uint32_t tv_sec, tv_usec;
1130 /* Unpack message */
1132 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1135 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1137 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1140 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1141 &msg->notify.value[0], &msg->notify.value[1]);
1143 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1144 &msg->len, &msg->notify.data);
1146 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1147 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1149 tv->tv_sec = tv_sec;
1150 tv->tv_usec = tv_usec;
1153 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1154 msg->notify.value[1]));
1156 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1161 /********************************************************************
1162 Receive a notify2 message list
1163 ********************************************************************/
1165 static void receive_notify2_message_list(struct messaging_context *msg,
1168 struct server_id server_id,
1171 size_t msg_count, i;
1172 char *buf = (char *)data->data;
1175 SPOOLSS_NOTIFY_MSG notify;
1176 SPOOLSS_NOTIFY_MSG_CTR messages;
1179 if (data->length < 4) {
1180 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1184 msg_count = IVAL(buf, 0);
1187 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1189 if (msg_count == 0) {
1190 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1194 /* initialize the container */
1196 ZERO_STRUCT( messages );
1197 notify_msg_ctr_init( &messages );
1200 * build message groups for each printer identified
1201 * in a change_notify msg. Remember that a PCN message
1202 * includes the handle returned for the srv_spoolss_replyopenprinter()
1203 * call. Therefore messages are grouped according to printer handle.
1206 for ( i=0; i<msg_count; i++ ) {
1207 struct timeval msg_tv;
1209 if (msg_ptr + 4 - buf > data->length) {
1210 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1214 msg_len = IVAL(msg_ptr,0);
1217 if (msg_ptr + msg_len - buf > data->length) {
1218 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1222 /* unpack messages */
1224 ZERO_STRUCT( notify );
1225 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1228 /* add to correct list in container */
1230 notify_msg_ctr_addmsg( &messages, ¬ify );
1232 /* free memory that might have been allocated by notify2_unpack_msg() */
1234 if ( notify.len != 0 )
1235 SAFE_FREE( notify.notify.data );
1238 /* process each group of messages */
1240 num_groups = notify_msg_ctr_numgroups( &messages );
1241 for ( i=0; i<num_groups; i++ )
1242 send_notify2_changes( &messages, i );
1247 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1248 (uint32_t)msg_count ));
1250 notify_msg_ctr_destroy( &messages );
1255 /********************************************************************
1256 Send a message to ourself about new driver being installed
1257 so we can upgrade the information for each printer bound to this
1259 ********************************************************************/
1261 static bool srv_spoolss_drv_upgrade_printer(const char *drivername)
1263 int len = strlen(drivername);
1268 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1271 messaging_send_buf(smbd_messaging_context(),
1272 messaging_server_id(smbd_messaging_context()),
1273 MSG_PRINTER_DRVUPGRADE,
1274 (uint8_t *)drivername, len+1);
1279 /**********************************************************************
1280 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1281 over all printers, upgrading ones as necessary
1282 **********************************************************************/
1284 void do_drv_upgrade_printer(struct messaging_context *msg,
1287 struct server_id server_id,
1292 int n_services = lp_numservices();
1295 len = MIN(data->length,sizeof(drivername)-1);
1296 strncpy(drivername, (const char *)data->data, len);
1298 DEBUG(10,("do_drv_upgrade_printer: Got message for new driver [%s]\n", drivername ));
1300 /* Iterate the printer list */
1302 for (snum=0; snum<n_services; snum++)
1304 if (lp_snum_ok(snum) && lp_print_ok(snum) )
1307 NT_PRINTER_INFO_LEVEL *printer = NULL;
1309 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
1310 if (!W_ERROR_IS_OK(result))
1313 if (printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername))
1315 DEBUG(6,("Updating printer [%s]\n", printer->info_2->printername));
1317 /* all we care about currently is the change_id */
1319 result = mod_a_printer(printer, 2);
1320 if (!W_ERROR_IS_OK(result)) {
1321 DEBUG(3,("do_drv_upgrade_printer: mod_a_printer() failed with status [%s]\n",
1322 win_errstr(result)));
1326 free_a_printer(&printer, 2);
1333 /********************************************************************
1334 Update the cache for all printq's with a registered client
1336 ********************************************************************/
1338 void update_monitored_printq_cache( void )
1340 Printer_entry *printer = printers_list;
1343 /* loop through all printers and update the cache where
1344 client_connected == true */
1347 if ( (printer->printer_type == SPLHND_PRINTER)
1348 && printer->notify.client_connected )
1350 snum = print_queue_snum(printer->sharename);
1351 print_queue_status( snum, NULL, NULL );
1354 printer = printer->next;
1360 /****************************************************************
1361 _spoolss_OpenPrinter
1362 ****************************************************************/
1364 WERROR _spoolss_OpenPrinter(pipes_struct *p,
1365 struct spoolss_OpenPrinter *r)
1367 struct spoolss_OpenPrinterEx e;
1370 ZERO_STRUCT(e.in.userlevel);
1372 e.in.printername = r->in.printername;
1373 e.in.datatype = r->in.datatype;
1374 e.in.devmode_ctr = r->in.devmode_ctr;
1375 e.in.access_mask = r->in.access_mask;
1378 e.out.handle = r->out.handle;
1380 werr = _spoolss_OpenPrinterEx(p, &e);
1382 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1383 /* OpenPrinterEx returns this for a bad
1384 * printer name. We must return WERR_INVALID_PRINTER_NAME
1387 werr = WERR_INVALID_PRINTER_NAME;
1393 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1394 struct spoolss_DeviceMode *orig,
1395 struct spoolss_DeviceMode **dest)
1397 struct spoolss_DeviceMode *dm;
1399 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1404 /* copy all values, then duplicate strings and structs */
1407 dm->devicename = talloc_strdup(dm, orig->devicename);
1408 if (!dm->devicename) {
1411 dm->formname = talloc_strdup(dm, orig->formname);
1412 if (!dm->formname) {
1415 if (orig->driverextra_data.data) {
1416 dm->driverextra_data.data =
1417 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1418 orig->driverextra_data.length);
1419 if (!dm->driverextra_data.data) {
1428 /****************************************************************
1429 _spoolss_OpenPrinterEx
1430 ****************************************************************/
1432 WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
1433 struct spoolss_OpenPrinterEx *r)
1436 Printer_entry *Printer=NULL;
1438 if (!r->in.printername) {
1439 return WERR_INVALID_PARAM;
1442 /* some sanity check because you can open a printer or a print server */
1443 /* aka: \\server\printer or \\server */
1445 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1447 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1448 ZERO_STRUCTP(r->out.handle);
1449 return WERR_INVALID_PARAM;
1452 Printer = find_printer_index_by_hnd(p, r->out.handle);
1454 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1455 "handle we created for printer %s\n", r->in.printername));
1456 close_printer_handle(p, r->out.handle);
1457 ZERO_STRUCTP(r->out.handle);
1458 return WERR_INVALID_PARAM;
1462 * First case: the user is opening the print server:
1464 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1465 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1467 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1468 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1469 * or if the user is listed in the smb.conf printer admin parameter.
1471 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1472 * client view printer folder, but does not show the MSAPW.
1474 * Note: this test needs code to check access rights here too. Jeremy
1475 * could you look at this?
1477 * Second case: the user is opening a printer:
1478 * NT doesn't let us connect to a printer if the connecting user
1479 * doesn't have print permission.
1481 * Third case: user is opening a Port Monitor
1482 * access checks same as opening a handle to the print server.
1485 switch (Printer->printer_type )
1488 case SPLHND_PORTMON_TCP:
1489 case SPLHND_PORTMON_LOCAL:
1490 /* Printserver handles use global struct... */
1494 /* Map standard access rights to object specific access rights */
1496 se_map_standard(&r->in.access_mask,
1497 &printserver_std_mapping);
1499 /* Deny any object specific bits that don't apply to print
1500 servers (i.e printer and job specific bits) */
1502 r->in.access_mask &= SEC_MASK_SPECIFIC;
1504 if (r->in.access_mask &
1505 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1506 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1507 close_printer_handle(p, r->out.handle);
1508 ZERO_STRUCTP(r->out.handle);
1509 return WERR_ACCESS_DENIED;
1512 /* Allow admin access */
1514 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1516 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1518 if (!lp_ms_add_printer_wizard()) {
1519 close_printer_handle(p, r->out.handle);
1520 ZERO_STRUCTP(r->out.handle);
1521 return WERR_ACCESS_DENIED;
1524 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1525 and not a printer admin, then fail */
1527 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1528 !user_has_privileges(p->server_info->ptok,
1530 !token_contains_name_in_list(
1531 uidtoname(p->server_info->utok.uid),
1532 p->server_info->info3->base.domain.string,
1534 p->server_info->ptok,
1535 lp_printer_admin(snum))) {
1536 close_printer_handle(p, r->out.handle);
1537 ZERO_STRUCTP(r->out.handle);
1538 return WERR_ACCESS_DENIED;
1541 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1545 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1548 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1549 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1551 /* We fall through to return WERR_OK */
1554 case SPLHND_PRINTER:
1555 /* NT doesn't let us connect to a printer if the connecting user
1556 doesn't have print permission. */
1558 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1559 close_printer_handle(p, r->out.handle);
1560 ZERO_STRUCTP(r->out.handle);
1564 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1565 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1568 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1570 /* map an empty access mask to the minimum access mask */
1571 if (r->in.access_mask == 0x0)
1572 r->in.access_mask = PRINTER_ACCESS_USE;
1575 * If we are not serving the printer driver for this printer,
1576 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1577 * will keep NT clients happy --jerry
1580 if (lp_use_client_driver(snum)
1581 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1583 r->in.access_mask = PRINTER_ACCESS_USE;
1586 /* check smb.conf parameters and the the sec_desc */
1588 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1589 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1590 ZERO_STRUCTP(r->out.handle);
1591 return WERR_ACCESS_DENIED;
1594 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1595 p->server_info->ptok, snum) ||
1596 !print_access_check(p->server_info, snum,
1597 r->in.access_mask)) {
1598 DEBUG(3, ("access DENIED for printer open\n"));
1599 close_printer_handle(p, r->out.handle);
1600 ZERO_STRUCTP(r->out.handle);
1601 return WERR_ACCESS_DENIED;
1604 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1605 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1606 close_printer_handle(p, r->out.handle);
1607 ZERO_STRUCTP(r->out.handle);
1608 return WERR_ACCESS_DENIED;
1611 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1612 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1614 r->in.access_mask = PRINTER_ACCESS_USE;
1616 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1617 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1622 /* sanity check to prevent programmer error */
1623 ZERO_STRUCTP(r->out.handle);
1627 Printer->access_granted = r->in.access_mask;
1630 * If the client sent a devmode in the OpenPrinter() call, then
1631 * save it here in case we get a job submission on this handle
1634 if ((Printer->printer_type != SPLHND_SERVER) &&
1635 r->in.devmode_ctr.devmode) {
1636 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1640 #if 0 /* JERRY -- I'm doubtful this is really effective */
1641 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1642 optimization in Windows 2000 clients --jerry */
1644 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1645 && (RA_WIN2K == get_remote_arch()) )
1647 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1648 sys_usleep( 500000 );
1655 /****************************************************************************
1656 ****************************************************************************/
1658 static bool printer_info2_to_nt_printer_info2(struct spoolss_SetPrinterInfo2 *r,
1659 NT_PRINTER_INFO_LEVEL_2 *d)
1661 DEBUG(7,("printer_info2_to_nt_printer_info2\n"));
1667 d->attributes = r->attributes;
1668 d->priority = r->priority;
1669 d->default_priority = r->defaultpriority;
1670 d->starttime = r->starttime;
1671 d->untiltime = r->untiltime;
1672 d->status = r->status;
1673 d->cjobs = r->cjobs;
1675 fstrcpy(d->servername, r->servername);
1676 fstrcpy(d->printername, r->printername);
1677 fstrcpy(d->sharename, r->sharename);
1678 fstrcpy(d->portname, r->portname);
1679 fstrcpy(d->drivername, r->drivername);
1680 slprintf(d->comment, sizeof(d->comment)-1, "%s", r->comment);
1681 fstrcpy(d->location, r->location);
1682 fstrcpy(d->sepfile, r->sepfile);
1683 fstrcpy(d->printprocessor, r->printprocessor);
1684 fstrcpy(d->datatype, r->datatype);
1685 fstrcpy(d->parameters, r->parameters);
1690 /****************************************************************************
1691 ****************************************************************************/
1693 static bool convert_printer_info(struct spoolss_SetPrinterInfoCtr *info_ctr,
1694 NT_PRINTER_INFO_LEVEL *printer)
1698 switch (info_ctr->level) {
1700 /* allocate memory if needed. Messy because
1701 convert_printer_info is used to update an existing
1702 printer or build a new one */
1704 if (!printer->info_2) {
1705 printer->info_2 = TALLOC_ZERO_P(printer, NT_PRINTER_INFO_LEVEL_2);
1706 if (!printer->info_2) {
1707 DEBUG(0,("convert_printer_info: "
1708 "talloc() failed!\n"));
1713 ret = printer_info2_to_nt_printer_info2(info_ctr->info.info2,
1715 printer->info_2->setuptime = time(NULL);
1722 /****************************************************************
1723 _spoolss_ClosePrinter
1724 ****************************************************************/
1726 WERROR _spoolss_ClosePrinter(pipes_struct *p,
1727 struct spoolss_ClosePrinter *r)
1729 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1731 if (Printer && Printer->document_started) {
1732 struct spoolss_EndDocPrinter e;
1734 e.in.handle = r->in.handle;
1736 _spoolss_EndDocPrinter(p, &e);
1739 if (!close_printer_handle(p, r->in.handle))
1742 /* clear the returned printer handle. Observed behavior
1743 from Win2k server. Don't think this really matters.
1744 Previous code just copied the value of the closed
1747 ZERO_STRUCTP(r->out.handle);
1752 /****************************************************************
1753 _spoolss_DeletePrinter
1754 ****************************************************************/
1756 WERROR _spoolss_DeletePrinter(pipes_struct *p,
1757 struct spoolss_DeletePrinter *r)
1759 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1762 if (Printer && Printer->document_started) {
1763 struct spoolss_EndDocPrinter e;
1765 e.in.handle = r->in.handle;
1767 _spoolss_EndDocPrinter(p, &e);
1770 result = delete_printer_handle(p, r->in.handle);
1772 update_c_setprinter(false);
1777 /*******************************************************************
1778 * static function to lookup the version id corresponding to an
1779 * long architecture string
1780 ******************************************************************/
1782 static const struct print_architecture_table_node archi_table[]= {
1784 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1785 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1786 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1787 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
1788 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
1789 {"Windows IA64", SPL_ARCH_IA64, 3 },
1790 {"Windows x64", SPL_ARCH_X64, 3 },
1794 static int get_version_id(const char *arch)
1798 for (i=0; archi_table[i].long_archi != NULL; i++)
1800 if (strcmp(arch, archi_table[i].long_archi) == 0)
1801 return (archi_table[i].version);
1807 /****************************************************************
1808 _spoolss_DeletePrinterDriver
1809 ****************************************************************/
1811 WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
1812 struct spoolss_DeletePrinterDriver *r)
1815 struct spoolss_DriverInfo8 *info = NULL;
1816 struct spoolss_DriverInfo8 *info_win2k = NULL;
1819 WERROR status_win2k = WERR_ACCESS_DENIED;
1820 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1822 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1823 and not a printer admin, then fail */
1825 if ( (p->server_info->utok.uid != sec_initial_uid())
1826 && !user_has_privileges(p->server_info->ptok, &se_printop )
1827 && !token_contains_name_in_list(
1828 uidtoname(p->server_info->utok.uid),
1829 p->server_info->info3->base.domain.string,
1831 p->server_info->ptok,
1832 lp_printer_admin(-1)) )
1834 return WERR_ACCESS_DENIED;
1837 /* check that we have a valid driver name first */
1839 if ((version = get_version_id(r->in.architecture)) == -1)
1840 return WERR_INVALID_ENVIRONMENT;
1842 if (!W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx, &info, r->in.driver,
1846 /* try for Win2k driver if "Windows NT x86" */
1848 if ( version == 2 ) {
1850 if (!W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx,
1855 status = WERR_UNKNOWN_PRINTER_DRIVER;
1859 /* otherwise it was a failure */
1861 status = WERR_UNKNOWN_PRINTER_DRIVER;
1867 if (printer_driver_in_use(info)) {
1868 status = WERR_PRINTER_DRIVER_IN_USE;
1874 if (W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx,
1877 r->in.architecture, 3)))
1879 /* if we get to here, we now have 2 driver info structures to remove */
1880 /* remove the Win2k driver first*/
1882 status_win2k = delete_printer_driver(
1883 p, info_win2k, 3, false);
1884 free_a_printer_driver(info_win2k);
1886 /* this should not have failed---if it did, report to client */
1887 if ( !W_ERROR_IS_OK(status_win2k) )
1889 status = status_win2k;
1895 status = delete_printer_driver(p, info, version, false);
1897 /* if at least one of the deletes succeeded return OK */
1899 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
1903 free_a_printer_driver(info);
1908 /****************************************************************
1909 _spoolss_DeletePrinterDriverEx
1910 ****************************************************************/
1912 WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
1913 struct spoolss_DeletePrinterDriverEx *r)
1915 struct spoolss_DriverInfo8 *info = NULL;
1916 struct spoolss_DriverInfo8 *info_win2k = NULL;
1920 WERROR status_win2k = WERR_ACCESS_DENIED;
1921 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1923 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1924 and not a printer admin, then fail */
1926 if ( (p->server_info->utok.uid != sec_initial_uid())
1927 && !user_has_privileges(p->server_info->ptok, &se_printop )
1928 && !token_contains_name_in_list(
1929 uidtoname(p->server_info->utok.uid),
1930 p->server_info->info3->base.domain.string,
1932 p->server_info->ptok, lp_printer_admin(-1)) )
1934 return WERR_ACCESS_DENIED;
1937 /* check that we have a valid driver name first */
1938 if ((version = get_version_id(r->in.architecture)) == -1) {
1939 /* this is what NT returns */
1940 return WERR_INVALID_ENVIRONMENT;
1943 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
1944 version = r->in.version;
1946 status = get_a_printer_driver(p->mem_ctx, &info, r->in.driver,
1947 r->in.architecture, version);
1949 if ( !W_ERROR_IS_OK(status) )
1952 * if the client asked for a specific version,
1953 * or this is something other than Windows NT x86,
1957 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
1960 /* try for Win2k driver if "Windows NT x86" */
1963 if (!W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx, &info, r->in.driver,
1966 status = WERR_UNKNOWN_PRINTER_DRIVER;
1971 if (printer_driver_in_use(info)) {
1972 status = WERR_PRINTER_DRIVER_IN_USE;
1977 * we have a couple of cases to consider.
1978 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
1979 * then the delete should fail if **any** files overlap with
1981 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
1982 * non-overlapping files
1983 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
1984 * is set, the do not delete any files
1985 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
1988 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
1990 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
1992 if (delete_files && printer_driver_files_in_use(info, info) & (r->in.delete_flags & DPD_DELETE_ALL_FILES)) {
1993 /* no idea of the correct error here */
1994 status = WERR_ACCESS_DENIED;
1999 /* also check for W32X86/3 if necessary; maybe we already have? */
2001 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2002 if (W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx, &info_win2k,
2004 r->in.architecture, 3)))
2007 if (delete_files && printer_driver_files_in_use(info, info_win2k) & (r->in.delete_flags & DPD_DELETE_ALL_FILES) ) {
2008 /* no idea of the correct error here */
2009 free_a_printer_driver(info_win2k);
2010 status = WERR_ACCESS_DENIED;
2014 /* if we get to here, we now have 2 driver info structures to remove */
2015 /* remove the Win2k driver first*/
2017 status_win2k = delete_printer_driver(
2018 p, info_win2k, 3, delete_files);
2019 free_a_printer_driver(info_win2k);
2021 /* this should not have failed---if it did, report to client */
2023 if ( !W_ERROR_IS_OK(status_win2k) )
2028 status = delete_printer_driver(p, info, version, delete_files);
2030 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2033 free_a_printer_driver(info);
2039 /****************************************************************************
2040 Internal routine for removing printerdata
2041 ***************************************************************************/
2043 static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value )
2045 return delete_printer_data( printer->info_2, key, value );
2048 /****************************************************************************
2049 Internal routine for storing printerdata
2050 ***************************************************************************/
2052 WERROR set_printer_dataex(NT_PRINTER_INFO_LEVEL *printer,
2053 const char *key, const char *value,
2054 uint32_t type, uint8_t *data, int real_len)
2056 /* the registry objects enforce uniqueness based on value name */
2058 return add_printer_data( printer->info_2, key, value, type, data, real_len );
2061 /********************************************************************
2062 GetPrinterData on a printer server Handle.
2063 ********************************************************************/
2065 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2067 enum winreg_Type *type,
2068 union spoolss_PrinterData *data)
2070 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2072 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2078 if (!StrCaseCmp(value, "BeepEnabled")) {
2084 if (!StrCaseCmp(value, "EventLog")) {
2086 /* formally was 0x1b */
2091 if (!StrCaseCmp(value, "NetPopup")) {
2097 if (!StrCaseCmp(value, "MajorVersion")) {
2100 /* Windows NT 4.0 seems to not allow uploading of drivers
2101 to a server that reports 0x3 as the MajorVersion.
2102 need to investigate more how Win2k gets around this .
2105 if (RA_WINNT == get_remote_arch()) {
2114 if (!StrCaseCmp(value, "MinorVersion")) {
2121 * uint32_t size = 0x114
2122 * uint32_t major = 5
2123 * uint32_t minor = [0|1]
2124 * uint32_t build = [2195|2600]
2125 * extra unicode string = e.g. "Service Pack 3"
2127 if (!StrCaseCmp(value, "OSVersion")) {
2129 enum ndr_err_code ndr_err;
2130 struct spoolss_OSVersion os;
2132 os.major = 5; /* Windows 2000 == 5.0 */
2134 os.build = 2195; /* build */
2135 os.extra_string = ""; /* leave extra string empty */
2137 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2138 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2139 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2140 return WERR_GENERAL_FAILURE;
2144 data->binary = blob;
2150 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2153 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2154 W_ERROR_HAVE_NO_MEMORY(data->string);
2159 if (!StrCaseCmp(value, "Architecture")) {
2161 data->string = talloc_strdup(mem_ctx,
2162 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2163 W_ERROR_HAVE_NO_MEMORY(data->string);
2168 if (!StrCaseCmp(value, "DsPresent")) {
2171 /* only show the publish check box if we are a
2172 member of a AD domain */
2174 if (lp_security() == SEC_ADS) {
2182 if (!StrCaseCmp(value, "DNSMachineName")) {
2183 const char *hostname = get_mydnsfullname();
2186 return WERR_BADFILE;
2190 data->string = talloc_strdup(mem_ctx, hostname);
2191 W_ERROR_HAVE_NO_MEMORY(data->string);
2198 return WERR_INVALID_PARAM;
2201 /****************************************************************
2202 _spoolss_GetPrinterData
2203 ****************************************************************/
2205 WERROR _spoolss_GetPrinterData(pipes_struct *p,
2206 struct spoolss_GetPrinterData *r)
2208 struct spoolss_GetPrinterDataEx r2;
2210 r2.in.handle = r->in.handle;
2211 r2.in.key_name = "PrinterDriverData";
2212 r2.in.value_name = r->in.value_name;
2213 r2.in.offered = r->in.offered;
2214 r2.out.type = r->out.type;
2215 r2.out.data = r->out.data;
2216 r2.out.needed = r->out.needed;
2218 return _spoolss_GetPrinterDataEx(p, &r2);
2221 /*********************************************************
2222 Connect to the client machine.
2223 **********************************************************/
2225 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2226 struct sockaddr_storage *client_ss, const char *remote_machine)
2229 struct cli_state *the_cli;
2230 struct sockaddr_storage rm_addr;
2231 char addr[INET6_ADDRSTRLEN];
2233 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2234 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2236 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2237 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2240 print_sockaddr(addr, sizeof(addr), &rm_addr);
2242 rm_addr = *client_ss;
2243 print_sockaddr(addr, sizeof(addr), &rm_addr);
2244 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2248 if (ismyaddr((struct sockaddr *)&rm_addr)) {
2249 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2254 /* setup the connection */
2255 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2256 &rm_addr, 0, "IPC$", "IPC",
2260 0, lp_client_signing(), NULL );
2262 if ( !NT_STATUS_IS_OK( ret ) ) {
2263 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2268 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2269 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2270 cli_shutdown(the_cli);
2275 * Ok - we have an anonymous connection to the IPC$ share.
2276 * Now start the NT Domain stuff :-).
2279 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2280 if (!NT_STATUS_IS_OK(ret)) {
2281 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2282 remote_machine, nt_errstr(ret)));
2283 cli_shutdown(the_cli);
2290 /***************************************************************************
2291 Connect to the client.
2292 ****************************************************************************/
2294 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2295 uint32_t localprinter, uint32_t type,
2296 struct policy_handle *handle,
2297 struct sockaddr_storage *client_ss)
2303 * If it's the first connection, contact the client
2304 * and connect to the IPC$ share anonymously
2306 if (smb_connections==0) {
2307 fstring unix_printer;
2309 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2311 if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ss, unix_printer ))
2314 messaging_register(smbd_messaging_context(), NULL,
2315 MSG_PRINTER_NOTIFY2,
2316 receive_notify2_message_list);
2317 /* Tell the connections db we're now interested in printer
2318 * notify messages. */
2319 serverid_register_msg_flags(
2320 messaging_server_id(smbd_messaging_context()),
2321 true, FLAG_MSG_PRINT_NOTIFY);
2325 * Tell the specific printing tdb we want messages for this printer
2326 * by registering our PID.
2329 if (!print_notify_register_pid(snum))
2330 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2334 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2342 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2343 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2344 win_errstr(result)));
2346 return (W_ERROR_IS_OK(result));
2349 /****************************************************************
2350 ****************************************************************/
2352 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2353 const struct spoolss_NotifyOption *r)
2355 struct spoolss_NotifyOption *option;
2362 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2369 if (!option->count) {
2373 option->types = talloc_zero_array(option,
2374 struct spoolss_NotifyOptionType, option->count);
2375 if (!option->types) {
2376 talloc_free(option);
2380 for (i=0; i < option->count; i++) {
2381 option->types[i] = r->types[i];
2383 if (option->types[i].count) {
2384 option->types[i].fields = talloc_zero_array(option,
2385 union spoolss_Field, option->types[i].count);
2386 if (!option->types[i].fields) {
2387 talloc_free(option);
2390 for (k=0; k<option->types[i].count; k++) {
2391 option->types[i].fields[k] =
2392 r->types[i].fields[k];
2400 /****************************************************************
2401 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2403 * before replying OK: status=0 a rpc call is made to the workstation
2404 * asking ReplyOpenPrinter
2406 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2407 * called from api_spoolss_rffpcnex
2408 ****************************************************************/
2410 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
2411 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2414 struct spoolss_NotifyOption *option = r->in.notify_options;
2415 struct sockaddr_storage client_ss;
2417 /* store the notify value in the printer struct */
2419 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2422 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2423 "Invalid handle (%s:%u:%u).\n",
2424 OUR_HANDLE(r->in.handle)));
2428 Printer->notify.flags = r->in.flags;
2429 Printer->notify.options = r->in.options;
2430 Printer->notify.printerlocal = r->in.printer_local;
2432 TALLOC_FREE(Printer->notify.option);
2433 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2435 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2437 /* Connect to the client machine and send a ReplyOpenPrinter */
2439 if ( Printer->printer_type == SPLHND_SERVER)
2441 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2442 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2445 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2446 "client_address is %s\n", p->client_address));
2448 if (!interpret_string_addr(&client_ss, p->client_address,
2450 return WERR_SERVER_UNAVAILABLE;
2453 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2454 Printer->notify.printerlocal, 1,
2455 &Printer->notify.client_hnd, &client_ss))
2456 return WERR_SERVER_UNAVAILABLE;
2458 Printer->notify.client_connected = true;
2463 /*******************************************************************
2464 * fill a notify_info_data with the servername
2465 ********************************************************************/
2467 static void spoolss_notify_server_name(int snum,
2468 struct spoolss_Notify *data,
2469 print_queue_struct *queue,
2470 NT_PRINTER_INFO_LEVEL *printer,
2471 TALLOC_CTX *mem_ctx)
2473 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->servername);
2476 /*******************************************************************
2477 * fill a notify_info_data with the printername (not including the servername).
2478 ********************************************************************/
2480 static void spoolss_notify_printer_name(int snum,
2481 struct spoolss_Notify *data,
2482 print_queue_struct *queue,
2483 NT_PRINTER_INFO_LEVEL *printer,
2484 TALLOC_CTX *mem_ctx)
2486 /* the notify name should not contain the \\server\ part */
2487 char *p = strrchr(printer->info_2->printername, '\\');
2490 p = printer->info_2->printername;
2495 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2498 /*******************************************************************
2499 * fill a notify_info_data with the servicename
2500 ********************************************************************/
2502 static void spoolss_notify_share_name(int snum,
2503 struct spoolss_Notify *data,
2504 print_queue_struct *queue,
2505 NT_PRINTER_INFO_LEVEL *printer,
2506 TALLOC_CTX *mem_ctx)
2508 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2511 /*******************************************************************
2512 * fill a notify_info_data with the port name
2513 ********************************************************************/
2515 static void spoolss_notify_port_name(int snum,
2516 struct spoolss_Notify *data,
2517 print_queue_struct *queue,
2518 NT_PRINTER_INFO_LEVEL *printer,
2519 TALLOC_CTX *mem_ctx)
2521 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->portname);
2524 /*******************************************************************
2525 * fill a notify_info_data with the printername
2526 * but it doesn't exist, have to see what to do
2527 ********************************************************************/
2529 static void spoolss_notify_driver_name(int snum,
2530 struct spoolss_Notify *data,
2531 print_queue_struct *queue,
2532 NT_PRINTER_INFO_LEVEL *printer,
2533 TALLOC_CTX *mem_ctx)
2535 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->drivername);
2538 /*******************************************************************
2539 * fill a notify_info_data with the comment
2540 ********************************************************************/
2542 static void spoolss_notify_comment(int snum,
2543 struct spoolss_Notify *data,
2544 print_queue_struct *queue,
2545 NT_PRINTER_INFO_LEVEL *printer,
2546 TALLOC_CTX *mem_ctx)
2550 if (*printer->info_2->comment == '\0') {
2551 p = lp_comment(snum);
2553 p = printer->info_2->comment;
2556 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->comment);
2559 /*******************************************************************
2560 * fill a notify_info_data with the comment
2561 * location = "Room 1, floor 2, building 3"
2562 ********************************************************************/
2564 static void spoolss_notify_location(int snum,
2565 struct spoolss_Notify *data,
2566 print_queue_struct *queue,
2567 NT_PRINTER_INFO_LEVEL *printer,
2568 TALLOC_CTX *mem_ctx)
2570 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->location);
2573 /*******************************************************************
2574 * fill a notify_info_data with the device mode
2575 * jfm:xxxx don't to it for know but that's a real problem !!!
2576 ********************************************************************/
2578 static void spoolss_notify_devmode(int snum,
2579 struct spoolss_Notify *data,
2580 print_queue_struct *queue,
2581 NT_PRINTER_INFO_LEVEL *printer,
2582 TALLOC_CTX *mem_ctx)
2584 /* for a dummy implementation we have to zero the fields */
2585 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2588 /*******************************************************************
2589 * fill a notify_info_data with the separator file name
2590 ********************************************************************/
2592 static void spoolss_notify_sepfile(int snum,
2593 struct spoolss_Notify *data,
2594 print_queue_struct *queue,
2595 NT_PRINTER_INFO_LEVEL *printer,
2596 TALLOC_CTX *mem_ctx)
2598 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->sepfile);
2601 /*******************************************************************
2602 * fill a notify_info_data with the print processor
2603 * jfm:xxxx return always winprint to indicate we don't do anything to it
2604 ********************************************************************/
2606 static void spoolss_notify_print_processor(int snum,
2607 struct spoolss_Notify *data,
2608 print_queue_struct *queue,
2609 NT_PRINTER_INFO_LEVEL *printer,
2610 TALLOC_CTX *mem_ctx)
2612 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->printprocessor);
2615 /*******************************************************************
2616 * fill a notify_info_data with the print processor options
2617 * jfm:xxxx send an empty string
2618 ********************************************************************/
2620 static void spoolss_notify_parameters(int snum,
2621 struct spoolss_Notify *data,
2622 print_queue_struct *queue,
2623 NT_PRINTER_INFO_LEVEL *printer,
2624 TALLOC_CTX *mem_ctx)
2626 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->parameters);
2629 /*******************************************************************
2630 * fill a notify_info_data with the data type
2631 * jfm:xxxx always send RAW as data type
2632 ********************************************************************/
2634 static void spoolss_notify_datatype(int snum,
2635 struct spoolss_Notify *data,
2636 print_queue_struct *queue,
2637 NT_PRINTER_INFO_LEVEL *printer,
2638 TALLOC_CTX *mem_ctx)
2640 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->datatype);
2643 /*******************************************************************
2644 * fill a notify_info_data with the security descriptor
2645 * jfm:xxxx send an null pointer to say no security desc
2646 * have to implement security before !
2647 ********************************************************************/
2649 static void spoolss_notify_security_desc(int snum,
2650 struct spoolss_Notify *data,
2651 print_queue_struct *queue,
2652 NT_PRINTER_INFO_LEVEL *printer,
2653 TALLOC_CTX *mem_ctx)
2655 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data,
2656 printer->info_2->secdesc_buf->sd_size,
2657 printer->info_2->secdesc_buf->sd);
2660 /*******************************************************************
2661 * fill a notify_info_data with the attributes
2662 * jfm:xxxx a samba printer is always shared
2663 ********************************************************************/
2665 static void spoolss_notify_attributes(int snum,
2666 struct spoolss_Notify *data,
2667 print_queue_struct *queue,
2668 NT_PRINTER_INFO_LEVEL *printer,
2669 TALLOC_CTX *mem_ctx)
2671 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->attributes);
2674 /*******************************************************************
2675 * fill a notify_info_data with the priority
2676 ********************************************************************/
2678 static void spoolss_notify_priority(int snum,
2679 struct spoolss_Notify *data,
2680 print_queue_struct *queue,
2681 NT_PRINTER_INFO_LEVEL *printer,
2682 TALLOC_CTX *mem_ctx)
2684 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->priority);
2687 /*******************************************************************
2688 * fill a notify_info_data with the default priority
2689 ********************************************************************/
2691 static void spoolss_notify_default_priority(int snum,
2692 struct spoolss_Notify *data,
2693 print_queue_struct *queue,
2694 NT_PRINTER_INFO_LEVEL *printer,
2695 TALLOC_CTX *mem_ctx)
2697 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->default_priority);
2700 /*******************************************************************
2701 * fill a notify_info_data with the start time
2702 ********************************************************************/
2704 static void spoolss_notify_start_time(int snum,
2705 struct spoolss_Notify *data,
2706 print_queue_struct *queue,
2707 NT_PRINTER_INFO_LEVEL *printer,
2708 TALLOC_CTX *mem_ctx)
2710 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->starttime);
2713 /*******************************************************************
2714 * fill a notify_info_data with the until time
2715 ********************************************************************/
2717 static void spoolss_notify_until_time(int snum,
2718 struct spoolss_Notify *data,
2719 print_queue_struct *queue,
2720 NT_PRINTER_INFO_LEVEL *printer,
2721 TALLOC_CTX *mem_ctx)
2723 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->untiltime);
2726 /*******************************************************************
2727 * fill a notify_info_data with the status
2728 ********************************************************************/
2730 static void spoolss_notify_status(int snum,
2731 struct spoolss_Notify *data,
2732 print_queue_struct *queue,
2733 NT_PRINTER_INFO_LEVEL *printer,
2734 TALLOC_CTX *mem_ctx)
2736 print_status_struct status;
2738 print_queue_length(snum, &status);
2739 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
2742 /*******************************************************************
2743 * fill a notify_info_data with the number of jobs queued
2744 ********************************************************************/
2746 static void spoolss_notify_cjobs(int snum,
2747 struct spoolss_Notify *data,
2748 print_queue_struct *queue,
2749 NT_PRINTER_INFO_LEVEL *printer,
2750 TALLOC_CTX *mem_ctx)
2752 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
2755 /*******************************************************************
2756 * fill a notify_info_data with the average ppm
2757 ********************************************************************/
2759 static void spoolss_notify_average_ppm(int snum,
2760 struct spoolss_Notify *data,
2761 print_queue_struct *queue,
2762 NT_PRINTER_INFO_LEVEL *printer,
2763 TALLOC_CTX *mem_ctx)
2765 /* always respond 8 pages per minutes */
2766 /* a little hard ! */
2767 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->averageppm);
2770 /*******************************************************************
2771 * fill a notify_info_data with username
2772 ********************************************************************/
2774 static void spoolss_notify_username(int snum,
2775 struct spoolss_Notify *data,
2776 print_queue_struct *queue,
2777 NT_PRINTER_INFO_LEVEL *printer,
2778 TALLOC_CTX *mem_ctx)
2780 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
2783 /*******************************************************************
2784 * fill a notify_info_data with job status
2785 ********************************************************************/
2787 static void spoolss_notify_job_status(int snum,
2788 struct spoolss_Notify *data,
2789 print_queue_struct *queue,
2790 NT_PRINTER_INFO_LEVEL *printer,
2791 TALLOC_CTX *mem_ctx)
2793 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
2796 /*******************************************************************
2797 * fill a notify_info_data with job name
2798 ********************************************************************/
2800 static void spoolss_notify_job_name(int snum,
2801 struct spoolss_Notify *data,
2802 print_queue_struct *queue,
2803 NT_PRINTER_INFO_LEVEL *printer,
2804 TALLOC_CTX *mem_ctx)
2806 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
2809 /*******************************************************************
2810 * fill a notify_info_data with job status
2811 ********************************************************************/
2813 static void spoolss_notify_job_status_string(int snum,
2814 struct spoolss_Notify *data,
2815 print_queue_struct *queue,
2816 NT_PRINTER_INFO_LEVEL *printer,
2817 TALLOC_CTX *mem_ctx)
2820 * Now we're returning job status codes we just return a "" here. JRA.
2825 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
2828 switch (queue->status) {
2833 p = ""; /* NT provides the paused string */
2842 #endif /* NO LONGER NEEDED. */
2844 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2847 /*******************************************************************
2848 * fill a notify_info_data with job time
2849 ********************************************************************/
2851 static void spoolss_notify_job_time(int snum,
2852 struct spoolss_Notify *data,
2853 print_queue_struct *queue,
2854 NT_PRINTER_INFO_LEVEL *printer,
2855 TALLOC_CTX *mem_ctx)
2857 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2860 /*******************************************************************
2861 * fill a notify_info_data with job size
2862 ********************************************************************/
2864 static void spoolss_notify_job_size(int snum,
2865 struct spoolss_Notify *data,
2866 print_queue_struct *queue,
2867 NT_PRINTER_INFO_LEVEL *printer,
2868 TALLOC_CTX *mem_ctx)
2870 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
2873 /*******************************************************************
2874 * fill a notify_info_data with page info
2875 ********************************************************************/
2876 static void spoolss_notify_total_pages(int snum,
2877 struct spoolss_Notify *data,
2878 print_queue_struct *queue,
2879 NT_PRINTER_INFO_LEVEL *printer,
2880 TALLOC_CTX *mem_ctx)
2882 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
2885 /*******************************************************************
2886 * fill a notify_info_data with pages printed info.
2887 ********************************************************************/
2888 static void spoolss_notify_pages_printed(int snum,
2889 struct spoolss_Notify *data,
2890 print_queue_struct *queue,
2891 NT_PRINTER_INFO_LEVEL *printer,
2892 TALLOC_CTX *mem_ctx)
2894 /* Add code when back-end tracks this */
2895 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2898 /*******************************************************************
2899 Fill a notify_info_data with job position.
2900 ********************************************************************/
2902 static void spoolss_notify_job_position(int snum,
2903 struct spoolss_Notify *data,
2904 print_queue_struct *queue,
2905 NT_PRINTER_INFO_LEVEL *printer,
2906 TALLOC_CTX *mem_ctx)
2908 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
2911 /*******************************************************************
2912 Fill a notify_info_data with submitted time.
2913 ********************************************************************/
2915 static void spoolss_notify_submitted_time(int snum,
2916 struct spoolss_Notify *data,
2917 print_queue_struct *queue,
2918 NT_PRINTER_INFO_LEVEL *printer,
2919 TALLOC_CTX *mem_ctx)
2921 data->data.string.string = NULL;
2922 data->data.string.size = 0;
2924 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
2925 &data->data.string.string,
2926 &data->data.string.size);
2930 struct s_notify_info_data_table
2932 enum spoolss_NotifyType type;
2935 enum spoolss_NotifyTable variable_type;
2936 void (*fn) (int snum, struct spoolss_Notify *data,
2937 print_queue_struct *queue,
2938 NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx);
2941 /* A table describing the various print notification constants and
2942 whether the notification data is a pointer to a variable sized
2943 buffer, a one value uint32_t or a two value uint32_t. */
2945 static const struct s_notify_info_data_table notify_info_data_table[] =
2947 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2948 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2949 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
2950 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2951 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2952 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
2953 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
2954 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2955 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
2956 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2957 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2958 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2959 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
2960 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
2961 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2962 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
2963 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2964 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2965 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
2966 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
2967 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
2968 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
2969 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
2970 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2971 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
2972 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2973 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2974 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2975 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2976 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2977 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2978 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2979 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2980 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2981 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2982 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2983 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
2984 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
2985 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
2986 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
2987 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2988 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
2989 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
2990 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2991 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2992 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
2993 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
2994 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
2995 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
2998 /*******************************************************************
2999 Return the variable_type of info_data structure.
3000 ********************************************************************/
3002 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3007 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3008 if ( (notify_info_data_table[i].type == type) &&
3009 (notify_info_data_table[i].field == field) ) {
3010 return notify_info_data_table[i].variable_type;
3014 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3019 /****************************************************************************
3020 ****************************************************************************/
3022 static bool search_notify(enum spoolss_NotifyType type,
3028 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3029 if (notify_info_data_table[i].type == type &&
3030 notify_info_data_table[i].field == field &&
3031 notify_info_data_table[i].fn != NULL) {
3040 /****************************************************************************
3041 ****************************************************************************/
3043 void construct_info_data(struct spoolss_Notify *info_data,
3044 enum spoolss_NotifyType type,
3048 info_data->type = type;
3049 info_data->field.field = field;
3050 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3051 info_data->job_id = id;
3054 /*******************************************************************
3056 * fill a notify_info struct with info asked
3058 ********************************************************************/
3060 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3061 struct spoolss_NotifyInfo *info,
3063 const struct spoolss_NotifyOptionType *option_type,
3065 TALLOC_CTX *mem_ctx)
3068 enum spoolss_NotifyType type;
3071 struct spoolss_Notify *current_data;
3072 NT_PRINTER_INFO_LEVEL *printer = NULL;
3073 print_queue_struct *queue=NULL;
3075 type = option_type->type;
3077 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3078 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3079 option_type->count, lp_servicename(snum)));
3081 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &printer, 2, lp_const_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"));
3097 free_a_printer(&printer, 2);
3101 current_data = &info->notifies[info->count];
3103 construct_info_data(current_data, type, field, id);
3105 DEBUG(10,("construct_notify_printer_info: calling [%s] snum=%d printername=[%s])\n",
3106 notify_info_data_table[j].name, snum, printer->info_2->printername ));
3108 notify_info_data_table[j].fn(snum, current_data, queue,
3114 free_a_printer(&printer, 2);
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 NT_PRINTER_INFO_LEVEL *printer,
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(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;
3212 DEBUG(4,("printserver_notify_info\n"));
3217 option = Printer->notify.option;
3220 info->notifies = NULL;
3223 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3224 sending a ffpcn() request first */
3229 for (i=0; i<option->count; i++) {
3230 option_type = option->types[i];
3232 if (option_type.type != PRINTER_NOTIFY_TYPE)
3235 for (snum=0; snum<n_services; snum++)
3237 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3238 construct_notify_printer_info ( Printer, info, snum, &option_type, snum, mem_ctx );
3244 * Debugging information, don't delete.
3247 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3248 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3249 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3251 for (i=0; i<info->count; i++) {
3252 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3253 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3254 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3261 /*******************************************************************
3263 * fill a notify_info struct with info asked
3265 ********************************************************************/
3267 static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
3268 struct spoolss_NotifyInfo *info,
3269 TALLOC_CTX *mem_ctx)
3272 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3275 struct spoolss_NotifyOption *option;
3276 struct spoolss_NotifyOptionType option_type;
3278 print_queue_struct *queue=NULL;
3279 print_status_struct status;
3281 DEBUG(4,("printer_notify_info\n"));
3286 option = Printer->notify.option;
3290 info->notifies = NULL;
3293 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3294 sending a ffpcn() request first */
3299 get_printer_snum(p, hnd, &snum, NULL);
3301 for (i=0; i<option->count; i++) {
3302 option_type = option->types[i];
3304 switch (option_type.type) {
3305 case PRINTER_NOTIFY_TYPE:
3306 if(construct_notify_printer_info(Printer, info, snum,
3312 case JOB_NOTIFY_TYPE: {
3313 NT_PRINTER_INFO_LEVEL *printer = NULL;
3315 count = print_queue_status(snum, &queue, &status);
3317 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))))
3320 for (j=0; j<count; j++) {
3321 construct_notify_jobs_info(&queue[j], info,
3328 free_a_printer(&printer, 2);
3338 * Debugging information, don't delete.
3341 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3342 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3343 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3345 for (i=0; i<info->count; i++) {
3346 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3347 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3348 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3354 /****************************************************************
3355 _spoolss_RouterRefreshPrinterChangeNotify
3356 ****************************************************************/
3358 WERROR _spoolss_RouterRefreshPrinterChangeNotify(pipes_struct *p,
3359 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3361 struct spoolss_NotifyInfo *info;
3363 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
3364 WERROR result = WERR_BADFID;
3366 /* we always have a spoolss_NotifyInfo struct */
3367 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3369 result = WERR_NOMEM;
3373 *r->out.info = info;
3376 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3377 "Invalid handle (%s:%u:%u).\n",
3378 OUR_HANDLE(r->in.handle)));
3382 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3385 * We are now using the change value, and
3386 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3387 * I don't have a global notification system, I'm sending back all the
3388 * informations even when _NOTHING_ has changed.
3391 /* We need to keep track of the change value to send back in
3392 RRPCN replies otherwise our updates are ignored. */
3394 Printer->notify.fnpcn = true;
3396 if (Printer->notify.client_connected) {
3397 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3398 "Saving change value in request [%x]\n",
3400 Printer->notify.change = r->in.change_low;
3403 /* just ignore the spoolss_NotifyOption */
3405 switch (Printer->printer_type) {
3407 result = printserver_notify_info(p, r->in.handle,
3411 case SPLHND_PRINTER:
3412 result = printer_notify_info(p, r->in.handle,
3417 Printer->notify.fnpcn = false;
3423 /********************************************************************
3424 * construct_printer_info_0
3425 * fill a printer_info_0 struct
3426 ********************************************************************/
3428 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3429 const NT_PRINTER_INFO_LEVEL *ntprinter,
3430 struct spoolss_PrinterInfo0 *r,
3434 counter_printer_0 *session_counter;
3436 print_status_struct status;
3438 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3439 W_ERROR_HAVE_NO_MEMORY(r->printername);
3441 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3442 W_ERROR_HAVE_NO_MEMORY(r->servername);
3444 count = print_queue_length(snum, &status);
3446 /* check if we already have a counter for this printer */
3447 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3448 if (session_counter->snum == snum)
3452 /* it's the first time, add it to the list */
3453 if (session_counter == NULL) {
3454 session_counter = SMB_MALLOC_P(counter_printer_0);
3455 W_ERROR_HAVE_NO_MEMORY(session_counter);
3456 ZERO_STRUCTP(session_counter);
3457 session_counter->snum = snum;
3458 session_counter->counter = 0;
3459 DLIST_ADD(counter_list, session_counter);
3463 session_counter->counter++;
3469 setuptime = (time_t)ntprinter->info_2->setuptime;
3471 init_systemtime(&r->time, gmtime(&setuptime));
3474 * the global_counter should be stored in a TDB as it's common to all the clients
3475 * and should be zeroed on samba startup
3477 r->global_counter = session_counter->counter;
3479 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3480 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3481 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3482 r->free_build = SPOOLSS_RELEASE_BUILD;
3484 r->max_spooling = 0;
3485 r->session_counter = session_counter->counter;
3486 r->num_error_out_of_paper = 0x0;
3487 r->num_error_not_ready = 0x0; /* number of print failure */
3489 r->number_of_processors = 0x1;
3490 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3491 r->high_part_total_bytes = 0x0;
3492 r->change_id = ntprinter->info_2->changeid; /* ChangeID in milliseconds*/
3493 r->last_error = WERR_OK;
3494 r->status = nt_printq_status(status.status);
3495 r->enumerate_network_printers = 0x0;
3496 r->c_setprinter = get_c_setprinter(); /* monotonically increasing sum of delta printer counts */
3497 r->processor_architecture = 0x0;
3498 r->processor_level = 0x6; /* 6 ???*/
3507 /****************************************************************************
3508 Create a spoolss_DeviceMode struct. Returns talloced memory.
3509 ****************************************************************************/
3511 struct spoolss_DeviceMode *construct_dev_mode(TALLOC_CTX *mem_ctx,
3512 const char *servicename)
3514 NT_PRINTER_INFO_LEVEL *printer = NULL;
3515 struct spoolss_DeviceMode *devmode = NULL;
3517 DEBUG(7,("construct_dev_mode\n"));
3519 DEBUGADD(8,("getting printer characteristics\n"));
3521 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename)))
3524 if (!printer->info_2->devmode) {
3525 DEBUG(5, ("BONG! There was no device mode!\n"));
3529 devmode = talloc_steal(mem_ctx, printer->info_2->devmode);
3532 free_a_printer(&printer,2);
3537 /********************************************************************
3538 * construct_printer_info1
3539 * fill a spoolss_PrinterInfo1 struct
3540 ********************************************************************/
3542 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3543 const NT_PRINTER_INFO_LEVEL *ntprinter,
3545 struct spoolss_PrinterInfo1 *r,
3550 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3551 ntprinter->info_2->printername,
3552 ntprinter->info_2->drivername,
3553 ntprinter->info_2->location);
3554 W_ERROR_HAVE_NO_MEMORY(r->description);
3556 if (*ntprinter->info_2->comment == '\0') {
3557 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3559 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment); /* saved comment */
3561 W_ERROR_HAVE_NO_MEMORY(r->comment);
3563 r->name = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3564 W_ERROR_HAVE_NO_MEMORY(r->name);
3569 /********************************************************************
3570 * construct_printer_info2
3571 * fill a spoolss_PrinterInfo2 struct
3572 ********************************************************************/
3574 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3575 const NT_PRINTER_INFO_LEVEL *ntprinter,
3576 struct spoolss_PrinterInfo2 *r,
3581 print_status_struct status;
3583 count = print_queue_length(snum, &status);
3585 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3586 W_ERROR_HAVE_NO_MEMORY(r->servername);
3587 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3588 W_ERROR_HAVE_NO_MEMORY(r->printername);
3589 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3590 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3591 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
3592 W_ERROR_HAVE_NO_MEMORY(r->portname);
3593 r->drivername = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
3594 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3596 if (*ntprinter->info_2->comment == '\0') {
3597 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3599 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment);
3601 W_ERROR_HAVE_NO_MEMORY(r->comment);
3603 r->location = talloc_strdup(mem_ctx, ntprinter->info_2->location);
3604 W_ERROR_HAVE_NO_MEMORY(r->location);
3605 r->sepfile = talloc_strdup(mem_ctx, ntprinter->info_2->sepfile);
3606 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3607 r->printprocessor = talloc_strdup(mem_ctx, ntprinter->info_2->printprocessor);
3608 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3609 r->datatype = talloc_strdup(mem_ctx, ntprinter->info_2->datatype);
3610 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3611 r->parameters = talloc_strdup(mem_ctx, ntprinter->info_2->parameters);
3612 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3614 r->attributes = ntprinter->info_2->attributes;
3616 r->priority = ntprinter->info_2->priority;
3617 r->defaultpriority = ntprinter->info_2->default_priority;
3618 r->starttime = ntprinter->info_2->starttime;
3619 r->untiltime = ntprinter->info_2->untiltime;
3620 r->status = nt_printq_status(status.status);
3622 r->averageppm = ntprinter->info_2->averageppm;
3624 r->devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
3626 DEBUG(8,("Returning NULL Devicemode!\n"));
3631 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
3632 /* don't use talloc_steal() here unless you do a deep steal of all
3633 the SEC_DESC members */
3635 r->secdesc = dup_sec_desc(mem_ctx, ntprinter->info_2->secdesc_buf->sd);
3641 /********************************************************************
3642 * construct_printer_info3
3643 * fill a spoolss_PrinterInfo3 struct
3644 ********************************************************************/
3646 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3647 const NT_PRINTER_INFO_LEVEL *ntprinter,
3648 struct spoolss_PrinterInfo3 *r,
3651 /* These are the components of the SD we are returning. */
3653 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
3654 /* don't use talloc_steal() here unless you do a deep steal of all
3655 the SEC_DESC members */
3657 r->secdesc = dup_sec_desc(mem_ctx,
3658 ntprinter->info_2->secdesc_buf->sd);
3659 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3665 /********************************************************************
3666 * construct_printer_info4
3667 * fill a spoolss_PrinterInfo4 struct
3668 ********************************************************************/
3670 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
3671 const NT_PRINTER_INFO_LEVEL *ntprinter,
3672 struct spoolss_PrinterInfo4 *r,
3675 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3676 W_ERROR_HAVE_NO_MEMORY(r->printername);
3677 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3678 W_ERROR_HAVE_NO_MEMORY(r->servername);
3680 r->attributes = ntprinter->info_2->attributes;
3685 /********************************************************************
3686 * construct_printer_info5
3687 * fill a spoolss_PrinterInfo5 struct
3688 ********************************************************************/
3690 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
3691 const NT_PRINTER_INFO_LEVEL *ntprinter,
3692 struct spoolss_PrinterInfo5 *r,
3695 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3696 W_ERROR_HAVE_NO_MEMORY(r->printername);
3697 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
3698 W_ERROR_HAVE_NO_MEMORY(r->portname);
3700 r->attributes = ntprinter->info_2->attributes;
3702 /* these two are not used by NT+ according to MSDN */
3704 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
3705 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
3710 /********************************************************************
3711 * construct_printer_info_6
3712 * fill a spoolss_PrinterInfo6 struct
3713 ********************************************************************/
3715 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
3716 const NT_PRINTER_INFO_LEVEL *ntprinter,
3717 struct spoolss_PrinterInfo6 *r,
3721 print_status_struct status;
3723 count = print_queue_length(snum, &status);
3725 r->status = nt_printq_status(status.status);
3730 /********************************************************************
3731 * construct_printer_info7
3732 * fill a spoolss_PrinterInfo7 struct
3733 ********************************************************************/
3735 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
3736 Printer_entry *print_hnd,
3737 struct spoolss_PrinterInfo7 *r,
3742 if (is_printer_published(print_hnd, snum, &guid)) {
3743 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
3744 r->action = DSPRINT_PUBLISH;
3746 r->guid = talloc_strdup(mem_ctx, "");
3747 r->action = DSPRINT_UNPUBLISH;
3749 W_ERROR_HAVE_NO_MEMORY(r->guid);
3754 /********************************************************************
3755 * construct_printer_info8
3756 * fill a spoolss_PrinterInfo8 struct
3757 ********************************************************************/
3759 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
3760 const NT_PRINTER_INFO_LEVEL *ntprinter,
3761 struct spoolss_DeviceModeInfo *r,
3764 r->devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
3766 DEBUG(8,("Returning NULL Devicemode!\n"));
3773 /********************************************************************
3774 ********************************************************************/
3776 static bool snum_is_shared_printer(int snum)
3778 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
3781 /********************************************************************
3782 Spoolss_enumprinters.
3783 ********************************************************************/
3785 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
3788 union spoolss_PrinterInfo **info_p,
3792 int n_services = lp_numservices();
3793 union spoolss_PrinterInfo *info = NULL;
3795 WERROR result = WERR_OK;
3800 for (snum = 0; snum < n_services; snum++) {
3802 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
3804 if (!snum_is_shared_printer(snum)) {
3808 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
3809 lp_servicename(snum), snum));
3811 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
3812 union spoolss_PrinterInfo,
3815 result = WERR_NOMEM;
3819 result = get_a_printer(NULL, &ntprinter, 2,
3820 lp_const_servicename(snum));
3821 if (!W_ERROR_IS_OK(result)) {
3827 result = construct_printer_info0(info, ntprinter,
3828 &info[count].info0, snum);
3831 result = construct_printer_info1(info, ntprinter, flags,
3832 &info[count].info1, snum);
3835 result = construct_printer_info2(info, ntprinter,
3836 &info[count].info2, snum);
3839 result = construct_printer_info4(info, ntprinter,
3840 &info[count].info4, snum);
3843 result = construct_printer_info5(info, ntprinter,
3844 &info[count].info5, snum);
3848 result = WERR_UNKNOWN_LEVEL;
3849 free_a_printer(&ntprinter, 2);
3853 free_a_printer(&ntprinter, 2);
3854 if (!W_ERROR_IS_OK(result)) {
3865 if (!W_ERROR_IS_OK(result)) {
3875 /********************************************************************
3876 * handle enumeration of printers at level 0
3877 ********************************************************************/
3879 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
3881 const char *servername,
3882 union spoolss_PrinterInfo **info,
3885 DEBUG(4,("enum_all_printers_info_0\n"));
3887 return enum_all_printers_info_level(mem_ctx, 0, flags, info, count);
3891 /********************************************************************
3892 ********************************************************************/
3894 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
3896 union spoolss_PrinterInfo **info,
3899 DEBUG(4,("enum_all_printers_info_1\n"));
3901 return enum_all_printers_info_level(mem_ctx, 1, flags, info, count);
3904 /********************************************************************
3905 enum_all_printers_info_1_local.
3906 *********************************************************************/
3908 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
3909 union spoolss_PrinterInfo **info,
3912 DEBUG(4,("enum_all_printers_info_1_local\n"));
3914 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
3917 /********************************************************************
3918 enum_all_printers_info_1_name.
3919 *********************************************************************/
3921 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
3923 union spoolss_PrinterInfo **info,
3926 const char *s = name;
3928 DEBUG(4,("enum_all_printers_info_1_name\n"));
3930 if ((name[0] == '\\') && (name[1] == '\\')) {
3934 if (!is_myname_or_ipaddr(s)) {
3935 return WERR_INVALID_NAME;
3938 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
3941 /********************************************************************
3942 enum_all_printers_info_1_network.
3943 *********************************************************************/
3945 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
3947 union spoolss_PrinterInfo **info,
3950 const char *s = name;
3952 DEBUG(4,("enum_all_printers_info_1_network\n"));
3954 /* If we respond to a enum_printers level 1 on our name with flags
3955 set to PRINTER_ENUM_REMOTE with a list of printers then these
3956 printers incorrectly appear in the APW browse list.
3957 Specifically the printers for the server appear at the workgroup
3958 level where all the other servers in the domain are
3959 listed. Windows responds to this call with a
3960 WERR_CAN_NOT_COMPLETE so we should do the same. */
3962 if (name[0] == '\\' && name[1] == '\\') {
3966 if (is_myname_or_ipaddr(s)) {
3967 return WERR_CAN_NOT_COMPLETE;
3970 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_NAME, info, count);
3973 /********************************************************************
3974 * api_spoolss_enumprinters
3976 * called from api_spoolss_enumprinters (see this to understand)
3977 ********************************************************************/
3979 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
3980 union spoolss_PrinterInfo **info,
3983 DEBUG(4,("enum_all_printers_info_2\n"));
3985 return enum_all_printers_info_level(mem_ctx, 2, 0, info, count);
3988 /********************************************************************
3989 * handle enumeration of printers at level 1
3990 ********************************************************************/
3992 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
3995 union spoolss_PrinterInfo **info,
3998 /* Not all the flags are equals */
4000 if (flags & PRINTER_ENUM_LOCAL) {
4001 return enum_all_printers_info_1_local(mem_ctx, info, count);
4004 if (flags & PRINTER_ENUM_NAME) {
4005 return enum_all_printers_info_1_name(mem_ctx, name, info, count);
4008 if (flags & PRINTER_ENUM_NETWORK) {
4009 return enum_all_printers_info_1_network(mem_ctx, name, info, count);
4012 return WERR_OK; /* NT4sp5 does that */
4015 /********************************************************************
4016 * handle enumeration of printers at level 2
4017 ********************************************************************/
4019 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4021 const char *servername,
4022 union spoolss_PrinterInfo **info,
4025 if (flags & PRINTER_ENUM_LOCAL) {
4026 return enum_all_printers_info_2(mem_ctx, info, count);
4029 if (flags & PRINTER_ENUM_NAME) {
4030 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4031 return WERR_INVALID_NAME;
4034 return enum_all_printers_info_2(mem_ctx, info, count);
4037 if (flags & PRINTER_ENUM_REMOTE) {
4038 return WERR_UNKNOWN_LEVEL;
4044 /********************************************************************
4045 * handle enumeration of printers at level 4
4046 ********************************************************************/
4048 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4050 const char *servername,
4051 union spoolss_PrinterInfo **info,
4054 DEBUG(4,("enum_all_printers_info_4\n"));
4056 return enum_all_printers_info_level(mem_ctx, 4, flags, info, count);
4060 /********************************************************************
4061 * handle enumeration of printers at level 5
4062 ********************************************************************/
4064 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4066 const char *servername,
4067 union spoolss_PrinterInfo **info,
4070 DEBUG(4,("enum_all_printers_info_5\n"));
4072 return enum_all_printers_info_level(mem_ctx, 5, flags, info, count);
4075 /****************************************************************
4076 _spoolss_EnumPrinters
4077 ****************************************************************/
4079 WERROR _spoolss_EnumPrinters(pipes_struct *p,
4080 struct spoolss_EnumPrinters *r)
4082 const char *name = NULL;
4085 /* that's an [in out] buffer */
4087 if (!r->in.buffer && (r->in.offered != 0)) {
4088 return WERR_INVALID_PARAM;
4091 DEBUG(4,("_spoolss_EnumPrinters\n"));
4095 *r->out.info = NULL;
4099 * flags==PRINTER_ENUM_NAME
4100 * if name=="" then enumerates all printers
4101 * if name!="" then enumerate the printer
4102 * flags==PRINTER_ENUM_REMOTE
4103 * name is NULL, enumerate printers
4104 * Level 2: name!="" enumerates printers, name can't be NULL
4105 * Level 3: doesn't exist
4106 * Level 4: does a local registry lookup
4107 * Level 5: same as Level 2
4111 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4112 W_ERROR_HAVE_NO_MEMORY(name);
4115 switch (r->in.level) {
4117 result = enumprinters_level0(p->mem_ctx, r->in.flags, name,
4118 r->out.info, r->out.count);
4121 result = enumprinters_level1(p->mem_ctx, r->in.flags, name,
4122 r->out.info, r->out.count);
4125 result = enumprinters_level2(p->mem_ctx, r->in.flags, name,
4126 r->out.info, r->out.count);
4129 result = enumprinters_level4(p->mem_ctx, r->in.flags, name,
4130 r->out.info, r->out.count);
4133 result = enumprinters_level5(p->mem_ctx, r->in.flags, name,
4134 r->out.info, r->out.count);
4137 return WERR_UNKNOWN_LEVEL;
4140 if (!W_ERROR_IS_OK(result)) {
4144 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4145 spoolss_EnumPrinters,
4146 *r->out.info, r->in.level,
4148 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4149 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4151 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4154 /****************************************************************
4156 ****************************************************************/
4158 WERROR _spoolss_GetPrinter(pipes_struct *p,
4159 struct spoolss_GetPrinter *r)
4161 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4162 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4163 WERROR result = WERR_OK;
4167 /* that's an [in out] buffer */
4169 if (!r->in.buffer && (r->in.offered != 0)) {
4170 return WERR_INVALID_PARAM;
4175 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4179 result = get_a_printer(Printer, &ntprinter, 2,
4180 lp_const_servicename(snum));
4181 if (!W_ERROR_IS_OK(result)) {
4185 switch (r->in.level) {
4187 result = construct_printer_info0(p->mem_ctx, ntprinter,
4188 &r->out.info->info0, snum);
4191 result = construct_printer_info1(p->mem_ctx, ntprinter,
4193 &r->out.info->info1, snum);
4196 result = construct_printer_info2(p->mem_ctx, ntprinter,
4197 &r->out.info->info2, snum);
4200 result = construct_printer_info3(p->mem_ctx, ntprinter,
4201 &r->out.info->info3, snum);
4204 result = construct_printer_info4(p->mem_ctx, ntprinter,
4205 &r->out.info->info4, snum);
4208 result = construct_printer_info5(p->mem_ctx, ntprinter,
4209 &r->out.info->info5, snum);
4212 result = construct_printer_info6(p->mem_ctx, ntprinter,
4213 &r->out.info->info6, snum);
4216 result = construct_printer_info7(p->mem_ctx, Printer,
4217 &r->out.info->info7, snum);
4220 result = construct_printer_info8(p->mem_ctx, ntprinter,
4221 &r->out.info->info8, snum);
4224 result = WERR_UNKNOWN_LEVEL;
4228 free_a_printer(&ntprinter, 2);
4230 if (!W_ERROR_IS_OK(result)) {
4231 TALLOC_FREE(r->out.info);
4235 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4236 r->out.info, r->in.level);
4237 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4239 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4242 /********************************************************************
4243 ********************************************************************/
4245 static const char **string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4246 const char **string_array,
4247 const char *cservername)
4249 int i, num_strings = 0;
4250 const char **array = NULL;
4252 if (!string_array) {
4256 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4258 const char *str = talloc_asprintf(mem_ctx, "\\\\%s%s",
4259 cservername, string_array[i]);
4266 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4273 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4274 &array, &num_strings);
4280 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4282 if (in && strlen(in)) { \
4283 out = talloc_strdup(mem_ctx, in); \
4284 W_ERROR_HAVE_NO_MEMORY(out); \
4290 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, in, out) \
4292 if (in && strlen(in)) { \
4293 out = talloc_asprintf(mem_ctx, "\\\\%s%s", server, in); \
4295 out = talloc_strdup(mem_ctx, ""); \
4297 W_ERROR_HAVE_NO_MEMORY(out); \
4300 /********************************************************************
4301 * fill a spoolss_DriverInfo1 struct
4302 ********************************************************************/
4304 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4305 struct spoolss_DriverInfo1 *r,
4306 const struct spoolss_DriverInfo8 *driver,
4307 const char *servername)
4309 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4310 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4315 /********************************************************************
4316 * fill a spoolss_DriverInfo2 struct
4317 ********************************************************************/
4319 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4320 struct spoolss_DriverInfo2 *r,
4321 const struct spoolss_DriverInfo8 *driver,
4322 const char *servername)
4325 const char *cservername = canon_servername(servername);
4327 r->version = driver->version;
4329 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4330 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4331 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4332 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4334 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4335 driver->driver_path,
4338 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4342 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4343 driver->config_file,
4349 /********************************************************************
4350 * fill a spoolss_DriverInfo3 struct
4351 ********************************************************************/
4353 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4354 struct spoolss_DriverInfo3 *r,
4355 const struct spoolss_DriverInfo8 *driver,
4356 const char *servername)
4358 const char *cservername = canon_servername(servername);
4360 r->version = driver->version;
4362 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4363 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4364 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4365 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4367 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4368 driver->driver_path,
4371 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4375 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4376 driver->config_file,
4379 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4383 FILL_DRIVER_STRING(mem_ctx,
4384 driver->monitor_name,
4387 FILL_DRIVER_STRING(mem_ctx,
4388 driver->default_datatype,
4389 r->default_datatype);
4391 r->dependent_files = string_array_from_driver_info(mem_ctx,
4392 driver->dependent_files,
4397 /********************************************************************
4398 * fill a spoolss_DriverInfo4 struct
4399 ********************************************************************/
4401 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4402 struct spoolss_DriverInfo4 *r,
4403 const struct spoolss_DriverInfo8 *driver,
4404 const char *servername)
4406 const char *cservername = canon_servername(servername);
4408 r->version = driver->version;
4410 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4411 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4412 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4413 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4415 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4416 driver->driver_path,
4419 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4423 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4424 driver->config_file,
4427 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4431 r->dependent_files = string_array_from_driver_info(mem_ctx,
4432 driver->dependent_files,
4435 FILL_DRIVER_STRING(mem_ctx,
4436 driver->monitor_name,
4439 FILL_DRIVER_STRING(mem_ctx,
4440 driver->default_datatype,
4441 r->default_datatype);
4443 r->previous_names = string_array_from_driver_info(mem_ctx,
4444 driver->previous_names,
4450 /********************************************************************
4451 * fill a spoolss_DriverInfo5 struct
4452 ********************************************************************/
4454 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4455 struct spoolss_DriverInfo5 *r,
4456 const struct spoolss_DriverInfo8 *driver,
4457 const char *servername)
4459 const char *cservername = canon_servername(servername);
4461 r->version = driver->version;
4463 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4464 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4465 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4466 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4468 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4469 driver->driver_path,
4472 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4476 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4477 driver->config_file,
4480 r->driver_attributes = 0;
4481 r->config_version = 0;
4482 r->driver_version = 0;
4486 /********************************************************************
4487 * fill a spoolss_DriverInfo6 struct
4488 ********************************************************************/
4490 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4491 struct spoolss_DriverInfo6 *r,
4492 const struct spoolss_DriverInfo8 *driver,
4493 const char *servername)
4495 const char *cservername = canon_servername(servername);
4497 r->version = driver->version;
4499 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4500 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4501 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4502 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4504 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4505 driver->driver_path,
4508 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4512 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4513 driver->config_file,
4516 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4520 FILL_DRIVER_STRING(mem_ctx,
4521 driver->monitor_name,
4524 FILL_DRIVER_STRING(mem_ctx,
4525 driver->default_datatype,
4526 r->default_datatype);
4528 r->dependent_files = string_array_from_driver_info(mem_ctx,
4529 driver->dependent_files,
4531 r->previous_names = string_array_from_driver_info(mem_ctx,
4532 driver->previous_names,
4535 r->driver_date = driver->driver_date;
4536 r->driver_version = driver->driver_version;
4538 FILL_DRIVER_STRING(mem_ctx,
4539 driver->manufacturer_name,
4540 r->manufacturer_name);
4541 FILL_DRIVER_STRING(mem_ctx,
4542 driver->manufacturer_url,
4543 r->manufacturer_url);
4544 FILL_DRIVER_STRING(mem_ctx,
4545 driver->hardware_id,
4547 FILL_DRIVER_STRING(mem_ctx,
4554 /********************************************************************
4555 * fill a spoolss_DriverInfo8 struct
4556 ********************************************************************/
4558 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
4559 struct spoolss_DriverInfo8 *r,
4560 const struct spoolss_DriverInfo8 *driver,
4561 const char *servername)
4563 const char *cservername = canon_servername(servername);
4565 r->version = driver->version;
4567 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4568 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4569 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4570 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4572 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4573 driver->driver_path,
4576 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4580 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4581 driver->config_file,
4584 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4588 FILL_DRIVER_STRING(mem_ctx,
4589 driver->monitor_name,
4592 FILL_DRIVER_STRING(mem_ctx,
4593 driver->default_datatype,
4594 r->default_datatype);
4596 r->dependent_files = string_array_from_driver_info(mem_ctx,
4597 driver->dependent_files,
4599 r->previous_names = string_array_from_driver_info(mem_ctx,
4600 driver->previous_names,
4603 r->driver_date = driver->driver_date;
4604 r->driver_version = driver->driver_version;
4606 FILL_DRIVER_STRING(mem_ctx,
4607 driver->manufacturer_name,
4608 r->manufacturer_name);
4609 FILL_DRIVER_STRING(mem_ctx,
4610 driver->manufacturer_url,
4611 r->manufacturer_url);
4612 FILL_DRIVER_STRING(mem_ctx,
4613 driver->hardware_id,
4615 FILL_DRIVER_STRING(mem_ctx,
4619 FILL_DRIVER_STRING(mem_ctx,
4620 driver->print_processor,
4621 r->print_processor);
4622 FILL_DRIVER_STRING(mem_ctx,
4623 driver->vendor_setup,
4626 r->color_profiles = string_array_from_driver_info(mem_ctx,
4627 driver->color_profiles,
4630 FILL_DRIVER_STRING(mem_ctx,
4634 r->printer_driver_attributes = driver->printer_driver_attributes;
4636 r->core_driver_dependencies = string_array_from_driver_info(mem_ctx,
4637 driver->core_driver_dependencies,
4640 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
4641 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
4646 #if 0 /* disabled until marshalling issues are resolved - gd */
4647 /********************************************************************
4648 ********************************************************************/
4650 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
4651 struct spoolss_DriverFileInfo *r,
4652 const char *cservername,
4653 const char *file_name,
4654 enum spoolss_DriverFileType file_type,
4655 uint32_t file_version)
4657 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
4658 cservername, file_name);
4659 W_ERROR_HAVE_NO_MEMORY(r->file_name);
4660 r->file_type = file_type;
4661 r->file_version = file_version;
4666 /********************************************************************
4667 ********************************************************************/
4669 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
4670 const struct spoolss_DriverInfo8 *driver,
4671 const char *cservername,
4672 struct spoolss_DriverFileInfo **info_p,
4675 struct spoolss_DriverFileInfo *info = NULL;
4683 if (strlen(driver->driver_path)) {
4684 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4685 struct spoolss_DriverFileInfo,
4687 W_ERROR_HAVE_NO_MEMORY(info);
4688 result = fill_spoolss_DriverFileInfo(info,
4691 driver->driver_path,
4692 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
4694 W_ERROR_NOT_OK_RETURN(result);
4698 if (strlen(driver->config_file)) {
4699 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4700 struct spoolss_DriverFileInfo,
4702 W_ERROR_HAVE_NO_MEMORY(info);
4703 result = fill_spoolss_DriverFileInfo(info,
4706 driver->config_file,
4707 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
4709 W_ERROR_NOT_OK_RETURN(result);
4713 if (strlen(driver->data_file)) {
4714 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4715 struct spoolss_DriverFileInfo,
4717 W_ERROR_HAVE_NO_MEMORY(info);
4718 result = fill_spoolss_DriverFileInfo(info,
4722 SPOOLSS_DRIVER_FILE_TYPE_DATA,
4724 W_ERROR_NOT_OK_RETURN(result);
4728 if (strlen(driver->help_file)) {
4729 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4730 struct spoolss_DriverFileInfo,
4732 W_ERROR_HAVE_NO_MEMORY(info);
4733 result = fill_spoolss_DriverFileInfo(info,
4737 SPOOLSS_DRIVER_FILE_TYPE_HELP,
4739 W_ERROR_NOT_OK_RETURN(result);
4743 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
4744 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4745 struct spoolss_DriverFileInfo,
4747 W_ERROR_HAVE_NO_MEMORY(info);
4748 result = fill_spoolss_DriverFileInfo(info,
4751 driver->dependent_files[i],
4752 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
4754 W_ERROR_NOT_OK_RETURN(result);
4764 /********************************************************************
4765 * fill a spoolss_DriverInfo101 struct
4766 ********************************************************************/
4768 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
4769 struct spoolss_DriverInfo101 *r,
4770 const struct spoolss_DriverInfo8 *driver,
4771 const char *servername)
4773 const char *cservername = canon_servername(servername);
4776 r->version = driver->version;
4778 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4779 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4780 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4781 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4783 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
4787 if (!W_ERROR_IS_OK(result)) {
4791 FILL_DRIVER_STRING(mem_ctx,
4792 driver->monitor_name,
4795 FILL_DRIVER_STRING(mem_ctx,
4796 driver->default_datatype,
4797 r->default_datatype);
4799 r->previous_names = string_array_from_driver_info(mem_ctx,
4800 driver->previous_names,
4802 r->driver_date = driver->driver_date;
4803 r->driver_version = driver->driver_version;
4805 FILL_DRIVER_STRING(mem_ctx,
4806 driver->manufacturer_name,
4807 r->manufacturer_name);
4808 FILL_DRIVER_STRING(mem_ctx,
4809 driver->manufacturer_url,
4810 r->manufacturer_url);
4811 FILL_DRIVER_STRING(mem_ctx,
4812 driver->hardware_id,
4814 FILL_DRIVER_STRING(mem_ctx,
4821 /********************************************************************
4822 ********************************************************************/
4824 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
4826 union spoolss_DriverInfo *r,
4828 const char *servername,
4829 const char *architecture,
4832 NT_PRINTER_INFO_LEVEL *printer = NULL;
4833 struct spoolss_DriverInfo8 *driver;
4836 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
4838 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
4839 win_errstr(result)));
4841 if (!W_ERROR_IS_OK(result)) {
4842 return WERR_INVALID_PRINTER_NAME;
4845 result = get_a_printer_driver(mem_ctx, &driver, printer->info_2->drivername,
4846 architecture, version);
4848 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
4849 win_errstr(result)));
4851 if (!W_ERROR_IS_OK(result)) {
4853 * Is this a W2k client ?
4857 free_a_printer(&printer, 2);
4858 return WERR_UNKNOWN_PRINTER_DRIVER;
4861 /* Yes - try again with a WinNT driver. */
4863 result = get_a_printer_driver(mem_ctx, &driver, printer->info_2->drivername,
4864 architecture, version);
4865 DEBUG(8,("construct_printer_driver_level: status: %s\n",
4866 win_errstr(result)));
4867 if (!W_ERROR_IS_OK(result)) {
4868 free_a_printer(&printer, 2);
4869 return WERR_UNKNOWN_PRINTER_DRIVER;
4875 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
4878 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
4881 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
4884 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
4887 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
4890 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
4893 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
4895 #if 0 /* disabled until marshalling issues are resolved - gd */
4897 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
4901 result = WERR_UNKNOWN_LEVEL;
4905 free_a_printer(&printer, 2);
4906 free_a_printer_driver(driver);
4911 /****************************************************************
4912 _spoolss_GetPrinterDriver2
4913 ****************************************************************/
4915 WERROR _spoolss_GetPrinterDriver2(pipes_struct *p,
4916 struct spoolss_GetPrinterDriver2 *r)
4918 Printer_entry *printer;
4921 const char *servername;
4924 /* that's an [in out] buffer */
4926 if (!r->in.buffer && (r->in.offered != 0)) {
4927 return WERR_INVALID_PARAM;
4930 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
4932 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
4933 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
4934 return WERR_INVALID_PRINTER_NAME;
4938 *r->out.server_major_version = 0;
4939 *r->out.server_minor_version = 0;
4941 servername = get_server_name(printer);
4943 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4947 result = construct_printer_driver_info_level(p->mem_ctx, r->in.level,
4951 r->in.client_major_version);
4952 if (!W_ERROR_IS_OK(result)) {
4953 TALLOC_FREE(r->out.info);
4957 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
4958 r->out.info, r->in.level);
4959 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4961 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4965 /****************************************************************
4966 _spoolss_StartPagePrinter
4967 ****************************************************************/
4969 WERROR _spoolss_StartPagePrinter(pipes_struct *p,
4970 struct spoolss_StartPagePrinter *r)
4972 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4975 DEBUG(3,("_spoolss_StartPagePrinter: "
4976 "Error in startpageprinter printer handle\n"));
4980 Printer->page_started = true;
4984 /****************************************************************
4985 _spoolss_EndPagePrinter
4986 ****************************************************************/
4988 WERROR _spoolss_EndPagePrinter(pipes_struct *p,
4989 struct spoolss_EndPagePrinter *r)
4993 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4996 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
4997 OUR_HANDLE(r->in.handle)));
5001 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5004 Printer->page_started = false;
5005 print_job_endpage(snum, Printer->jobid);
5010 /****************************************************************
5011 _spoolss_StartDocPrinter
5012 ****************************************************************/
5014 WERROR _spoolss_StartDocPrinter(pipes_struct *p,
5015 struct spoolss_StartDocPrinter *r)
5017 struct spoolss_DocumentInfo1 *info_1;
5019 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5022 DEBUG(2,("_spoolss_StartDocPrinter: "
5023 "Invalid handle (%s:%u:%u)\n",
5024 OUR_HANDLE(r->in.handle)));
5028 if (r->in.level != 1) {
5029 return WERR_UNKNOWN_LEVEL;
5032 info_1 = r->in.info.info1;
5035 * a nice thing with NT is it doesn't listen to what you tell it.
5036 * when asked to send _only_ RAW datas, it tries to send datas
5039 * So I add checks like in NT Server ...
5042 if (info_1->datatype) {
5043 if (strcmp(info_1->datatype, "RAW") != 0) {
5045 return WERR_INVALID_DATATYPE;
5049 /* get the share number of the printer */
5050 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5054 Printer->jobid = print_job_start(p->server_info, snum,
5055 info_1->document_name,
5058 /* An error occured in print_job_start() so return an appropriate
5061 if (Printer->jobid == -1) {
5062 return map_werror_from_unix(errno);
5065 Printer->document_started = true;
5066 *r->out.job_id = Printer->jobid;
5071 /****************************************************************
5072 _spoolss_EndDocPrinter
5073 ****************************************************************/
5075 WERROR _spoolss_EndDocPrinter(pipes_struct *p,
5076 struct spoolss_EndDocPrinter *r)
5078 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5082 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5083 OUR_HANDLE(r->in.handle)));
5087 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5091 Printer->document_started = false;
5092 print_job_end(snum, Printer->jobid, NORMAL_CLOSE);
5093 /* error codes unhandled so far ... */
5098 /****************************************************************
5099 _spoolss_WritePrinter
5100 ****************************************************************/
5102 WERROR _spoolss_WritePrinter(pipes_struct *p,
5103 struct spoolss_WritePrinter *r)
5105 ssize_t buffer_written;
5107 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5110 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5111 OUR_HANDLE(r->in.handle)));
5112 *r->out.num_written = r->in._data_size;
5116 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5119 buffer_written = print_job_write(snum, Printer->jobid,
5120 (const char *)r->in.data.data,
5122 (size_t)r->in._data_size);
5123 if (buffer_written == (ssize_t)-1) {
5124 *r->out.num_written = 0;
5125 if (errno == ENOSPC)
5126 return WERR_NO_SPOOL_SPACE;
5128 return WERR_ACCESS_DENIED;
5131 *r->out.num_written = r->in._data_size;
5136 /********************************************************************
5137 * api_spoolss_getprinter
5138 * called from the spoolss dispatcher
5140 ********************************************************************/
5142 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5146 WERROR errcode = WERR_BADFUNC;
5147 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5150 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5151 OUR_HANDLE(handle)));
5155 if (!get_printer_snum(p, handle, &snum, NULL))
5159 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5160 errcode = print_queue_pause(p->server_info, snum);
5162 case SPOOLSS_PRINTER_CONTROL_RESUME:
5163 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5164 errcode = print_queue_resume(p->server_info, snum);
5166 case SPOOLSS_PRINTER_CONTROL_PURGE:
5167 errcode = print_queue_purge(p->server_info, snum);
5170 return WERR_UNKNOWN_LEVEL;
5177 /****************************************************************
5178 _spoolss_AbortPrinter
5179 * From MSDN: "Deletes printer's spool file if printer is configured
5181 ****************************************************************/
5183 WERROR _spoolss_AbortPrinter(pipes_struct *p,
5184 struct spoolss_AbortPrinter *r)
5186 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5188 WERROR errcode = WERR_OK;
5191 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5192 OUR_HANDLE(r->in.handle)));
5196 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5199 print_job_delete(p->server_info, snum, Printer->jobid, &errcode );
5204 /********************************************************************
5205 * called by spoolss_api_setprinter
5206 * when updating a printer description
5207 ********************************************************************/
5209 static WERROR update_printer_sec(struct policy_handle *handle,
5210 pipes_struct *p, struct sec_desc_buf *secdesc_ctr)
5212 struct sec_desc_buf *new_secdesc_ctr = NULL, *old_secdesc_ctr = NULL;
5216 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5218 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5219 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5220 OUR_HANDLE(handle)));
5222 result = WERR_BADFID;
5227 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5228 result = WERR_INVALID_PARAM;
5232 /* Check the user has permissions to change the security
5233 descriptor. By experimentation with two NT machines, the user
5234 requires Full Access to the printer to change security
5237 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5238 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5239 result = WERR_ACCESS_DENIED;
5243 /* NT seems to like setting the security descriptor even though
5244 nothing may have actually changed. */
5246 if ( !nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr)) {
5247 DEBUG(2,("update_printer_sec: nt_printing_getsec() failed\n"));
5248 result = WERR_BADFID;
5252 if (DEBUGLEVEL >= 10) {
5253 struct security_acl *the_acl;
5256 the_acl = old_secdesc_ctr->sd->dacl;
5257 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5258 lp_printername(snum), the_acl->num_aces));
5260 for (i = 0; i < the_acl->num_aces; i++) {
5261 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5262 &the_acl->aces[i].trustee),
5263 the_acl->aces[i].access_mask));
5266 the_acl = secdesc_ctr->sd->dacl;
5269 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5270 lp_printername(snum), the_acl->num_aces));
5272 for (i = 0; i < the_acl->num_aces; i++) {
5273 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5274 &the_acl->aces[i].trustee),
5275 the_acl->aces[i].access_mask));
5278 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5282 new_secdesc_ctr = sec_desc_merge_buf(p->mem_ctx, secdesc_ctr, old_secdesc_ctr);
5283 if (!new_secdesc_ctr) {
5284 result = WERR_NOMEM;
5288 if (security_descriptor_equal(new_secdesc_ctr->sd, old_secdesc_ctr->sd)) {
5293 result = nt_printing_setsec(Printer->sharename, new_secdesc_ctr);
5300 /********************************************************************
5301 Canonicalize printer info from a client
5303 ATTN: It does not matter what we set the servername to hear
5304 since we do the necessary work in get_a_printer() to set it to
5305 the correct value based on what the client sent in the
5306 _spoolss_open_printer_ex().
5307 ********************************************************************/
5309 static bool check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum)
5311 fstring printername;
5314 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5315 "portname=%s drivername=%s comment=%s location=%s\n",
5316 info->servername, info->printername, info->sharename,
5317 info->portname, info->drivername, info->comment, info->location));
5319 /* we force some elements to "correct" values */
5320 slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname());
5321 fstrcpy(info->sharename, lp_servicename(snum));
5323 /* check to see if we allow printername != sharename */
5325 if ( lp_force_printername(snum) ) {
5326 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5327 global_myname(), info->sharename );
5330 /* make sure printername is in \\server\printername format */
5332 fstrcpy( printername, info->printername );
5334 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5335 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5339 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5340 global_myname(), p );
5343 info->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5344 info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5351 /****************************************************************************
5352 ****************************************************************************/
5354 static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri)
5356 char *cmd = lp_addport_cmd();
5357 char *command = NULL;
5359 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5360 bool is_print_op = false;
5363 return WERR_ACCESS_DENIED;
5366 command = talloc_asprintf(ctx,
5367 "%s \"%s\" \"%s\"", cmd, portname, uri );
5373 is_print_op = user_has_privileges( token, &se_printop );
5375 DEBUG(10,("Running [%s]\n", command));
5377 /********* BEGIN SePrintOperatorPrivilege **********/
5382 ret = smbrun(command, NULL);
5387 /********* END SePrintOperatorPrivilege **********/
5389 DEBUGADD(10,("returned [%d]\n", ret));
5391 TALLOC_FREE(command);
5394 return WERR_ACCESS_DENIED;
5400 /****************************************************************************
5401 ****************************************************************************/
5403 bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer)
5405 char *cmd = lp_addprinter_cmd();
5407 char *command = NULL;
5411 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5412 bool is_print_op = false;
5413 char *remote_machine = talloc_strdup(ctx, "%m");
5415 if (!remote_machine) {
5418 remote_machine = talloc_sub_basic(ctx,
5419 current_user_info.smb_name,
5420 current_user_info.domain,
5422 if (!remote_machine) {
5426 command = talloc_asprintf(ctx,
5427 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5428 cmd, printer->info_2->printername, printer->info_2->sharename,
5429 printer->info_2->portname, printer->info_2->drivername,
5430 printer->info_2->location, printer->info_2->comment, remote_machine);
5436 is_print_op = user_has_privileges( token, &se_printop );
5438 DEBUG(10,("Running [%s]\n", command));
5440 /********* BEGIN SePrintOperatorPrivilege **********/
5445 if ( (ret = smbrun(command, &fd)) == 0 ) {
5446 /* Tell everyone we updated smb.conf. */
5447 message_send_all(smbd_messaging_context(),
5448 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5454 /********* END SePrintOperatorPrivilege **********/
5456 DEBUGADD(10,("returned [%d]\n", ret));
5458 TALLOC_FREE(command);
5459 TALLOC_FREE(remote_machine);
5467 /* reload our services immediately */
5469 reload_services(false);
5473 /* Get lines and convert them back to dos-codepage */
5474 qlines = fd_lines_load(fd, &numlines, 0, NULL);
5475 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
5478 /* Set the portname to what the script says the portname should be. */
5479 /* but don't require anything to be return from the script exit a good error code */
5482 /* Set the portname to what the script says the portname should be. */
5483 strncpy(printer->info_2->portname, qlines[0], sizeof(printer->info_2->portname));
5484 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
5487 TALLOC_FREE(qlines);
5492 /********************************************************************
5493 * Called by spoolss_api_setprinter
5494 * when updating a printer description.
5495 ********************************************************************/
5497 static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
5498 struct spoolss_SetPrinterInfoCtr *info_ctr,
5499 struct spoolss_DeviceMode *devmode)
5502 NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL;
5503 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5508 DEBUG(8,("update_printer\n"));
5513 result = WERR_BADFID;
5517 if (!get_printer_snum(p, handle, &snum, NULL)) {
5518 result = WERR_BADFID;
5522 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))) ||
5523 (!W_ERROR_IS_OK(get_a_printer(Printer, &old_printer, 2, lp_const_servicename(snum))))) {
5524 result = WERR_BADFID;
5528 DEBUGADD(8,("Converting info_2 struct\n"));
5531 * convert_printer_info converts the incoming
5532 * info from the client and overwrites the info
5533 * just read from the tdb in the pointer 'printer'.
5536 if (!convert_printer_info(info_ctr, printer)) {
5537 result = WERR_NOMEM;
5542 /* we have a valid devmode
5543 convert it and link it*/
5545 DEBUGADD(8,("update_printer: Converting the devicemode struct\n"));
5546 result = copy_devicemode(printer->info_2, devmode,
5547 &printer->info_2->devmode);
5548 if (!W_ERROR_IS_OK(result)) {
5553 /* Do sanity check on the requested changes for Samba */
5555 if (!check_printer_ok(printer->info_2, snum)) {
5556 result = WERR_INVALID_PARAM;
5560 /* FIXME!!! If the driver has changed we really should verify that
5561 it is installed before doing much else --jerry */
5563 /* Check calling user has permission to update printer description */
5565 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
5566 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
5567 result = WERR_ACCESS_DENIED;
5571 /* Call addprinter hook */
5572 /* Check changes to see if this is really needed */
5574 if ( *lp_addprinter_cmd()
5575 && (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)
5576 || !strequal(printer->info_2->comment, old_printer->info_2->comment)
5577 || !strequal(printer->info_2->portname, old_printer->info_2->portname)
5578 || !strequal(printer->info_2->location, old_printer->info_2->location)) )
5580 /* add_printer_hook() will call reload_services() */
5582 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
5584 result = WERR_ACCESS_DENIED;
5590 * When a *new* driver is bound to a printer, the drivername is used to
5591 * lookup previously saved driver initialization info, which is then
5592 * bound to the printer, simulating what happens in the Windows arch.
5594 if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername))
5596 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
5597 printer->info_2->drivername));
5599 notify_printer_driver(snum, printer->info_2->drivername);
5603 * flag which changes actually occured. This is a small subset of
5604 * all the possible changes. We also have to update things in the
5608 if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) {
5609 push_reg_sz(talloc_tos(), &buffer, printer->info_2->comment);
5610 winreg_set_printer_dataex(p->mem_ctx,
5612 printer->info_2->sharename,
5613 SPOOL_DSSPOOLER_KEY,
5619 notify_printer_comment(snum, printer->info_2->comment);
5622 if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) {
5623 push_reg_sz(talloc_tos(), &buffer, printer->info_2->sharename);
5624 winreg_set_printer_dataex(p->mem_ctx,
5626 printer->info_2->sharename,
5627 SPOOL_DSSPOOLER_KEY,
5633 notify_printer_sharename(snum, printer->info_2->sharename);
5636 if (!strequal(printer->info_2->printername, old_printer->info_2->printername)) {
5639 if ( (pname = strchr_m( printer->info_2->printername+2, '\\' )) != NULL )
5642 pname = printer->info_2->printername;
5645 push_reg_sz(talloc_tos(), &buffer, pname);
5646 winreg_set_printer_dataex(p->mem_ctx,
5648 printer->info_2->sharename,
5649 SPOOL_DSSPOOLER_KEY,
5655 notify_printer_printername( snum, pname );
5658 if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) {
5659 push_reg_sz(talloc_tos(), &buffer, printer->info_2->portname);
5660 winreg_set_printer_dataex(p->mem_ctx,
5662 printer->info_2->sharename,
5663 SPOOL_DSSPOOLER_KEY,
5669 notify_printer_port(snum, printer->info_2->portname);
5672 if (!strequal(printer->info_2->location, old_printer->info_2->location)) {
5673 push_reg_sz(talloc_tos(), &buffer, printer->info_2->location);
5674 winreg_set_printer_dataex(p->mem_ctx,
5676 printer->info_2->sharename,
5677 SPOOL_DSSPOOLER_KEY,
5683 notify_printer_location(snum, printer->info_2->location);
5686 /* here we need to update some more DsSpooler keys */
5687 /* uNCName, serverName, shortServerName */
5689 push_reg_sz(talloc_tos(), &buffer, global_myname());
5690 winreg_set_printer_dataex(p->mem_ctx,
5692 printer->info_2->sharename,
5693 SPOOL_DSSPOOLER_KEY,
5698 winreg_set_printer_dataex(p->mem_ctx,
5700 printer->info_2->sharename,
5701 SPOOL_DSSPOOLER_KEY,
5707 slprintf( asc_buffer, sizeof(asc_buffer)-1, "\\\\%s\\%s",
5708 global_myname(), printer->info_2->sharename );
5709 push_reg_sz(talloc_tos(), &buffer, asc_buffer);
5710 winreg_set_printer_dataex(p->mem_ctx,
5712 printer->info_2->sharename,
5713 SPOOL_DSSPOOLER_KEY,
5719 /* Update printer info */
5720 result = mod_a_printer(printer, 2);
5723 free_a_printer(&printer, 2);
5724 free_a_printer(&old_printer, 2);
5730 /****************************************************************************
5731 ****************************************************************************/
5732 static WERROR publish_or_unpublish_printer(pipes_struct *p,
5733 struct policy_handle *handle,
5734 struct spoolss_SetPrinterInfo7 *info7)
5738 Printer_entry *Printer;
5740 if ( lp_security() != SEC_ADS ) {
5741 return WERR_UNKNOWN_LEVEL;
5744 Printer = find_printer_index_by_hnd(p, handle);
5746 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
5751 if (!get_printer_snum(p, handle, &snum, NULL))
5754 nt_printer_publish(Printer, snum, info7->action);
5758 return WERR_UNKNOWN_LEVEL;
5762 /********************************************************************
5763 ********************************************************************/
5765 static WERROR update_printer_devmode(pipes_struct *p, struct policy_handle *handle,
5766 struct spoolss_DeviceMode *devmode)
5769 NT_PRINTER_INFO_LEVEL *printer = NULL;
5770 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5773 DEBUG(8,("update_printer_devmode\n"));
5778 result = WERR_BADFID;
5782 if (!get_printer_snum(p, handle, &snum, NULL)) {
5783 result = WERR_BADFID;
5787 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)))) {
5788 result = WERR_BADFID;
5793 /* we have a valid devmode, copy it */
5795 DEBUGADD(8, ("update_printer: Copying the devicemode struct\n"));
5796 result = copy_devicemode(printer->info_2, devmode,
5797 &printer->info_2->devmode);
5798 if (!W_ERROR_IS_OK(result)) {
5803 /* Check calling user has permission to update printer description */
5805 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
5806 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
5807 result = WERR_ACCESS_DENIED;
5812 /* Update printer info */
5813 result = mod_a_printer(printer, 2);
5816 free_a_printer(&printer, 2);
5822 /****************************************************************
5824 ****************************************************************/
5826 WERROR _spoolss_SetPrinter(pipes_struct *p,
5827 struct spoolss_SetPrinter *r)
5831 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5834 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
5835 OUR_HANDLE(r->in.handle)));
5839 /* check the level */
5840 switch (r->in.info_ctr->level) {
5842 return control_printer(r->in.handle, r->in.command, p);
5844 result = update_printer(p, r->in.handle,
5846 r->in.devmode_ctr->devmode);
5847 if (!W_ERROR_IS_OK(result))
5849 if (r->in.secdesc_ctr->sd)
5850 result = update_printer_sec(r->in.handle, p,
5854 return update_printer_sec(r->in.handle, p,
5857 return publish_or_unpublish_printer(p, r->in.handle,
5858 r->in.info_ctr->info.info7);
5860 return update_printer_devmode(p, r->in.handle,
5861 r->in.devmode_ctr->devmode);
5863 return WERR_UNKNOWN_LEVEL;
5867 /****************************************************************
5868 _spoolss_FindClosePrinterNotify
5869 ****************************************************************/
5871 WERROR _spoolss_FindClosePrinterNotify(pipes_struct *p,
5872 struct spoolss_FindClosePrinterNotify *r)
5874 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5877 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
5878 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
5882 if (Printer->notify.client_connected == true) {
5885 if ( Printer->printer_type == SPLHND_SERVER)
5887 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
5888 !get_printer_snum(p, r->in.handle, &snum, NULL) )
5891 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
5894 Printer->notify.flags=0;
5895 Printer->notify.options=0;
5896 Printer->notify.localmachine[0]='\0';
5897 Printer->notify.printerlocal=0;
5898 TALLOC_FREE(Printer->notify.option);
5899 Printer->notify.client_connected = false;
5904 /****************************************************************
5906 ****************************************************************/
5908 WERROR _spoolss_AddJob(pipes_struct *p,
5909 struct spoolss_AddJob *r)
5911 if (!r->in.buffer && (r->in.offered != 0)) {
5912 return WERR_INVALID_PARAM;
5915 /* this is what a NT server returns for AddJob. AddJob must fail on
5916 * non-local printers */
5918 if (r->in.level != 1) {
5919 return WERR_UNKNOWN_LEVEL;
5922 return WERR_INVALID_PARAM;
5925 /****************************************************************************
5927 ****************************************************************************/
5929 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
5930 struct spoolss_JobInfo1 *r,
5931 const print_queue_struct *queue,
5932 int position, int snum,
5933 const NT_PRINTER_INFO_LEVEL *ntprinter)
5937 t = gmtime(&queue->time);
5939 r->job_id = queue->job;
5941 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
5942 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
5943 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
5944 W_ERROR_HAVE_NO_MEMORY(r->server_name);
5945 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
5946 W_ERROR_HAVE_NO_MEMORY(r->user_name);
5947 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
5948 W_ERROR_HAVE_NO_MEMORY(r->document_name);
5949 r->data_type = talloc_strdup(mem_ctx, "RAW");
5950 W_ERROR_HAVE_NO_MEMORY(r->data_type);
5951 r->text_status = talloc_strdup(mem_ctx, "");
5952 W_ERROR_HAVE_NO_MEMORY(r->text_status);
5954 r->status = nt_printj_status(queue->status);
5955 r->priority = queue->priority;
5956 r->position = position;
5957 r->total_pages = queue->page_count;
5958 r->pages_printed = 0; /* ??? */
5960 init_systemtime(&r->submitted, t);
5965 /****************************************************************************
5967 ****************************************************************************/
5969 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
5970 struct spoolss_JobInfo2 *r,
5971 const print_queue_struct *queue,
5972 int position, int snum,
5973 const NT_PRINTER_INFO_LEVEL *ntprinter,
5974 struct spoolss_DeviceMode *devmode)
5978 t = gmtime(&queue->time);
5980 r->job_id = queue->job;
5982 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
5983 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
5984 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
5985 W_ERROR_HAVE_NO_MEMORY(r->server_name);
5986 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
5987 W_ERROR_HAVE_NO_MEMORY(r->user_name);
5988 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
5989 W_ERROR_HAVE_NO_MEMORY(r->document_name);
5990 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
5991 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
5992 r->data_type = talloc_strdup(mem_ctx, "RAW");
5993 W_ERROR_HAVE_NO_MEMORY(r->data_type);
5994 r->print_processor = talloc_strdup(mem_ctx, "winprint");
5995 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
5996 r->parameters = talloc_strdup(mem_ctx, "");
5997 W_ERROR_HAVE_NO_MEMORY(r->parameters);
5998 r->driver_name = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
5999 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6001 r->devmode = devmode;
6003 r->text_status = talloc_strdup(mem_ctx, "");
6004 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6008 r->status = nt_printj_status(queue->status);
6009 r->priority = queue->priority;
6010 r->position = position;
6013 r->total_pages = queue->page_count;
6014 r->size = queue->size;
6015 init_systemtime(&r->submitted, t);
6017 r->pages_printed = 0; /* ??? */
6022 /****************************************************************************
6024 ****************************************************************************/
6026 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6027 struct spoolss_JobInfo3 *r,
6028 const print_queue_struct *queue,
6029 const print_queue_struct *next_queue,
6030 int position, int snum,
6031 const NT_PRINTER_INFO_LEVEL *ntprinter)
6033 r->job_id = queue->job;
6036 r->next_job_id = next_queue->job;
6043 /****************************************************************************
6044 Enumjobs at level 1.
6045 ****************************************************************************/
6047 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6048 const print_queue_struct *queue,
6049 uint32_t num_queues, int snum,
6050 const NT_PRINTER_INFO_LEVEL *ntprinter,
6051 union spoolss_JobInfo **info_p,
6054 union spoolss_JobInfo *info;
6056 WERROR result = WERR_OK;
6058 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6059 W_ERROR_HAVE_NO_MEMORY(info);
6061 *count = num_queues;
6063 for (i=0; i<*count; i++) {
6064 result = fill_job_info1(info,
6070 if (!W_ERROR_IS_OK(result)) {
6076 if (!W_ERROR_IS_OK(result)) {
6087 /****************************************************************************
6088 Enumjobs at level 2.
6089 ****************************************************************************/
6091 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6092 const print_queue_struct *queue,
6093 uint32_t num_queues, int snum,
6094 const NT_PRINTER_INFO_LEVEL *ntprinter,
6095 union spoolss_JobInfo **info_p,
6098 union spoolss_JobInfo *info;
6100 WERROR result = WERR_OK;
6102 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6103 W_ERROR_HAVE_NO_MEMORY(info);
6105 *count = num_queues;
6107 for (i=0; i<*count; i++) {
6109 struct spoolss_DeviceMode *devmode;
6111 devmode = construct_dev_mode(info, lp_const_servicename(snum));
6113 result = WERR_NOMEM;
6117 result = fill_job_info2(info,
6124 if (!W_ERROR_IS_OK(result)) {
6130 if (!W_ERROR_IS_OK(result)) {
6141 /****************************************************************************
6142 Enumjobs at level 3.
6143 ****************************************************************************/
6145 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6146 const print_queue_struct *queue,
6147 uint32_t num_queues, int snum,
6148 const NT_PRINTER_INFO_LEVEL *ntprinter,
6149 union spoolss_JobInfo **info_p,
6152 union spoolss_JobInfo *info;
6154 WERROR result = WERR_OK;
6156 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6157 W_ERROR_HAVE_NO_MEMORY(info);
6159 *count = num_queues;
6161 for (i=0; i<*count; i++) {
6162 const print_queue_struct *next_queue = NULL;
6165 next_queue = &queue[i+1];
6168 result = fill_job_info3(info,
6175 if (!W_ERROR_IS_OK(result)) {
6181 if (!W_ERROR_IS_OK(result)) {
6192 /****************************************************************
6194 ****************************************************************/
6196 WERROR _spoolss_EnumJobs(pipes_struct *p,
6197 struct spoolss_EnumJobs *r)
6200 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
6202 print_status_struct prt_status;
6203 print_queue_struct *queue = NULL;
6206 /* that's an [in out] buffer */
6208 if (!r->in.buffer && (r->in.offered != 0)) {
6209 return WERR_INVALID_PARAM;
6212 DEBUG(4,("_spoolss_EnumJobs\n"));
6216 *r->out.info = NULL;
6218 /* lookup the printer snum and tdb entry */
6220 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6224 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
6225 if (!W_ERROR_IS_OK(result)) {
6229 count = print_queue_status(snum, &queue, &prt_status);
6230 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6231 count, prt_status.status, prt_status.message));
6235 free_a_printer(&ntprinter, 2);
6239 switch (r->in.level) {
6241 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6242 ntprinter, r->out.info, r->out.count);
6245 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6246 ntprinter, r->out.info, r->out.count);
6249 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
6250 ntprinter, r->out.info, r->out.count);
6253 result = WERR_UNKNOWN_LEVEL;
6258 free_a_printer(&ntprinter, 2);
6260 if (!W_ERROR_IS_OK(result)) {
6264 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6266 *r->out.info, r->in.level,
6268 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6269 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6271 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6274 /****************************************************************
6275 _spoolss_ScheduleJob
6276 ****************************************************************/
6278 WERROR _spoolss_ScheduleJob(pipes_struct *p,
6279 struct spoolss_ScheduleJob *r)
6284 /****************************************************************
6285 ****************************************************************/
6287 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
6288 const char *printer_name,
6290 struct spoolss_SetJobInfo1 *r)
6294 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
6298 if (strequal(old_doc_name, r->document_name)) {
6302 if (!print_job_set_name(printer_name, job_id, r->document_name)) {
6309 /****************************************************************
6311 ****************************************************************/
6313 WERROR _spoolss_SetJob(pipes_struct *p,
6314 struct spoolss_SetJob *r)
6317 WERROR errcode = WERR_BADFUNC;
6319 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6323 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6324 return WERR_INVALID_PRINTER_NAME;
6327 switch (r->in.command) {
6328 case SPOOLSS_JOB_CONTROL_CANCEL:
6329 case SPOOLSS_JOB_CONTROL_DELETE:
6330 if (print_job_delete(p->server_info, snum, r->in.job_id, &errcode)) {
6334 case SPOOLSS_JOB_CONTROL_PAUSE:
6335 if (print_job_pause(p->server_info, snum, r->in.job_id, &errcode)) {
6339 case SPOOLSS_JOB_CONTROL_RESTART:
6340 case SPOOLSS_JOB_CONTROL_RESUME:
6341 if (print_job_resume(p->server_info, snum, r->in.job_id, &errcode)) {
6349 return WERR_UNKNOWN_LEVEL;
6352 if (!W_ERROR_IS_OK(errcode)) {
6356 if (r->in.ctr == NULL) {
6360 switch (r->in.ctr->level) {
6362 errcode = spoolss_setjob_1(p->mem_ctx, lp_const_servicename(snum),
6364 r->in.ctr->info.info1);
6370 return WERR_UNKNOWN_LEVEL;
6376 /****************************************************************************
6377 Enumerates all printer drivers by level and architecture.
6378 ****************************************************************************/
6380 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
6381 const char *servername,
6382 const char *architecture,
6384 union spoolss_DriverInfo **info_p,
6390 fstring *list = NULL;
6391 struct spoolss_DriverInfo8 *driver;
6392 union spoolss_DriverInfo *info = NULL;
6394 WERROR result = WERR_OK;
6399 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6401 ndrivers = get_ntdrivers(&list, architecture, version);
6402 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n",
6403 ndrivers, architecture, version));
6405 if (ndrivers == -1) {
6406 result = WERR_NOMEM;
6410 if (ndrivers != 0) {
6411 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6412 union spoolss_DriverInfo,
6415 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
6416 "failed to enlarge driver info buffer!\n"));
6417 result = WERR_NOMEM;
6422 for (i=0; i<ndrivers; i++) {
6423 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
6424 ZERO_STRUCT(driver);
6425 result = get_a_printer_driver(mem_ctx, &driver, list[i],
6426 architecture, version);
6427 if (!W_ERROR_IS_OK(result)) {
6433 result = fill_printer_driver_info1(info, &info[count+i].info1,
6434 driver, servername);
6437 result = fill_printer_driver_info2(info, &info[count+i].info2,
6438 driver, servername);
6441 result = fill_printer_driver_info3(info, &info[count+i].info3,
6442 driver, servername);
6445 result = fill_printer_driver_info4(info, &info[count+i].info4,
6446 driver, servername);
6449 result = fill_printer_driver_info5(info, &info[count+i].info5,
6450 driver, servername);
6453 result = fill_printer_driver_info6(info, &info[count+i].info6,
6454 driver, servername);
6457 result = fill_printer_driver_info8(info, &info[count+i].info8,
6458 driver, servername);
6461 result = WERR_UNKNOWN_LEVEL;
6465 free_a_printer_driver(driver);
6467 if (!W_ERROR_IS_OK(result)) {
6479 if (!W_ERROR_IS_OK(result)) {
6490 /****************************************************************************
6491 Enumerates all printer drivers by level.
6492 ****************************************************************************/
6494 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
6495 const char *servername,
6496 const char *architecture,
6498 union spoolss_DriverInfo **info_p,
6502 WERROR result = WERR_OK;
6504 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
6506 for (a=0; archi_table[a].long_archi != NULL; a++) {
6508 union spoolss_DriverInfo *info = NULL;
6511 result = enumprinterdrivers_level_by_architecture(mem_ctx,
6513 archi_table[a].long_archi,
6517 if (!W_ERROR_IS_OK(result)) {
6521 for (i=0; i < count; i++) {
6522 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
6523 info[i], info_p, count_p);
6530 return enumprinterdrivers_level_by_architecture(mem_ctx,
6538 /****************************************************************
6539 _spoolss_EnumPrinterDrivers
6540 ****************************************************************/
6542 WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
6543 struct spoolss_EnumPrinterDrivers *r)
6545 const char *cservername;
6548 /* that's an [in out] buffer */
6550 if (!r->in.buffer && (r->in.offered != 0)) {
6551 return WERR_INVALID_PARAM;
6554 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
6558 *r->out.info = NULL;
6560 cservername = canon_servername(r->in.server);
6562 if (!is_myname_or_ipaddr(cservername)) {
6563 return WERR_UNKNOWN_PRINTER_DRIVER;
6566 result = enumprinterdrivers_level(p->mem_ctx, cservername,
6571 if (!W_ERROR_IS_OK(result)) {
6575 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6576 spoolss_EnumPrinterDrivers,
6577 *r->out.info, r->in.level,
6579 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6580 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6582 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6585 /****************************************************************************
6586 ****************************************************************************/
6588 static WERROR fill_form_info_1(TALLOC_CTX *mem_ctx,
6589 struct spoolss_FormInfo1 *r,
6590 const nt_forms_struct *form)
6592 r->form_name = talloc_strdup(mem_ctx, form->name);
6593 W_ERROR_HAVE_NO_MEMORY(r->form_name);
6595 r->flags = form->flag;
6596 r->size.width = form->width;
6597 r->size.height = form->length;
6598 r->area.left = form->left;
6599 r->area.top = form->top;
6600 r->area.right = form->right;
6601 r->area.bottom = form->bottom;
6606 /****************************************************************
6607 spoolss_enumforms_level1
6608 ****************************************************************/
6610 static WERROR spoolss_enumforms_level1(TALLOC_CTX *mem_ctx,
6611 const nt_forms_struct *builtin_forms,
6612 uint32_t num_builtin_forms,
6613 const nt_forms_struct *user_forms,
6614 uint32_t num_user_forms,
6615 union spoolss_FormInfo **info_p,
6618 union spoolss_FormInfo *info;
6619 WERROR result = WERR_OK;
6622 *count = num_builtin_forms + num_user_forms;
6624 info = TALLOC_ARRAY(mem_ctx, union spoolss_FormInfo, *count);
6625 W_ERROR_HAVE_NO_MEMORY(info);
6627 /* construct the list of form structures */
6628 for (i=0; i<num_builtin_forms; i++) {
6629 DEBUGADD(6,("Filling builtin form number [%d]\n",i));
6630 result = fill_form_info_1(info, &info[i].info1,
6632 if (!W_ERROR_IS_OK(result)) {
6637 for (i=0; i<num_user_forms; i++) {
6638 DEBUGADD(6,("Filling user form number [%d]\n",i));
6639 result = fill_form_info_1(info, &info[i+num_builtin_forms].info1,
6641 if (!W_ERROR_IS_OK(result)) {
6647 if (!W_ERROR_IS_OK(result)) {
6658 /****************************************************************
6660 ****************************************************************/
6662 WERROR _spoolss_EnumForms(pipes_struct *p,
6663 struct spoolss_EnumForms *r)
6666 nt_forms_struct *user_forms = NULL;
6667 nt_forms_struct *builtin_forms = NULL;
6668 uint32_t num_user_forms;
6669 uint32_t num_builtin_forms;
6673 *r->out.info = NULL;
6675 /* that's an [in out] buffer */
6677 if (!r->in.buffer && (r->in.offered != 0) ) {
6678 return WERR_INVALID_PARAM;
6681 DEBUG(4,("_spoolss_EnumForms\n"));
6682 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6683 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6685 num_builtin_forms = get_builtin_ntforms(&builtin_forms);
6686 DEBUGADD(5,("Number of builtin forms [%d]\n", num_builtin_forms));
6687 num_user_forms = get_ntforms(&user_forms);
6688 DEBUGADD(5,("Number of user forms [%d]\n", num_user_forms));
6690 if (num_user_forms + num_builtin_forms == 0) {
6691 SAFE_FREE(builtin_forms);
6692 SAFE_FREE(user_forms);
6693 return WERR_NO_MORE_ITEMS;
6696 switch (r->in.level) {
6698 result = spoolss_enumforms_level1(p->mem_ctx,
6707 result = WERR_UNKNOWN_LEVEL;
6711 SAFE_FREE(user_forms);
6712 SAFE_FREE(builtin_forms);
6714 if (!W_ERROR_IS_OK(result)) {
6718 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6720 *r->out.info, r->in.level,
6722 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6723 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6725 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6728 /****************************************************************
6729 ****************************************************************/
6731 static WERROR find_form_byname(const char *name,
6732 nt_forms_struct *form)
6734 nt_forms_struct *list = NULL;
6735 int num_forms = 0, i = 0;
6737 if (get_a_builtin_ntform_by_string(name, form)) {
6741 num_forms = get_ntforms(&list);
6742 DEBUGADD(5,("Number of forms [%d]\n", num_forms));
6744 if (num_forms == 0) {
6748 /* Check if the requested name is in the list of form structures */
6749 for (i = 0; i < num_forms; i++) {
6751 DEBUG(4,("checking form %s (want %s)\n", list[i].name, name));
6753 if (strequal(name, list[i].name)) {
6754 DEBUGADD(6,("Found form %s number [%d]\n", name, i));
6766 /****************************************************************
6768 ****************************************************************/
6770 WERROR _spoolss_GetForm(pipes_struct *p,
6771 struct spoolss_GetForm *r)
6774 nt_forms_struct form;
6776 /* that's an [in out] buffer */
6778 if (!r->in.buffer && (r->in.offered != 0)) {
6779 return WERR_INVALID_PARAM;
6782 DEBUG(4,("_spoolss_GetForm\n"));
6783 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6784 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6786 result = find_form_byname(r->in.form_name, &form);
6787 if (!W_ERROR_IS_OK(result)) {
6788 TALLOC_FREE(r->out.info);
6792 switch (r->in.level) {
6794 result = fill_form_info_1(p->mem_ctx,
6795 &r->out.info->info1,
6800 result = WERR_UNKNOWN_LEVEL;
6804 if (!W_ERROR_IS_OK(result)) {
6805 TALLOC_FREE(r->out.info);
6809 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
6810 r->out.info, r->in.level);
6811 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
6813 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6816 /****************************************************************************
6817 ****************************************************************************/
6819 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
6820 struct spoolss_PortInfo1 *r,
6823 r->port_name = talloc_strdup(mem_ctx, name);
6824 W_ERROR_HAVE_NO_MEMORY(r->port_name);
6829 /****************************************************************************
6830 TODO: This probably needs distinguish between TCP/IP and Local ports
6832 ****************************************************************************/
6834 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
6835 struct spoolss_PortInfo2 *r,
6838 r->port_name = talloc_strdup(mem_ctx, name);
6839 W_ERROR_HAVE_NO_MEMORY(r->port_name);
6841 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
6842 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
6844 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
6845 W_ERROR_HAVE_NO_MEMORY(r->description);
6847 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
6854 /****************************************************************************
6855 wrapper around the enumer ports command
6856 ****************************************************************************/
6858 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
6860 char *cmd = lp_enumports_cmd();
6861 char **qlines = NULL;
6862 char *command = NULL;
6870 /* if no hook then just fill in the default port */
6873 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
6876 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
6877 TALLOC_FREE(qlines);
6884 /* we have a valid enumport command */
6886 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
6891 DEBUG(10,("Running [%s]\n", command));
6892 ret = smbrun(command, &fd);
6893 DEBUG(10,("Returned [%d]\n", ret));
6894 TALLOC_FREE(command);
6899 return WERR_ACCESS_DENIED;
6903 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6904 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6914 /****************************************************************************
6916 ****************************************************************************/
6918 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
6919 union spoolss_PortInfo **info_p,
6922 union spoolss_PortInfo *info = NULL;
6924 WERROR result = WERR_OK;
6925 char **qlines = NULL;
6928 result = enumports_hook(talloc_tos(), &numlines, &qlines );
6929 if (!W_ERROR_IS_OK(result)) {
6934 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
6936 DEBUG(10,("Returning WERR_NOMEM\n"));
6937 result = WERR_NOMEM;
6941 for (i=0; i<numlines; i++) {
6942 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
6943 result = fill_port_1(info, &info[i].info1, qlines[i]);
6944 if (!W_ERROR_IS_OK(result)) {
6949 TALLOC_FREE(qlines);
6952 if (!W_ERROR_IS_OK(result)) {
6954 TALLOC_FREE(qlines);
6966 /****************************************************************************
6968 ****************************************************************************/
6970 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
6971 union spoolss_PortInfo **info_p,
6974 union spoolss_PortInfo *info = NULL;
6976 WERROR result = WERR_OK;
6977 char **qlines = NULL;
6980 result = enumports_hook(talloc_tos(), &numlines, &qlines );
6981 if (!W_ERROR_IS_OK(result)) {
6986 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
6988 DEBUG(10,("Returning WERR_NOMEM\n"));
6989 result = WERR_NOMEM;
6993 for (i=0; i<numlines; i++) {
6994 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
6995 result = fill_port_2(info, &info[i].info2, qlines[i]);
6996 if (!W_ERROR_IS_OK(result)) {
7001 TALLOC_FREE(qlines);
7004 if (!W_ERROR_IS_OK(result)) {
7006 TALLOC_FREE(qlines);
7018 /****************************************************************
7020 ****************************************************************/
7022 WERROR _spoolss_EnumPorts(pipes_struct *p,
7023 struct spoolss_EnumPorts *r)
7027 /* that's an [in out] buffer */
7029 if (!r->in.buffer && (r->in.offered != 0)) {
7030 return WERR_INVALID_PARAM;
7033 DEBUG(4,("_spoolss_EnumPorts\n"));
7037 *r->out.info = NULL;
7039 switch (r->in.level) {
7041 result = enumports_level_1(p->mem_ctx, r->out.info,
7045 result = enumports_level_2(p->mem_ctx, r->out.info,
7049 return WERR_UNKNOWN_LEVEL;
7052 if (!W_ERROR_IS_OK(result)) {
7056 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7058 *r->out.info, r->in.level,
7060 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7061 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7063 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7066 /****************************************************************************
7067 ****************************************************************************/
7069 static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
7071 struct spoolss_SetPrinterInfoCtr *info_ctr,
7072 struct spoolss_DeviceMode *devmode,
7073 struct security_descriptor *sec_desc,
7074 struct spoolss_UserLevelCtr *user_ctr,
7075 struct policy_handle *handle)
7077 NT_PRINTER_INFO_LEVEL *printer = NULL;
7080 WERROR err = WERR_OK;
7082 if ( !(printer = TALLOC_ZERO_P(NULL, NT_PRINTER_INFO_LEVEL)) ) {
7083 DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
7087 /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/
7088 if (!convert_printer_info(info_ctr, printer)) {
7089 free_a_printer(&printer, 2);
7093 /* samba does not have a concept of local, non-shared printers yet, so
7094 * make sure we always setup sharename - gd */
7095 if ((printer->info_2->sharename[0] == '\0') && (printer->info_2->printername != '\0')) {
7096 DEBUG(5, ("spoolss_addprinterex_level_2: "
7097 "no sharename has been set, setting printername %s as sharename\n",
7098 printer->info_2->printername));
7099 fstrcpy(printer->info_2->sharename, printer->info_2->printername);
7102 /* check to see if the printer already exists */
7104 if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) {
7105 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7106 printer->info_2->sharename));
7107 free_a_printer(&printer, 2);
7108 return WERR_PRINTER_ALREADY_EXISTS;
7111 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7112 if ((snum = print_queue_snum(printer->info_2->printername)) != -1) {
7113 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7114 printer->info_2->printername));
7115 free_a_printer(&printer, 2);
7116 return WERR_PRINTER_ALREADY_EXISTS;
7120 /* validate printer info struct */
7121 if (!info_ctr->info.info2->printername ||
7122 strlen(info_ctr->info.info2->printername) == 0) {
7123 free_a_printer(&printer,2);
7124 return WERR_INVALID_PRINTER_NAME;
7126 if (!info_ctr->info.info2->portname ||
7127 strlen(info_ctr->info.info2->portname) == 0) {
7128 free_a_printer(&printer,2);
7129 return WERR_UNKNOWN_PORT;
7131 if (!info_ctr->info.info2->drivername ||
7132 strlen(info_ctr->info.info2->drivername) == 0) {
7133 free_a_printer(&printer,2);
7134 return WERR_UNKNOWN_PRINTER_DRIVER;
7136 if (!info_ctr->info.info2->printprocessor ||
7137 strlen(info_ctr->info.info2->printprocessor) == 0) {
7138 free_a_printer(&printer,2);
7139 return WERR_UNKNOWN_PRINTPROCESSOR;
7142 /* FIXME!!! smbd should check to see if the driver is installed before
7143 trying to add a printer like this --jerry */
7145 if (*lp_addprinter_cmd() ) {
7146 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7148 free_a_printer(&printer,2);
7149 return WERR_ACCESS_DENIED;
7152 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7153 "smb.conf parameter \"addprinter command\" is defined. This"
7154 "parameter must exist for this call to succeed\n",
7155 printer->info_2->sharename ));
7158 /* use our primary netbios name since get_a_printer() will convert
7159 it to what the client expects on a case by case basis */
7161 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname(),
7162 printer->info_2->sharename);
7165 if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) {
7166 free_a_printer(&printer,2);
7167 return WERR_ACCESS_DENIED;
7170 /* you must be a printer admin to add a new printer */
7171 if (!print_access_check(p->server_info, snum, PRINTER_ACCESS_ADMINISTER)) {
7172 free_a_printer(&printer,2);
7173 return WERR_ACCESS_DENIED;
7177 * Do sanity check on the requested changes for Samba.
7180 if (!check_printer_ok(printer->info_2, snum)) {
7181 free_a_printer(&printer,2);
7182 return WERR_INVALID_PARAM;
7186 * When a printer is created, the drivername bound to the printer is used
7187 * to lookup previously saved driver initialization info, which is then
7188 * bound to the new printer, simulating what happens in the Windows arch.
7193 /* A valid devmode was included, convert and link it
7195 DEBUGADD(10, ("spoolss_addprinterex_level_2: devmode included, converting\n"));
7197 err = copy_devicemode(printer, devmode,
7198 &printer->info_2->devmode);
7199 if (!W_ERROR_IS_OK(err)) {
7204 /* write the ASCII on disk */
7205 err = mod_a_printer(printer, 2);
7206 if (!W_ERROR_IS_OK(err)) {
7207 free_a_printer(&printer,2);
7211 if (!open_printer_hnd(p, handle, name, PRINTER_ACCESS_ADMINISTER)) {
7212 /* Handle open failed - remove addition. */
7213 del_a_printer(printer->info_2->sharename);
7214 free_a_printer(&printer,2);
7215 ZERO_STRUCTP(handle);
7216 return WERR_ACCESS_DENIED;
7219 update_c_setprinter(false);
7220 free_a_printer(&printer,2);
7225 /****************************************************************
7226 _spoolss_AddPrinterEx
7227 ****************************************************************/
7229 WERROR _spoolss_AddPrinterEx(pipes_struct *p,
7230 struct spoolss_AddPrinterEx *r)
7232 switch (r->in.info_ctr->level) {
7234 /* we don't handle yet */
7235 /* but I know what to do ... */
7236 return WERR_UNKNOWN_LEVEL;
7238 return spoolss_addprinterex_level_2(p, r->in.server,
7240 r->in.devmode_ctr->devmode,
7241 r->in.secdesc_ctr->sd,
7242 r->in.userlevel_ctr,
7245 return WERR_UNKNOWN_LEVEL;
7249 /****************************************************************
7251 ****************************************************************/
7253 WERROR _spoolss_AddPrinter(pipes_struct *p,
7254 struct spoolss_AddPrinter *r)
7256 struct spoolss_AddPrinterEx a;
7257 struct spoolss_UserLevelCtr userlevel_ctr;
7259 ZERO_STRUCT(userlevel_ctr);
7261 userlevel_ctr.level = 1;
7263 a.in.server = r->in.server;
7264 a.in.info_ctr = r->in.info_ctr;
7265 a.in.devmode_ctr = r->in.devmode_ctr;
7266 a.in.secdesc_ctr = r->in.secdesc_ctr;
7267 a.in.userlevel_ctr = &userlevel_ctr;
7268 a.out.handle = r->out.handle;
7270 return _spoolss_AddPrinterEx(p, &a);
7273 /****************************************************************
7274 _spoolss_AddPrinterDriverEx
7275 ****************************************************************/
7277 WERROR _spoolss_AddPrinterDriverEx(pipes_struct *p,
7278 struct spoolss_AddPrinterDriverEx *r)
7280 WERROR err = WERR_OK;
7281 char *driver_name = NULL;
7286 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7287 fn = "_spoolss_AddPrinterDriver";
7289 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7290 fn = "_spoolss_AddPrinterDriverEx";
7293 return WERR_INVALID_PARAM;
7297 * we only support the semantics of AddPrinterDriver()
7298 * i.e. only copy files that are newer than existing ones
7301 if (r->in.flags == 0) {
7302 return WERR_INVALID_PARAM;
7305 if (r->in.flags != APD_COPY_NEW_FILES) {
7306 return WERR_ACCESS_DENIED;
7310 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7311 /* Clever hack from Martin Zielinski <mz@seh.de>
7312 * to allow downgrade from level 8 (Vista).
7314 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7315 r->in.info_ctr->level));
7316 return WERR_UNKNOWN_LEVEL;
7319 DEBUG(5,("Cleaning driver's information\n"));
7320 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
7321 if (!W_ERROR_IS_OK(err))
7324 DEBUG(5,("Moving driver to final destination\n"));
7325 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7330 if (add_a_printer_driver(p->mem_ctx, r->in.info_ctr, &driver_name, &version)!=0) {
7331 err = WERR_ACCESS_DENIED;
7336 * I think this is where he DrvUpgradePrinter() hook would be
7337 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7338 * server. Right now, we just need to send ourselves a message
7339 * to update each printer bound to this driver. --jerry
7342 if (!srv_spoolss_drv_upgrade_printer(driver_name)) {
7343 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7351 /****************************************************************
7352 _spoolss_AddPrinterDriver
7353 ****************************************************************/
7355 WERROR _spoolss_AddPrinterDriver(pipes_struct *p,
7356 struct spoolss_AddPrinterDriver *r)
7358 struct spoolss_AddPrinterDriverEx a;
7360 switch (r->in.info_ctr->level) {
7367 return WERR_UNKNOWN_LEVEL;
7370 a.in.servername = r->in.servername;
7371 a.in.info_ctr = r->in.info_ctr;
7372 a.in.flags = APD_COPY_NEW_FILES;
7374 return _spoolss_AddPrinterDriverEx(p, &a);
7377 /****************************************************************************
7378 ****************************************************************************/
7380 struct _spoolss_paths {
7386 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7388 static const struct _spoolss_paths spoolss_paths[]= {
7389 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7390 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7393 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7394 const char *servername,
7395 const char *environment,
7399 const char *pservername = NULL;
7400 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7401 const char *short_archi;
7405 /* environment may be empty */
7406 if (environment && strlen(environment)) {
7407 long_archi = environment;
7410 /* servername may be empty */
7411 if (servername && strlen(servername)) {
7412 pservername = canon_servername(servername);
7414 if (!is_myname_or_ipaddr(pservername)) {
7415 return WERR_INVALID_PARAM;
7419 if (!(short_archi = get_short_archi(long_archi))) {
7420 return WERR_INVALID_ENVIRONMENT;
7423 switch (component) {
7424 case SPOOLSS_PRTPROCS_PATH:
7425 case SPOOLSS_DRIVER_PATH:
7427 *path = talloc_asprintf(mem_ctx,
7430 spoolss_paths[component].share,
7433 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7434 SPOOLSS_DEFAULT_SERVER_PATH,
7435 spoolss_paths[component].dir,
7440 return WERR_INVALID_PARAM;
7450 /****************************************************************************
7451 ****************************************************************************/
7453 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7454 const char *servername,
7455 const char *environment,
7456 struct spoolss_DriverDirectoryInfo1 *r)
7461 werr = compose_spoolss_server_path(mem_ctx,
7464 SPOOLSS_DRIVER_PATH,
7466 if (!W_ERROR_IS_OK(werr)) {
7470 DEBUG(4,("printer driver directory: [%s]\n", path));
7472 r->directory_name = path;
7477 /****************************************************************
7478 _spoolss_GetPrinterDriverDirectory
7479 ****************************************************************/
7481 WERROR _spoolss_GetPrinterDriverDirectory(pipes_struct *p,
7482 struct spoolss_GetPrinterDriverDirectory *r)
7486 /* that's an [in out] buffer */
7488 if (!r->in.buffer && (r->in.offered != 0)) {
7489 return WERR_INVALID_PARAM;
7492 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
7497 /* r->in.level is ignored */
7499 werror = getprinterdriverdir_level_1(p->mem_ctx,
7502 &r->out.info->info1);
7503 if (!W_ERROR_IS_OK(werror)) {
7504 TALLOC_FREE(r->out.info);
7508 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
7509 r->out.info, r->in.level);
7510 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7512 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7515 /****************************************************************
7516 _spoolss_EnumPrinterData
7517 ****************************************************************/
7519 WERROR _spoolss_EnumPrinterData(pipes_struct *p,
7520 struct spoolss_EnumPrinterData *r)
7523 struct spoolss_EnumPrinterDataEx r2;
7525 struct spoolss_PrinterEnumValues *info, *val = NULL;
7528 r2.in.handle = r->in.handle;
7529 r2.in.key_name = "PrinterDriverData";
7531 r2.out.count = &count;
7532 r2.out.info = &info;
7533 r2.out.needed = &needed;
7535 result = _spoolss_EnumPrinterDataEx(p, &r2);
7536 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
7537 r2.in.offered = needed;
7538 result = _spoolss_EnumPrinterDataEx(p, &r2);
7540 if (!W_ERROR_IS_OK(result)) {
7545 * The NT machine wants to know the biggest size of value and data
7547 * cf: MSDN EnumPrinterData remark section
7550 if (!r->in.value_offered && !r->in.data_offered) {
7551 uint32_t biggest_valuesize = 0;
7552 uint32_t biggest_datasize = 0;
7555 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
7557 for (i=0; i<count; i++) {
7559 name_length = strlen(info[i].value_name);
7560 if (strlen(info[i].value_name) > biggest_valuesize) {
7561 biggest_valuesize = name_length;
7564 if (info[i].data_length > biggest_datasize) {
7565 biggest_datasize = info[i].data_length;
7568 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
7572 /* the value is an UNICODE string but real_value_size is the length
7573 in bytes including the trailing 0 */
7575 *r->out.value_needed = 2 * (1 + biggest_valuesize);
7576 *r->out.data_needed = biggest_datasize;
7578 DEBUG(6,("final values: [%d], [%d]\n",
7579 *r->out.value_needed, *r->out.data_needed));
7584 if (r->in.enum_index < count) {
7585 val = &info[r->in.enum_index];
7589 /* out_value should default to "" or else NT4 has
7590 problems unmarshalling the response */
7592 if (r->in.value_offered) {
7593 *r->out.value_needed = 1;
7594 r->out.value_name = talloc_strdup(r, "");
7595 if (!r->out.value_name) {
7599 r->out.value_name = NULL;
7600 *r->out.value_needed = 0;
7603 /* the data is counted in bytes */
7605 *r->out.data_needed = r->in.data_offered;
7607 result = WERR_NO_MORE_ITEMS;
7611 * - counted in bytes in the request
7612 * - counted in UNICODE chars in the max reply
7613 * - counted in bytes in the real size
7615 * take a pause *before* coding not *during* coding
7619 if (r->in.value_offered) {
7620 r->out.value_name = talloc_strdup(r, val->value_name);
7621 if (!r->out.value_name) {
7624 *r->out.value_needed = val->value_name_len;
7626 r->out.value_name = NULL;
7627 *r->out.value_needed = 0;
7632 *r->out.type = val->type;
7634 /* data - counted in bytes */
7637 * See the section "Dynamically Typed Query Parameters"
7641 if (r->out.data && val->data && val->data->data &&
7642 val->data_length && r->in.data_offered) {
7643 memcpy(r->out.data, val->data->data,
7644 MIN(val->data_length,r->in.data_offered));
7647 *r->out.data_needed = val->data_length;
7655 /****************************************************************
7656 _spoolss_SetPrinterData
7657 ****************************************************************/
7659 WERROR _spoolss_SetPrinterData(pipes_struct *p,
7660 struct spoolss_SetPrinterData *r)
7662 struct spoolss_SetPrinterDataEx r2;
7664 r2.in.handle = r->in.handle;
7665 r2.in.key_name = "PrinterDriverData";
7666 r2.in.value_name = r->in.value_name;
7667 r2.in.type = r->in.type;
7668 r2.in.data = r->in.data;
7669 r2.in.offered = r->in.offered;
7671 return _spoolss_SetPrinterDataEx(p, &r2);
7674 /****************************************************************
7675 _spoolss_ResetPrinter
7676 ****************************************************************/
7678 WERROR _spoolss_ResetPrinter(pipes_struct *p,
7679 struct spoolss_ResetPrinter *r)
7681 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7684 DEBUG(5,("_spoolss_ResetPrinter\n"));
7687 * All we do is to check to see if the handle and queue is valid.
7688 * This call really doesn't mean anything to us because we only
7689 * support RAW printing. --jerry
7693 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
7694 OUR_HANDLE(r->in.handle)));
7698 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
7702 /* blindly return success */
7706 /****************************************************************
7707 _spoolss_DeletePrinterData
7708 ****************************************************************/
7710 WERROR _spoolss_DeletePrinterData(pipes_struct *p,
7711 struct spoolss_DeletePrinterData *r)
7713 struct spoolss_DeletePrinterDataEx r2;
7715 r2.in.handle = r->in.handle;
7716 r2.in.key_name = "PrinterDriverData";
7717 r2.in.value_name = r->in.value_name;
7719 return _spoolss_DeletePrinterDataEx(p, &r2);
7722 /****************************************************************
7724 ****************************************************************/
7726 WERROR _spoolss_AddForm(pipes_struct *p,
7727 struct spoolss_AddForm *r)
7729 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
7730 nt_forms_struct tmpForm;
7732 WERROR status = WERR_OK;
7733 NT_PRINTER_INFO_LEVEL *printer = NULL;
7734 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7737 nt_forms_struct *list=NULL;
7738 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7741 DEBUG(5,("_spoolss_AddForm\n"));
7744 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
7745 OUR_HANDLE(r->in.handle)));
7750 /* forms can be added on printer or on the print server handle */
7752 if ( Printer->printer_type == SPLHND_PRINTER )
7754 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
7757 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
7758 if (!W_ERROR_IS_OK(status))
7762 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
7763 and not a printer admin, then fail */
7765 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7766 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7767 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7768 p->server_info->info3->base.domain.string,
7770 p->server_info->ptok,
7771 lp_printer_admin(snum))) {
7772 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
7773 status = WERR_ACCESS_DENIED;
7777 switch (form->flags) {
7778 case SPOOLSS_FORM_USER:
7779 case SPOOLSS_FORM_BUILTIN:
7780 case SPOOLSS_FORM_PRINTER:
7783 status = WERR_INVALID_PARAM;
7787 /* can't add if builtin */
7789 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
7790 status = WERR_FILE_EXISTS;
7794 count = get_ntforms(&list);
7796 for (i=0; i < count; i++) {
7797 if (strequal(form->form_name, list[i].name)) {
7798 status = WERR_FILE_EXISTS;
7803 if(!add_a_form(&list, form, &count)) {
7804 status = WERR_NOMEM;
7809 write_ntforms(&list, count);
7813 * ChangeID must always be set if this is a printer
7816 if ( Printer->printer_type == SPLHND_PRINTER )
7817 status = mod_a_printer(printer, 2);
7821 free_a_printer(&printer, 2);
7827 /****************************************************************
7829 ****************************************************************/
7831 WERROR _spoolss_DeleteForm(pipes_struct *p,
7832 struct spoolss_DeleteForm *r)
7834 const char *form_name = r->in.form_name;
7835 nt_forms_struct tmpForm;
7837 nt_forms_struct *list=NULL;
7838 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7840 WERROR status = WERR_OK;
7841 NT_PRINTER_INFO_LEVEL *printer = NULL;
7842 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7845 DEBUG(5,("_spoolss_DeleteForm\n"));
7848 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
7849 OUR_HANDLE(r->in.handle)));
7853 /* forms can be deleted on printer of on the print server handle */
7855 if ( Printer->printer_type == SPLHND_PRINTER )
7857 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
7860 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
7861 if (!W_ERROR_IS_OK(status))
7865 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7866 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7867 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7868 p->server_info->info3->base.domain.string,
7870 p->server_info->ptok,
7871 lp_printer_admin(snum))) {
7872 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
7873 return WERR_ACCESS_DENIED;
7877 /* can't delete if builtin */
7879 if (get_a_builtin_ntform_by_string(form_name,&tmpForm)) {
7880 status = WERR_INVALID_PARAM;
7884 count = get_ntforms(&list);
7887 ret = delete_a_form(&list, form_name, &count, &status);
7894 * ChangeID must always be set if this is a printer
7897 if ( Printer->printer_type == SPLHND_PRINTER )
7898 status = mod_a_printer(printer, 2);
7902 free_a_printer(&printer, 2);
7908 /****************************************************************
7910 ****************************************************************/
7912 WERROR _spoolss_SetForm(pipes_struct *p,
7913 struct spoolss_SetForm *r)
7915 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
7916 nt_forms_struct tmpForm;
7918 WERROR status = WERR_OK;
7919 NT_PRINTER_INFO_LEVEL *printer = NULL;
7920 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7923 nt_forms_struct *list=NULL;
7924 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7926 DEBUG(5,("_spoolss_SetForm\n"));
7929 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
7930 OUR_HANDLE(r->in.handle)));
7934 /* forms can be modified on printer of on the print server handle */
7936 if ( Printer->printer_type == SPLHND_PRINTER )
7938 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
7941 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
7942 if (!W_ERROR_IS_OK(status))
7946 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
7947 and not a printer admin, then fail */
7949 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7950 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7951 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7952 p->server_info->info3->base.domain.string,
7954 p->server_info->ptok,
7955 lp_printer_admin(snum))) {
7956 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
7957 status = WERR_ACCESS_DENIED;
7961 /* can't set if builtin */
7962 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
7963 status = WERR_INVALID_PARAM;
7967 count = get_ntforms(&list);
7968 update_a_form(&list, form, count);
7970 write_ntforms(&list, count);
7974 * ChangeID must always be set if this is a printer
7977 if ( Printer->printer_type == SPLHND_PRINTER )
7978 status = mod_a_printer(printer, 2);
7983 free_a_printer(&printer, 2);
7989 /****************************************************************************
7990 fill_print_processor1
7991 ****************************************************************************/
7993 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
7994 struct spoolss_PrintProcessorInfo1 *r,
7995 const char *print_processor_name)
7997 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
7998 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8003 /****************************************************************************
8004 enumprintprocessors level 1.
8005 ****************************************************************************/
8007 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8008 union spoolss_PrintProcessorInfo **info_p,
8011 union spoolss_PrintProcessorInfo *info;
8014 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8015 W_ERROR_HAVE_NO_MEMORY(info);
8019 result = fill_print_processor1(info, &info[0].info1, "winprint");
8020 if (!W_ERROR_IS_OK(result)) {
8025 if (!W_ERROR_IS_OK(result)) {
8036 /****************************************************************
8037 _spoolss_EnumPrintProcessors
8038 ****************************************************************/
8040 WERROR _spoolss_EnumPrintProcessors(pipes_struct *p,
8041 struct spoolss_EnumPrintProcessors *r)
8045 /* that's an [in out] buffer */
8047 if (!r->in.buffer && (r->in.offered != 0)) {
8048 return WERR_INVALID_PARAM;
8051 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8054 * Enumerate the print processors ...
8056 * Just reply with "winprint", to keep NT happy
8057 * and I can use my nice printer checker.
8062 *r->out.info = NULL;
8064 switch (r->in.level) {
8066 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8070 return WERR_UNKNOWN_LEVEL;
8073 if (!W_ERROR_IS_OK(result)) {
8077 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8078 spoolss_EnumPrintProcessors,
8079 *r->out.info, r->in.level,
8081 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8082 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8084 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8087 /****************************************************************************
8088 fill_printprocdatatype1
8089 ****************************************************************************/
8091 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8092 struct spoolss_PrintProcDataTypesInfo1 *r,
8093 const char *name_array)
8095 r->name_array = talloc_strdup(mem_ctx, name_array);
8096 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8101 /****************************************************************************
8102 enumprintprocdatatypes level 1.
8103 ****************************************************************************/
8105 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8106 union spoolss_PrintProcDataTypesInfo **info_p,
8110 union spoolss_PrintProcDataTypesInfo *info;
8112 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8113 W_ERROR_HAVE_NO_MEMORY(info);
8117 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8118 if (!W_ERROR_IS_OK(result)) {
8123 if (!W_ERROR_IS_OK(result)) {
8134 /****************************************************************
8135 _spoolss_EnumPrintProcDataTypes
8136 ****************************************************************/
8138 WERROR _spoolss_EnumPrintProcDataTypes(pipes_struct *p,
8139 struct spoolss_EnumPrintProcDataTypes *r)
8143 /* that's an [in out] buffer */
8145 if (!r->in.buffer && (r->in.offered != 0)) {
8146 return WERR_INVALID_PARAM;
8149 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8153 *r->out.info = NULL;
8155 switch (r->in.level) {
8157 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8161 return WERR_UNKNOWN_LEVEL;
8164 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8165 spoolss_EnumPrintProcDataTypes,
8166 *r->out.info, r->in.level,
8168 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8169 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8171 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8174 /****************************************************************************
8176 ****************************************************************************/
8178 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8179 struct spoolss_MonitorInfo1 *r,
8180 const char *monitor_name)
8182 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8183 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8188 /****************************************************************************
8190 ****************************************************************************/
8192 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8193 struct spoolss_MonitorInfo2 *r,
8194 const char *monitor_name,
8195 const char *environment,
8196 const char *dll_name)
8198 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8199 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8200 r->environment = talloc_strdup(mem_ctx, environment);
8201 W_ERROR_HAVE_NO_MEMORY(r->environment);
8202 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8203 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8208 /****************************************************************************
8209 enumprintmonitors level 1.
8210 ****************************************************************************/
8212 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8213 union spoolss_MonitorInfo **info_p,
8216 union spoolss_MonitorInfo *info;
8217 WERROR result = WERR_OK;
8219 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8220 W_ERROR_HAVE_NO_MEMORY(info);
8224 result = fill_monitor_1(info, &info[0].info1,
8226 if (!W_ERROR_IS_OK(result)) {
8230 result = fill_monitor_1(info, &info[1].info1,
8232 if (!W_ERROR_IS_OK(result)) {
8237 if (!W_ERROR_IS_OK(result)) {
8248 /****************************************************************************
8249 enumprintmonitors level 2.
8250 ****************************************************************************/
8252 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8253 union spoolss_MonitorInfo **info_p,
8256 union spoolss_MonitorInfo *info;
8257 WERROR result = WERR_OK;
8259 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8260 W_ERROR_HAVE_NO_MEMORY(info);
8264 result = fill_monitor_2(info, &info[0].info2,
8266 "Windows NT X86", /* FIXME */
8268 if (!W_ERROR_IS_OK(result)) {
8272 result = fill_monitor_2(info, &info[1].info2,
8274 "Windows NT X86", /* FIXME */
8276 if (!W_ERROR_IS_OK(result)) {
8281 if (!W_ERROR_IS_OK(result)) {
8292 /****************************************************************
8293 _spoolss_EnumMonitors
8294 ****************************************************************/
8296 WERROR _spoolss_EnumMonitors(pipes_struct *p,
8297 struct spoolss_EnumMonitors *r)
8301 /* that's an [in out] buffer */
8303 if (!r->in.buffer && (r->in.offered != 0)) {
8304 return WERR_INVALID_PARAM;
8307 DEBUG(5,("_spoolss_EnumMonitors\n"));
8310 * Enumerate the print monitors ...
8312 * Just reply with "Local Port", to keep NT happy
8313 * and I can use my nice printer checker.
8318 *r->out.info = NULL;
8320 switch (r->in.level) {
8322 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8326 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8330 return WERR_UNKNOWN_LEVEL;
8333 if (!W_ERROR_IS_OK(result)) {
8337 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8338 spoolss_EnumMonitors,
8339 *r->out.info, r->in.level,
8341 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8342 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8344 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8347 /****************************************************************************
8348 ****************************************************************************/
8350 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8351 const print_queue_struct *queue,
8352 int count, int snum,
8353 const NT_PRINTER_INFO_LEVEL *ntprinter,
8355 struct spoolss_JobInfo1 *r)
8360 for (i=0; i<count; i++) {
8361 if (queue[i].job == (int)jobid) {
8367 if (found == false) {
8368 /* NT treats not found as bad param... yet another bad choice */
8369 return WERR_INVALID_PARAM;
8372 return fill_job_info1(mem_ctx,
8380 /****************************************************************************
8381 ****************************************************************************/
8383 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8384 const print_queue_struct *queue,
8385 int count, int snum,
8386 const NT_PRINTER_INFO_LEVEL *ntprinter,
8388 struct spoolss_JobInfo2 *r)
8392 struct spoolss_DeviceMode *devmode;
8394 for (i=0; i<count; i++) {
8395 if (queue[i].job == (int)jobid) {
8401 if (found == false) {
8402 /* NT treats not found as bad param... yet another bad
8404 return WERR_INVALID_PARAM;
8408 * if the print job does not have a DEVMODE associated with it,
8409 * just use the one for the printer. A NULL devicemode is not
8410 * a failure condition
8413 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8415 devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
8416 W_ERROR_HAVE_NO_MEMORY(devmode);
8419 return fill_job_info2(mem_ctx,
8428 /****************************************************************
8430 ****************************************************************/
8432 WERROR _spoolss_GetJob(pipes_struct *p,
8433 struct spoolss_GetJob *r)
8435 WERROR result = WERR_OK;
8436 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
8439 print_queue_struct *queue = NULL;
8440 print_status_struct prt_status;
8442 /* that's an [in out] buffer */
8444 if (!r->in.buffer && (r->in.offered != 0)) {
8445 return WERR_INVALID_PARAM;
8448 DEBUG(5,("_spoolss_GetJob\n"));
8452 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8456 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
8457 if (!W_ERROR_IS_OK(result)) {
8461 count = print_queue_status(snum, &queue, &prt_status);
8463 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8464 count, prt_status.status, prt_status.message));
8466 switch (r->in.level) {
8468 result = getjob_level_1(p->mem_ctx,
8469 queue, count, snum, ntprinter,
8470 r->in.job_id, &r->out.info->info1);
8473 result = getjob_level_2(p->mem_ctx,
8474 queue, count, snum, ntprinter,
8475 r->in.job_id, &r->out.info->info2);
8478 result = WERR_UNKNOWN_LEVEL;
8483 free_a_printer(&ntprinter, 2);
8485 if (!W_ERROR_IS_OK(result)) {
8486 TALLOC_FREE(r->out.info);
8490 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
8492 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8494 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8497 /****************************************************************
8498 _spoolss_GetPrinterDataEx
8499 ****************************************************************/
8501 WERROR _spoolss_GetPrinterDataEx(pipes_struct *p,
8502 struct spoolss_GetPrinterDataEx *r)
8505 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8506 struct regval_blob *val = NULL;
8507 NT_PRINTER_INFO_LEVEL *printer = NULL;
8509 WERROR result = WERR_OK;
8512 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8514 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8515 r->in.key_name, r->in.value_name));
8517 /* in case of problem, return some default values */
8520 *r->out.type = REG_NONE;
8523 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8524 OUR_HANDLE(r->in.handle)));
8525 result = WERR_BADFID;
8529 /* Is the handle to a printer or to the server? */
8531 if (Printer->printer_type == SPLHND_SERVER) {
8533 union spoolss_PrinterData data;
8535 result = getprinterdata_printer_server(p->mem_ctx,
8539 if (!W_ERROR_IS_OK(result)) {
8543 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
8544 *r->out.type, &data);
8545 if (!W_ERROR_IS_OK(result)) {
8549 *r->out.needed = blob.length;
8551 if (r->in.offered >= *r->out.needed) {
8552 memcpy(r->out.data, blob.data, blob.length);
8555 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8558 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8559 result = WERR_BADFID;
8563 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
8564 if (!W_ERROR_IS_OK(result)) {
8568 /* check to see if the keyname is valid */
8569 if (!strlen(r->in.key_name)) {
8570 result = WERR_INVALID_PARAM;
8574 /* XP sends this and wants to change id value from the PRINTER_INFO_0 */
8576 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
8577 strequal(r->in.value_name, "ChangeId")) {
8578 *r->out.type = REG_DWORD;
8580 if (r->in.offered >= *r->out.needed) {
8581 SIVAL(r->out.data, 0, printer->info_2->changeid);
8587 if (lookup_printerkey(printer->info_2->data, r->in.key_name) == -1) {
8588 DEBUG(4,("_spoolss_GetPrinterDataEx: "
8589 "Invalid keyname [%s]\n", r->in.key_name ));
8590 result = WERR_BADFILE;
8594 val = get_printer_data(printer->info_2,
8595 r->in.key_name, r->in.value_name);
8597 result = WERR_BADFILE;
8601 *r->out.needed = regval_size(val);
8602 *r->out.type = regval_type(val);
8604 if (r->in.offered >= *r->out.needed) {
8605 memcpy(r->out.data, regval_data_p(val), regval_size(val));
8609 free_a_printer(&printer, 2);
8612 if (!W_ERROR_IS_OK(result)) {
8616 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
8617 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
8619 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8622 /****************************************************************
8623 _spoolss_SetPrinterDataEx
8624 ****************************************************************/
8626 WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
8627 struct spoolss_SetPrinterDataEx *r)
8629 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8631 WERROR result = WERR_OK;
8632 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8635 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
8637 /* From MSDN documentation of SetPrinterDataEx: pass request to
8638 SetPrinterData if key is "PrinterDriverData" */
8641 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8642 OUR_HANDLE(r->in.handle)));
8646 if (Printer->printer_type == SPLHND_SERVER) {
8647 DEBUG(10,("_spoolss_SetPrinterDataEx: "
8648 "Not implemented for server handles yet\n"));
8649 return WERR_INVALID_PARAM;
8652 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8657 * Access check : NT returns "access denied" if you make a
8658 * SetPrinterData call without the necessary privildge.
8659 * we were originally returning OK if nothing changed
8660 * which made Win2k issue **a lot** of SetPrinterData
8661 * when connecting to a printer --jerry
8664 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8665 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
8666 "change denied by handle access permissions\n"));
8667 return WERR_ACCESS_DENIED;
8670 result = winreg_get_printer(Printer, p->server_info,
8671 Printer->servername,
8672 lp_servicename(snum),
8674 if (!W_ERROR_IS_OK(result)) {
8678 /* check for OID in valuename */
8680 oid_string = strchr(r->in.value_name, ',');
8686 /* save the registry data */
8688 result = winreg_set_printer_dataex(p->mem_ctx,
8697 if (W_ERROR_IS_OK(result)) {
8698 /* save the OID if one was specified */
8700 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
8701 r->in.key_name, SPOOL_OID_KEY);
8703 result = WERR_NOMEM;
8708 * I'm not checking the status here on purpose. Don't know
8709 * if this is right, but I'm returning the status from the
8710 * previous set_printer_dataex() call. I have no idea if
8711 * this is right. --jerry
8713 winreg_set_printer_dataex(p->mem_ctx,
8719 (uint8_t *) oid_string,
8720 strlen(oid_string) + 1);
8723 result = winreg_printer_update_changeid(p->mem_ctx,
8725 lp_const_servicename(snum));
8730 talloc_free(pinfo2);
8734 /****************************************************************
8735 _spoolss_DeletePrinterDataEx
8736 ****************************************************************/
8738 WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
8739 struct spoolss_DeletePrinterDataEx *r)
8741 NT_PRINTER_INFO_LEVEL *printer = NULL;
8743 WERROR status = WERR_OK;
8744 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8746 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
8749 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
8750 "Invalid handle (%s:%u:%u).\n",
8751 OUR_HANDLE(r->in.handle)));
8755 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8758 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8759 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
8760 "printer properties change denied by handle\n"));
8761 return WERR_ACCESS_DENIED;
8764 if (!r->in.value_name || !r->in.key_name) {
8768 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8769 if (!W_ERROR_IS_OK(status))
8772 status = delete_printer_dataex( printer, r->in.key_name, r->in.value_name );
8774 if ( W_ERROR_IS_OK(status) )
8775 mod_a_printer( printer, 2 );
8777 free_a_printer(&printer, 2);
8782 /****************************************************************
8783 _spoolss_EnumPrinterKey
8784 ****************************************************************/
8786 WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
8787 struct spoolss_EnumPrinterKey *r)
8789 fstring *keynames = NULL;
8791 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8792 NT_PRINTER_DATA *data;
8793 NT_PRINTER_INFO_LEVEL *printer = NULL;
8795 WERROR result = WERR_BADFILE;
8797 const char **array = NULL;
8800 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
8803 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
8804 OUR_HANDLE(r->in.handle)));
8808 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8812 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8813 if (!W_ERROR_IS_OK(result)) {
8817 /* get the list of subkey names */
8819 data = printer->info_2->data;
8821 num_keys = get_printer_subkeys(data, r->in.key_name, &keynames);
8822 if (num_keys == -1) {
8823 result = WERR_BADFILE;
8827 array = talloc_zero_array(r->out.key_buffer, const char *, num_keys + 2);
8829 result = WERR_NOMEM;
8834 array[0] = talloc_strdup(array, "");
8836 result = WERR_NOMEM;
8841 for (i=0; i < num_keys; i++) {
8843 DEBUG(10,("_spoolss_EnumPrinterKey: adding keyname: %s\n",
8846 array[i] = talloc_strdup(array, keynames[i]);
8848 result = WERR_NOMEM;
8853 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
8854 result = WERR_NOMEM;
8858 *r->out._ndr_size = r->in.offered / 2;
8859 *r->out.needed = blob.length;
8861 if (r->in.offered < *r->out.needed) {
8862 result = WERR_MORE_DATA;
8865 r->out.key_buffer->string_array = array;
8869 if (!W_ERROR_IS_OK(result)) {
8871 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8876 free_a_printer(&printer, 2);
8877 SAFE_FREE(keynames);
8882 /****************************************************************
8883 _spoolss_DeletePrinterKey
8884 ****************************************************************/
8886 WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
8887 struct spoolss_DeletePrinterKey *r)
8889 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8890 NT_PRINTER_INFO_LEVEL *printer = NULL;
8894 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
8897 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
8898 OUR_HANDLE(r->in.handle)));
8902 /* if keyname == NULL, return error */
8904 if ( !r->in.key_name )
8905 return WERR_INVALID_PARAM;
8907 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8910 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8911 DEBUG(3, ("_spoolss_DeletePrinterKey: "
8912 "printer properties change denied by handle\n"));
8913 return WERR_ACCESS_DENIED;
8916 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8917 if (!W_ERROR_IS_OK(status))
8920 /* delete the key and all subneys */
8922 status = delete_all_printer_data( printer->info_2, r->in.key_name );
8924 if ( W_ERROR_IS_OK(status) )
8925 status = mod_a_printer(printer, 2);
8927 free_a_printer( &printer, 2 );
8932 /****************************************************************
8933 ****************************************************************/
8935 static WERROR registry_value_to_printer_enum_value(TALLOC_CTX *mem_ctx,
8936 struct regval_blob *v,
8937 struct spoolss_PrinterEnumValues *r)
8939 r->data = TALLOC_ZERO_P(mem_ctx, DATA_BLOB);
8940 W_ERROR_HAVE_NO_MEMORY(r->data);
8942 r->value_name = talloc_strdup(mem_ctx, regval_name(v));
8943 W_ERROR_HAVE_NO_MEMORY(r->value_name);
8945 r->value_name_len = strlen_m_term(regval_name(v)) * 2;
8947 r->type = regval_type(v);
8948 r->data_length = regval_size(v);
8950 if (r->data_length) {
8951 *r->data = data_blob_talloc(r->data, regval_data_p(v), regval_size(v));
8957 /****************************************************************
8958 _spoolss_EnumPrinterDataEx
8959 ****************************************************************/
8961 WERROR _spoolss_EnumPrinterDataEx(pipes_struct *p,
8962 struct spoolss_EnumPrinterDataEx *r)
8965 NT_PRINTER_INFO_LEVEL *printer = NULL;
8966 struct spoolss_PrinterEnumValues *info = NULL;
8967 NT_PRINTER_DATA *p_data;
8968 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8974 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
8978 *r->out.info = NULL;
8981 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
8982 OUR_HANDLE(r->in.handle)));
8987 * first check for a keyname of NULL or "". Win2k seems to send
8988 * this a lot and we should send back WERR_INVALID_PARAM
8989 * no need to spend time looking up the printer in this case.
8993 if (!strlen(r->in.key_name)) {
8994 result = WERR_INVALID_PARAM;
8998 /* get the printer off of disk */
9000 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9004 ZERO_STRUCT(printer);
9005 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9006 if (!W_ERROR_IS_OK(result)) {
9010 /* now look for a match on the key name */
9012 p_data = printer->info_2->data;
9014 key_index = lookup_printerkey(p_data, r->in.key_name);
9015 if (key_index == -1) {
9016 DEBUG(10,("_spoolss_EnumPrinterDataEx: Unknown keyname [%s]\n",
9018 result = WERR_INVALID_PARAM;
9022 /* allocate the memory for the array of pointers -- if necessary */
9024 count = regval_ctr_numvals(p_data->keys[key_index].values);
9026 result = WERR_OK; /* ??? */
9030 info = TALLOC_ZERO_ARRAY(p->mem_ctx,
9031 struct spoolss_PrinterEnumValues,
9034 DEBUG(0,("_spoolss_EnumPrinterDataEx: talloc() failed\n"));
9035 result = WERR_NOMEM;
9040 * loop through all params and build the array to pass
9041 * back to the client
9044 for (i=0; i < count; i++) {
9046 struct regval_blob *val;
9048 /* lookup the registry value */
9050 val = regval_ctr_specific_value(p_data->keys[key_index].values, i);
9052 DEBUG(10,("retrieved value number [%d] [%s]\n", i, regval_name(val)));
9056 result = registry_value_to_printer_enum_value(info, val, &info[i]);
9057 if (!W_ERROR_IS_OK(result)) {
9062 #if 0 /* FIXME - gd */
9063 /* housekeeping information in the reply */
9065 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9066 * the hand marshalled container size is a multiple
9067 * of 4 bytes for RPC alignment.
9071 needed += 4-(needed % 4);
9074 *r->out.count = count;
9075 *r->out.info = info;
9080 free_a_printer(&printer, 2);
9083 if (!W_ERROR_IS_OK(result)) {
9087 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9088 spoolss_EnumPrinterDataEx,
9091 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9092 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9094 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9097 /****************************************************************************
9098 ****************************************************************************/
9100 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9101 const char *servername,
9102 const char *environment,
9103 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9108 werr = compose_spoolss_server_path(mem_ctx,
9111 SPOOLSS_PRTPROCS_PATH,
9113 if (!W_ERROR_IS_OK(werr)) {
9117 DEBUG(4,("print processor directory: [%s]\n", path));
9119 r->directory_name = path;
9124 /****************************************************************
9125 _spoolss_GetPrintProcessorDirectory
9126 ****************************************************************/
9128 WERROR _spoolss_GetPrintProcessorDirectory(pipes_struct *p,
9129 struct spoolss_GetPrintProcessorDirectory *r)
9133 /* that's an [in out] buffer */
9135 if (!r->in.buffer && (r->in.offered != 0)) {
9136 return WERR_INVALID_PARAM;
9139 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9144 /* r->in.level is ignored */
9146 /* We always should reply with a local print processor directory so that
9147 * users are not forced to have a [prnproc$] share on the Samba spoolss
9148 * server - Guenther */
9150 result = getprintprocessordirectory_level_1(p->mem_ctx,
9151 NULL, /* r->in.server */
9153 &r->out.info->info1);
9154 if (!W_ERROR_IS_OK(result)) {
9155 TALLOC_FREE(r->out.info);
9159 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9160 r->out.info, r->in.level);
9161 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9163 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9166 /*******************************************************************
9167 ********************************************************************/
9169 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9170 const char *dllname)
9172 enum ndr_err_code ndr_err;
9173 struct spoolss_MonitorUi ui;
9175 ui.dll_name = dllname;
9177 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9178 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9179 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9180 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9182 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9185 /*******************************************************************
9186 Streams the monitor UI DLL name in UNICODE
9187 *******************************************************************/
9189 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9190 NT_USER_TOKEN *token, DATA_BLOB *in,
9191 DATA_BLOB *out, uint32_t *needed)
9193 const char *dllname = "tcpmonui.dll";
9195 *needed = (strlen(dllname)+1) * 2;
9197 if (out->length < *needed) {
9198 return WERR_INSUFFICIENT_BUFFER;
9201 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9208 /*******************************************************************
9209 ********************************************************************/
9211 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9212 struct spoolss_PortData1 *port1,
9213 const DATA_BLOB *buf)
9215 enum ndr_err_code ndr_err;
9216 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9217 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9218 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9219 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9221 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9224 /*******************************************************************
9225 ********************************************************************/
9227 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9228 struct spoolss_PortData2 *port2,
9229 const DATA_BLOB *buf)
9231 enum ndr_err_code ndr_err;
9232 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9233 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9234 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9235 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9237 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9240 /*******************************************************************
9241 Create a new TCP/IP port
9242 *******************************************************************/
9244 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9245 NT_USER_TOKEN *token, DATA_BLOB *in,
9246 DATA_BLOB *out, uint32_t *needed)
9248 struct spoolss_PortData1 port1;
9249 struct spoolss_PortData2 port2;
9250 char *device_uri = NULL;
9253 const char *portname;
9254 const char *hostaddress;
9256 uint32_t port_number;
9259 /* peek for spoolss_PortData version */
9261 if (!in || (in->length < (128 + 4))) {
9262 return WERR_GENERAL_FAILURE;
9265 version = IVAL(in->data, 128);
9271 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9275 portname = port1.portname;
9276 hostaddress = port1.hostaddress;
9277 queue = port1.queue;
9278 protocol = port1.protocol;
9279 port_number = port1.port_number;
9285 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9289 portname = port2.portname;
9290 hostaddress = port2.hostaddress;
9291 queue = port2.queue;
9292 protocol = port2.protocol;
9293 port_number = port2.port_number;
9297 DEBUG(1,("xcvtcp_addport: "
9298 "unknown version of port_data: %d\n", version));
9299 return WERR_UNKNOWN_PORT;
9302 /* create the device URI and call the add_port_hook() */
9305 case PROTOCOL_RAWTCP_TYPE:
9306 device_uri = talloc_asprintf(mem_ctx,
9307 "socket://%s:%d/", hostaddress,
9311 case PROTOCOL_LPR_TYPE:
9312 device_uri = talloc_asprintf(mem_ctx,
9313 "lpr://%s/%s", hostaddress, queue );
9317 return WERR_UNKNOWN_PORT;
9324 return add_port_hook(mem_ctx, token, portname, device_uri);
9327 /*******************************************************************
9328 *******************************************************************/
9330 struct xcv_api_table xcvtcp_cmds[] = {
9331 { "MonitorUI", xcvtcp_monitorui },
9332 { "AddPort", xcvtcp_addport},
9336 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9337 NT_USER_TOKEN *token, const char *command,
9344 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9346 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9347 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9348 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9351 return WERR_BADFUNC;
9354 /*******************************************************************
9355 *******************************************************************/
9356 #if 0 /* don't support management using the "Local Port" monitor */
9358 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9359 NT_USER_TOKEN *token, DATA_BLOB *in,
9360 DATA_BLOB *out, uint32_t *needed)
9362 const char *dllname = "localui.dll";
9364 *needed = (strlen(dllname)+1) * 2;
9366 if (out->length < *needed) {
9367 return WERR_INSUFFICIENT_BUFFER;
9370 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9377 /*******************************************************************
9378 *******************************************************************/
9380 struct xcv_api_table xcvlocal_cmds[] = {
9381 { "MonitorUI", xcvlocal_monitorui },
9385 struct xcv_api_table xcvlocal_cmds[] = {
9392 /*******************************************************************
9393 *******************************************************************/
9395 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9396 NT_USER_TOKEN *token, const char *command,
9397 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9402 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9404 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9405 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9406 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9408 return WERR_BADFUNC;
9411 /****************************************************************
9413 ****************************************************************/
9415 WERROR _spoolss_XcvData(pipes_struct *p,
9416 struct spoolss_XcvData *r)
9418 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9419 DATA_BLOB out_data = data_blob_null;
9423 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9424 OUR_HANDLE(r->in.handle)));
9428 /* Has to be a handle to the TCP/IP port monitor */
9430 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9431 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9435 /* requires administrative access to the server */
9437 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9438 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9439 return WERR_ACCESS_DENIED;
9442 /* Allocate the outgoing buffer */
9444 if (r->in.out_data_size) {
9445 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9446 if (out_data.data == NULL) {
9451 switch ( Printer->printer_type ) {
9452 case SPLHND_PORTMON_TCP:
9453 werror = process_xcvtcp_command(p->mem_ctx,
9454 p->server_info->ptok,
9455 r->in.function_name,
9456 &r->in.in_data, &out_data,
9459 case SPLHND_PORTMON_LOCAL:
9460 werror = process_xcvlocal_command(p->mem_ctx,
9461 p->server_info->ptok,
9462 r->in.function_name,
9463 &r->in.in_data, &out_data,
9467 werror = WERR_INVALID_PRINT_MONITOR;
9470 if (!W_ERROR_IS_OK(werror)) {
9474 *r->out.status_code = 0;
9476 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9477 memcpy(r->out.out_data, out_data.data,
9478 MIN(r->in.out_data_size, out_data.length));
9484 /****************************************************************
9485 _spoolss_AddPrintProcessor
9486 ****************************************************************/
9488 WERROR _spoolss_AddPrintProcessor(pipes_struct *p,
9489 struct spoolss_AddPrintProcessor *r)
9491 /* for now, just indicate success and ignore the add. We'll
9492 automatically set the winprint processor for printer
9493 entries later. Used to debug the LexMark Optra S 1855 PCL
9499 /****************************************************************
9501 ****************************************************************/
9503 WERROR _spoolss_AddPort(pipes_struct *p,
9504 struct spoolss_AddPort *r)
9506 /* do what w2k3 does */
9508 return WERR_NOT_SUPPORTED;
9511 /****************************************************************
9512 _spoolss_GetPrinterDriver
9513 ****************************************************************/
9515 WERROR _spoolss_GetPrinterDriver(pipes_struct *p,
9516 struct spoolss_GetPrinterDriver *r)
9518 p->rng_fault_state = true;
9519 return WERR_NOT_SUPPORTED;
9522 /****************************************************************
9523 _spoolss_ReadPrinter
9524 ****************************************************************/
9526 WERROR _spoolss_ReadPrinter(pipes_struct *p,
9527 struct spoolss_ReadPrinter *r)
9529 p->rng_fault_state = true;
9530 return WERR_NOT_SUPPORTED;
9533 /****************************************************************
9534 _spoolss_WaitForPrinterChange
9535 ****************************************************************/
9537 WERROR _spoolss_WaitForPrinterChange(pipes_struct *p,
9538 struct spoolss_WaitForPrinterChange *r)
9540 p->rng_fault_state = true;
9541 return WERR_NOT_SUPPORTED;
9544 /****************************************************************
9545 _spoolss_ConfigurePort
9546 ****************************************************************/
9548 WERROR _spoolss_ConfigurePort(pipes_struct *p,
9549 struct spoolss_ConfigurePort *r)
9551 p->rng_fault_state = true;
9552 return WERR_NOT_SUPPORTED;
9555 /****************************************************************
9557 ****************************************************************/
9559 WERROR _spoolss_DeletePort(pipes_struct *p,
9560 struct spoolss_DeletePort *r)
9562 p->rng_fault_state = true;
9563 return WERR_NOT_SUPPORTED;
9566 /****************************************************************
9567 _spoolss_CreatePrinterIC
9568 ****************************************************************/
9570 WERROR _spoolss_CreatePrinterIC(pipes_struct *p,
9571 struct spoolss_CreatePrinterIC *r)
9573 p->rng_fault_state = true;
9574 return WERR_NOT_SUPPORTED;
9577 /****************************************************************
9578 _spoolss_PlayGDIScriptOnPrinterIC
9579 ****************************************************************/
9581 WERROR _spoolss_PlayGDIScriptOnPrinterIC(pipes_struct *p,
9582 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9584 p->rng_fault_state = true;
9585 return WERR_NOT_SUPPORTED;
9588 /****************************************************************
9589 _spoolss_DeletePrinterIC
9590 ****************************************************************/
9592 WERROR _spoolss_DeletePrinterIC(pipes_struct *p,
9593 struct spoolss_DeletePrinterIC *r)
9595 p->rng_fault_state = true;
9596 return WERR_NOT_SUPPORTED;
9599 /****************************************************************
9600 _spoolss_AddPrinterConnection
9601 ****************************************************************/
9603 WERROR _spoolss_AddPrinterConnection(pipes_struct *p,
9604 struct spoolss_AddPrinterConnection *r)
9606 p->rng_fault_state = true;
9607 return WERR_NOT_SUPPORTED;
9610 /****************************************************************
9611 _spoolss_DeletePrinterConnection
9612 ****************************************************************/
9614 WERROR _spoolss_DeletePrinterConnection(pipes_struct *p,
9615 struct spoolss_DeletePrinterConnection *r)
9617 p->rng_fault_state = true;
9618 return WERR_NOT_SUPPORTED;
9621 /****************************************************************
9622 _spoolss_PrinterMessageBox
9623 ****************************************************************/
9625 WERROR _spoolss_PrinterMessageBox(pipes_struct *p,
9626 struct spoolss_PrinterMessageBox *r)
9628 p->rng_fault_state = true;
9629 return WERR_NOT_SUPPORTED;
9632 /****************************************************************
9634 ****************************************************************/
9636 WERROR _spoolss_AddMonitor(pipes_struct *p,
9637 struct spoolss_AddMonitor *r)
9639 p->rng_fault_state = true;
9640 return WERR_NOT_SUPPORTED;
9643 /****************************************************************
9644 _spoolss_DeleteMonitor
9645 ****************************************************************/
9647 WERROR _spoolss_DeleteMonitor(pipes_struct *p,
9648 struct spoolss_DeleteMonitor *r)
9650 p->rng_fault_state = true;
9651 return WERR_NOT_SUPPORTED;
9654 /****************************************************************
9655 _spoolss_DeletePrintProcessor
9656 ****************************************************************/
9658 WERROR _spoolss_DeletePrintProcessor(pipes_struct *p,
9659 struct spoolss_DeletePrintProcessor *r)
9661 p->rng_fault_state = true;
9662 return WERR_NOT_SUPPORTED;
9665 /****************************************************************
9666 _spoolss_AddPrintProvidor
9667 ****************************************************************/
9669 WERROR _spoolss_AddPrintProvidor(pipes_struct *p,
9670 struct spoolss_AddPrintProvidor *r)
9672 p->rng_fault_state = true;
9673 return WERR_NOT_SUPPORTED;
9676 /****************************************************************
9677 _spoolss_DeletePrintProvidor
9678 ****************************************************************/
9680 WERROR _spoolss_DeletePrintProvidor(pipes_struct *p,
9681 struct spoolss_DeletePrintProvidor *r)
9683 p->rng_fault_state = true;
9684 return WERR_NOT_SUPPORTED;
9687 /****************************************************************
9688 _spoolss_FindFirstPrinterChangeNotification
9689 ****************************************************************/
9691 WERROR _spoolss_FindFirstPrinterChangeNotification(pipes_struct *p,
9692 struct spoolss_FindFirstPrinterChangeNotification *r)
9694 p->rng_fault_state = true;
9695 return WERR_NOT_SUPPORTED;
9698 /****************************************************************
9699 _spoolss_FindNextPrinterChangeNotification
9700 ****************************************************************/
9702 WERROR _spoolss_FindNextPrinterChangeNotification(pipes_struct *p,
9703 struct spoolss_FindNextPrinterChangeNotification *r)
9705 p->rng_fault_state = true;
9706 return WERR_NOT_SUPPORTED;
9709 /****************************************************************
9710 _spoolss_RouterFindFirstPrinterChangeNotificationOld
9711 ****************************************************************/
9713 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(pipes_struct *p,
9714 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
9716 p->rng_fault_state = true;
9717 return WERR_NOT_SUPPORTED;
9720 /****************************************************************
9721 _spoolss_ReplyOpenPrinter
9722 ****************************************************************/
9724 WERROR _spoolss_ReplyOpenPrinter(pipes_struct *p,
9725 struct spoolss_ReplyOpenPrinter *r)
9727 p->rng_fault_state = true;
9728 return WERR_NOT_SUPPORTED;
9731 /****************************************************************
9732 _spoolss_RouterReplyPrinter
9733 ****************************************************************/
9735 WERROR _spoolss_RouterReplyPrinter(pipes_struct *p,
9736 struct spoolss_RouterReplyPrinter *r)
9738 p->rng_fault_state = true;
9739 return WERR_NOT_SUPPORTED;
9742 /****************************************************************
9743 _spoolss_ReplyClosePrinter
9744 ****************************************************************/
9746 WERROR _spoolss_ReplyClosePrinter(pipes_struct *p,
9747 struct spoolss_ReplyClosePrinter *r)
9749 p->rng_fault_state = true;
9750 return WERR_NOT_SUPPORTED;
9753 /****************************************************************
9755 ****************************************************************/
9757 WERROR _spoolss_AddPortEx(pipes_struct *p,
9758 struct spoolss_AddPortEx *r)
9760 p->rng_fault_state = true;
9761 return WERR_NOT_SUPPORTED;
9764 /****************************************************************
9765 _spoolss_RouterFindFirstPrinterChangeNotification
9766 ****************************************************************/
9768 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(pipes_struct *p,
9769 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
9771 p->rng_fault_state = true;
9772 return WERR_NOT_SUPPORTED;
9775 /****************************************************************
9776 _spoolss_SpoolerInit
9777 ****************************************************************/
9779 WERROR _spoolss_SpoolerInit(pipes_struct *p,
9780 struct spoolss_SpoolerInit *r)
9782 p->rng_fault_state = true;
9783 return WERR_NOT_SUPPORTED;
9786 /****************************************************************
9787 _spoolss_ResetPrinterEx
9788 ****************************************************************/
9790 WERROR _spoolss_ResetPrinterEx(pipes_struct *p,
9791 struct spoolss_ResetPrinterEx *r)
9793 p->rng_fault_state = true;
9794 return WERR_NOT_SUPPORTED;
9797 /****************************************************************
9798 _spoolss_RouterReplyPrinterEx
9799 ****************************************************************/
9801 WERROR _spoolss_RouterReplyPrinterEx(pipes_struct *p,
9802 struct spoolss_RouterReplyPrinterEx *r)
9804 p->rng_fault_state = true;
9805 return WERR_NOT_SUPPORTED;
9808 /****************************************************************
9810 ****************************************************************/
9812 WERROR _spoolss_44(pipes_struct *p,
9813 struct spoolss_44 *r)
9815 p->rng_fault_state = true;
9816 return WERR_NOT_SUPPORTED;
9819 /****************************************************************
9821 ****************************************************************/
9823 WERROR _spoolss_47(pipes_struct *p,
9824 struct spoolss_47 *r)
9826 p->rng_fault_state = true;
9827 return WERR_NOT_SUPPORTED;
9830 /****************************************************************
9832 ****************************************************************/
9834 WERROR _spoolss_4a(pipes_struct *p,
9835 struct spoolss_4a *r)
9837 p->rng_fault_state = true;
9838 return WERR_NOT_SUPPORTED;
9841 /****************************************************************
9843 ****************************************************************/
9845 WERROR _spoolss_4b(pipes_struct *p,
9846 struct spoolss_4b *r)
9848 p->rng_fault_state = true;
9849 return WERR_NOT_SUPPORTED;
9852 /****************************************************************
9854 ****************************************************************/
9856 WERROR _spoolss_4c(pipes_struct *p,
9857 struct spoolss_4c *r)
9859 p->rng_fault_state = true;
9860 return WERR_NOT_SUPPORTED;
9863 /****************************************************************
9865 ****************************************************************/
9867 WERROR _spoolss_53(pipes_struct *p,
9868 struct spoolss_53 *r)
9870 p->rng_fault_state = true;
9871 return WERR_NOT_SUPPORTED;
9874 /****************************************************************
9876 ****************************************************************/
9878 WERROR _spoolss_55(pipes_struct *p,
9879 struct spoolss_55 *r)
9881 p->rng_fault_state = true;
9882 return WERR_NOT_SUPPORTED;
9885 /****************************************************************
9887 ****************************************************************/
9889 WERROR _spoolss_56(pipes_struct *p,
9890 struct spoolss_56 *r)
9892 p->rng_fault_state = true;
9893 return WERR_NOT_SUPPORTED;
9896 /****************************************************************
9898 ****************************************************************/
9900 WERROR _spoolss_57(pipes_struct *p,
9901 struct spoolss_57 *r)
9903 p->rng_fault_state = true;
9904 return WERR_NOT_SUPPORTED;
9907 /****************************************************************
9909 ****************************************************************/
9911 WERROR _spoolss_5a(pipes_struct *p,
9912 struct spoolss_5a *r)
9914 p->rng_fault_state = true;
9915 return WERR_NOT_SUPPORTED;
9918 /****************************************************************
9920 ****************************************************************/
9922 WERROR _spoolss_5b(pipes_struct *p,
9923 struct spoolss_5b *r)
9925 p->rng_fault_state = true;
9926 return WERR_NOT_SUPPORTED;
9929 /****************************************************************
9931 ****************************************************************/
9933 WERROR _spoolss_5c(pipes_struct *p,
9934 struct spoolss_5c *r)
9936 p->rng_fault_state = true;
9937 return WERR_NOT_SUPPORTED;
9940 /****************************************************************
9942 ****************************************************************/
9944 WERROR _spoolss_5d(pipes_struct *p,
9945 struct spoolss_5d *r)
9947 p->rng_fault_state = true;
9948 return WERR_NOT_SUPPORTED;
9951 /****************************************************************
9953 ****************************************************************/
9955 WERROR _spoolss_5e(pipes_struct *p,
9956 struct spoolss_5e *r)
9958 p->rng_fault_state = true;
9959 return WERR_NOT_SUPPORTED;
9962 /****************************************************************
9964 ****************************************************************/
9966 WERROR _spoolss_5f(pipes_struct *p,
9967 struct spoolss_5f *r)
9969 p->rng_fault_state = true;
9970 return WERR_NOT_SUPPORTED;
9973 /****************************************************************
9975 ****************************************************************/
9977 WERROR _spoolss_60(pipes_struct *p,
9978 struct spoolss_60 *r)
9980 p->rng_fault_state = true;
9981 return WERR_NOT_SUPPORTED;
9984 /****************************************************************
9986 ****************************************************************/
9988 WERROR _spoolss_61(pipes_struct *p,
9989 struct spoolss_61 *r)
9991 p->rng_fault_state = true;
9992 return WERR_NOT_SUPPORTED;
9995 /****************************************************************
9997 ****************************************************************/
9999 WERROR _spoolss_62(pipes_struct *p,
10000 struct spoolss_62 *r)
10002 p->rng_fault_state = true;
10003 return WERR_NOT_SUPPORTED;
10006 /****************************************************************
10008 ****************************************************************/
10010 WERROR _spoolss_63(pipes_struct *p,
10011 struct spoolss_63 *r)
10013 p->rng_fault_state = true;
10014 return WERR_NOT_SUPPORTED;
10017 /****************************************************************
10019 ****************************************************************/
10021 WERROR _spoolss_64(pipes_struct *p,
10022 struct spoolss_64 *r)
10024 p->rng_fault_state = true;
10025 return WERR_NOT_SUPPORTED;
10028 /****************************************************************
10030 ****************************************************************/
10032 WERROR _spoolss_65(pipes_struct *p,
10033 struct spoolss_65 *r)
10035 p->rng_fault_state = true;
10036 return WERR_NOT_SUPPORTED;
10039 /****************************************************************
10040 _spoolss_GetCorePrinterDrivers
10041 ****************************************************************/
10043 WERROR _spoolss_GetCorePrinterDrivers(pipes_struct *p,
10044 struct spoolss_GetCorePrinterDrivers *r)
10046 p->rng_fault_state = true;
10047 return WERR_NOT_SUPPORTED;
10050 /****************************************************************
10052 ****************************************************************/
10054 WERROR _spoolss_67(pipes_struct *p,
10055 struct spoolss_67 *r)
10057 p->rng_fault_state = true;
10058 return WERR_NOT_SUPPORTED;
10061 /****************************************************************
10062 _spoolss_GetPrinterDriverPackagePath
10063 ****************************************************************/
10065 WERROR _spoolss_GetPrinterDriverPackagePath(pipes_struct *p,
10066 struct spoolss_GetPrinterDriverPackagePath *r)
10068 p->rng_fault_state = true;
10069 return WERR_NOT_SUPPORTED;
10072 /****************************************************************
10074 ****************************************************************/
10076 WERROR _spoolss_69(pipes_struct *p,
10077 struct spoolss_69 *r)
10079 p->rng_fault_state = true;
10080 return WERR_NOT_SUPPORTED;
10083 /****************************************************************
10085 ****************************************************************/
10087 WERROR _spoolss_6a(pipes_struct *p,
10088 struct spoolss_6a *r)
10090 p->rng_fault_state = true;
10091 return WERR_NOT_SUPPORTED;
10094 /****************************************************************
10096 ****************************************************************/
10098 WERROR _spoolss_6b(pipes_struct *p,
10099 struct spoolss_6b *r)
10101 p->rng_fault_state = true;
10102 return WERR_NOT_SUPPORTED;
10105 /****************************************************************
10107 ****************************************************************/
10109 WERROR _spoolss_6c(pipes_struct *p,
10110 struct spoolss_6c *r)
10112 p->rng_fault_state = true;
10113 return WERR_NOT_SUPPORTED;
10116 /****************************************************************
10118 ****************************************************************/
10120 WERROR _spoolss_6d(pipes_struct *p,
10121 struct spoolss_6d *r)
10123 p->rng_fault_state = true;
10124 return WERR_NOT_SUPPORTED;