2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Jeremy Allison 2001-2002,
8 * Copyright (C) Gerald Carter 2000-2004,
9 * Copyright (C) Tim Potter 2001-2002.
10 * Copyright (C) Guenther Deschner 2009-2010.
11 * Copyright (C) Andreas Schneider 2010.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
28 up, all the errors returned are DOS errors, not NT status codes. */
31 #include "nt_printing.h"
32 #include "srv_spoolss_util.h"
33 #include "../librpc/gen_ndr/srv_spoolss.h"
34 #include "../librpc/gen_ndr/cli_spoolss.h"
35 #include "rpc_client/init_spoolss.h"
36 #include "librpc/gen_ndr/messaging.h"
37 #include "librpc/gen_ndr/ndr_security.h"
39 #include "registry/reg_objects.h"
40 #include "include/printing.h"
42 #include "../librpc/gen_ndr/netlogon.h"
44 /* macros stolen from s4 spoolss server */
45 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
46 ((info)?ndr_size_##fn(info, level, 0):0)
48 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
49 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
51 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
52 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
54 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
57 #define DBGC_CLASS DBGC_RPC_SRV
59 static Printer_entry *printers_list;
61 typedef struct _counter_printer_0 {
62 struct _counter_printer_0 *next;
63 struct _counter_printer_0 *prev;
69 static counter_printer_0 *counter_list;
71 static struct rpc_pipe_client *notify_cli_pipe; /* print notify back-channel pipe handle*/
72 static uint32_t smb_connections = 0;
75 /* Map generic permissions to printer object specific permissions */
77 const struct standard_mapping printer_std_mapping = {
84 /* Map generic permissions to print server object specific permissions */
86 const struct standard_mapping printserver_std_mapping = {
93 /* API table for Xcv Monitor functions */
95 struct xcv_api_table {
97 WERROR(*fn) (TALLOC_CTX *mem_ctx, NT_USER_TOKEN *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
100 /********************************************************************
101 * Canonicalize servername.
102 ********************************************************************/
104 static const char *canon_servername(const char *servername)
106 const char *pservername = servername;
107 while (*pservername == '\\') {
113 /* translate between internal status numbers and NT status numbers */
114 static int nt_printj_status(int v)
120 return JOB_STATUS_PAUSED;
122 return JOB_STATUS_SPOOLING;
124 return JOB_STATUS_PRINTING;
126 return JOB_STATUS_ERROR;
128 return JOB_STATUS_DELETING;
130 return JOB_STATUS_OFFLINE;
132 return JOB_STATUS_PAPEROUT;
134 return JOB_STATUS_PRINTED;
136 return JOB_STATUS_DELETED;
138 return JOB_STATUS_BLOCKED_DEVQ;
139 case LPQ_USER_INTERVENTION:
140 return JOB_STATUS_USER_INTERVENTION;
145 static int nt_printq_status(int v)
149 return PRINTER_STATUS_PAUSED;
158 /***************************************************************************
159 Disconnect from the client
160 ****************************************************************************/
162 static void srv_spoolss_replycloseprinter(
163 int snum, struct policy_handle *handle,
164 struct messaging_context *msg_ctx)
170 * Tell the specific printing tdb we no longer want messages for this printer
171 * by deregistering our PID.
174 if (!print_notify_deregister_pid(snum))
175 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
177 /* weird if the test succeeds !!! */
178 if (smb_connections==0) {
179 DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
183 status = rpccli_spoolss_ReplyClosePrinter(notify_cli_pipe, talloc_tos(),
186 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
187 DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
188 win_errstr(result)));
190 /* if it's the last connection, deconnect the IPC$ share */
191 if (smb_connections==1) {
193 cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) );
195 * The above call shuts down the pipe also.
197 notify_cli_pipe = NULL;
199 if (msg_ctx != NULL) {
200 messaging_deregister(msg_ctx, MSG_PRINTER_NOTIFY2,
204 * Tell the serverid.tdb we're no longer
205 * interested in printer notify messages.
208 serverid_register_msg_flags(
209 messaging_server_id(msg_ctx),
210 false, FLAG_MSG_PRINT_NOTIFY);
217 /****************************************************************************
218 Functions to free a printer entry datastruct.
219 ****************************************************************************/
221 static int printer_entry_destructor(Printer_entry *Printer)
223 if (Printer->notify.client_connected == true) {
226 if ( Printer->printer_type == SPLHND_SERVER) {
228 srv_spoolss_replycloseprinter(
229 snum, &Printer->notify.client_hnd,
230 Printer->notify.msg_ctx);
231 } else if (Printer->printer_type == SPLHND_PRINTER) {
232 snum = print_queue_snum(Printer->sharename);
234 srv_spoolss_replycloseprinter(
235 snum, &Printer->notify.client_hnd,
236 Printer->notify.msg_ctx);
240 Printer->notify.flags=0;
241 Printer->notify.options=0;
242 Printer->notify.localmachine[0]='\0';
243 Printer->notify.printerlocal=0;
244 TALLOC_FREE(Printer->notify.option);
245 Printer->notify.client_connected = false;
247 TALLOC_FREE(Printer->devmode);
249 /* Remove from the internal list. */
250 DLIST_REMOVE(printers_list, Printer);
254 /****************************************************************************
255 find printer index by handle
256 ****************************************************************************/
258 static Printer_entry *find_printer_index_by_hnd(struct pipes_struct *p,
259 struct policy_handle *hnd)
261 Printer_entry *find_printer = NULL;
263 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
264 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
271 /****************************************************************************
272 Close printer index by handle.
273 ****************************************************************************/
275 static bool close_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
277 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
280 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
285 close_policy_hnd(p, hnd);
290 /****************************************************************************
291 Delete a printer given a handle.
292 ****************************************************************************/
294 static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
295 const char *sharename,
296 struct messaging_context *msg_ctx)
298 char *cmd = lp_deleteprinter_cmd();
299 char *command = NULL;
301 SE_PRIV se_printop = SE_PRINT_OPERATOR;
302 bool is_print_op = false;
304 /* can't fail if we don't try */
309 command = talloc_asprintf(ctx,
316 is_print_op = user_has_privileges( token, &se_printop );
318 DEBUG(10,("Running [%s]\n", command));
320 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
325 if ( (ret = smbrun(command, NULL)) == 0 ) {
326 /* Tell everyone we updated smb.conf. */
327 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
333 /********** END SePrintOperatorPrivlege BLOCK **********/
335 DEBUGADD(10,("returned [%d]\n", ret));
337 TALLOC_FREE(command);
340 return WERR_BADFID; /* What to return here? */
342 /* go ahead and re-read the services immediately */
344 reload_services(false);
347 if ( lp_servicenumber( sharename ) > 0 )
348 return WERR_ACCESS_DENIED;
353 /****************************************************************************
354 Delete a printer given a handle.
355 ****************************************************************************/
357 static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
359 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
363 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
369 * It turns out that Windows allows delete printer on a handle
370 * opened by an admin user, then used on a pipe handle created
371 * by an anonymous user..... but they're working on security.... riiight !
375 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
376 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
377 return WERR_ACCESS_DENIED;
380 /* this does not need a become root since the access check has been
381 done on the handle already */
383 result = winreg_delete_printer_key(p->mem_ctx, p->server_info,
384 p->msg_ctx, Printer->sharename, "");
385 if (!W_ERROR_IS_OK(result)) {
386 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
390 return delete_printer_hook(p->mem_ctx, p->server_info->ptok,
391 Printer->sharename, p->msg_ctx);
394 /****************************************************************************
395 Return the snum of a printer corresponding to an handle.
396 ****************************************************************************/
398 static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
399 int *number, struct share_params **params)
401 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
404 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
409 switch (Printer->printer_type) {
411 DEBUG(4,("short name:%s\n", Printer->sharename));
412 *number = print_queue_snum(Printer->sharename);
413 return (*number != -1);
421 /****************************************************************************
422 Set printer handle type.
423 Check if it's \\server or \\server\printer
424 ****************************************************************************/
426 static bool set_printer_hnd_printertype(Printer_entry *Printer, const char *handlename)
428 DEBUG(3,("Setting printer type=%s\n", handlename));
430 if ( strlen(handlename) < 3 ) {
431 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", handlename));
435 /* it's a print server */
436 if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
437 DEBUGADD(4,("Printer is a print server\n"));
438 Printer->printer_type = SPLHND_SERVER;
440 /* it's a printer (set_printer_hnd_name() will handle port monitors */
442 DEBUGADD(4,("Printer is a printer\n"));
443 Printer->printer_type = SPLHND_PRINTER;
449 /****************************************************************************
450 Set printer handle name.. Accept names like \\server, \\server\printer,
451 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
452 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
453 XcvDataPort() interface.
454 ****************************************************************************/
456 static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
457 struct auth_serversupplied_info *server_info,
458 Printer_entry *Printer,
459 const char *handlename)
462 int n_services=lp_numservices();
464 const char *printername;
465 const char *servername = NULL;
468 struct spoolss_PrinterInfo2 *info2 = NULL;
471 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
472 (unsigned long)strlen(handlename)));
474 aprinter = CONST_DISCARD(char *, handlename);
475 if ( *handlename == '\\' ) {
476 servername = canon_servername(handlename);
477 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
481 if (!is_myname_or_ipaddr(servername)) {
485 fstrcpy(Printer->servername, servername);
488 if (Printer->printer_type == SPLHND_SERVER) {
492 if (Printer->printer_type != SPLHND_PRINTER) {
496 DEBUGADD(5, ("searching for [%s]\n", aprinter));
498 /* check for the Port Monitor Interface */
499 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
500 Printer->printer_type = SPLHND_PORTMON_TCP;
501 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
504 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
505 Printer->printer_type = SPLHND_PORTMON_LOCAL;
506 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
510 /* Search all sharenames first as this is easier than pulling
511 the printer_info_2 off of disk. Don't use find_service() since
512 that calls out to map_username() */
514 /* do another loop to look for printernames */
515 for (snum = 0; !found && snum < n_services; snum++) {
516 const char *printer = lp_const_servicename(snum);
518 /* no point going on if this is not a printer */
519 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
523 /* ignore [printers] share */
524 if (strequal(printer, "printers")) {
528 fstrcpy(sname, printer);
529 if (strequal(aprinter, printer)) {
534 /* no point looking up the printer object if
535 we aren't allowing printername != sharename */
536 if (lp_force_printername(snum)) {
540 result = winreg_get_printer(mem_ctx,
542 smbd_messaging_context(),
546 if ( !W_ERROR_IS_OK(result) ) {
547 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
548 sname, win_errstr(result)));
552 printername = strrchr(info2->printername, '\\');
553 if (printername == NULL) {
554 printername = info2->printername;
559 if (strequal(printername, aprinter)) {
564 DEBUGADD(10, ("printername: %s\n", printername));
570 DEBUGADD(4,("Printer not found\n"));
574 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
576 fstrcpy(Printer->sharename, sname);
581 /****************************************************************************
582 Find first available printer slot. creates a printer handle for you.
583 ****************************************************************************/
585 static bool open_printer_hnd(struct pipes_struct *p, struct policy_handle *hnd,
586 const char *name, uint32_t access_granted)
588 Printer_entry *new_printer;
590 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
592 new_printer = TALLOC_ZERO_P(NULL, Printer_entry);
593 if (new_printer == NULL) {
596 talloc_set_destructor(new_printer, printer_entry_destructor);
598 if (!create_policy_hnd(p, hnd, new_printer)) {
599 TALLOC_FREE(new_printer);
603 /* Add to the internal list. */
604 DLIST_ADD(printers_list, new_printer);
606 new_printer->notify.option=NULL;
608 if (!set_printer_hnd_printertype(new_printer, name)) {
609 close_printer_handle(p, hnd);
613 if (!set_printer_hnd_name(p->mem_ctx, p->server_info, new_printer, name)) {
614 close_printer_handle(p, hnd);
618 new_printer->access_granted = access_granted;
620 DEBUG(5, ("%d printer handles active\n",
621 (int)num_pipe_handles(p)));
626 /***************************************************************************
627 check to see if the client motify handle is monitoring the notification
628 given by (notify_type, notify_field).
629 **************************************************************************/
631 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
632 uint16_t notify_field)
637 static bool is_monitoring_event(Printer_entry *p, uint16_t notify_type,
638 uint16_t notify_field)
640 struct spoolss_NotifyOption *option = p->notify.option;
644 * Flags should always be zero when the change notify
645 * is registered by the client's spooler. A user Win32 app
646 * might use the flags though instead of the NOTIFY_OPTION_INFO
655 return is_monitoring_event_flags(
656 p->notify.flags, notify_type, notify_field);
658 for (i = 0; i < option->count; i++) {
660 /* Check match for notify_type */
662 if (option->types[i].type != notify_type)
665 /* Check match for field */
667 for (j = 0; j < option->types[i].count; j++) {
668 if (option->types[i].fields[j].field == notify_field) {
674 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
675 p->servername, p->sharename, notify_type, notify_field));
680 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
681 _data->data.integer[0] = _integer; \
682 _data->data.integer[1] = 0;
685 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
686 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
687 if (!_data->data.string.string) {\
688 _data->data.string.size = 0; \
690 _data->data.string.size = strlen_m_term(_p) * 2;
692 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
693 _data->data.devmode.devmode = _devmode;
695 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
696 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
697 if (!_data->data.sd.sd) { \
698 _data->data.sd.sd_size = 0; \
700 _data->data.sd.sd_size = \
701 ndr_size_security_descriptor(_data->data.sd.sd, 0);
703 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
708 struct spoolss_Time st;
712 if (!init_systemtime(&st, t)) {
716 p = talloc_array(mem_ctx, char, len);
722 * Systemtime must be linearized as a set of UINT16's.
723 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
726 SSVAL(p, 0, st.year);
727 SSVAL(p, 2, st.month);
728 SSVAL(p, 4, st.day_of_week);
730 SSVAL(p, 8, st.hour);
731 SSVAL(p, 10, st.minute);
732 SSVAL(p, 12, st.second);
733 SSVAL(p, 14, st.millisecond);
739 /* Convert a notification message to a struct spoolss_Notify */
741 static void notify_one_value(struct spoolss_notify_msg *msg,
742 struct spoolss_Notify *data,
745 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
748 static void notify_string(struct spoolss_notify_msg *msg,
749 struct spoolss_Notify *data,
752 /* The length of the message includes the trailing \0 */
754 data->data.string.size = msg->len * 2;
755 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
756 if (!data->data.string.string) {
757 data->data.string.size = 0;
762 static void notify_system_time(struct spoolss_notify_msg *msg,
763 struct spoolss_Notify *data,
766 data->data.string.string = NULL;
767 data->data.string.size = 0;
769 if (msg->len != sizeof(time_t)) {
770 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
775 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
776 &data->data.string.string,
777 &data->data.string.size);
780 struct notify2_message_table {
782 void (*fn)(struct spoolss_notify_msg *msg,
783 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
786 static struct notify2_message_table printer_notify_table[] = {
787 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
788 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
789 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
790 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
791 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
792 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
793 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
794 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
795 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
796 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
797 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
798 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
799 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
800 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
801 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
802 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
803 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
804 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
805 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
808 static struct notify2_message_table job_notify_table[] = {
809 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
810 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
811 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
812 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
813 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
814 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
815 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
816 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
817 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
818 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
819 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
820 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
821 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
822 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
823 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
824 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
825 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
826 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
827 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
828 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
829 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
830 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
831 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
832 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
836 /***********************************************************************
837 Allocate talloc context for container object
838 **********************************************************************/
840 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
845 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
850 /***********************************************************************
851 release all allocated memory and zero out structure
852 **********************************************************************/
854 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
860 talloc_destroy(ctr->ctx);
867 /***********************************************************************
868 **********************************************************************/
870 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
878 /***********************************************************************
879 **********************************************************************/
881 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
883 if ( !ctr || !ctr->msg_groups )
886 if ( idx >= ctr->num_groups )
889 return &ctr->msg_groups[idx];
893 /***********************************************************************
894 How many groups of change messages do we have ?
895 **********************************************************************/
897 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
902 return ctr->num_groups;
905 /***********************************************************************
906 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
907 **********************************************************************/
909 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
911 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
912 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
913 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
919 /* loop over all groups looking for a matching printer name */
921 for ( i=0; i<ctr->num_groups; i++ ) {
922 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
926 /* add a new group? */
928 if ( i == ctr->num_groups ) {
931 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
932 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
935 ctr->msg_groups = groups;
937 /* clear the new entry and set the printer name */
939 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
940 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
943 /* add the change messages; 'i' is the correct index now regardless */
945 msg_grp = &ctr->msg_groups[i];
949 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
950 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
953 msg_grp->msgs = msg_list;
955 new_slot = msg_grp->num_msgs-1;
956 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
958 /* need to allocate own copy of data */
961 msg_grp->msgs[new_slot].notify.data = (char *)
962 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
964 return ctr->num_groups;
967 static void construct_info_data(struct spoolss_Notify *info_data,
968 enum spoolss_NotifyType type,
969 uint16_t field, int id);
971 /***********************************************************************
972 Send a change notication message on all handles which have a call
974 **********************************************************************/
976 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
979 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
980 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
981 SPOOLSS_NOTIFY_MSG *messages;
982 int sending_msg_count;
985 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
989 messages = msg_group->msgs;
992 DEBUG(5,("send_notify2_changes() called with no messages!\n"));
996 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
998 /* loop over all printers */
1000 for (p = printers_list; p; p = p->next) {
1001 struct spoolss_Notify *notifies;
1006 /* Is there notification on this handle? */
1008 if ( !p->notify.client_connected )
1011 DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
1013 /* For this printer? Print servers always receive
1016 if ( ( p->printer_type == SPLHND_PRINTER ) &&
1017 ( !strequal(msg_group->printername, p->sharename) ) )
1020 DEBUG(10,("Our printer\n"));
1022 /* allocate the max entries possible */
1024 notifies = TALLOC_ZERO_ARRAY(mem_ctx, struct spoolss_Notify, msg_group->num_msgs);
1029 /* build the array of change notifications */
1031 sending_msg_count = 0;
1033 for ( i=0; i<msg_group->num_msgs; i++ ) {
1034 SPOOLSS_NOTIFY_MSG *msg = &messages[i];
1036 /* Are we monitoring this event? */
1038 if (!is_monitoring_event(p, msg->type, msg->field))
1041 sending_msg_count++;
1044 DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
1045 msg->type, msg->field, p->sharename));
1048 * if the is a printer notification handle and not a job notification
1049 * type, then set the id to 0. Other wise just use what was specified
1052 * When registering change notification on a print server handle
1053 * we always need to send back the id (snum) matching the printer
1054 * for which the change took place. For change notify registered
1055 * on a printer handle, this does not matter and the id should be 0.
1060 if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
1066 /* Convert unix jobid to smb jobid */
1068 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1069 id = sysjob_to_jobid(msg->id);
1072 DEBUG(3, ("no such unix jobid %d\n", msg->id));
1077 construct_info_data( ¬ifies[count], msg->type, msg->field, id );
1080 case PRINTER_NOTIFY_TYPE:
1081 if ( printer_notify_table[msg->field].fn )
1082 printer_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1085 case JOB_NOTIFY_TYPE:
1086 if ( job_notify_table[msg->field].fn )
1087 job_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1091 DEBUG(5, ("Unknown notification type %d\n", msg->type));
1098 if ( sending_msg_count ) {
1101 union spoolss_ReplyPrinterInfo info;
1102 struct spoolss_NotifyInfo info0;
1103 uint32_t reply_result;
1105 info0.version = 0x2;
1106 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1107 info0.count = count;
1108 info0.notifies = notifies;
1110 info.info0 = &info0;
1112 status = rpccli_spoolss_RouterReplyPrinterEx(notify_cli_pipe, mem_ctx,
1113 &p->notify.client_hnd,
1114 p->notify.change, /* color */
1117 0, /* reply_type, must be 0 */
1120 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1121 DEBUG(1,("RouterReplyPrinterEx to client: %s failed: %s\n",
1122 notify_cli_pipe->srv_name_slash,
1125 switch (reply_result) {
1128 case PRINTER_NOTIFY_INFO_DISCARDED:
1129 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1130 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1139 DEBUG(8,("send_notify2_changes: Exit...\n"));
1143 /***********************************************************************
1144 **********************************************************************/
1146 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1149 uint32_t tv_sec, tv_usec;
1152 /* Unpack message */
1154 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1157 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1159 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1162 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1163 &msg->notify.value[0], &msg->notify.value[1]);
1165 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1166 &msg->len, &msg->notify.data);
1168 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1169 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1171 tv->tv_sec = tv_sec;
1172 tv->tv_usec = tv_usec;
1175 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1176 msg->notify.value[1]));
1178 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1183 /********************************************************************
1184 Receive a notify2 message list
1185 ********************************************************************/
1187 static void receive_notify2_message_list(struct messaging_context *msg,
1190 struct server_id server_id,
1193 size_t msg_count, i;
1194 char *buf = (char *)data->data;
1197 SPOOLSS_NOTIFY_MSG notify;
1198 SPOOLSS_NOTIFY_MSG_CTR messages;
1201 if (data->length < 4) {
1202 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1206 msg_count = IVAL(buf, 0);
1209 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1211 if (msg_count == 0) {
1212 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1216 /* initialize the container */
1218 ZERO_STRUCT( messages );
1219 notify_msg_ctr_init( &messages );
1222 * build message groups for each printer identified
1223 * in a change_notify msg. Remember that a PCN message
1224 * includes the handle returned for the srv_spoolss_replyopenprinter()
1225 * call. Therefore messages are grouped according to printer handle.
1228 for ( i=0; i<msg_count; i++ ) {
1229 struct timeval msg_tv;
1231 if (msg_ptr + 4 - buf > data->length) {
1232 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1236 msg_len = IVAL(msg_ptr,0);
1239 if (msg_ptr + msg_len - buf > data->length) {
1240 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1244 /* unpack messages */
1246 ZERO_STRUCT( notify );
1247 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1250 /* add to correct list in container */
1252 notify_msg_ctr_addmsg( &messages, ¬ify );
1254 /* free memory that might have been allocated by notify2_unpack_msg() */
1256 if ( notify.len != 0 )
1257 SAFE_FREE( notify.notify.data );
1260 /* process each group of messages */
1262 num_groups = notify_msg_ctr_numgroups( &messages );
1263 for ( i=0; i<num_groups; i++ )
1264 send_notify2_changes( &messages, i );
1269 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1270 (uint32_t)msg_count ));
1272 notify_msg_ctr_destroy( &messages );
1277 /********************************************************************
1278 Send a message to ourself about new driver being installed
1279 so we can upgrade the information for each printer bound to this
1281 ********************************************************************/
1283 static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
1284 struct messaging_context *msg_ctx)
1286 int len = strlen(drivername);
1291 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1294 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
1295 MSG_PRINTER_DRVUPGRADE,
1296 (uint8_t *)drivername, len+1);
1301 /**********************************************************************
1302 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1303 over all printers, upgrading ones as necessary
1304 **********************************************************************/
1306 void do_drv_upgrade_printer(struct messaging_context *msg,
1309 struct server_id server_id,
1312 TALLOC_CTX *tmp_ctx;
1313 struct auth_serversupplied_info *server_info = NULL;
1314 struct spoolss_PrinterInfo2 *pinfo2;
1317 const char *drivername;
1319 int n_services = lp_numservices();
1322 tmp_ctx = talloc_new(NULL);
1323 if (!tmp_ctx) return;
1325 status = make_server_info_system(tmp_ctx, &server_info);
1326 if (!NT_STATUS_IS_OK(status)) {
1327 DEBUG(0, ("do_drv_upgrade_printer: "
1328 "Could not create system server_info\n"));
1332 len = MIN(data->length,sizeof(drivername)-1);
1333 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, len);
1335 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1339 DEBUG(10, ("do_drv_upgrade_printer: "
1340 "Got message for new driver [%s]\n", drivername));
1342 /* Iterate the printer list */
1344 for (snum = 0; snum < n_services; snum++) {
1345 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1349 result = winreg_get_printer(tmp_ctx, server_info, msg,
1351 lp_const_servicename(snum),
1354 if (!W_ERROR_IS_OK(result)) {
1358 if (!pinfo2->drivername) {
1362 if (strcmp(drivername, pinfo2->drivername) != 0) {
1366 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1368 /* all we care about currently is the change_id */
1369 result = winreg_printer_update_changeid(tmp_ctx,
1372 pinfo2->printername);
1374 if (!W_ERROR_IS_OK(result)) {
1375 DEBUG(3, ("do_drv_upgrade_printer: "
1376 "Failed to update changeid [%s]\n",
1377 win_errstr(result)));
1383 talloc_free(tmp_ctx);
1386 /********************************************************************
1387 Update the cache for all printq's with a registered client
1389 ********************************************************************/
1391 void update_monitored_printq_cache( void )
1393 Printer_entry *printer = printers_list;
1396 /* loop through all printers and update the cache where
1397 client_connected == true */
1400 if ( (printer->printer_type == SPLHND_PRINTER)
1401 && printer->notify.client_connected )
1403 snum = print_queue_snum(printer->sharename);
1404 print_queue_status( snum, NULL, NULL );
1407 printer = printer->next;
1413 /****************************************************************
1414 _spoolss_OpenPrinter
1415 ****************************************************************/
1417 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1418 struct spoolss_OpenPrinter *r)
1420 struct spoolss_OpenPrinterEx e;
1423 ZERO_STRUCT(e.in.userlevel);
1425 e.in.printername = r->in.printername;
1426 e.in.datatype = r->in.datatype;
1427 e.in.devmode_ctr = r->in.devmode_ctr;
1428 e.in.access_mask = r->in.access_mask;
1431 e.out.handle = r->out.handle;
1433 werr = _spoolss_OpenPrinterEx(p, &e);
1435 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1436 /* OpenPrinterEx returns this for a bad
1437 * printer name. We must return WERR_INVALID_PRINTER_NAME
1440 werr = WERR_INVALID_PRINTER_NAME;
1446 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1447 struct spoolss_DeviceMode *orig,
1448 struct spoolss_DeviceMode **dest)
1450 struct spoolss_DeviceMode *dm;
1452 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1457 /* copy all values, then duplicate strings and structs */
1460 dm->devicename = talloc_strdup(dm, orig->devicename);
1461 if (!dm->devicename) {
1464 dm->formname = talloc_strdup(dm, orig->formname);
1465 if (!dm->formname) {
1468 if (orig->driverextra_data.data) {
1469 dm->driverextra_data.data =
1470 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1471 orig->driverextra_data.length);
1472 if (!dm->driverextra_data.data) {
1481 /****************************************************************
1482 _spoolss_OpenPrinterEx
1483 ****************************************************************/
1485 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1486 struct spoolss_OpenPrinterEx *r)
1489 Printer_entry *Printer=NULL;
1491 if (!r->in.printername) {
1492 return WERR_INVALID_PARAM;
1495 /* some sanity check because you can open a printer or a print server */
1496 /* aka: \\server\printer or \\server */
1498 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1500 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1501 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1502 " for printer %s\n", r->in.printername));
1503 ZERO_STRUCTP(r->out.handle);
1504 return WERR_INVALID_PARAM;
1507 Printer = find_printer_index_by_hnd(p, r->out.handle);
1509 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1510 "handle we created for printer %s\n", r->in.printername));
1511 close_printer_handle(p, r->out.handle);
1512 ZERO_STRUCTP(r->out.handle);
1513 return WERR_INVALID_PARAM;
1517 * First case: the user is opening the print server:
1519 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1520 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1522 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1523 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1524 * or if the user is listed in the smb.conf printer admin parameter.
1526 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1527 * client view printer folder, but does not show the MSAPW.
1529 * Note: this test needs code to check access rights here too. Jeremy
1530 * could you look at this?
1532 * Second case: the user is opening a printer:
1533 * NT doesn't let us connect to a printer if the connecting user
1534 * doesn't have print permission.
1536 * Third case: user is opening a Port Monitor
1537 * access checks same as opening a handle to the print server.
1540 switch (Printer->printer_type )
1543 case SPLHND_PORTMON_TCP:
1544 case SPLHND_PORTMON_LOCAL:
1545 /* Printserver handles use global struct... */
1549 /* Map standard access rights to object specific access rights */
1551 se_map_standard(&r->in.access_mask,
1552 &printserver_std_mapping);
1554 /* Deny any object specific bits that don't apply to print
1555 servers (i.e printer and job specific bits) */
1557 r->in.access_mask &= SEC_MASK_SPECIFIC;
1559 if (r->in.access_mask &
1560 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1561 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1562 close_printer_handle(p, r->out.handle);
1563 ZERO_STRUCTP(r->out.handle);
1564 return WERR_ACCESS_DENIED;
1567 /* Allow admin access */
1569 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1571 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1573 if (!lp_ms_add_printer_wizard()) {
1574 close_printer_handle(p, r->out.handle);
1575 ZERO_STRUCTP(r->out.handle);
1576 return WERR_ACCESS_DENIED;
1579 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1580 and not a printer admin, then fail */
1582 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1583 !user_has_privileges(p->server_info->ptok,
1585 !token_contains_name_in_list(
1586 uidtoname(p->server_info->utok.uid),
1587 p->server_info->info3->base.domain.string,
1589 p->server_info->ptok,
1590 lp_printer_admin(snum))) {
1591 close_printer_handle(p, r->out.handle);
1592 ZERO_STRUCTP(r->out.handle);
1593 return WERR_ACCESS_DENIED;
1596 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1600 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1603 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1604 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1606 /* We fall through to return WERR_OK */
1609 case SPLHND_PRINTER:
1610 /* NT doesn't let us connect to a printer if the connecting user
1611 doesn't have print permission. */
1613 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1614 close_printer_handle(p, r->out.handle);
1615 ZERO_STRUCTP(r->out.handle);
1619 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1620 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1623 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1625 /* map an empty access mask to the minimum access mask */
1626 if (r->in.access_mask == 0x0)
1627 r->in.access_mask = PRINTER_ACCESS_USE;
1630 * If we are not serving the printer driver for this printer,
1631 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1632 * will keep NT clients happy --jerry
1635 if (lp_use_client_driver(snum)
1636 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1638 r->in.access_mask = PRINTER_ACCESS_USE;
1641 /* check smb.conf parameters and the the sec_desc */
1643 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1644 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1645 ZERO_STRUCTP(r->out.handle);
1646 return WERR_ACCESS_DENIED;
1649 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1650 p->server_info->ptok, snum) ||
1651 !print_access_check(p->server_info, snum,
1652 r->in.access_mask)) {
1653 DEBUG(3, ("access DENIED for printer open\n"));
1654 close_printer_handle(p, r->out.handle);
1655 ZERO_STRUCTP(r->out.handle);
1656 return WERR_ACCESS_DENIED;
1659 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1660 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1661 close_printer_handle(p, r->out.handle);
1662 ZERO_STRUCTP(r->out.handle);
1663 return WERR_ACCESS_DENIED;
1666 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1667 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1669 r->in.access_mask = PRINTER_ACCESS_USE;
1671 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1672 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1674 winreg_create_printer(p->mem_ctx,
1677 Printer->servername,
1678 lp_const_servicename(snum));
1683 /* sanity check to prevent programmer error */
1684 ZERO_STRUCTP(r->out.handle);
1688 Printer->access_granted = r->in.access_mask;
1691 * If the client sent a devmode in the OpenPrinter() call, then
1692 * save it here in case we get a job submission on this handle
1695 if ((Printer->printer_type != SPLHND_SERVER) &&
1696 r->in.devmode_ctr.devmode) {
1697 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1701 #if 0 /* JERRY -- I'm doubtful this is really effective */
1702 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1703 optimization in Windows 2000 clients --jerry */
1705 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1706 && (RA_WIN2K == get_remote_arch()) )
1708 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1709 sys_usleep( 500000 );
1716 /****************************************************************
1717 _spoolss_ClosePrinter
1718 ****************************************************************/
1720 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1721 struct spoolss_ClosePrinter *r)
1723 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1725 if (Printer && Printer->document_started) {
1726 struct spoolss_EndDocPrinter e;
1728 e.in.handle = r->in.handle;
1730 _spoolss_EndDocPrinter(p, &e);
1733 if (!close_printer_handle(p, r->in.handle))
1736 /* clear the returned printer handle. Observed behavior
1737 from Win2k server. Don't think this really matters.
1738 Previous code just copied the value of the closed
1741 ZERO_STRUCTP(r->out.handle);
1746 /****************************************************************
1747 _spoolss_DeletePrinter
1748 ****************************************************************/
1750 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1751 struct spoolss_DeletePrinter *r)
1753 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1757 if (Printer && Printer->document_started) {
1758 struct spoolss_EndDocPrinter e;
1760 e.in.handle = r->in.handle;
1762 _spoolss_EndDocPrinter(p, &e);
1765 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
1766 winreg_delete_printer_key(p->mem_ctx,
1769 lp_const_servicename(snum),
1773 result = delete_printer_handle(p, r->in.handle);
1778 /*******************************************************************
1779 * static function to lookup the version id corresponding to an
1780 * long architecture string
1781 ******************************************************************/
1783 static const struct print_architecture_table_node archi_table[]= {
1785 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1786 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1787 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1788 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
1789 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
1790 {"Windows IA64", SPL_ARCH_IA64, 3 },
1791 {"Windows x64", SPL_ARCH_X64, 3 },
1795 static int get_version_id(const char *arch)
1799 for (i=0; archi_table[i].long_archi != NULL; i++)
1801 if (strcmp(arch, archi_table[i].long_archi) == 0)
1802 return (archi_table[i].version);
1808 /****************************************************************
1809 _spoolss_DeletePrinterDriver
1810 ****************************************************************/
1812 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
1813 struct spoolss_DeletePrinterDriver *r)
1816 struct spoolss_DriverInfo8 *info = NULL;
1817 struct spoolss_DriverInfo8 *info_win2k = NULL;
1820 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1822 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1823 and not a printer admin, then fail */
1825 if ( (p->server_info->utok.uid != sec_initial_uid())
1826 && !user_has_privileges(p->server_info->ptok, &se_printop )
1827 && !token_contains_name_in_list(
1828 uidtoname(p->server_info->utok.uid),
1829 p->server_info->info3->base.domain.string,
1831 p->server_info->ptok,
1832 lp_printer_admin(-1)) )
1834 return WERR_ACCESS_DENIED;
1837 /* check that we have a valid driver name first */
1839 if ((version = get_version_id(r->in.architecture)) == -1)
1840 return WERR_INVALID_ENVIRONMENT;
1842 status = winreg_get_driver(p->mem_ctx, p->server_info,
1843 r->in.architecture, r->in.driver,
1845 if (!W_ERROR_IS_OK(status)) {
1846 /* try for Win2k driver if "Windows NT x86" */
1848 if ( version == 2 ) {
1851 status = winreg_get_driver(p->mem_ctx, p->server_info,
1855 if (!W_ERROR_IS_OK(status)) {
1856 status = WERR_UNKNOWN_PRINTER_DRIVER;
1860 /* otherwise it was a failure */
1862 status = WERR_UNKNOWN_PRINTER_DRIVER;
1868 if (printer_driver_in_use(p->mem_ctx, p->server_info, info)) {
1869 status = WERR_PRINTER_DRIVER_IN_USE;
1874 status = winreg_get_driver(p->mem_ctx, p->server_info,
1876 r->in.driver, 3, &info_win2k);
1877 if (W_ERROR_IS_OK(status)) {
1878 /* if we get to here, we now have 2 driver info structures to remove */
1879 /* remove the Win2k driver first*/
1881 status = winreg_del_driver(p->mem_ctx,
1884 talloc_free(info_win2k);
1886 /* this should not have failed---if it did, report to client */
1887 if (!W_ERROR_IS_OK(status)) {
1893 status = winreg_del_driver(p->mem_ctx, p->server_info, info, version);
1901 /****************************************************************
1902 _spoolss_DeletePrinterDriverEx
1903 ****************************************************************/
1905 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
1906 struct spoolss_DeletePrinterDriverEx *r)
1908 struct spoolss_DriverInfo8 *info = NULL;
1909 struct spoolss_DriverInfo8 *info_win2k = NULL;
1913 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1915 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1916 and not a printer admin, then fail */
1918 if ( (p->server_info->utok.uid != sec_initial_uid())
1919 && !user_has_privileges(p->server_info->ptok, &se_printop )
1920 && !token_contains_name_in_list(
1921 uidtoname(p->server_info->utok.uid),
1922 p->server_info->info3->base.domain.string,
1924 p->server_info->ptok, lp_printer_admin(-1)) )
1926 return WERR_ACCESS_DENIED;
1929 /* check that we have a valid driver name first */
1930 if ((version = get_version_id(r->in.architecture)) == -1) {
1931 /* this is what NT returns */
1932 return WERR_INVALID_ENVIRONMENT;
1935 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
1936 version = r->in.version;
1938 status = winreg_get_driver(p->mem_ctx, p->server_info,
1939 r->in.architecture, r->in.driver,
1941 if (!W_ERROR_IS_OK(status)) {
1942 status = WERR_UNKNOWN_PRINTER_DRIVER;
1945 * if the client asked for a specific version,
1946 * or this is something other than Windows NT x86,
1950 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
1953 /* try for Win2k driver if "Windows NT x86" */
1956 status = winreg_get_driver(info, p->server_info,
1960 if (!W_ERROR_IS_OK(status)) {
1961 status = WERR_UNKNOWN_PRINTER_DRIVER;
1966 if (printer_driver_in_use(info, p->server_info, info)) {
1967 status = WERR_PRINTER_DRIVER_IN_USE;
1972 * we have a couple of cases to consider.
1973 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
1974 * then the delete should fail if **any** files overlap with
1976 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
1977 * non-overlapping files
1978 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
1979 * is set, the do not delete any files
1980 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
1983 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
1985 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
1988 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
1989 printer_driver_files_in_use(info, p->server_info, info)) {
1990 /* no idea of the correct error here */
1991 status = WERR_ACCESS_DENIED;
1996 /* also check for W32X86/3 if necessary; maybe we already have? */
1998 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
1999 status = winreg_get_driver(info, p->server_info,
2001 r->in.driver, 3, &info_win2k);
2002 if (W_ERROR_IS_OK(status)) {
2005 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2006 printer_driver_files_in_use(info, p->server_info,
2008 /* no idea of the correct error here */
2009 talloc_free(info_win2k);
2010 status = WERR_ACCESS_DENIED;
2014 /* if we get to here, we now have 2 driver info structures to remove */
2015 /* remove the Win2k driver first*/
2017 status = winreg_del_driver(info, p->server_info,
2020 /* this should not have failed---if it did, report to client */
2022 if (!W_ERROR_IS_OK(status)) {
2027 * now delete any associated files if delete_files is
2028 * true. Even if this part failes, we return succes
2029 * because the driver doesn not exist any more
2032 delete_driver_files(p->server_info,
2038 status = winreg_del_driver(info, p->server_info, info, version);
2039 if (!W_ERROR_IS_OK(status)) {
2044 * now delete any associated files if delete_files is
2045 * true. Even if this part failes, we return succes
2046 * because the driver doesn not exist any more
2049 delete_driver_files(p->server_info, info);
2058 /********************************************************************
2059 GetPrinterData on a printer server Handle.
2060 ********************************************************************/
2062 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2064 enum winreg_Type *type,
2065 union spoolss_PrinterData *data)
2067 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2069 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2075 if (!StrCaseCmp(value, "BeepEnabled")) {
2081 if (!StrCaseCmp(value, "EventLog")) {
2083 /* formally was 0x1b */
2088 if (!StrCaseCmp(value, "NetPopup")) {
2094 if (!StrCaseCmp(value, "MajorVersion")) {
2097 /* Windows NT 4.0 seems to not allow uploading of drivers
2098 to a server that reports 0x3 as the MajorVersion.
2099 need to investigate more how Win2k gets around this .
2102 if (RA_WINNT == get_remote_arch()) {
2111 if (!StrCaseCmp(value, "MinorVersion")) {
2118 * uint32_t size = 0x114
2119 * uint32_t major = 5
2120 * uint32_t minor = [0|1]
2121 * uint32_t build = [2195|2600]
2122 * extra unicode string = e.g. "Service Pack 3"
2124 if (!StrCaseCmp(value, "OSVersion")) {
2126 enum ndr_err_code ndr_err;
2127 struct spoolss_OSVersion os;
2129 os.major = 5; /* Windows 2000 == 5.0 */
2131 os.build = 2195; /* build */
2132 os.extra_string = ""; /* leave extra string empty */
2134 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2135 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2136 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2137 return WERR_GENERAL_FAILURE;
2141 data->binary = blob;
2147 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2150 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2151 W_ERROR_HAVE_NO_MEMORY(data->string);
2156 if (!StrCaseCmp(value, "Architecture")) {
2158 data->string = talloc_strdup(mem_ctx,
2159 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2160 W_ERROR_HAVE_NO_MEMORY(data->string);
2165 if (!StrCaseCmp(value, "DsPresent")) {
2168 /* only show the publish check box if we are a
2169 member of a AD domain */
2171 if (lp_security() == SEC_ADS) {
2179 if (!StrCaseCmp(value, "DNSMachineName")) {
2180 const char *hostname = get_mydnsfullname();
2183 return WERR_BADFILE;
2187 data->string = talloc_strdup(mem_ctx, hostname);
2188 W_ERROR_HAVE_NO_MEMORY(data->string);
2195 return WERR_INVALID_PARAM;
2198 /****************************************************************
2199 _spoolss_GetPrinterData
2200 ****************************************************************/
2202 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2203 struct spoolss_GetPrinterData *r)
2205 struct spoolss_GetPrinterDataEx r2;
2207 r2.in.handle = r->in.handle;
2208 r2.in.key_name = "PrinterDriverData";
2209 r2.in.value_name = r->in.value_name;
2210 r2.in.offered = r->in.offered;
2211 r2.out.type = r->out.type;
2212 r2.out.data = r->out.data;
2213 r2.out.needed = r->out.needed;
2215 return _spoolss_GetPrinterDataEx(p, &r2);
2218 /*********************************************************
2219 Connect to the client machine.
2220 **********************************************************/
2222 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2223 struct sockaddr_storage *client_ss, const char *remote_machine)
2226 struct cli_state *the_cli;
2227 struct sockaddr_storage rm_addr;
2228 char addr[INET6_ADDRSTRLEN];
2230 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2231 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2233 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2234 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2237 print_sockaddr(addr, sizeof(addr), &rm_addr);
2239 rm_addr = *client_ss;
2240 print_sockaddr(addr, sizeof(addr), &rm_addr);
2241 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2245 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2246 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2251 /* setup the connection */
2252 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2253 &rm_addr, 0, "IPC$", "IPC",
2257 0, lp_client_signing(), NULL );
2259 if ( !NT_STATUS_IS_OK( ret ) ) {
2260 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2265 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2266 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2267 cli_shutdown(the_cli);
2272 * Ok - we have an anonymous connection to the IPC$ share.
2273 * Now start the NT Domain stuff :-).
2276 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2277 if (!NT_STATUS_IS_OK(ret)) {
2278 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2279 remote_machine, nt_errstr(ret)));
2280 cli_shutdown(the_cli);
2287 /***************************************************************************
2288 Connect to the client.
2289 ****************************************************************************/
2291 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2292 uint32_t localprinter, uint32_t type,
2293 struct policy_handle *handle,
2294 struct sockaddr_storage *client_ss,
2295 struct messaging_context *msg_ctx)
2301 * If it's the first connection, contact the client
2302 * and connect to the IPC$ share anonymously
2304 if (smb_connections==0) {
2305 fstring unix_printer;
2307 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2309 if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ss, unix_printer ))
2312 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2313 receive_notify2_message_list);
2314 /* Tell the connections db we're now interested in printer
2315 * notify messages. */
2316 serverid_register_msg_flags(messaging_server_id(msg_ctx),
2317 true, FLAG_MSG_PRINT_NOTIFY);
2321 * Tell the specific printing tdb we want messages for this printer
2322 * by registering our PID.
2325 if (!print_notify_register_pid(snum))
2326 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2330 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2338 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2339 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2340 win_errstr(result)));
2342 return (W_ERROR_IS_OK(result));
2345 /****************************************************************
2346 ****************************************************************/
2348 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2349 const struct spoolss_NotifyOption *r)
2351 struct spoolss_NotifyOption *option;
2358 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2365 if (!option->count) {
2369 option->types = talloc_zero_array(option,
2370 struct spoolss_NotifyOptionType, option->count);
2371 if (!option->types) {
2372 talloc_free(option);
2376 for (i=0; i < option->count; i++) {
2377 option->types[i] = r->types[i];
2379 if (option->types[i].count) {
2380 option->types[i].fields = talloc_zero_array(option,
2381 union spoolss_Field, option->types[i].count);
2382 if (!option->types[i].fields) {
2383 talloc_free(option);
2386 for (k=0; k<option->types[i].count; k++) {
2387 option->types[i].fields[k] =
2388 r->types[i].fields[k];
2396 /****************************************************************
2397 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2399 * before replying OK: status=0 a rpc call is made to the workstation
2400 * asking ReplyOpenPrinter
2402 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2403 * called from api_spoolss_rffpcnex
2404 ****************************************************************/
2406 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2407 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2410 struct spoolss_NotifyOption *option = r->in.notify_options;
2411 struct sockaddr_storage client_ss;
2413 /* store the notify value in the printer struct */
2415 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2418 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2419 "Invalid handle (%s:%u:%u).\n",
2420 OUR_HANDLE(r->in.handle)));
2424 Printer->notify.flags = r->in.flags;
2425 Printer->notify.options = r->in.options;
2426 Printer->notify.printerlocal = r->in.printer_local;
2427 Printer->notify.msg_ctx = p->msg_ctx;
2429 TALLOC_FREE(Printer->notify.option);
2430 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2432 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2434 /* Connect to the client machine and send a ReplyOpenPrinter */
2436 if ( Printer->printer_type == SPLHND_SERVER)
2438 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2439 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2442 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2443 "client_address is %s\n", p->client_address));
2445 if (!interpret_string_addr(&client_ss, p->client_address,
2447 return WERR_SERVER_UNAVAILABLE;
2450 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2451 Printer->notify.printerlocal, 1,
2452 &Printer->notify.client_hnd,
2453 &client_ss, p->msg_ctx))
2454 return WERR_SERVER_UNAVAILABLE;
2456 Printer->notify.client_connected = true;
2461 /*******************************************************************
2462 * fill a notify_info_data with the servername
2463 ********************************************************************/
2465 static void spoolss_notify_server_name(int snum,
2466 struct spoolss_Notify *data,
2467 print_queue_struct *queue,
2468 struct spoolss_PrinterInfo2 *pinfo2,
2469 TALLOC_CTX *mem_ctx)
2471 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2474 /*******************************************************************
2475 * fill a notify_info_data with the printername (not including the servername).
2476 ********************************************************************/
2478 static void spoolss_notify_printer_name(int snum,
2479 struct spoolss_Notify *data,
2480 print_queue_struct *queue,
2481 struct spoolss_PrinterInfo2 *pinfo2,
2482 TALLOC_CTX *mem_ctx)
2484 /* the notify name should not contain the \\server\ part */
2485 const char *p = strrchr(pinfo2->printername, '\\');
2488 p = pinfo2->printername;
2493 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2496 /*******************************************************************
2497 * fill a notify_info_data with the servicename
2498 ********************************************************************/
2500 static void spoolss_notify_share_name(int snum,
2501 struct spoolss_Notify *data,
2502 print_queue_struct *queue,
2503 struct spoolss_PrinterInfo2 *pinfo2,
2504 TALLOC_CTX *mem_ctx)
2506 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2509 /*******************************************************************
2510 * fill a notify_info_data with the port name
2511 ********************************************************************/
2513 static void spoolss_notify_port_name(int snum,
2514 struct spoolss_Notify *data,
2515 print_queue_struct *queue,
2516 struct spoolss_PrinterInfo2 *pinfo2,
2517 TALLOC_CTX *mem_ctx)
2519 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2522 /*******************************************************************
2523 * fill a notify_info_data with the printername
2524 * but it doesn't exist, have to see what to do
2525 ********************************************************************/
2527 static void spoolss_notify_driver_name(int snum,
2528 struct spoolss_Notify *data,
2529 print_queue_struct *queue,
2530 struct spoolss_PrinterInfo2 *pinfo2,
2531 TALLOC_CTX *mem_ctx)
2533 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2536 /*******************************************************************
2537 * fill a notify_info_data with the comment
2538 ********************************************************************/
2540 static void spoolss_notify_comment(int snum,
2541 struct spoolss_Notify *data,
2542 print_queue_struct *queue,
2543 struct spoolss_PrinterInfo2 *pinfo2,
2544 TALLOC_CTX *mem_ctx)
2548 if (*pinfo2->comment == '\0') {
2549 p = lp_comment(snum);
2551 p = pinfo2->comment;
2554 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2557 /*******************************************************************
2558 * fill a notify_info_data with the comment
2559 * location = "Room 1, floor 2, building 3"
2560 ********************************************************************/
2562 static void spoolss_notify_location(int snum,
2563 struct spoolss_Notify *data,
2564 print_queue_struct *queue,
2565 struct spoolss_PrinterInfo2 *pinfo2,
2566 TALLOC_CTX *mem_ctx)
2568 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
2571 /*******************************************************************
2572 * fill a notify_info_data with the device mode
2573 * jfm:xxxx don't to it for know but that's a real problem !!!
2574 ********************************************************************/
2576 static void spoolss_notify_devmode(int snum,
2577 struct spoolss_Notify *data,
2578 print_queue_struct *queue,
2579 struct spoolss_PrinterInfo2 *pinfo2,
2580 TALLOC_CTX *mem_ctx)
2582 /* for a dummy implementation we have to zero the fields */
2583 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2586 /*******************************************************************
2587 * fill a notify_info_data with the separator file name
2588 ********************************************************************/
2590 static void spoolss_notify_sepfile(int snum,
2591 struct spoolss_Notify *data,
2592 print_queue_struct *queue,
2593 struct spoolss_PrinterInfo2 *pinfo2,
2594 TALLOC_CTX *mem_ctx)
2596 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2599 /*******************************************************************
2600 * fill a notify_info_data with the print processor
2601 * jfm:xxxx return always winprint to indicate we don't do anything to it
2602 ********************************************************************/
2604 static void spoolss_notify_print_processor(int snum,
2605 struct spoolss_Notify *data,
2606 print_queue_struct *queue,
2607 struct spoolss_PrinterInfo2 *pinfo2,
2608 TALLOC_CTX *mem_ctx)
2610 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2613 /*******************************************************************
2614 * fill a notify_info_data with the print processor options
2615 * jfm:xxxx send an empty string
2616 ********************************************************************/
2618 static void spoolss_notify_parameters(int snum,
2619 struct spoolss_Notify *data,
2620 print_queue_struct *queue,
2621 struct spoolss_PrinterInfo2 *pinfo2,
2622 TALLOC_CTX *mem_ctx)
2624 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2627 /*******************************************************************
2628 * fill a notify_info_data with the data type
2629 * jfm:xxxx always send RAW as data type
2630 ********************************************************************/
2632 static void spoolss_notify_datatype(int snum,
2633 struct spoolss_Notify *data,
2634 print_queue_struct *queue,
2635 struct spoolss_PrinterInfo2 *pinfo2,
2636 TALLOC_CTX *mem_ctx)
2638 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2641 /*******************************************************************
2642 * fill a notify_info_data with the security descriptor
2643 * jfm:xxxx send an null pointer to say no security desc
2644 * have to implement security before !
2645 ********************************************************************/
2647 static void spoolss_notify_security_desc(int snum,
2648 struct spoolss_Notify *data,
2649 print_queue_struct *queue,
2650 struct spoolss_PrinterInfo2 *pinfo2,
2651 TALLOC_CTX *mem_ctx)
2653 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2656 /*******************************************************************
2657 * fill a notify_info_data with the attributes
2658 * jfm:xxxx a samba printer is always shared
2659 ********************************************************************/
2661 static void spoolss_notify_attributes(int snum,
2662 struct spoolss_Notify *data,
2663 print_queue_struct *queue,
2664 struct spoolss_PrinterInfo2 *pinfo2,
2665 TALLOC_CTX *mem_ctx)
2667 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2670 /*******************************************************************
2671 * fill a notify_info_data with the priority
2672 ********************************************************************/
2674 static void spoolss_notify_priority(int snum,
2675 struct spoolss_Notify *data,
2676 print_queue_struct *queue,
2677 struct spoolss_PrinterInfo2 *pinfo2,
2678 TALLOC_CTX *mem_ctx)
2680 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2683 /*******************************************************************
2684 * fill a notify_info_data with the default priority
2685 ********************************************************************/
2687 static void spoolss_notify_default_priority(int snum,
2688 struct spoolss_Notify *data,
2689 print_queue_struct *queue,
2690 struct spoolss_PrinterInfo2 *pinfo2,
2691 TALLOC_CTX *mem_ctx)
2693 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
2696 /*******************************************************************
2697 * fill a notify_info_data with the start time
2698 ********************************************************************/
2700 static void spoolss_notify_start_time(int snum,
2701 struct spoolss_Notify *data,
2702 print_queue_struct *queue,
2703 struct spoolss_PrinterInfo2 *pinfo2,
2704 TALLOC_CTX *mem_ctx)
2706 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
2709 /*******************************************************************
2710 * fill a notify_info_data with the until time
2711 ********************************************************************/
2713 static void spoolss_notify_until_time(int snum,
2714 struct spoolss_Notify *data,
2715 print_queue_struct *queue,
2716 struct spoolss_PrinterInfo2 *pinfo2,
2717 TALLOC_CTX *mem_ctx)
2719 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
2722 /*******************************************************************
2723 * fill a notify_info_data with the status
2724 ********************************************************************/
2726 static void spoolss_notify_status(int snum,
2727 struct spoolss_Notify *data,
2728 print_queue_struct *queue,
2729 struct spoolss_PrinterInfo2 *pinfo2,
2730 TALLOC_CTX *mem_ctx)
2732 print_status_struct status;
2734 print_queue_length(snum, &status);
2735 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
2738 /*******************************************************************
2739 * fill a notify_info_data with the number of jobs queued
2740 ********************************************************************/
2742 static void spoolss_notify_cjobs(int snum,
2743 struct spoolss_Notify *data,
2744 print_queue_struct *queue,
2745 struct spoolss_PrinterInfo2 *pinfo2,
2746 TALLOC_CTX *mem_ctx)
2748 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
2751 /*******************************************************************
2752 * fill a notify_info_data with the average ppm
2753 ********************************************************************/
2755 static void spoolss_notify_average_ppm(int snum,
2756 struct spoolss_Notify *data,
2757 print_queue_struct *queue,
2758 struct spoolss_PrinterInfo2 *pinfo2,
2759 TALLOC_CTX *mem_ctx)
2761 /* always respond 8 pages per minutes */
2762 /* a little hard ! */
2763 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
2766 /*******************************************************************
2767 * fill a notify_info_data with username
2768 ********************************************************************/
2770 static void spoolss_notify_username(int snum,
2771 struct spoolss_Notify *data,
2772 print_queue_struct *queue,
2773 struct spoolss_PrinterInfo2 *pinfo2,
2774 TALLOC_CTX *mem_ctx)
2776 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
2779 /*******************************************************************
2780 * fill a notify_info_data with job status
2781 ********************************************************************/
2783 static void spoolss_notify_job_status(int snum,
2784 struct spoolss_Notify *data,
2785 print_queue_struct *queue,
2786 struct spoolss_PrinterInfo2 *pinfo2,
2787 TALLOC_CTX *mem_ctx)
2789 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
2792 /*******************************************************************
2793 * fill a notify_info_data with job name
2794 ********************************************************************/
2796 static void spoolss_notify_job_name(int snum,
2797 struct spoolss_Notify *data,
2798 print_queue_struct *queue,
2799 struct spoolss_PrinterInfo2 *pinfo2,
2800 TALLOC_CTX *mem_ctx)
2802 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
2805 /*******************************************************************
2806 * fill a notify_info_data with job status
2807 ********************************************************************/
2809 static void spoolss_notify_job_status_string(int snum,
2810 struct spoolss_Notify *data,
2811 print_queue_struct *queue,
2812 struct spoolss_PrinterInfo2 *pinfo2,
2813 TALLOC_CTX *mem_ctx)
2816 * Now we're returning job status codes we just return a "" here. JRA.
2821 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
2824 switch (queue->status) {
2829 p = ""; /* NT provides the paused string */
2838 #endif /* NO LONGER NEEDED. */
2840 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2843 /*******************************************************************
2844 * fill a notify_info_data with job time
2845 ********************************************************************/
2847 static void spoolss_notify_job_time(int snum,
2848 struct spoolss_Notify *data,
2849 print_queue_struct *queue,
2850 struct spoolss_PrinterInfo2 *pinfo2,
2851 TALLOC_CTX *mem_ctx)
2853 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2856 /*******************************************************************
2857 * fill a notify_info_data with job size
2858 ********************************************************************/
2860 static void spoolss_notify_job_size(int snum,
2861 struct spoolss_Notify *data,
2862 print_queue_struct *queue,
2863 struct spoolss_PrinterInfo2 *pinfo2,
2864 TALLOC_CTX *mem_ctx)
2866 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
2869 /*******************************************************************
2870 * fill a notify_info_data with page info
2871 ********************************************************************/
2872 static void spoolss_notify_total_pages(int snum,
2873 struct spoolss_Notify *data,
2874 print_queue_struct *queue,
2875 struct spoolss_PrinterInfo2 *pinfo2,
2876 TALLOC_CTX *mem_ctx)
2878 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
2881 /*******************************************************************
2882 * fill a notify_info_data with pages printed info.
2883 ********************************************************************/
2884 static void spoolss_notify_pages_printed(int snum,
2885 struct spoolss_Notify *data,
2886 print_queue_struct *queue,
2887 struct spoolss_PrinterInfo2 *pinfo2,
2888 TALLOC_CTX *mem_ctx)
2890 /* Add code when back-end tracks this */
2891 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2894 /*******************************************************************
2895 Fill a notify_info_data with job position.
2896 ********************************************************************/
2898 static void spoolss_notify_job_position(int snum,
2899 struct spoolss_Notify *data,
2900 print_queue_struct *queue,
2901 struct spoolss_PrinterInfo2 *pinfo2,
2902 TALLOC_CTX *mem_ctx)
2904 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
2907 /*******************************************************************
2908 Fill a notify_info_data with submitted time.
2909 ********************************************************************/
2911 static void spoolss_notify_submitted_time(int snum,
2912 struct spoolss_Notify *data,
2913 print_queue_struct *queue,
2914 struct spoolss_PrinterInfo2 *pinfo2,
2915 TALLOC_CTX *mem_ctx)
2917 data->data.string.string = NULL;
2918 data->data.string.size = 0;
2920 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
2921 &data->data.string.string,
2922 &data->data.string.size);
2926 struct s_notify_info_data_table
2928 enum spoolss_NotifyType type;
2931 enum spoolss_NotifyTable variable_type;
2932 void (*fn) (int snum, struct spoolss_Notify *data,
2933 print_queue_struct *queue,
2934 struct spoolss_PrinterInfo2 *pinfo2,
2935 TALLOC_CTX *mem_ctx);
2938 /* A table describing the various print notification constants and
2939 whether the notification data is a pointer to a variable sized
2940 buffer, a one value uint32_t or a two value uint32_t. */
2942 static const struct s_notify_info_data_table notify_info_data_table[] =
2944 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2945 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2946 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
2947 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2948 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2949 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
2950 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
2951 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2952 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
2953 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2954 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2955 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2956 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
2957 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
2958 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2959 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
2960 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2961 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2962 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
2963 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
2964 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
2965 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
2966 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
2967 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2968 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
2969 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
2970 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
2971 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
2972 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
2973 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2974 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
2975 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
2976 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
2977 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
2978 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
2979 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
2980 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
2981 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
2982 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
2983 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
2984 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
2985 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
2986 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
2987 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
2988 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
2989 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
2990 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
2991 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
2992 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
2995 /*******************************************************************
2996 Return the variable_type of info_data structure.
2997 ********************************************************************/
2999 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3004 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3005 if ( (notify_info_data_table[i].type == type) &&
3006 (notify_info_data_table[i].field == field) ) {
3007 return notify_info_data_table[i].variable_type;
3011 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3016 /****************************************************************************
3017 ****************************************************************************/
3019 static bool search_notify(enum spoolss_NotifyType type,
3025 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3026 if (notify_info_data_table[i].type == type &&
3027 notify_info_data_table[i].field == field &&
3028 notify_info_data_table[i].fn != NULL) {
3037 /****************************************************************************
3038 ****************************************************************************/
3040 static void construct_info_data(struct spoolss_Notify *info_data,
3041 enum spoolss_NotifyType type,
3042 uint16_t field, int id)
3044 info_data->type = type;
3045 info_data->field.field = field;
3046 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3047 info_data->job_id = id;
3050 /*******************************************************************
3052 * fill a notify_info struct with info asked
3054 ********************************************************************/
3056 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3057 struct spoolss_NotifyInfo *info,
3058 struct spoolss_PrinterInfo2 *pinfo2,
3060 const struct spoolss_NotifyOptionType *option_type,
3062 TALLOC_CTX *mem_ctx)
3065 enum spoolss_NotifyType type;
3068 struct spoolss_Notify *current_data;
3069 print_queue_struct *queue=NULL;
3071 type = option_type->type;
3073 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3074 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3075 option_type->count, lp_servicename(snum)));
3077 for(field_num=0; field_num < option_type->count; field_num++) {
3078 field = option_type->fields[field_num].field;
3080 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3082 if (!search_notify(type, field, &j) )
3085 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3086 struct spoolss_Notify,
3088 if (info->notifies == NULL) {
3089 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3093 current_data = &info->notifies[info->count];
3095 construct_info_data(current_data, type, field, id);
3097 DEBUG(10, ("construct_notify_printer_info: "
3098 "calling [%s] snum=%d printername=[%s])\n",
3099 notify_info_data_table[j].name, snum,
3100 pinfo2->printername));
3102 notify_info_data_table[j].fn(snum, current_data, queue,
3111 /*******************************************************************
3113 * fill a notify_info struct with info asked
3115 ********************************************************************/
3117 static bool construct_notify_jobs_info(print_queue_struct *queue,
3118 struct spoolss_NotifyInfo *info,
3119 struct spoolss_PrinterInfo2 *pinfo2,
3121 const struct spoolss_NotifyOptionType *option_type,