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 standard_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 (!pinfo2->drivername) {
1349 if (strcmp(drivername, pinfo2->drivername) != 0) {
1353 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1355 /* all we care about currently is the change_id */
1356 result = winreg_printer_update_changeid(tmp_ctx,
1358 pinfo2->printername);
1360 if (!W_ERROR_IS_OK(result)) {
1361 DEBUG(3, ("do_drv_upgrade_printer: "
1362 "Failed to update changeid [%s]\n",
1363 win_errstr(result)));
1369 talloc_free(tmp_ctx);
1372 /********************************************************************
1373 Update the cache for all printq's with a registered client
1375 ********************************************************************/
1377 void update_monitored_printq_cache( void )
1379 Printer_entry *printer = printers_list;
1382 /* loop through all printers and update the cache where
1383 client_connected == true */
1386 if ( (printer->printer_type == SPLHND_PRINTER)
1387 && printer->notify.client_connected )
1389 snum = print_queue_snum(printer->sharename);
1390 print_queue_status( snum, NULL, NULL );
1393 printer = printer->next;
1399 /****************************************************************
1400 _spoolss_OpenPrinter
1401 ****************************************************************/
1403 WERROR _spoolss_OpenPrinter(pipes_struct *p,
1404 struct spoolss_OpenPrinter *r)
1406 struct spoolss_OpenPrinterEx e;
1409 ZERO_STRUCT(e.in.userlevel);
1411 e.in.printername = r->in.printername;
1412 e.in.datatype = r->in.datatype;
1413 e.in.devmode_ctr = r->in.devmode_ctr;
1414 e.in.access_mask = r->in.access_mask;
1417 e.out.handle = r->out.handle;
1419 werr = _spoolss_OpenPrinterEx(p, &e);
1421 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1422 /* OpenPrinterEx returns this for a bad
1423 * printer name. We must return WERR_INVALID_PRINTER_NAME
1426 werr = WERR_INVALID_PRINTER_NAME;
1432 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1433 struct spoolss_DeviceMode *orig,
1434 struct spoolss_DeviceMode **dest)
1436 struct spoolss_DeviceMode *dm;
1438 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1443 /* copy all values, then duplicate strings and structs */
1446 dm->devicename = talloc_strdup(dm, orig->devicename);
1447 if (!dm->devicename) {
1450 dm->formname = talloc_strdup(dm, orig->formname);
1451 if (!dm->formname) {
1454 if (orig->driverextra_data.data) {
1455 dm->driverextra_data.data =
1456 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1457 orig->driverextra_data.length);
1458 if (!dm->driverextra_data.data) {
1467 /****************************************************************
1468 _spoolss_OpenPrinterEx
1469 ****************************************************************/
1471 WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
1472 struct spoolss_OpenPrinterEx *r)
1475 Printer_entry *Printer=NULL;
1477 if (!r->in.printername) {
1478 return WERR_INVALID_PARAM;
1481 /* some sanity check because you can open a printer or a print server */
1482 /* aka: \\server\printer or \\server */
1484 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1486 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1487 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1488 " for printer %s\n", r->in.printername));
1489 ZERO_STRUCTP(r->out.handle);
1490 return WERR_INVALID_PARAM;
1493 Printer = find_printer_index_by_hnd(p, r->out.handle);
1495 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1496 "handle we created for printer %s\n", r->in.printername));
1497 close_printer_handle(p, r->out.handle);
1498 ZERO_STRUCTP(r->out.handle);
1499 return WERR_INVALID_PARAM;
1503 * First case: the user is opening the print server:
1505 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1506 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1508 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1509 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1510 * or if the user is listed in the smb.conf printer admin parameter.
1512 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1513 * client view printer folder, but does not show the MSAPW.
1515 * Note: this test needs code to check access rights here too. Jeremy
1516 * could you look at this?
1518 * Second case: the user is opening a printer:
1519 * NT doesn't let us connect to a printer if the connecting user
1520 * doesn't have print permission.
1522 * Third case: user is opening a Port Monitor
1523 * access checks same as opening a handle to the print server.
1526 switch (Printer->printer_type )
1529 case SPLHND_PORTMON_TCP:
1530 case SPLHND_PORTMON_LOCAL:
1531 /* Printserver handles use global struct... */
1535 /* Map standard access rights to object specific access rights */
1537 se_map_standard(&r->in.access_mask,
1538 &printserver_std_mapping);
1540 /* Deny any object specific bits that don't apply to print
1541 servers (i.e printer and job specific bits) */
1543 r->in.access_mask &= SEC_MASK_SPECIFIC;
1545 if (r->in.access_mask &
1546 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1547 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1548 close_printer_handle(p, r->out.handle);
1549 ZERO_STRUCTP(r->out.handle);
1550 return WERR_ACCESS_DENIED;
1553 /* Allow admin access */
1555 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1557 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1559 if (!lp_ms_add_printer_wizard()) {
1560 close_printer_handle(p, r->out.handle);
1561 ZERO_STRUCTP(r->out.handle);
1562 return WERR_ACCESS_DENIED;
1565 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1566 and not a printer admin, then fail */
1568 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1569 !user_has_privileges(p->server_info->ptok,
1571 !token_contains_name_in_list(
1572 uidtoname(p->server_info->utok.uid),
1573 p->server_info->info3->base.domain.string,
1575 p->server_info->ptok,
1576 lp_printer_admin(snum))) {
1577 close_printer_handle(p, r->out.handle);
1578 ZERO_STRUCTP(r->out.handle);
1579 return WERR_ACCESS_DENIED;
1582 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1586 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1589 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1590 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1592 /* We fall through to return WERR_OK */
1595 case SPLHND_PRINTER:
1596 /* NT doesn't let us connect to a printer if the connecting user
1597 doesn't have print permission. */
1599 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1600 close_printer_handle(p, r->out.handle);
1601 ZERO_STRUCTP(r->out.handle);
1605 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1606 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1609 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1611 /* map an empty access mask to the minimum access mask */
1612 if (r->in.access_mask == 0x0)
1613 r->in.access_mask = PRINTER_ACCESS_USE;
1616 * If we are not serving the printer driver for this printer,
1617 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1618 * will keep NT clients happy --jerry
1621 if (lp_use_client_driver(snum)
1622 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1624 r->in.access_mask = PRINTER_ACCESS_USE;
1627 /* check smb.conf parameters and the the sec_desc */
1629 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1630 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1631 ZERO_STRUCTP(r->out.handle);
1632 return WERR_ACCESS_DENIED;
1635 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1636 p->server_info->ptok, snum) ||
1637 !print_access_check(p->server_info, snum,
1638 r->in.access_mask)) {
1639 DEBUG(3, ("access DENIED for printer open\n"));
1640 close_printer_handle(p, r->out.handle);
1641 ZERO_STRUCTP(r->out.handle);
1642 return WERR_ACCESS_DENIED;
1645 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1646 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1647 close_printer_handle(p, r->out.handle);
1648 ZERO_STRUCTP(r->out.handle);
1649 return WERR_ACCESS_DENIED;
1652 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1653 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1655 r->in.access_mask = PRINTER_ACCESS_USE;
1657 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1658 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1660 winreg_create_printer(p->mem_ctx,
1662 Printer->servername,
1663 lp_const_servicename(snum));
1668 /* sanity check to prevent programmer error */
1669 ZERO_STRUCTP(r->out.handle);
1673 Printer->access_granted = r->in.access_mask;
1676 * If the client sent a devmode in the OpenPrinter() call, then
1677 * save it here in case we get a job submission on this handle
1680 if ((Printer->printer_type != SPLHND_SERVER) &&
1681 r->in.devmode_ctr.devmode) {
1682 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1686 #if 0 /* JERRY -- I'm doubtful this is really effective */
1687 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1688 optimization in Windows 2000 clients --jerry */
1690 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1691 && (RA_WIN2K == get_remote_arch()) )
1693 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1694 sys_usleep( 500000 );
1701 /****************************************************************
1702 _spoolss_ClosePrinter
1703 ****************************************************************/
1705 WERROR _spoolss_ClosePrinter(pipes_struct *p,
1706 struct spoolss_ClosePrinter *r)
1708 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1710 if (Printer && Printer->document_started) {
1711 struct spoolss_EndDocPrinter e;
1713 e.in.handle = r->in.handle;
1715 _spoolss_EndDocPrinter(p, &e);
1718 if (!close_printer_handle(p, r->in.handle))
1721 /* clear the returned printer handle. Observed behavior
1722 from Win2k server. Don't think this really matters.
1723 Previous code just copied the value of the closed
1726 ZERO_STRUCTP(r->out.handle);
1731 /****************************************************************
1732 _spoolss_DeletePrinter
1733 ****************************************************************/
1735 WERROR _spoolss_DeletePrinter(pipes_struct *p,
1736 struct spoolss_DeletePrinter *r)
1738 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1742 if (Printer && Printer->document_started) {
1743 struct spoolss_EndDocPrinter e;
1745 e.in.handle = r->in.handle;
1747 _spoolss_EndDocPrinter(p, &e);
1750 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
1751 winreg_delete_printer_key(p->mem_ctx,
1753 lp_const_servicename(snum),
1757 result = delete_printer_handle(p, r->in.handle);
1762 /*******************************************************************
1763 * static function to lookup the version id corresponding to an
1764 * long architecture string
1765 ******************************************************************/
1767 static const struct print_architecture_table_node archi_table[]= {
1769 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1770 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1771 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1772 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
1773 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
1774 {"Windows IA64", SPL_ARCH_IA64, 3 },
1775 {"Windows x64", SPL_ARCH_X64, 3 },
1779 static int get_version_id(const char *arch)
1783 for (i=0; archi_table[i].long_archi != NULL; i++)
1785 if (strcmp(arch, archi_table[i].long_archi) == 0)
1786 return (archi_table[i].version);
1792 /****************************************************************
1793 _spoolss_DeletePrinterDriver
1794 ****************************************************************/
1796 WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
1797 struct spoolss_DeletePrinterDriver *r)
1800 struct spoolss_DriverInfo8 *info = NULL;
1801 struct spoolss_DriverInfo8 *info_win2k = NULL;
1804 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1806 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1807 and not a printer admin, then fail */
1809 if ( (p->server_info->utok.uid != sec_initial_uid())
1810 && !user_has_privileges(p->server_info->ptok, &se_printop )
1811 && !token_contains_name_in_list(
1812 uidtoname(p->server_info->utok.uid),
1813 p->server_info->info3->base.domain.string,
1815 p->server_info->ptok,
1816 lp_printer_admin(-1)) )
1818 return WERR_ACCESS_DENIED;
1821 /* check that we have a valid driver name first */
1823 if ((version = get_version_id(r->in.architecture)) == -1)
1824 return WERR_INVALID_ENVIRONMENT;
1826 status = winreg_get_driver(p->mem_ctx, p->server_info,
1827 r->in.architecture, r->in.driver,
1829 if (!W_ERROR_IS_OK(status)) {
1830 /* try for Win2k driver if "Windows NT x86" */
1832 if ( version == 2 ) {
1835 status = winreg_get_driver(p->mem_ctx, p->server_info,
1839 if (!W_ERROR_IS_OK(status)) {
1840 status = WERR_UNKNOWN_PRINTER_DRIVER;
1844 /* otherwise it was a failure */
1846 status = WERR_UNKNOWN_PRINTER_DRIVER;
1852 if (printer_driver_in_use(p->mem_ctx, p->server_info, info)) {
1853 status = WERR_PRINTER_DRIVER_IN_USE;
1858 status = winreg_get_driver(p->mem_ctx, p->server_info,
1860 r->in.driver, 3, &info_win2k);
1861 if (W_ERROR_IS_OK(status)) {
1862 /* if we get to here, we now have 2 driver info structures to remove */
1863 /* remove the Win2k driver first*/
1865 status = winreg_del_driver(p->mem_ctx,
1868 talloc_free(info_win2k);
1870 /* this should not have failed---if it did, report to client */
1871 if (!W_ERROR_IS_OK(status)) {
1877 status = winreg_del_driver(p->mem_ctx, p->server_info, info, version);
1885 /****************************************************************
1886 _spoolss_DeletePrinterDriverEx
1887 ****************************************************************/
1889 WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
1890 struct spoolss_DeletePrinterDriverEx *r)
1892 struct spoolss_DriverInfo8 *info = NULL;
1893 struct spoolss_DriverInfo8 *info_win2k = NULL;
1897 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1899 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1900 and not a printer admin, then fail */
1902 if ( (p->server_info->utok.uid != sec_initial_uid())
1903 && !user_has_privileges(p->server_info->ptok, &se_printop )
1904 && !token_contains_name_in_list(
1905 uidtoname(p->server_info->utok.uid),
1906 p->server_info->info3->base.domain.string,
1908 p->server_info->ptok, lp_printer_admin(-1)) )
1910 return WERR_ACCESS_DENIED;
1913 /* check that we have a valid driver name first */
1914 if ((version = get_version_id(r->in.architecture)) == -1) {
1915 /* this is what NT returns */
1916 return WERR_INVALID_ENVIRONMENT;
1919 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
1920 version = r->in.version;
1922 status = winreg_get_driver(p->mem_ctx, p->server_info,
1923 r->in.architecture, r->in.driver,
1925 if (!W_ERROR_IS_OK(status)) {
1926 status = WERR_UNKNOWN_PRINTER_DRIVER;
1929 * if the client asked for a specific version,
1930 * or this is something other than Windows NT x86,
1934 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
1937 /* try for Win2k driver if "Windows NT x86" */
1940 status = winreg_get_driver(info, p->server_info,
1944 if (!W_ERROR_IS_OK(status)) {
1945 status = WERR_UNKNOWN_PRINTER_DRIVER;
1950 if (printer_driver_in_use(info, p->server_info, info)) {
1951 status = WERR_PRINTER_DRIVER_IN_USE;
1956 * we have a couple of cases to consider.
1957 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
1958 * then the delete should fail if **any** files overlap with
1960 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
1961 * non-overlapping files
1962 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
1963 * is set, the do not delete any files
1964 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
1967 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
1969 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
1972 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
1973 printer_driver_files_in_use(info, p->server_info, info)) {
1974 /* no idea of the correct error here */
1975 status = WERR_ACCESS_DENIED;
1980 /* also check for W32X86/3 if necessary; maybe we already have? */
1982 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
1983 status = winreg_get_driver(info, p->server_info,
1985 r->in.driver, 3, &info_win2k);
1986 if (W_ERROR_IS_OK(status)) {
1989 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
1990 printer_driver_files_in_use(info, p->server_info,
1992 /* no idea of the correct error here */
1993 talloc_free(info_win2k);
1994 status = WERR_ACCESS_DENIED;
1998 /* if we get to here, we now have 2 driver info structures to remove */
1999 /* remove the Win2k driver first*/
2001 status = winreg_del_driver(info, p->server_info,
2004 /* this should not have failed---if it did, report to client */
2006 if (!W_ERROR_IS_OK(status)) {
2011 * now delete any associated files if delete_files is
2012 * true. Even if this part failes, we return succes
2013 * because the driver doesn not exist any more
2016 delete_driver_files(p->server_info,
2022 status = winreg_del_driver(info, p->server_info, info, version);
2023 if (!W_ERROR_IS_OK(status)) {
2028 * now delete any associated files if delete_files is
2029 * true. Even if this part failes, we return succes
2030 * because the driver doesn not exist any more
2033 delete_driver_files(p->server_info, info);
2042 /********************************************************************
2043 GetPrinterData on a printer server Handle.
2044 ********************************************************************/
2046 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2048 enum winreg_Type *type,
2049 union spoolss_PrinterData *data)
2051 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2053 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2059 if (!StrCaseCmp(value, "BeepEnabled")) {
2065 if (!StrCaseCmp(value, "EventLog")) {
2067 /* formally was 0x1b */
2072 if (!StrCaseCmp(value, "NetPopup")) {
2078 if (!StrCaseCmp(value, "MajorVersion")) {
2081 /* Windows NT 4.0 seems to not allow uploading of drivers
2082 to a server that reports 0x3 as the MajorVersion.
2083 need to investigate more how Win2k gets around this .
2086 if (RA_WINNT == get_remote_arch()) {
2095 if (!StrCaseCmp(value, "MinorVersion")) {
2102 * uint32_t size = 0x114
2103 * uint32_t major = 5
2104 * uint32_t minor = [0|1]
2105 * uint32_t build = [2195|2600]
2106 * extra unicode string = e.g. "Service Pack 3"
2108 if (!StrCaseCmp(value, "OSVersion")) {
2110 enum ndr_err_code ndr_err;
2111 struct spoolss_OSVersion os;
2113 os.major = 5; /* Windows 2000 == 5.0 */
2115 os.build = 2195; /* build */
2116 os.extra_string = ""; /* leave extra string empty */
2118 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2119 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2120 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2121 return WERR_GENERAL_FAILURE;
2125 data->binary = blob;
2131 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2134 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2135 W_ERROR_HAVE_NO_MEMORY(data->string);
2140 if (!StrCaseCmp(value, "Architecture")) {
2142 data->string = talloc_strdup(mem_ctx,
2143 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2144 W_ERROR_HAVE_NO_MEMORY(data->string);
2149 if (!StrCaseCmp(value, "DsPresent")) {
2152 /* only show the publish check box if we are a
2153 member of a AD domain */
2155 if (lp_security() == SEC_ADS) {
2163 if (!StrCaseCmp(value, "DNSMachineName")) {
2164 const char *hostname = get_mydnsfullname();
2167 return WERR_BADFILE;
2171 data->string = talloc_strdup(mem_ctx, hostname);
2172 W_ERROR_HAVE_NO_MEMORY(data->string);
2179 return WERR_INVALID_PARAM;
2182 /****************************************************************
2183 _spoolss_GetPrinterData
2184 ****************************************************************/
2186 WERROR _spoolss_GetPrinterData(pipes_struct *p,
2187 struct spoolss_GetPrinterData *r)
2189 struct spoolss_GetPrinterDataEx r2;
2191 r2.in.handle = r->in.handle;
2192 r2.in.key_name = "PrinterDriverData";
2193 r2.in.value_name = r->in.value_name;
2194 r2.in.offered = r->in.offered;
2195 r2.out.type = r->out.type;
2196 r2.out.data = r->out.data;
2197 r2.out.needed = r->out.needed;
2199 return _spoolss_GetPrinterDataEx(p, &r2);
2202 /*********************************************************
2203 Connect to the client machine.
2204 **********************************************************/
2206 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2207 struct sockaddr_storage *client_ss, const char *remote_machine)
2210 struct cli_state *the_cli;
2211 struct sockaddr_storage rm_addr;
2212 char addr[INET6_ADDRSTRLEN];
2214 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2215 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2217 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2218 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2221 print_sockaddr(addr, sizeof(addr), &rm_addr);
2223 rm_addr = *client_ss;
2224 print_sockaddr(addr, sizeof(addr), &rm_addr);
2225 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2229 if (ismyaddr((struct sockaddr *)&rm_addr)) {
2230 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2235 /* setup the connection */
2236 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2237 &rm_addr, 0, "IPC$", "IPC",
2241 0, lp_client_signing(), NULL );
2243 if ( !NT_STATUS_IS_OK( ret ) ) {
2244 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2249 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2250 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2251 cli_shutdown(the_cli);
2256 * Ok - we have an anonymous connection to the IPC$ share.
2257 * Now start the NT Domain stuff :-).
2260 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2261 if (!NT_STATUS_IS_OK(ret)) {
2262 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2263 remote_machine, nt_errstr(ret)));
2264 cli_shutdown(the_cli);
2271 /***************************************************************************
2272 Connect to the client.
2273 ****************************************************************************/
2275 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2276 uint32_t localprinter, uint32_t type,
2277 struct policy_handle *handle,
2278 struct sockaddr_storage *client_ss)
2284 * If it's the first connection, contact the client
2285 * and connect to the IPC$ share anonymously
2287 if (smb_connections==0) {
2288 fstring unix_printer;
2290 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2292 if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ss, unix_printer ))
2295 messaging_register(smbd_messaging_context(), NULL,
2296 MSG_PRINTER_NOTIFY2,
2297 receive_notify2_message_list);
2298 /* Tell the connections db we're now interested in printer
2299 * notify messages. */
2300 serverid_register_msg_flags(
2301 messaging_server_id(smbd_messaging_context()),
2302 true, FLAG_MSG_PRINT_NOTIFY);
2306 * Tell the specific printing tdb we want messages for this printer
2307 * by registering our PID.
2310 if (!print_notify_register_pid(snum))
2311 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2315 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2323 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2324 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2325 win_errstr(result)));
2327 return (W_ERROR_IS_OK(result));
2330 /****************************************************************
2331 ****************************************************************/
2333 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2334 const struct spoolss_NotifyOption *r)
2336 struct spoolss_NotifyOption *option;
2343 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2350 if (!option->count) {
2354 option->types = talloc_zero_array(option,
2355 struct spoolss_NotifyOptionType, option->count);
2356 if (!option->types) {
2357 talloc_free(option);
2361 for (i=0; i < option->count; i++) {
2362 option->types[i] = r->types[i];
2364 if (option->types[i].count) {
2365 option->types[i].fields = talloc_zero_array(option,
2366 union spoolss_Field, option->types[i].count);
2367 if (!option->types[i].fields) {
2368 talloc_free(option);
2371 for (k=0; k<option->types[i].count; k++) {
2372 option->types[i].fields[k] =
2373 r->types[i].fields[k];
2381 /****************************************************************
2382 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2384 * before replying OK: status=0 a rpc call is made to the workstation
2385 * asking ReplyOpenPrinter
2387 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2388 * called from api_spoolss_rffpcnex
2389 ****************************************************************/
2391 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
2392 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2395 struct spoolss_NotifyOption *option = r->in.notify_options;
2396 struct sockaddr_storage client_ss;
2398 /* store the notify value in the printer struct */
2400 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2403 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2404 "Invalid handle (%s:%u:%u).\n",
2405 OUR_HANDLE(r->in.handle)));
2409 Printer->notify.flags = r->in.flags;
2410 Printer->notify.options = r->in.options;
2411 Printer->notify.printerlocal = r->in.printer_local;
2413 TALLOC_FREE(Printer->notify.option);
2414 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2416 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2418 /* Connect to the client machine and send a ReplyOpenPrinter */
2420 if ( Printer->printer_type == SPLHND_SERVER)
2422 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2423 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2426 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2427 "client_address is %s\n", p->client_address));
2429 if (!interpret_string_addr(&client_ss, p->client_address,
2431 return WERR_SERVER_UNAVAILABLE;
2434 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2435 Printer->notify.printerlocal, 1,
2436 &Printer->notify.client_hnd, &client_ss))
2437 return WERR_SERVER_UNAVAILABLE;
2439 Printer->notify.client_connected = true;
2444 /*******************************************************************
2445 * fill a notify_info_data with the servername
2446 ********************************************************************/
2448 static void spoolss_notify_server_name(int snum,
2449 struct spoolss_Notify *data,
2450 print_queue_struct *queue,
2451 struct spoolss_PrinterInfo2 *pinfo2,
2452 TALLOC_CTX *mem_ctx)
2454 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2457 /*******************************************************************
2458 * fill a notify_info_data with the printername (not including the servername).
2459 ********************************************************************/
2461 static void spoolss_notify_printer_name(int snum,
2462 struct spoolss_Notify *data,
2463 print_queue_struct *queue,
2464 struct spoolss_PrinterInfo2 *pinfo2,
2465 TALLOC_CTX *mem_ctx)
2467 /* the notify name should not contain the \\server\ part */
2468 const char *p = strrchr(pinfo2->printername, '\\');
2471 p = pinfo2->printername;
2476 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2479 /*******************************************************************
2480 * fill a notify_info_data with the servicename
2481 ********************************************************************/
2483 static void spoolss_notify_share_name(int snum,
2484 struct spoolss_Notify *data,
2485 print_queue_struct *queue,
2486 struct spoolss_PrinterInfo2 *pinfo2,
2487 TALLOC_CTX *mem_ctx)
2489 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2492 /*******************************************************************
2493 * fill a notify_info_data with the port name
2494 ********************************************************************/
2496 static void spoolss_notify_port_name(int snum,
2497 struct spoolss_Notify *data,
2498 print_queue_struct *queue,
2499 struct spoolss_PrinterInfo2 *pinfo2,
2500 TALLOC_CTX *mem_ctx)
2502 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2505 /*******************************************************************
2506 * fill a notify_info_data with the printername
2507 * but it doesn't exist, have to see what to do
2508 ********************************************************************/
2510 static void spoolss_notify_driver_name(int snum,
2511 struct spoolss_Notify *data,
2512 print_queue_struct *queue,
2513 struct spoolss_PrinterInfo2 *pinfo2,
2514 TALLOC_CTX *mem_ctx)
2516 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2519 /*******************************************************************
2520 * fill a notify_info_data with the comment
2521 ********************************************************************/
2523 static void spoolss_notify_comment(int snum,
2524 struct spoolss_Notify *data,
2525 print_queue_struct *queue,
2526 struct spoolss_PrinterInfo2 *pinfo2,
2527 TALLOC_CTX *mem_ctx)
2531 if (*pinfo2->comment == '\0') {
2532 p = lp_comment(snum);
2534 p = pinfo2->comment;
2537 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2540 /*******************************************************************
2541 * fill a notify_info_data with the comment
2542 * location = "Room 1, floor 2, building 3"
2543 ********************************************************************/
2545 static void spoolss_notify_location(int snum,
2546 struct spoolss_Notify *data,
2547 print_queue_struct *queue,
2548 struct spoolss_PrinterInfo2 *pinfo2,
2549 TALLOC_CTX *mem_ctx)
2551 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
2554 /*******************************************************************
2555 * fill a notify_info_data with the device mode
2556 * jfm:xxxx don't to it for know but that's a real problem !!!
2557 ********************************************************************/
2559 static void spoolss_notify_devmode(int snum,
2560 struct spoolss_Notify *data,
2561 print_queue_struct *queue,
2562 struct spoolss_PrinterInfo2 *pinfo2,
2563 TALLOC_CTX *mem_ctx)
2565 /* for a dummy implementation we have to zero the fields */
2566 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2569 /*******************************************************************
2570 * fill a notify_info_data with the separator file name
2571 ********************************************************************/
2573 static void spoolss_notify_sepfile(int snum,
2574 struct spoolss_Notify *data,
2575 print_queue_struct *queue,
2576 struct spoolss_PrinterInfo2 *pinfo2,
2577 TALLOC_CTX *mem_ctx)
2579 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2582 /*******************************************************************
2583 * fill a notify_info_data with the print processor
2584 * jfm:xxxx return always winprint to indicate we don't do anything to it
2585 ********************************************************************/
2587 static void spoolss_notify_print_processor(int snum,
2588 struct spoolss_Notify *data,
2589 print_queue_struct *queue,
2590 struct spoolss_PrinterInfo2 *pinfo2,
2591 TALLOC_CTX *mem_ctx)
2593 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2596 /*******************************************************************
2597 * fill a notify_info_data with the print processor options
2598 * jfm:xxxx send an empty string
2599 ********************************************************************/
2601 static void spoolss_notify_parameters(int snum,
2602 struct spoolss_Notify *data,
2603 print_queue_struct *queue,
2604 struct spoolss_PrinterInfo2 *pinfo2,
2605 TALLOC_CTX *mem_ctx)
2607 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2610 /*******************************************************************
2611 * fill a notify_info_data with the data type
2612 * jfm:xxxx always send RAW as data type
2613 ********************************************************************/
2615 static void spoolss_notify_datatype(int snum,
2616 struct spoolss_Notify *data,
2617 print_queue_struct *queue,
2618 struct spoolss_PrinterInfo2 *pinfo2,
2619 TALLOC_CTX *mem_ctx)
2621 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2624 /*******************************************************************
2625 * fill a notify_info_data with the security descriptor
2626 * jfm:xxxx send an null pointer to say no security desc
2627 * have to implement security before !
2628 ********************************************************************/
2630 static void spoolss_notify_security_desc(int snum,
2631 struct spoolss_Notify *data,
2632 print_queue_struct *queue,
2633 struct spoolss_PrinterInfo2 *pinfo2,
2634 TALLOC_CTX *mem_ctx)
2636 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2639 /*******************************************************************
2640 * fill a notify_info_data with the attributes
2641 * jfm:xxxx a samba printer is always shared
2642 ********************************************************************/
2644 static void spoolss_notify_attributes(int snum,
2645 struct spoolss_Notify *data,
2646 print_queue_struct *queue,
2647 struct spoolss_PrinterInfo2 *pinfo2,
2648 TALLOC_CTX *mem_ctx)
2650 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2653 /*******************************************************************
2654 * fill a notify_info_data with the priority
2655 ********************************************************************/
2657 static void spoolss_notify_priority(int snum,
2658 struct spoolss_Notify *data,
2659 print_queue_struct *queue,
2660 struct spoolss_PrinterInfo2 *pinfo2,
2661 TALLOC_CTX *mem_ctx)
2663 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2666 /*******************************************************************
2667 * fill a notify_info_data with the default priority
2668 ********************************************************************/
2670 static void spoolss_notify_default_priority(int snum,
2671 struct spoolss_Notify *data,
2672 print_queue_struct *queue,
2673 struct spoolss_PrinterInfo2 *pinfo2,
2674 TALLOC_CTX *mem_ctx)
2676 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
2679 /*******************************************************************
2680 * fill a notify_info_data with the start time
2681 ********************************************************************/
2683 static void spoolss_notify_start_time(int snum,
2684 struct spoolss_Notify *data,
2685 print_queue_struct *queue,
2686 struct spoolss_PrinterInfo2 *pinfo2,
2687 TALLOC_CTX *mem_ctx)
2689 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
2692 /*******************************************************************
2693 * fill a notify_info_data with the until time
2694 ********************************************************************/
2696 static void spoolss_notify_until_time(int snum,
2697 struct spoolss_Notify *data,
2698 print_queue_struct *queue,
2699 struct spoolss_PrinterInfo2 *pinfo2,
2700 TALLOC_CTX *mem_ctx)
2702 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
2705 /*******************************************************************
2706 * fill a notify_info_data with the status
2707 ********************************************************************/
2709 static void spoolss_notify_status(int snum,
2710 struct spoolss_Notify *data,
2711 print_queue_struct *queue,
2712 struct spoolss_PrinterInfo2 *pinfo2,
2713 TALLOC_CTX *mem_ctx)
2715 print_status_struct status;
2717 print_queue_length(snum, &status);
2718 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
2721 /*******************************************************************
2722 * fill a notify_info_data with the number of jobs queued
2723 ********************************************************************/
2725 static void spoolss_notify_cjobs(int snum,
2726 struct spoolss_Notify *data,
2727 print_queue_struct *queue,
2728 struct spoolss_PrinterInfo2 *pinfo2,
2729 TALLOC_CTX *mem_ctx)
2731 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
2734 /*******************************************************************
2735 * fill a notify_info_data with the average ppm
2736 ********************************************************************/
2738 static void spoolss_notify_average_ppm(int snum,
2739 struct spoolss_Notify *data,
2740 print_queue_struct *queue,
2741 struct spoolss_PrinterInfo2 *pinfo2,
2742 TALLOC_CTX *mem_ctx)
2744 /* always respond 8 pages per minutes */
2745 /* a little hard ! */
2746 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
2749 /*******************************************************************
2750 * fill a notify_info_data with username
2751 ********************************************************************/
2753 static void spoolss_notify_username(int snum,
2754 struct spoolss_Notify *data,
2755 print_queue_struct *queue,
2756 struct spoolss_PrinterInfo2 *pinfo2,
2757 TALLOC_CTX *mem_ctx)
2759 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
2762 /*******************************************************************
2763 * fill a notify_info_data with job status
2764 ********************************************************************/
2766 static void spoolss_notify_job_status(int snum,
2767 struct spoolss_Notify *data,
2768 print_queue_struct *queue,
2769 struct spoolss_PrinterInfo2 *pinfo2,
2770 TALLOC_CTX *mem_ctx)
2772 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
2775 /*******************************************************************
2776 * fill a notify_info_data with job name
2777 ********************************************************************/
2779 static void spoolss_notify_job_name(int snum,
2780 struct spoolss_Notify *data,
2781 print_queue_struct *queue,
2782 struct spoolss_PrinterInfo2 *pinfo2,
2783 TALLOC_CTX *mem_ctx)
2785 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
2788 /*******************************************************************
2789 * fill a notify_info_data with job status
2790 ********************************************************************/
2792 static void spoolss_notify_job_status_string(int snum,
2793 struct spoolss_Notify *data,
2794 print_queue_struct *queue,
2795 struct spoolss_PrinterInfo2 *pinfo2,
2796 TALLOC_CTX *mem_ctx)
2799 * Now we're returning job status codes we just return a "" here. JRA.
2804 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
2807 switch (queue->status) {
2812 p = ""; /* NT provides the paused string */
2821 #endif /* NO LONGER NEEDED. */
2823 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2826 /*******************************************************************
2827 * fill a notify_info_data with job time
2828 ********************************************************************/
2830 static void spoolss_notify_job_time(int snum,
2831 struct spoolss_Notify *data,
2832 print_queue_struct *queue,
2833 struct spoolss_PrinterInfo2 *pinfo2,
2834 TALLOC_CTX *mem_ctx)
2836 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2839 /*******************************************************************
2840 * fill a notify_info_data with job size
2841 ********************************************************************/
2843 static void spoolss_notify_job_size(int snum,
2844 struct spoolss_Notify *data,
2845 print_queue_struct *queue,
2846 struct spoolss_PrinterInfo2 *pinfo2,
2847 TALLOC_CTX *mem_ctx)
2849 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
2852 /*******************************************************************
2853 * fill a notify_info_data with page info
2854 ********************************************************************/
2855 static void spoolss_notify_total_pages(int snum,
2856 struct spoolss_Notify *data,
2857 print_queue_struct *queue,
2858 struct spoolss_PrinterInfo2 *pinfo2,
2859 TALLOC_CTX *mem_ctx)
2861 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
2864 /*******************************************************************
2865 * fill a notify_info_data with pages printed info.
2866 ********************************************************************/
2867 static void spoolss_notify_pages_printed(int snum,
2868 struct spoolss_Notify *data,
2869 print_queue_struct *queue,
2870 struct spoolss_PrinterInfo2 *pinfo2,
2871 TALLOC_CTX *mem_ctx)
2873 /* Add code when back-end tracks this */
2874 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2877 /*******************************************************************
2878 Fill a notify_info_data with job position.
2879 ********************************************************************/
2881 static void spoolss_notify_job_position(int snum,
2882 struct spoolss_Notify *data,
2883 print_queue_struct *queue,
2884 struct spoolss_PrinterInfo2 *pinfo2,
2885 TALLOC_CTX *mem_ctx)
2887 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
2890 /*******************************************************************
2891 Fill a notify_info_data with submitted time.
2892 ********************************************************************/
2894 static void spoolss_notify_submitted_time(int snum,
2895 struct spoolss_Notify *data,
2896 print_queue_struct *queue,
2897 struct spoolss_PrinterInfo2 *pinfo2,
2898 TALLOC_CTX *mem_ctx)
2900 data->data.string.string = NULL;
2901 data->data.string.size = 0;
2903 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
2904 &data->data.string.string,
2905 &data->data.string.size);
2909 struct s_notify_info_data_table
2911 enum spoolss_NotifyType type;
2914 enum spoolss_NotifyTable variable_type;
2915 void (*fn) (int snum, struct spoolss_Notify *data,
2916 print_queue_struct *queue,
2917 struct spoolss_PrinterInfo2 *pinfo2,
2918 TALLOC_CTX *mem_ctx);
2921 /* A table describing the various print notification constants and
2922 whether the notification data is a pointer to a variable sized
2923 buffer, a one value uint32_t or a two value uint32_t. */
2925 static const struct s_notify_info_data_table notify_info_data_table[] =
2927 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2928 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2929 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
2930 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2931 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2932 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
2933 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
2934 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2935 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
2936 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2937 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2938 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2939 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
2940 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
2941 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2942 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
2943 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2944 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2945 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
2946 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
2947 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
2948 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
2949 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
2950 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2951 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
2952 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2953 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2954 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2955 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2956 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2957 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2958 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2959 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2960 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2961 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2962 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2963 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
2964 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
2965 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
2966 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
2967 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2968 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
2969 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
2970 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2971 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2972 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
2973 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
2974 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
2975 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
2978 /*******************************************************************
2979 Return the variable_type of info_data structure.
2980 ********************************************************************/
2982 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
2987 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
2988 if ( (notify_info_data_table[i].type == type) &&
2989 (notify_info_data_table[i].field == field) ) {
2990 return notify_info_data_table[i].variable_type;
2994 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
2999 /****************************************************************************
3000 ****************************************************************************/
3002 static bool search_notify(enum spoolss_NotifyType type,
3008 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3009 if (notify_info_data_table[i].type == type &&
3010 notify_info_data_table[i].field == field &&
3011 notify_info_data_table[i].fn != NULL) {
3020 /****************************************************************************
3021 ****************************************************************************/
3023 static void construct_info_data(struct spoolss_Notify *info_data,
3024 enum spoolss_NotifyType type,
3025 uint16_t field, int id)
3027 info_data->type = type;
3028 info_data->field.field = field;
3029 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3030 info_data->job_id = id;
3033 /*******************************************************************
3035 * fill a notify_info struct with info asked
3037 ********************************************************************/
3039 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3040 struct spoolss_NotifyInfo *info,
3041 struct spoolss_PrinterInfo2 *pinfo2,
3043 const struct spoolss_NotifyOptionType *option_type,
3045 TALLOC_CTX *mem_ctx)
3048 enum spoolss_NotifyType type;
3051 struct spoolss_Notify *current_data;
3052 print_queue_struct *queue=NULL;
3054 type = option_type->type;
3056 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3057 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3058 option_type->count, lp_servicename(snum)));
3060 for(field_num=0; field_num < option_type->count; field_num++) {
3061 field = option_type->fields[field_num].field;
3063 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3065 if (!search_notify(type, field, &j) )
3068 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3069 struct spoolss_Notify,
3071 if (info->notifies == NULL) {
3072 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3076 current_data = &info->notifies[info->count];
3078 construct_info_data(current_data, type, field, id);
3080 DEBUG(10, ("construct_notify_printer_info: "
3081 "calling [%s] snum=%d printername=[%s])\n",
3082 notify_info_data_table[j].name, snum,
3083 pinfo2->printername));
3085 notify_info_data_table[j].fn(snum, current_data, queue,
3094 /*******************************************************************
3096 * fill a notify_info struct with info asked
3098 ********************************************************************/
3100 static bool construct_notify_jobs_info(print_queue_struct *queue,
3101 struct spoolss_NotifyInfo *info,
3102 struct spoolss_PrinterInfo2 *pinfo2,
3104 const struct spoolss_NotifyOptionType *option_type,
3106 TALLOC_CTX *mem_ctx)
3109 enum spoolss_NotifyType type;
3111 struct spoolss_Notify *current_data;
3113 DEBUG(4,("construct_notify_jobs_info\n"));
3115 type = option_type->type;
3117 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3118 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3119 option_type->count));
3121 for(field_num=0; field_num<option_type->count; field_num++) {
3122 field = option_type->fields[field_num].field;
3124 if (!search_notify(type, field, &j) )
3127 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3128 struct spoolss_Notify,
3130 if (info->notifies == NULL) {
3131 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3135 current_data=&(info->notifies[info->count]);
3137 construct_info_data(current_data, type, field, id);
3138 notify_info_data_table[j].fn(snum, current_data, queue,
3147 * JFM: The enumeration is not that simple, it's even non obvious.
3149 * let's take an example: I want to monitor the PRINTER SERVER for
3150 * the printer's name and the number of jobs currently queued.
3151 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3152 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3154 * I have 3 printers on the back of my server.
3156 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3159 * 1 printer 1 name 1
3160 * 2 printer 1 cjob 1
3161 * 3 printer 2 name 2
3162 * 4 printer 2 cjob 2
3163 * 5 printer 3 name 3
3164 * 6 printer 3 name 3
3166 * that's the print server case, the printer case is even worse.
3169 /*******************************************************************
3171 * enumerate all printers on the printserver
3172 * fill a notify_info struct with info asked
3174 ********************************************************************/
3176 static WERROR printserver_notify_info(pipes_struct *p,
3177 struct policy_handle *hnd,
3178 struct spoolss_NotifyInfo *info,
3179 TALLOC_CTX *mem_ctx)
3182 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3183 int n_services=lp_numservices();
3185 struct spoolss_NotifyOption *option;
3186 struct spoolss_NotifyOptionType option_type;
3187 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3190 DEBUG(4,("printserver_notify_info\n"));
3195 option = Printer->notify.option;
3198 info->notifies = NULL;
3201 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3202 sending a ffpcn() request first */
3207 for (i=0; i<option->count; i++) {
3208 option_type = option->types[i];
3210 if (option_type.type != PRINTER_NOTIFY_TYPE)
3213 for (snum = 0; snum < n_services; snum++) {
3214 if (!lp_browseable(snum) ||
3215 !lp_snum_ok(snum) ||
3216 !lp_print_ok(snum)) {
3217 continue; /* skip */
3220 /* Maybe we should use the SYSTEM server_info here... */
3221 result = winreg_get_printer(mem_ctx, p->server_info,
3222 Printer->servername,
3223 lp_servicename(snum),
3225 if (!W_ERROR_IS_OK(result)) {
3226 DEBUG(4, ("printserver_notify_info: "
3227 "Failed to get printer [%s]\n",
3228 lp_servicename(snum)));
3233 construct_notify_printer_info(Printer, info,
3238 TALLOC_FREE(pinfo2);
3244 * Debugging information, don't delete.
3247 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3248 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3249 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3251 for (i=0; i<info->count; i++) {
3252 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3253 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3254 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3261 /*******************************************************************
3263 * fill a notify_info struct with info asked
3265 ********************************************************************/
3267 static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
3268 struct spoolss_NotifyInfo *info,
3269 TALLOC_CTX *mem_ctx)
3272 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3275 struct spoolss_NotifyOption *option;
3276 struct spoolss_NotifyOptionType option_type;
3278 print_queue_struct *queue=NULL;
3279 print_status_struct status;
3280 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3283 DEBUG(4,("printer_notify_info\n"));
3288 option = Printer->notify.option;
3292 info->notifies = NULL;
3295 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3296 sending a ffpcn() request first */
3301 get_printer_snum(p, hnd, &snum, NULL);
3303 /* Maybe we should use the SYSTEM server_info here... */
3304 result = winreg_get_printer(mem_ctx, p->server_info,
3305 Printer->servername,
3306 lp_servicename(snum), &pinfo2);
3307 if (!W_ERROR_IS_OK(result)) {
3311 for (i=0; i<option->count; i++) {
3312 option_type = option->types[i];
3314 switch (option_type.type) {
3315 case PRINTER_NOTIFY_TYPE:
3316 if (construct_notify_printer_info(Printer, info,
3324 case JOB_NOTIFY_TYPE:
3326 count = print_queue_status(snum, &queue, &status);
3328 for (j=0; j<count; j++) {
3329 construct_notify_jobs_info(&queue[j], info,
3342 * Debugging information, don't delete.
3345 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3346 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3347 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3349 for (i=0; i<info->count; i++) {
3350 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3351 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3352 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3356 talloc_free(pinfo2);
3360 /****************************************************************
3361 _spoolss_RouterRefreshPrinterChangeNotify
3362 ****************************************************************/
3364 WERROR _spoolss_RouterRefreshPrinterChangeNotify(pipes_struct *p,
3365 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3367 struct spoolss_NotifyInfo *info;
3369 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
3370 WERROR result = WERR_BADFID;
3372 /* we always have a spoolss_NotifyInfo struct */
3373 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3375 result = WERR_NOMEM;
3379 *r->out.info = info;
3382 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3383 "Invalid handle (%s:%u:%u).\n",
3384 OUR_HANDLE(r->in.handle)));
3388 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3391 * We are now using the change value, and
3392 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3393 * I don't have a global notification system, I'm sending back all the
3394 * informations even when _NOTHING_ has changed.
3397 /* We need to keep track of the change value to send back in
3398 RRPCN replies otherwise our updates are ignored. */
3400 Printer->notify.fnpcn = true;
3402 if (Printer->notify.client_connected) {
3403 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3404 "Saving change value in request [%x]\n",
3406 Printer->notify.change = r->in.change_low;
3409 /* just ignore the spoolss_NotifyOption */
3411 switch (Printer->printer_type) {
3413 result = printserver_notify_info(p, r->in.handle,
3417 case SPLHND_PRINTER:
3418 result = printer_notify_info(p, r->in.handle,
3423 Printer->notify.fnpcn = false;
3429 /********************************************************************
3430 * construct_printer_info_0
3431 * fill a printer_info_0 struct
3432 ********************************************************************/
3434 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3435 struct auth_serversupplied_info *server_info,
3436 struct spoolss_PrinterInfo2 *info2,
3437 struct spoolss_PrinterInfo0 *r,
3441 counter_printer_0 *session_counter;
3442 struct timeval setuptime;
3443 print_status_struct status;
3445 r->printername = talloc_strdup(mem_ctx, info2->printername);
3446 W_ERROR_HAVE_NO_MEMORY(r->printername);
3448 r->servername = talloc_strdup(mem_ctx, info2->servername);
3449 W_ERROR_HAVE_NO_MEMORY(r->servername);
3451 count = print_queue_length(snum, &status);
3453 /* check if we already have a counter for this printer */
3454 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3455 if (session_counter->snum == snum)
3459 /* it's the first time, add it to the list */
3460 if (session_counter == NULL) {
3461 session_counter = SMB_MALLOC_P(counter_printer_0);
3462 W_ERROR_HAVE_NO_MEMORY(session_counter);
3463 ZERO_STRUCTP(session_counter);
3464 session_counter->snum = snum;
3465 session_counter->counter = 0;
3466 DLIST_ADD(counter_list, session_counter);
3470 session_counter->counter++;
3476 get_startup_time(&setuptime);
3477 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3480 * the global_counter should be stored in a TDB as it's common to all the clients
3481 * and should be zeroed on samba startup
3483 r->global_counter = session_counter->counter;
3485 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3486 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3487 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3488 r->free_build = SPOOLSS_RELEASE_BUILD;
3490 r->max_spooling = 0;
3491 r->session_counter = session_counter->counter;
3492 r->num_error_out_of_paper = 0x0;
3493 r->num_error_not_ready = 0x0; /* number of print failure */
3495 r->number_of_processors = 0x1;
3496 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3497 r->high_part_total_bytes = 0x0;
3498 winreg_printer_get_changeid(mem_ctx, server_info, info2->sharename, &r->change_id); /* ChangeID in milliseconds*/
3499 r->last_error = WERR_OK;
3500 r->status = nt_printq_status(status.status);
3501 r->enumerate_network_printers = 0x0;
3502 r->c_setprinter = 0x0;
3503 r->processor_architecture = 0x0;
3504 r->processor_level = 0x6; /* 6 ???*/
3513 /********************************************************************
3514 * construct_printer_info1
3515 * fill a spoolss_PrinterInfo1 struct
3516 ********************************************************************/
3518 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3519 const struct spoolss_PrinterInfo2 *info2,
3521 struct spoolss_PrinterInfo1 *r,
3526 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3530 W_ERROR_HAVE_NO_MEMORY(r->description);
3532 if (info2->comment == NULL || info2->comment[0] == '\0') {
3533 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3535 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3537 W_ERROR_HAVE_NO_MEMORY(r->comment);
3539 r->name = talloc_strdup(mem_ctx, info2->printername);
3540 W_ERROR_HAVE_NO_MEMORY(r->name);
3545 /********************************************************************
3546 * construct_printer_info2
3547 * fill a spoolss_PrinterInfo2 struct
3548 ********************************************************************/
3550 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3551 const struct spoolss_PrinterInfo2 *info2,
3552 struct spoolss_PrinterInfo2 *r,
3556 print_status_struct status;
3558 count = print_queue_length(snum, &status);
3560 r->servername = talloc_strdup(mem_ctx, info2->servername);
3561 W_ERROR_HAVE_NO_MEMORY(r->servername);
3562 r->printername = talloc_strdup(mem_ctx, info2->printername);
3563 W_ERROR_HAVE_NO_MEMORY(r->printername);
3564 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3565 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3566 r->portname = talloc_strdup(mem_ctx, info2->portname);
3567 W_ERROR_HAVE_NO_MEMORY(r->portname);
3568 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
3569 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3571 if (info2->comment[0] == '\0') {
3572 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3574 r->comment = talloc_strdup(mem_ctx, info2->comment);
3576 W_ERROR_HAVE_NO_MEMORY(r->comment);
3578 r->location = talloc_strdup(mem_ctx, info2->location);
3579 W_ERROR_HAVE_NO_MEMORY(r->location);
3580 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
3581 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3582 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
3583 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3584 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
3585 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3586 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
3587 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3589 r->attributes = info2->attributes;
3591 r->priority = info2->priority;
3592 r->defaultpriority = info2->defaultpriority;
3593 r->starttime = info2->starttime;
3594 r->untiltime = info2->untiltime;
3595 r->status = nt_printq_status(status.status);
3597 r->averageppm = info2->averageppm;
3599 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3601 DEBUG(8,("Returning NULL Devicemode!\n"));
3606 if (info2->secdesc != NULL) {
3607 /* don't use talloc_steal() here unless you do a deep steal of all
3608 the SEC_DESC members */
3610 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3616 /********************************************************************
3617 * construct_printer_info3
3618 * fill a spoolss_PrinterInfo3 struct
3619 ********************************************************************/
3621 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3622 const struct spoolss_PrinterInfo2 *info2,
3623 struct spoolss_PrinterInfo3 *r,
3626 /* These are the components of the SD we are returning. */
3628 if (info2->secdesc != NULL) {
3629 /* don't use talloc_steal() here unless you do a deep steal of all
3630 the SEC_DESC members */
3632 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3633 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3639 /********************************************************************
3640 * construct_printer_info4
3641 * fill a spoolss_PrinterInfo4 struct
3642 ********************************************************************/
3644 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
3645 const struct spoolss_PrinterInfo2 *info2,
3646 struct spoolss_PrinterInfo4 *r,
3649 r->printername = talloc_strdup(mem_ctx, info2->printername);
3650 W_ERROR_HAVE_NO_MEMORY(r->printername);
3651 r->servername = talloc_strdup(mem_ctx, info2->servername);
3652 W_ERROR_HAVE_NO_MEMORY(r->servername);
3654 r->attributes = info2->attributes;
3659 /********************************************************************
3660 * construct_printer_info5
3661 * fill a spoolss_PrinterInfo5 struct
3662 ********************************************************************/
3664 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
3665 const struct spoolss_PrinterInfo2 *info2,
3666 struct spoolss_PrinterInfo5 *r,
3669 r->printername = talloc_strdup(mem_ctx, info2->printername);
3670 W_ERROR_HAVE_NO_MEMORY(r->printername);
3671 r->portname = talloc_strdup(mem_ctx, info2->portname);
3672 W_ERROR_HAVE_NO_MEMORY(r->portname);
3674 r->attributes = info2->attributes;
3676 /* these two are not used by NT+ according to MSDN */
3677 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
3678 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
3683 /********************************************************************
3684 * construct_printer_info_6
3685 * fill a spoolss_PrinterInfo6 struct
3686 ********************************************************************/
3688 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
3689 const struct spoolss_PrinterInfo2 *info2,
3690 struct spoolss_PrinterInfo6 *r,
3694 print_status_struct status;
3696 count = print_queue_length(snum, &status);
3698 r->status = nt_printq_status(status.status);
3703 /********************************************************************
3704 * construct_printer_info7
3705 * fill a spoolss_PrinterInfo7 struct
3706 ********************************************************************/
3708 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
3709 Printer_entry *print_hnd,
3710 struct spoolss_PrinterInfo7 *r,
3713 struct auth_serversupplied_info *server_info;
3717 status = make_server_info_system(mem_ctx, &server_info);
3718 if (!NT_STATUS_IS_OK(status)) {
3719 DEBUG(0, ("construct_printer_info7: "
3720 "Could not create system server_info\n"));
3724 if (is_printer_published(mem_ctx, server_info, print_hnd->servername,
3725 lp_servicename(snum), &guid, NULL)) {
3726 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
3727 r->action = DSPRINT_PUBLISH;
3729 r->guid = talloc_strdup(mem_ctx, "");
3730 r->action = DSPRINT_UNPUBLISH;
3732 W_ERROR_HAVE_NO_MEMORY(r->guid);
3734 TALLOC_FREE(server_info);
3738 /********************************************************************
3739 * construct_printer_info8
3740 * fill a spoolss_PrinterInfo8 struct
3741 ********************************************************************/
3743 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
3744 const struct spoolss_PrinterInfo2 *info2,
3745 struct spoolss_DeviceModeInfo *r,
3748 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3750 DEBUG(8,("Returning NULL Devicemode!\n"));
3757 /********************************************************************
3758 ********************************************************************/
3760 static bool snum_is_shared_printer(int snum)
3762 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
3765 /********************************************************************
3766 Spoolss_enumprinters.
3767 ********************************************************************/
3769 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
3770 struct auth_serversupplied_info *server_info,
3773 union spoolss_PrinterInfo **info_p,
3777 int n_services = lp_numservices();
3778 union spoolss_PrinterInfo *info = NULL;
3780 WERROR result = WERR_OK;
3785 for (snum = 0; snum < n_services; snum++) {
3787 const char *printer;
3788 struct spoolss_PrinterInfo2 *info2;
3790 if (!snum_is_shared_printer(snum)) {
3794 printer = lp_const_servicename(snum);
3796 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
3799 result = winreg_create_printer(mem_ctx,
3803 if (!W_ERROR_IS_OK(result)) {
3807 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
3808 union spoolss_PrinterInfo,
3811 result = WERR_NOMEM;
3815 result = winreg_get_printer(mem_ctx, server_info,
3816 NULL, printer, &info2);
3817 if (!W_ERROR_IS_OK(result)) {
3823 result = construct_printer_info0(info, server_info, info2,
3824 &info[count].info0, snum);
3827 result = construct_printer_info1(info, info2, flags,
3828 &info[count].info1, snum);
3831 result = construct_printer_info2(info, info2,
3832 &info[count].info2, snum);
3835 result = construct_printer_info4(info, info2,
3836 &info[count].info4, snum);
3839 result = construct_printer_info5(info, info2,
3840 &info[count].info5, snum);
3844 result = WERR_UNKNOWN_LEVEL;
3848 if (!W_ERROR_IS_OK(result)) {
3859 if (!W_ERROR_IS_OK(result)) {
3869 /********************************************************************
3870 * handle enumeration of printers at level 0
3871 ********************************************************************/
3873 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
3874 struct auth_serversupplied_info *server_info,
3876 const char *servername,
3877 union spoolss_PrinterInfo **info,
3880 DEBUG(4,("enum_all_printers_info_0\n"));
3882 return enum_all_printers_info_level(mem_ctx, server_info, 0, flags, info, count);
3886 /********************************************************************
3887 ********************************************************************/
3889 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
3890 struct auth_serversupplied_info *server_info,
3892 union spoolss_PrinterInfo **info,
3895 DEBUG(4,("enum_all_printers_info_1\n"));
3897 return enum_all_printers_info_level(mem_ctx, server_info, 1, flags, info, count);
3900 /********************************************************************
3901 enum_all_printers_info_1_local.
3902 *********************************************************************/
3904 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
3905 struct auth_serversupplied_info *server_info,
3906 union spoolss_PrinterInfo **info,
3909 DEBUG(4,("enum_all_printers_info_1_local\n"));
3911 return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_ICON8, info, count);
3914 /********************************************************************
3915 enum_all_printers_info_1_name.
3916 *********************************************************************/
3918 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
3919 struct auth_serversupplied_info *server_info,
3921 union spoolss_PrinterInfo **info,
3924 const char *s = name;
3926 DEBUG(4,("enum_all_printers_info_1_name\n"));
3928 if ((name[0] == '\\') && (name[1] == '\\')) {
3932 if (!is_myname_or_ipaddr(s)) {
3933 return WERR_INVALID_NAME;
3936 return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_ICON8, info, count);
3939 /********************************************************************
3940 enum_all_printers_info_1_network.
3941 *********************************************************************/
3943 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
3944 struct auth_serversupplied_info *server_info,
3946 union spoolss_PrinterInfo **info,
3949 const char *s = name;
3951 DEBUG(4,("enum_all_printers_info_1_network\n"));
3953 /* If we respond to a enum_printers level 1 on our name with flags
3954 set to PRINTER_ENUM_REMOTE with a list of printers then these
3955 printers incorrectly appear in the APW browse list.
3956 Specifically the printers for the server appear at the workgroup
3957 level where all the other servers in the domain are
3958 listed. Windows responds to this call with a
3959 WERR_CAN_NOT_COMPLETE so we should do the same. */
3961 if (name[0] == '\\' && name[1] == '\\') {
3965 if (is_myname_or_ipaddr(s)) {
3966 return WERR_CAN_NOT_COMPLETE;
3969 return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_NAME, info, count);
3972 /********************************************************************
3973 * api_spoolss_enumprinters
3975 * called from api_spoolss_enumprinters (see this to understand)
3976 ********************************************************************/
3978 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
3979 struct auth_serversupplied_info *server_info,
3980 union spoolss_PrinterInfo **info,
3983 DEBUG(4,("enum_all_printers_info_2\n"));
3985 return enum_all_printers_info_level(mem_ctx, server_info, 2, 0, info, count);
3988 /********************************************************************
3989 * handle enumeration of printers at level 1
3990 ********************************************************************/
3992 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
3993 struct auth_serversupplied_info *server_info,
3996 union spoolss_PrinterInfo **info,
3999 /* Not all the flags are equals */
4001 if (flags & PRINTER_ENUM_LOCAL) {
4002 return enum_all_printers_info_1_local(mem_ctx, server_info, info, count);
4005 if (flags & PRINTER_ENUM_NAME) {
4006 return enum_all_printers_info_1_name(mem_ctx, server_info, name, info, count);
4009 if (flags & PRINTER_ENUM_NETWORK) {
4010 return enum_all_printers_info_1_network(mem_ctx, server_info, name, info, count);
4013 return WERR_OK; /* NT4sp5 does that */
4016 /********************************************************************
4017 * handle enumeration of printers at level 2
4018 ********************************************************************/
4020 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4021 struct auth_serversupplied_info *server_info,
4023 const char *servername,
4024 union spoolss_PrinterInfo **info,
4027 if (flags & PRINTER_ENUM_LOCAL) {
4028 return enum_all_printers_info_2(mem_ctx, server_info, info, count);
4031 if (flags & PRINTER_ENUM_NAME) {
4032 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4033 return WERR_INVALID_NAME;
4036 return enum_all_printers_info_2(mem_ctx, server_info, info, count);
4039 if (flags & PRINTER_ENUM_REMOTE) {
4040 return WERR_UNKNOWN_LEVEL;
4046 /********************************************************************
4047 * handle enumeration of printers at level 4
4048 ********************************************************************/
4050 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4051 struct auth_serversupplied_info *server_info,
4053 const char *servername,
4054 union spoolss_PrinterInfo **info,
4057 DEBUG(4,("enum_all_printers_info_4\n"));
4059 return enum_all_printers_info_level(mem_ctx, server_info, 4, flags, info, count);
4063 /********************************************************************
4064 * handle enumeration of printers at level 5
4065 ********************************************************************/
4067 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4068 struct auth_serversupplied_info *server_info,
4070 const char *servername,
4071 union spoolss_PrinterInfo **info,
4074 DEBUG(4,("enum_all_printers_info_5\n"));
4076 return enum_all_printers_info_level(mem_ctx, server_info, 5, flags, info, count);
4079 /****************************************************************
4080 _spoolss_EnumPrinters
4081 ****************************************************************/
4083 WERROR _spoolss_EnumPrinters(pipes_struct *p,
4084 struct spoolss_EnumPrinters *r)
4086 const char *name = NULL;
4089 /* that's an [in out] buffer */
4091 if (!r->in.buffer && (r->in.offered != 0)) {
4092 return WERR_INVALID_PARAM;
4095 DEBUG(4,("_spoolss_EnumPrinters\n"));
4099 *r->out.info = NULL;
4103 * flags==PRINTER_ENUM_NAME
4104 * if name=="" then enumerates all printers
4105 * if name!="" then enumerate the printer
4106 * flags==PRINTER_ENUM_REMOTE
4107 * name is NULL, enumerate printers
4108 * Level 2: name!="" enumerates printers, name can't be NULL
4109 * Level 3: doesn't exist
4110 * Level 4: does a local registry lookup
4111 * Level 5: same as Level 2
4115 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4116 W_ERROR_HAVE_NO_MEMORY(name);
4119 switch (r->in.level) {
4121 result = enumprinters_level0(p->mem_ctx, p->server_info,
4123 r->out.info, r->out.count);
4126 result = enumprinters_level1(p->mem_ctx, p->server_info,
4128 r->out.info, r->out.count);
4131 result = enumprinters_level2(p->mem_ctx, p->server_info,
4133 r->out.info, r->out.count);
4136 result = enumprinters_level4(p->mem_ctx, p->server_info,
4138 r->out.info, r->out.count);
4141 result = enumprinters_level5(p->mem_ctx, p->server_info,
4143 r->out.info, r->out.count);
4146 return WERR_UNKNOWN_LEVEL;
4149 if (!W_ERROR_IS_OK(result)) {
4153 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4154 spoolss_EnumPrinters,
4155 *r->out.info, r->in.level,
4157 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4158 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4160 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4163 /****************************************************************
4165 ****************************************************************/
4167 WERROR _spoolss_GetPrinter(pipes_struct *p,
4168 struct spoolss_GetPrinter *r)
4170 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4171 struct spoolss_PrinterInfo2 *info2 = NULL;
4172 WERROR result = WERR_OK;
4173 const char *servername = NULL;
4176 /* that's an [in out] buffer */
4178 if (!r->in.buffer && (r->in.offered != 0)) {
4179 return WERR_INVALID_PARAM;
4184 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4188 if (Printer != NULL || Printer->servername != NULL) {
4189 servername = Printer->servername;
4192 result = winreg_get_printer(p->mem_ctx,
4195 lp_const_servicename(snum),
4197 if (!W_ERROR_IS_OK(result)) {
4201 switch (r->in.level) {
4203 result = construct_printer_info0(p->mem_ctx, p->server_info,
4205 &r->out.info->info0, snum);
4208 result = construct_printer_info1(p->mem_ctx, info2,
4210 &r->out.info->info1, snum);
4213 result = construct_printer_info2(p->mem_ctx, info2,
4214 &r->out.info->info2, snum);
4217 result = construct_printer_info3(p->mem_ctx, info2,
4218 &r->out.info->info3, snum);
4221 result = construct_printer_info4(p->mem_ctx, info2,
4222 &r->out.info->info4, snum);
4225 result = construct_printer_info5(p->mem_ctx, info2,
4226 &r->out.info->info5, snum);
4229 result = construct_printer_info6(p->mem_ctx, info2,
4230 &r->out.info->info6, snum);
4233 result = construct_printer_info7(p->mem_ctx, Printer,
4234 &r->out.info->info7, snum);
4237 result = construct_printer_info8(p->mem_ctx, info2,
4238 &r->out.info->info8, snum);
4241 result = WERR_UNKNOWN_LEVEL;
4245 if (!W_ERROR_IS_OK(result)) {
4246 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4247 r->in.level, win_errstr(result)));
4248 TALLOC_FREE(r->out.info);
4252 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4253 r->out.info, r->in.level);
4254 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4256 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4259 /********************************************************************
4260 ********************************************************************/
4262 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4264 if (in && strlen(in)) { \
4265 out = talloc_strdup(mem_ctx, in); \
4266 W_ERROR_HAVE_NO_MEMORY(out); \
4272 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4274 if (in && strlen(in)) { \
4275 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4277 out = talloc_strdup(mem_ctx, ""); \
4279 W_ERROR_HAVE_NO_MEMORY(out); \
4282 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4283 const char **string_array,
4284 const char ***presult,
4285 const char *cservername,
4289 int i, num_strings = 0;
4290 const char **array = NULL;
4292 if (string_array == NULL) {
4293 return WERR_INVALID_PARAMETER;;
4296 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4297 const char *str = NULL;
4299 if (cservername == NULL || arch == NULL) {
4300 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4302 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4305 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4312 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4313 &array, &num_strings);
4323 /********************************************************************
4324 * fill a spoolss_DriverInfo1 struct
4325 ********************************************************************/
4327 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4328 struct spoolss_DriverInfo1 *r,
4329 const struct spoolss_DriverInfo8 *driver,
4330 const char *servername)
4332 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4333 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4338 /********************************************************************
4339 * fill a spoolss_DriverInfo2 struct
4340 ********************************************************************/
4342 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4343 struct spoolss_DriverInfo2 *r,
4344 const struct spoolss_DriverInfo8 *driver,
4345 const char *servername)
4348 const char *cservername = canon_servername(servername);
4350 r->version = driver->version;
4352 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4353 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4354 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4355 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4357 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4358 driver->architecture,
4360 driver->driver_path,
4363 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4364 driver->architecture,
4369 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4370 driver->architecture,
4372 driver->config_file,
4378 /********************************************************************
4379 * fill a spoolss_DriverInfo3 struct
4380 ********************************************************************/
4382 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4383 struct spoolss_DriverInfo3 *r,
4384 const struct spoolss_DriverInfo8 *driver,
4385 const char *servername)
4387 const char *cservername = canon_servername(servername);
4389 r->version = driver->version;
4391 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4392 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4393 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4394 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4396 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4397 driver->architecture,
4399 driver->driver_path,
4402 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4403 driver->architecture,
4408 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4409 driver->architecture,
4411 driver->config_file,
4414 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4415 driver->architecture,
4420 FILL_DRIVER_STRING(mem_ctx,
4421 driver->monitor_name,
4424 FILL_DRIVER_STRING(mem_ctx,
4425 driver->default_datatype,
4426 r->default_datatype);
4428 return string_array_from_driver_info(mem_ctx,
4429 driver->dependent_files,
4430 &r->dependent_files,
4432 driver->architecture,
4436 /********************************************************************
4437 * fill a spoolss_DriverInfo4 struct
4438 ********************************************************************/
4440 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4441 struct spoolss_DriverInfo4 *r,
4442 const struct spoolss_DriverInfo8 *driver,
4443 const char *servername)
4445 const char *cservername = canon_servername(servername);
4448 r->version = driver->version;
4450 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4451 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4452 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4453 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4455 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4456 driver->architecture,
4458 driver->driver_path,
4461 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4462 driver->architecture,
4467 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4468 driver->architecture,
4470 driver->config_file,
4473 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4474 driver->architecture,
4479 result = string_array_from_driver_info(mem_ctx,
4480 driver->dependent_files,
4481 &r->dependent_files,
4483 driver->architecture,
4485 if (!W_ERROR_IS_OK(result)) {
4489 FILL_DRIVER_STRING(mem_ctx,
4490 driver->monitor_name,
4493 FILL_DRIVER_STRING(mem_ctx,
4494 driver->default_datatype,
4495 r->default_datatype);
4498 result = string_array_from_driver_info(mem_ctx,
4499 driver->previous_names,
4506 /********************************************************************
4507 * fill a spoolss_DriverInfo5 struct
4508 ********************************************************************/
4510 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4511 struct spoolss_DriverInfo5 *r,
4512 const struct spoolss_DriverInfo8 *driver,
4513 const char *servername)
4515 const char *cservername = canon_servername(servername);
4517 r->version = driver->version;
4519 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4520 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4521 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4522 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4524 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4525 driver->architecture,
4527 driver->driver_path,
4530 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4531 driver->architecture,
4536 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4537 driver->architecture,
4539 driver->config_file,
4542 r->driver_attributes = 0;
4543 r->config_version = 0;
4544 r->driver_version = 0;
4548 /********************************************************************
4549 * fill a spoolss_DriverInfo6 struct
4550 ********************************************************************/
4552 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4553 struct spoolss_DriverInfo6 *r,
4554 const struct spoolss_DriverInfo8 *driver,
4555 const char *servername)
4557 const char *cservername = canon_servername(servername);
4560 r->version = driver->version;
4562 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4563 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4564 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4565 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4567 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4568 driver->architecture,
4570 driver->driver_path,
4573 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4574 driver->architecture,
4579 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4580 driver->architecture,
4582 driver->config_file,
4585 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4586 driver->architecture,
4591 FILL_DRIVER_STRING(mem_ctx,
4592 driver->monitor_name,
4595 FILL_DRIVER_STRING(mem_ctx,
4596 driver->default_datatype,
4597 r->default_datatype);
4599 result = string_array_from_driver_info(mem_ctx,
4600 driver->dependent_files,
4601 &r->dependent_files,
4603 driver->architecture,
4605 if (!W_ERROR_IS_OK(result)) {
4609 result = string_array_from_driver_info(mem_ctx,
4610 driver->previous_names,
4613 if (!W_ERROR_IS_OK(result)) {
4617 r->driver_date = driver->driver_date;
4618 r->driver_version = driver->driver_version;
4620 FILL_DRIVER_STRING(mem_ctx,
4621 driver->manufacturer_name,
4622 r->manufacturer_name);
4623 FILL_DRIVER_STRING(mem_ctx,
4624 driver->manufacturer_url,
4625 r->manufacturer_url);
4626 FILL_DRIVER_STRING(mem_ctx,
4627 driver->hardware_id,
4629 FILL_DRIVER_STRING(mem_ctx,
4636 /********************************************************************
4637 * fill a spoolss_DriverInfo8 struct
4638 ********************************************************************/
4640 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
4641 struct spoolss_DriverInfo8 *r,
4642 const struct spoolss_DriverInfo8 *driver,
4643 const char *servername)
4645 const char *cservername = canon_servername(servername);
4648 r->version = driver->version;
4650 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4651 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4652 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4653 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4655 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4656 driver->architecture,
4658 driver->driver_path,
4661 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4662 driver->architecture,
4667 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4668 driver->architecture,
4670 driver->config_file,
4673 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4674 driver->architecture,
4679 FILL_DRIVER_STRING(mem_ctx,
4680 driver->monitor_name,
4683 FILL_DRIVER_STRING(mem_ctx,
4684 driver->default_datatype,
4685 r->default_datatype);
4687 result = string_array_from_driver_info(mem_ctx,
4688 driver->dependent_files,
4689 &r->dependent_files,
4691 driver->architecture,
4693 if (!W_ERROR_IS_OK(result)) {
4697 result = string_array_from_driver_info(mem_ctx,
4698 driver->previous_names,
4701 if (!W_ERROR_IS_OK(result)) {
4705 r->driver_date = driver->driver_date;
4706 r->driver_version = driver->driver_version;
4708 FILL_DRIVER_STRING(mem_ctx,
4709 driver->manufacturer_name,
4710 r->manufacturer_name);
4711 FILL_DRIVER_STRING(mem_ctx,
4712 driver->manufacturer_url,
4713 r->manufacturer_url);
4714 FILL_DRIVER_STRING(mem_ctx,
4715 driver->hardware_id,
4717 FILL_DRIVER_STRING(mem_ctx,
4721 FILL_DRIVER_STRING(mem_ctx,
4722 driver->print_processor,
4723 r->print_processor);
4724 FILL_DRIVER_STRING(mem_ctx,
4725 driver->vendor_setup,
4728 result = string_array_from_driver_info(mem_ctx,
4729 driver->color_profiles,
4732 if (!W_ERROR_IS_OK(result)) {
4736 FILL_DRIVER_STRING(mem_ctx,
4740 r->printer_driver_attributes = driver->printer_driver_attributes;
4742 result = string_array_from_driver_info(mem_ctx,
4743 driver->core_driver_dependencies,
4744 &r->core_driver_dependencies,
4746 if (!W_ERROR_IS_OK(result)) {
4750 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
4751 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
4756 #if 0 /* disabled until marshalling issues are resolved - gd */
4757 /********************************************************************
4758 ********************************************************************/
4760 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
4761 struct spoolss_DriverFileInfo *r,
4762 const char *cservername,
4763 const char *file_name,
4764 enum spoolss_DriverFileType file_type,
4765 uint32_t file_version)
4767 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
4768 cservername, file_name);
4769 W_ERROR_HAVE_NO_MEMORY(r->file_name);
4770 r->file_type = file_type;
4771 r->file_version = file_version;
4776 /********************************************************************
4777 ********************************************************************/
4779 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
4780 const struct spoolss_DriverInfo8 *driver,
4781 const char *cservername,
4782 struct spoolss_DriverFileInfo **info_p,
4785 struct spoolss_DriverFileInfo *info = NULL;
4793 if (strlen(driver->driver_path)) {
4794 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4795 struct spoolss_DriverFileInfo,
4797 W_ERROR_HAVE_NO_MEMORY(info);
4798 result = fill_spoolss_DriverFileInfo(info,
4801 driver->driver_path,
4802 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
4804 W_ERROR_NOT_OK_RETURN(result);
4808 if (strlen(driver->config_file)) {
4809 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4810 struct spoolss_DriverFileInfo,
4812 W_ERROR_HAVE_NO_MEMORY(info);
4813 result = fill_spoolss_DriverFileInfo(info,
4816 driver->config_file,
4817 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
4819 W_ERROR_NOT_OK_RETURN(result);
4823 if (strlen(driver->data_file)) {
4824 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4825 struct spoolss_DriverFileInfo,
4827 W_ERROR_HAVE_NO_MEMORY(info);
4828 result = fill_spoolss_DriverFileInfo(info,
4832 SPOOLSS_DRIVER_FILE_TYPE_DATA,
4834 W_ERROR_NOT_OK_RETURN(result);
4838 if (strlen(driver->help_file)) {
4839 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4840 struct spoolss_DriverFileInfo,
4842 W_ERROR_HAVE_NO_MEMORY(info);
4843 result = fill_spoolss_DriverFileInfo(info,
4847 SPOOLSS_DRIVER_FILE_TYPE_HELP,
4849 W_ERROR_NOT_OK_RETURN(result);
4853 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
4854 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4855 struct spoolss_DriverFileInfo,
4857 W_ERROR_HAVE_NO_MEMORY(info);
4858 result = fill_spoolss_DriverFileInfo(info,
4861 driver->dependent_files[i],
4862 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
4864 W_ERROR_NOT_OK_RETURN(result);
4874 /********************************************************************
4875 * fill a spoolss_DriverInfo101 struct
4876 ********************************************************************/
4878 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
4879 struct spoolss_DriverInfo101 *r,
4880 const struct spoolss_DriverInfo8 *driver,
4881 const char *servername)
4883 const char *cservername = canon_servername(servername);
4886 r->version = driver->version;
4888 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4889 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4890 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4891 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4893 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
4897 if (!W_ERROR_IS_OK(result)) {
4901 FILL_DRIVER_STRING(mem_ctx,
4902 driver->monitor_name,
4905 FILL_DRIVER_STRING(mem_ctx,
4906 driver->default_datatype,
4907 r->default_datatype);
4909 result = string_array_from_driver_info(mem_ctx,
4910 driver->previous_names,
4913 if (!W_ERROR_IS_OK(result)) {
4917 r->driver_date = driver->driver_date;
4918 r->driver_version = driver->driver_version;
4920 FILL_DRIVER_STRING(mem_ctx,
4921 driver->manufacturer_name,
4922 r->manufacturer_name);
4923 FILL_DRIVER_STRING(mem_ctx,
4924 driver->manufacturer_url,
4925 r->manufacturer_url);
4926 FILL_DRIVER_STRING(mem_ctx,
4927 driver->hardware_id,
4929 FILL_DRIVER_STRING(mem_ctx,
4936 /********************************************************************
4937 ********************************************************************/
4939 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
4940 struct auth_serversupplied_info *server_info,
4942 union spoolss_DriverInfo *r,
4944 const char *servername,
4945 const char *architecture,
4948 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
4949 struct spoolss_DriverInfo8 *driver;
4952 result = winreg_get_printer(mem_ctx,
4955 lp_const_servicename(snum),
4958 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
4959 win_errstr(result)));
4961 if (!W_ERROR_IS_OK(result)) {
4962 return WERR_INVALID_PRINTER_NAME;
4965 result = winreg_get_driver(mem_ctx, server_info, architecture,
4966 pinfo2->drivername, version, &driver);
4968 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
4969 win_errstr(result)));
4971 if (!W_ERROR_IS_OK(result)) {
4973 * Is this a W2k client ?
4977 talloc_free(pinfo2);
4978 return WERR_UNKNOWN_PRINTER_DRIVER;
4981 /* Yes - try again with a WinNT driver. */
4983 result = winreg_get_driver(mem_ctx, server_info, architecture,
4986 DEBUG(8,("construct_printer_driver_level: status: %s\n",
4987 win_errstr(result)));
4988 if (!W_ERROR_IS_OK(result)) {
4989 talloc_free(pinfo2);
4990 return WERR_UNKNOWN_PRINTER_DRIVER;
4996 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
4999 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5002 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5005 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5008 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5011 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5014 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5016 #if 0 /* disabled until marshalling issues are resolved - gd */
5018 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5022 result = WERR_UNKNOWN_LEVEL;
5026 talloc_free(pinfo2);
5027 talloc_free(driver);
5032 /****************************************************************
5033 _spoolss_GetPrinterDriver2
5034 ****************************************************************/
5036 WERROR _spoolss_GetPrinterDriver2(pipes_struct *p,
5037 struct spoolss_GetPrinterDriver2 *r)
5039 Printer_entry *printer;
5044 /* that's an [in out] buffer */
5046 if (!r->in.buffer && (r->in.offered != 0)) {
5047 return WERR_INVALID_PARAM;
5050 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5052 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5053 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5054 return WERR_INVALID_PRINTER_NAME;
5058 *r->out.server_major_version = 0;
5059 *r->out.server_minor_version = 0;
5061 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5065 result = construct_printer_driver_info_level(p->mem_ctx, p->server_info,
5066 r->in.level, r->out.info,
5067 snum, printer->servername,
5069 r->in.client_major_version);
5070 if (!W_ERROR_IS_OK(result)) {
5071 TALLOC_FREE(r->out.info);
5075 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5076 r->out.info, r->in.level);
5077 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5079 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5083 /****************************************************************
5084 _spoolss_StartPagePrinter
5085 ****************************************************************/
5087 WERROR _spoolss_StartPagePrinter(pipes_struct *p,
5088 struct spoolss_StartPagePrinter *r)
5090 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5093 DEBUG(3,("_spoolss_StartPagePrinter: "
5094 "Error in startpageprinter printer handle\n"));
5098 Printer->page_started = true;
5102 /****************************************************************
5103 _spoolss_EndPagePrinter
5104 ****************************************************************/
5106 WERROR _spoolss_EndPagePrinter(pipes_struct *p,
5107 struct spoolss_EndPagePrinter *r)
5111 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5114 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5115 OUR_HANDLE(r->in.handle)));
5119 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5122 Printer->page_started = false;
5123 print_job_endpage(snum, Printer->jobid);
5128 /****************************************************************
5129 _spoolss_StartDocPrinter
5130 ****************************************************************/
5132 WERROR _spoolss_StartDocPrinter(pipes_struct *p,
5133 struct spoolss_StartDocPrinter *r)
5135 struct spoolss_DocumentInfo1 *info_1;
5137 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5141 DEBUG(2,("_spoolss_StartDocPrinter: "
5142 "Invalid handle (%s:%u:%u)\n",
5143 OUR_HANDLE(r->in.handle)));
5147 if (Printer->jobid) {
5148 DEBUG(2, ("_spoolss_StartDocPrinter: "
5149 "StartDocPrinter called twice! "
5150 "(existing jobid = %d)\n", Printer->jobid));
5151 return WERR_INVALID_HANDLE;
5154 if (r->in.level != 1) {
5155 return WERR_UNKNOWN_LEVEL;
5158 info_1 = r->in.info.info1;
5161 * a nice thing with NT is it doesn't listen to what you tell it.
5162 * when asked to send _only_ RAW datas, it tries to send datas
5165 * So I add checks like in NT Server ...
5168 if (info_1->datatype) {
5169 if (strcmp(info_1->datatype, "RAW") != 0) {
5171 return WERR_INVALID_DATATYPE;
5175 /* get the share number of the printer */
5176 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5180 werr = print_job_start(p->server_info, snum,
5181 info_1->document_name, info_1->output_file,
5182 Printer->devmode, &Printer->jobid);
5184 /* An error occured in print_job_start() so return an appropriate
5187 if (!W_ERROR_IS_OK(werr)) {
5191 Printer->document_started = true;
5192 *r->out.job_id = Printer->jobid;
5197 /****************************************************************
5198 _spoolss_EndDocPrinter
5199 ****************************************************************/
5201 WERROR _spoolss_EndDocPrinter(pipes_struct *p,
5202 struct spoolss_EndDocPrinter *r)
5204 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5209 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5210 OUR_HANDLE(r->in.handle)));
5214 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5218 Printer->document_started = false;
5219 status = print_job_end(snum, Printer->jobid, NORMAL_CLOSE);
5220 if (!NT_STATUS_IS_OK(status)) {
5221 DEBUG(2, ("_spoolss_EndDocPrinter: "
5222 "print_job_end failed [%s]\n",
5223 nt_errstr(status)));
5227 return ntstatus_to_werror(status);
5230 /****************************************************************
5231 _spoolss_WritePrinter
5232 ****************************************************************/
5234 WERROR _spoolss_WritePrinter(pipes_struct *p,
5235 struct spoolss_WritePrinter *r)
5237 ssize_t buffer_written;
5239 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5242 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5243 OUR_HANDLE(r->in.handle)));
5244 *r->out.num_written = r->in._data_size;
5248 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5251 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5252 buffer_written = print_job_write(snum, Printer->jobid,
5253 (const char *)r->in.data.data,
5255 (size_t)r->in._data_size);
5256 if (buffer_written == (ssize_t)-1) {
5257 *r->out.num_written = 0;
5258 if (errno == ENOSPC)
5259 return WERR_NO_SPOOL_SPACE;
5261 return WERR_ACCESS_DENIED;
5264 *r->out.num_written = r->in._data_size;
5269 /********************************************************************
5270 * api_spoolss_getprinter
5271 * called from the spoolss dispatcher
5273 ********************************************************************/
5275 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5279 WERROR errcode = WERR_BADFUNC;
5280 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5283 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5284 OUR_HANDLE(handle)));
5288 if (!get_printer_snum(p, handle, &snum, NULL))
5292 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5293 errcode = print_queue_pause(p->server_info, snum);
5295 case SPOOLSS_PRINTER_CONTROL_RESUME:
5296 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5297 errcode = print_queue_resume(p->server_info, snum);
5299 case SPOOLSS_PRINTER_CONTROL_PURGE:
5300 errcode = print_queue_purge(p->server_info, snum);
5303 return WERR_UNKNOWN_LEVEL;
5310 /****************************************************************
5311 _spoolss_AbortPrinter
5312 * From MSDN: "Deletes printer's spool file if printer is configured
5314 ****************************************************************/
5316 WERROR _spoolss_AbortPrinter(pipes_struct *p,
5317 struct spoolss_AbortPrinter *r)
5319 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5321 WERROR errcode = WERR_OK;
5324 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5325 OUR_HANDLE(r->in.handle)));
5329 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5332 if (!Printer->document_started) {
5333 return WERR_SPL_NO_STARTDOC;
5336 errcode = print_job_delete(p->server_info, snum, Printer->jobid);
5341 /********************************************************************
5342 * called by spoolss_api_setprinter
5343 * when updating a printer description
5344 ********************************************************************/
5346 static WERROR update_printer_sec(struct policy_handle *handle,
5347 pipes_struct *p, struct sec_desc_buf *secdesc_ctr)
5349 struct spoolss_security_descriptor *new_secdesc = NULL;
5350 struct spoolss_security_descriptor *old_secdesc = NULL;
5351 const char *printer;
5355 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5357 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5358 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5359 OUR_HANDLE(handle)));
5361 result = WERR_BADFID;
5365 if (secdesc_ctr == NULL) {
5366 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5367 result = WERR_INVALID_PARAM;
5370 printer = lp_const_servicename(snum);
5372 /* Check the user has permissions to change the security
5373 descriptor. By experimentation with two NT machines, the user
5374 requires Full Access to the printer to change security
5377 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5378 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5379 result = WERR_ACCESS_DENIED;
5383 /* NT seems to like setting the security descriptor even though
5384 nothing may have actually changed. */
5385 result = winreg_get_printer_secdesc(p->mem_ctx,
5389 if (!W_ERROR_IS_OK(result)) {
5390 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5391 result = WERR_BADFID;
5395 if (DEBUGLEVEL >= 10) {
5396 struct security_acl *the_acl;
5399 the_acl = old_secdesc->dacl;
5400 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5401 printer, the_acl->num_aces));
5403 for (i = 0; i < the_acl->num_aces; i++) {
5404 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5405 &the_acl->aces[i].trustee),
5406 the_acl->aces[i].access_mask));
5409 the_acl = secdesc_ctr->sd->dacl;
5412 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5413 printer, the_acl->num_aces));
5415 for (i = 0; i < the_acl->num_aces; i++) {
5416 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5417 &the_acl->aces[i].trustee),
5418 the_acl->aces[i].access_mask));
5421 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5425 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
5426 if (new_secdesc == NULL) {
5427 result = WERR_NOMEM;
5431 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
5436 result = winreg_set_printer_secdesc(p->mem_ctx,
5445 /********************************************************************
5446 Canonicalize printer info from a client
5447 ********************************************************************/
5449 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
5450 struct spoolss_SetPrinterInfo2 *info2,
5453 fstring printername;
5456 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5457 "portname=%s drivername=%s comment=%s location=%s\n",
5458 info2->servername, info2->printername, info2->sharename,
5459 info2->portname, info2->drivername, info2->comment,
5462 /* we force some elements to "correct" values */
5463 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
5464 if (info2->servername == NULL) {
5467 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
5468 if (info2->sharename == NULL) {
5472 /* check to see if we allow printername != sharename */
5473 if (lp_force_printername(snum)) {
5474 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5475 global_myname(), info2->sharename);
5477 /* make sure printername is in \\server\printername format */
5478 fstrcpy(printername, info2->printername);
5480 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5481 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5485 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5486 global_myname(), p);
5488 if (info2->printername == NULL) {
5492 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5493 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5498 /****************************************************************************
5499 ****************************************************************************/
5501 static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri)
5503 char *cmd = lp_addport_cmd();
5504 char *command = NULL;
5506 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5507 bool is_print_op = false;
5510 return WERR_ACCESS_DENIED;
5513 command = talloc_asprintf(ctx,
5514 "%s \"%s\" \"%s\"", cmd, portname, uri );
5520 is_print_op = user_has_privileges( token, &se_printop );
5522 DEBUG(10,("Running [%s]\n", command));
5524 /********* BEGIN SePrintOperatorPrivilege **********/
5529 ret = smbrun(command, NULL);
5534 /********* END SePrintOperatorPrivilege **********/
5536 DEBUGADD(10,("returned [%d]\n", ret));
5538 TALLOC_FREE(command);
5541 return WERR_ACCESS_DENIED;
5547 /****************************************************************************
5548 ****************************************************************************/
5550 bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
5551 struct spoolss_SetPrinterInfo2 *info2,
5552 const char *remote_machine)
5554 char *cmd = lp_addprinter_cmd();
5556 char *command = NULL;
5560 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5561 bool is_print_op = false;
5563 if (!remote_machine) {
5567 command = talloc_asprintf(ctx,
5568 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5569 cmd, info2->printername, info2->sharename,
5570 info2->portname, info2->drivername,
5571 info2->location, info2->comment, remote_machine);
5577 is_print_op = user_has_privileges( token, &se_printop );
5579 DEBUG(10,("Running [%s]\n", command));
5581 /********* BEGIN SePrintOperatorPrivilege **********/
5586 if ( (ret = smbrun(command, &fd)) == 0 ) {
5587 /* Tell everyone we updated smb.conf. */
5588 message_send_all(smbd_messaging_context(),
5589 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5595 /********* END SePrintOperatorPrivilege **********/
5597 DEBUGADD(10,("returned [%d]\n", ret));
5599 TALLOC_FREE(command);
5607 /* reload our services immediately */
5609 reload_services(false);
5613 /* Get lines and convert them back to dos-codepage */
5614 qlines = fd_lines_load(fd, &numlines, 0, NULL);
5615 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
5618 /* Set the portname to what the script says the portname should be. */
5619 /* but don't require anything to be return from the script exit a good error code */
5622 /* Set the portname to what the script says the portname should be. */
5623 info2->portname = talloc_strdup(ctx, qlines[0]);
5624 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
5627 TALLOC_FREE(qlines);
5631 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
5632 struct auth_serversupplied_info *server_info,
5634 struct spoolss_SetPrinterInfo2 *printer,
5635 struct spoolss_PrinterInfo2 *old_printer)
5637 bool force_update = (old_printer == NULL);
5638 const char *dnsdomname;
5639 const char *longname;
5640 const char *uncname;
5641 const char *spooling;
5643 WERROR result = WERR_OK;
5645 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
5646 push_reg_sz(mem_ctx, &buffer, printer->drivername);
5647 winreg_set_printer_dataex(mem_ctx,
5650 SPOOL_DSSPOOLER_KEY,
5651 SPOOL_REG_DRIVERNAME,
5656 if (!force_update) {
5657 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
5658 printer->drivername));
5660 notify_printer_driver(snum, printer->drivername);
5664 if (force_update || !strequal(printer->comment, old_printer->comment)) {
5665 push_reg_sz(mem_ctx, &buffer, printer->comment);
5666 winreg_set_printer_dataex(mem_ctx,
5669 SPOOL_DSSPOOLER_KEY,
5670 SPOOL_REG_DESCRIPTION,
5675 if (!force_update) {
5676 notify_printer_comment(snum, printer->comment);
5680 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
5681 push_reg_sz(mem_ctx, &buffer, printer->sharename);
5682 winreg_set_printer_dataex(mem_ctx,
5685 SPOOL_DSSPOOLER_KEY,
5686 SPOOL_REG_PRINTSHARENAME,
5691 if (!force_update) {
5692 notify_printer_sharename(snum, printer->sharename);
5696 if (force_update || !strequal(printer->printername, old_printer->printername)) {
5699 p = strrchr(printer->printername, '\\' );
5703 p = printer->printername;
5706 push_reg_sz(mem_ctx, &buffer, p);
5707 winreg_set_printer_dataex(mem_ctx,
5710 SPOOL_DSSPOOLER_KEY,
5711 SPOOL_REG_PRINTERNAME,
5716 if (!force_update) {
5717 notify_printer_printername(snum, p);
5721 if (force_update || !strequal(printer->portname, old_printer->portname)) {
5722 push_reg_sz(mem_ctx, &buffer, printer->portname);
5723 winreg_set_printer_dataex(mem_ctx,
5726 SPOOL_DSSPOOLER_KEY,
5732 if (!force_update) {
5733 notify_printer_port(snum, printer->portname);
5737 if (force_update || !strequal(printer->location, old_printer->location)) {
5738 push_reg_sz(mem_ctx, &buffer, printer->location);
5739 winreg_set_printer_dataex(mem_ctx,
5742 SPOOL_DSSPOOLER_KEY,
5748 if (!force_update) {
5749 notify_printer_location(snum, printer->location);
5753 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
5754 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
5755 winreg_set_printer_dataex(mem_ctx,
5758 SPOOL_DSSPOOLER_KEY,
5759 SPOOL_REG_PRINTSEPARATORFILE,
5764 if (!force_update) {
5765 notify_printer_location(snum, printer->location);
5769 if (force_update || printer->starttime != old_printer->starttime) {
5770 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5771 SIVAL(buffer.data, 0, printer->starttime);
5772 winreg_set_printer_dataex(mem_ctx,
5775 SPOOL_DSSPOOLER_KEY,
5776 SPOOL_REG_PRINTSTARTTIME,
5782 if (force_update || printer->untiltime != old_printer->untiltime) {
5783 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5784 SIVAL(buffer.data, 0, printer->untiltime);
5785 winreg_set_printer_dataex(mem_ctx,
5788 SPOOL_DSSPOOLER_KEY,
5789 SPOOL_REG_PRINTENDTIME,
5795 if (force_update || printer->priority != old_printer->priority) {
5796 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5797 SIVAL(buffer.data, 0, printer->priority);
5798 winreg_set_printer_dataex(mem_ctx,
5801 SPOOL_DSSPOOLER_KEY,
5808 if (force_update || printer->attributes != old_printer->attributes) {
5809 buffer = data_blob_talloc(mem_ctx, NULL, 4);
5810 SIVAL(buffer.data, 0, (printer->attributes &
5811 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
5812 winreg_set_printer_dataex(mem_ctx,
5815 SPOOL_DSSPOOLER_KEY,
5816 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
5821 switch (printer->attributes & 0x3) {
5823 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
5826 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
5829 spooling = SPOOL_REGVAL_PRINTDIRECT;
5832 spooling = "unknown";
5834 push_reg_sz(mem_ctx, &buffer, spooling);
5835 winreg_set_printer_dataex(mem_ctx,
5838 SPOOL_DSSPOOLER_KEY,
5839 SPOOL_REG_PRINTSPOOLING,
5845 push_reg_sz(mem_ctx, &buffer, global_myname());
5846 winreg_set_printer_dataex(mem_ctx,
5849 SPOOL_DSSPOOLER_KEY,
5850 SPOOL_REG_SHORTSERVERNAME,
5855 dnsdomname = get_mydnsfullname();
5856 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
5857 longname = talloc_strdup(mem_ctx, dnsdomname);
5859 longname = talloc_strdup(mem_ctx, global_myname());
5861 if (longname == NULL) {
5862 result = WERR_NOMEM;
5866 push_reg_sz(mem_ctx, &buffer, longname);
5867 winreg_set_printer_dataex(mem_ctx,
5870 SPOOL_DSSPOOLER_KEY,
5871 SPOOL_REG_SERVERNAME,
5876 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5877 global_myname(), printer->sharename);
5878 push_reg_sz(mem_ctx, &buffer, uncname);
5879 winreg_set_printer_dataex(mem_ctx,
5882 SPOOL_DSSPOOLER_KEY,
5892 /********************************************************************
5893 * Called by spoolss_api_setprinter
5894 * when updating a printer description.
5895 ********************************************************************/
5897 static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
5898 struct spoolss_SetPrinterInfoCtr *info_ctr,
5899 struct spoolss_DeviceMode *devmode)
5901 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
5902 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
5903 struct spoolss_PrinterInfo2 *old_printer;
5904 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5905 const char *servername = NULL;
5907 WERROR result = WERR_OK;
5908 TALLOC_CTX *tmp_ctx;
5910 DEBUG(8,("update_printer\n"));
5912 tmp_ctx = talloc_new(p->mem_ctx);
5913 if (tmp_ctx == NULL) {
5918 result = WERR_BADFID;
5922 if (!get_printer_snum(p, handle, &snum, NULL)) {
5923 result = WERR_BADFID;
5927 if (Printer != NULL || Printer->servername != NULL) {
5928 servername = Printer->servername;
5931 result = winreg_get_printer(tmp_ctx,
5934 lp_const_servicename(snum),
5936 if (!W_ERROR_IS_OK(result)) {
5937 result = WERR_BADFID;
5941 /* Do sanity check on the requested changes for Samba */
5942 if (!check_printer_ok(tmp_ctx, printer, snum)) {
5943 result = WERR_INVALID_PARAM;
5947 /* FIXME!!! If the driver has changed we really should verify that
5948 it is installed before doing much else --jerry */
5950 /* Check calling user has permission to update printer description */
5951 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
5952 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
5953 result = WERR_ACCESS_DENIED;
5957 /* Call addprinter hook */
5958 /* Check changes to see if this is really needed */
5960 if (*lp_addprinter_cmd() &&
5961 (!strequal(printer->drivername, old_printer->drivername) ||
5962 !strequal(printer->comment, old_printer->comment) ||
5963 !strequal(printer->portname, old_printer->portname) ||
5964 !strequal(printer->location, old_printer->location)) )
5966 /* add_printer_hook() will call reload_services() */
5967 if (!add_printer_hook(tmp_ctx, p->server_info->ptok,
5968 printer, p->client_address) ) {
5969 result = WERR_ACCESS_DENIED;
5974 update_dsspooler(tmp_ctx,
5980 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
5982 if (devmode == NULL) {
5983 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
5985 result = winreg_update_printer(tmp_ctx,
5994 talloc_free(tmp_ctx);
5999 /****************************************************************************
6000 ****************************************************************************/
6001 static WERROR publish_or_unpublish_printer(pipes_struct *p,
6002 struct policy_handle *handle,
6003 struct spoolss_SetPrinterInfo7 *info7)
6006 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6009 Printer_entry *Printer;
6011 if ( lp_security() != SEC_ADS ) {
6012 return WERR_UNKNOWN_LEVEL;
6015 Printer = find_printer_index_by_hnd(p, handle);
6017 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6022 if (!get_printer_snum(p, handle, &snum, NULL))
6025 result = winreg_get_printer(p->mem_ctx, p->server_info,
6026 Printer->servername,
6027 lp_servicename(snum), &pinfo2);
6028 if (!W_ERROR_IS_OK(result)) {
6032 nt_printer_publish(pinfo2, p->server_info, pinfo2, info7->action);
6034 TALLOC_FREE(pinfo2);
6037 return WERR_UNKNOWN_LEVEL;
6041 /********************************************************************
6042 ********************************************************************/
6044 static WERROR update_printer_devmode(pipes_struct *p, struct policy_handle *handle,
6045 struct spoolss_DeviceMode *devmode)
6048 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6049 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6051 DEBUG(8,("update_printer_devmode\n"));
6057 if (!get_printer_snum(p, handle, &snum, NULL)) {
6061 /* Check calling user has permission to update printer description */
6062 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6063 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6064 return WERR_ACCESS_DENIED;
6067 return winreg_update_printer(p->mem_ctx,
6069 lp_const_servicename(snum),
6077 /****************************************************************
6079 ****************************************************************/
6081 WERROR _spoolss_SetPrinter(pipes_struct *p,
6082 struct spoolss_SetPrinter *r)
6086 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6089 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6090 OUR_HANDLE(r->in.handle)));
6094 /* check the level */
6095 switch (r->in.info_ctr->level) {
6097 return control_printer(r->in.handle, r->in.command, p);
6099 result = update_printer(p, r->in.handle,
6101 r->in.devmode_ctr->devmode);
6102 if (!W_ERROR_IS_OK(result))
6104 if (r->in.secdesc_ctr->sd)
6105 result = update_printer_sec(r->in.handle, p,
6109 return update_printer_sec(r->in.handle, p,
6112 return publish_or_unpublish_printer(p, r->in.handle,
6113 r->in.info_ctr->info.info7);
6115 return update_printer_devmode(p, r->in.handle,
6116 r->in.devmode_ctr->devmode);
6118 return WERR_UNKNOWN_LEVEL;
6122 /****************************************************************
6123 _spoolss_FindClosePrinterNotify
6124 ****************************************************************/
6126 WERROR _spoolss_FindClosePrinterNotify(pipes_struct *p,
6127 struct spoolss_FindClosePrinterNotify *r)
6129 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6132 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6133 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6137 if (Printer->notify.client_connected == true) {
6140 if ( Printer->printer_type == SPLHND_SERVER)
6142 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6143 !get_printer_snum(p, r->in.handle, &snum, NULL) )
6146 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
6149 Printer->notify.flags=0;
6150 Printer->notify.options=0;
6151 Printer->notify.localmachine[0]='\0';
6152 Printer->notify.printerlocal=0;
6153 TALLOC_FREE(Printer->notify.option);
6154 Printer->notify.client_connected = false;
6159 /****************************************************************
6161 ****************************************************************/
6163 WERROR _spoolss_AddJob(pipes_struct *p,
6164 struct spoolss_AddJob *r)
6166 if (!r->in.buffer && (r->in.offered != 0)) {
6167 return WERR_INVALID_PARAM;
6170 /* this is what a NT server returns for AddJob. AddJob must fail on
6171 * non-local printers */
6173 if (r->in.level != 1) {
6174 return WERR_UNKNOWN_LEVEL;
6177 return WERR_INVALID_PARAM;
6180 /****************************************************************************
6182 ****************************************************************************/
6184 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6185 struct spoolss_JobInfo1 *r,
6186 const print_queue_struct *queue,
6187 int position, int snum,
6188 struct spoolss_PrinterInfo2 *pinfo2)
6192 t = gmtime(&queue->time);
6194 r->job_id = queue->job;
6196 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6197 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6198 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6199 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6200 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6201 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6202 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6203 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6204 r->data_type = talloc_strdup(mem_ctx, "RAW");
6205 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6206 r->text_status = talloc_strdup(mem_ctx, "");
6207 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6209 r->status = nt_printj_status(queue->status);
6210 r->priority = queue->priority;
6211 r->position = position;
6212 r->total_pages = queue->page_count;
6213 r->pages_printed = 0; /* ??? */
6215 init_systemtime(&r->submitted, t);
6220 /****************************************************************************
6222 ****************************************************************************/
6224 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6225 struct spoolss_JobInfo2 *r,
6226 const print_queue_struct *queue,
6227 int position, int snum,
6228 struct spoolss_PrinterInfo2 *pinfo2,
6229 struct spoolss_DeviceMode *devmode)
6233 t = gmtime(&queue->time);
6235 r->job_id = queue->job;
6237 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6238 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6239 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6240 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6241 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6242 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6243 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6244 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6245 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6246 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6247 r->data_type = talloc_strdup(mem_ctx, "RAW");
6248 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6249 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6250 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6251 r->parameters = talloc_strdup(mem_ctx, "");
6252 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6253 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6254 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6256 r->devmode = devmode;
6258 r->text_status = talloc_strdup(mem_ctx, "");
6259 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6263 r->status = nt_printj_status(queue->status);
6264 r->priority = queue->priority;
6265 r->position = position;
6268 r->total_pages = queue->page_count;
6269 r->size = queue->size;
6270 init_systemtime(&r->submitted, t);
6272 r->pages_printed = 0; /* ??? */
6277 /****************************************************************************
6279 ****************************************************************************/
6281 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6282 struct spoolss_JobInfo3 *r,
6283 const print_queue_struct *queue,
6284 const print_queue_struct *next_queue,
6285 int position, int snum,
6286 struct spoolss_PrinterInfo2 *pinfo2)
6288 r->job_id = queue->job;
6291 r->next_job_id = next_queue->job;
6298 /****************************************************************************
6299 Enumjobs at level 1.
6300 ****************************************************************************/
6302 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6303 const print_queue_struct *queue,
6304 uint32_t num_queues, int snum,
6305 struct spoolss_PrinterInfo2 *pinfo2,
6306 union spoolss_JobInfo **info_p,
6309 union spoolss_JobInfo *info;
6311 WERROR result = WERR_OK;
6313 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6314 W_ERROR_HAVE_NO_MEMORY(info);
6316 *count = num_queues;
6318 for (i=0; i<*count; i++) {
6319 result = fill_job_info1(info,
6325 if (!W_ERROR_IS_OK(result)) {
6331 if (!W_ERROR_IS_OK(result)) {
6342 /****************************************************************************
6343 Enumjobs at level 2.
6344 ****************************************************************************/
6346 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6347 const print_queue_struct *queue,
6348 uint32_t num_queues, int snum,
6349 struct spoolss_PrinterInfo2 *pinfo2,
6350 union spoolss_JobInfo **info_p,
6353 union spoolss_JobInfo *info;
6355 WERROR result = WERR_OK;
6357 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6358 W_ERROR_HAVE_NO_MEMORY(info);
6360 *count = num_queues;
6362 for (i=0; i<*count; i++) {
6363 struct spoolss_DeviceMode *devmode;
6365 result = spoolss_create_default_devmode(info,
6366 pinfo2->printername,
6368 if (!W_ERROR_IS_OK(result)) {
6369 DEBUG(3, ("Can't proceed w/o a devmode!"));
6373 result = fill_job_info2(info,
6380 if (!W_ERROR_IS_OK(result)) {
6386 if (!W_ERROR_IS_OK(result)) {
6397 /****************************************************************************
6398 Enumjobs at level 3.
6399 ****************************************************************************/
6401 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6402 const print_queue_struct *queue,
6403 uint32_t num_queues, int snum,
6404 struct spoolss_PrinterInfo2 *pinfo2,
6405 union spoolss_JobInfo **info_p,
6408 union spoolss_JobInfo *info;
6410 WERROR result = WERR_OK;
6412 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6413 W_ERROR_HAVE_NO_MEMORY(info);
6415 *count = num_queues;
6417 for (i=0; i<*count; i++) {
6418 const print_queue_struct *next_queue = NULL;
6421 next_queue = &queue[i+1];
6424 result = fill_job_info3(info,
6431 if (!W_ERROR_IS_OK(result)) {
6437 if (!W_ERROR_IS_OK(result)) {
6448 /****************************************************************
6450 ****************************************************************/
6452 WERROR _spoolss_EnumJobs(pipes_struct *p,
6453 struct spoolss_EnumJobs *r)
6456 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6458 print_status_struct prt_status;
6459 print_queue_struct *queue = NULL;
6462 /* that's an [in out] buffer */
6464 if (!r->in.buffer && (r->in.offered != 0)) {
6465 return WERR_INVALID_PARAM;
6468 DEBUG(4,("_spoolss_EnumJobs\n"));
6472 *r->out.info = NULL;
6474 /* lookup the printer snum and tdb entry */
6476 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6480 result = winreg_get_printer(p->mem_ctx, p->server_info, NULL,
6481 lp_servicename(snum), &pinfo2);
6482 if (!W_ERROR_IS_OK(result)) {
6486 count = print_queue_status(snum, &queue, &prt_status);
6487 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6488 count, prt_status.status, prt_status.message));
6492 TALLOC_FREE(pinfo2);
6496 switch (r->in.level) {
6498 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6499 pinfo2, r->out.info, r->out.count);
6502 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6503 pinfo2, r->out.info, r->out.count);
6506 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
6507 pinfo2, r->out.info, r->out.count);
6510 result = WERR_UNKNOWN_LEVEL;
6515 TALLOC_FREE(pinfo2);
6517 if (!W_ERROR_IS_OK(result)) {
6521 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6523 *r->out.info, r->in.level,
6525 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6526 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6528 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6531 /****************************************************************
6532 _spoolss_ScheduleJob
6533 ****************************************************************/
6535 WERROR _spoolss_ScheduleJob(pipes_struct *p,
6536 struct spoolss_ScheduleJob *r)
6541 /****************************************************************
6542 ****************************************************************/
6544 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
6545 const char *printer_name,
6547 struct spoolss_SetJobInfo1 *r)
6551 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
6555 if (strequal(old_doc_name, r->document_name)) {
6559 if (!print_job_set_name(printer_name, job_id, r->document_name)) {
6566 /****************************************************************
6568 ****************************************************************/
6570 WERROR _spoolss_SetJob(pipes_struct *p,
6571 struct spoolss_SetJob *r)
6574 WERROR errcode = WERR_BADFUNC;
6576 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6580 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6581 return WERR_INVALID_PRINTER_NAME;
6584 switch (r->in.command) {
6585 case SPOOLSS_JOB_CONTROL_CANCEL:
6586 case SPOOLSS_JOB_CONTROL_DELETE:
6587 errcode = print_job_delete(p->server_info,
6588 snum, r->in.job_id);
6589 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
6593 case SPOOLSS_JOB_CONTROL_PAUSE:
6594 if (print_job_pause(p->server_info, snum, r->in.job_id, &errcode)) {
6598 case SPOOLSS_JOB_CONTROL_RESTART:
6599 case SPOOLSS_JOB_CONTROL_RESUME:
6600 if (print_job_resume(p->server_info, snum, r->in.job_id, &errcode)) {
6608 return WERR_UNKNOWN_LEVEL;
6611 if (!W_ERROR_IS_OK(errcode)) {
6615 if (r->in.ctr == NULL) {
6619 switch (r->in.ctr->level) {
6621 errcode = spoolss_setjob_1(p->mem_ctx, lp_const_servicename(snum),
6623 r->in.ctr->info.info1);
6629 return WERR_UNKNOWN_LEVEL;
6635 /****************************************************************************
6636 Enumerates all printer drivers by level and architecture.
6637 ****************************************************************************/
6639 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
6640 struct auth_serversupplied_info *server_info,
6641 const char *servername,
6642 const char *architecture,
6644 union spoolss_DriverInfo **info_p,
6649 struct spoolss_DriverInfo8 *driver;
6650 union spoolss_DriverInfo *info = NULL;
6652 WERROR result = WERR_OK;
6653 uint32_t num_drivers;
6654 const char **drivers;
6659 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6660 result = winreg_get_driver_list(mem_ctx, server_info,
6661 architecture, version,
6662 &num_drivers, &drivers);
6663 if (!W_ERROR_IS_OK(result)) {
6666 DEBUG(4, ("we have:[%d] drivers in environment"
6667 " [%s] and version [%d]\n",
6668 num_drivers, architecture, version));
6670 if (num_drivers != 0) {
6671 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6672 union spoolss_DriverInfo,
6673 count + num_drivers);
6675 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
6676 "failed to enlarge driver info buffer!\n"));
6677 result = WERR_NOMEM;
6682 for (i = 0; i < num_drivers; i++) {
6683 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
6685 result = winreg_get_driver(mem_ctx, server_info,
6686 architecture, drivers[i],
6688 if (!W_ERROR_IS_OK(result)) {
6694 result = fill_printer_driver_info1(info, &info[count+i].info1,
6695 driver, servername);
6698 result = fill_printer_driver_info2(info, &info[count+i].info2,
6699 driver, servername);
6702 result = fill_printer_driver_info3(info, &info[count+i].info3,
6703 driver, servername);
6706 result = fill_printer_driver_info4(info, &info[count+i].info4,
6707 driver, servername);
6710 result = fill_printer_driver_info5(info, &info[count+i].info5,
6711 driver, servername);
6714 result = fill_printer_driver_info6(info, &info[count+i].info6,
6715 driver, servername);
6718 result = fill_printer_driver_info8(info, &info[count+i].info8,
6719 driver, servername);
6722 result = WERR_UNKNOWN_LEVEL;
6726 TALLOC_FREE(driver);
6728 if (!W_ERROR_IS_OK(result)) {
6733 count += num_drivers;
6734 TALLOC_FREE(drivers);
6738 TALLOC_FREE(drivers);
6740 if (!W_ERROR_IS_OK(result)) {
6751 /****************************************************************************
6752 Enumerates all printer drivers by level.
6753 ****************************************************************************/
6755 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
6756 struct auth_serversupplied_info *server_info,
6757 const char *servername,
6758 const char *architecture,
6760 union spoolss_DriverInfo **info_p,
6764 WERROR result = WERR_OK;
6766 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
6768 for (a=0; archi_table[a].long_archi != NULL; a++) {
6770 union spoolss_DriverInfo *info = NULL;
6773 result = enumprinterdrivers_level_by_architecture(mem_ctx,
6776 archi_table[a].long_archi,
6780 if (!W_ERROR_IS_OK(result)) {
6784 for (i=0; i < count; i++) {
6785 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
6786 info[i], info_p, count_p);
6793 return enumprinterdrivers_level_by_architecture(mem_ctx,
6802 /****************************************************************
6803 _spoolss_EnumPrinterDrivers
6804 ****************************************************************/
6806 WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
6807 struct spoolss_EnumPrinterDrivers *r)
6809 const char *cservername;
6812 /* that's an [in out] buffer */
6814 if (!r->in.buffer && (r->in.offered != 0)) {
6815 return WERR_INVALID_PARAM;
6818 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
6822 *r->out.info = NULL;
6824 cservername = canon_servername(r->in.server);
6826 if (!is_myname_or_ipaddr(cservername)) {
6827 return WERR_UNKNOWN_PRINTER_DRIVER;
6830 result = enumprinterdrivers_level(p->mem_ctx,
6837 if (!W_ERROR_IS_OK(result)) {
6841 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6842 spoolss_EnumPrinterDrivers,
6843 *r->out.info, r->in.level,
6845 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6846 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6848 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6851 /****************************************************************
6853 ****************************************************************/
6855 WERROR _spoolss_EnumForms(pipes_struct *p,
6856 struct spoolss_EnumForms *r)
6862 *r->out.info = NULL;
6864 /* that's an [in out] buffer */
6866 if (!r->in.buffer && (r->in.offered != 0) ) {
6867 return WERR_INVALID_PARAM;
6870 DEBUG(4,("_spoolss_EnumForms\n"));
6871 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6872 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6874 switch (r->in.level) {
6876 result = winreg_printer_enumforms1(p->mem_ctx,
6882 result = WERR_UNKNOWN_LEVEL;
6886 if (!W_ERROR_IS_OK(result)) {
6890 if (*r->out.count == 0) {
6891 return WERR_NO_MORE_ITEMS;
6894 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6896 *r->out.info, r->in.level,
6898 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6899 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6901 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6904 /****************************************************************
6906 ****************************************************************/
6908 WERROR _spoolss_GetForm(pipes_struct *p,
6909 struct spoolss_GetForm *r)
6913 /* that's an [in out] buffer */
6915 if (!r->in.buffer && (r->in.offered != 0)) {
6916 return WERR_INVALID_PARAM;
6919 DEBUG(4,("_spoolss_GetForm\n"));
6920 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6921 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6923 switch (r->in.level) {
6925 result = winreg_printer_getform1(p->mem_ctx,
6928 &r->out.info->info1);
6931 result = WERR_UNKNOWN_LEVEL;
6935 if (!W_ERROR_IS_OK(result)) {
6936 TALLOC_FREE(r->out.info);
6940 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
6941 r->out.info, r->in.level);
6942 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
6944 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6947 /****************************************************************************
6948 ****************************************************************************/
6950 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
6951 struct spoolss_PortInfo1 *r,
6954 r->port_name = talloc_strdup(mem_ctx, name);
6955 W_ERROR_HAVE_NO_MEMORY(r->port_name);
6960 /****************************************************************************
6961 TODO: This probably needs distinguish between TCP/IP and Local ports
6963 ****************************************************************************/
6965 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
6966 struct spoolss_PortInfo2 *r,
6969 r->port_name = talloc_strdup(mem_ctx, name);
6970 W_ERROR_HAVE_NO_MEMORY(r->port_name);
6972 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
6973 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
6975 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
6976 W_ERROR_HAVE_NO_MEMORY(r->description);
6978 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
6985 /****************************************************************************
6986 wrapper around the enumer ports command
6987 ****************************************************************************/
6989 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
6991 char *cmd = lp_enumports_cmd();
6992 char **qlines = NULL;
6993 char *command = NULL;
7001 /* if no hook then just fill in the default port */
7004 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7007 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7008 TALLOC_FREE(qlines);
7015 /* we have a valid enumport command */
7017 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7022 DEBUG(10,("Running [%s]\n", command));
7023 ret = smbrun(command, &fd);
7024 DEBUG(10,("Returned [%d]\n", ret));
7025 TALLOC_FREE(command);
7030 return WERR_ACCESS_DENIED;
7034 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7035 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7045 /****************************************************************************
7047 ****************************************************************************/
7049 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7050 union spoolss_PortInfo **info_p,
7053 union spoolss_PortInfo *info = NULL;
7055 WERROR result = WERR_OK;
7056 char **qlines = NULL;
7059 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7060 if (!W_ERROR_IS_OK(result)) {
7065 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7067 DEBUG(10,("Returning WERR_NOMEM\n"));
7068 result = WERR_NOMEM;
7072 for (i=0; i<numlines; i++) {
7073 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7074 result = fill_port_1(info, &info[i].info1, qlines[i]);
7075 if (!W_ERROR_IS_OK(result)) {
7080 TALLOC_FREE(qlines);
7083 if (!W_ERROR_IS_OK(result)) {
7085 TALLOC_FREE(qlines);
7097 /****************************************************************************
7099 ****************************************************************************/
7101 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7102 union spoolss_PortInfo **info_p,
7105 union spoolss_PortInfo *info = NULL;
7107 WERROR result = WERR_OK;
7108 char **qlines = NULL;
7111 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7112 if (!W_ERROR_IS_OK(result)) {
7117 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7119 DEBUG(10,("Returning WERR_NOMEM\n"));
7120 result = WERR_NOMEM;
7124 for (i=0; i<numlines; i++) {
7125 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7126 result = fill_port_2(info, &info[i].info2, qlines[i]);
7127 if (!W_ERROR_IS_OK(result)) {
7132 TALLOC_FREE(qlines);
7135 if (!W_ERROR_IS_OK(result)) {
7137 TALLOC_FREE(qlines);
7149 /****************************************************************
7151 ****************************************************************/
7153 WERROR _spoolss_EnumPorts(pipes_struct *p,
7154 struct spoolss_EnumPorts *r)
7158 /* that's an [in out] buffer */
7160 if (!r->in.buffer && (r->in.offered != 0)) {
7161 return WERR_INVALID_PARAM;
7164 DEBUG(4,("_spoolss_EnumPorts\n"));
7168 *r->out.info = NULL;
7170 switch (r->in.level) {
7172 result = enumports_level_1(p->mem_ctx, r->out.info,
7176 result = enumports_level_2(p->mem_ctx, r->out.info,
7180 return WERR_UNKNOWN_LEVEL;
7183 if (!W_ERROR_IS_OK(result)) {
7187 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7189 *r->out.info, r->in.level,
7191 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7192 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7194 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7197 /****************************************************************************
7198 ****************************************************************************/
7200 static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
7202 struct spoolss_SetPrinterInfoCtr *info_ctr,
7203 struct spoolss_DeviceMode *devmode,
7204 struct security_descriptor *secdesc,
7205 struct spoolss_UserLevelCtr *user_ctr,
7206 struct policy_handle *handle)
7208 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7209 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7211 WERROR err = WERR_OK;
7213 /* samba does not have a concept of local, non-shared printers yet, so
7214 * make sure we always setup sharename - gd */
7215 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7216 (info2->printername != NULL && info2->printername[0] != '\0')) {
7217 DEBUG(5, ("spoolss_addprinterex_level_2: "
7218 "no sharename has been set, setting printername %s as sharename\n",
7219 info2->printername));
7220 info2->sharename = info2->printername;
7223 /* check to see if the printer already exists */
7224 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7225 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7227 return WERR_PRINTER_ALREADY_EXISTS;
7230 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7231 if ((snum = print_queue_snum(info2->printername)) != -1) {
7232 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7233 info2->printername));
7234 return WERR_PRINTER_ALREADY_EXISTS;
7238 /* validate printer info struct */
7239 if (!info2->printername || strlen(info2->printername) == 0) {
7240 return WERR_INVALID_PRINTER_NAME;
7242 if (!info2->portname || strlen(info2->portname) == 0) {
7243 return WERR_UNKNOWN_PORT;
7245 if (!info2->drivername || strlen(info2->drivername) == 0) {
7246 return WERR_UNKNOWN_PRINTER_DRIVER;
7248 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7249 return WERR_UNKNOWN_PRINTPROCESSOR;
7252 /* FIXME!!! smbd should check to see if the driver is installed before
7253 trying to add a printer like this --jerry */
7255 if (*lp_addprinter_cmd() ) {
7256 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7257 info2, p->client_address) ) {
7258 return WERR_ACCESS_DENIED;
7261 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7262 "smb.conf parameter \"addprinter command\" is defined. This"
7263 "parameter must exist for this call to succeed\n",
7264 info2->sharename ));
7267 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7268 return WERR_ACCESS_DENIED;
7271 /* you must be a printer admin to add a new printer */
7272 if (!print_access_check(p->server_info, snum, PRINTER_ACCESS_ADMINISTER)) {
7273 return WERR_ACCESS_DENIED;
7277 * Do sanity check on the requested changes for Samba.
7280 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7281 return WERR_INVALID_PARAM;
7284 if (devmode == NULL) {
7285 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7288 update_dsspooler(p->mem_ctx,
7294 err = winreg_update_printer(p->mem_ctx,
7301 if (!W_ERROR_IS_OK(err)) {
7305 if (!open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER)) {
7306 /* Handle open failed - remove addition. */
7307 ZERO_STRUCTP(handle);
7308 return WERR_ACCESS_DENIED;
7314 /****************************************************************
7315 _spoolss_AddPrinterEx
7316 ****************************************************************/
7318 WERROR _spoolss_AddPrinterEx(pipes_struct *p,
7319 struct spoolss_AddPrinterEx *r)
7321 switch (r->in.info_ctr->level) {
7323 /* we don't handle yet */
7324 /* but I know what to do ... */
7325 return WERR_UNKNOWN_LEVEL;
7327 return spoolss_addprinterex_level_2(p, r->in.server,
7329 r->in.devmode_ctr->devmode,
7330 r->in.secdesc_ctr->sd,
7331 r->in.userlevel_ctr,
7334 return WERR_UNKNOWN_LEVEL;
7338 /****************************************************************
7340 ****************************************************************/
7342 WERROR _spoolss_AddPrinter(pipes_struct *p,
7343 struct spoolss_AddPrinter *r)
7345 struct spoolss_AddPrinterEx a;
7346 struct spoolss_UserLevelCtr userlevel_ctr;
7348 ZERO_STRUCT(userlevel_ctr);
7350 userlevel_ctr.level = 1;
7352 a.in.server = r->in.server;
7353 a.in.info_ctr = r->in.info_ctr;
7354 a.in.devmode_ctr = r->in.devmode_ctr;
7355 a.in.secdesc_ctr = r->in.secdesc_ctr;
7356 a.in.userlevel_ctr = &userlevel_ctr;
7357 a.out.handle = r->out.handle;
7359 return _spoolss_AddPrinterEx(p, &a);
7362 /****************************************************************
7363 _spoolss_AddPrinterDriverEx
7364 ****************************************************************/
7366 WERROR _spoolss_AddPrinterDriverEx(pipes_struct *p,
7367 struct spoolss_AddPrinterDriverEx *r)
7369 WERROR err = WERR_OK;
7370 const char *driver_name = NULL;
7375 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7376 fn = "_spoolss_AddPrinterDriver";
7378 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7379 fn = "_spoolss_AddPrinterDriverEx";
7382 return WERR_INVALID_PARAM;
7386 * we only support the semantics of AddPrinterDriver()
7387 * i.e. only copy files that are newer than existing ones
7390 if (r->in.flags == 0) {
7391 return WERR_INVALID_PARAM;
7394 if (r->in.flags != APD_COPY_NEW_FILES) {
7395 return WERR_ACCESS_DENIED;
7399 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7400 /* Clever hack from Martin Zielinski <mz@seh.de>
7401 * to allow downgrade from level 8 (Vista).
7403 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7404 r->in.info_ctr->level));
7405 return WERR_UNKNOWN_LEVEL;
7408 DEBUG(5,("Cleaning driver's information\n"));
7409 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
7410 if (!W_ERROR_IS_OK(err))
7413 DEBUG(5,("Moving driver to final destination\n"));
7414 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7419 err = winreg_add_driver(p->mem_ctx, p->server_info,
7420 r->in.info_ctr, &driver_name, &version);
7421 if (!W_ERROR_IS_OK(err)) {
7426 * I think this is where he DrvUpgradePrinter() hook would be
7427 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7428 * server. Right now, we just need to send ourselves a message
7429 * to update each printer bound to this driver. --jerry
7432 if (!srv_spoolss_drv_upgrade_printer(driver_name)) {
7433 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7441 /****************************************************************
7442 _spoolss_AddPrinterDriver
7443 ****************************************************************/
7445 WERROR _spoolss_AddPrinterDriver(pipes_struct *p,
7446 struct spoolss_AddPrinterDriver *r)
7448 struct spoolss_AddPrinterDriverEx a;
7450 switch (r->in.info_ctr->level) {
7457 return WERR_UNKNOWN_LEVEL;
7460 a.in.servername = r->in.servername;
7461 a.in.info_ctr = r->in.info_ctr;
7462 a.in.flags = APD_COPY_NEW_FILES;
7464 return _spoolss_AddPrinterDriverEx(p, &a);
7467 /****************************************************************************
7468 ****************************************************************************/
7470 struct _spoolss_paths {
7476 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7478 static const struct _spoolss_paths spoolss_paths[]= {
7479 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7480 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7483 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7484 const char *servername,
7485 const char *environment,
7489 const char *pservername = NULL;
7490 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7491 const char *short_archi;
7495 /* environment may be empty */
7496 if (environment && strlen(environment)) {
7497 long_archi = environment;
7500 /* servername may be empty */
7501 if (servername && strlen(servername)) {
7502 pservername = canon_servername(servername);
7504 if (!is_myname_or_ipaddr(pservername)) {
7505 return WERR_INVALID_PARAM;
7509 if (!(short_archi = get_short_archi(long_archi))) {
7510 return WERR_INVALID_ENVIRONMENT;
7513 switch (component) {
7514 case SPOOLSS_PRTPROCS_PATH:
7515 case SPOOLSS_DRIVER_PATH:
7517 *path = talloc_asprintf(mem_ctx,
7520 spoolss_paths[component].share,
7523 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7524 SPOOLSS_DEFAULT_SERVER_PATH,
7525 spoolss_paths[component].dir,
7530 return WERR_INVALID_PARAM;
7540 /****************************************************************************
7541 ****************************************************************************/
7543 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7544 const char *servername,
7545 const char *environment,
7546 struct spoolss_DriverDirectoryInfo1 *r)
7551 werr = compose_spoolss_server_path(mem_ctx,
7554 SPOOLSS_DRIVER_PATH,
7556 if (!W_ERROR_IS_OK(werr)) {
7560 DEBUG(4,("printer driver directory: [%s]\n", path));
7562 r->directory_name = path;
7567 /****************************************************************
7568 _spoolss_GetPrinterDriverDirectory
7569 ****************************************************************/
7571 WERROR _spoolss_GetPrinterDriverDirectory(pipes_struct *p,
7572 struct spoolss_GetPrinterDriverDirectory *r)
7576 /* that's an [in out] buffer */
7578 if (!r->in.buffer && (r->in.offered != 0)) {
7579 return WERR_INVALID_PARAM;
7582 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
7587 /* r->in.level is ignored */
7589 werror = getprinterdriverdir_level_1(p->mem_ctx,
7592 &r->out.info->info1);
7593 if (!W_ERROR_IS_OK(werror)) {
7594 TALLOC_FREE(r->out.info);
7598 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
7599 r->out.info, r->in.level);
7600 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7602 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7605 /****************************************************************
7606 _spoolss_EnumPrinterData
7607 ****************************************************************/
7609 WERROR _spoolss_EnumPrinterData(pipes_struct *p,
7610 struct spoolss_EnumPrinterData *r)
7613 struct spoolss_EnumPrinterDataEx r2;
7615 struct spoolss_PrinterEnumValues *info, *val = NULL;
7618 r2.in.handle = r->in.handle;
7619 r2.in.key_name = "PrinterDriverData";
7621 r2.out.count = &count;
7622 r2.out.info = &info;
7623 r2.out.needed = &needed;
7625 result = _spoolss_EnumPrinterDataEx(p, &r2);
7626 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
7627 r2.in.offered = needed;
7628 result = _spoolss_EnumPrinterDataEx(p, &r2);
7630 if (!W_ERROR_IS_OK(result)) {
7635 * The NT machine wants to know the biggest size of value and data
7637 * cf: MSDN EnumPrinterData remark section
7640 if (!r->in.value_offered && !r->in.data_offered) {
7641 uint32_t biggest_valuesize = 0;
7642 uint32_t biggest_datasize = 0;
7645 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
7647 for (i=0; i<count; i++) {
7649 name_length = strlen(info[i].value_name);
7650 if (strlen(info[i].value_name) > biggest_valuesize) {
7651 biggest_valuesize = name_length;
7654 if (info[i].data_length > biggest_datasize) {
7655 biggest_datasize = info[i].data_length;
7658 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
7662 /* the value is an UNICODE string but real_value_size is the length
7663 in bytes including the trailing 0 */
7665 *r->out.value_needed = 2 * (1 + biggest_valuesize);
7666 *r->out.data_needed = biggest_datasize;
7668 DEBUG(6,("final values: [%d], [%d]\n",
7669 *r->out.value_needed, *r->out.data_needed));
7674 if (r->in.enum_index < count) {
7675 val = &info[r->in.enum_index];
7679 /* out_value should default to "" or else NT4 has
7680 problems unmarshalling the response */
7682 if (r->in.value_offered) {
7683 *r->out.value_needed = 1;
7684 r->out.value_name = talloc_strdup(r, "");
7685 if (!r->out.value_name) {
7689 r->out.value_name = NULL;
7690 *r->out.value_needed = 0;
7693 /* the data is counted in bytes */
7695 *r->out.data_needed = r->in.data_offered;
7697 result = WERR_NO_MORE_ITEMS;
7701 * - counted in bytes in the request
7702 * - counted in UNICODE chars in the max reply
7703 * - counted in bytes in the real size
7705 * take a pause *before* coding not *during* coding
7709 if (r->in.value_offered) {
7710 r->out.value_name = talloc_strdup(r, val->value_name);
7711 if (!r->out.value_name) {
7714 *r->out.value_needed = val->value_name_len;
7716 r->out.value_name = NULL;
7717 *r->out.value_needed = 0;
7722 *r->out.type = val->type;
7724 /* data - counted in bytes */
7727 * See the section "Dynamically Typed Query Parameters"
7731 if (r->out.data && val->data && val->data->data &&
7732 val->data_length && r->in.data_offered) {
7733 memcpy(r->out.data, val->data->data,
7734 MIN(val->data_length,r->in.data_offered));
7737 *r->out.data_needed = val->data_length;
7745 /****************************************************************
7746 _spoolss_SetPrinterData
7747 ****************************************************************/
7749 WERROR _spoolss_SetPrinterData(pipes_struct *p,
7750 struct spoolss_SetPrinterData *r)
7752 struct spoolss_SetPrinterDataEx r2;
7754 r2.in.handle = r->in.handle;
7755 r2.in.key_name = "PrinterDriverData";
7756 r2.in.value_name = r->in.value_name;
7757 r2.in.type = r->in.type;
7758 r2.in.data = r->in.data;
7759 r2.in.offered = r->in.offered;
7761 return _spoolss_SetPrinterDataEx(p, &r2);
7764 /****************************************************************
7765 _spoolss_ResetPrinter
7766 ****************************************************************/
7768 WERROR _spoolss_ResetPrinter(pipes_struct *p,
7769 struct spoolss_ResetPrinter *r)
7771 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7774 DEBUG(5,("_spoolss_ResetPrinter\n"));
7777 * All we do is to check to see if the handle and queue is valid.
7778 * This call really doesn't mean anything to us because we only
7779 * support RAW printing. --jerry
7783 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
7784 OUR_HANDLE(r->in.handle)));
7788 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
7792 /* blindly return success */
7796 /****************************************************************
7797 _spoolss_DeletePrinterData
7798 ****************************************************************/
7800 WERROR _spoolss_DeletePrinterData(pipes_struct *p,
7801 struct spoolss_DeletePrinterData *r)
7803 struct spoolss_DeletePrinterDataEx r2;
7805 r2.in.handle = r->in.handle;
7806 r2.in.key_name = "PrinterDriverData";
7807 r2.in.value_name = r->in.value_name;
7809 return _spoolss_DeletePrinterDataEx(p, &r2);
7812 /****************************************************************
7814 ****************************************************************/
7816 WERROR _spoolss_AddForm(pipes_struct *p,
7817 struct spoolss_AddForm *r)
7819 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
7821 WERROR status = WERR_OK;
7822 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7824 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7826 DEBUG(5,("_spoolss_AddForm\n"));
7829 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
7830 OUR_HANDLE(r->in.handle)));
7834 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
7835 and not a printer admin, then fail */
7837 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7838 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7839 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7840 p->server_info->info3->base.domain.string,
7842 p->server_info->ptok,
7843 lp_printer_admin(snum))) {
7844 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
7845 return WERR_ACCESS_DENIED;
7848 switch (form->flags) {
7849 case SPOOLSS_FORM_USER:
7850 case SPOOLSS_FORM_BUILTIN:
7851 case SPOOLSS_FORM_PRINTER:
7854 return WERR_INVALID_PARAM;
7857 status = winreg_printer_addform1(p->mem_ctx, p->server_info, form);
7858 if (!W_ERROR_IS_OK(status)) {
7863 * ChangeID must always be set if this is a printer
7865 if (Printer->printer_type == SPLHND_PRINTER) {
7866 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7870 status = winreg_printer_update_changeid(p->mem_ctx,
7872 lp_const_servicename(snum));
7873 if (!W_ERROR_IS_OK(status)) {
7881 /****************************************************************
7883 ****************************************************************/
7885 WERROR _spoolss_DeleteForm(pipes_struct *p,
7886 struct spoolss_DeleteForm *r)
7888 const char *form_name = r->in.form_name;
7889 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7891 WERROR status = WERR_OK;
7892 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7894 DEBUG(5,("_spoolss_DeleteForm\n"));
7897 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
7898 OUR_HANDLE(r->in.handle)));
7902 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7903 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7904 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7905 p->server_info->info3->base.domain.string,
7907 p->server_info->ptok,
7908 lp_printer_admin(snum))) {
7909 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
7910 return WERR_ACCESS_DENIED;
7913 status = winreg_printer_deleteform1(p->mem_ctx,
7916 if (!W_ERROR_IS_OK(status)) {
7921 * ChangeID must always be set if this is a printer
7923 if (Printer->printer_type == SPLHND_PRINTER) {
7924 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7928 status = winreg_printer_update_changeid(p->mem_ctx,
7930 lp_const_servicename(snum));
7931 if (!W_ERROR_IS_OK(status)) {
7939 /****************************************************************
7941 ****************************************************************/
7943 WERROR _spoolss_SetForm(pipes_struct *p,
7944 struct spoolss_SetForm *r)
7946 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
7947 const char *form_name = r->in.form_name;
7949 WERROR status = WERR_OK;
7950 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7952 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7954 DEBUG(5,("_spoolss_SetForm\n"));
7957 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
7958 OUR_HANDLE(r->in.handle)));
7962 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
7963 and not a printer admin, then fail */
7965 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7966 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7967 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7968 p->server_info->info3->base.domain.string,
7970 p->server_info->ptok,
7971 lp_printer_admin(snum))) {
7972 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
7973 return WERR_ACCESS_DENIED;
7976 status = winreg_printer_setform1(p->mem_ctx,
7980 if (!W_ERROR_IS_OK(status)) {
7985 * ChangeID must always be set if this is a printer
7987 if (Printer->printer_type == SPLHND_PRINTER) {
7988 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7992 status = winreg_printer_update_changeid(p->mem_ctx,
7994 lp_const_servicename(snum));
7995 if (!W_ERROR_IS_OK(status)) {
8003 /****************************************************************************
8004 fill_print_processor1
8005 ****************************************************************************/
8007 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8008 struct spoolss_PrintProcessorInfo1 *r,
8009 const char *print_processor_name)
8011 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8012 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8017 /****************************************************************************
8018 enumprintprocessors level 1.
8019 ****************************************************************************/
8021 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8022 union spoolss_PrintProcessorInfo **info_p,
8025 union spoolss_PrintProcessorInfo *info;
8028 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8029 W_ERROR_HAVE_NO_MEMORY(info);
8033 result = fill_print_processor1(info, &info[0].info1, "winprint");
8034 if (!W_ERROR_IS_OK(result)) {
8039 if (!W_ERROR_IS_OK(result)) {
8050 /****************************************************************
8051 _spoolss_EnumPrintProcessors
8052 ****************************************************************/
8054 WERROR _spoolss_EnumPrintProcessors(pipes_struct *p,
8055 struct spoolss_EnumPrintProcessors *r)
8059 /* that's an [in out] buffer */
8061 if (!r->in.buffer && (r->in.offered != 0)) {
8062 return WERR_INVALID_PARAM;
8065 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8068 * Enumerate the print processors ...
8070 * Just reply with "winprint", to keep NT happy
8071 * and I can use my nice printer checker.
8076 *r->out.info = NULL;
8078 switch (r->in.level) {
8080 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8084 return WERR_UNKNOWN_LEVEL;
8087 if (!W_ERROR_IS_OK(result)) {
8091 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8092 spoolss_EnumPrintProcessors,
8093 *r->out.info, r->in.level,
8095 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8096 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8098 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8101 /****************************************************************************
8102 fill_printprocdatatype1
8103 ****************************************************************************/
8105 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8106 struct spoolss_PrintProcDataTypesInfo1 *r,
8107 const char *name_array)
8109 r->name_array = talloc_strdup(mem_ctx, name_array);
8110 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8115 /****************************************************************************
8116 enumprintprocdatatypes level 1.
8117 ****************************************************************************/
8119 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8120 union spoolss_PrintProcDataTypesInfo **info_p,
8124 union spoolss_PrintProcDataTypesInfo *info;
8126 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8127 W_ERROR_HAVE_NO_MEMORY(info);
8131 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8132 if (!W_ERROR_IS_OK(result)) {
8137 if (!W_ERROR_IS_OK(result)) {
8148 /****************************************************************
8149 _spoolss_EnumPrintProcDataTypes
8150 ****************************************************************/
8152 WERROR _spoolss_EnumPrintProcDataTypes(pipes_struct *p,
8153 struct spoolss_EnumPrintProcDataTypes *r)
8157 /* that's an [in out] buffer */
8159 if (!r->in.buffer && (r->in.offered != 0)) {
8160 return WERR_INVALID_PARAM;
8163 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8167 *r->out.info = NULL;
8169 switch (r->in.level) {
8171 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8175 return WERR_UNKNOWN_LEVEL;
8178 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8179 spoolss_EnumPrintProcDataTypes,
8180 *r->out.info, r->in.level,
8182 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8183 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8185 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8188 /****************************************************************************
8190 ****************************************************************************/
8192 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8193 struct spoolss_MonitorInfo1 *r,
8194 const char *monitor_name)
8196 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8197 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8202 /****************************************************************************
8204 ****************************************************************************/
8206 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8207 struct spoolss_MonitorInfo2 *r,
8208 const char *monitor_name,
8209 const char *environment,
8210 const char *dll_name)
8212 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8213 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8214 r->environment = talloc_strdup(mem_ctx, environment);
8215 W_ERROR_HAVE_NO_MEMORY(r->environment);
8216 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8217 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8222 /****************************************************************************
8223 enumprintmonitors level 1.
8224 ****************************************************************************/
8226 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8227 union spoolss_MonitorInfo **info_p,
8230 union spoolss_MonitorInfo *info;
8231 WERROR result = WERR_OK;
8233 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8234 W_ERROR_HAVE_NO_MEMORY(info);
8238 result = fill_monitor_1(info, &info[0].info1,
8240 if (!W_ERROR_IS_OK(result)) {
8244 result = fill_monitor_1(info, &info[1].info1,
8246 if (!W_ERROR_IS_OK(result)) {
8251 if (!W_ERROR_IS_OK(result)) {
8262 /****************************************************************************
8263 enumprintmonitors level 2.
8264 ****************************************************************************/
8266 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8267 union spoolss_MonitorInfo **info_p,
8270 union spoolss_MonitorInfo *info;
8271 WERROR result = WERR_OK;
8273 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8274 W_ERROR_HAVE_NO_MEMORY(info);
8278 result = fill_monitor_2(info, &info[0].info2,
8280 "Windows NT X86", /* FIXME */
8282 if (!W_ERROR_IS_OK(result)) {
8286 result = fill_monitor_2(info, &info[1].info2,
8288 "Windows NT X86", /* FIXME */
8290 if (!W_ERROR_IS_OK(result)) {
8295 if (!W_ERROR_IS_OK(result)) {
8306 /****************************************************************
8307 _spoolss_EnumMonitors
8308 ****************************************************************/
8310 WERROR _spoolss_EnumMonitors(pipes_struct *p,
8311 struct spoolss_EnumMonitors *r)
8315 /* that's an [in out] buffer */
8317 if (!r->in.buffer && (r->in.offered != 0)) {
8318 return WERR_INVALID_PARAM;
8321 DEBUG(5,("_spoolss_EnumMonitors\n"));
8324 * Enumerate the print monitors ...
8326 * Just reply with "Local Port", to keep NT happy
8327 * and I can use my nice printer checker.
8332 *r->out.info = NULL;
8334 switch (r->in.level) {
8336 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8340 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8344 return WERR_UNKNOWN_LEVEL;
8347 if (!W_ERROR_IS_OK(result)) {
8351 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8352 spoolss_EnumMonitors,
8353 *r->out.info, r->in.level,
8355 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8356 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8358 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8361 /****************************************************************************
8362 ****************************************************************************/
8364 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8365 const print_queue_struct *queue,
8366 int count, int snum,
8367 struct spoolss_PrinterInfo2 *pinfo2,
8369 struct spoolss_JobInfo1 *r)
8374 for (i=0; i<count; i++) {
8375 if (queue[i].job == (int)jobid) {
8381 if (found == false) {
8382 /* NT treats not found as bad param... yet another bad choice */
8383 return WERR_INVALID_PARAM;
8386 return fill_job_info1(mem_ctx,
8394 /****************************************************************************
8395 ****************************************************************************/
8397 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8398 const print_queue_struct *queue,
8399 int count, int snum,
8400 struct spoolss_PrinterInfo2 *pinfo2,
8402 struct spoolss_JobInfo2 *r)
8406 struct spoolss_DeviceMode *devmode;
8409 for (i=0; i<count; i++) {
8410 if (queue[i].job == (int)jobid) {
8416 if (found == false) {
8417 /* NT treats not found as bad param... yet another bad
8419 return WERR_INVALID_PARAM;
8423 * if the print job does not have a DEVMODE associated with it,
8424 * just use the one for the printer. A NULL devicemode is not
8425 * a failure condition
8428 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8430 result = spoolss_create_default_devmode(mem_ctx,
8431 pinfo2->printername,
8433 if (!W_ERROR_IS_OK(result)) {
8434 DEBUG(3, ("Can't proceed w/o a devmode!"));
8439 return fill_job_info2(mem_ctx,
8448 /****************************************************************
8450 ****************************************************************/
8452 WERROR _spoolss_GetJob(pipes_struct *p,
8453 struct spoolss_GetJob *r)
8455 WERROR result = WERR_OK;
8456 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8459 print_queue_struct *queue = NULL;
8460 print_status_struct prt_status;
8462 /* that's an [in out] buffer */
8464 if (!r->in.buffer && (r->in.offered != 0)) {
8465 return WERR_INVALID_PARAM;
8468 DEBUG(5,("_spoolss_GetJob\n"));
8472 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8476 result = winreg_get_printer(p->mem_ctx, p->server_info, NULL,
8477 lp_servicename(snum), &pinfo2);
8478 if (!W_ERROR_IS_OK(result)) {
8482 count = print_queue_status(snum, &queue, &prt_status);
8484 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8485 count, prt_status.status, prt_status.message));
8487 switch (r->in.level) {
8489 result = getjob_level_1(p->mem_ctx,
8490 queue, count, snum, pinfo2,
8491 r->in.job_id, &r->out.info->info1);
8494 result = getjob_level_2(p->mem_ctx,
8495 queue, count, snum, pinfo2,
8496 r->in.job_id, &r->out.info->info2);
8499 result = WERR_UNKNOWN_LEVEL;
8504 TALLOC_FREE(pinfo2);
8506 if (!W_ERROR_IS_OK(result)) {
8507 TALLOC_FREE(r->out.info);
8511 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
8513 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8515 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8518 /****************************************************************
8519 _spoolss_GetPrinterDataEx
8520 ****************************************************************/
8522 WERROR _spoolss_GetPrinterDataEx(pipes_struct *p,
8523 struct spoolss_GetPrinterDataEx *r)
8526 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8527 const char *printer;
8529 WERROR result = WERR_OK;
8531 enum winreg_Type val_type;
8536 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8538 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8539 r->in.key_name, r->in.value_name));
8541 /* in case of problem, return some default values */
8544 *r->out.type = REG_NONE;
8547 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8548 OUR_HANDLE(r->in.handle)));
8549 result = WERR_BADFID;
8553 /* Is the handle to a printer or to the server? */
8555 if (Printer->printer_type == SPLHND_SERVER) {
8557 union spoolss_PrinterData data;
8559 result = getprinterdata_printer_server(p->mem_ctx,
8563 if (!W_ERROR_IS_OK(result)) {
8567 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
8568 *r->out.type, &data);
8569 if (!W_ERROR_IS_OK(result)) {
8573 *r->out.needed = blob.length;
8575 if (r->in.offered >= *r->out.needed) {
8576 memcpy(r->out.data, blob.data, blob.length);
8579 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8582 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8585 printer = lp_const_servicename(snum);
8587 /* check to see if the keyname is valid */
8588 if (!strlen(r->in.key_name)) {
8589 return WERR_INVALID_PARAM;
8592 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
8593 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
8594 strequal(r->in.value_name, "ChangeId")) {
8595 *r->out.type = REG_DWORD;
8597 if (r->in.offered >= *r->out.needed) {
8598 uint32_t changeid = 0;
8600 result = winreg_printer_get_changeid(p->mem_ctx,
8604 if (!W_ERROR_IS_OK(result)) {
8608 SIVAL(r->out.data, 0, changeid);
8614 result = winreg_get_printer_dataex(p->mem_ctx,
8622 if (!W_ERROR_IS_OK(result)) {
8626 *r->out.needed = val_size;
8627 *r->out.type = val_type;
8629 if (r->in.offered >= *r->out.needed) {
8630 memcpy(r->out.data, val_data, val_size);
8634 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
8635 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
8637 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8640 /****************************************************************
8641 _spoolss_SetPrinterDataEx
8642 ****************************************************************/
8644 WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
8645 struct spoolss_SetPrinterDataEx *r)
8647 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
8649 WERROR result = WERR_OK;
8650 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8653 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
8655 /* From MSDN documentation of SetPrinterDataEx: pass request to
8656 SetPrinterData if key is "PrinterDriverData" */
8659 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8660 OUR_HANDLE(r->in.handle)));
8664 if (Printer->printer_type == SPLHND_SERVER) {
8665 DEBUG(10,("_spoolss_SetPrinterDataEx: "
8666 "Not implemented for server handles yet\n"));
8667 return WERR_INVALID_PARAM;
8670 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8675 * Access check : NT returns "access denied" if you make a
8676 * SetPrinterData call without the necessary privildge.
8677 * we were originally returning OK if nothing changed
8678 * which made Win2k issue **a lot** of SetPrinterData
8679 * when connecting to a printer --jerry
8682 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8683 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
8684 "change denied by handle access permissions\n"));
8685 return WERR_ACCESS_DENIED;
8688 result = winreg_get_printer(Printer, p->server_info,
8689 Printer->servername,
8690 lp_servicename(snum),
8692 if (!W_ERROR_IS_OK(result)) {
8696 /* check for OID in valuename */
8698 oid_string = strchr(r->in.value_name, ',');
8704 /* save the registry data */
8706 result = winreg_set_printer_dataex(p->mem_ctx,
8715 if (W_ERROR_IS_OK(result)) {
8716 /* save the OID if one was specified */
8718 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
8719 r->in.key_name, SPOOL_OID_KEY);
8721 result = WERR_NOMEM;
8726 * I'm not checking the status here on purpose. Don't know
8727 * if this is right, but I'm returning the status from the
8728 * previous set_printer_dataex() call. I have no idea if
8729 * this is right. --jerry
8731 winreg_set_printer_dataex(p->mem_ctx,
8737 (uint8_t *) oid_string,
8738 strlen(oid_string) + 1);
8741 result = winreg_printer_update_changeid(p->mem_ctx,
8743 lp_const_servicename(snum));
8748 talloc_free(pinfo2);
8752 /****************************************************************
8753 _spoolss_DeletePrinterDataEx
8754 ****************************************************************/
8756 WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
8757 struct spoolss_DeletePrinterDataEx *r)
8759 const char *printer;
8761 WERROR status = WERR_OK;
8762 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8764 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
8767 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
8768 "Invalid handle (%s:%u:%u).\n",
8769 OUR_HANDLE(r->in.handle)));
8773 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8774 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
8775 "printer properties change denied by handle\n"));
8776 return WERR_ACCESS_DENIED;
8779 if (!r->in.value_name || !r->in.key_name) {
8783 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8786 printer = lp_const_servicename(snum);
8788 status = winreg_delete_printer_dataex(p->mem_ctx,
8793 if (W_ERROR_IS_OK(status)) {
8794 status = winreg_printer_update_changeid(p->mem_ctx,
8802 /****************************************************************
8803 _spoolss_EnumPrinterKey
8804 ****************************************************************/
8806 WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
8807 struct spoolss_EnumPrinterKey *r)
8810 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8812 WERROR result = WERR_BADFILE;
8813 const char **array = NULL;
8816 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
8819 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
8820 OUR_HANDLE(r->in.handle)));
8824 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8828 result = winreg_enum_printer_key(p->mem_ctx,
8830 lp_const_servicename(snum),
8834 if (!W_ERROR_IS_OK(result)) {
8838 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
8839 result = WERR_NOMEM;
8843 *r->out._ndr_size = r->in.offered / 2;
8844 *r->out.needed = blob.length;
8846 if (r->in.offered < *r->out.needed) {
8847 result = WERR_MORE_DATA;
8850 r->out.key_buffer->string_array = array;
8854 if (!W_ERROR_IS_OK(result)) {
8856 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8864 /****************************************************************
8865 _spoolss_DeletePrinterKey
8866 ****************************************************************/
8868 WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
8869 struct spoolss_DeletePrinterKey *r)
8871 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8874 const char *printer;
8876 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
8879 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
8880 OUR_HANDLE(r->in.handle)));
8884 /* if keyname == NULL, return error */
8885 if ( !r->in.key_name )
8886 return WERR_INVALID_PARAM;
8888 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8892 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8893 DEBUG(3, ("_spoolss_DeletePrinterKey: "
8894 "printer properties change denied by handle\n"));
8895 return WERR_ACCESS_DENIED;
8898 printer = lp_const_servicename(snum);
8900 /* delete the key and all subkeys */
8901 status = winreg_delete_printer_key(p->mem_ctx,
8905 if (W_ERROR_IS_OK(status)) {
8906 status = winreg_printer_update_changeid(p->mem_ctx,
8914 /****************************************************************
8915 _spoolss_EnumPrinterDataEx
8916 ****************************************************************/
8918 WERROR _spoolss_EnumPrinterDataEx(pipes_struct *p,
8919 struct spoolss_EnumPrinterDataEx *r)
8922 struct spoolss_PrinterEnumValues *info = NULL;
8923 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8927 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
8931 *r->out.info = NULL;
8934 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
8935 OUR_HANDLE(r->in.handle)));
8940 * first check for a keyname of NULL or "". Win2k seems to send
8941 * this a lot and we should send back WERR_INVALID_PARAM
8942 * no need to spend time looking up the printer in this case.
8946 if (!strlen(r->in.key_name)) {
8947 result = WERR_INVALID_PARAM;
8951 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8955 /* now look for a match on the key name */
8956 result = winreg_enum_printer_dataex(p->mem_ctx,
8958 lp_const_servicename(snum),
8962 if (!W_ERROR_IS_OK(result)) {
8966 #if 0 /* FIXME - gd */
8967 /* housekeeping information in the reply */
8969 /* Fix from Martin Zielinski <mz@seh.de> - ensure
8970 * the hand marshalled container size is a multiple
8971 * of 4 bytes for RPC alignment.
8975 needed += 4-(needed % 4);
8978 *r->out.count = count;
8979 *r->out.info = info;
8982 if (!W_ERROR_IS_OK(result)) {
8986 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
8987 spoolss_EnumPrinterDataEx,
8990 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8991 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
8993 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8996 /****************************************************************************
8997 ****************************************************************************/
8999 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9000 const char *servername,
9001 const char *environment,
9002 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9007 werr = compose_spoolss_server_path(mem_ctx,
9010 SPOOLSS_PRTPROCS_PATH,
9012 if (!W_ERROR_IS_OK(werr)) {
9016 DEBUG(4,("print processor directory: [%s]\n", path));
9018 r->directory_name = path;
9023 /****************************************************************
9024 _spoolss_GetPrintProcessorDirectory
9025 ****************************************************************/
9027 WERROR _spoolss_GetPrintProcessorDirectory(pipes_struct *p,
9028 struct spoolss_GetPrintProcessorDirectory *r)
9032 /* that's an [in out] buffer */
9034 if (!r->in.buffer && (r->in.offered != 0)) {
9035 return WERR_INVALID_PARAM;
9038 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9043 /* r->in.level is ignored */
9045 /* We always should reply with a local print processor directory so that
9046 * users are not forced to have a [prnproc$] share on the Samba spoolss
9047 * server - Guenther */
9049 result = getprintprocessordirectory_level_1(p->mem_ctx,
9050 NULL, /* r->in.server */
9052 &r->out.info->info1);
9053 if (!W_ERROR_IS_OK(result)) {
9054 TALLOC_FREE(r->out.info);
9058 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9059 r->out.info, r->in.level);
9060 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9062 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9065 /*******************************************************************
9066 ********************************************************************/
9068 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9069 const char *dllname)
9071 enum ndr_err_code ndr_err;
9072 struct spoolss_MonitorUi ui;
9074 ui.dll_name = dllname;
9076 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9077 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9078 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9079 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9081 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9084 /*******************************************************************
9085 Streams the monitor UI DLL name in UNICODE
9086 *******************************************************************/
9088 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9089 NT_USER_TOKEN *token, DATA_BLOB *in,
9090 DATA_BLOB *out, uint32_t *needed)
9092 const char *dllname = "tcpmonui.dll";
9094 *needed = (strlen(dllname)+1) * 2;
9096 if (out->length < *needed) {
9097 return WERR_INSUFFICIENT_BUFFER;
9100 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9107 /*******************************************************************
9108 ********************************************************************/
9110 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9111 struct spoolss_PortData1 *port1,
9112 const DATA_BLOB *buf)
9114 enum ndr_err_code ndr_err;
9115 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9116 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9117 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9118 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9120 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9123 /*******************************************************************
9124 ********************************************************************/
9126 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9127 struct spoolss_PortData2 *port2,
9128 const DATA_BLOB *buf)
9130 enum ndr_err_code ndr_err;
9131 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9132 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9133 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9134 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9136 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9139 /*******************************************************************
9140 Create a new TCP/IP port
9141 *******************************************************************/
9143 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9144 NT_USER_TOKEN *token, DATA_BLOB *in,
9145 DATA_BLOB *out, uint32_t *needed)
9147 struct spoolss_PortData1 port1;
9148 struct spoolss_PortData2 port2;
9149 char *device_uri = NULL;
9152 const char *portname;
9153 const char *hostaddress;
9155 uint32_t port_number;
9158 /* peek for spoolss_PortData version */
9160 if (!in || (in->length < (128 + 4))) {
9161 return WERR_GENERAL_FAILURE;
9164 version = IVAL(in->data, 128);
9170 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9174 portname = port1.portname;
9175 hostaddress = port1.hostaddress;
9176 queue = port1.queue;
9177 protocol = port1.protocol;
9178 port_number = port1.port_number;
9184 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9188 portname = port2.portname;
9189 hostaddress = port2.hostaddress;
9190 queue = port2.queue;
9191 protocol = port2.protocol;
9192 port_number = port2.port_number;
9196 DEBUG(1,("xcvtcp_addport: "
9197 "unknown version of port_data: %d\n", version));
9198 return WERR_UNKNOWN_PORT;
9201 /* create the device URI and call the add_port_hook() */
9204 case PROTOCOL_RAWTCP_TYPE:
9205 device_uri = talloc_asprintf(mem_ctx,
9206 "socket://%s:%d/", hostaddress,
9210 case PROTOCOL_LPR_TYPE:
9211 device_uri = talloc_asprintf(mem_ctx,
9212 "lpr://%s/%s", hostaddress, queue );
9216 return WERR_UNKNOWN_PORT;
9223 return add_port_hook(mem_ctx, token, portname, device_uri);
9226 /*******************************************************************
9227 *******************************************************************/
9229 struct xcv_api_table xcvtcp_cmds[] = {
9230 { "MonitorUI", xcvtcp_monitorui },
9231 { "AddPort", xcvtcp_addport},
9235 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9236 NT_USER_TOKEN *token, const char *command,
9243 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9245 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9246 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9247 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9250 return WERR_BADFUNC;
9253 /*******************************************************************
9254 *******************************************************************/
9255 #if 0 /* don't support management using the "Local Port" monitor */
9257 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9258 NT_USER_TOKEN *token, DATA_BLOB *in,
9259 DATA_BLOB *out, uint32_t *needed)
9261 const char *dllname = "localui.dll";
9263 *needed = (strlen(dllname)+1) * 2;
9265 if (out->length < *needed) {
9266 return WERR_INSUFFICIENT_BUFFER;
9269 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9276 /*******************************************************************
9277 *******************************************************************/
9279 struct xcv_api_table xcvlocal_cmds[] = {
9280 { "MonitorUI", xcvlocal_monitorui },
9284 struct xcv_api_table xcvlocal_cmds[] = {
9291 /*******************************************************************
9292 *******************************************************************/
9294 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9295 NT_USER_TOKEN *token, const char *command,
9296 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9301 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9303 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9304 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9305 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9307 return WERR_BADFUNC;
9310 /****************************************************************
9312 ****************************************************************/
9314 WERROR _spoolss_XcvData(pipes_struct *p,
9315 struct spoolss_XcvData *r)
9317 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9318 DATA_BLOB out_data = data_blob_null;
9322 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9323 OUR_HANDLE(r->in.handle)));
9327 /* Has to be a handle to the TCP/IP port monitor */
9329 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9330 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9334 /* requires administrative access to the server */
9336 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9337 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9338 return WERR_ACCESS_DENIED;
9341 /* Allocate the outgoing buffer */
9343 if (r->in.out_data_size) {
9344 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9345 if (out_data.data == NULL) {
9350 switch ( Printer->printer_type ) {
9351 case SPLHND_PORTMON_TCP:
9352 werror = process_xcvtcp_command(p->mem_ctx,
9353 p->server_info->ptok,
9354 r->in.function_name,
9355 &r->in.in_data, &out_data,
9358 case SPLHND_PORTMON_LOCAL:
9359 werror = process_xcvlocal_command(p->mem_ctx,
9360 p->server_info->ptok,
9361 r->in.function_name,
9362 &r->in.in_data, &out_data,
9366 werror = WERR_INVALID_PRINT_MONITOR;
9369 if (!W_ERROR_IS_OK(werror)) {
9373 *r->out.status_code = 0;
9375 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9376 memcpy(r->out.out_data, out_data.data,
9377 MIN(r->in.out_data_size, out_data.length));
9383 /****************************************************************
9384 _spoolss_AddPrintProcessor
9385 ****************************************************************/
9387 WERROR _spoolss_AddPrintProcessor(pipes_struct *p,
9388 struct spoolss_AddPrintProcessor *r)
9390 /* for now, just indicate success and ignore the add. We'll
9391 automatically set the winprint processor for printer
9392 entries later. Used to debug the LexMark Optra S 1855 PCL
9398 /****************************************************************
9400 ****************************************************************/
9402 WERROR _spoolss_AddPort(pipes_struct *p,
9403 struct spoolss_AddPort *r)
9405 /* do what w2k3 does */
9407 return WERR_NOT_SUPPORTED;
9410 /****************************************************************
9411 _spoolss_GetPrinterDriver
9412 ****************************************************************/
9414 WERROR _spoolss_GetPrinterDriver(pipes_struct *p,
9415 struct spoolss_GetPrinterDriver *r)
9417 p->rng_fault_state = true;
9418 return WERR_NOT_SUPPORTED;
9421 /****************************************************************
9422 _spoolss_ReadPrinter
9423 ****************************************************************/
9425 WERROR _spoolss_ReadPrinter(pipes_struct *p,
9426 struct spoolss_ReadPrinter *r)
9428 p->rng_fault_state = true;
9429 return WERR_NOT_SUPPORTED;
9432 /****************************************************************
9433 _spoolss_WaitForPrinterChange
9434 ****************************************************************/
9436 WERROR _spoolss_WaitForPrinterChange(pipes_struct *p,
9437 struct spoolss_WaitForPrinterChange *r)
9439 p->rng_fault_state = true;
9440 return WERR_NOT_SUPPORTED;
9443 /****************************************************************
9444 _spoolss_ConfigurePort
9445 ****************************************************************/
9447 WERROR _spoolss_ConfigurePort(pipes_struct *p,
9448 struct spoolss_ConfigurePort *r)
9450 p->rng_fault_state = true;
9451 return WERR_NOT_SUPPORTED;
9454 /****************************************************************
9456 ****************************************************************/
9458 WERROR _spoolss_DeletePort(pipes_struct *p,
9459 struct spoolss_DeletePort *r)
9461 p->rng_fault_state = true;
9462 return WERR_NOT_SUPPORTED;
9465 /****************************************************************
9466 _spoolss_CreatePrinterIC
9467 ****************************************************************/
9469 WERROR _spoolss_CreatePrinterIC(pipes_struct *p,
9470 struct spoolss_CreatePrinterIC *r)
9472 p->rng_fault_state = true;
9473 return WERR_NOT_SUPPORTED;
9476 /****************************************************************
9477 _spoolss_PlayGDIScriptOnPrinterIC
9478 ****************************************************************/
9480 WERROR _spoolss_PlayGDIScriptOnPrinterIC(pipes_struct *p,
9481 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9483 p->rng_fault_state = true;
9484 return WERR_NOT_SUPPORTED;
9487 /****************************************************************
9488 _spoolss_DeletePrinterIC
9489 ****************************************************************/
9491 WERROR _spoolss_DeletePrinterIC(pipes_struct *p,
9492 struct spoolss_DeletePrinterIC *r)
9494 p->rng_fault_state = true;
9495 return WERR_NOT_SUPPORTED;
9498 /****************************************************************
9499 _spoolss_AddPrinterConnection
9500 ****************************************************************/
9502 WERROR _spoolss_AddPrinterConnection(pipes_struct *p,
9503 struct spoolss_AddPrinterConnection *r)
9505 p->rng_fault_state = true;
9506 return WERR_NOT_SUPPORTED;
9509 /****************************************************************
9510 _spoolss_DeletePrinterConnection
9511 ****************************************************************/
9513 WERROR _spoolss_DeletePrinterConnection(pipes_struct *p,
9514 struct spoolss_DeletePrinterConnection *r)
9516 p->rng_fault_state = true;
9517 return WERR_NOT_SUPPORTED;
9520 /****************************************************************
9521 _spoolss_PrinterMessageBox
9522 ****************************************************************/
9524 WERROR _spoolss_PrinterMessageBox(pipes_struct *p,
9525 struct spoolss_PrinterMessageBox *r)
9527 p->rng_fault_state = true;
9528 return WERR_NOT_SUPPORTED;
9531 /****************************************************************
9533 ****************************************************************/
9535 WERROR _spoolss_AddMonitor(pipes_struct *p,
9536 struct spoolss_AddMonitor *r)
9538 p->rng_fault_state = true;
9539 return WERR_NOT_SUPPORTED;
9542 /****************************************************************
9543 _spoolss_DeleteMonitor
9544 ****************************************************************/
9546 WERROR _spoolss_DeleteMonitor(pipes_struct *p,
9547 struct spoolss_DeleteMonitor *r)
9549 p->rng_fault_state = true;
9550 return WERR_NOT_SUPPORTED;
9553 /****************************************************************
9554 _spoolss_DeletePrintProcessor
9555 ****************************************************************/
9557 WERROR _spoolss_DeletePrintProcessor(pipes_struct *p,
9558 struct spoolss_DeletePrintProcessor *r)
9560 p->rng_fault_state = true;
9561 return WERR_NOT_SUPPORTED;
9564 /****************************************************************
9565 _spoolss_AddPrintProvidor
9566 ****************************************************************/
9568 WERROR _spoolss_AddPrintProvidor(pipes_struct *p,
9569 struct spoolss_AddPrintProvidor *r)
9571 p->rng_fault_state = true;
9572 return WERR_NOT_SUPPORTED;
9575 /****************************************************************
9576 _spoolss_DeletePrintProvidor
9577 ****************************************************************/
9579 WERROR _spoolss_DeletePrintProvidor(pipes_struct *p,
9580 struct spoolss_DeletePrintProvidor *r)
9582 p->rng_fault_state = true;
9583 return WERR_NOT_SUPPORTED;
9586 /****************************************************************
9587 _spoolss_FindFirstPrinterChangeNotification
9588 ****************************************************************/
9590 WERROR _spoolss_FindFirstPrinterChangeNotification(pipes_struct *p,
9591 struct spoolss_FindFirstPrinterChangeNotification *r)
9593 p->rng_fault_state = true;
9594 return WERR_NOT_SUPPORTED;
9597 /****************************************************************
9598 _spoolss_FindNextPrinterChangeNotification
9599 ****************************************************************/
9601 WERROR _spoolss_FindNextPrinterChangeNotification(pipes_struct *p,
9602 struct spoolss_FindNextPrinterChangeNotification *r)
9604 p->rng_fault_state = true;
9605 return WERR_NOT_SUPPORTED;
9608 /****************************************************************
9609 _spoolss_RouterFindFirstPrinterChangeNotificationOld
9610 ****************************************************************/
9612 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(pipes_struct *p,
9613 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
9615 p->rng_fault_state = true;
9616 return WERR_NOT_SUPPORTED;
9619 /****************************************************************
9620 _spoolss_ReplyOpenPrinter
9621 ****************************************************************/
9623 WERROR _spoolss_ReplyOpenPrinter(pipes_struct *p,
9624 struct spoolss_ReplyOpenPrinter *r)
9626 p->rng_fault_state = true;
9627 return WERR_NOT_SUPPORTED;
9630 /****************************************************************
9631 _spoolss_RouterReplyPrinter
9632 ****************************************************************/
9634 WERROR _spoolss_RouterReplyPrinter(pipes_struct *p,
9635 struct spoolss_RouterReplyPrinter *r)
9637 p->rng_fault_state = true;
9638 return WERR_NOT_SUPPORTED;
9641 /****************************************************************
9642 _spoolss_ReplyClosePrinter
9643 ****************************************************************/
9645 WERROR _spoolss_ReplyClosePrinter(pipes_struct *p,
9646 struct spoolss_ReplyClosePrinter *r)
9648 p->rng_fault_state = true;
9649 return WERR_NOT_SUPPORTED;
9652 /****************************************************************
9654 ****************************************************************/
9656 WERROR _spoolss_AddPortEx(pipes_struct *p,
9657 struct spoolss_AddPortEx *r)
9659 p->rng_fault_state = true;
9660 return WERR_NOT_SUPPORTED;
9663 /****************************************************************
9664 _spoolss_RouterFindFirstPrinterChangeNotification
9665 ****************************************************************/
9667 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(pipes_struct *p,
9668 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
9670 p->rng_fault_state = true;
9671 return WERR_NOT_SUPPORTED;
9674 /****************************************************************
9675 _spoolss_SpoolerInit
9676 ****************************************************************/
9678 WERROR _spoolss_SpoolerInit(pipes_struct *p,
9679 struct spoolss_SpoolerInit *r)
9681 p->rng_fault_state = true;
9682 return WERR_NOT_SUPPORTED;
9685 /****************************************************************
9686 _spoolss_ResetPrinterEx
9687 ****************************************************************/
9689 WERROR _spoolss_ResetPrinterEx(pipes_struct *p,
9690 struct spoolss_ResetPrinterEx *r)
9692 p->rng_fault_state = true;
9693 return WERR_NOT_SUPPORTED;
9696 /****************************************************************
9697 _spoolss_RouterReplyPrinterEx
9698 ****************************************************************/
9700 WERROR _spoolss_RouterReplyPrinterEx(pipes_struct *p,
9701 struct spoolss_RouterReplyPrinterEx *r)
9703 p->rng_fault_state = true;
9704 return WERR_NOT_SUPPORTED;
9707 /****************************************************************
9709 ****************************************************************/
9711 WERROR _spoolss_44(pipes_struct *p,
9712 struct spoolss_44 *r)
9714 p->rng_fault_state = true;
9715 return WERR_NOT_SUPPORTED;
9718 /****************************************************************
9720 ****************************************************************/
9722 WERROR _spoolss_47(pipes_struct *p,
9723 struct spoolss_47 *r)
9725 p->rng_fault_state = true;
9726 return WERR_NOT_SUPPORTED;
9729 /****************************************************************
9731 ****************************************************************/
9733 WERROR _spoolss_4a(pipes_struct *p,
9734 struct spoolss_4a *r)
9736 p->rng_fault_state = true;
9737 return WERR_NOT_SUPPORTED;
9740 /****************************************************************
9742 ****************************************************************/
9744 WERROR _spoolss_4b(pipes_struct *p,
9745 struct spoolss_4b *r)
9747 p->rng_fault_state = true;
9748 return WERR_NOT_SUPPORTED;
9751 /****************************************************************
9753 ****************************************************************/
9755 WERROR _spoolss_4c(pipes_struct *p,
9756 struct spoolss_4c *r)
9758 p->rng_fault_state = true;
9759 return WERR_NOT_SUPPORTED;
9762 /****************************************************************
9764 ****************************************************************/
9766 WERROR _spoolss_53(pipes_struct *p,
9767 struct spoolss_53 *r)
9769 p->rng_fault_state = true;
9770 return WERR_NOT_SUPPORTED;
9773 /****************************************************************
9775 ****************************************************************/
9777 WERROR _spoolss_55(pipes_struct *p,
9778 struct spoolss_55 *r)
9780 p->rng_fault_state = true;
9781 return WERR_NOT_SUPPORTED;
9784 /****************************************************************
9786 ****************************************************************/
9788 WERROR _spoolss_56(pipes_struct *p,
9789 struct spoolss_56 *r)
9791 p->rng_fault_state = true;
9792 return WERR_NOT_SUPPORTED;
9795 /****************************************************************
9797 ****************************************************************/
9799 WERROR _spoolss_57(pipes_struct *p,
9800 struct spoolss_57 *r)
9802 p->rng_fault_state = true;
9803 return WERR_NOT_SUPPORTED;
9806 /****************************************************************
9808 ****************************************************************/
9810 WERROR _spoolss_5a(pipes_struct *p,
9811 struct spoolss_5a *r)
9813 p->rng_fault_state = true;
9814 return WERR_NOT_SUPPORTED;
9817 /****************************************************************
9819 ****************************************************************/
9821 WERROR _spoolss_5b(pipes_struct *p,
9822 struct spoolss_5b *r)
9824 p->rng_fault_state = true;
9825 return WERR_NOT_SUPPORTED;
9828 /****************************************************************
9830 ****************************************************************/
9832 WERROR _spoolss_5c(pipes_struct *p,
9833 struct spoolss_5c *r)
9835 p->rng_fault_state = true;
9836 return WERR_NOT_SUPPORTED;
9839 /****************************************************************
9841 ****************************************************************/
9843 WERROR _spoolss_5d(pipes_struct *p,
9844 struct spoolss_5d *r)
9846 p->rng_fault_state = true;
9847 return WERR_NOT_SUPPORTED;
9850 /****************************************************************
9852 ****************************************************************/
9854 WERROR _spoolss_5e(pipes_struct *p,
9855 struct spoolss_5e *r)
9857 p->rng_fault_state = true;
9858 return WERR_NOT_SUPPORTED;
9861 /****************************************************************
9863 ****************************************************************/
9865 WERROR _spoolss_5f(pipes_struct *p,
9866 struct spoolss_5f *r)
9868 p->rng_fault_state = true;
9869 return WERR_NOT_SUPPORTED;
9872 /****************************************************************
9874 ****************************************************************/
9876 WERROR _spoolss_60(pipes_struct *p,
9877 struct spoolss_60 *r)
9879 p->rng_fault_state = true;
9880 return WERR_NOT_SUPPORTED;
9883 /****************************************************************
9885 ****************************************************************/
9887 WERROR _spoolss_61(pipes_struct *p,
9888 struct spoolss_61 *r)
9890 p->rng_fault_state = true;
9891 return WERR_NOT_SUPPORTED;
9894 /****************************************************************
9896 ****************************************************************/
9898 WERROR _spoolss_62(pipes_struct *p,
9899 struct spoolss_62 *r)
9901 p->rng_fault_state = true;
9902 return WERR_NOT_SUPPORTED;
9905 /****************************************************************
9907 ****************************************************************/
9909 WERROR _spoolss_63(pipes_struct *p,
9910 struct spoolss_63 *r)
9912 p->rng_fault_state = true;
9913 return WERR_NOT_SUPPORTED;
9916 /****************************************************************
9918 ****************************************************************/
9920 WERROR _spoolss_64(pipes_struct *p,
9921 struct spoolss_64 *r)
9923 p->rng_fault_state = true;
9924 return WERR_NOT_SUPPORTED;
9927 /****************************************************************
9929 ****************************************************************/
9931 WERROR _spoolss_65(pipes_struct *p,
9932 struct spoolss_65 *r)
9934 p->rng_fault_state = true;
9935 return WERR_NOT_SUPPORTED;
9938 /****************************************************************
9939 _spoolss_GetCorePrinterDrivers
9940 ****************************************************************/
9942 WERROR _spoolss_GetCorePrinterDrivers(pipes_struct *p,
9943 struct spoolss_GetCorePrinterDrivers *r)
9945 p->rng_fault_state = true;
9946 return WERR_NOT_SUPPORTED;
9949 /****************************************************************
9951 ****************************************************************/
9953 WERROR _spoolss_67(pipes_struct *p,
9954 struct spoolss_67 *r)
9956 p->rng_fault_state = true;
9957 return WERR_NOT_SUPPORTED;
9960 /****************************************************************
9961 _spoolss_GetPrinterDriverPackagePath
9962 ****************************************************************/
9964 WERROR _spoolss_GetPrinterDriverPackagePath(pipes_struct *p,
9965 struct spoolss_GetPrinterDriverPackagePath *r)
9967 p->rng_fault_state = true;
9968 return WERR_NOT_SUPPORTED;
9971 /****************************************************************
9973 ****************************************************************/
9975 WERROR _spoolss_69(pipes_struct *p,
9976 struct spoolss_69 *r)
9978 p->rng_fault_state = true;
9979 return WERR_NOT_SUPPORTED;
9982 /****************************************************************
9984 ****************************************************************/
9986 WERROR _spoolss_6a(pipes_struct *p,
9987 struct spoolss_6a *r)
9989 p->rng_fault_state = true;
9990 return WERR_NOT_SUPPORTED;
9993 /****************************************************************
9995 ****************************************************************/
9997 WERROR _spoolss_6b(pipes_struct *p,
9998 struct spoolss_6b *r)
10000 p->rng_fault_state = true;
10001 return WERR_NOT_SUPPORTED;
10004 /****************************************************************
10006 ****************************************************************/
10008 WERROR _spoolss_6c(pipes_struct *p,
10009 struct spoolss_6c *r)
10011 p->rng_fault_state = true;
10012 return WERR_NOT_SUPPORTED;
10015 /****************************************************************
10017 ****************************************************************/
10019 WERROR _spoolss_6d(pipes_struct *p,
10020 struct spoolss_6d *r)
10022 p->rng_fault_state = true;
10023 return WERR_NOT_SUPPORTED;