2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Jeremy Allison 2001-2002,
8 * Copyright (C) Gerald Carter 2000-2004,
9 * Copyright (C) Tim Potter 2001-2002.
10 * Copyright (C) Guenther Deschner 2009-2010.
11 * Copyright (C) Andreas Schneider 2010.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
28 up, all the errors returned are DOS errors, not NT status codes. */
31 #include "nt_printing.h"
32 #include "srv_spoolss_util.h"
33 #include "../librpc/gen_ndr/srv_spoolss.h"
34 #include "../librpc/gen_ndr/cli_spoolss.h"
35 #include "rpc_client/init_spoolss.h"
36 #include "librpc/gen_ndr/messaging.h"
37 #include "librpc/gen_ndr/ndr_security.h"
39 #include "registry/reg_objects.h"
40 #include "include/printing.h"
42 /* macros stolen from s4 spoolss server */
43 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
44 ((info)?ndr_size_##fn(info, level, 0):0)
46 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
47 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
49 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
50 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
52 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
55 #define DBGC_CLASS DBGC_RPC_SRV
57 #ifndef MAX_OPEN_PRINTER_EXS
58 #define MAX_OPEN_PRINTER_EXS 50
61 static Printer_entry *printers_list;
63 typedef struct _counter_printer_0 {
64 struct _counter_printer_0 *next;
65 struct _counter_printer_0 *prev;
71 static counter_printer_0 *counter_list;
73 static struct rpc_pipe_client *notify_cli_pipe; /* print notify back-channel pipe handle*/
74 static uint32_t smb_connections = 0;
77 /* Map generic permissions to printer object specific permissions */
79 const struct standard_mapping printer_std_mapping = {
86 /* Map generic permissions to print server object specific permissions */
88 const struct generic_mapping printserver_std_mapping = {
95 /* API table for Xcv Monitor functions */
97 struct xcv_api_table {
99 WERROR(*fn) (TALLOC_CTX *mem_ctx, NT_USER_TOKEN *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
102 /********************************************************************
103 * Canonicalize servername.
104 ********************************************************************/
106 static const char *canon_servername(const char *servername)
108 const char *pservername = servername;
109 while (*pservername == '\\') {
115 /* translate between internal status numbers and NT status numbers */
116 static int nt_printj_status(int v)
122 return JOB_STATUS_PAUSED;
124 return JOB_STATUS_SPOOLING;
126 return JOB_STATUS_PRINTING;
128 return JOB_STATUS_ERROR;
130 return JOB_STATUS_DELETING;
132 return JOB_STATUS_OFFLINE;
134 return JOB_STATUS_PAPEROUT;
136 return JOB_STATUS_PRINTED;
138 return JOB_STATUS_DELETED;
140 return JOB_STATUS_BLOCKED_DEVQ;
141 case LPQ_USER_INTERVENTION:
142 return JOB_STATUS_USER_INTERVENTION;
147 static int nt_printq_status(int v)
151 return PRINTER_STATUS_PAUSED;
160 /***************************************************************************
161 Disconnect from the client
162 ****************************************************************************/
164 static void srv_spoolss_replycloseprinter(int snum, struct policy_handle *handle)
170 * Tell the specific printing tdb we no longer want messages for this printer
171 * by deregistering our PID.
174 if (!print_notify_deregister_pid(snum))
175 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
177 /* weird if the test succeds !!! */
178 if (smb_connections==0) {
179 DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
183 status = rpccli_spoolss_ReplyClosePrinter(notify_cli_pipe, talloc_tos(),
186 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
187 DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
188 win_errstr(result)));
190 /* if it's the last connection, deconnect the IPC$ share */
191 if (smb_connections==1) {
193 cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) );
194 notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */
196 messaging_deregister(smbd_messaging_context(),
197 MSG_PRINTER_NOTIFY2, NULL);
199 /* Tell the connections db we're no longer interested in
200 * printer notify messages. */
202 serverid_register_msg_flags(
203 messaging_server_id(smbd_messaging_context()),
204 false, FLAG_MSG_PRINT_NOTIFY);
210 /****************************************************************************
211 Functions to free a printer entry datastruct.
212 ****************************************************************************/
214 static int printer_entry_destructor(Printer_entry *Printer)
216 if (Printer->notify.client_connected == true) {
219 if ( Printer->printer_type == SPLHND_SERVER) {
221 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
222 } else if (Printer->printer_type == SPLHND_PRINTER) {
223 snum = print_queue_snum(Printer->sharename);
225 srv_spoolss_replycloseprinter(snum,
226 &Printer->notify.client_hnd);
230 Printer->notify.flags=0;
231 Printer->notify.options=0;
232 Printer->notify.localmachine[0]='\0';
233 Printer->notify.printerlocal=0;
234 TALLOC_FREE(Printer->notify.option);
235 Printer->notify.client_connected = false;
237 TALLOC_FREE(Printer->devmode);
239 /* Remove from the internal list. */
240 DLIST_REMOVE(printers_list, Printer);
244 /****************************************************************************
245 find printer index by handle
246 ****************************************************************************/
248 static Printer_entry *find_printer_index_by_hnd(pipes_struct *p,
249 struct policy_handle *hnd)
251 Printer_entry *find_printer = NULL;
253 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
254 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
261 /****************************************************************************
262 Close printer index by handle.
263 ****************************************************************************/
265 static bool close_printer_handle(pipes_struct *p, struct policy_handle *hnd)
267 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
270 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
275 close_policy_hnd(p, hnd);
280 /****************************************************************************
281 Delete a printer given a handle.
282 ****************************************************************************/
284 static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *sharename)
286 char *cmd = lp_deleteprinter_cmd();
287 char *command = NULL;
289 SE_PRIV se_printop = SE_PRINT_OPERATOR;
290 bool is_print_op = false;
292 /* can't fail if we don't try */
297 command = talloc_asprintf(ctx,
304 is_print_op = user_has_privileges( token, &se_printop );
306 DEBUG(10,("Running [%s]\n", command));
308 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
313 if ( (ret = smbrun(command, NULL)) == 0 ) {
314 /* Tell everyone we updated smb.conf. */
315 message_send_all(smbd_messaging_context(),
316 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
322 /********** END SePrintOperatorPrivlege BLOCK **********/
324 DEBUGADD(10,("returned [%d]\n", ret));
326 TALLOC_FREE(command);
329 return WERR_BADFID; /* What to return here? */
331 /* go ahead and re-read the services immediately */
333 reload_services(false);
336 if ( lp_servicenumber( sharename ) > 0 )
337 return WERR_ACCESS_DENIED;
342 /****************************************************************************
343 Delete a printer given a handle.
344 ****************************************************************************/
346 static WERROR delete_printer_handle(pipes_struct *p, struct policy_handle *hnd)
348 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
352 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
358 * It turns out that Windows allows delete printer on a handle
359 * opened by an admin user, then used on a pipe handle created
360 * by an anonymous user..... but they're working on security.... riiight !
364 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
365 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
366 return WERR_ACCESS_DENIED;
369 /* this does not need a become root since the access check has been
370 done on the handle already */
372 result = winreg_delete_printer_key(p->mem_ctx, p->server_info,
373 Printer->sharename, "");
374 if (!W_ERROR_IS_OK(result)) {
375 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
379 return delete_printer_hook(p->mem_ctx, p->server_info->ptok,
380 Printer->sharename );
383 /****************************************************************************
384 Return the snum of a printer corresponding to an handle.
385 ****************************************************************************/
387 static bool get_printer_snum(pipes_struct *p, struct policy_handle *hnd,
388 int *number, struct share_params **params)
390 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
393 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
398 switch (Printer->printer_type) {
400 DEBUG(4,("short name:%s\n", Printer->sharename));
401 *number = print_queue_snum(Printer->sharename);
402 return (*number != -1);
410 /****************************************************************************
411 Set printer handle type.
412 Check if it's \\server or \\server\printer
413 ****************************************************************************/
415 static bool set_printer_hnd_printertype(Printer_entry *Printer, const char *handlename)
417 DEBUG(3,("Setting printer type=%s\n", handlename));
419 if ( strlen(handlename) < 3 ) {
420 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", handlename));
424 /* it's a print server */
425 if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
426 DEBUGADD(4,("Printer is a print server\n"));
427 Printer->printer_type = SPLHND_SERVER;
429 /* it's a printer (set_printer_hnd_name() will handle port monitors */
431 DEBUGADD(4,("Printer is a printer\n"));
432 Printer->printer_type = SPLHND_PRINTER;
438 /****************************************************************************
439 Set printer handle name.. Accept names like \\server, \\server\printer,
440 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
441 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
442 XcvDataPort() interface.
443 ****************************************************************************/
445 static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
446 struct auth_serversupplied_info *server_info,
447 Printer_entry *Printer,
448 const char *handlename)
451 int n_services=lp_numservices();
453 const char *printername;
454 const char *servername;
457 struct spoolss_PrinterInfo2 *info2 = NULL;
460 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
461 (unsigned long)strlen(handlename)));
463 aprinter = CONST_DISCARD(char *, handlename);
464 if ( *handlename == '\\' ) {
465 servername = canon_servername(handlename);
466 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
470 if (!is_myname_or_ipaddr(servername)) {
474 fstrcpy(Printer->servername, servername);
477 if (Printer->printer_type == SPLHND_SERVER) {
481 if (Printer->printer_type != SPLHND_PRINTER) {
485 DEBUGADD(5, ("searching for [%s]\n", aprinter));
487 /* check for the Port Monitor Interface */
488 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
489 Printer->printer_type = SPLHND_PORTMON_TCP;
490 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
493 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
494 Printer->printer_type = SPLHND_PORTMON_LOCAL;
495 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
499 /* Search all sharenames first as this is easier than pulling
500 the printer_info_2 off of disk. Don't use find_service() since
501 that calls out to map_username() */
503 /* do another loop to look for printernames */
504 for (snum = 0; !found && snum < n_services; snum++) {
505 const char *printer = lp_const_servicename(snum);
507 /* no point going on if this is not a printer */
508 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
512 /* ignore [printers] share */
513 if (strequal(printer, "printers")) {
517 fstrcpy(sname, printer);
518 if (strequal(aprinter, printer)) {
523 /* no point looking up the printer object if
524 we aren't allowing printername != sharename */
525 if (lp_force_printername(snum)) {
529 result = winreg_get_printer(mem_ctx,
534 if ( !W_ERROR_IS_OK(result) ) {
535 DEBUG(0,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
536 sname, win_errstr(result)));
540 printername = strrchr(info2->printername, '\\');
541 if (printername == NULL) {
542 printername = info2->printername;
547 if (strequal(printername, aprinter)) {
552 DEBUGADD(10, ("printername: %s\n", printername));
558 DEBUGADD(4,("Printer not found\n"));
562 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
564 fstrcpy(Printer->sharename, sname);
569 /****************************************************************************
570 Find first available printer slot. creates a printer handle for you.
571 ****************************************************************************/
573 static bool open_printer_hnd(pipes_struct *p, struct policy_handle *hnd,
574 const char *name, uint32_t access_granted)
576 Printer_entry *new_printer;
578 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
580 new_printer = TALLOC_ZERO_P(NULL, Printer_entry);
581 if (new_printer == NULL) {
584 talloc_set_destructor(new_printer, printer_entry_destructor);
586 if (!create_policy_hnd(p, hnd, new_printer)) {
587 TALLOC_FREE(new_printer);
591 /* Add to the internal list. */
592 DLIST_ADD(printers_list, new_printer);
594 new_printer->notify.option=NULL;
596 if (!set_printer_hnd_printertype(new_printer, name)) {
597 close_printer_handle(p, hnd);
601 if (!set_printer_hnd_name(p->mem_ctx, p->server_info, new_printer, name)) {
602 close_printer_handle(p, hnd);
606 new_printer->access_granted = access_granted;
608 DEBUG(5, ("%d printer handles active\n",
609 (int)num_pipe_handles(p)));
614 /***************************************************************************
615 check to see if the client motify handle is monitoring the notification
616 given by (notify_type, notify_field).
617 **************************************************************************/
619 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
620 uint16_t notify_field)
625 static bool is_monitoring_event(Printer_entry *p, uint16_t notify_type,
626 uint16_t notify_field)
628 struct spoolss_NotifyOption *option = p->notify.option;
632 * Flags should always be zero when the change notify
633 * is registered by the client's spooler. A user Win32 app
634 * might use the flags though instead of the NOTIFY_OPTION_INFO
643 return is_monitoring_event_flags(
644 p->notify.flags, notify_type, notify_field);
646 for (i = 0; i < option->count; i++) {
648 /* Check match for notify_type */
650 if (option->types[i].type != notify_type)
653 /* Check match for field */
655 for (j = 0; j < option->types[i].count; j++) {
656 if (option->types[i].fields[j].field == notify_field) {
662 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
663 p->servername, p->sharename, notify_type, notify_field));
668 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
669 _data->data.integer[0] = _integer; \
670 _data->data.integer[1] = 0;
673 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
674 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
675 if (!_data->data.string.string) {\
676 _data->data.string.size = 0; \
678 _data->data.string.size = strlen_m_term(_p) * 2;
680 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
681 _data->data.devmode.devmode = _devmode;
683 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
684 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
685 if (!_data->data.sd.sd) { \
686 _data->data.sd.sd_size = 0; \
688 _data->data.sd.sd_size = \
689 ndr_size_security_descriptor(_data->data.sd.sd, 0);
691 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
696 struct spoolss_Time st;
700 if (!init_systemtime(&st, t)) {
704 p = talloc_array(mem_ctx, char, len);
710 * Systemtime must be linearized as a set of UINT16's.
711 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
714 SSVAL(p, 0, st.year);
715 SSVAL(p, 2, st.month);
716 SSVAL(p, 4, st.day_of_week);
718 SSVAL(p, 8, st.hour);
719 SSVAL(p, 10, st.minute);
720 SSVAL(p, 12, st.second);
721 SSVAL(p, 14, st.millisecond);
727 /* Convert a notification message to a struct spoolss_Notify */
729 static void notify_one_value(struct spoolss_notify_msg *msg,
730 struct spoolss_Notify *data,
733 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
736 static void notify_string(struct spoolss_notify_msg *msg,
737 struct spoolss_Notify *data,
740 /* The length of the message includes the trailing \0 */
742 data->data.string.size = msg->len * 2;
743 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
744 if (!data->data.string.string) {
745 data->data.string.size = 0;
750 static void notify_system_time(struct spoolss_notify_msg *msg,
751 struct spoolss_Notify *data,
754 data->data.string.string = NULL;
755 data->data.string.size = 0;
757 if (msg->len != sizeof(time_t)) {
758 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
763 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
764 &data->data.string.string,
765 &data->data.string.size);
768 struct notify2_message_table {
770 void (*fn)(struct spoolss_notify_msg *msg,
771 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
774 static struct notify2_message_table printer_notify_table[] = {
775 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
776 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
777 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
778 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
779 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
780 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
781 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
782 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
783 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
784 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
785 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
786 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
787 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
788 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
789 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
790 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
791 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
792 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
793 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
796 static struct notify2_message_table job_notify_table[] = {
797 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
798 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
799 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
800 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
801 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
802 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
803 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
804 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
805 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
806 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
807 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
808 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
809 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
810 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
811 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
812 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
813 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
814 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
815 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
816 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
817 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
818 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
819 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
820 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
824 /***********************************************************************
825 Allocate talloc context for container object
826 **********************************************************************/
828 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
833 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
838 /***********************************************************************
839 release all allocated memory and zero out structure
840 **********************************************************************/
842 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
848 talloc_destroy(ctr->ctx);
855 /***********************************************************************
856 **********************************************************************/
858 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
866 /***********************************************************************
867 **********************************************************************/
869 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
871 if ( !ctr || !ctr->msg_groups )
874 if ( idx >= ctr->num_groups )
877 return &ctr->msg_groups[idx];
881 /***********************************************************************
882 How many groups of change messages do we have ?
883 **********************************************************************/
885 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
890 return ctr->num_groups;
893 /***********************************************************************
894 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
895 **********************************************************************/
897 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
899 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
900 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
901 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
907 /* loop over all groups looking for a matching printer name */
909 for ( i=0; i<ctr->num_groups; i++ ) {
910 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
914 /* add a new group? */
916 if ( i == ctr->num_groups ) {
919 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
920 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
923 ctr->msg_groups = groups;
925 /* clear the new entry and set the printer name */
927 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
928 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
931 /* add the change messages; 'i' is the correct index now regardless */
933 msg_grp = &ctr->msg_groups[i];
937 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
938 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
941 msg_grp->msgs = msg_list;
943 new_slot = msg_grp->num_msgs-1;
944 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
946 /* need to allocate own copy of data */
949 msg_grp->msgs[new_slot].notify.data = (char *)
950 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
952 return ctr->num_groups;
955 static void construct_info_data(struct spoolss_Notify *info_data,
956 enum spoolss_NotifyType type,
957 uint16_t field, int id);
959 /***********************************************************************
960 Send a change notication message on all handles which have a call
962 **********************************************************************/
964 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
967 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
968 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
969 SPOOLSS_NOTIFY_MSG *messages;
970 int sending_msg_count;
973 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
977 messages = msg_group->msgs;
980 DEBUG(5,("send_notify2_changes() called with no messages!\n"));
984 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
986 /* loop over all printers */
988 for (p = printers_list; p; p = p->next) {
989 struct spoolss_Notify *notifies;
994 /* Is there notification on this handle? */
996 if ( !p->notify.client_connected )
999 DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
1001 /* For this printer? Print servers always receive
1004 if ( ( p->printer_type == SPLHND_PRINTER ) &&
1005 ( !strequal(msg_group->printername, p->sharename) ) )
1008 DEBUG(10,("Our printer\n"));
1010 /* allocate the max entries possible */
1012 notifies = TALLOC_ZERO_ARRAY(mem_ctx, struct spoolss_Notify, msg_group->num_msgs);
1017 /* build the array of change notifications */
1019 sending_msg_count = 0;
1021 for ( i=0; i<msg_group->num_msgs; i++ ) {
1022 SPOOLSS_NOTIFY_MSG *msg = &messages[i];
1024 /* Are we monitoring this event? */
1026 if (!is_monitoring_event(p, msg->type, msg->field))
1029 sending_msg_count++;
1032 DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
1033 msg->type, msg->field, p->sharename));
1036 * if the is a printer notification handle and not a job notification
1037 * type, then set the id to 0. Other wise just use what was specified
1040 * When registering change notification on a print server handle
1041 * we always need to send back the id (snum) matching the printer
1042 * for which the change took place. For change notify registered
1043 * on a printer handle, this does not matter and the id should be 0.
1048 if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
1054 /* Convert unix jobid to smb jobid */
1056 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1057 id = sysjob_to_jobid(msg->id);
1060 DEBUG(3, ("no such unix jobid %d\n", msg->id));
1065 construct_info_data( ¬ifies[count], msg->type, msg->field, id );
1068 case PRINTER_NOTIFY_TYPE:
1069 if ( printer_notify_table[msg->field].fn )
1070 printer_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1073 case JOB_NOTIFY_TYPE:
1074 if ( job_notify_table[msg->field].fn )
1075 job_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1079 DEBUG(5, ("Unknown notification type %d\n", msg->type));
1086 if ( sending_msg_count ) {
1089 union spoolss_ReplyPrinterInfo info;
1090 struct spoolss_NotifyInfo info0;
1091 uint32_t reply_result;
1093 info0.version = 0x2;
1094 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1095 info0.count = count;
1096 info0.notifies = notifies;
1098 info.info0 = &info0;
1100 status = rpccli_spoolss_RouterReplyPrinterEx(notify_cli_pipe, mem_ctx,
1101 &p->notify.client_hnd,
1102 p->notify.change, /* color */
1105 0, /* reply_type, must be 0 */
1108 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1109 DEBUG(1,("RouterReplyPrinterEx to client: %s failed: %s\n",
1110 notify_cli_pipe->srv_name_slash,
1113 switch (reply_result) {
1116 case PRINTER_NOTIFY_INFO_DISCARDED:
1117 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1118 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1127 DEBUG(8,("send_notify2_changes: Exit...\n"));
1131 /***********************************************************************
1132 **********************************************************************/
1134 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1137 uint32_t tv_sec, tv_usec;
1140 /* Unpack message */
1142 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1145 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1147 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1150 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1151 &msg->notify.value[0], &msg->notify.value[1]);
1153 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1154 &msg->len, &msg->notify.data);
1156 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1157 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1159 tv->tv_sec = tv_sec;
1160 tv->tv_usec = tv_usec;
1163 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1164 msg->notify.value[1]));
1166 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1171 /********************************************************************
1172 Receive a notify2 message list
1173 ********************************************************************/
1175 static void receive_notify2_message_list(struct messaging_context *msg,
1178 struct server_id server_id,
1181 size_t msg_count, i;
1182 char *buf = (char *)data->data;
1185 SPOOLSS_NOTIFY_MSG notify;
1186 SPOOLSS_NOTIFY_MSG_CTR messages;
1189 if (data->length < 4) {
1190 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1194 msg_count = IVAL(buf, 0);
1197 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1199 if (msg_count == 0) {
1200 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1204 /* initialize the container */
1206 ZERO_STRUCT( messages );
1207 notify_msg_ctr_init( &messages );
1210 * build message groups for each printer identified
1211 * in a change_notify msg. Remember that a PCN message
1212 * includes the handle returned for the srv_spoolss_replyopenprinter()
1213 * call. Therefore messages are grouped according to printer handle.
1216 for ( i=0; i<msg_count; i++ ) {
1217 struct timeval msg_tv;
1219 if (msg_ptr + 4 - buf > data->length) {
1220 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1224 msg_len = IVAL(msg_ptr,0);
1227 if (msg_ptr + msg_len - buf > data->length) {
1228 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1232 /* unpack messages */
1234 ZERO_STRUCT( notify );
1235 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1238 /* add to correct list in container */
1240 notify_msg_ctr_addmsg( &messages, ¬ify );
1242 /* free memory that might have been allocated by notify2_unpack_msg() */
1244 if ( notify.len != 0 )
1245 SAFE_FREE( notify.notify.data );
1248 /* process each group of messages */
1250 num_groups = notify_msg_ctr_numgroups( &messages );
1251 for ( i=0; i<num_groups; i++ )
1252 send_notify2_changes( &messages, i );
1257 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1258 (uint32_t)msg_count ));
1260 notify_msg_ctr_destroy( &messages );
1265 /********************************************************************
1266 Send a message to ourself about new driver being installed
1267 so we can upgrade the information for each printer bound to this
1269 ********************************************************************/
1271 static bool srv_spoolss_drv_upgrade_printer(const char *drivername)
1273 int len = strlen(drivername);
1278 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1281 messaging_send_buf(smbd_messaging_context(),
1282 messaging_server_id(smbd_messaging_context()),
1283 MSG_PRINTER_DRVUPGRADE,
1284 (uint8_t *)drivername, len+1);
1289 /**********************************************************************
1290 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1291 over all printers, upgrading ones as necessary
1292 **********************************************************************/
1294 void do_drv_upgrade_printer(struct messaging_context *msg,
1297 struct server_id server_id,
1300 TALLOC_CTX *tmp_ctx;
1301 struct auth_serversupplied_info *server_info = NULL;
1302 struct spoolss_PrinterInfo2 *pinfo2;
1305 const char *drivername;
1307 int n_services = lp_numservices();
1310 tmp_ctx = talloc_new(NULL);
1311 if (!tmp_ctx) return;
1313 status = make_server_info_system(tmp_ctx, &server_info);
1314 if (!NT_STATUS_IS_OK(status)) {
1315 DEBUG(0, ("do_drv_upgrade_printer: "
1316 "Could not create system server_info\n"));
1320 len = MIN(data->length,sizeof(drivername)-1);
1321 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, len);
1323 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1327 DEBUG(10, ("do_drv_upgrade_printer: "
1328 "Got message for new driver [%s]\n", drivername));
1330 /* Iterate the printer list */
1332 for (snum = 0; snum < n_services; snum++) {
1333 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1337 result = winreg_get_printer(tmp_ctx, server_info, NULL,
1338 lp_const_servicename(snum),
1341 if (!W_ERROR_IS_OK(result)) {
1345 if (strcmp(drivername, pinfo2->drivername) != 0) {
1349 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1351 /* all we care about currently is the change_id */
1352 result = winreg_printer_update_changeid(tmp_ctx,
1354 pinfo2->printername);
1356 if (!W_ERROR_IS_OK(result)) {
1357 DEBUG(3, ("do_drv_upgrade_printer: "
1358 "Failed to update changeid [%s]\n",
1359 win_errstr(result)));
1365 talloc_free(tmp_ctx);
1368 /********************************************************************
1369 Update the cache for all printq's with a registered client
1371 ********************************************************************/
1373 void update_monitored_printq_cache( void )
1375 Printer_entry *printer = printers_list;
1378 /* loop through all printers and update the cache where
1379 client_connected == true */
1382 if ( (printer->printer_type == SPLHND_PRINTER)
1383 && printer->notify.client_connected )
1385 snum = print_queue_snum(printer->sharename);
1386 print_queue_status( snum, NULL, NULL );
1389 printer = printer->next;
1395 /****************************************************************
1396 _spoolss_OpenPrinter
1397 ****************************************************************/
1399 WERROR _spoolss_OpenPrinter(pipes_struct *p,
1400 struct spoolss_OpenPrinter *r)
1402 struct spoolss_OpenPrinterEx e;
1405 ZERO_STRUCT(e.in.userlevel);
1407 e.in.printername = r->in.printername;
1408 e.in.datatype = r->in.datatype;
1409 e.in.devmode_ctr = r->in.devmode_ctr;
1410 e.in.access_mask = r->in.access_mask;
1413 e.out.handle = r->out.handle;
1415 werr = _spoolss_OpenPrinterEx(p, &e);
1417 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1418 /* OpenPrinterEx returns this for a bad
1419 * printer name. We must return WERR_INVALID_PRINTER_NAME
1422 werr = WERR_INVALID_PRINTER_NAME;
1428 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1429 struct spoolss_DeviceMode *orig,
1430 struct spoolss_DeviceMode **dest)
1432 struct spoolss_DeviceMode *dm;
1434 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1439 /* copy all values, then duplicate strings and structs */
1442 dm->devicename = talloc_strdup(dm, orig->devicename);
1443 if (!dm->devicename) {
1446 dm->formname = talloc_strdup(dm, orig->formname);
1447 if (!dm->formname) {
1450 if (orig->driverextra_data.data) {
1451 dm->driverextra_data.data =
1452 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1453 orig->driverextra_data.length);
1454 if (!dm->driverextra_data.data) {
1463 /****************************************************************
1464 _spoolss_OpenPrinterEx
1465 ****************************************************************/
1467 WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
1468 struct spoolss_OpenPrinterEx *r)
1471 Printer_entry *Printer=NULL;
1473 if (!r->in.printername) {
1474 return WERR_INVALID_PARAM;
1477 /* some sanity check because you can open a printer or a print server */
1478 /* aka: \\server\printer or \\server */
1480 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1482 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1483 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1484 " for printer %s\n", r->in.printername));
1485 ZERO_STRUCTP(r->out.handle);
1486 return WERR_INVALID_PARAM;
1489 Printer = find_printer_index_by_hnd(p, r->out.handle);
1491 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1492 "handle we created for printer %s\n", r->in.printername));
1493 close_printer_handle(p, r->out.handle);
1494 ZERO_STRUCTP(r->out.handle);
1495 return WERR_INVALID_PARAM;
1499 * First case: the user is opening the print server:
1501 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1502 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1504 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1505 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1506 * or if the user is listed in the smb.conf printer admin parameter.
1508 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1509 * client view printer folder, but does not show the MSAPW.
1511 * Note: this test needs code to check access rights here too. Jeremy
1512 * could you look at this?
1514 * Second case: the user is opening a printer:
1515 * NT doesn't let us connect to a printer if the connecting user
1516 * doesn't have print permission.
1518 * Third case: user is opening a Port Monitor
1519 * access checks same as opening a handle to the print server.
1522 switch (Printer->printer_type )
1525 case SPLHND_PORTMON_TCP:
1526 case SPLHND_PORTMON_LOCAL:
1527 /* Printserver handles use global struct... */
1531 /* Map standard access rights to object specific access rights */
1533 se_map_standard(&r->in.access_mask,
1534 &printserver_std_mapping);
1536 /* Deny any object specific bits that don't apply to print
1537 servers (i.e printer and job specific bits) */
1539 r->in.access_mask &= SEC_MASK_SPECIFIC;
1541 if (r->in.access_mask &
1542 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1543 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1544 close_printer_handle(p, r->out.handle);
1545 ZERO_STRUCTP(r->out.handle);
1546 return WERR_ACCESS_DENIED;
1549 /* Allow admin access */
1551 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1553 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1555 if (!lp_ms_add_printer_wizard()) {
1556 close_printer_handle(p, r->out.handle);
1557 ZERO_STRUCTP(r->out.handle);
1558 return WERR_ACCESS_DENIED;
1561 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1562 and not a printer admin, then fail */
1564 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1565 !user_has_privileges(p->server_info->ptok,
1567 !token_contains_name_in_list(
1568 uidtoname(p->server_info->utok.uid),
1569 p->server_info->info3->base.domain.string,
1571 p->server_info->ptok,
1572 lp_printer_admin(snum))) {
1573 close_printer_handle(p, r->out.handle);
1574 ZERO_STRUCTP(r->out.handle);
1575 return WERR_ACCESS_DENIED;
1578 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1582 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1585 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1586 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1588 /* We fall through to return WERR_OK */
1591 case SPLHND_PRINTER:
1592 /* NT doesn't let us connect to a printer if the connecting user
1593 doesn't have print permission. */
1595 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1596 close_printer_handle(p, r->out.handle);
1597 ZERO_STRUCTP(r->out.handle);
1601 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1602 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1605 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1607 /* map an empty access mask to the minimum access mask */
1608 if (r->in.access_mask == 0x0)
1609 r->in.access_mask = PRINTER_ACCESS_USE;
1612 * If we are not serving the printer driver for this printer,
1613 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1614 * will keep NT clients happy --jerry
1617 if (lp_use_client_driver(snum)
1618 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1620 r->in.access_mask = PRINTER_ACCESS_USE;
1623 /* check smb.conf parameters and the the sec_desc */
1625 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1626 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1627 ZERO_STRUCTP(r->out.handle);
1628 return WERR_ACCESS_DENIED;
1631 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1632 p->server_info->ptok, snum) ||
1633 !print_access_check(p->server_info, snum,
1634 r->in.access_mask)) {
1635 DEBUG(3, ("access DENIED for printer open\n"));
1636 close_printer_handle(p, r->out.handle);
1637 ZERO_STRUCTP(r->out.handle);
1638 return WERR_ACCESS_DENIED;
1641 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1642 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1643 close_printer_handle(p, r->out.handle);
1644 ZERO_STRUCTP(r->out.handle);
1645 return WERR_ACCESS_DENIED;
1648 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1649 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1651 r->in.access_mask = PRINTER_ACCESS_USE;
1653 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1654 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1656 winreg_create_printer(p->mem_ctx,
1658 Printer->servername,
1659 lp_const_servicename(snum));
1664 /* sanity check to prevent programmer error */
1665 ZERO_STRUCTP(r->out.handle);
1669 Printer->access_granted = r->in.access_mask;
1672 * If the client sent a devmode in the OpenPrinter() call, then
1673 * save it here in case we get a job submission on this handle
1676 if ((Printer->printer_type != SPLHND_SERVER) &&
1677 r->in.devmode_ctr.devmode) {
1678 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1682 #if 0 /* JERRY -- I'm doubtful this is really effective */
1683 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1684 optimization in Windows 2000 clients --jerry */
1686 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1687 && (RA_WIN2K == get_remote_arch()) )
1689 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1690 sys_usleep( 500000 );
1697 /****************************************************************
1698 _spoolss_ClosePrinter
1699 ****************************************************************/
1701 WERROR _spoolss_ClosePrinter(pipes_struct *p,
1702 struct spoolss_ClosePrinter *r)
1704 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1706 if (Printer && Printer->document_started) {
1707 struct spoolss_EndDocPrinter e;
1709 e.in.handle = r->in.handle;
1711 _spoolss_EndDocPrinter(p, &e);
1714 if (!close_printer_handle(p, r->in.handle))
1717 /* clear the returned printer handle. Observed behavior
1718 from Win2k server. Don't think this really matters.
1719 Previous code just copied the value of the closed
1722 ZERO_STRUCTP(r->out.handle);
1727 /****************************************************************
1728 _spoolss_DeletePrinter
1729 ****************************************************************/
1731 WERROR _spoolss_DeletePrinter(pipes_struct *p,
1732 struct spoolss_DeletePrinter *r)
1734 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1738 if (Printer && Printer->document_started) {
1739 struct spoolss_EndDocPrinter e;
1741 e.in.handle = r->in.handle;
1743 _spoolss_EndDocPrinter(p, &e);
1746 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
1747 winreg_delete_printer_key(p->mem_ctx,
1749 lp_const_servicename(snum),
1753 result = delete_printer_handle(p, r->in.handle);
1758 /*******************************************************************
1759 * static function to lookup the version id corresponding to an
1760 * long architecture string
1761 ******************************************************************/
1763 static const struct print_architecture_table_node archi_table[]= {
1765 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1766 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1767 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1768 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
1769 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
1770 {"Windows IA64", SPL_ARCH_IA64, 3 },
1771 {"Windows x64", SPL_ARCH_X64, 3 },
1775 static int get_version_id(const char *arch)
1779 for (i=0; archi_table[i].long_archi != NULL; i++)
1781 if (strcmp(arch, archi_table[i].long_archi) == 0)
1782 return (archi_table[i].version);
1788 /****************************************************************
1789 _spoolss_DeletePrinterDriver
1790 ****************************************************************/
1792 WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
1793 struct spoolss_DeletePrinterDriver *r)
1796 struct spoolss_DriverInfo8 *info = NULL;
1797 struct spoolss_DriverInfo8 *info_win2k = NULL;
1800 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1802 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1803 and not a printer admin, then fail */
1805 if ( (p->server_info->utok.uid != sec_initial_uid())
1806 && !user_has_privileges(p->server_info->ptok, &se_printop )
1807 && !token_contains_name_in_list(
1808 uidtoname(p->server_info->utok.uid),
1809 p->server_info->info3->base.domain.string,
1811 p->server_info->ptok,
1812 lp_printer_admin(-1)) )
1814 return WERR_ACCESS_DENIED;
1817 /* check that we have a valid driver name first */
1819 if ((version = get_version_id(r->in.architecture)) == -1)
1820 return WERR_INVALID_ENVIRONMENT;
1822 status = winreg_get_driver(p->mem_ctx, p->server_info,
1823 r->in.architecture, r->in.driver,
1825 if (!W_ERROR_IS_OK(status)) {
1826 /* try for Win2k driver if "Windows NT x86" */
1828 if ( version == 2 ) {
1831 status = winreg_get_driver(p->mem_ctx, p->server_info,
1835 if (!W_ERROR_IS_OK(status)) {
1836 status = WERR_UNKNOWN_PRINTER_DRIVER;
1840 /* otherwise it was a failure */
1842 status = WERR_UNKNOWN_PRINTER_DRIVER;
1848 if (printer_driver_in_use(p->mem_ctx, p->server_info, info)) {
1849 status = WERR_PRINTER_DRIVER_IN_USE;
1854 status = winreg_get_driver(p->mem_ctx, p->server_info,
1856 r->in.driver, 3, &info_win2k);
1857 if (W_ERROR_IS_OK(status)) {
1858 /* if we get to here, we now have 2 driver info structures to remove */
1859 /* remove the Win2k driver first*/
1861 status = winreg_del_driver(p->mem_ctx,
1864 talloc_free(info_win2k);
1866 /* this should not have failed---if it did, report to client */
1867 if (!W_ERROR_IS_OK(status)) {
1873 status = winreg_del_driver(p->mem_ctx, p->server_info, info, version);
1881 /****************************************************************
1882 _spoolss_DeletePrinterDriverEx
1883 ****************************************************************/
1885 WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
1886 struct spoolss_DeletePrinterDriverEx *r)
1888 struct spoolss_DriverInfo8 *info = NULL;
1889 struct spoolss_DriverInfo8 *info_win2k = NULL;
1893 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1895 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1896 and not a printer admin, then fail */
1898 if ( (p->server_info->utok.uid != sec_initial_uid())
1899 && !user_has_privileges(p->server_info->ptok, &se_printop )
1900 && !token_contains_name_in_list(
1901 uidtoname(p->server_info->utok.uid),
1902 p->server_info->info3->base.domain.string,
1904 p->server_info->ptok, lp_printer_admin(-1)) )
1906 return WERR_ACCESS_DENIED;
1909 /* check that we have a valid driver name first */
1910 if ((version = get_version_id(r->in.architecture)) == -1) {
1911 /* this is what NT returns */
1912 return WERR_INVALID_ENVIRONMENT;
1915 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
1916 version = r->in.version;
1918 status = winreg_get_driver(p->mem_ctx, p->server_info,
1919 r->in.architecture, r->in.driver,
1921 if (!W_ERROR_IS_OK(status)) {
1922 status = WERR_UNKNOWN_PRINTER_DRIVER;
1925 * if the client asked for a specific version,
1926 * or this is something other than Windows NT x86,
1930 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
1933 /* try for Win2k driver if "Windows NT x86" */
1936 status = winreg_get_driver(info, p->server_info,
1940 if (!W_ERROR_IS_OK(status)) {
1941 status = WERR_UNKNOWN_PRINTER_DRIVER;
1946 if (printer_driver_in_use(info, p->server_info, info)) {
1947 status = WERR_PRINTER_DRIVER_IN_USE;
1952 * we have a couple of cases to consider.
1953 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
1954 * then the delete should fail if **any** files overlap with
1956 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
1957 * non-overlapping files
1958 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
1959 * is set, the do not delete any files
1960 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
1963 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
1965 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
1968 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
1969 printer_driver_files_in_use(info, p->server_info, info)) {
1970 /* no idea of the correct error here */
1971 status = WERR_ACCESS_DENIED;
1976 /* also check for W32X86/3 if necessary; maybe we already have? */
1978 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
1979 status = winreg_get_driver(info, p->server_info,
1981 r->in.driver, 3, &info_win2k);
1982 if (W_ERROR_IS_OK(status)) {
1985 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
1986 printer_driver_files_in_use(info, p->server_info,
1988 /* no idea of the correct error here */
1989 talloc_free(info_win2k);
1990 status = WERR_ACCESS_DENIED;
1994 /* if we get to here, we now have 2 driver info structures to remove */
1995 /* remove the Win2k driver first*/
1997 status = winreg_del_driver(info, p->server_info,
2000 /* this should not have failed---if it did, report to client */
2002 if (!W_ERROR_IS_OK(status)) {
2007 * now delete any associated files if delete_files is
2008 * true. Even if this part failes, we return succes
2009 * because the driver doesn not exist any more
2012 delete_driver_files(p->server_info,
2018 status = winreg_del_driver(info, p->server_info, info, version);
2019 if (!W_ERROR_IS_OK(status)) {
2024 * now delete any associated files if delete_files is
2025 * true. Even if this part failes, we return succes
2026 * because the driver doesn not exist any more
2029 delete_driver_files(p->server_info, info);
2038 /********************************************************************
2039 GetPrinterData on a printer server Handle.
2040 ********************************************************************/
2042 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2044 enum winreg_Type *type,
2045 union spoolss_PrinterData *data)
2047 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2049 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2055 if (!StrCaseCmp(value, "BeepEnabled")) {
2061 if (!StrCaseCmp(value, "EventLog")) {
2063 /* formally was 0x1b */
2068 if (!StrCaseCmp(value, "NetPopup")) {
2074 if (!StrCaseCmp(value, "MajorVersion")) {
2077 /* Windows NT 4.0 seems to not allow uploading of drivers
2078 to a server that reports 0x3 as the MajorVersion.
2079 need to investigate more how Win2k gets around this .
2082 if (RA_WINNT == get_remote_arch()) {
2091 if (!StrCaseCmp(value, "MinorVersion")) {
2098 * uint32_t size = 0x114
2099 * uint32_t major = 5
2100 * uint32_t minor = [0|1]
2101 * uint32_t build = [2195|2600]
2102 * extra unicode string = e.g. "Service Pack 3"
2104 if (!StrCaseCmp(value, "OSVersion")) {
2106 enum ndr_err_code ndr_err;
2107 struct spoolss_OSVersion os;
2109 os.major = 5; /* Windows 2000 == 5.0 */
2111 os.build = 2195; /* build */
2112 os.extra_string = ""; /* leave extra string empty */
2114 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2115 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2116 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2117 return WERR_GENERAL_FAILURE;
2121 data->binary = blob;
2127 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2130 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2131 W_ERROR_HAVE_NO_MEMORY(data->string);
2136 if (!StrCaseCmp(value, "Architecture")) {
2138 data->string = talloc_strdup(mem_ctx,
2139 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2140 W_ERROR_HAVE_NO_MEMORY(data->string);
2145 if (!StrCaseCmp(value, "DsPresent")) {
2148 /* only show the publish check box if we are a
2149 member of a AD domain */
2151 if (lp_security() == SEC_ADS) {
2159 if (!StrCaseCmp(value, "DNSMachineName")) {
2160 const char *hostname = get_mydnsfullname();
2163 return WERR_BADFILE;
2167 data->string = talloc_strdup(mem_ctx, hostname);
2168 W_ERROR_HAVE_NO_MEMORY(data->string);
2175 return WERR_INVALID_PARAM;
2178 /****************************************************************
2179 _spoolss_GetPrinterData
2180 ****************************************************************/
2182 WERROR _spoolss_GetPrinterData(pipes_struct *p,
2183 struct spoolss_GetPrinterData *r)
2185 struct spoolss_GetPrinterDataEx r2;
2187 r2.in.handle = r->in.handle;
2188 r2.in.key_name = "PrinterDriverData";
2189 r2.in.value_name = r->in.value_name;
2190 r2.in.offered = r->in.offered;
2191 r2.out.type = r->out.type;
2192 r2.out.data = r->out.data;
2193 r2.out.needed = r->out.needed;
2195 return _spoolss_GetPrinterDataEx(p, &r2);
2198 /*********************************************************
2199 Connect to the client machine.
2200 **********************************************************/
2202 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2203 struct sockaddr_storage *client_ss, const char *remote_machine)
2206 struct cli_state *the_cli;
2207 struct sockaddr_storage rm_addr;
2208 char addr[INET6_ADDRSTRLEN];
2210 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2211 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2213 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2214 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2217 print_sockaddr(addr, sizeof(addr), &rm_addr);
2219 rm_addr = *client_ss;
2220 print_sockaddr(addr, sizeof(addr), &rm_addr);
2221 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2225 if (ismyaddr((struct sockaddr *)&rm_addr)) {
2226 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2231 /* setup the connection */
2232 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2233 &rm_addr, 0, "IPC$", "IPC",
2237 0, lp_client_signing(), NULL );
2239 if ( !NT_STATUS_IS_OK( ret ) ) {
2240 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2245 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2246 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2247 cli_shutdown(the_cli);
2252 * Ok - we have an anonymous connection to the IPC$ share.
2253 * Now start the NT Domain stuff :-).
2256 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2257 if (!NT_STATUS_IS_OK(ret)) {
2258 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2259 remote_machine, nt_errstr(ret)));
2260 cli_shutdown(the_cli);
2267 /***************************************************************************
2268 Connect to the client.
2269 ****************************************************************************/
2271 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2272 uint32_t localprinter, uint32_t type,
2273 struct policy_handle *handle,
2274 struct sockaddr_storage *client_ss)
2280 * If it's the first connection, contact the client
2281 * and connect to the IPC$ share anonymously
2283 if (smb_connections==0) {
2284 fstring unix_printer;
2286 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2288 if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ss, unix_printer ))
2291 messaging_register(smbd_messaging_context(), NULL,
2292 MSG_PRINTER_NOTIFY2,
2293 receive_notify2_message_list);
2294 /* Tell the connections db we're now interested in printer
2295 * notify messages. */
2296 serverid_register_msg_flags(
2297 messaging_server_id(smbd_messaging_context()),
2298 true, FLAG_MSG_PRINT_NOTIFY);
2302 * Tell the specific printing tdb we want messages for this printer
2303 * by registering our PID.
2306 if (!print_notify_register_pid(snum))
2307 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2311 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2319 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2320 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2321 win_errstr(result)));
2323 return (W_ERROR_IS_OK(result));
2326 /****************************************************************
2327 ****************************************************************/
2329 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2330 const struct spoolss_NotifyOption *r)
2332 struct spoolss_NotifyOption *option;
2339 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2346 if (!option->count) {
2350 option->types = talloc_zero_array(option,
2351 struct spoolss_NotifyOptionType, option->count);
2352 if (!option->types) {
2353 talloc_free(option);
2357 for (i=0; i < option->count; i++) {
2358 option->types[i] = r->types[i];
2360 if (option->types[i].count) {
2361 option->types[i].fields = talloc_zero_array(option,
2362 union spoolss_Field, option->types[i].count);
2363 if (!option->types[i].fields) {
2364 talloc_free(option);
2367 for (k=0; k<option->types[i].count; k++) {
2368 option->types[i].fields[k] =
2369 r->types[i].fields[k];
2377 /****************************************************************
2378 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2380 * before replying OK: status=0 a rpc call is made to the workstation
2381 * asking ReplyOpenPrinter
2383 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2384 * called from api_spoolss_rffpcnex
2385 ****************************************************************/
2387 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
2388 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2391 struct spoolss_NotifyOption *option = r->in.notify_options;
2392 struct sockaddr_storage client_ss;
2394 /* store the notify value in the printer struct */
2396 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2399 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2400 "Invalid handle (%s:%u:%u).\n",
2401 OUR_HANDLE(r->in.handle)));
2405 Printer->notify.flags = r->in.flags;
2406 Printer->notify.options = r->in.options;
2407 Printer->notify.printerlocal = r->in.printer_local;
2409 TALLOC_FREE(Printer->notify.option);
2410 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2412 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2414 /* Connect to the client machine and send a ReplyOpenPrinter */
2416 if ( Printer->printer_type == SPLHND_SERVER)
2418 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2419 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2422 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2423 "client_address is %s\n", p->client_address));
2425 if (!interpret_string_addr(&client_ss, p->client_address,
2427 return WERR_SERVER_UNAVAILABLE;
2430 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2431 Printer->notify.printerlocal, 1,
2432 &Printer->notify.client_hnd, &client_ss))
2433 return WERR_SERVER_UNAVAILABLE;
2435 Printer->notify.client_connected = true;
2440 /*******************************************************************
2441 * fill a notify_info_data with the servername
2442 ********************************************************************/
2444 static void spoolss_notify_server_name(int snum,
2445 struct spoolss_Notify *data,
2446 print_queue_struct *queue,
2447 struct spoolss_PrinterInfo2 *pinfo2,
2448 TALLOC_CTX *mem_ctx)
2450 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2453 /*******************************************************************
2454 * fill a notify_info_data with the printername (not including the servername).
2455 ********************************************************************/
2457 static void spoolss_notify_printer_name(int snum,
2458 struct spoolss_Notify *data,
2459 print_queue_struct *queue,
2460 struct spoolss_PrinterInfo2 *pinfo2,
2461 TALLOC_CTX *mem_ctx)
2463 /* the notify name should not contain the \\server\ part */
2464 const char *p = strrchr(pinfo2->printername, '\\');
2467 p = pinfo2->printername;
2472 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2475 /*******************************************************************
2476 * fill a notify_info_data with the servicename
2477 ********************************************************************/
2479 static void spoolss_notify_share_name(int snum,
2480 struct spoolss_Notify *data,
2481 print_queue_struct *queue,
2482 struct spoolss_PrinterInfo2 *pinfo2,
2483 TALLOC_CTX *mem_ctx)
2485 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2488 /*******************************************************************
2489 * fill a notify_info_data with the port name
2490 ********************************************************************/
2492 static void spoolss_notify_port_name(int snum,
2493 struct spoolss_Notify *data,
2494 print_queue_struct *queue,
2495 struct spoolss_PrinterInfo2 *pinfo2,
2496 TALLOC_CTX *mem_ctx)
2498 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2501 /*******************************************************************
2502 * fill a notify_info_data with the printername
2503 * but it doesn't exist, have to see what to do
2504 ********************************************************************/
2506 static void spoolss_notify_driver_name(int snum,
2507 struct spoolss_Notify *data,
2508 print_queue_struct *queue,
2509 struct spoolss_PrinterInfo2 *pinfo2,
2510 TALLOC_CTX *mem_ctx)
2512 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2515 /*******************************************************************
2516 * fill a notify_info_data with the comment
2517 ********************************************************************/
2519 static void spoolss_notify_comment(int snum,
2520 struct spoolss_Notify *data,
2521 print_queue_struct *queue,
2522 struct spoolss_PrinterInfo2 *pinfo2,
2523 TALLOC_CTX *mem_ctx)
2527 if (*pinfo2->comment == '\0') {
2528 p = lp_comment(snum);
2530 p = pinfo2->comment;
2533 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2536 /*******************************************************************
2537 * fill a notify_info_data with the comment
2538 * location = "Room 1, floor 2, building 3"
2539 ********************************************************************/
2541 static void spoolss_notify_location(int snum,
2542 struct spoolss_Notify *data,
2543 print_queue_struct *queue,
2544 struct spoolss_PrinterInfo2 *pinfo2,
2545 TALLOC_CTX *mem_ctx)
2547 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
2550 /*******************************************************************
2551 * fill a notify_info_data with the device mode
2552 * jfm:xxxx don't to it for know but that's a real problem !!!
2553 ********************************************************************/
2555 static void spoolss_notify_devmode(int snum,
2556 struct spoolss_Notify *data,
2557 print_queue_struct *queue,
2558 struct spoolss_PrinterInfo2 *pinfo2,
2559 TALLOC_CTX *mem_ctx)
2561 /* for a dummy implementation we have to zero the fields */
2562 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2565 /*******************************************************************
2566 * fill a notify_info_data with the separator file name
2567 ********************************************************************/
2569 static void spoolss_notify_sepfile(int snum,
2570 struct spoolss_Notify *data,
2571 print_queue_struct *queue,
2572 struct spoolss_PrinterInfo2 *pinfo2,
2573 TALLOC_CTX *mem_ctx)
2575 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2578 /*******************************************************************
2579 * fill a notify_info_data with the print processor
2580 * jfm:xxxx return always winprint to indicate we don't do anything to it
2581 ********************************************************************/
2583 static void spoolss_notify_print_processor(int snum,
2584 struct spoolss_Notify *data,
2585 print_queue_struct *queue,
2586 struct spoolss_PrinterInfo2 *pinfo2,
2587 TALLOC_CTX *mem_ctx)
2589 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2592 /*******************************************************************
2593 * fill a notify_info_data with the print processor options
2594 * jfm:xxxx send an empty string
2595 ********************************************************************/
2597 static void spoolss_notify_parameters(int snum,
2598 struct spoolss_Notify *data,
2599 print_queue_struct *queue,
2600 struct spoolss_PrinterInfo2 *pinfo2,
2601 TALLOC_CTX *mem_ctx)
2603 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2606 /*******************************************************************
2607 * fill a notify_info_data with the data type
2608 * jfm:xxxx always send RAW as data type
2609 ********************************************************************/
2611 static void spoolss_notify_datatype(int snum,
2612 struct spoolss_Notify *data,
2613 print_queue_struct *queue,
2614 struct spoolss_PrinterInfo2 *pinfo2,
2615 TALLOC_CTX *mem_ctx)
2617 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2620 /*******************************************************************
2621 * fill a notify_info_data with the security descriptor
2622 * jfm:xxxx send an null pointer to say no security desc
2623 * have to implement security before !
2624 ********************************************************************/
2626 static void spoolss_notify_security_desc(int snum,
2627 struct spoolss_Notify *data,
2628 print_queue_struct *queue,
2629 struct spoolss_PrinterInfo2 *pinfo2,
2630 TALLOC_CTX *mem_ctx)
2632 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2635 /*******************************************************************
2636 * fill a notify_info_data with the attributes
2637 * jfm:xxxx a samba printer is always shared
2638 ********************************************************************/
2640 static void spoolss_notify_attributes(int snum,
2641 struct spoolss_Notify *data,
2642 print_queue_struct *queue,
2643 struct spoolss_PrinterInfo2 *pinfo2,
2644 TALLOC_CTX *mem_ctx)
2646 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2649 /*******************************************************************
2650 * fill a notify_info_data with the priority
2651 ********************************************************************/
2653 static void spoolss_notify_priority(int snum,
2654 struct spoolss_Notify *data,
2655 print_queue_struct *queue,
2656 struct spoolss_PrinterInfo2 *pinfo2,
2657 TALLOC_CTX *mem_ctx)
2659 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2662 /*******************************************************************
2663 * fill a notify_info_data with the default priority
2664 ********************************************************************/
2666 static void spoolss_notify_default_priority(int snum,
2667 struct spoolss_Notify *data,
2668 print_queue_struct *queue,
2669 struct spoolss_PrinterInfo2 *pinfo2,
2670 TALLOC_CTX *mem_ctx)
2672 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
2675 /*******************************************************************
2676 * fill a notify_info_data with the start time
2677 ********************************************************************/
2679 static void spoolss_notify_start_time(int snum,
2680 struct spoolss_Notify *data,
2681 print_queue_struct *queue,
2682 struct spoolss_PrinterInfo2 *pinfo2,
2683 TALLOC_CTX *mem_ctx)
2685 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
2688 /*******************************************************************
2689 * fill a notify_info_data with the until time
2690 ********************************************************************/
2692 static void spoolss_notify_until_time(int snum,
2693 struct spoolss_Notify *data,
2694 print_queue_struct *queue,
2695 struct spoolss_PrinterInfo2 *pinfo2,
2696 TALLOC_CTX *mem_ctx)
2698 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
2701 /*******************************************************************
2702 * fill a notify_info_data with the status
2703 ********************************************************************/
2705 static void spoolss_notify_status(int snum,
2706 struct spoolss_Notify *data,
2707 print_queue_struct *queue,
2708 struct spoolss_PrinterInfo2 *pinfo2,
2709 TALLOC_CTX *mem_ctx)
2711 print_status_struct status;
2713 print_queue_length(snum, &status);
2714 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
2717 /*******************************************************************
2718 * fill a notify_info_data with the number of jobs queued
2719 ********************************************************************/
2721 static void spoolss_notify_cjobs(int snum,
2722 struct spoolss_Notify *data,
2723 print_queue_struct *queue,
2724 struct spoolss_PrinterInfo2 *pinfo2,
2725 TALLOC_CTX *mem_ctx)
2727 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
2730 /*******************************************************************
2731 * fill a notify_info_data with the average ppm
2732 ********************************************************************/
2734 static void spoolss_notify_average_ppm(int snum,
2735 struct spoolss_Notify *data,
2736 print_queue_struct *queue,
2737 struct spoolss_PrinterInfo2 *pinfo2,
2738 TALLOC_CTX *mem_ctx)
2740 /* always respond 8 pages per minutes */
2741 /* a little hard ! */
2742 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
2745 /*******************************************************************
2746 * fill a notify_info_data with username
2747 ********************************************************************/
2749 static void spoolss_notify_username(int snum,
2750 struct spoolss_Notify *data,
2751 print_queue_struct *queue,
2752 struct spoolss_PrinterInfo2 *pinfo2,
2753 TALLOC_CTX *mem_ctx)
2755 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
2758 /*******************************************************************
2759 * fill a notify_info_data with job status
2760 ********************************************************************/
2762 static void spoolss_notify_job_status(int snum,
2763 struct spoolss_Notify *data,
2764 print_queue_struct *queue,
2765 struct spoolss_PrinterInfo2 *pinfo2,
2766 TALLOC_CTX *mem_ctx)
2768 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
2771 /*******************************************************************
2772 * fill a notify_info_data with job name
2773 ********************************************************************/
2775 static void spoolss_notify_job_name(int snum,
2776 struct spoolss_Notify *data,
2777 print_queue_struct *queue,
2778 struct spoolss_PrinterInfo2 *pinfo2,
2779 TALLOC_CTX *mem_ctx)
2781 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
2784 /*******************************************************************
2785 * fill a notify_info_data with job status
2786 ********************************************************************/
2788 static void spoolss_notify_job_status_string(int snum,
2789 struct spoolss_Notify *data,
2790 print_queue_struct *queue,
2791 struct spoolss_PrinterInfo2 *pinfo2,
2792 TALLOC_CTX *mem_ctx)
2795 * Now we're returning job status codes we just return a "" here. JRA.
2800 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
2803 switch (queue->status) {
2808 p = ""; /* NT provides the paused string */
2817 #endif /* NO LONGER NEEDED. */
2819 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2822 /*******************************************************************
2823 * fill a notify_info_data with job time
2824 ********************************************************************/
2826 static void spoolss_notify_job_time(int snum,
2827 struct spoolss_Notify *data,
2828 print_queue_struct *queue,
2829 struct spoolss_PrinterInfo2 *pinfo2,
2830 TALLOC_CTX *mem_ctx)
2832 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2835 /*******************************************************************
2836 * fill a notify_info_data with job size
2837 ********************************************************************/
2839 static void spoolss_notify_job_size(int snum,
2840 struct spoolss_Notify *data,
2841 print_queue_struct *queue,
2842 struct spoolss_PrinterInfo2 *pinfo2,
2843 TALLOC_CTX *mem_ctx)
2845 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
2848 /*******************************************************************
2849 * fill a notify_info_data with page info
2850 ********************************************************************/
2851 static void spoolss_notify_total_pages(int snum,
2852 struct spoolss_Notify *data,
2853 print_queue_struct *queue,
2854 struct spoolss_PrinterInfo2 *pinfo2,
2855 TALLOC_CTX *mem_ctx)
2857 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
2860 /*******************************************************************
2861 * fill a notify_info_data with pages printed info.
2862 ********************************************************************/
2863 static void spoolss_notify_pages_printed(int snum,
2864 struct spoolss_Notify *data,
2865 print_queue_struct *queue,
2866 struct spoolss_PrinterInfo2 *pinfo2,
2867 TALLOC_CTX *mem_ctx)
2869 /* Add code when back-end tracks this */
2870 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2873 /*******************************************************************
2874 Fill a notify_info_data with job position.
2875 ********************************************************************/
2877 static void spoolss_notify_job_position(int snum,
2878 struct spoolss_Notify *data,
2879 print_queue_struct *queue,
2880 struct spoolss_PrinterInfo2 *pinfo2,
2881 TALLOC_CTX *mem_ctx)
2883 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
2886 /*******************************************************************
2887 Fill a notify_info_data with submitted time.
2888 ********************************************************************/
2890 static void spoolss_notify_submitted_time(int snum,
2891 struct spoolss_Notify *data,
2892 print_queue_struct *queue,
2893 struct spoolss_PrinterInfo2 *pinfo2,
2894 TALLOC_CTX *mem_ctx)
2896 data->data.string.string = NULL;
2897 data->data.string.size = 0;
2899 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
2900 &data->data.string.string,
2901 &data->data.string.size);
2905 struct s_notify_info_data_table
2907 enum spoolss_NotifyType type;
2910 enum spoolss_NotifyTable variable_type;
2911 void (*fn) (int snum, struct spoolss_Notify *data,
2912 print_queue_struct *queue,
2913 struct spoolss_PrinterInfo2 *pinfo2,
2914 TALLOC_CTX *mem_ctx);
2917 /* A table describing the various print notification constants and
2918 whether the notification data is a pointer to a variable sized
2919 buffer, a one value uint32_t or a two value uint32_t. */
2921 static const struct s_notify_info_data_table notify_info_data_table[] =
2923 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2924 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2925 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
2926 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2927 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2928 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
2929 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
2930 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2931 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
2932 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2933 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2934 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2935 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
2936 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
2937 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2938 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
2939 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2940 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2941 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
2942 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
2943 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
2944 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
2945 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
2946 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2947 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
2948 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2949 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2950 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2951 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2952 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2953 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2954 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2955 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2956 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2957 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2958 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2959 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
2960 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
2961 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
2962 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
2963 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2964 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
2965 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
2966 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2967 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2968 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
2969 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
2970 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
2971 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
2974 /*******************************************************************
2975 Return the variable_type of info_data structure.
2976 ********************************************************************/
2978 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
2983 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
2984 if ( (notify_info_data_table[i].type == type) &&
2985 (notify_info_data_table[i].field == field) ) {
2986 return notify_info_data_table[i].variable_type;
2990 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
2995 /****************************************************************************
2996 ****************************************************************************/
2998 static bool search_notify(enum spoolss_NotifyType type,
3004 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3005 if (notify_info_data_table[i].type == type &&
3006 notify_info_data_table[i].field == field &&
3007 notify_info_data_table[i].fn != NULL) {
3016 /****************************************************************************
3017 ****************************************************************************/
3019 static void construct_info_data(struct spoolss_Notify *info_data,
3020 enum spoolss_NotifyType type,
3021 uint16_t field, int id)
3023 info_data->type = type;
3024 info_data->field.field = field;
3025 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3026 info_data->job_id = id;
3029 /*******************************************************************
3031 * fill a notify_info struct with info asked
3033 ********************************************************************/
3035 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3036 struct spoolss_NotifyInfo *info,
3037 struct spoolss_PrinterInfo2 *pinfo2,
3039 const struct spoolss_NotifyOptionType *option_type,
3041 TALLOC_CTX *mem_ctx)
3044 enum spoolss_NotifyType type;
3047 struct spoolss_Notify *current_data;
3048 print_queue_struct *queue=NULL;
3050 type = option_type->type;
3052 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3053 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3054 option_type->count, lp_servicename(snum)));
3056 for(field_num=0; field_num < option_type->count; field_num++) {
3057 field = option_type->fields[field_num].field;
3059 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3061 if (!search_notify(type, field, &j) )
3064 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3065 struct spoolss_Notify,
3067 if (info->notifies == NULL) {
3068 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3072 current_data = &info->notifies[info->count];
3074 construct_info_data(current_data, type, field, id);
3076 DEBUG(10, ("construct_notify_printer_info: "
3077 "calling [%s] snum=%d printername=[%s])\n",
3078 notify_info_data_table[j].name, snum,
3079 pinfo2->printername));
3081 notify_info_data_table[j].fn(snum, current_data, queue,
3090 /*******************************************************************
3092 * fill a notify_info struct with info asked
3094 ********************************************************************/
3096 static bool construct_notify_jobs_info(print_queue_struct *queue,
3097 struct spoolss_NotifyInfo *info,
3098 struct spoolss_PrinterInfo2 *pinfo2,
3100 const struct spoolss_NotifyOptionType *option_type,
3102 TALLOC_CTX *mem_ctx)
3105 enum spoolss_NotifyType type;
3107 struct spoolss_Notify *current_data;
3109 DEBUG(4,("construct_notify_jobs_info\n"));
3111 type = option_type->type;
3113 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3114 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3115 option_type->count));
3117 for(field_num=0; field_num<option_type->count; field_num++) {
3118 field = option_type->fields[field_num].field;
3120 if (!search_notify(type, field, &j) )
3123 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3124 struct spoolss_Notify,
3126 if (info->notifies == NULL) {
3127 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3131 current_data=&(info->notifies[info->count]);
3133 construct_info_data(current_data, type, field, id);
3134 notify_info_data_table[j].fn(snum, current_data, queue,
3143 * JFM: The enumeration is not that simple, it's even non obvious.
3145 * let's take an example: I want to monitor the PRINTER SERVER for
3146 * the printer's name and the number of jobs currently queued.
3147 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3148 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3150 * I have 3 printers on the back of my server.
3152 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3155 * 1 printer 1 name 1
3156 * 2 printer 1 cjob 1
3157 * 3 printer 2 name 2
3158 * 4 printer 2 cjob 2
3159 * 5 printer 3 name 3
3160 * 6 printer 3 name 3
3162 * that's the print server case, the printer case is even worse.
3165 /*******************************************************************
3167 * enumerate all printers on the printserver
3168 * fill a notify_info struct with info asked
3170 ********************************************************************/
3172 static WERROR printserver_notify_info(pipes_struct *p,
3173 struct policy_handle *hnd,
3174 struct spoolss_NotifyInfo *info,
3175 TALLOC_CTX *mem_ctx)
3178 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3179 int n_services=lp_numservices();
3181 struct spoolss_NotifyOption *option;
3182 struct spoolss_NotifyOptionType option_type;
3183 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3186 DEBUG(4,("printserver_notify_info\n"));
3191 option = Printer->notify.option;
3194 info->notifies = NULL;
3197 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3198 sending a ffpcn() request first */
3203 for (i=0; i<option->count; i++) {
3204 option_type = option->types[i];
3206 if (option_type.type != PRINTER_NOTIFY_TYPE)
3209 for (snum = 0; snum < n_services; snum++) {
3210 if (!lp_browseable(snum) ||
3211 !lp_snum_ok(snum) ||
3212 !lp_print_ok(snum)) {
3213 continue; /* skip */
3216 /* FIXME: should we use a SYSTEM server_info here? */
3217 result = winreg_get_printer(mem_ctx, p->server_info,
3218 Printer->servername,
3219 lp_servicename(snum),
3221 if (!W_ERROR_IS_OK(result)) {
3222 DEBUG(4, ("printserver_notify_info: "
3223 "Failed to get printer [%s]\n",
3224 lp_servicename(snum)));
3229 construct_notify_printer_info(Printer, info,
3234 TALLOC_FREE(pinfo2);
3240 * Debugging information, don't delete.
3243 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3244 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3245 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3247 for (i=0; i<info->count; i++) {
3248 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3249 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3250 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3257 /*******************************************************************
3259 * fill a notify_info struct with info asked
3261 ********************************************************************/
3263 static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
3264 struct spoolss_NotifyInfo *info,
3265 TALLOC_CTX *mem_ctx)
3268 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3271 struct spoolss_NotifyOption *option;
3272 struct spoolss_NotifyOptionType option_type;
3274 print_queue_struct *queue=NULL;
3275 print_status_struct status;
3276 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3279 DEBUG(4,("printer_notify_info\n"));
3284 option = Printer->notify.option;
3288 info->notifies = NULL;
3291 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3292 sending a ffpcn() request first */
3297 get_printer_snum(p, hnd, &snum, NULL);
3299 /* FIXME: should we use a SYSTEM server_info here ? */
3300 result = winreg_get_printer(mem_ctx, p->server_info,
3301 Printer->servername,
3302 lp_servicename(snum), &pinfo2);
3303 if (!W_ERROR_IS_OK(result)) {
3307 for (i=0; i<option->count; i++) {
3308 option_type = option->types[i];
3310 switch (option_type.type) {
3311 case PRINTER_NOTIFY_TYPE:
3312 if (construct_notify_printer_info(Printer, info,
3320 case JOB_NOTIFY_TYPE:
3322 count = print_queue_status(snum, &queue, &status);
3324 for (j=0; j<count; j++) {
3325 construct_notify_jobs_info(&queue[j], info,
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));
3352 talloc_free(pinfo2);
3356 /****************************************************************
3357 _spoolss_RouterRefreshPrinterChangeNotify
3358 ****************************************************************/
3360 WERROR _spoolss_RouterRefreshPrinterChangeNotify(pipes_struct *p,
3361 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3363 struct spoolss_NotifyInfo *info;
3365 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
3366 WERROR result = WERR_BADFID;
3368 /* we always have a spoolss_NotifyInfo struct */
3369 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3371 result = WERR_NOMEM;
3375 *r->out.info = info;
3378 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3379 "Invalid handle (%s:%u:%u).\n",
3380 OUR_HANDLE(r->in.handle)));
3384 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3387 * We are now using the change value, and
3388 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3389 * I don't have a global notification system, I'm sending back all the
3390 * informations even when _NOTHING_ has changed.
3393 /* We need to keep track of the change value to send back in
3394 RRPCN replies otherwise our updates are ignored. */
3396 Printer->notify.fnpcn = true;
3398 if (Printer->notify.client_connected) {
3399 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3400 "Saving change value in request [%x]\n",
3402 Printer->notify.change = r->in.change_low;
3405 /* just ignore the spoolss_NotifyOption */
3407 switch (Printer->printer_type) {
3409 result = printserver_notify_info(p, r->in.handle,
3413 case SPLHND_PRINTER:
3414 result = printer_notify_info(p, r->in.handle,
3419 Printer->notify.fnpcn = false;
3425 /********************************************************************
3426 * construct_printer_info_0
3427 * fill a printer_info_0 struct
3428 ********************************************************************/
3430 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3431 struct auth_serversupplied_info *server_info,
3432 struct spoolss_PrinterInfo2 *info2,
3433 struct spoolss_PrinterInfo0 *r,
3437 counter_printer_0 *session_counter;
3438 struct timeval setuptime;
3439 print_status_struct status;
3441 r->printername = talloc_strdup(mem_ctx, info2->printername);
3442 W_ERROR_HAVE_NO_MEMORY(r->printername);
3444 r->servername = talloc_strdup(mem_ctx, info2->servername);
3445 W_ERROR_HAVE_NO_MEMORY(r->servername);
3447 count = print_queue_length(snum, &status);
3449 /* check if we already have a counter for this printer */
3450 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3451 if (session_counter->snum == snum)
3455 /* it's the first time, add it to the list */
3456 if (session_counter == NULL) {
3457 session_counter = SMB_MALLOC_P(counter_printer_0);
3458 W_ERROR_HAVE_NO_MEMORY(session_counter);
3459 ZERO_STRUCTP(session_counter);
3460 session_counter->snum = snum;
3461 session_counter->counter = 0;
3462 DLIST_ADD(counter_list, session_counter);
3466 session_counter->counter++;
3472 get_startup_time(&setuptime);
3473 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3476 * the global_counter should be stored in a TDB as it's common to all the clients
3477 * and should be zeroed on samba startup
3479 r->global_counter = session_counter->counter;
3481 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3482 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3483 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3484 r->free_build = SPOOLSS_RELEASE_BUILD;
3486 r->max_spooling = 0;
3487 r->session_counter = session_counter->counter;
3488 r->num_error_out_of_paper = 0x0;
3489 r->num_error_not_ready = 0x0; /* number of print failure */
3491 r->number_of_processors = 0x1;
3492 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3493 r->high_part_total_bytes = 0x0;
3494 winreg_printer_get_changeid(mem_ctx, server_info, info2->sharename, &r->change_id); /* ChangeID in milliseconds*/
3495 r->last_error = WERR_OK;
3496 r->status = nt_printq_status(status.status);
3497 r->enumerate_network_printers = 0x0;
3498 r->c_setprinter = 0x0;
3499 r->processor_architecture = 0x0;
3500 r->processor_level = 0x6; /* 6 ???*/
3509 /********************************************************************
3510 * construct_printer_info1
3511 * fill a spoolss_PrinterInfo1 struct
3512 ********************************************************************/
3514 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3515 const struct spoolss_PrinterInfo2 *info2,
3517 struct spoolss_PrinterInfo1 *r,
3522 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3526 W_ERROR_HAVE_NO_MEMORY(r->description);
3528 if (info2->comment == NULL || info2->comment[0] == '\0') {
3529 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3531 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3533 W_ERROR_HAVE_NO_MEMORY(r->comment);
3535 r->name = talloc_strdup(mem_ctx, info2->printername);
3536 W_ERROR_HAVE_NO_MEMORY(r->name);
3541 /********************************************************************
3542 * construct_printer_info2
3543 * fill a spoolss_PrinterInfo2 struct
3544 ********************************************************************/
3546 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3547 const struct spoolss_PrinterInfo2 *info2,
3548 struct spoolss_PrinterInfo2 *r,
3552 print_status_struct status;
3554 count = print_queue_length(snum, &status);
3556 r->servername = talloc_strdup(mem_ctx, info2->servername);
3557 W_ERROR_HAVE_NO_MEMORY(r->servername);
3558 r->printername = talloc_strdup(mem_ctx, info2->printername);
3559 W_ERROR_HAVE_NO_MEMORY(r->printername);
3560 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3561 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3562 r->portname = talloc_strdup(mem_ctx, info2->portname);
3563 W_ERROR_HAVE_NO_MEMORY(r->portname);
3564 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
3565 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3567 if (info2->comment[0] == '\0') {
3568 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3570 r->comment = talloc_strdup(mem_ctx, info2->comment);
3572 W_ERROR_HAVE_NO_MEMORY(r->comment);
3574 r->location = talloc_strdup(mem_ctx, info2->location);
3575 W_ERROR_HAVE_NO_MEMORY(r->location);
3576 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
3577 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3578 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
3579 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3580 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
3581 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3582 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
3583 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3585 r->attributes = info2->attributes;
3587 r->priority = info2->priority;
3588 r->defaultpriority = info2->defaultpriority;
3589 r->starttime = info2->starttime;
3590 r->untiltime = info2->untiltime;
3591 r->status = nt_printq_status(status.status);
3593 r->averageppm = info2->averageppm;
3595 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3597 DEBUG(8,("Returning NULL Devicemode!\n"));
3602 if (info2->secdesc != NULL) {
3603 /* don't use talloc_steal() here unless you do a deep steal of all
3604 the SEC_DESC members */
3606 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3612 /********************************************************************
3613 * construct_printer_info3
3614 * fill a spoolss_PrinterInfo3 struct
3615 ********************************************************************/
3617 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3618 const struct spoolss_PrinterInfo2 *info2,
3619 struct spoolss_PrinterInfo3 *r,
3622 /* These are the components of the SD we are returning. */
3624 if (info2->secdesc != NULL) {
3625 /* don't use talloc_steal() here unless you do a deep steal of all
3626 the SEC_DESC members */
3628 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3629 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3635 /********************************************************************
3636 * construct_printer_info4
3637 * fill a spoolss_PrinterInfo4 struct
3638 ********************************************************************/
3640 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
3641 const struct spoolss_PrinterInfo2 *info2,
3642 struct spoolss_PrinterInfo4 *r,
3645 r->printername = talloc_strdup(mem_ctx, info2->printername);
3646 W_ERROR_HAVE_NO_MEMORY(r->printername);
3647 r->servername = talloc_strdup(mem_ctx, info2->servername);
3648 W_ERROR_HAVE_NO_MEMORY(r->servername);
3650 r->attributes = info2->attributes;
3655 /********************************************************************
3656 * construct_printer_info5
3657 * fill a spoolss_PrinterInfo5 struct
3658 ********************************************************************/
3660 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
3661 const struct spoolss_PrinterInfo2 *info2,
3662 struct spoolss_PrinterInfo5 *r,
3665 r->printername = talloc_strdup(mem_ctx, info2->printername);
3666 W_ERROR_HAVE_NO_MEMORY(r->printername);
3667 r->portname = talloc_strdup(mem_ctx, info2->portname);
3668 W_ERROR_HAVE_NO_MEMORY(r->portname);
3670 r->attributes = info2->attributes;
3672 /* these two are not used by NT+ according to MSDN */
3673 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
3674 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
3679 /********************************************************************
3680 * construct_printer_info_6
3681 * fill a spoolss_PrinterInfo6 struct
3682 ********************************************************************/
3684 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
3685 const struct spoolss_PrinterInfo2 *info2,
3686 struct spoolss_PrinterInfo6 *r,
3690 print_status_struct status;
3692 count = print_queue_length(snum, &status);
3694 r->status = nt_printq_status(status.status);
3699 /********************************************************************
3700 * construct_printer_info7
3701 * fill a spoolss_PrinterInfo7 struct
3702 ********************************************************************/
3704 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
3705 Printer_entry *print_hnd,
3706 struct spoolss_PrinterInfo7 *r,
3709 struct auth_serversupplied_info *server_info;
3713 status = make_server_info_system(mem_ctx, &server_info);
3714 if (!NT_STATUS_IS_OK(status)) {
3715 DEBUG(0, ("construct_printer_info7: "
3716 "Could not create system server_info\n"));
3720 if (is_printer_published(mem_ctx, server_info, print_hnd->servername,
3721 lp_servicename(snum), &guid, NULL)) {
3722 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
3723 r->action = DSPRINT_PUBLISH;
3725 r->guid = talloc_strdup(mem_ctx, "");
3726 r->action = DSPRINT_UNPUBLISH;
3728 W_ERROR_HAVE_NO_MEMORY(r->guid);
3730 TALLOC_FREE(server_info);
3734 /********************************************************************
3735 * construct_printer_info8
3736 * fill a spoolss_PrinterInfo8 struct
3737 ********************************************************************/
3739 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
3740 const struct spoolss_PrinterInfo2 *info2,
3741 struct spoolss_DeviceModeInfo *r,
3744 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3746 DEBUG(8,("Returning NULL Devicemode!\n"));
3753 /********************************************************************
3754 ********************************************************************/
3756 static bool snum_is_shared_printer(int snum)
3758 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
3761 /********************************************************************
3762 Spoolss_enumprinters.
3763 ********************************************************************/
3765 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
3766 struct auth_serversupplied_info *server_info,
3769 union spoolss_PrinterInfo **info_p,
3773 int n_services = lp_numservices();
3774 union spoolss_PrinterInfo *info = NULL;
3776 WERROR result = WERR_OK;
3781 for (snum = 0; snum < n_services; snum++) {
3783 const char *printer;
3784 struct spoolss_PrinterInfo2 *info2;
3786 if (!snum_is_shared_printer(snum)) {
3790 printer = lp_const_servicename(snum);
3792 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
3795 result = winreg_create_printer(mem_ctx,
3799 if (!W_ERROR_IS_OK(result)) {
3803 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
3804 union spoolss_PrinterInfo,
3807 result = WERR_NOMEM;
3811 result = winreg_get_printer(mem_ctx, server_info,
3812 NULL, printer, &info2);
3813 if (!W_ERROR_IS_OK(result)) {
3819 result = construct_printer_info0(info, server_info, info2,
3820 &info[count].info0, snum);
3823 result = construct_printer_info1(info, info2, flags,
3824 &info[count].info1, snum);
3827 result = construct_printer_info2(info, info2,
3828 &info[count].info2, snum);
3831 result = construct_printer_info4(info, info2,
3832 &info[count].info4, snum);
3835 result = construct_printer_info5(info, info2,
3836 &info[count].info5, snum);
3840 result = WERR_UNKNOWN_LEVEL;
3844 if (!W_ERROR_IS_OK(result)) {
3855 if (!W_ERROR_IS_OK(result)) {
3865 /********************************************************************
3866 * handle enumeration of printers at level 0
3867 ********************************************************************/
3869 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
3870 struct auth_serversupplied_info *server_info,
3872 const char *servername,
3873 union spoolss_PrinterInfo **info,
3876 DEBUG(4,("enum_all_printers_info_0\n"));
3878 return enum_all_printers_info_level(mem_ctx, server_info, 0, flags, info, count);
3882 /********************************************************************
3883 ********************************************************************/
3885 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
3886 struct auth_serversupplied_info *server_info,
3888 union spoolss_PrinterInfo **info,
3891 DEBUG(4,("enum_all_printers_info_1\n"));
3893 return enum_all_printers_info_level(mem_ctx, server_info, 1, flags, info, count);
3896 /********************************************************************
3897 enum_all_printers_info_1_local.
3898 *********************************************************************/
3900 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
3901 struct auth_serversupplied_info *server_info,
3902 union spoolss_PrinterInfo **info,
3905 DEBUG(4,("enum_all_printers_info_1_local\n"));
3907 return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_ICON8, info, count);
3910 /********************************************************************
3911 enum_all_printers_info_1_name.
3912 *********************************************************************/
3914 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
3915 struct auth_serversupplied_info *server_info,
3917 union spoolss_PrinterInfo **info,
3920 const char *s = name;
3922 DEBUG(4,("enum_all_printers_info_1_name\n"));
3924 if ((name[0] == '\\') && (name[1] == '\\')) {
3928 if (!is_myname_or_ipaddr(s)) {
3929 return WERR_INVALID_NAME;
3932 return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_ICON8, info, count);
3935 /********************************************************************
3936 enum_all_printers_info_1_network.
3937 *********************************************************************/
3939 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
3940 struct auth_serversupplied_info *server_info,
3942 union spoolss_PrinterInfo **info,
3945 const char *s = name;
3947 DEBUG(4,("enum_all_printers_info_1_network\n"));
3949 /* If we respond to a enum_printers level 1 on our name with flags
3950 set to PRINTER_ENUM_REMOTE with a list of printers then these
3951 printers incorrectly appear in the APW browse list.
3952 Specifically the printers for the server appear at the workgroup
3953 level where all the other servers in the domain are
3954 listed. Windows responds to this call with a
3955 WERR_CAN_NOT_COMPLETE so we should do the same. */
3957 if (name[0] == '\\' && name[1] == '\\') {
3961 if (is_myname_or_ipaddr(s)) {
3962 return WERR_CAN_NOT_COMPLETE;
3965 return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_NAME, info, count);
3968 /********************************************************************
3969 * api_spoolss_enumprinters
3971 * called from api_spoolss_enumprinters (see this to understand)
3972 ********************************************************************/
3974 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
3975 struct auth_serversupplied_info *server_info,
3976 union spoolss_PrinterInfo **info,
3979 DEBUG(4,("enum_all_printers_info_2\n"));
3981 return enum_all_printers_info_level(mem_ctx, server_info, 2, 0, info, count);
3984 /********************************************************************
3985 * handle enumeration of printers at level 1
3986 ********************************************************************/
3988 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
3989 struct auth_serversupplied_info *server_info,
3992 union spoolss_PrinterInfo **info,
3995 /* Not all the flags are equals */
3997 if (flags & PRINTER_ENUM_LOCAL) {
3998 return enum_all_printers_info_1_local(mem_ctx, server_info, info, count);
4001 if (flags & PRINTER_ENUM_NAME) {
4002 return enum_all_printers_info_1_name(mem_ctx, server_info, name, info, count);
4005 if (flags & PRINTER_ENUM_NETWORK) {
4006 return enum_all_printers_info_1_network(mem_ctx, server_info, name, info, count);
4009 return WERR_OK; /* NT4sp5 does that */
4012 /********************************************************************
4013 * handle enumeration of printers at level 2
4014 ********************************************************************/
4016 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4017 struct auth_serversupplied_info *server_info,
4019 const char *servername,
4020 union spoolss_PrinterInfo **info,
4023 if (flags & PRINTER_ENUM_LOCAL) {
4024 return enum_all_printers_info_2(mem_ctx, server_info, info, count);
4027 if (flags & PRINTER_ENUM_NAME) {
4028 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4029 return WERR_INVALID_NAME;
4032 return enum_all_printers_info_2(mem_ctx, server_info, info, count);
4035 if (flags & PRINTER_ENUM_REMOTE) {
4036 return WERR_UNKNOWN_LEVEL;
4042 /********************************************************************
4043 * handle enumeration of printers at level 4
4044 ********************************************************************/
4046 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4047 struct auth_serversupplied_info *server_info,
4049 const char *servername,
4050 union spoolss_PrinterInfo **info,
4053 DEBUG(4,("enum_all_printers_info_4\n"));
4055 return enum_all_printers_info_level(mem_ctx, server_info, 4, flags, info, count);
4059 /********************************************************************
4060 * handle enumeration of printers at level 5
4061 ********************************************************************/
4063 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4064 struct auth_serversupplied_info *server_info,
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, server_info, 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, p->server_info,
4119 r->out.info, r->out.count);
4122 result = enumprinters_level1(p->mem_ctx, p->server_info,
4124 r->out.info, r->out.count);
4127 result = enumprinters_level2(p->mem_ctx, p->server_info,
4129 r->out.info, r->out.count);
4132 result = enumprinters_level4(p->mem_ctx, p->server_info,
4134 r->out.info, r->out.count);
4137 result = enumprinters_level5(p->mem_ctx, p->server_info,
4139 r->out.info, r->out.count);
4142 return WERR_UNKNOWN_LEVEL;
4145 if (!W_ERROR_IS_OK(result)) {
4149 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4150 spoolss_EnumPrinters,
4151 *r->out.info, r->in.level,
4153 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4154 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4156 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4159 /****************************************************************
4161 ****************************************************************/
4163 WERROR _spoolss_GetPrinter(pipes_struct *p,
4164 struct spoolss_GetPrinter *r)
4166 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4167 struct spoolss_PrinterInfo2 *info2 = NULL;
4168 WERROR result = WERR_OK;
4169 const char *servername = NULL;
4172 /* that's an [in out] buffer */
4174 if (!r->in.buffer && (r->in.offered != 0)) {
4175 return WERR_INVALID_PARAM;
4180 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4184 if (Printer != NULL || Printer->servername != NULL) {
4185 servername = Printer->servername;
4188 result = winreg_get_printer(p->mem_ctx,
4191 lp_const_servicename(snum),
4193 if (!W_ERROR_IS_OK(result)) {
4197 switch (r->in.level) {
4199 result = construct_printer_info0(p->mem_ctx, p->server_info,
4201 &r->out.info->info0, snum);
4204 result = construct_printer_info1(p->mem_ctx, info2,
4206 &r->out.info->info1, snum);
4209 result = construct_printer_info2(p->mem_ctx, info2,
4210 &r->out.info->info2, snum);
4213 result = construct_printer_info3(p->mem_ctx, info2,
4214 &r->out.info->info3, snum);
4217 result = construct_printer_info4(p->mem_ctx, info2,
4218 &r->out.info->info4, snum);
4221 result = construct_printer_info5(p->mem_ctx, info2,
4222 &r->out.info->info5, snum);
4225 result = construct_printer_info6(p->mem_ctx, info2,
4226 &r->out.info->info6, snum);
4229 result = construct_printer_info7(p->mem_ctx, Printer,
4230 &r->out.info->info7, snum);
4233 result = construct_printer_info8(p->mem_ctx, info2,
4234 &r->out.info->info8, snum);
4237 result = WERR_UNKNOWN_LEVEL;
4241 if (!W_ERROR_IS_OK(result)) {
4242 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4243 r->in.level, win_errstr(result)));
4244 TALLOC_FREE(r->out.info);
4248 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4249 r->out.info, r->in.level);
4250 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4252 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4255 /********************************************************************
4256 ********************************************************************/
4258 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4260 if (in && strlen(in)) { \
4261 out = talloc_strdup(mem_ctx, in); \
4262 W_ERROR_HAVE_NO_MEMORY(out); \
4268 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4270 if (in && strlen(in)) { \
4271 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4273 out = talloc_strdup(mem_ctx, ""); \
4275 W_ERROR_HAVE_NO_MEMORY(out); \
4278 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4279 const char **string_array,
4280 const char ***presult,
4281 const char *cservername,
4285 int i, num_strings = 0;
4286 const char **array = NULL;
4288 if (string_array == NULL) {
4289 return WERR_INVALID_PARAMETER;;
4292 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4293 const char *str = NULL;
4295 if (cservername == NULL || arch == NULL) {
4296 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4298 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4301 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4308 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4309 &array, &num_strings);
4319 /********************************************************************
4320 * fill a spoolss_DriverInfo1 struct
4321 ********************************************************************/
4323 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4324 struct spoolss_DriverInfo1 *r,
4325 const struct spoolss_DriverInfo8 *driver,
4326 const char *servername)
4328 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4329 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4334 /********************************************************************
4335 * fill a spoolss_DriverInfo2 struct
4336 ********************************************************************/
4338 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4339 struct spoolss_DriverInfo2 *r,
4340 const struct spoolss_DriverInfo8 *driver,
4341 const char *servername)
4344 const char *cservername = canon_servername(servername);
4346 r->version = driver->version;
4348 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4349 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4350 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4351 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4353 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4354 driver->architecture,
4356 driver->driver_path,
4359 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4360 driver->architecture,
4365 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4366 driver->architecture,
4368 driver->config_file,
4374 /********************************************************************
4375 * fill a spoolss_DriverInfo3 struct
4376 ********************************************************************/
4378 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4379 struct spoolss_DriverInfo3 *r,
4380 const struct spoolss_DriverInfo8 *driver,
4381 const char *servername)
4383 const char *cservername = canon_servername(servername);
4385 r->version = driver->version;
4387 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4388 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4389 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4390 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4392 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4393 driver->architecture,
4395 driver->driver_path,
4398 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4399 driver->architecture,
4404 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4405 driver->architecture,
4407 driver->config_file,
4410 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4411 driver->architecture,
4416 FILL_DRIVER_STRING(mem_ctx,
4417 driver->monitor_name,
4420 FILL_DRIVER_STRING(mem_ctx,
4421 driver->default_datatype,
4422 r->default_datatype);
4424 return string_array_from_driver_info(mem_ctx,
4425 driver->dependent_files,
4426 &r->dependent_files,
4428 driver->architecture,
4432 /********************************************************************
4433 * fill a spoolss_DriverInfo4 struct
4434 ********************************************************************/
4436 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4437 struct spoolss_DriverInfo4 *r,
4438 const struct spoolss_DriverInfo8 *driver,
4439 const char *servername)
4441 const char *cservername = canon_servername(servername);
4444 r->version = driver->version;
4446 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4447 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4448 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4449 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4451 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4452 driver->architecture,
4454 driver->driver_path,
4457 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4458 driver->architecture,
4463 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4464 driver->architecture,
4466 driver->config_file,
4469 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4470 driver->architecture,
4475 result = string_array_from_driver_info(mem_ctx,
4476 driver->dependent_files,
4477 &r->dependent_files,
4479 driver->architecture,
4481 if (!W_ERROR_IS_OK(result)) {
4485 FILL_DRIVER_STRING(mem_ctx,
4486 driver->monitor_name,
4489 FILL_DRIVER_STRING(mem_ctx,
4490 driver->default_datatype,
4491 r->default_datatype);
4494 result = string_array_from_driver_info(mem_ctx,
4495 driver->previous_names,
4502 /********************************************************************
4503 * fill a spoolss_DriverInfo5 struct
4504 ********************************************************************/
4506 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4507 struct spoolss_DriverInfo5 *r,
4508 const struct spoolss_DriverInfo8 *driver,
4509 const char *servername)
4511 const char *cservername = canon_servername(servername);
4513 r->version = driver->version;
4515 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4516 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4517 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4518 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4520 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4521 driver->architecture,
4523 driver->driver_path,
4526 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4527 driver->architecture,
4532 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4533 driver->architecture,
4535 driver->config_file,
4538 r->driver_attributes = 0;
4539 r->config_version = 0;
4540 r->driver_version = 0;
4544 /********************************************************************
4545 * fill a spoolss_DriverInfo6 struct
4546 ********************************************************************/
4548 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4549 struct spoolss_DriverInfo6 *r,
4550 const struct spoolss_DriverInfo8 *driver,
4551 const char *servername)
4553 const char *cservername = canon_servername(servername);
4556 r->version = driver->version;
4558 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4559 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4560 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4561 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4563 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4564 driver->architecture,
4566 driver->driver_path,
4569 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4570 driver->architecture,
4575 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4576 driver->architecture,
4578 driver->config_file,
4581 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4582 driver->architecture,
4587 FILL_DRIVER_STRING(mem_ctx,
4588 driver->monitor_name,
4591 FILL_DRIVER_STRING(mem_ctx,
4592 driver->default_datatype,
4593 r->default_datatype);
4595 result = string_array_from_driver_info(mem_ctx,
4596 driver->dependent_files,
4597 &r->dependent_files,
4599 driver->architecture,
4601 if (!W_ERROR_IS_OK(result)) {
4605 result = string_array_from_driver_info(mem_ctx,
4606 driver->previous_names,
4609 if (!W_ERROR_IS_OK(result)) {
4613 r->driver_date = driver->driver_date;
4614 r->driver_version = driver->driver_version;
4616 FILL_DRIVER_STRING(mem_ctx,
4617 driver->manufacturer_name,
4618 r->manufacturer_name);
4619 FILL_DRIVER_STRING(mem_ctx,
4620 driver->manufacturer_url,
4621 r->manufacturer_url);
4622 FILL_DRIVER_STRING(mem_ctx,
4623 driver->hardware_id,
4625 FILL_DRIVER_STRING(mem_ctx,
4632 /********************************************************************
4633 * fill a spoolss_DriverInfo8 struct
4634 ********************************************************************/
4636 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
4637 struct spoolss_DriverInfo8 *r,
4638 const struct spoolss_DriverInfo8 *driver,
4639 const char *servername)
4641 const char *cservername = canon_servername(servername);
4644 r->version = driver->version;
4646 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4647 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4648 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4649 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4651 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4652 driver->architecture,
4654 driver->driver_path,
4657 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4658 driver->architecture,
4663 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4664 driver->architecture,
4666 driver->config_file,
4669 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4670 driver->architecture,
4675 FILL_DRIVER_STRING(mem_ctx,
4676 driver->monitor_name,
4679 FILL_DRIVER_STRING(mem_ctx,
4680 driver->default_datatype,
4681 r->default_datatype);
4683 result = string_array_from_driver_info(mem_ctx,
4684 driver->dependent_files,
4685 &r->dependent_files,
4687 driver->architecture,
4689 if (!W_ERROR_IS_OK(result)) {
4693 result = string_array_from_driver_info(mem_ctx,
4694 driver->previous_names,
4697 if (!W_ERROR_IS_OK(result)) {
4701 r->driver_date = driver->driver_date;
4702 r->driver_version = driver->driver_version;
4704 FILL_DRIVER_STRING(mem_ctx,
4705 driver->manufacturer_name,
4706 r->manufacturer_name);
4707 FILL_DRIVER_STRING(mem_ctx,
4708 driver->manufacturer_url,
4709 r->manufacturer_url);
4710 FILL_DRIVER_STRING(mem_ctx,
4711 driver->hardware_id,
4713 FILL_DRIVER_STRING(mem_ctx,
4717 FILL_DRIVER_STRING(mem_ctx,
4718 driver->print_processor,
4719 r->print_processor);
4720 FILL_DRIVER_STRING(mem_ctx,
4721 driver->vendor_setup,
4724 result = string_array_from_driver_info(mem_ctx,
4725 driver->color_profiles,
4728 if (!W_ERROR_IS_OK(result)) {
4732 FILL_DRIVER_STRING(mem_ctx,
4736 r->printer_driver_attributes = driver->printer_driver_attributes;
4738 result = string_array_from_driver_info(mem_ctx,
4739 driver->core_driver_dependencies,
4740 &r->core_driver_dependencies,
4742 if (!W_ERROR_IS_OK(result)) {
4746 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
4747 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
4752 #if 0 /* disabled until marshalling issues are resolved - gd */
4753 /********************************************************************
4754 ********************************************************************/
4756 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
4757 struct spoolss_DriverFileInfo *r,
4758 const char *cservername,
4759 const char *file_name,
4760 enum spoolss_DriverFileType file_type,
4761 uint32_t file_version)
4763 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
4764 cservername, file_name);
4765 W_ERROR_HAVE_NO_MEMORY(r->file_name);
4766 r->file_type = file_type;
4767 r->file_version = file_version;
4772 /********************************************************************
4773 ********************************************************************/
4775 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
4776 const struct spoolss_DriverInfo8 *driver,
4777 const char *cservername,
4778 struct spoolss_DriverFileInfo **info_p,
4781 struct spoolss_DriverFileInfo *info = NULL;
4789 if (strlen(driver->driver_path)) {
4790 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4791 struct spoolss_DriverFileInfo,
4793 W_ERROR_HAVE_NO_MEMORY(info);
4794 result = fill_spoolss_DriverFileInfo(info,
4797 driver->driver_path,
4798 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
4800 W_ERROR_NOT_OK_RETURN(result);
4804 if (strlen(driver->config_file)) {
4805 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4806 struct spoolss_DriverFileInfo,
4808 W_ERROR_HAVE_NO_MEMORY(info);
4809 result = fill_spoolss_DriverFileInfo(info,
4812 driver->config_file,
4813 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
4815 W_ERROR_NOT_OK_RETURN(result);
4819 if (strlen(driver->data_file)) {
4820 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4821 struct spoolss_DriverFileInfo,
4823 W_ERROR_HAVE_NO_MEMORY(info);
4824 result = fill_spoolss_DriverFileInfo(info,
4828 SPOOLSS_DRIVER_FILE_TYPE_DATA,
4830 W_ERROR_NOT_OK_RETURN(result);
4834 if (strlen(driver->help_file)) {
4835 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4836 struct spoolss_DriverFileInfo,
4838 W_ERROR_HAVE_NO_MEMORY(info);
4839 result = fill_spoolss_DriverFileInfo(info,
4843 SPOOLSS_DRIVER_FILE_TYPE_HELP,
4845 W_ERROR_NOT_OK_RETURN(result);
4849 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
4850 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4851 struct spoolss_DriverFileInfo,
4853 W_ERROR_HAVE_NO_MEMORY(info);
4854 result = fill_spoolss_DriverFileInfo(info,
4857 driver->dependent_files[i],
4858 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
4860 W_ERROR_NOT_OK_RETURN(result);
4870 /********************************************************************
4871 * fill a spoolss_DriverInfo101 struct
4872 ********************************************************************/
4874 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
4875 struct spoolss_DriverInfo101 *r,
4876 const struct spoolss_DriverInfo8 *driver,
4877 const char *servername)
4879 const char *cservername = canon_servername(servername);
4882 r->version = driver->version;
4884 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4885 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4886 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4887 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4889 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
4893 if (!W_ERROR_IS_OK(result)) {
4897 FILL_DRIVER_STRING(mem_ctx,
4898 driver->monitor_name,
4901 FILL_DRIVER_STRING(mem_ctx,
4902 driver->default_datatype,
4903 r->default_datatype);
4905 result = string_array_from_driver_info(mem_ctx,
4906 driver->previous_names,
4909 if (!W_ERROR_IS_OK(result)) {
4913 r->driver_date = driver->driver_date;
4914 r->driver_version = driver->driver_version;
4916 FILL_DRIVER_STRING(mem_ctx,
4917 driver->manufacturer_name,
4918 r->manufacturer_name);
4919 FILL_DRIVER_STRING(mem_ctx,
4920 driver->manufacturer_url,
4921 r->manufacturer_url);
4922 FILL_DRIVER_STRING(mem_ctx,
4923 driver->hardware_id,
4925 FILL_DRIVER_STRING(mem_ctx,
4932 /********************************************************************
4933 ********************************************************************/
4935 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
4936 struct auth_serversupplied_info *server_info,
4938 union spoolss_DriverInfo *r,
4940 const char *servername,
4941 const char *architecture,
4944 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
4945 struct spoolss_DriverInfo8 *driver;
4948 result = winreg_get_printer(mem_ctx,
4951 lp_const_servicename(snum),
4954 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
4955 win_errstr(result)));
4957 if (!W_ERROR_IS_OK(result)) {
4958 return WERR_INVALID_PRINTER_NAME;
4961 result = winreg_get_driver(mem_ctx, server_info, architecture,
4962 pinfo2->drivername, version, &driver);
4964 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
4965 win_errstr(result)));
4967 if (!W_ERROR_IS_OK(result)) {
4969 * Is this a W2k client ?
4973 talloc_free(pinfo2);
4974 return WERR_UNKNOWN_PRINTER_DRIVER;
4977 /* Yes - try again with a WinNT driver. */
4979 result = winreg_get_driver(mem_ctx, server_info, architecture,
4982 DEBUG(8,("construct_printer_driver_level: status: %s\n",
4983 win_errstr(result)));
4984 if (!W_ERROR_IS_OK(result)) {
4985 talloc_free(pinfo2);
4986 return WERR_UNKNOWN_PRINTER_DRIVER;
4992 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
4995 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
4998 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5001 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5004 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5007 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5010 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5012 #if 0 /* disabled until marshalling issues are resolved - gd */
5014 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5018 result = WERR_UNKNOWN_LEVEL;
5022 talloc_free(pinfo2);
5023 talloc_free(driver);
5028 /****************************************************************
5029 _spoolss_GetPrinterDriver2
5030 ****************************************************************/
5032 WERROR _spoolss_GetPrinterDriver2(pipes_struct *p,
5033 struct spoolss_GetPrinterDriver2 *r)
5035 Printer_entry *printer;
5040 /* that's an [in out] buffer */
5042 if (!r->in.buffer && (r->in.offered != 0)) {
5043 return WERR_INVALID_PARAM;
5046 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5048 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5049 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5050 return WERR_INVALID_PRINTER_NAME;
5054 *r->out.server_major_version = 0;
5055 *r->out.server_minor_version = 0;
5057 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5061 result = construct_printer_driver_info_level(p->mem_ctx, p->server_info,
5062 r->in.level, r->out.info,
5063 snum, printer->servername,
5065 r->in.client_major_version);
5066 if (!W_ERROR_IS_OK(result)) {
5067 TALLOC_FREE(r->out.info);
5071 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5072 r->out.info, r->in.level);
5073 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5075 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5079 /****************************************************************
5080 _spoolss_StartPagePrinter
5081 ****************************************************************/
5083 WERROR _spoolss_StartPagePrinter(pipes_struct *p,
5084 struct spoolss_StartPagePrinter *r)
5086 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5089 DEBUG(3,("_spoolss_StartPagePrinter: "
5090 "Error in startpageprinter printer handle\n"));
5094 Printer->page_started = true;
5098 /****************************************************************
5099 _spoolss_EndPagePrinter
5100 ****************************************************************/
5102 WERROR _spoolss_EndPagePrinter(pipes_struct *p,
5103 struct spoolss_EndPagePrinter *r)
5107 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5110 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5111 OUR_HANDLE(r->in.handle)));
5115 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5118 Printer->page_started = false;
5119 print_job_endpage(snum, Printer->jobid);
5124 /****************************************************************
5125 _spoolss_StartDocPrinter
5126 ****************************************************************/
5128 WERROR _spoolss_StartDocPrinter(pipes_struct *p,
5129 struct spoolss_StartDocPrinter *r)
5131 struct spoolss_DocumentInfo1 *info_1;
5133 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5137 DEBUG(2,("_spoolss_StartDocPrinter: "
5138 "Invalid handle (%s:%u:%u)\n",
5139 OUR_HANDLE(r->in.handle)));
5143 if (Printer->jobid) {
5144 DEBUG(2, ("_spoolss_StartDocPrinter: "
5145 "StartDocPrinter called twice! "
5146 "(existing jobid = %d)\n", Printer->jobid));
5147 return WERR_INVALID_HANDLE;
5150 if (r->in.level != 1) {
5151 return WERR_UNKNOWN_LEVEL;
5154 info_1 = r->in.info.info1;
5157 * a nice thing with NT is it doesn't listen to what you tell it.
5158 * when asked to send _only_ RAW datas, it tries to send datas
5161 * So I add checks like in NT Server ...
5164 if (info_1->datatype) {
5165 if (strcmp(info_1->datatype, "RAW") != 0) {
5167 return WERR_INVALID_DATATYPE;
5171 /* get the share number of the printer */
5172 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5176 werr = print_job_start(p->server_info, snum,
5177 info_1->document_name, info_1->output_file,
5178 Printer->devmode, &Printer->jobid);
5180 /* An error occured in print_job_start() so return an appropriate
5183 if (!W_ERROR_IS_OK(werr)) {
5187 Printer->document_started = true;
5188 *r->out.job_id = Printer->jobid;
5193 /****************************************************************
5194 _spoolss_EndDocPrinter
5195 ****************************************************************/
5197 WERROR _spoolss_EndDocPrinter(pipes_struct *p,
5198 struct spoolss_EndDocPrinter *r)
5200 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5205 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5206 OUR_HANDLE(r->in.handle)));
5210 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5214 Printer->document_started = false;
5215 status = print_job_end(snum, Printer->jobid, NORMAL_CLOSE);
5216 if (!NT_STATUS_IS_OK(status)) {
5217 DEBUG(2, ("_spoolss_EndDocPrinter: "
5218 "print_job_end failed [%s]\n",
5219 nt_errstr(status)));
5223 return ntstatus_to_werror(status);
5226 /****************************************************************
5227 _spoolss_WritePrinter
5228 ****************************************************************/
5230 WERROR _spoolss_WritePrinter(pipes_struct *p,
5231 struct spoolss_WritePrinter *r)
5233 ssize_t buffer_written;
5235 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5238 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5239 OUR_HANDLE(r->in.handle)));
5240 *r->out.num_written = r->in._data_size;
5244 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5247 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5248 buffer_written = print_job_write(snum, Printer->jobid,
5249 (const char *)r->in.data.data,
5251 (size_t)r->in._data_size);
5252 if (buffer_written == (ssize_t)-1) {
5253 *r->out.num_written = 0;
5254 if (errno == ENOSPC)
5255 return WERR_NO_SPOOL_SPACE;
5257 return WERR_ACCESS_DENIED;
5260 *r->out.num_written = r->in._data_size;
5265 /********************************************************************
5266 * api_spoolss_getprinter
5267 * called from the spoolss dispatcher
5269 ********************************************************************/
5271 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5275 WERROR errcode = WERR_BADFUNC;
5276 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5279 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5280 OUR_HANDLE(handle)));
5284 if (!get_printer_snum(p, handle, &snum, NULL))
5288 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5289 errcode = print_queue_pause(p->server_info, snum);
5291 case SPOOLSS_PRINTER_CONTROL_RESUME:
5292 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5293 errcode = print_queue_resume(p->server_info, snum);
5295 case SPOOLSS_PRINTER_CONTROL_PURGE:
5296 errcode = print_queue_purge(p->server_info, snum);
5299 return WERR_UNKNOWN_LEVEL;
5306 /****************************************************************
5307 _spoolss_AbortPrinter
5308 * From MSDN: "Deletes printer's spool file if printer is configured
5310 ****************************************************************/
5312 WERROR _spoolss_AbortPrinter(pipes_struct *p,
5313 struct spoolss_AbortPrinter *r)
5315 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5317 WERROR errcode = WERR_OK;
5320 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5321 OUR_HANDLE(r->in.handle)));
5325 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5328 if (!Printer->document_started) {
5329 return WERR_SPL_NO_STARTDOC;
5332 errcode = print_job_delete(p->server_info, snum, Printer->jobid);
5337 /********************************************************************
5338 * called by spoolss_api_setprinter
5339 * when updating a printer description
5340 ********************************************************************/
5342 static WERROR update_printer_sec(struct policy_handle *handle,
5343 pipes_struct *p, struct sec_desc_buf *secdesc_ctr)
5345 struct spoolss_security_descriptor *new_secdesc = NULL;
5346 struct spoolss_security_descriptor *old_secdesc = NULL;
5347 const char *printer;
5351 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5353 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5354 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5355 OUR_HANDLE(handle)));
5357 result = WERR_BADFID;
5361 if (secdesc_ctr == NULL) {
5362 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5363 result = WERR_INVALID_PARAM;
5366 printer = lp_const_servicename(snum);
5368 /* Check the user has permissions to change the security
5369 descriptor. By experimentation with two NT machines, the user
5370 requires Full Access to the printer to change security
5373 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5374 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5375 result = WERR_ACCESS_DENIED;
5379 /* NT seems to like setting the security descriptor even though
5380 nothing may have actually changed. */
5381 result = winreg_get_printer_secdesc(p->mem_ctx,
5385 if (!W_ERROR_IS_OK(result)) {
5386 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5387 result = WERR_BADFID;
5391 if (DEBUGLEVEL >= 10) {
5392 struct security_acl *the_acl;
5395 the_acl = secdesc_ctr->sd->dacl;
5396 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5397 printer, the_acl->num_aces));
5399 for (i = 0; i < the_acl->num_aces; i++) {
5400 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5401 &the_acl->aces[i].trustee),
5402 the_acl->aces[i].access_mask));
5405 the_acl = secdesc_ctr->sd->dacl;
5408 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5409 printer, the_acl->num_aces));
5411 for (i = 0; i < the_acl->num_aces; i++) {
5412 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5413 &the_acl->aces[i].trustee),
5414 the_acl->aces[i].access_mask));
5417 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5421 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
5422 if (new_secdesc == NULL) {
5423 result = WERR_NOMEM;
5427 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
5432 result = winreg_set_printer_secdesc(p->mem_ctx,
5441 /********************************************************************
5442 Canonicalize printer info from a client
5443 ********************************************************************/
5445 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
5446 struct spoolss_SetPrinterInfo2 *info2,
5449 fstring printername;
5452 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5453 "portname=%s drivername=%s comment=%s location=%s\n",
5454 info2->servername, info2->printername, info2->sharename,
5455 info2->portname, info2->drivername, info2->comment,
5458 /* we force some elements to "correct" values */
5459 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
5460 if (info2->servername == NULL) {
5463 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
5464 if (info2->sharename == NULL) {
5468 /* check to see if we allow printername != sharename */
5469 if (lp_force_printername(snum)) {
5470 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5471 global_myname(), info2->sharename);
5473 /* make sure printername is in \\server\printername format */
5474 fstrcpy(printername, info2->printername);
5476 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5477 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5481 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5482 global_myname(), p);
5484 if (info2->printername == NULL) {
5488 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5489 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5494 /****************************************************************************
5495 ****************************************************************************/
5497 static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri)
5499 char *cmd = lp_addport_cmd();
5500 char *command = NULL;
5502 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5503 bool is_print_op = false;
5506 return WERR_ACCESS_DENIED;
5509 command = talloc_asprintf(ctx,
5510 "%s \"%s\" \"%s\"", cmd, portname, uri );
5516 is_print_op = user_has_privileges( token, &se_printop );
5518 DEBUG(10,("Running [%s]\n", command));
5520 /********* BEGIN SePrintOperatorPrivilege **********/
5525 ret = smbrun(command, NULL);
5530 /********* END SePrintOperatorPrivilege **********/
5532 DEBUGADD(10,("returned [%d]\n", ret));
5534 TALLOC_FREE(command);
5537 return WERR_ACCESS_DENIED;
5543 /****************************************************************************
5544 ****************************************************************************/
5546 bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
5547 struct spoolss_SetPrinterInfo2 *info2,
5548 const char *remote_machine)
5550 char *cmd = lp_addprinter_cmd();
5552 char *command = NULL;
5556 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5557 bool is_print_op = false;
5559 if (!remote_machine) {
5563 command = talloc_asprintf(ctx,
5564 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5565 cmd, info2->printername, info2->sharename,
5566 info2->portname, info2->drivername,
5567 info2->location, info2->comment, remote_machine);
5573 is_print_op = user_has_privileges( token, &se_printop );
5575 DEBUG(10,("Running [%s]\n", command));
5577 /********* BEGIN SePrintOperatorPrivilege **********/
5582 if ( (ret = smbrun(command, &fd)) == 0 ) {
5583 /* Tell everyone we updated smb.conf. */
5584 message_send_all(smbd_messaging_context(),
5585 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5591 /********* END SePrintOperatorPrivilege **********/
5593 DEBUGADD(10,("returned [%d]\n", ret));
5595 TALLOC_FREE(command);
5603 /* reload our services immediately */
5605 reload_services(false);
5609 /* Get lines and convert them back to dos-codepage */
5610 qlines = fd_lines_load(fd, &numlines, 0, NULL);
5611 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
5614 /* Set the portname to what the script says the portname should be. */
5615 /* but don't require anything to be return from the script exit a good error code */
5618 /* Set the portname to what the script says the portname should be. */
5619 info2->portname = talloc_strdup(ctx, qlines[0]);
5620 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
5623 TALLOC_FREE(qlines);
5627 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
5628 struct auth_serversupplied_info *server_info,
5630 struct spoolss_SetPrinterInfo2 *printer,
5631 struct spoolss_PrinterInfo2 *old_printer)
5633 bool force_update = (old_printer == NULL);
5634 const char *dnsdomname;
5635 const char *longname;
5636 const char *uncname;
5637 const char *spooling;
5639 WERROR result = WERR_OK;
5641 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
5642 push_reg_sz(mem_ctx, &buffer, printer->drivername);
5643 winreg_set_printer_dataex(mem_ctx,
5646 SPOOL_DSSPOOLER_KEY,
5647 SPOOL_REG_DRIVERNAME,
5652 if (!force_update) {
5653 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
5654 printer->drivername));
5656 notify_printer_driver(snum, printer->drivername);
5660 if (force_update || !strequal(printer->comment, old_printer->comment)) {
5661 push_reg_sz(mem_ctx, &buffer, printer->comment);
5662 winreg_set_printer_dataex(mem_ctx,
5665 SPOOL_DSSPOOLER_KEY,
5666 SPOOL_REG_DESCRIPTION,
5671 if (!force_update) {
5672 notify_printer_comment(snum, printer->comment);
5676 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
5677 push_reg_sz(mem_ctx, &buffer, printer->sharename);
5678 winreg_set_printer_dataex(mem_ctx,
5681 SPOOL_DSSPOOLER_KEY,
5682 SPOOL_REG_PRINTSHARENAME,
5687 if (!force_update) {
5688 notify_printer_sharename(snum, printer->sharename);
5692 if (force_update || !strequal(printer->printername, old_printer->printername)) {
5695 p = strrchr(printer->printername, '\\' );
5699 p = printer->printername;
5702 push_reg_sz(mem_ctx, &buffer, p);
5703 winreg_set_printer_dataex(mem_ctx,
5706 SPOOL_DSSPOOLER_KEY,
5707 SPOOL_REG_PRINTERNAME,
5712 if (!force_update) {
5713 notify_printer_printername(snum, p);
5717 if (force_update || !strequal(printer->portname, old_printer->portname)) {
5718 push_reg_sz(mem_ctx, &buffer, printer->portname);
5719 winreg_set_printer_dataex(mem_ctx,
5722 SPOOL_DSSPOOLER_KEY,
5728 if (!force_update) {
5729 notify_printer_port(snum, printer->portname);
5733 if (force_update || !strequal(printer->location, old_printer->location)) {
5734 push_reg_sz(mem_ctx, &buffer, printer->location);
5735 winreg_set_printer_dataex(mem_ctx,
5738 SPOOL_DSSPOOLER_KEY,
5744 if (!force_update) {
5745 notify_printer_location(snum, printer->location);
5749 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
5750 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
5751 winreg_set_printer_dataex(mem_ctx,
5754 SPOOL_DSSPOOLER_KEY,
5755 SPOOL_REG_PRINTSEPARATORFILE,
5760 if (!force_update) {
5761 notify_printer_location(snum, printer->location);
5765 if (force_update || printer->starttime != old_printer->starttime) {
5766 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5767 SIVAL(buffer.data, 0, printer->starttime);
5768 winreg_set_printer_dataex(mem_ctx,
5771 SPOOL_DSSPOOLER_KEY,
5772 SPOOL_REG_PRINTSTARTTIME,
5778 if (force_update || printer->untiltime != old_printer->untiltime) {
5779 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5780 SIVAL(buffer.data, 0, printer->untiltime);
5781 winreg_set_printer_dataex(mem_ctx,
5784 SPOOL_DSSPOOLER_KEY,
5785 SPOOL_REG_PRINTENDTIME,
5791 if (force_update || printer->priority != old_printer->priority) {
5792 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5793 SIVAL(buffer.data, 0, printer->priority);
5794 winreg_set_printer_dataex(mem_ctx,
5797 SPOOL_DSSPOOLER_KEY,
5804 if (force_update || printer->attributes != old_printer->attributes) {
5805 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5806 SIVAL(buffer.data, 0, (printer->attributes &
5807 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
5808 winreg_set_printer_dataex(mem_ctx,
5811 SPOOL_DSSPOOLER_KEY,
5812 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
5817 switch (printer->attributes & 0x3) {
5819 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
5822 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
5825 spooling = SPOOL_REGVAL_PRINTDIRECT;
5828 spooling = "unknown";
5830 push_reg_sz(mem_ctx, &buffer, spooling);
5831 winreg_set_printer_dataex(mem_ctx,
5834 SPOOL_DSSPOOLER_KEY,
5835 SPOOL_REG_PRINTSPOOLING,
5841 push_reg_sz(mem_ctx, &buffer, global_myname());
5842 winreg_set_printer_dataex(mem_ctx,
5845 SPOOL_DSSPOOLER_KEY,
5846 SPOOL_REG_SHORTSERVERNAME,
5851 dnsdomname = get_mydnsfullname();
5852 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
5853 longname = talloc_strdup(mem_ctx, dnsdomname);
5855 longname = talloc_strdup(mem_ctx, global_myname());
5857 if (longname == NULL) {
5858 result = WERR_NOMEM;
5862 push_reg_sz(mem_ctx, &buffer, longname);
5863 winreg_set_printer_dataex(mem_ctx,
5866 SPOOL_DSSPOOLER_KEY,
5867 SPOOL_REG_SERVERNAME,
5872 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5873 global_myname(), printer->sharename);
5874 push_reg_sz(mem_ctx, &buffer, uncname);
5875 winreg_set_printer_dataex(mem_ctx,
5878 SPOOL_DSSPOOLER_KEY,
5888 /********************************************************************
5889 * Called by spoolss_api_setprinter
5890 * when updating a printer description.
5891 ********************************************************************/
5893 static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
5894 struct spoolss_SetPrinterInfoCtr *info_ctr,
5895 struct spoolss_DeviceMode *devmode)
5897 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
5898 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
5899 struct spoolss_PrinterInfo2 *old_printer;
5900 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5901 const char *servername = NULL;
5903 WERROR result = WERR_OK;
5904 TALLOC_CTX *tmp_ctx;
5906 DEBUG(8,("update_printer\n"));
5908 tmp_ctx = talloc_new(p->mem_ctx);
5909 if (tmp_ctx == NULL) {
5914 result = WERR_BADFID;
5918 if (!get_printer_snum(p, handle, &snum, NULL)) {
5919 result = WERR_BADFID;
5923 if (Printer != NULL || Printer->servername != NULL) {
5924 servername = Printer->servername;
5927 result = winreg_get_printer(tmp_ctx,
5930 lp_const_servicename(snum),
5932 if (!W_ERROR_IS_OK(result)) {
5933 result = WERR_BADFID;
5937 /* Do sanity check on the requested changes for Samba */
5938 if (!check_printer_ok(tmp_ctx, printer, snum)) {
5939 result = WERR_INVALID_PARAM;
5943 /* FIXME!!! If the driver has changed we really should verify that
5944 it is installed before doing much else --jerry */
5946 /* Check calling user has permission to update printer description */
5947 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
5948 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
5949 result = WERR_ACCESS_DENIED;
5953 /* Call addprinter hook */
5954 /* Check changes to see if this is really needed */
5956 if (*lp_addprinter_cmd() &&
5957 (!strequal(printer->drivername, old_printer->drivername) ||
5958 !strequal(printer->comment, old_printer->comment) ||
5959 !strequal(printer->portname, old_printer->portname) ||
5960 !strequal(printer->location, old_printer->location)) )
5962 /* add_printer_hook() will call reload_services() */
5963 if (!add_printer_hook(tmp_ctx, p->server_info->ptok,
5964 printer, p->client_address) ) {
5965 result = WERR_ACCESS_DENIED;
5970 update_dsspooler(tmp_ctx,
5976 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
5978 if (devmode == NULL) {
5979 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
5981 result = winreg_update_printer(tmp_ctx,
5990 talloc_free(tmp_ctx);
5995 /****************************************************************************
5996 ****************************************************************************/
5997 static WERROR publish_or_unpublish_printer(pipes_struct *p,
5998 struct policy_handle *handle,
5999 struct spoolss_SetPrinterInfo7 *info7)
6002 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6005 Printer_entry *Printer;
6007 if ( lp_security() != SEC_ADS ) {
6008 return WERR_UNKNOWN_LEVEL;
6011 Printer = find_printer_index_by_hnd(p, handle);
6013 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6018 if (!get_printer_snum(p, handle, &snum, NULL))
6021 result = winreg_get_printer(p->mem_ctx, p->server_info,
6022 Printer->servername,
6023 lp_servicename(snum), &pinfo2);
6024 if (!W_ERROR_IS_OK(result)) {
6028 nt_printer_publish(pinfo2, p->server_info, pinfo2, info7->action);
6030 TALLOC_FREE(pinfo2);
6033 return WERR_UNKNOWN_LEVEL;
6037 /********************************************************************
6038 ********************************************************************/
6040 static WERROR update_printer_devmode(pipes_struct *p, struct policy_handle *handle,
6041 struct spoolss_DeviceMode *devmode)
6044 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6045 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6047 DEBUG(8,("update_printer_devmode\n"));
6053 if (!get_printer_snum(p, handle, &snum, NULL)) {
6057 /* Check calling user has permission to update printer description */
6058 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6059 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6060 return WERR_ACCESS_DENIED;
6063 return winreg_update_printer(p->mem_ctx,
6065 lp_const_servicename(snum),
6073 /****************************************************************
6075 ****************************************************************/
6077 WERROR _spoolss_SetPrinter(pipes_struct *p,
6078 struct spoolss_SetPrinter *r)
6082 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6085 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6086 OUR_HANDLE(r->in.handle)));
6090 /* check the level */
6091 switch (r->in.info_ctr->level) {
6093 return control_printer(r->in.handle, r->in.command, p);
6095 result = update_printer(p, r->in.handle,
6097 r->in.devmode_ctr->devmode);
6098 if (!W_ERROR_IS_OK(result))
6100 if (r->in.secdesc_ctr->sd)
6101 result = update_printer_sec(r->in.handle, p,
6105 return update_printer_sec(r->in.handle, p,
6108 return publish_or_unpublish_printer(p, r->in.handle,
6109 r->in.info_ctr->info.info7);
6111 return update_printer_devmode(p, r->in.handle,
6112 r->in.devmode_ctr->devmode);
6114 return WERR_UNKNOWN_LEVEL;
6118 /****************************************************************
6119 _spoolss_FindClosePrinterNotify
6120 ****************************************************************/
6122 WERROR _spoolss_FindClosePrinterNotify(pipes_struct *p,
6123 struct spoolss_FindClosePrinterNotify *r)
6125 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6128 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6129 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6133 if (Printer->notify.client_connected == true) {
6136 if ( Printer->printer_type == SPLHND_SERVER)
6138 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6139 !get_printer_snum(p, r->in.handle, &snum, NULL) )
6142 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
6145 Printer->notify.flags=0;
6146 Printer->notify.options=0;
6147 Printer->notify.localmachine[0]='\0';
6148 Printer->notify.printerlocal=0;
6149 TALLOC_FREE(Printer->notify.option);
6150 Printer->notify.client_connected = false;
6155 /****************************************************************
6157 ****************************************************************/
6159 WERROR _spoolss_AddJob(pipes_struct *p,
6160 struct spoolss_AddJob *r)
6162 if (!r->in.buffer && (r->in.offered != 0)) {
6163 return WERR_INVALID_PARAM;
6166 /* this is what a NT server returns for AddJob. AddJob must fail on
6167 * non-local printers */
6169 if (r->in.level != 1) {
6170 return WERR_UNKNOWN_LEVEL;
6173 return WERR_INVALID_PARAM;
6176 /****************************************************************************
6178 ****************************************************************************/
6180 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6181 struct spoolss_JobInfo1 *r,
6182 const print_queue_struct *queue,
6183 int position, int snum,
6184 struct spoolss_PrinterInfo2 *pinfo2)
6188 t = gmtime(&queue->time);
6190 r->job_id = queue->job;
6192 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6193 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6194 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6195 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6196 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6197 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6198 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6199 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6200 r->data_type = talloc_strdup(mem_ctx, "RAW");
6201 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6202 r->text_status = talloc_strdup(mem_ctx, "");
6203 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6205 r->status = nt_printj_status(queue->status);
6206 r->priority = queue->priority;
6207 r->position = position;
6208 r->total_pages = queue->page_count;
6209 r->pages_printed = 0; /* ??? */
6211 init_systemtime(&r->submitted, t);
6216 /****************************************************************************
6218 ****************************************************************************/
6220 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6221 struct spoolss_JobInfo2 *r,
6222 const print_queue_struct *queue,
6223 int position, int snum,
6224 struct spoolss_PrinterInfo2 *pinfo2,
6225 struct spoolss_DeviceMode *devmode)
6229 t = gmtime(&queue->time);
6231 r->job_id = queue->job;
6233 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6234 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6235 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6236 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6237 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6238 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6239 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6240 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6241 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6242 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6243 r->data_type = talloc_strdup(mem_ctx, "RAW");
6244 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6245 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6246 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6247 r->parameters = talloc_strdup(mem_ctx, "");
6248 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6249 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6250 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6252 r->devmode = devmode;
6254 r->text_status = talloc_strdup(mem_ctx, "");
6255 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6259 r->status = nt_printj_status(queue->status);
6260 r->priority = queue->priority;
6261 r->position = position;
6264 r->total_pages = queue->page_count;
6265 r->size = queue->size;
6266 init_systemtime(&r->submitted, t);
6268 r->pages_printed = 0; /* ??? */
6273 /****************************************************************************
6275 ****************************************************************************/
6277 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6278 struct spoolss_JobInfo3 *r,
6279 const print_queue_struct *queue,
6280 const print_queue_struct *next_queue,
6281 int position, int snum,
6282 struct spoolss_PrinterInfo2 *pinfo2)
6284 r->job_id = queue->job;
6287 r->next_job_id = next_queue->job;
6294 /****************************************************************************
6295 Enumjobs at level 1.
6296 ****************************************************************************/
6298 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6299 const print_queue_struct *queue,
6300 uint32_t num_queues, int snum,
6301 struct spoolss_PrinterInfo2 *pinfo2,
6302 union spoolss_JobInfo **info_p,
6305 union spoolss_JobInfo *info;
6307 WERROR result = WERR_OK;
6309 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6310 W_ERROR_HAVE_NO_MEMORY(info);
6312 *count = num_queues;
6314 for (i=0; i<*count; i++) {
6315 result = fill_job_info1(info,
6321 if (!W_ERROR_IS_OK(result)) {
6327 if (!W_ERROR_IS_OK(result)) {
6338 /****************************************************************************
6339 Enumjobs at level 2.
6340 ****************************************************************************/
6342 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6343 const print_queue_struct *queue,
6344 uint32_t num_queues, int snum,
6345 struct spoolss_PrinterInfo2 *pinfo2,
6346 union spoolss_JobInfo **info_p,
6349 union spoolss_JobInfo *info;
6351 WERROR result = WERR_OK;
6353 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6354 W_ERROR_HAVE_NO_MEMORY(info);
6356 *count = num_queues;
6358 for (i=0; i<*count; i++) {
6359 struct spoolss_DeviceMode *devmode;
6361 result = spoolss_create_default_devmode(info,
6362 pinfo2->printername,
6364 if (!W_ERROR_IS_OK(result)) {
6365 DEBUG(3, ("Can't proceed w/o a devmode!"));
6369 result = fill_job_info2(info,
6376 if (!W_ERROR_IS_OK(result)) {
6382 if (!W_ERROR_IS_OK(result)) {
6393 /****************************************************************************
6394 Enumjobs at level 3.
6395 ****************************************************************************/
6397 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6398 const print_queue_struct *queue,
6399 uint32_t num_queues, int snum,
6400 struct spoolss_PrinterInfo2 *pinfo2,
6401 union spoolss_JobInfo **info_p,
6404 union spoolss_JobInfo *info;
6406 WERROR result = WERR_OK;
6408 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6409 W_ERROR_HAVE_NO_MEMORY(info);
6411 *count = num_queues;
6413 for (i=0; i<*count; i++) {
6414 const print_queue_struct *next_queue = NULL;
6417 next_queue = &queue[i+1];
6420 result = fill_job_info3(info,
6427 if (!W_ERROR_IS_OK(result)) {
6433 if (!W_ERROR_IS_OK(result)) {
6444 /****************************************************************
6446 ****************************************************************/
6448 WERROR _spoolss_EnumJobs(pipes_struct *p,
6449 struct spoolss_EnumJobs *r)
6452 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6454 print_status_struct prt_status;
6455 print_queue_struct *queue = NULL;
6458 /* that's an [in out] buffer */
6460 if (!r->in.buffer && (r->in.offered != 0)) {
6461 return WERR_INVALID_PARAM;
6464 DEBUG(4,("_spoolss_EnumJobs\n"));
6468 *r->out.info = NULL;
6470 /* lookup the printer snum and tdb entry */
6472 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6476 result = winreg_get_printer(p->mem_ctx, p->server_info, NULL,
6477 lp_servicename(snum), &pinfo2);
6478 if (!W_ERROR_IS_OK(result)) {
6482 count = print_queue_status(snum, &queue, &prt_status);
6483 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6484 count, prt_status.status, prt_status.message));
6488 TALLOC_FREE(pinfo2);
6492 switch (r->in.level) {
6494 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6495 pinfo2, r->out.info, r->out.count);
6498 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6499 pinfo2, r->out.info, r->out.count);
6502 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
6503 pinfo2, r->out.info, r->out.count);
6506 result = WERR_UNKNOWN_LEVEL;
6511 TALLOC_FREE(pinfo2);
6513 if (!W_ERROR_IS_OK(result)) {
6517 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6519 *r->out.info, r->in.level,
6521 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6522 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6524 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6527 /****************************************************************
6528 _spoolss_ScheduleJob
6529 ****************************************************************/
6531 WERROR _spoolss_ScheduleJob(pipes_struct *p,
6532 struct spoolss_ScheduleJob *r)
6537 /****************************************************************
6538 ****************************************************************/
6540 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
6541 const char *printer_name,
6543 struct spoolss_SetJobInfo1 *r)
6547 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
6551 if (strequal(old_doc_name, r->document_name)) {
6555 if (!print_job_set_name(printer_name, job_id, r->document_name)) {
6562 /****************************************************************
6564 ****************************************************************/
6566 WERROR _spoolss_SetJob(pipes_struct *p,
6567 struct spoolss_SetJob *r)
6570 WERROR errcode = WERR_BADFUNC;
6572 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6576 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6577 return WERR_INVALID_PRINTER_NAME;
6580 switch (r->in.command) {
6581 case SPOOLSS_JOB_CONTROL_CANCEL:
6582 case SPOOLSS_JOB_CONTROL_DELETE:
6583 errcode = print_job_delete(p->server_info,
6584 snum, r->in.job_id);
6585 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
6589 case SPOOLSS_JOB_CONTROL_PAUSE:
6590 if (print_job_pause(p->server_info, snum, r->in.job_id, &errcode)) {
6594 case SPOOLSS_JOB_CONTROL_RESTART:
6595 case SPOOLSS_JOB_CONTROL_RESUME:
6596 if (print_job_resume(p->server_info, snum, r->in.job_id, &errcode)) {
6604 return WERR_UNKNOWN_LEVEL;
6607 if (!W_ERROR_IS_OK(errcode)) {
6611 if (r->in.ctr == NULL) {
6615 switch (r->in.ctr->level) {
6617 errcode = spoolss_setjob_1(p->mem_ctx, lp_const_servicename(snum),
6619 r->in.ctr->info.info1);
6625 return WERR_UNKNOWN_LEVEL;
6631 /****************************************************************************
6632 Enumerates all printer drivers by level and architecture.
6633 ****************************************************************************/
6635 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
6636 struct auth_serversupplied_info *server_info,
6637 const char *servername,
6638 const char *architecture,
6640 union spoolss_DriverInfo **info_p,
6645 struct spoolss_DriverInfo8 *driver;
6646 union spoolss_DriverInfo *info = NULL;
6648 WERROR result = WERR_OK;
6649 uint32_t num_drivers;
6650 const char **drivers;
6655 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6656 result = winreg_get_driver_list(mem_ctx, server_info,
6657 architecture, version,
6658 &num_drivers, &drivers);
6659 if (!W_ERROR_IS_OK(result)) {
6662 DEBUG(4, ("we have:[%d] drivers in environment"
6663 " [%s] and version [%d]\n",
6664 num_drivers, architecture, version));
6666 if (num_drivers != 0) {
6667 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6668 union spoolss_DriverInfo,
6669 count + num_drivers);
6671 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
6672 "failed to enlarge driver info buffer!\n"));
6673 result = WERR_NOMEM;
6678 for (i = 0; i < num_drivers; i++) {
6679 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
6681 result = winreg_get_driver(mem_ctx, server_info,
6682 architecture, drivers[i],
6684 if (!W_ERROR_IS_OK(result)) {
6690 result = fill_printer_driver_info1(info, &info[count+i].info1,
6691 driver, servername);
6694 result = fill_printer_driver_info2(info, &info[count+i].info2,
6695 driver, servername);
6698 result = fill_printer_driver_info3(info, &info[count+i].info3,
6699 driver, servername);
6702 result = fill_printer_driver_info4(info, &info[count+i].info4,
6703 driver, servername);
6706 result = fill_printer_driver_info5(info, &info[count+i].info5,
6707 driver, servername);
6710 result = fill_printer_driver_info6(info, &info[count+i].info6,
6711 driver, servername);
6714 result = fill_printer_driver_info8(info, &info[count+i].info8,
6715 driver, servername);
6718 result = WERR_UNKNOWN_LEVEL;
6722 TALLOC_FREE(driver);
6724 if (!W_ERROR_IS_OK(result)) {
6729 count += num_drivers;
6730 TALLOC_FREE(drivers);
6734 TALLOC_FREE(drivers);
6736 if (!W_ERROR_IS_OK(result)) {
6747 /****************************************************************************
6748 Enumerates all printer drivers by level.
6749 ****************************************************************************/
6751 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
6752 struct auth_serversupplied_info *server_info,
6753 const char *servername,
6754 const char *architecture,
6756 union spoolss_DriverInfo **info_p,
6760 WERROR result = WERR_OK;
6762 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
6764 for (a=0; archi_table[a].long_archi != NULL; a++) {
6766 union spoolss_DriverInfo *info = NULL;
6769 result = enumprinterdrivers_level_by_architecture(mem_ctx,
6772 archi_table[a].long_archi,
6776 if (!W_ERROR_IS_OK(result)) {
6780 for (i=0; i < count; i++) {
6781 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
6782 info[i], info_p, count_p);
6789 return enumprinterdrivers_level_by_architecture(mem_ctx,
6798 /****************************************************************
6799 _spoolss_EnumPrinterDrivers
6800 ****************************************************************/
6802 WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
6803 struct spoolss_EnumPrinterDrivers *r)
6805 const char *cservername;
6808 /* that's an [in out] buffer */
6810 if (!r->in.buffer && (r->in.offered != 0)) {
6811 return WERR_INVALID_PARAM;
6814 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
6818 *r->out.info = NULL;
6820 cservername = canon_servername(r->in.server);
6822 if (!is_myname_or_ipaddr(cservername)) {
6823 return WERR_UNKNOWN_PRINTER_DRIVER;
6826 result = enumprinterdrivers_level(p->mem_ctx,
6833 if (!W_ERROR_IS_OK(result)) {
6837 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6838 spoolss_EnumPrinterDrivers,
6839 *r->out.info, r->in.level,
6841 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6842 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6844 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6847 /****************************************************************
6849 ****************************************************************/
6851 WERROR _spoolss_EnumForms(pipes_struct *p,
6852 struct spoolss_EnumForms *r)
6858 *r->out.info = NULL;
6860 /* that's an [in out] buffer */
6862 if (!r->in.buffer && (r->in.offered != 0) ) {
6863 return WERR_INVALID_PARAM;
6866 DEBUG(4,("_spoolss_EnumForms\n"));
6867 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6868 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6870 switch (r->in.level) {
6872 result = winreg_printer_enumforms1(p->mem_ctx,
6878 result = WERR_UNKNOWN_LEVEL;
6882 if (!W_ERROR_IS_OK(result)) {
6886 if (*r->out.count == 0) {
6887 return WERR_NO_MORE_ITEMS;
6890 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6892 *r->out.info, r->in.level,
6894 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6895 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6897 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6900 /****************************************************************
6902 ****************************************************************/
6904 WERROR _spoolss_GetForm(pipes_struct *p,
6905 struct spoolss_GetForm *r)
6909 /* that's an [in out] buffer */
6911 if (!r->in.buffer && (r->in.offered != 0)) {
6912 return WERR_INVALID_PARAM;
6915 DEBUG(4,("_spoolss_GetForm\n"));
6916 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6917 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6919 switch (r->in.level) {
6921 result = winreg_printer_getform1(p->mem_ctx,
6924 &r->out.info->info1);
6927 result = WERR_UNKNOWN_LEVEL;
6931 if (!W_ERROR_IS_OK(result)) {
6932 TALLOC_FREE(r->out.info);
6936 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
6937 r->out.info, r->in.level);
6938 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
6940 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6943 /****************************************************************************
6944 ****************************************************************************/
6946 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
6947 struct spoolss_PortInfo1 *r,
6950 r->port_name = talloc_strdup(mem_ctx, name);
6951 W_ERROR_HAVE_NO_MEMORY(r->port_name);
6956 /****************************************************************************
6957 TODO: This probably needs distinguish between TCP/IP and Local ports
6959 ****************************************************************************/
6961 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
6962 struct spoolss_PortInfo2 *r,
6965 r->port_name = talloc_strdup(mem_ctx, name);
6966 W_ERROR_HAVE_NO_MEMORY(r->port_name);
6968 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
6969 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
6971 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
6972 W_ERROR_HAVE_NO_MEMORY(r->description);
6974 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
6981 /****************************************************************************
6982 wrapper around the enumer ports command
6983 ****************************************************************************/
6985 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
6987 char *cmd = lp_enumports_cmd();
6988 char **qlines = NULL;
6989 char *command = NULL;
6997 /* if no hook then just fill in the default port */
7000 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7003 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7004 TALLOC_FREE(qlines);
7011 /* we have a valid enumport command */
7013 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7018 DEBUG(10,("Running [%s]\n", command));
7019 ret = smbrun(command, &fd);
7020 DEBUG(10,("Returned [%d]\n", ret));
7021 TALLOC_FREE(command);
7026 return WERR_ACCESS_DENIED;
7030 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7031 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7041 /****************************************************************************
7043 ****************************************************************************/
7045 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7046 union spoolss_PortInfo **info_p,
7049 union spoolss_PortInfo *info = NULL;
7051 WERROR result = WERR_OK;
7052 char **qlines = NULL;
7055 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7056 if (!W_ERROR_IS_OK(result)) {
7061 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7063 DEBUG(10,("Returning WERR_NOMEM\n"));
7064 result = WERR_NOMEM;
7068 for (i=0; i<numlines; i++) {
7069 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7070 result = fill_port_1(info, &info[i].info1, qlines[i]);
7071 if (!W_ERROR_IS_OK(result)) {
7076 TALLOC_FREE(qlines);
7079 if (!W_ERROR_IS_OK(result)) {
7081 TALLOC_FREE(qlines);
7093 /****************************************************************************
7095 ****************************************************************************/
7097 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7098 union spoolss_PortInfo **info_p,
7101 union spoolss_PortInfo *info = NULL;
7103 WERROR result = WERR_OK;
7104 char **qlines = NULL;
7107 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7108 if (!W_ERROR_IS_OK(result)) {
7113 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7115 DEBUG(10,("Returning WERR_NOMEM\n"));
7116 result = WERR_NOMEM;
7120 for (i=0; i<numlines; i++) {
7121 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7122 result = fill_port_2(info, &info[i].info2, qlines[i]);
7123 if (!W_ERROR_IS_OK(result)) {
7128 TALLOC_FREE(qlines);
7131 if (!W_ERROR_IS_OK(result)) {
7133 TALLOC_FREE(qlines);
7145 /****************************************************************
7147 ****************************************************************/
7149 WERROR _spoolss_EnumPorts(pipes_struct *p,
7150 struct spoolss_EnumPorts *r)
7154 /* that's an [in out] buffer */
7156 if (!r->in.buffer && (r->in.offered != 0)) {
7157 return WERR_INVALID_PARAM;
7160 DEBUG(4,("_spoolss_EnumPorts\n"));
7164 *r->out.info = NULL;
7166 switch (r->in.level) {
7168 result = enumports_level_1(p->mem_ctx, r->out.info,
7172 result = enumports_level_2(p->mem_ctx, r->out.info,
7176 return WERR_UNKNOWN_LEVEL;
7179 if (!W_ERROR_IS_OK(result)) {
7183 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7185 *r->out.info, r->in.level,
7187 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7188 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7190 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7193 /****************************************************************************
7194 ****************************************************************************/
7196 static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
7198 struct spoolss_SetPrinterInfoCtr *info_ctr,
7199 struct spoolss_DeviceMode *devmode,
7200 struct security_descriptor *secdesc,
7201 struct spoolss_UserLevelCtr *user_ctr,
7202 struct policy_handle *handle)
7204 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7205 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7207 WERROR err = WERR_OK;
7209 /* samba does not have a concept of local, non-shared printers yet, so
7210 * make sure we always setup sharename - gd */
7211 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7212 (info2->printername != NULL && info2->printername[0] != '\0')) {
7213 DEBUG(5, ("spoolss_addprinterex_level_2: "
7214 "no sharename has been set, setting printername %s as sharename\n",
7215 info2->printername));
7216 info2->sharename = info2->printername;
7219 /* check to see if the printer already exists */
7220 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7221 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7223 return WERR_PRINTER_ALREADY_EXISTS;
7226 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7227 if ((snum = print_queue_snum(info2->printername)) != -1) {
7228 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7229 info2->printername));
7230 return WERR_PRINTER_ALREADY_EXISTS;
7234 /* validate printer info struct */
7235 if (!info2->printername || strlen(info2->printername) == 0) {
7236 return WERR_INVALID_PRINTER_NAME;
7238 if (!info2->portname || strlen(info2->portname) == 0) {
7239 return WERR_UNKNOWN_PORT;
7241 if (!info2->drivername || strlen(info2->drivername) == 0) {
7242 return WERR_UNKNOWN_PRINTER_DRIVER;
7244 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7245 return WERR_UNKNOWN_PRINTPROCESSOR;
7248 /* FIXME!!! smbd should check to see if the driver is installed before
7249 trying to add a printer like this --jerry */
7251 if (*lp_addprinter_cmd() ) {
7252 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7253 info2, p->client_address) ) {
7254 return WERR_ACCESS_DENIED;
7257 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7258 "smb.conf parameter \"addprinter command\" is defined. This"
7259 "parameter must exist for this call to succeed\n",
7260 info2->sharename ));
7263 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7264 return WERR_ACCESS_DENIED;
7267 /* you must be a printer admin to add a new printer */
7268 if (!print_access_check(p->server_info, snum, PRINTER_ACCESS_ADMINISTER)) {
7269 return WERR_ACCESS_DENIED;
7273 * Do sanity check on the requested changes for Samba.
7276 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7277 return WERR_INVALID_PARAM;
7280 if (devmode == NULL) {
7281 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7284 update_dsspooler(p->mem_ctx,
7290 err = winreg_update_printer(p->mem_ctx,
7297 if (!W_ERROR_IS_OK(err)) {
7301 if (!open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER)) {
7302 /* Handle open failed - remove addition. */
7303 ZERO_STRUCTP(handle);
7304 return WERR_ACCESS_DENIED;
7310 /****************************************************************
7311 _spoolss_AddPrinterEx
7312 ****************************************************************/
7314 WERROR _spoolss_AddPrinterEx(pipes_struct *p,
7315 struct spoolss_AddPrinterEx *r)
7317 switch (r->in.info_ctr->level) {
7319 /* we don't handle yet */
7320 /* but I know what to do ... */
7321 return WERR_UNKNOWN_LEVEL;
7323 return spoolss_addprinterex_level_2(p, r->in.server,
7325 r->in.devmode_ctr->devmode,
7326 r->in.secdesc_ctr->sd,
7327 r->in.userlevel_ctr,
7330 return WERR_UNKNOWN_LEVEL;
7334 /****************************************************************
7336 ****************************************************************/
7338 WERROR _spoolss_AddPrinter(pipes_struct *p,
7339 struct spoolss_AddPrinter *r)
7341 struct spoolss_AddPrinterEx a;
7342 struct spoolss_UserLevelCtr userlevel_ctr;
7344 ZERO_STRUCT(userlevel_ctr);
7346 userlevel_ctr.level = 1;
7348 a.in.server = r->in.server;
7349 a.in.info_ctr = r->in.info_ctr;
7350 a.in.devmode_ctr = r->in.devmode_ctr;
7351 a.in.secdesc_ctr = r->in.secdesc_ctr;
7352 a.in.userlevel_ctr = &userlevel_ctr;
7353 a.out.handle = r->out.handle;
7355 return _spoolss_AddPrinterEx(p, &a);
7358 /****************************************************************
7359 _spoolss_AddPrinterDriverEx
7360 ****************************************************************/
7362 WERROR _spoolss_AddPrinterDriverEx(pipes_struct *p,
7363 struct spoolss_AddPrinterDriverEx *r)
7365 WERROR err = WERR_OK;
7366 const char *driver_name = NULL;
7371 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7372 fn = "_spoolss_AddPrinterDriver";
7374 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7375 fn = "_spoolss_AddPrinterDriverEx";
7378 return WERR_INVALID_PARAM;
7382 * we only support the semantics of AddPrinterDriver()
7383 * i.e. only copy files that are newer than existing ones
7386 if (r->in.flags == 0) {
7387 return WERR_INVALID_PARAM;
7390 if (r->in.flags != APD_COPY_NEW_FILES) {
7391 return WERR_ACCESS_DENIED;
7395 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7396 /* Clever hack from Martin Zielinski <mz@seh.de>
7397 * to allow downgrade from level 8 (Vista).
7399 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7400 r->in.info_ctr->level));
7401 return WERR_UNKNOWN_LEVEL;
7404 DEBUG(5,("Cleaning driver's information\n"));
7405 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
7406 if (!W_ERROR_IS_OK(err))
7409 DEBUG(5,("Moving driver to final destination\n"));
7410 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7415 err = winreg_add_driver(p->mem_ctx, p->server_info,
7416 r->in.info_ctr, &driver_name, &version);
7417 if (!W_ERROR_IS_OK(err)) {
7422 * I think this is where he DrvUpgradePrinter() hook would be
7423 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7424 * server. Right now, we just need to send ourselves a message
7425 * to update each printer bound to this driver. --jerry
7428 if (!srv_spoolss_drv_upgrade_printer(driver_name)) {
7429 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7437 /****************************************************************
7438 _spoolss_AddPrinterDriver
7439 ****************************************************************/
7441 WERROR _spoolss_AddPrinterDriver(pipes_struct *p,
7442 struct spoolss_AddPrinterDriver *r)
7444 struct spoolss_AddPrinterDriverEx a;
7446 switch (r->in.info_ctr->level) {
7453 return WERR_UNKNOWN_LEVEL;
7456 a.in.servername = r->in.servername;
7457 a.in.info_ctr = r->in.info_ctr;
7458 a.in.flags = APD_COPY_NEW_FILES;
7460 return _spoolss_AddPrinterDriverEx(p, &a);
7463 /****************************************************************************
7464 ****************************************************************************/
7466 struct _spoolss_paths {
7472 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7474 static const struct _spoolss_paths spoolss_paths[]= {
7475 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7476 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7479 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7480 const char *servername,
7481 const char *environment,
7485 const char *pservername = NULL;
7486 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7487 const char *short_archi;
7491 /* environment may be empty */
7492 if (environment && strlen(environment)) {
7493 long_archi = environment;
7496 /* servername may be empty */
7497 if (servername && strlen(servername)) {
7498 pservername = canon_servername(servername);
7500 if (!is_myname_or_ipaddr(pservername)) {
7501 return WERR_INVALID_PARAM;
7505 if (!(short_archi = get_short_archi(long_archi))) {
7506 return WERR_INVALID_ENVIRONMENT;
7509 switch (component) {
7510 case SPOOLSS_PRTPROCS_PATH:
7511 case SPOOLSS_DRIVER_PATH:
7513 *path = talloc_asprintf(mem_ctx,
7516 spoolss_paths[component].share,
7519 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7520 SPOOLSS_DEFAULT_SERVER_PATH,
7521 spoolss_paths[component].dir,
7526 return WERR_INVALID_PARAM;
7536 /****************************************************************************
7537 ****************************************************************************/
7539 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7540 const char *servername,
7541 const char *environment,
7542 struct spoolss_DriverDirectoryInfo1 *r)
7547 werr = compose_spoolss_server_path(mem_ctx,
7550 SPOOLSS_DRIVER_PATH,
7552 if (!W_ERROR_IS_OK(werr)) {
7556 DEBUG(4,("printer driver directory: [%s]\n", path));
7558 r->directory_name = path;
7563 /****************************************************************
7564 _spoolss_GetPrinterDriverDirectory
7565 ****************************************************************/
7567 WERROR _spoolss_GetPrinterDriverDirectory(pipes_struct *p,
7568 struct spoolss_GetPrinterDriverDirectory *r)
7572 /* that's an [in out] buffer */
7574 if (!r->in.buffer && (r->in.offered != 0)) {
7575 return WERR_INVALID_PARAM;
7578 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
7583 /* r->in.level is ignored */
7585 werror = getprinterdriverdir_level_1(p->mem_ctx,
7588 &r->out.info->info1);
7589 if (!W_ERROR_IS_OK(werror)) {
7590 TALLOC_FREE(r->out.info);
7594 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
7595 r->out.info, r->in.level);
7596 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7598 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7601 /****************************************************************
7602 _spoolss_EnumPrinterData
7603 ****************************************************************/
7605 WERROR _spoolss_EnumPrinterData(pipes_struct *p,
7606 struct spoolss_EnumPrinterData *r)
7609 struct spoolss_EnumPrinterDataEx r2;
7611 struct spoolss_PrinterEnumValues *info, *val = NULL;
7614 r2.in.handle = r->in.handle;
7615 r2.in.key_name = "PrinterDriverData";
7617 r2.out.count = &count;
7618 r2.out.info = &info;
7619 r2.out.needed = &needed;
7621 result = _spoolss_EnumPrinterDataEx(p, &r2);
7622 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
7623 r2.in.offered = needed;
7624 result = _spoolss_EnumPrinterDataEx(p, &r2);
7626 if (!W_ERROR_IS_OK(result)) {
7631 * The NT machine wants to know the biggest size of value and data
7633 * cf: MSDN EnumPrinterData remark section
7636 if (!r->in.value_offered && !r->in.data_offered) {
7637 uint32_t biggest_valuesize = 0;
7638 uint32_t biggest_datasize = 0;
7641 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
7643 for (i=0; i<count; i++) {
7645 name_length = strlen(info[i].value_name);
7646 if (strlen(info[i].value_name) > biggest_valuesize) {
7647 biggest_valuesize = name_length;
7650 if (info[i].data_length > biggest_datasize) {
7651 biggest_datasize = info[i].data_length;
7654 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
7658 /* the value is an UNICODE string but real_value_size is the length
7659 in bytes including the trailing 0 */
7661 *r->out.value_needed = 2 * (1 + biggest_valuesize);
7662 *r->out.data_needed = biggest_datasize;
7664 DEBUG(6,("final values: [%d], [%d]\n",
7665 *r->out.value_needed, *r->out.data_needed));
7670 if (r->in.enum_index < count) {
7671 val = &info[r->in.enum_index];
7675 /* out_value should default to "" or else NT4 has
7676 problems unmarshalling the response */
7678 if (r->in.value_offered) {
7679 *r->out.value_needed = 1;
7680 r->out.value_name = talloc_strdup(r, "");
7681 if (!r->out.value_name) {
7685 r->out.value_name = NULL;
7686 *r->out.value_needed = 0;
7689 /* the data is counted in bytes */
7691 *r->out.data_needed = r->in.data_offered;
7693 result = WERR_NO_MORE_ITEMS;
7697 * - counted in bytes in the request
7698 * - counted in UNICODE chars in the max reply
7699 * - counted in bytes in the real size
7701 * take a pause *before* coding not *during* coding
7705 if (r->in.value_offered) {
7706 r->out.value_name = talloc_strdup(r, val->value_name);
7707 if (!r->out.value_name) {
7710 *r->out.value_needed = val->value_name_len;
7712 r->out.value_name = NULL;
7713 *r->out.value_needed = 0;
7718 *r->out.type = val->type;
7720 /* data - counted in bytes */
7723 * See the section "Dynamically Typed Query Parameters"
7727 if (r->out.data && val->data && val->data->data &&
7728 val->data_length && r->in.data_offered) {
7729 memcpy(r->out.data, val->data->data,
7730 MIN(val->data_length,r->in.data_offered));
7733 *r->out.data_needed = val->data_length;
7741 /****************************************************************
7742 _spoolss_SetPrinterData
7743 ****************************************************************/
7745 WERROR _spoolss_SetPrinterData(pipes_struct *p,
7746 struct spoolss_SetPrinterData *r)
7748 struct spoolss_SetPrinterDataEx r2;
7750 r2.in.handle = r->in.handle;
7751 r2.in.key_name = "PrinterDriverData";
7752 r2.in.value_name = r->in.value_name;
7753 r2.in.type = r->in.type;
7754 r2.in.data = r->in.data;
7755 r2.in.offered = r->in.offered;
7757 return _spoolss_SetPrinterDataEx(p, &r2);
7760 /****************************************************************
7761 _spoolss_ResetPrinter
7762 ****************************************************************/
7764 WERROR _spoolss_ResetPrinter(pipes_struct *p,
7765 struct spoolss_ResetPrinter *r)
7767 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7770 DEBUG(5,("_spoolss_ResetPrinter\n"));
7773 * All we do is to check to see if the handle and queue is valid.
7774 * This call really doesn't mean anything to us because we only
7775 * support RAW printing. --jerry
7779 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
7780 OUR_HANDLE(r->in.handle)));
7784 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
7788 /* blindly return success */
7792 /****************************************************************
7793 _spoolss_DeletePrinterData
7794 ****************************************************************/
7796 WERROR _spoolss_DeletePrinterData(pipes_struct *p,
7797 struct spoolss_DeletePrinterData *r)
7799 struct spoolss_DeletePrinterDataEx r2;
7801 r2.in.handle = r->in.handle;
7802 r2.in.key_name = "PrinterDriverData";
7803 r2.in.value_name = r->in.value_name;
7805 return _spoolss_DeletePrinterDataEx(p, &r2);
7808 /****************************************************************
7810 ****************************************************************/
7812 WERROR _spoolss_AddForm(pipes_struct *p,
7813 struct spoolss_AddForm *r)
7815 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
7817 WERROR status = WERR_OK;
7818 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7820 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7822 DEBUG(5,("_spoolss_AddForm\n"));
7825 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
7826 OUR_HANDLE(r->in.handle)));
7830 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
7831 and not a printer admin, then fail */
7833 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7834 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7835 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7836 p->server_info->info3->base.domain.string,
7838 p->server_info->ptok,
7839 lp_printer_admin(snum))) {
7840 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
7841 return WERR_ACCESS_DENIED;
7844 switch (form->flags) {
7845 case SPOOLSS_FORM_USER:
7846 case SPOOLSS_FORM_BUILTIN:
7847 case SPOOLSS_FORM_PRINTER:
7850 return WERR_INVALID_PARAM;
7853 status = winreg_printer_addform1(p->mem_ctx, p->server_info, form);
7854 if (!W_ERROR_IS_OK(status)) {
7859 * ChangeID must always be set if this is a printer
7861 if (Printer->printer_type == SPLHND_PRINTER) {
7862 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7866 status = winreg_printer_update_changeid(p->mem_ctx,
7868 lp_const_servicename(snum));
7869 if (!W_ERROR_IS_OK(status)) {
7877 /****************************************************************
7879 ****************************************************************/
7881 WERROR _spoolss_DeleteForm(pipes_struct *p,
7882 struct spoolss_DeleteForm *r)
7884 const char *form_name = r->in.form_name;
7885 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7887 WERROR status = WERR_OK;
7888 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7890 DEBUG(5,("_spoolss_DeleteForm\n"));
7893 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
7894 OUR_HANDLE(r->in.handle)));
7898 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7899 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7900 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7901 p->server_info->info3->base.domain.string,
7903 p->server_info->ptok,
7904 lp_printer_admin(snum))) {
7905 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
7906 return WERR_ACCESS_DENIED;
7909 status = winreg_printer_deleteform1(p->mem_ctx,
7912 if (!W_ERROR_IS_OK(status)) {
7917 * ChangeID must always be set if this is a printer
7919 if (Printer->printer_type == SPLHND_PRINTER) {
7920 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7924 status = winreg_printer_update_changeid(p->mem_ctx,
7926 lp_const_servicename(snum));
7927 if (!W_ERROR_IS_OK(status)) {
7935 /****************************************************************
7937 ****************************************************************/
7939 WERROR _spoolss_SetForm(pipes_struct *p,
7940 struct spoolss_SetForm *r)
7942 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
7943 const char *form_name = r->in.form_name;
7945 WERROR status = WERR_OK;
7946 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7948 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7950 DEBUG(5,("_spoolss_SetForm\n"));
7953 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
7954 OUR_HANDLE(r->in.handle)));
7958 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
7959 and not a printer admin, then fail */
7961 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7962 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7963 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7964 p->server_info->info3->base.domain.string,
7966 p->server_info->ptok,
7967 lp_printer_admin(snum))) {
7968 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
7969 return WERR_ACCESS_DENIED;
7972 status = winreg_printer_setform1(p->mem_ctx,
7976 if (!W_ERROR_IS_OK(status)) {
7981 * ChangeID must always be set if this is a printer
7983 if (Printer->printer_type == SPLHND_PRINTER) {
7984 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7988 status = winreg_printer_update_changeid(p->mem_ctx,
7990 lp_const_servicename(snum));
7991 if (!W_ERROR_IS_OK(status)) {
7999 /****************************************************************************
8000 fill_print_processor1
8001 ****************************************************************************/
8003 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8004 struct spoolss_PrintProcessorInfo1 *r,
8005 const char *print_processor_name)
8007 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8008 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8013 /****************************************************************************
8014 enumprintprocessors level 1.
8015 ****************************************************************************/
8017 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8018 union spoolss_PrintProcessorInfo **info_p,
8021 union spoolss_PrintProcessorInfo *info;
8024 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8025 W_ERROR_HAVE_NO_MEMORY(info);
8029 result = fill_print_processor1(info, &info[0].info1, "winprint");
8030 if (!W_ERROR_IS_OK(result)) {
8035 if (!W_ERROR_IS_OK(result)) {
8046 /****************************************************************
8047 _spoolss_EnumPrintProcessors
8048 ****************************************************************/
8050 WERROR _spoolss_EnumPrintProcessors(pipes_struct *p,
8051 struct spoolss_EnumPrintProcessors *r)
8055 /* that's an [in out] buffer */
8057 if (!r->in.buffer && (r->in.offered != 0)) {
8058 return WERR_INVALID_PARAM;
8061 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8064 * Enumerate the print processors ...
8066 * Just reply with "winprint", to keep NT happy
8067 * and I can use my nice printer checker.
8072 *r->out.info = NULL;
8074 switch (r->in.level) {
8076 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8080 return WERR_UNKNOWN_LEVEL;
8083 if (!W_ERROR_IS_OK(result)) {
8087 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8088 spoolss_EnumPrintProcessors,
8089 *r->out.info, r->in.level,
8091 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8092 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8094 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8097 /****************************************************************************
8098 fill_printprocdatatype1
8099 ****************************************************************************/
8101 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8102 struct spoolss_PrintProcDataTypesInfo1 *r,
8103 const char *name_array)
8105 r->name_array = talloc_strdup(mem_ctx, name_array);
8106 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8111 /****************************************************************************
8112 enumprintprocdatatypes level 1.
8113 ****************************************************************************/
8115 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8116 union spoolss_PrintProcDataTypesInfo **info_p,
8120 union spoolss_PrintProcDataTypesInfo *info;
8122 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8123 W_ERROR_HAVE_NO_MEMORY(info);
8127 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8128 if (!W_ERROR_IS_OK(result)) {
8133 if (!W_ERROR_IS_OK(result)) {
8144 /****************************************************************
8145 _spoolss_EnumPrintProcDataTypes
8146 ****************************************************************/
8148 WERROR _spoolss_EnumPrintProcDataTypes(pipes_struct *p,
8149 struct spoolss_EnumPrintProcDataTypes *r)
8153 /* that's an [in out] buffer */
8155 if (!r->in.buffer && (r->in.offered != 0)) {
8156 return WERR_INVALID_PARAM;
8159 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8163 *r->out.info = NULL;
8165 switch (r->in.level) {
8167 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8171 return WERR_UNKNOWN_LEVEL;
8174 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8175 spoolss_EnumPrintProcDataTypes,
8176 *r->out.info, r->in.level,
8178 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8179 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8181 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8184 /****************************************************************************
8186 ****************************************************************************/
8188 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8189 struct spoolss_MonitorInfo1 *r,
8190 const char *monitor_name)
8192 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8193 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8198 /****************************************************************************
8200 ****************************************************************************/
8202 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8203 struct spoolss_MonitorInfo2 *r,
8204 const char *monitor_name,
8205 const char *environment,
8206 const char *dll_name)
8208 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8209 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8210 r->environment = talloc_strdup(mem_ctx, environment);
8211 W_ERROR_HAVE_NO_MEMORY(r->environment);
8212 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8213 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8218 /****************************************************************************
8219 enumprintmonitors level 1.
8220 ****************************************************************************/
8222 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8223 union spoolss_MonitorInfo **info_p,
8226 union spoolss_MonitorInfo *info;
8227 WERROR result = WERR_OK;
8229 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8230 W_ERROR_HAVE_NO_MEMORY(info);
8234 result = fill_monitor_1(info, &info[0].info1,
8236 if (!W_ERROR_IS_OK(result)) {
8240 result = fill_monitor_1(info, &info[1].info1,
8242 if (!W_ERROR_IS_OK(result)) {
8247 if (!W_ERROR_IS_OK(result)) {
8258 /****************************************************************************
8259 enumprintmonitors level 2.
8260 ****************************************************************************/
8262 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8263 union spoolss_MonitorInfo **info_p,
8266 union spoolss_MonitorInfo *info;
8267 WERROR result = WERR_OK;
8269 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8270 W_ERROR_HAVE_NO_MEMORY(info);
8274 result = fill_monitor_2(info, &info[0].info2,
8276 "Windows NT X86", /* FIXME */
8278 if (!W_ERROR_IS_OK(result)) {
8282 result = fill_monitor_2(info, &info[1].info2,
8284 "Windows NT X86", /* FIXME */
8286 if (!W_ERROR_IS_OK(result)) {
8291 if (!W_ERROR_IS_OK(result)) {
8302 /****************************************************************
8303 _spoolss_EnumMonitors
8304 ****************************************************************/
8306 WERROR _spoolss_EnumMonitors(pipes_struct *p,
8307 struct spoolss_EnumMonitors *r)
8311 /* that's an [in out] buffer */
8313 if (!r->in.buffer && (r->in.offered != 0)) {
8314 return WERR_INVALID_PARAM;
8317 DEBUG(5,("_spoolss_EnumMonitors\n"));
8320 * Enumerate the print monitors ...
8322 * Just reply with "Local Port", to keep NT happy
8323 * and I can use my nice printer checker.
8328 *r->out.info = NULL;
8330 switch (r->in.level) {
8332 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8336 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8340 return WERR_UNKNOWN_LEVEL;
8343 if (!W_ERROR_IS_OK(result)) {
8347 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8348 spoolss_EnumMonitors,
8349 *r->out.info, r->in.level,
8351 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8352 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8354 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8357 /****************************************************************************
8358 ****************************************************************************/
8360 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8361 const print_queue_struct *queue,
8362 int count, int snum,
8363 struct spoolss_PrinterInfo2 *pinfo2,
8365 struct spoolss_JobInfo1 *r)
8370 for (i=0; i<count; i++) {
8371 if (queue[i].job == (int)jobid) {
8377 if (found == false) {
8378 /* NT treats not found as bad param... yet another bad choice */
8379 return WERR_INVALID_PARAM;
8382 return fill_job_info1(mem_ctx,
8390 /****************************************************************************
8391 ****************************************************************************/
8393 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8394 const print_queue_struct *queue,
8395 int count, int snum,
8396 struct spoolss_PrinterInfo2 *pinfo2,
8398 struct spoolss_JobInfo2 *r)
8402 struct spoolss_DeviceMode *devmode;
8405 for (i=0; i<count; i++) {
8406 if (queue[i].job == (int)jobid) {
8412 if (found == false) {
8413 /* NT treats not found as bad param... yet another bad
8415 return WERR_INVALID_PARAM;
8419 * if the print job does not have a DEVMODE associated with it,
8420 * just use the one for the printer. A NULL devicemode is not
8421 * a failure condition
8424 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8426 result = spoolss_create_default_devmode(mem_ctx,
8427 pinfo2->printername,
8429 if (!W_ERROR_IS_OK(result)) {
8430 DEBUG(3, ("Can't proceed w/o a devmode!"));
8435 return fill_job_info2(mem_ctx,
8444 /****************************************************************
8446 ****************************************************************/
8448 WERROR _spoolss_GetJob(pipes_struct *p,
8449 struct spoolss_GetJob *r)
8451 WERROR result = WERR_OK;
8452 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8455 print_queue_struct *queue = NULL;
8456 print_status_struct prt_status;
8458 /* that's an [in out] buffer */
8460 if (!r->in.buffer && (r->in.offered != 0)) {
8461 return WERR_INVALID_PARAM;
8464 DEBUG(5,("_spoolss_GetJob\n"));
8468 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8472 result = winreg_get_printer(p->mem_ctx, p->server_info, NULL,
8473 lp_servicename(snum), &pinfo2);
8474 if (!W_ERROR_IS_OK(result)) {
8478 count = print_queue_status(snum, &queue, &prt_status);
8480 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8481 count, prt_status.status, prt_status.message));
8483 switch (r->in.level) {
8485 result = getjob_level_1(p->mem_ctx,
8486 queue, count, snum, pinfo2,
8487 r->in.job_id, &r->out.info->info1);
8490 result = getjob_level_2(p->mem_ctx,
8491 queue, count, snum, pinfo2,
8492 r->in.job_id, &r->out.info->info2);
8495 result = WERR_UNKNOWN_LEVEL;
8500 TALLOC_FREE(pinfo2);
8502 if (!W_ERROR_IS_OK(result)) {
8503 TALLOC_FREE(r->out.info);
8507 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
8509 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8511 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8514 /****************************************************************
8515 _spoolss_GetPrinterDataEx
8516 ****************************************************************/
8518 WERROR _spoolss_GetPrinterDataEx(pipes_struct *p,
8519 struct spoolss_GetPrinterDataEx *r)
8522 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8523 const char *printer;
8525 WERROR result = WERR_OK;
8527 enum winreg_Type val_type;
8532 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8534 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8535 r->in.key_name, r->in.value_name));
8537 /* in case of problem, return some default values */
8540 *r->out.type = REG_NONE;
8543 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8544 OUR_HANDLE(r->in.handle)));
8545 result = WERR_BADFID;
8549 /* Is the handle to a printer or to the server? */
8551 if (Printer->printer_type == SPLHND_SERVER) {
8553 union spoolss_PrinterData data;
8555 result = getprinterdata_printer_server(p->mem_ctx,
8559 if (!W_ERROR_IS_OK(result)) {
8563 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
8564 *r->out.type, &data);
8565 if (!W_ERROR_IS_OK(result)) {
8569 *r->out.needed = blob.length;
8571 if (r->in.offered >= *r->out.needed) {
8572 memcpy(r->out.data, blob.data, blob.length);
8575 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8578 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8581 printer = lp_const_servicename(snum);
8583 /* check to see if the keyname is valid */
8584 if (!strlen(r->in.key_name)) {
8585 return WERR_INVALID_PARAM;
8588 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
8589 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
8590 strequal(r->in.value_name, "ChangeId")) {
8591 *r->out.type = REG_DWORD;
8593 if (r->in.offered >= *r->out.needed) {
8594 uint32_t changeid = 0;
8596 result = winreg_printer_get_changeid(p->mem_ctx,
8600 if (!W_ERROR_IS_OK(result)) {
8604 SIVAL(r->out.data, 0, changeid);
8610 result = winreg_get_printer_dataex(p->mem_ctx,
8618 if (!W_ERROR_IS_OK(result)) {
8622 *r->out.needed = val_size;
8623 *r->out.type = val_type;
8625 if (r->in.offered >= *r->out.needed) {
8626 memcpy(r->out.data, val_data, val_size);
8630 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
8631 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
8633 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8636 /****************************************************************
8637 _spoolss_SetPrinterDataEx
8638 ****************************************************************/
8640 WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
8641 struct spoolss_SetPrinterDataEx *r)
8643 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8645 WERROR result = WERR_OK;
8646 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8649 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
8651 /* From MSDN documentation of SetPrinterDataEx: pass request to
8652 SetPrinterData if key is "PrinterDriverData" */
8655 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8656 OUR_HANDLE(r->in.handle)));
8660 if (Printer->printer_type == SPLHND_SERVER) {
8661 DEBUG(10,("_spoolss_SetPrinterDataEx: "
8662 "Not implemented for server handles yet\n"));
8663 return WERR_INVALID_PARAM;
8666 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8671 * Access check : NT returns "access denied" if you make a
8672 * SetPrinterData call without the necessary privildge.
8673 * we were originally returning OK if nothing changed
8674 * which made Win2k issue **a lot** of SetPrinterData
8675 * when connecting to a printer --jerry
8678 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8679 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
8680 "change denied by handle access permissions\n"));
8681 return WERR_ACCESS_DENIED;
8684 result = winreg_get_printer(Printer, p->server_info,
8685 Printer->servername,
8686 lp_servicename(snum),
8688 if (!W_ERROR_IS_OK(result)) {
8692 /* check for OID in valuename */
8694 oid_string = strchr(r->in.value_name, ',');
8700 /* save the registry data */
8702 result = winreg_set_printer_dataex(p->mem_ctx,
8711 if (W_ERROR_IS_OK(result)) {
8712 /* save the OID if one was specified */
8714 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
8715 r->in.key_name, SPOOL_OID_KEY);
8717 result = WERR_NOMEM;
8722 * I'm not checking the status here on purpose. Don't know
8723 * if this is right, but I'm returning the status from the
8724 * previous set_printer_dataex() call. I have no idea if
8725 * this is right. --jerry
8727 winreg_set_printer_dataex(p->mem_ctx,
8733 (uint8_t *) oid_string,
8734 strlen(oid_string) + 1);
8737 result = winreg_printer_update_changeid(p->mem_ctx,
8739 lp_const_servicename(snum));
8744 talloc_free(pinfo2);
8748 /****************************************************************
8749 _spoolss_DeletePrinterDataEx
8750 ****************************************************************/
8752 WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
8753 struct spoolss_DeletePrinterDataEx *r)
8755 const char *printer;
8757 WERROR status = WERR_OK;
8758 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8760 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
8763 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
8764 "Invalid handle (%s:%u:%u).\n",
8765 OUR_HANDLE(r->in.handle)));
8769 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8770 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
8771 "printer properties change denied by handle\n"));
8772 return WERR_ACCESS_DENIED;
8775 if (!r->in.value_name || !r->in.key_name) {
8779 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8782 printer = lp_const_servicename(snum);
8784 status = winreg_delete_printer_dataex(p->mem_ctx,
8789 if (W_ERROR_IS_OK(status)) {
8790 status = winreg_printer_update_changeid(p->mem_ctx,
8798 /****************************************************************
8799 _spoolss_EnumPrinterKey
8800 ****************************************************************/
8802 WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
8803 struct spoolss_EnumPrinterKey *r)
8806 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8808 WERROR result = WERR_BADFILE;
8809 const char **array = NULL;
8812 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
8815 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
8816 OUR_HANDLE(r->in.handle)));
8820 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8824 result = winreg_enum_printer_key(p->mem_ctx,
8826 lp_const_servicename(snum),
8830 if (!W_ERROR_IS_OK(result)) {
8834 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
8835 result = WERR_NOMEM;
8839 *r->out._ndr_size = r->in.offered / 2;
8840 *r->out.needed = blob.length;
8842 if (r->in.offered < *r->out.needed) {
8843 result = WERR_MORE_DATA;
8846 r->out.key_buffer->string_array = array;
8850 if (!W_ERROR_IS_OK(result)) {
8852 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8860 /****************************************************************
8861 _spoolss_DeletePrinterKey
8862 ****************************************************************/
8864 WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
8865 struct spoolss_DeletePrinterKey *r)
8867 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8870 const char *printer;
8872 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
8875 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
8876 OUR_HANDLE(r->in.handle)));
8880 /* if keyname == NULL, return error */
8881 if ( !r->in.key_name )
8882 return WERR_INVALID_PARAM;
8884 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8888 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8889 DEBUG(3, ("_spoolss_DeletePrinterKey: "
8890 "printer properties change denied by handle\n"));
8891 return WERR_ACCESS_DENIED;
8894 printer = lp_const_servicename(snum);
8896 /* delete the key and all subkeys */
8897 status = winreg_delete_printer_key(p->mem_ctx,
8901 if (W_ERROR_IS_OK(status)) {
8902 status = winreg_printer_update_changeid(p->mem_ctx,
8910 /****************************************************************
8911 _spoolss_EnumPrinterDataEx
8912 ****************************************************************/
8914 WERROR _spoolss_EnumPrinterDataEx(pipes_struct *p,
8915 struct spoolss_EnumPrinterDataEx *r)
8918 struct spoolss_PrinterEnumValues *info = NULL;
8919 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8923 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
8927 *r->out.info = NULL;
8930 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
8931 OUR_HANDLE(r->in.handle)));
8936 * first check for a keyname of NULL or "". Win2k seems to send
8937 * this a lot and we should send back WERR_INVALID_PARAM
8938 * no need to spend time looking up the printer in this case.
8942 if (!strlen(r->in.key_name)) {
8943 result = WERR_INVALID_PARAM;
8947 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8951 /* now look for a match on the key name */
8952 result = winreg_enum_printer_dataex(p->mem_ctx,
8954 lp_const_servicename(snum),
8958 if (!W_ERROR_IS_OK(result)) {
8962 #if 0 /* FIXME - gd */
8963 /* housekeeping information in the reply */
8965 /* Fix from Martin Zielinski <mz@seh.de> - ensure
8966 * the hand marshalled container size is a multiple
8967 * of 4 bytes for RPC alignment.
8971 needed += 4-(needed % 4);
8974 *r->out.count = count;
8975 *r->out.info = info;
8978 if (!W_ERROR_IS_OK(result)) {
8982 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
8983 spoolss_EnumPrinterDataEx,
8986 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8987 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
8989 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8992 /****************************************************************************
8993 ****************************************************************************/
8995 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
8996 const char *servername,
8997 const char *environment,
8998 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9003 werr = compose_spoolss_server_path(mem_ctx,
9006 SPOOLSS_PRTPROCS_PATH,
9008 if (!W_ERROR_IS_OK(werr)) {
9012 DEBUG(4,("print processor directory: [%s]\n", path));
9014 r->directory_name = path;
9019 /****************************************************************
9020 _spoolss_GetPrintProcessorDirectory
9021 ****************************************************************/
9023 WERROR _spoolss_GetPrintProcessorDirectory(pipes_struct *p,
9024 struct spoolss_GetPrintProcessorDirectory *r)
9028 /* that's an [in out] buffer */
9030 if (!r->in.buffer && (r->in.offered != 0)) {
9031 return WERR_INVALID_PARAM;
9034 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9039 /* r->in.level is ignored */
9041 /* We always should reply with a local print processor directory so that
9042 * users are not forced to have a [prnproc$] share on the Samba spoolss
9043 * server - Guenther */
9045 result = getprintprocessordirectory_level_1(p->mem_ctx,
9046 NULL, /* r->in.server */
9048 &r->out.info->info1);
9049 if (!W_ERROR_IS_OK(result)) {
9050 TALLOC_FREE(r->out.info);
9054 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9055 r->out.info, r->in.level);
9056 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9058 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9061 /*******************************************************************
9062 ********************************************************************/
9064 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9065 const char *dllname)
9067 enum ndr_err_code ndr_err;
9068 struct spoolss_MonitorUi ui;
9070 ui.dll_name = dllname;
9072 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9073 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9074 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9075 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9077 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9080 /*******************************************************************
9081 Streams the monitor UI DLL name in UNICODE
9082 *******************************************************************/
9084 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9085 NT_USER_TOKEN *token, DATA_BLOB *in,
9086 DATA_BLOB *out, uint32_t *needed)
9088 const char *dllname = "tcpmonui.dll";
9090 *needed = (strlen(dllname)+1) * 2;
9092 if (out->length < *needed) {
9093 return WERR_INSUFFICIENT_BUFFER;
9096 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9103 /*******************************************************************
9104 ********************************************************************/
9106 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9107 struct spoolss_PortData1 *port1,
9108 const DATA_BLOB *buf)
9110 enum ndr_err_code ndr_err;
9111 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9112 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9113 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9114 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9116 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9119 /*******************************************************************
9120 ********************************************************************/
9122 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9123 struct spoolss_PortData2 *port2,
9124 const DATA_BLOB *buf)
9126 enum ndr_err_code ndr_err;
9127 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9128 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9129 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9130 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9132 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9135 /*******************************************************************
9136 Create a new TCP/IP port
9137 *******************************************************************/
9139 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9140 NT_USER_TOKEN *token, DATA_BLOB *in,
9141 DATA_BLOB *out, uint32_t *needed)
9143 struct spoolss_PortData1 port1;
9144 struct spoolss_PortData2 port2;
9145 char *device_uri = NULL;
9148 const char *portname;
9149 const char *hostaddress;
9151 uint32_t port_number;
9154 /* peek for spoolss_PortData version */
9156 if (!in || (in->length < (128 + 4))) {
9157 return WERR_GENERAL_FAILURE;
9160 version = IVAL(in->data, 128);
9166 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9170 portname = port1.portname;
9171 hostaddress = port1.hostaddress;
9172 queue = port1.queue;
9173 protocol = port1.protocol;
9174 port_number = port1.port_number;
9180 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9184 portname = port2.portname;
9185 hostaddress = port2.hostaddress;
9186 queue = port2.queue;
9187 protocol = port2.protocol;
9188 port_number = port2.port_number;
9192 DEBUG(1,("xcvtcp_addport: "
9193 "unknown version of port_data: %d\n", version));
9194 return WERR_UNKNOWN_PORT;
9197 /* create the device URI and call the add_port_hook() */
9200 case PROTOCOL_RAWTCP_TYPE:
9201 device_uri = talloc_asprintf(mem_ctx,
9202 "socket://%s:%d/", hostaddress,
9206 case PROTOCOL_LPR_TYPE:
9207 device_uri = talloc_asprintf(mem_ctx,
9208 "lpr://%s/%s", hostaddress, queue );
9212 return WERR_UNKNOWN_PORT;
9219 return add_port_hook(mem_ctx, token, portname, device_uri);
9222 /*******************************************************************
9223 *******************************************************************/
9225 struct xcv_api_table xcvtcp_cmds[] = {
9226 { "MonitorUI", xcvtcp_monitorui },
9227 { "AddPort", xcvtcp_addport},
9231 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9232 NT_USER_TOKEN *token, const char *command,
9239 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9241 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9242 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9243 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9246 return WERR_BADFUNC;
9249 /*******************************************************************
9250 *******************************************************************/
9251 #if 0 /* don't support management using the "Local Port" monitor */
9253 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9254 NT_USER_TOKEN *token, DATA_BLOB *in,
9255 DATA_BLOB *out, uint32_t *needed)
9257 const char *dllname = "localui.dll";
9259 *needed = (strlen(dllname)+1) * 2;
9261 if (out->length < *needed) {
9262 return WERR_INSUFFICIENT_BUFFER;
9265 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9272 /*******************************************************************
9273 *******************************************************************/
9275 struct xcv_api_table xcvlocal_cmds[] = {
9276 { "MonitorUI", xcvlocal_monitorui },
9280 struct xcv_api_table xcvlocal_cmds[] = {
9287 /*******************************************************************
9288 *******************************************************************/
9290 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9291 NT_USER_TOKEN *token, const char *command,
9292 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9297 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9299 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9300 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9301 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9303 return WERR_BADFUNC;
9306 /****************************************************************
9308 ****************************************************************/
9310 WERROR _spoolss_XcvData(pipes_struct *p,
9311 struct spoolss_XcvData *r)
9313 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9314 DATA_BLOB out_data = data_blob_null;
9318 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9319 OUR_HANDLE(r->in.handle)));
9323 /* Has to be a handle to the TCP/IP port monitor */
9325 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9326 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9330 /* requires administrative access to the server */
9332 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9333 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9334 return WERR_ACCESS_DENIED;
9337 /* Allocate the outgoing buffer */
9339 if (r->in.out_data_size) {
9340 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9341 if (out_data.data == NULL) {
9346 switch ( Printer->printer_type ) {
9347 case SPLHND_PORTMON_TCP:
9348 werror = process_xcvtcp_command(p->mem_ctx,
9349 p->server_info->ptok,
9350 r->in.function_name,
9351 &r->in.in_data, &out_data,
9354 case SPLHND_PORTMON_LOCAL:
9355 werror = process_xcvlocal_command(p->mem_ctx,
9356 p->server_info->ptok,
9357 r->in.function_name,
9358 &r->in.in_data, &out_data,
9362 werror = WERR_INVALID_PRINT_MONITOR;
9365 if (!W_ERROR_IS_OK(werror)) {
9369 *r->out.status_code = 0;
9371 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9372 memcpy(r->out.out_data, out_data.data,
9373 MIN(r->in.out_data_size, out_data.length));
9379 /****************************************************************
9380 _spoolss_AddPrintProcessor
9381 ****************************************************************/
9383 WERROR _spoolss_AddPrintProcessor(pipes_struct *p,
9384 struct spoolss_AddPrintProcessor *r)
9386 /* for now, just indicate success and ignore the add. We'll
9387 automatically set the winprint processor for printer
9388 entries later. Used to debug the LexMark Optra S 1855 PCL
9394 /****************************************************************
9396 ****************************************************************/
9398 WERROR _spoolss_AddPort(pipes_struct *p,
9399 struct spoolss_AddPort *r)
9401 /* do what w2k3 does */
9403 return WERR_NOT_SUPPORTED;
9406 /****************************************************************
9407 _spoolss_GetPrinterDriver
9408 ****************************************************************/
9410 WERROR _spoolss_GetPrinterDriver(pipes_struct *p,
9411 struct spoolss_GetPrinterDriver *r)
9413 p->rng_fault_state = true;
9414 return WERR_NOT_SUPPORTED;
9417 /****************************************************************
9418 _spoolss_ReadPrinter
9419 ****************************************************************/
9421 WERROR _spoolss_ReadPrinter(pipes_struct *p,
9422 struct spoolss_ReadPrinter *r)
9424 p->rng_fault_state = true;
9425 return WERR_NOT_SUPPORTED;
9428 /****************************************************************
9429 _spoolss_WaitForPrinterChange
9430 ****************************************************************/
9432 WERROR _spoolss_WaitForPrinterChange(pipes_struct *p,
9433 struct spoolss_WaitForPrinterChange *r)
9435 p->rng_fault_state = true;
9436 return WERR_NOT_SUPPORTED;
9439 /****************************************************************
9440 _spoolss_ConfigurePort
9441 ****************************************************************/
9443 WERROR _spoolss_ConfigurePort(pipes_struct *p,
9444 struct spoolss_ConfigurePort *r)
9446 p->rng_fault_state = true;
9447 return WERR_NOT_SUPPORTED;
9450 /****************************************************************
9452 ****************************************************************/
9454 WERROR _spoolss_DeletePort(pipes_struct *p,
9455 struct spoolss_DeletePort *r)
9457 p->rng_fault_state = true;
9458 return WERR_NOT_SUPPORTED;
9461 /****************************************************************
9462 _spoolss_CreatePrinterIC
9463 ****************************************************************/
9465 WERROR _spoolss_CreatePrinterIC(pipes_struct *p,
9466 struct spoolss_CreatePrinterIC *r)
9468 p->rng_fault_state = true;
9469 return WERR_NOT_SUPPORTED;
9472 /****************************************************************
9473 _spoolss_PlayGDIScriptOnPrinterIC
9474 ****************************************************************/
9476 WERROR _spoolss_PlayGDIScriptOnPrinterIC(pipes_struct *p,
9477 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9479 p->rng_fault_state = true;
9480 return WERR_NOT_SUPPORTED;
9483 /****************************************************************
9484 _spoolss_DeletePrinterIC
9485 ****************************************************************/
9487 WERROR _spoolss_DeletePrinterIC(pipes_struct *p,
9488 struct spoolss_DeletePrinterIC *r)
9490 p->rng_fault_state = true;
9491 return WERR_NOT_SUPPORTED;
9494 /****************************************************************
9495 _spoolss_AddPrinterConnection
9496 ****************************************************************/
9498 WERROR _spoolss_AddPrinterConnection(pipes_struct *p,
9499 struct spoolss_AddPrinterConnection *r)
9501 p->rng_fault_state = true;
9502 return WERR_NOT_SUPPORTED;
9505 /****************************************************************
9506 _spoolss_DeletePrinterConnection
9507 ****************************************************************/
9509 WERROR _spoolss_DeletePrinterConnection(pipes_struct *p,
9510 struct spoolss_DeletePrinterConnection *r)
9512 p->rng_fault_state = true;
9513 return WERR_NOT_SUPPORTED;
9516 /****************************************************************
9517 _spoolss_PrinterMessageBox
9518 ****************************************************************/
9520 WERROR _spoolss_PrinterMessageBox(pipes_struct *p,
9521 struct spoolss_PrinterMessageBox *r)
9523 p->rng_fault_state = true;
9524 return WERR_NOT_SUPPORTED;
9527 /****************************************************************
9529 ****************************************************************/
9531 WERROR _spoolss_AddMonitor(pipes_struct *p,
9532 struct spoolss_AddMonitor *r)
9534 p->rng_fault_state = true;
9535 return WERR_NOT_SUPPORTED;
9538 /****************************************************************
9539 _spoolss_DeleteMonitor
9540 ****************************************************************/
9542 WERROR _spoolss_DeleteMonitor(pipes_struct *p,
9543 struct spoolss_DeleteMonitor *r)
9545 p->rng_fault_state = true;
9546 return WERR_NOT_SUPPORTED;
9549 /****************************************************************
9550 _spoolss_DeletePrintProcessor
9551 ****************************************************************/
9553 WERROR _spoolss_DeletePrintProcessor(pipes_struct *p,
9554 struct spoolss_DeletePrintProcessor *r)
9556 p->rng_fault_state = true;
9557 return WERR_NOT_SUPPORTED;
9560 /****************************************************************
9561 _spoolss_AddPrintProvidor
9562 ****************************************************************/
9564 WERROR _spoolss_AddPrintProvidor(pipes_struct *p,
9565 struct spoolss_AddPrintProvidor *r)
9567 p->rng_fault_state = true;
9568 return WERR_NOT_SUPPORTED;
9571 /****************************************************************
9572 _spoolss_DeletePrintProvidor
9573 ****************************************************************/
9575 WERROR _spoolss_DeletePrintProvidor(pipes_struct *p,
9576 struct spoolss_DeletePrintProvidor *r)
9578 p->rng_fault_state = true;
9579 return WERR_NOT_SUPPORTED;
9582 /****************************************************************
9583 _spoolss_FindFirstPrinterChangeNotification
9584 ****************************************************************/
9586 WERROR _spoolss_FindFirstPrinterChangeNotification(pipes_struct *p,
9587 struct spoolss_FindFirstPrinterChangeNotification *r)
9589 p->rng_fault_state = true;
9590 return WERR_NOT_SUPPORTED;
9593 /****************************************************************
9594 _spoolss_FindNextPrinterChangeNotification
9595 ****************************************************************/
9597 WERROR _spoolss_FindNextPrinterChangeNotification(pipes_struct *p,
9598 struct spoolss_FindNextPrinterChangeNotification *r)
9600 p->rng_fault_state = true;
9601 return WERR_NOT_SUPPORTED;
9604 /****************************************************************
9605 _spoolss_RouterFindFirstPrinterChangeNotificationOld
9606 ****************************************************************/
9608 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(pipes_struct *p,
9609 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
9611 p->rng_fault_state = true;
9612 return WERR_NOT_SUPPORTED;
9615 /****************************************************************
9616 _spoolss_ReplyOpenPrinter
9617 ****************************************************************/
9619 WERROR _spoolss_ReplyOpenPrinter(pipes_struct *p,
9620 struct spoolss_ReplyOpenPrinter *r)
9622 p->rng_fault_state = true;
9623 return WERR_NOT_SUPPORTED;
9626 /****************************************************************
9627 _spoolss_RouterReplyPrinter
9628 ****************************************************************/
9630 WERROR _spoolss_RouterReplyPrinter(pipes_struct *p,
9631 struct spoolss_RouterReplyPrinter *r)
9633 p->rng_fault_state = true;
9634 return WERR_NOT_SUPPORTED;
9637 /****************************************************************
9638 _spoolss_ReplyClosePrinter
9639 ****************************************************************/
9641 WERROR _spoolss_ReplyClosePrinter(pipes_struct *p,
9642 struct spoolss_ReplyClosePrinter *r)
9644 p->rng_fault_state = true;
9645 return WERR_NOT_SUPPORTED;
9648 /****************************************************************
9650 ****************************************************************/
9652 WERROR _spoolss_AddPortEx(pipes_struct *p,
9653 struct spoolss_AddPortEx *r)
9655 p->rng_fault_state = true;
9656 return WERR_NOT_SUPPORTED;
9659 /****************************************************************
9660 _spoolss_RouterFindFirstPrinterChangeNotification
9661 ****************************************************************/
9663 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(pipes_struct *p,
9664 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
9666 p->rng_fault_state = true;
9667 return WERR_NOT_SUPPORTED;
9670 /****************************************************************
9671 _spoolss_SpoolerInit
9672 ****************************************************************/
9674 WERROR _spoolss_SpoolerInit(pipes_struct *p,
9675 struct spoolss_SpoolerInit *r)
9677 p->rng_fault_state = true;
9678 return WERR_NOT_SUPPORTED;
9681 /****************************************************************
9682 _spoolss_ResetPrinterEx
9683 ****************************************************************/
9685 WERROR _spoolss_ResetPrinterEx(pipes_struct *p,
9686 struct spoolss_ResetPrinterEx *r)
9688 p->rng_fault_state = true;
9689 return WERR_NOT_SUPPORTED;
9692 /****************************************************************
9693 _spoolss_RouterReplyPrinterEx
9694 ****************************************************************/
9696 WERROR _spoolss_RouterReplyPrinterEx(pipes_struct *p,
9697 struct spoolss_RouterReplyPrinterEx *r)
9699 p->rng_fault_state = true;
9700 return WERR_NOT_SUPPORTED;
9703 /****************************************************************
9705 ****************************************************************/
9707 WERROR _spoolss_44(pipes_struct *p,
9708 struct spoolss_44 *r)
9710 p->rng_fault_state = true;
9711 return WERR_NOT_SUPPORTED;
9714 /****************************************************************
9716 ****************************************************************/
9718 WERROR _spoolss_47(pipes_struct *p,
9719 struct spoolss_47 *r)
9721 p->rng_fault_state = true;
9722 return WERR_NOT_SUPPORTED;
9725 /****************************************************************
9727 ****************************************************************/
9729 WERROR _spoolss_4a(pipes_struct *p,
9730 struct spoolss_4a *r)
9732 p->rng_fault_state = true;
9733 return WERR_NOT_SUPPORTED;
9736 /****************************************************************
9738 ****************************************************************/
9740 WERROR _spoolss_4b(pipes_struct *p,
9741 struct spoolss_4b *r)
9743 p->rng_fault_state = true;
9744 return WERR_NOT_SUPPORTED;
9747 /****************************************************************
9749 ****************************************************************/
9751 WERROR _spoolss_4c(pipes_struct *p,
9752 struct spoolss_4c *r)
9754 p->rng_fault_state = true;
9755 return WERR_NOT_SUPPORTED;
9758 /****************************************************************
9760 ****************************************************************/
9762 WERROR _spoolss_53(pipes_struct *p,
9763 struct spoolss_53 *r)
9765 p->rng_fault_state = true;
9766 return WERR_NOT_SUPPORTED;
9769 /****************************************************************
9771 ****************************************************************/
9773 WERROR _spoolss_55(pipes_struct *p,
9774 struct spoolss_55 *r)
9776 p->rng_fault_state = true;
9777 return WERR_NOT_SUPPORTED;
9780 /****************************************************************
9782 ****************************************************************/
9784 WERROR _spoolss_56(pipes_struct *p,
9785 struct spoolss_56 *r)
9787 p->rng_fault_state = true;
9788 return WERR_NOT_SUPPORTED;
9791 /****************************************************************
9793 ****************************************************************/
9795 WERROR _spoolss_57(pipes_struct *p,
9796 struct spoolss_57 *r)
9798 p->rng_fault_state = true;
9799 return WERR_NOT_SUPPORTED;
9802 /****************************************************************
9804 ****************************************************************/
9806 WERROR _spoolss_5a(pipes_struct *p,
9807 struct spoolss_5a *r)
9809 p->rng_fault_state = true;
9810 return WERR_NOT_SUPPORTED;
9813 /****************************************************************
9815 ****************************************************************/
9817 WERROR _spoolss_5b(pipes_struct *p,
9818 struct spoolss_5b *r)
9820 p->rng_fault_state = true;
9821 return WERR_NOT_SUPPORTED;
9824 /****************************************************************
9826 ****************************************************************/
9828 WERROR _spoolss_5c(pipes_struct *p,
9829 struct spoolss_5c *r)
9831 p->rng_fault_state = true;
9832 return WERR_NOT_SUPPORTED;
9835 /****************************************************************
9837 ****************************************************************/
9839 WERROR _spoolss_5d(pipes_struct *p,
9840 struct spoolss_5d *r)
9842 p->rng_fault_state = true;
9843 return WERR_NOT_SUPPORTED;
9846 /****************************************************************
9848 ****************************************************************/
9850 WERROR _spoolss_5e(pipes_struct *p,
9851 struct spoolss_5e *r)
9853 p->rng_fault_state = true;
9854 return WERR_NOT_SUPPORTED;
9857 /****************************************************************
9859 ****************************************************************/
9861 WERROR _spoolss_5f(pipes_struct *p,
9862 struct spoolss_5f *r)
9864 p->rng_fault_state = true;
9865 return WERR_NOT_SUPPORTED;
9868 /****************************************************************
9870 ****************************************************************/
9872 WERROR _spoolss_60(pipes_struct *p,
9873 struct spoolss_60 *r)
9875 p->rng_fault_state = true;
9876 return WERR_NOT_SUPPORTED;
9879 /****************************************************************
9881 ****************************************************************/
9883 WERROR _spoolss_61(pipes_struct *p,
9884 struct spoolss_61 *r)
9886 p->rng_fault_state = true;
9887 return WERR_NOT_SUPPORTED;
9890 /****************************************************************
9892 ****************************************************************/
9894 WERROR _spoolss_62(pipes_struct *p,
9895 struct spoolss_62 *r)
9897 p->rng_fault_state = true;
9898 return WERR_NOT_SUPPORTED;
9901 /****************************************************************
9903 ****************************************************************/
9905 WERROR _spoolss_63(pipes_struct *p,
9906 struct spoolss_63 *r)
9908 p->rng_fault_state = true;
9909 return WERR_NOT_SUPPORTED;
9912 /****************************************************************
9914 ****************************************************************/
9916 WERROR _spoolss_64(pipes_struct *p,
9917 struct spoolss_64 *r)
9919 p->rng_fault_state = true;
9920 return WERR_NOT_SUPPORTED;
9923 /****************************************************************
9925 ****************************************************************/
9927 WERROR _spoolss_65(pipes_struct *p,
9928 struct spoolss_65 *r)
9930 p->rng_fault_state = true;
9931 return WERR_NOT_SUPPORTED;
9934 /****************************************************************
9935 _spoolss_GetCorePrinterDrivers
9936 ****************************************************************/
9938 WERROR _spoolss_GetCorePrinterDrivers(pipes_struct *p,
9939 struct spoolss_GetCorePrinterDrivers *r)
9941 p->rng_fault_state = true;
9942 return WERR_NOT_SUPPORTED;
9945 /****************************************************************
9947 ****************************************************************/
9949 WERROR _spoolss_67(pipes_struct *p,
9950 struct spoolss_67 *r)
9952 p->rng_fault_state = true;
9953 return WERR_NOT_SUPPORTED;
9956 /****************************************************************
9957 _spoolss_GetPrinterDriverPackagePath
9958 ****************************************************************/
9960 WERROR _spoolss_GetPrinterDriverPackagePath(pipes_struct *p,
9961 struct spoolss_GetPrinterDriverPackagePath *r)
9963 p->rng_fault_state = true;
9964 return WERR_NOT_SUPPORTED;
9967 /****************************************************************
9969 ****************************************************************/
9971 WERROR _spoolss_69(pipes_struct *p,
9972 struct spoolss_69 *r)
9974 p->rng_fault_state = true;
9975 return WERR_NOT_SUPPORTED;
9978 /****************************************************************
9980 ****************************************************************/
9982 WERROR _spoolss_6a(pipes_struct *p,
9983 struct spoolss_6a *r)
9985 p->rng_fault_state = true;
9986 return WERR_NOT_SUPPORTED;
9989 /****************************************************************
9991 ****************************************************************/
9993 WERROR _spoolss_6b(pipes_struct *p,
9994 struct spoolss_6b *r)
9996 p->rng_fault_state = true;
9997 return WERR_NOT_SUPPORTED;
10000 /****************************************************************
10002 ****************************************************************/
10004 WERROR _spoolss_6c(pipes_struct *p,
10005 struct spoolss_6c *r)
10007 p->rng_fault_state = true;
10008 return WERR_NOT_SUPPORTED;
10011 /****************************************************************
10013 ****************************************************************/
10015 WERROR _spoolss_6d(pipes_struct *p,
10016 struct spoolss_6d *r)
10018 p->rng_fault_state = true;
10019 return WERR_NOT_SUPPORTED;