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. */
32 #include "nt_printing.h"
33 #include "srv_spoolss_util.h"
34 #include "../librpc/gen_ndr/srv_spoolss.h"
35 #include "../librpc/gen_ndr/ndr_spoolss_c.h"
36 #include "rpc_client/init_spoolss.h"
37 #include "rpc_client/cli_pipe.h"
38 #include "../libcli/security/security.h"
39 #include "librpc/gen_ndr/ndr_security.h"
41 #include "registry/reg_objects.h"
42 #include "include/printing.h"
44 #include "../librpc/gen_ndr/netlogon.h"
46 #include "printing/notify.h"
48 #include "../libcli/registry/util_reg.h"
49 #include "smbd/smbd.h"
50 #include "smbd/globals.h"
53 #include "rpc_server/spoolss/srv_spoolss_nt.h"
55 #include "libsmb/libsmb.h"
56 #include "printing/printer_list.h"
58 /* macros stolen from s4 spoolss server */
59 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
60 ((info)?ndr_size_##fn(info, level, 0):0)
62 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
63 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
65 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
66 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
68 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
71 #define DBGC_CLASS DBGC_RPC_SRV
73 #ifndef MAX_OPEN_PRINTER_EXS
74 #define MAX_OPEN_PRINTER_EXS 50
77 struct notify_back_channel
;
79 /* structure to store the printer handles */
80 /* and a reference to what it's pointing to */
81 /* and the notify info asked about */
82 /* that's the central struct */
83 struct printer_handle
{
84 struct printer_handle
*prev
, *next
;
85 bool document_started
;
87 uint32 jobid
; /* jobid in printing backend */
89 const char *servername
;
92 uint32 access_granted
;
98 struct spoolss_NotifyOption
*option
;
99 struct policy_handle cli_hnd
;
100 struct notify_back_channel
*cli_chan
;
102 /* are we in a FindNextPrinterChangeNotify() call? */
104 struct messaging_context
*msg_ctx
;
111 /* devmode sent in the OpenPrinter() call */
112 struct spoolss_DeviceMode
*devmode
;
114 /* TODO cache the printer info2 structure */
115 struct spoolss_PrinterInfo2
*info2
;
119 static struct printer_handle
*printers_list
;
121 struct printer_session_counter
{
122 struct printer_session_counter
*next
;
123 struct printer_session_counter
*prev
;
129 static struct printer_session_counter
*counter_list
;
131 struct notify_back_channel
{
132 struct notify_back_channel
*prev
, *next
;
134 /* associated client */
135 struct sockaddr_storage client_address
;
137 /* print notify back-channel pipe handle*/
138 struct rpc_pipe_client
*cli_pipe
;
139 struct dcerpc_binding_handle
*binding_handle
;
140 uint32_t active_connections
;
143 static struct notify_back_channel
*back_channels
;
145 /* Map generic permissions to printer object specific permissions */
147 const struct standard_mapping printer_std_mapping
= {
154 /* Map generic permissions to print server object specific permissions */
156 const struct standard_mapping printserver_std_mapping
= {
163 /* API table for Xcv Monitor functions */
165 struct xcv_api_table
{
167 WERROR(*fn
) (TALLOC_CTX
*mem_ctx
, struct security_token
*token
, DATA_BLOB
*in
, DATA_BLOB
*out
, uint32_t *needed
);
170 static void prune_printername_cache(void);
172 /********************************************************************
173 * Canonicalize servername.
174 ********************************************************************/
176 static const char *canon_servername(const char *servername
)
178 const char *pservername
= servername
;
179 while (*pservername
== '\\') {
185 /* translate between internal status numbers and NT status numbers */
186 static int nt_printj_status(int v
)
192 return JOB_STATUS_PAUSED
;
194 return JOB_STATUS_SPOOLING
;
196 return JOB_STATUS_PRINTING
;
198 return JOB_STATUS_ERROR
;
200 return JOB_STATUS_DELETING
;
202 return JOB_STATUS_OFFLINE
;
204 return JOB_STATUS_PAPEROUT
;
206 return JOB_STATUS_PRINTED
;
208 return JOB_STATUS_DELETED
;
210 return JOB_STATUS_BLOCKED_DEVQ
;
211 case LPQ_USER_INTERVENTION
:
212 return JOB_STATUS_USER_INTERVENTION
;
217 static int nt_printq_status(int v
)
221 return PRINTER_STATUS_PAUSED
;
230 /***************************************************************************
231 Disconnect from the client
232 ****************************************************************************/
234 static void srv_spoolss_replycloseprinter(int snum
,
235 struct printer_handle
*prn_hnd
)
241 * Tell the specific printing tdb we no longer want messages for this printer
242 * by deregistering our PID.
245 if (!print_notify_deregister_pid(snum
)) {
246 DEBUG(0, ("Failed to register our pid for printer %s\n",
247 lp_const_servicename(snum
)));
250 /* weird if the test succeeds !!! */
251 if (prn_hnd
->notify
.cli_chan
== NULL
||
252 prn_hnd
->notify
.cli_chan
->active_connections
== 0) {
253 DEBUG(0, ("Trying to close unexisting backchannel!\n"));
254 DLIST_REMOVE(back_channels
, prn_hnd
->notify
.cli_chan
);
255 TALLOC_FREE(prn_hnd
->notify
.cli_chan
);
259 status
= dcerpc_spoolss_ReplyClosePrinter(
260 prn_hnd
->notify
.cli_chan
->binding_handle
,
262 &prn_hnd
->notify
.cli_hnd
,
264 if (!NT_STATUS_IS_OK(status
)) {
265 DEBUG(0, ("dcerpc_spoolss_ReplyClosePrinter failed [%s].\n",
267 result
= ntstatus_to_werror(status
);
268 } else if (!W_ERROR_IS_OK(result
)) {
269 DEBUG(0, ("reply_close_printer failed [%s].\n",
270 win_errstr(result
)));
273 /* if it's the last connection, deconnect the IPC$ share */
274 if (prn_hnd
->notify
.cli_chan
->active_connections
== 1) {
276 prn_hnd
->notify
.cli_chan
->binding_handle
= NULL
;
277 cli_shutdown(rpc_pipe_np_smb_conn(prn_hnd
->notify
.cli_chan
->cli_pipe
));
278 DLIST_REMOVE(back_channels
, prn_hnd
->notify
.cli_chan
);
279 TALLOC_FREE(prn_hnd
->notify
.cli_chan
);
281 if (prn_hnd
->notify
.msg_ctx
!= NULL
) {
282 messaging_deregister(prn_hnd
->notify
.msg_ctx
,
283 MSG_PRINTER_NOTIFY2
, NULL
);
286 * Tell the serverid.tdb we're no longer
287 * interested in printer notify messages.
290 serverid_register_msg_flags(
291 messaging_server_id(prn_hnd
->notify
.msg_ctx
),
292 false, FLAG_MSG_PRINT_NOTIFY
);
296 if (prn_hnd
->notify
.cli_chan
) {
297 prn_hnd
->notify
.cli_chan
->active_connections
--;
301 /****************************************************************************
302 Functions to free a printer entry datastruct.
303 ****************************************************************************/
305 static int printer_entry_destructor(struct printer_handle
*Printer
)
307 if (Printer
->notify
.cli_chan
!= NULL
&&
308 Printer
->notify
.cli_chan
->active_connections
> 0) {
311 switch(Printer
->printer_type
) {
313 srv_spoolss_replycloseprinter(snum
, Printer
);
317 snum
= print_queue_snum(Printer
->sharename
);
319 srv_spoolss_replycloseprinter(snum
, Printer
);
327 Printer
->notify
.flags
=0;
328 Printer
->notify
.options
=0;
329 Printer
->notify
.localmachine
[0]='\0';
330 Printer
->notify
.printerlocal
=0;
331 TALLOC_FREE(Printer
->notify
.option
);
332 TALLOC_FREE(Printer
->devmode
);
334 /* Remove from the internal list. */
335 DLIST_REMOVE(printers_list
, Printer
);
339 /****************************************************************************
340 find printer index by handle
341 ****************************************************************************/
343 static struct printer_handle
*find_printer_index_by_hnd(struct pipes_struct
*p
,
344 struct policy_handle
*hnd
)
346 struct printer_handle
*find_printer
= NULL
;
348 if(!find_policy_by_hnd(p
,hnd
,(void **)(void *)&find_printer
)) {
349 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
356 /****************************************************************************
357 Close printer index by handle.
358 ****************************************************************************/
360 static bool close_printer_handle(struct pipes_struct
*p
, struct policy_handle
*hnd
)
362 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
365 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
370 close_policy_hnd(p
, hnd
);
375 /****************************************************************************
376 Delete a printer given a handle.
377 ****************************************************************************/
379 static WERROR
delete_printer_hook(TALLOC_CTX
*ctx
, struct security_token
*token
,
380 const char *sharename
,
381 struct messaging_context
*msg_ctx
)
383 char *cmd
= lp_deleteprinter_cmd();
384 char *command
= NULL
;
386 bool is_print_op
= false;
388 /* can't fail if we don't try */
393 command
= talloc_asprintf(ctx
,
400 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
402 DEBUG(10,("Running [%s]\n", command
));
404 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
409 if ( (ret
= smbrun(command
, NULL
)) == 0 ) {
410 /* Tell everyone we updated smb.conf. */
411 message_send_all(msg_ctx
, MSG_SMB_CONF_UPDATED
, NULL
, 0, NULL
);
417 /********** END SePrintOperatorPrivlege BLOCK **********/
419 DEBUGADD(10,("returned [%d]\n", ret
));
421 TALLOC_FREE(command
);
424 return WERR_BADFID
; /* What to return here? */
426 /* go ahead and re-read the services immediately */
428 reload_services(msg_ctx
, -1, false);
431 if ( lp_servicenumber( sharename
) >= 0 )
432 return WERR_ACCESS_DENIED
;
437 /****************************************************************************
438 Delete a printer given a handle.
439 ****************************************************************************/
441 static WERROR
delete_printer_handle(struct pipes_struct
*p
, struct policy_handle
*hnd
)
443 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
447 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
453 * It turns out that Windows allows delete printer on a handle
454 * opened by an admin user, then used on a pipe handle created
455 * by an anonymous user..... but they're working on security.... riiight !
459 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
460 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
461 return WERR_ACCESS_DENIED
;
464 /* this does not need a become root since the access check has been
465 done on the handle already */
467 result
= winreg_delete_printer_key(p
->mem_ctx
,
468 get_session_info_system(),
472 if (!W_ERROR_IS_OK(result
)) {
473 DEBUG(3,("Error deleting printer %s\n", Printer
->sharename
));
477 result
= delete_printer_hook(p
->mem_ctx
, p
->session_info
->security_token
,
478 Printer
->sharename
, p
->msg_ctx
);
479 if (!W_ERROR_IS_OK(result
)) {
482 prune_printername_cache();
486 /****************************************************************************
487 Return the snum of a printer corresponding to an handle.
488 ****************************************************************************/
490 static bool get_printer_snum(struct pipes_struct
*p
, struct policy_handle
*hnd
,
491 int *number
, struct share_params
**params
)
493 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
496 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
501 switch (Printer
->printer_type
) {
503 DEBUG(4,("short name:%s\n", Printer
->sharename
));
504 *number
= print_queue_snum(Printer
->sharename
);
505 return (*number
!= -1);
513 /****************************************************************************
514 Set printer handle type.
515 Check if it's \\server or \\server\printer
516 ****************************************************************************/
518 static bool set_printer_hnd_printertype(struct printer_handle
*Printer
, const char *handlename
)
520 DEBUG(3,("Setting printer type=%s\n", handlename
));
522 /* it's a print server */
523 if (handlename
&& *handlename
=='\\' && *(handlename
+1)=='\\' && !strchr_m(handlename
+2, '\\')) {
524 DEBUGADD(4,("Printer is a print server\n"));
525 Printer
->printer_type
= SPLHND_SERVER
;
527 /* it's a printer (set_printer_hnd_name() will handle port monitors */
529 DEBUGADD(4,("Printer is a printer\n"));
530 Printer
->printer_type
= SPLHND_PRINTER
;
536 static void prune_printername_cache_fn(const char *key
, const char *value
,
537 time_t timeout
, void *private_data
)
542 static void prune_printername_cache(void)
544 gencache_iterate(prune_printername_cache_fn
, NULL
, "PRINTERNAME/*");
547 /****************************************************************************
548 Set printer handle name.. Accept names like \\server, \\server\printer,
549 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
550 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
551 XcvDataPort() interface.
552 ****************************************************************************/
554 static WERROR
set_printer_hnd_name(TALLOC_CTX
*mem_ctx
,
555 const struct auth_serversupplied_info
*session_info
,
556 struct messaging_context
*msg_ctx
,
557 struct printer_handle
*Printer
,
558 const char *handlename
)
561 int n_services
=lp_numservices();
563 const char *printername
;
564 const char *servername
= NULL
;
567 struct spoolss_PrinterInfo2
*info2
= NULL
;
572 * Hopefully nobody names his printers like this. Maybe \ or ,
573 * are illegal in printer names even?
575 const char printer_not_found
[] = "Printer \\, !@#$%^&*( not found";
579 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename
,
580 (unsigned long)strlen(handlename
)));
582 aprinter
= discard_const_p(char, handlename
);
583 if ( *handlename
== '\\' ) {
584 servername
= canon_servername(handlename
);
585 if ( (aprinter
= strchr_m( servername
, '\\' )) != NULL
) {
589 if (!is_myname_or_ipaddr(servername
)) {
590 return WERR_INVALID_PRINTER_NAME
;
592 Printer
->servername
= talloc_asprintf(Printer
, "\\\\%s", servername
);
593 if (Printer
->servername
== NULL
) {
598 if (Printer
->printer_type
== SPLHND_SERVER
) {
602 if (Printer
->printer_type
!= SPLHND_PRINTER
) {
603 return WERR_INVALID_HANDLE
;
606 DEBUGADD(5, ("searching for [%s]\n", aprinter
));
608 p
= strchr(aprinter
, ',');
615 if (strncmp(p
, "DrvConvert", strlen("DrvConvert")) == 0) {
617 } else if (strncmp(p
, "LocalOnly", strlen("LocalOnly")) == 0) {
623 DEBUGADD(5, ("stripped handlename: [%s]\n", aprinter
));
626 /* check for the Port Monitor Interface */
627 if ( strequal( aprinter
, SPL_XCV_MONITOR_TCPMON
) ) {
628 Printer
->printer_type
= SPLHND_PORTMON_TCP
;
629 fstrcpy(sname
, SPL_XCV_MONITOR_TCPMON
);
632 else if ( strequal( aprinter
, SPL_XCV_MONITOR_LOCALMON
) ) {
633 Printer
->printer_type
= SPLHND_PORTMON_LOCAL
;
634 fstrcpy(sname
, SPL_XCV_MONITOR_LOCALMON
);
639 * With hundreds of printers, the "for" loop iterating all
640 * shares can be quite expensive, as it is done on every
641 * OpenPrinter. The loop maps "aprinter" to "sname", the
642 * result of which we cache in gencache.
645 cache_key
= talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
647 if ((cache_key
!= NULL
) && gencache_get(cache_key
, &tmp
, NULL
)) {
649 found
= (strcmp(tmp
, printer_not_found
) != 0);
651 DEBUG(4, ("Printer %s not found\n", aprinter
));
653 return WERR_INVALID_PRINTER_NAME
;
659 /* Search all sharenames first as this is easier than pulling
660 the printer_info_2 off of disk. Don't use find_service() since
661 that calls out to map_username() */
663 /* do another loop to look for printernames */
664 for (snum
= 0; !found
&& snum
< n_services
; snum
++) {
665 const char *printer
= lp_const_servicename(snum
);
667 /* no point going on if this is not a printer */
668 if (!(lp_snum_ok(snum
) && lp_print_ok(snum
))) {
672 /* ignore [printers] share */
673 if (strequal(printer
, "printers")) {
677 fstrcpy(sname
, printer
);
678 if (strequal(aprinter
, printer
)) {
683 /* no point looking up the printer object if
684 we aren't allowing printername != sharename */
685 if (lp_force_printername(snum
)) {
689 result
= winreg_get_printer(mem_ctx
,
694 if ( !W_ERROR_IS_OK(result
) ) {
695 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
696 sname
, win_errstr(result
)));
700 printername
= strrchr(info2
->printername
, '\\');
701 if (printername
== NULL
) {
702 printername
= info2
->printername
;
707 if (strequal(printername
, aprinter
)) {
712 DEBUGADD(10, ("printername: %s\n", printername
));
718 if (cache_key
!= NULL
) {
719 gencache_set(cache_key
, printer_not_found
,
721 TALLOC_FREE(cache_key
);
723 DEBUGADD(4,("Printer not found\n"));
724 return WERR_INVALID_PRINTER_NAME
;
727 if (cache_key
!= NULL
) {
728 gencache_set(cache_key
, sname
, time(NULL
)+300);
729 TALLOC_FREE(cache_key
);
732 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter
, sname
));
734 strlcpy(Printer
->sharename
, sname
, sizeof(Printer
->sharename
));
739 /****************************************************************************
740 Find first available printer slot. creates a printer handle for you.
741 ****************************************************************************/
743 static WERROR
open_printer_hnd(struct pipes_struct
*p
,
744 struct policy_handle
*hnd
,
746 uint32_t access_granted
)
748 struct printer_handle
*new_printer
;
751 DEBUG(10,("open_printer_hnd: name [%s]\n", name
));
753 new_printer
= talloc_zero(p
->mem_ctx
, struct printer_handle
);
754 if (new_printer
== NULL
) {
757 talloc_set_destructor(new_printer
, printer_entry_destructor
);
759 /* This also steals the printer_handle on the policy_handle */
760 if (!create_policy_hnd(p
, hnd
, new_printer
)) {
761 TALLOC_FREE(new_printer
);
762 return WERR_INVALID_HANDLE
;
765 /* Add to the internal list. */
766 DLIST_ADD(printers_list
, new_printer
);
768 new_printer
->notify
.option
=NULL
;
770 if (!set_printer_hnd_printertype(new_printer
, name
)) {
771 close_printer_handle(p
, hnd
);
772 return WERR_INVALID_HANDLE
;
775 result
= set_printer_hnd_name(p
->mem_ctx
,
776 get_session_info_system(),
779 if (!W_ERROR_IS_OK(result
)) {
780 close_printer_handle(p
, hnd
);
784 new_printer
->access_granted
= access_granted
;
786 DEBUG(5, ("%d printer handles active\n",
787 (int)num_pipe_handles(p
)));
792 /***************************************************************************
793 check to see if the client motify handle is monitoring the notification
794 given by (notify_type, notify_field).
795 **************************************************************************/
797 static bool is_monitoring_event_flags(uint32_t flags
, uint16_t notify_type
,
798 uint16_t notify_field
)
803 static bool is_monitoring_event(struct printer_handle
*p
, uint16_t notify_type
,
804 uint16_t notify_field
)
806 struct spoolss_NotifyOption
*option
= p
->notify
.option
;
810 * Flags should always be zero when the change notify
811 * is registered by the client's spooler. A user Win32 app
812 * might use the flags though instead of the NOTIFY_OPTION_INFO
821 return is_monitoring_event_flags(
822 p
->notify
.flags
, notify_type
, notify_field
);
824 for (i
= 0; i
< option
->count
; i
++) {
826 /* Check match for notify_type */
828 if (option
->types
[i
].type
!= notify_type
)
831 /* Check match for field */
833 for (j
= 0; j
< option
->types
[i
].count
; j
++) {
834 if (option
->types
[i
].fields
[j
].field
== notify_field
) {
840 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
841 p
->servername
, p
->sharename
, notify_type
, notify_field
));
846 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
847 _data->data.integer[0] = _integer; \
848 _data->data.integer[1] = 0;
851 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
852 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
853 if (!_data->data.string.string) {\
854 _data->data.string.size = 0; \
856 _data->data.string.size = strlen_m_term(_p) * 2;
858 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
859 _data->data.devmode.devmode = _devmode;
861 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
862 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
863 if (!_data->data.sd.sd) { \
864 _data->data.sd.sd_size = 0; \
866 _data->data.sd.sd_size = \
867 ndr_size_security_descriptor(_data->data.sd.sd, 0);
869 static void init_systemtime_buffer(TALLOC_CTX
*mem_ctx
,
874 struct spoolss_Time st
;
878 if (!init_systemtime(&st
, t
)) {
882 p
= talloc_array(mem_ctx
, char, len
);
888 * Systemtime must be linearized as a set of UINT16's.
889 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
892 SSVAL(p
, 0, st
.year
);
893 SSVAL(p
, 2, st
.month
);
894 SSVAL(p
, 4, st
.day_of_week
);
896 SSVAL(p
, 8, st
.hour
);
897 SSVAL(p
, 10, st
.minute
);
898 SSVAL(p
, 12, st
.second
);
899 SSVAL(p
, 14, st
.millisecond
);
905 /* Convert a notification message to a struct spoolss_Notify */
907 static void notify_one_value(struct spoolss_notify_msg
*msg
,
908 struct spoolss_Notify
*data
,
911 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, msg
->notify
.value
[0]);
914 static void notify_string(struct spoolss_notify_msg
*msg
,
915 struct spoolss_Notify
*data
,
918 /* The length of the message includes the trailing \0 */
920 data
->data
.string
.size
= msg
->len
* 2;
921 data
->data
.string
.string
= talloc_strdup(mem_ctx
, msg
->notify
.data
);
922 if (!data
->data
.string
.string
) {
923 data
->data
.string
.size
= 0;
928 static void notify_system_time(struct spoolss_notify_msg
*msg
,
929 struct spoolss_Notify
*data
,
932 data
->data
.string
.string
= NULL
;
933 data
->data
.string
.size
= 0;
935 if (msg
->len
!= sizeof(time_t)) {
936 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
941 init_systemtime_buffer(mem_ctx
, gmtime((time_t *)msg
->notify
.data
),
942 &data
->data
.string
.string
,
943 &data
->data
.string
.size
);
946 struct notify2_message_table
{
948 void (*fn
)(struct spoolss_notify_msg
*msg
,
949 struct spoolss_Notify
*data
, TALLOC_CTX
*mem_ctx
);
952 static struct notify2_message_table printer_notify_table
[] = {
953 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string
},
954 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string
},
955 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string
},
956 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string
},
957 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string
},
958 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string
},
959 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string
},
960 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL
},
961 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string
},
962 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string
},
963 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL
},
964 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string
},
965 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL
},
966 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value
},
967 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value
},
968 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL
},
969 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL
},
970 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL
},
971 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value
},
974 static struct notify2_message_table job_notify_table
[] = {
975 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL
},
976 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL
},
977 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL
},
978 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string
},
979 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL
},
980 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL
},
981 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL
},
982 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL
},
983 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL
},
984 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL
},
985 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value
},
986 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL
},
987 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL
},
988 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string
},
989 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL
},
990 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL
},
991 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time
},
992 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL
},
993 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL
},
994 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL
},
995 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value
},
996 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL
},
997 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value
},
998 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL
},
1002 /***********************************************************************
1003 Allocate talloc context for container object
1004 **********************************************************************/
1006 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1011 ctr
->ctx
= talloc_init("notify_msg_ctr_init %p", ctr
);
1016 /***********************************************************************
1017 release all allocated memory and zero out structure
1018 **********************************************************************/
1020 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1026 talloc_destroy(ctr
->ctx
);
1033 /***********************************************************************
1034 **********************************************************************/
1036 static TALLOC_CTX
* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1044 /***********************************************************************
1045 **********************************************************************/
1047 static SPOOLSS_NOTIFY_MSG_GROUP
* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR
*ctr
, uint32_t idx
)
1049 if ( !ctr
|| !ctr
->msg_groups
)
1052 if ( idx
>= ctr
->num_groups
)
1055 return &ctr
->msg_groups
[idx
];
1059 /***********************************************************************
1060 How many groups of change messages do we have ?
1061 **********************************************************************/
1063 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1068 return ctr
->num_groups
;
1071 /***********************************************************************
1072 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1073 **********************************************************************/
1075 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR
*ctr
, SPOOLSS_NOTIFY_MSG
*msg
)
1077 SPOOLSS_NOTIFY_MSG_GROUP
*groups
= NULL
;
1078 SPOOLSS_NOTIFY_MSG_GROUP
*msg_grp
= NULL
;
1079 SPOOLSS_NOTIFY_MSG
*msg_list
= NULL
;
1085 /* loop over all groups looking for a matching printer name */
1087 for ( i
=0; i
<ctr
->num_groups
; i
++ ) {
1088 if ( strcmp(ctr
->msg_groups
[i
].printername
, msg
->printer
) == 0 )
1092 /* add a new group? */
1094 if ( i
== ctr
->num_groups
) {
1097 if ( !(groups
= TALLOC_REALLOC_ARRAY( ctr
->ctx
, ctr
->msg_groups
, SPOOLSS_NOTIFY_MSG_GROUP
, ctr
->num_groups
)) ) {
1098 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1101 ctr
->msg_groups
= groups
;
1103 /* clear the new entry and set the printer name */
1105 ZERO_STRUCT( ctr
->msg_groups
[ctr
->num_groups
-1] );
1106 fstrcpy( ctr
->msg_groups
[ctr
->num_groups
-1].printername
, msg
->printer
);
1109 /* add the change messages; 'i' is the correct index now regardless */
1111 msg_grp
= &ctr
->msg_groups
[i
];
1113 msg_grp
->num_msgs
++;
1115 if ( !(msg_list
= TALLOC_REALLOC_ARRAY( ctr
->ctx
, msg_grp
->msgs
, SPOOLSS_NOTIFY_MSG
, msg_grp
->num_msgs
)) ) {
1116 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp
->num_msgs
));
1119 msg_grp
->msgs
= msg_list
;
1121 new_slot
= msg_grp
->num_msgs
-1;
1122 memcpy( &msg_grp
->msgs
[new_slot
], msg
, sizeof(SPOOLSS_NOTIFY_MSG
) );
1124 /* need to allocate own copy of data */
1126 if ( msg
->len
!= 0 )
1127 msg_grp
->msgs
[new_slot
].notify
.data
= (char *)
1128 TALLOC_MEMDUP( ctr
->ctx
, msg
->notify
.data
, msg
->len
);
1130 return ctr
->num_groups
;
1133 static void construct_info_data(struct spoolss_Notify
*info_data
,
1134 enum spoolss_NotifyType type
,
1135 uint16_t field
, int id
);
1137 /***********************************************************************
1138 Send a change notication message on all handles which have a call
1140 **********************************************************************/
1142 static int build_notify2_messages(TALLOC_CTX
*mem_ctx
,
1143 struct printer_handle
*prn_hnd
,
1144 SPOOLSS_NOTIFY_MSG
*messages
,
1146 struct spoolss_Notify
**_notifies
,
1149 struct spoolss_Notify
*notifies
;
1150 SPOOLSS_NOTIFY_MSG
*msg
;
1155 notifies
= talloc_zero_array(mem_ctx
,
1156 struct spoolss_Notify
, num_msgs
);
1161 for (i
= 0; i
< num_msgs
; i
++) {
1165 /* Are we monitoring this event? */
1167 if (!is_monitoring_event(prn_hnd
, msg
->type
, msg
->field
)) {
1171 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1172 "for printer [%s]\n",
1173 msg
->type
, msg
->field
, prn_hnd
->sharename
));
1176 * if the is a printer notification handle and not a job
1177 * notification type, then set the id to 0.
1178 * Otherwise just use what was specified in the message.
1180 * When registering change notification on a print server
1181 * handle we always need to send back the id (snum) matching
1182 * the printer for which the change took place.
1183 * For change notify registered on a printer handle,
1184 * this does not matter and the id should be 0.
1189 if ((msg
->type
== PRINTER_NOTIFY_TYPE
) &&
1190 (prn_hnd
->printer_type
== SPLHND_PRINTER
)) {
1196 /* Convert unix jobid to smb jobid */
1198 if (msg
->flags
& SPOOLSS_NOTIFY_MSG_UNIX_JOBID
) {
1199 id
= sysjob_to_jobid(msg
->id
);
1202 DEBUG(3, ("no such unix jobid %d\n",
1208 construct_info_data(¬ifies
[count
],
1209 msg
->type
, msg
->field
, id
);
1212 case PRINTER_NOTIFY_TYPE
:
1213 if (printer_notify_table
[msg
->field
].fn
) {
1214 printer_notify_table
[msg
->field
].fn(msg
,
1215 ¬ifies
[count
], mem_ctx
);
1219 case JOB_NOTIFY_TYPE
:
1220 if (job_notify_table
[msg
->field
].fn
) {
1221 job_notify_table
[msg
->field
].fn(msg
,
1222 ¬ifies
[count
], mem_ctx
);
1227 DEBUG(5, ("Unknown notification type %d\n",
1235 *_notifies
= notifies
;
1241 static int send_notify2_printer(TALLOC_CTX
*mem_ctx
,
1242 struct printer_handle
*prn_hnd
,
1243 SPOOLSS_NOTIFY_MSG_GROUP
*msg_group
)
1245 struct spoolss_Notify
*notifies
;
1247 union spoolss_ReplyPrinterInfo info
;
1248 struct spoolss_NotifyInfo info0
;
1249 uint32_t reply_result
;
1254 /* Is there notification on this handle? */
1255 if (prn_hnd
->notify
.cli_chan
== NULL
||
1256 prn_hnd
->notify
.cli_chan
->active_connections
== 0) {
1260 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1261 prn_hnd
->servername
, prn_hnd
->sharename
));
1263 /* For this printer? Print servers always receive notifications. */
1264 if ((prn_hnd
->printer_type
== SPLHND_PRINTER
) &&
1265 (!strequal(msg_group
->printername
, prn_hnd
->sharename
))) {
1269 DEBUG(10,("Our printer\n"));
1271 /* build the array of change notifications */
1272 ret
= build_notify2_messages(mem_ctx
, prn_hnd
,
1274 msg_group
->num_msgs
,
1280 info0
.version
= 0x2;
1281 info0
.flags
= count
? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED
;
1282 info0
.count
= count
;
1283 info0
.notifies
= notifies
;
1285 info
.info0
= &info0
;
1287 status
= dcerpc_spoolss_RouterReplyPrinterEx(
1288 prn_hnd
->notify
.cli_chan
->binding_handle
,
1290 &prn_hnd
->notify
.cli_hnd
,
1291 prn_hnd
->notify
.change
, /* color */
1292 prn_hnd
->notify
.flags
,
1294 0, /* reply_type, must be 0 */
1296 if (!NT_STATUS_IS_OK(status
)) {
1297 DEBUG(1, ("dcerpc_spoolss_RouterReplyPrinterEx to client: %s "
1299 prn_hnd
->notify
.cli_chan
->cli_pipe
->srv_name_slash
,
1300 nt_errstr(status
)));
1301 werr
= ntstatus_to_werror(status
);
1302 } else if (!W_ERROR_IS_OK(werr
)) {
1303 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1305 prn_hnd
->notify
.cli_chan
->cli_pipe
->srv_name_slash
,
1308 switch (reply_result
) {
1311 case PRINTER_NOTIFY_INFO_DISCARDED
:
1312 case PRINTER_NOTIFY_INFO_DISCARDNOTED
:
1313 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH
:
1322 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR
*ctr
, uint32_t idx
)
1324 struct printer_handle
*p
;
1325 TALLOC_CTX
*mem_ctx
= notify_ctr_getctx( ctr
);
1326 SPOOLSS_NOTIFY_MSG_GROUP
*msg_group
= notify_ctr_getgroup( ctr
, idx
);
1330 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1334 if (!msg_group
->msgs
) {
1335 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1339 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group
->printername
));
1341 /* loop over all printers */
1343 for (p
= printers_list
; p
; p
= p
->next
) {
1344 ret
= send_notify2_printer(mem_ctx
, p
, msg_group
);
1351 DEBUG(8,("send_notify2_changes: Exit...\n"));
1355 /***********************************************************************
1356 **********************************************************************/
1358 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG
*msg
, struct timeval
*tv
, void *buf
, size_t len
)
1361 uint32_t tv_sec
, tv_usec
;
1364 /* Unpack message */
1366 offset
+= tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "f",
1369 offset
+= tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "ddddddd",
1371 &msg
->type
, &msg
->field
, &msg
->id
, &msg
->len
, &msg
->flags
);
1374 tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "dd",
1375 &msg
->notify
.value
[0], &msg
->notify
.value
[1]);
1377 tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "B",
1378 &msg
->len
, &msg
->notify
.data
);
1380 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1381 msg
->printer
, (unsigned int)msg
->id
, msg
->type
, msg
->field
, msg
->flags
));
1383 tv
->tv_sec
= tv_sec
;
1384 tv
->tv_usec
= tv_usec
;
1387 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg
->notify
.value
[0],
1388 msg
->notify
.value
[1]));
1390 dump_data(3, (uint8_t *)msg
->notify
.data
, msg
->len
);
1395 /********************************************************************
1396 Receive a notify2 message list
1397 ********************************************************************/
1399 static void receive_notify2_message_list(struct messaging_context
*msg
,
1402 struct server_id server_id
,
1405 size_t msg_count
, i
;
1406 char *buf
= (char *)data
->data
;
1409 SPOOLSS_NOTIFY_MSG notify
;
1410 SPOOLSS_NOTIFY_MSG_CTR messages
;
1413 if (data
->length
< 4) {
1414 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1418 msg_count
= IVAL(buf
, 0);
1421 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count
));
1423 if (msg_count
== 0) {
1424 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1428 /* initialize the container */
1430 ZERO_STRUCT( messages
);
1431 notify_msg_ctr_init( &messages
);
1434 * build message groups for each printer identified
1435 * in a change_notify msg. Remember that a PCN message
1436 * includes the handle returned for the srv_spoolss_replyopenprinter()
1437 * call. Therefore messages are grouped according to printer handle.
1440 for ( i
=0; i
<msg_count
; i
++ ) {
1441 struct timeval msg_tv
;
1443 if (msg_ptr
+ 4 - buf
> data
->length
) {
1444 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1448 msg_len
= IVAL(msg_ptr
,0);
1451 if (msg_ptr
+ msg_len
- buf
> data
->length
) {
1452 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1456 /* unpack messages */
1458 ZERO_STRUCT( notify
);
1459 notify2_unpack_msg( ¬ify
, &msg_tv
, msg_ptr
, msg_len
);
1462 /* add to correct list in container */
1464 notify_msg_ctr_addmsg( &messages
, ¬ify
);
1466 /* free memory that might have been allocated by notify2_unpack_msg() */
1468 if ( notify
.len
!= 0 )
1469 SAFE_FREE( notify
.notify
.data
);
1472 /* process each group of messages */
1474 num_groups
= notify_msg_ctr_numgroups( &messages
);
1475 for ( i
=0; i
<num_groups
; i
++ )
1476 send_notify2_changes( &messages
, i
);
1481 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1482 (uint32_t)msg_count
));
1484 notify_msg_ctr_destroy( &messages
);
1489 /********************************************************************
1490 Send a message to ourself about new driver being installed
1491 so we can upgrade the information for each printer bound to this
1493 ********************************************************************/
1495 static bool srv_spoolss_drv_upgrade_printer(const char *drivername
,
1496 struct messaging_context
*msg_ctx
)
1498 int len
= strlen(drivername
);
1503 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1506 messaging_send_buf(msg_ctx
, messaging_server_id(msg_ctx
),
1507 MSG_PRINTER_DRVUPGRADE
,
1508 (const uint8_t *)drivername
, len
+1);
1513 void srv_spoolss_cleanup(void)
1515 struct printer_session_counter
*session_counter
;
1517 for (session_counter
= counter_list
;
1518 session_counter
!= NULL
;
1519 session_counter
= counter_list
) {
1520 DLIST_REMOVE(counter_list
, session_counter
);
1521 TALLOC_FREE(session_counter
);
1525 /**********************************************************************
1526 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1527 over all printers, upgrading ones as necessary
1528 **********************************************************************/
1530 void do_drv_upgrade_printer(struct messaging_context
*msg
,
1533 struct server_id server_id
,
1536 TALLOC_CTX
*tmp_ctx
;
1537 struct auth_serversupplied_info
*session_info
= NULL
;
1538 struct spoolss_PrinterInfo2
*pinfo2
;
1541 const char *drivername
;
1543 int n_services
= lp_numservices();
1545 tmp_ctx
= talloc_new(NULL
);
1546 if (!tmp_ctx
) return;
1548 status
= make_session_info_system(tmp_ctx
, &session_info
);
1549 if (!NT_STATUS_IS_OK(status
)) {
1550 DEBUG(0, ("do_drv_upgrade_printer: "
1551 "Could not create system session_info\n"));
1555 drivername
= talloc_strndup(tmp_ctx
, (const char *)data
->data
, data
->length
);
1557 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1561 DEBUG(10, ("do_drv_upgrade_printer: "
1562 "Got message for new driver [%s]\n", drivername
));
1564 /* Iterate the printer list */
1566 for (snum
= 0; snum
< n_services
; snum
++) {
1567 if (!lp_snum_ok(snum
) || !lp_print_ok(snum
)) {
1571 /* ignore [printers] share */
1572 if (strequal(lp_const_servicename(snum
), "printers")) {
1576 result
= winreg_get_printer(tmp_ctx
, session_info
, msg
,
1577 lp_const_servicename(snum
),
1580 if (!W_ERROR_IS_OK(result
)) {
1584 if (!pinfo2
->drivername
) {
1588 if (strcmp(drivername
, pinfo2
->drivername
) != 0) {
1592 DEBUG(6,("Updating printer [%s]\n", pinfo2
->printername
));
1594 /* all we care about currently is the change_id */
1595 result
= winreg_printer_update_changeid(tmp_ctx
,
1598 pinfo2
->printername
);
1600 if (!W_ERROR_IS_OK(result
)) {
1601 DEBUG(3, ("do_drv_upgrade_printer: "
1602 "Failed to update changeid [%s]\n",
1603 win_errstr(result
)));
1609 talloc_free(tmp_ctx
);
1612 /********************************************************************
1613 Update the cache for all printq's with a registered client
1615 ********************************************************************/
1617 void update_monitored_printq_cache(struct messaging_context
*msg_ctx
)
1619 struct printer_handle
*printer
= printers_list
;
1622 /* loop through all printers and update the cache where
1623 a client is connected */
1625 if ((printer
->printer_type
== SPLHND_PRINTER
) &&
1626 ((printer
->notify
.cli_chan
!= NULL
) &&
1627 (printer
->notify
.cli_chan
->active_connections
> 0))) {
1628 snum
= print_queue_snum(printer
->sharename
);
1629 print_queue_status(msg_ctx
, snum
, NULL
, NULL
);
1632 printer
= printer
->next
;
1638 /****************************************************************
1639 _spoolss_OpenPrinter
1640 ****************************************************************/
1642 WERROR
_spoolss_OpenPrinter(struct pipes_struct
*p
,
1643 struct spoolss_OpenPrinter
*r
)
1645 struct spoolss_OpenPrinterEx e
;
1648 ZERO_STRUCT(e
.in
.userlevel
);
1650 e
.in
.printername
= r
->in
.printername
;
1651 e
.in
.datatype
= r
->in
.datatype
;
1652 e
.in
.devmode_ctr
= r
->in
.devmode_ctr
;
1653 e
.in
.access_mask
= r
->in
.access_mask
;
1656 e
.out
.handle
= r
->out
.handle
;
1658 werr
= _spoolss_OpenPrinterEx(p
, &e
);
1660 if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
1661 /* OpenPrinterEx returns this for a bad
1662 * printer name. We must return WERR_INVALID_PRINTER_NAME
1665 werr
= WERR_INVALID_PRINTER_NAME
;
1671 static WERROR
copy_devicemode(TALLOC_CTX
*mem_ctx
,
1672 struct spoolss_DeviceMode
*orig
,
1673 struct spoolss_DeviceMode
**dest
)
1675 struct spoolss_DeviceMode
*dm
;
1677 dm
= talloc(mem_ctx
, struct spoolss_DeviceMode
);
1682 /* copy all values, then duplicate strings and structs */
1685 dm
->devicename
= talloc_strdup(dm
, orig
->devicename
);
1686 if (!dm
->devicename
) {
1689 dm
->formname
= talloc_strdup(dm
, orig
->formname
);
1690 if (!dm
->formname
) {
1693 if (orig
->driverextra_data
.data
) {
1694 dm
->driverextra_data
.data
=
1695 (uint8_t *) talloc_memdup(dm
, orig
->driverextra_data
.data
,
1696 orig
->driverextra_data
.length
);
1697 if (!dm
->driverextra_data
.data
) {
1706 /****************************************************************
1707 _spoolss_OpenPrinterEx
1708 ****************************************************************/
1710 WERROR
_spoolss_OpenPrinterEx(struct pipes_struct
*p
,
1711 struct spoolss_OpenPrinterEx
*r
)
1714 struct printer_handle
*Printer
=NULL
;
1717 if (!r
->in
.printername
) {
1718 return WERR_INVALID_PARAM
;
1721 if (r
->in
.level
> 3) {
1722 return WERR_INVALID_PARAM
;
1724 if ((r
->in
.level
== 1 && !r
->in
.userlevel
.level1
) ||
1725 (r
->in
.level
== 2 && !r
->in
.userlevel
.level2
) ||
1726 (r
->in
.level
== 3 && !r
->in
.userlevel
.level3
)) {
1727 return WERR_INVALID_PARAM
;
1730 /* some sanity check because you can open a printer or a print server */
1731 /* aka: \\server\printer or \\server */
1733 DEBUGADD(3,("checking name: %s\n", r
->in
.printername
));
1735 result
= open_printer_hnd(p
, r
->out
.handle
, r
->in
.printername
, 0);
1736 if (!W_ERROR_IS_OK(result
)) {
1737 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1738 "for printer %s\n", r
->in
.printername
));
1739 ZERO_STRUCTP(r
->out
.handle
);
1743 Printer
= find_printer_index_by_hnd(p
, r
->out
.handle
);
1745 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1746 "handle we created for printer %s\n", r
->in
.printername
));
1747 close_printer_handle(p
, r
->out
.handle
);
1748 ZERO_STRUCTP(r
->out
.handle
);
1749 return WERR_INVALID_PARAM
;
1753 * First case: the user is opening the print server:
1755 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1756 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1758 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1759 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1760 * or if the user is listed in the smb.conf printer admin parameter.
1762 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1763 * client view printer folder, but does not show the MSAPW.
1765 * Note: this test needs code to check access rights here too. Jeremy
1766 * could you look at this?
1768 * Second case: the user is opening a printer:
1769 * NT doesn't let us connect to a printer if the connecting user
1770 * doesn't have print permission.
1772 * Third case: user is opening a Port Monitor
1773 * access checks same as opening a handle to the print server.
1776 switch (Printer
->printer_type
)
1779 case SPLHND_PORTMON_TCP
:
1780 case SPLHND_PORTMON_LOCAL
:
1781 /* Printserver handles use global struct... */
1785 /* Map standard access rights to object specific access rights */
1787 se_map_standard(&r
->in
.access_mask
,
1788 &printserver_std_mapping
);
1790 /* Deny any object specific bits that don't apply to print
1791 servers (i.e printer and job specific bits) */
1793 r
->in
.access_mask
&= SEC_MASK_SPECIFIC
;
1795 if (r
->in
.access_mask
&
1796 ~(SERVER_ACCESS_ADMINISTER
| SERVER_ACCESS_ENUMERATE
)) {
1797 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1798 close_printer_handle(p
, r
->out
.handle
);
1799 ZERO_STRUCTP(r
->out
.handle
);
1800 return WERR_ACCESS_DENIED
;
1803 /* Allow admin access */
1805 if ( r
->in
.access_mask
& SERVER_ACCESS_ADMINISTER
)
1807 if (!lp_ms_add_printer_wizard()) {
1808 close_printer_handle(p
, r
->out
.handle
);
1809 ZERO_STRUCTP(r
->out
.handle
);
1810 return WERR_ACCESS_DENIED
;
1813 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1814 and not a printer admin, then fail */
1816 if ((p
->session_info
->utok
.uid
!= sec_initial_uid()) &&
1817 !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
) &&
1818 !nt_token_check_sid(&global_sid_Builtin_Print_Operators
, p
->session_info
->security_token
) &&
1819 !token_contains_name_in_list(
1820 uidtoname(p
->session_info
->utok
.uid
),
1821 p
->session_info
->info3
->base
.domain
.string
,
1823 p
->session_info
->security_token
,
1824 lp_printer_admin(snum
))) {
1825 close_printer_handle(p
, r
->out
.handle
);
1826 ZERO_STRUCTP(r
->out
.handle
);
1827 DEBUG(3,("access DENIED as user is not root, "
1828 "has no printoperator privilege, "
1829 "not a member of the printoperator builtin group and "
1830 "is not in printer admin list"));
1831 return WERR_ACCESS_DENIED
;
1834 r
->in
.access_mask
= SERVER_ACCESS_ADMINISTER
;
1838 r
->in
.access_mask
= SERVER_ACCESS_ENUMERATE
;
1841 DEBUG(4,("Setting print server access = %s\n", (r
->in
.access_mask
== SERVER_ACCESS_ADMINISTER
)
1842 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1844 /* We fall through to return WERR_OK */
1847 case SPLHND_PRINTER
:
1848 /* NT doesn't let us connect to a printer if the connecting user
1849 doesn't have print permission. */
1851 if (!get_printer_snum(p
, r
->out
.handle
, &snum
, NULL
)) {
1852 close_printer_handle(p
, r
->out
.handle
);
1853 ZERO_STRUCTP(r
->out
.handle
);
1857 if (r
->in
.access_mask
== SEC_FLAG_MAXIMUM_ALLOWED
) {
1858 r
->in
.access_mask
= PRINTER_ACCESS_ADMINISTER
;
1861 se_map_standard(&r
->in
.access_mask
, &printer_std_mapping
);
1863 /* map an empty access mask to the minimum access mask */
1864 if (r
->in
.access_mask
== 0x0)
1865 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1868 * If we are not serving the printer driver for this printer,
1869 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1870 * will keep NT clients happy --jerry
1873 if (lp_use_client_driver(snum
)
1874 && (r
->in
.access_mask
& PRINTER_ACCESS_ADMINISTER
))
1876 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1879 /* check smb.conf parameters and the the sec_desc */
1881 if (!allow_access(lp_hostsdeny(snum
), lp_hostsallow(snum
),
1882 p
->client_id
->name
, p
->client_id
->addr
)) {
1883 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1884 ZERO_STRUCTP(r
->out
.handle
);
1885 return WERR_ACCESS_DENIED
;
1888 if (!user_ok_token(uidtoname(p
->session_info
->utok
.uid
), NULL
,
1889 p
->session_info
->security_token
, snum
) ||
1890 !print_access_check(p
->session_info
,
1893 r
->in
.access_mask
)) {
1894 DEBUG(3, ("access DENIED for printer open\n"));
1895 close_printer_handle(p
, r
->out
.handle
);
1896 ZERO_STRUCTP(r
->out
.handle
);
1897 return WERR_ACCESS_DENIED
;
1900 if ((r
->in
.access_mask
& SEC_MASK_SPECIFIC
)& ~(PRINTER_ACCESS_ADMINISTER
|PRINTER_ACCESS_USE
)) {
1901 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1902 close_printer_handle(p
, r
->out
.handle
);
1903 ZERO_STRUCTP(r
->out
.handle
);
1904 return WERR_ACCESS_DENIED
;
1907 if (r
->in
.access_mask
& PRINTER_ACCESS_ADMINISTER
)
1908 r
->in
.access_mask
= PRINTER_ACCESS_ADMINISTER
;
1910 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1912 DEBUG(4,("Setting printer access = %s\n", (r
->in
.access_mask
== PRINTER_ACCESS_ADMINISTER
)
1913 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1915 winreg_create_printer(p
->mem_ctx
,
1916 get_session_info_system(),
1918 lp_const_servicename(snum
));
1923 /* sanity check to prevent programmer error */
1924 ZERO_STRUCTP(r
->out
.handle
);
1928 Printer
->access_granted
= r
->in
.access_mask
;
1931 * If the client sent a devmode in the OpenPrinter() call, then
1932 * save it here in case we get a job submission on this handle
1935 if ((Printer
->printer_type
!= SPLHND_SERVER
) &&
1936 r
->in
.devmode_ctr
.devmode
) {
1937 copy_devicemode(NULL
, r
->in
.devmode_ctr
.devmode
,
1941 #if 0 /* JERRY -- I'm doubtful this is really effective */
1942 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1943 optimization in Windows 2000 clients --jerry */
1945 if ( (r
->in
.access_mask
== PRINTER_ACCESS_ADMINISTER
)
1946 && (RA_WIN2K
== get_remote_arch()) )
1948 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1949 sys_usleep( 500000 );
1956 /****************************************************************
1957 _spoolss_ClosePrinter
1958 ****************************************************************/
1960 WERROR
_spoolss_ClosePrinter(struct pipes_struct
*p
,
1961 struct spoolss_ClosePrinter
*r
)
1963 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
1965 if (Printer
&& Printer
->document_started
) {
1966 struct spoolss_EndDocPrinter e
;
1968 e
.in
.handle
= r
->in
.handle
;
1970 _spoolss_EndDocPrinter(p
, &e
);
1973 if (!close_printer_handle(p
, r
->in
.handle
))
1976 /* clear the returned printer handle. Observed behavior
1977 from Win2k server. Don't think this really matters.
1978 Previous code just copied the value of the closed
1981 ZERO_STRUCTP(r
->out
.handle
);
1986 /****************************************************************
1987 _spoolss_DeletePrinter
1988 ****************************************************************/
1990 WERROR
_spoolss_DeletePrinter(struct pipes_struct
*p
,
1991 struct spoolss_DeletePrinter
*r
)
1993 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
1997 if (Printer
&& Printer
->document_started
) {
1998 struct spoolss_EndDocPrinter e
;
2000 e
.in
.handle
= r
->in
.handle
;
2002 _spoolss_EndDocPrinter(p
, &e
);
2005 if (get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
2006 winreg_delete_printer_key(p
->mem_ctx
,
2007 get_session_info_system(),
2009 lp_const_servicename(snum
),
2013 result
= delete_printer_handle(p
, r
->in
.handle
);
2018 /*******************************************************************
2019 * static function to lookup the version id corresponding to an
2020 * long architecture string
2021 ******************************************************************/
2023 static const struct print_architecture_table_node archi_table
[]= {
2025 {"Windows 4.0", SPL_ARCH_WIN40
, 0 },
2026 {"Windows NT x86", SPL_ARCH_W32X86
, 2 },
2027 {"Windows NT R4000", SPL_ARCH_W32MIPS
, 2 },
2028 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA
, 2 },
2029 {"Windows NT PowerPC", SPL_ARCH_W32PPC
, 2 },
2030 {"Windows IA64", SPL_ARCH_IA64
, 3 },
2031 {"Windows x64", SPL_ARCH_X64
, 3 },
2035 static int get_version_id(const char *arch
)
2039 for (i
=0; archi_table
[i
].long_archi
!= NULL
; i
++)
2041 if (strcmp(arch
, archi_table
[i
].long_archi
) == 0)
2042 return (archi_table
[i
].version
);
2048 /****************************************************************
2049 _spoolss_DeletePrinterDriver
2050 ****************************************************************/
2052 WERROR
_spoolss_DeletePrinterDriver(struct pipes_struct
*p
,
2053 struct spoolss_DeletePrinterDriver
*r
)
2056 struct spoolss_DriverInfo8
*info
= NULL
;
2057 struct spoolss_DriverInfo8
*info_win2k
= NULL
;
2061 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2062 and not a printer admin, then fail */
2064 if ( (p
->session_info
->utok
.uid
!= sec_initial_uid())
2065 && !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
)
2066 && !token_contains_name_in_list(
2067 uidtoname(p
->session_info
->utok
.uid
),
2068 p
->session_info
->info3
->base
.domain
.string
,
2070 p
->session_info
->security_token
,
2071 lp_printer_admin(-1)) )
2073 return WERR_ACCESS_DENIED
;
2076 /* check that we have a valid driver name first */
2078 if ((version
= get_version_id(r
->in
.architecture
)) == -1)
2079 return WERR_INVALID_ENVIRONMENT
;
2081 status
= winreg_get_driver(p
->mem_ctx
,
2082 get_session_info_system(),
2084 r
->in
.architecture
, r
->in
.driver
,
2086 if (!W_ERROR_IS_OK(status
)) {
2087 /* try for Win2k driver if "Windows NT x86" */
2089 if ( version
== 2 ) {
2092 status
= winreg_get_driver(p
->mem_ctx
,
2093 get_session_info_system(),
2098 if (!W_ERROR_IS_OK(status
)) {
2099 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2103 /* otherwise it was a failure */
2105 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2111 if (printer_driver_in_use(p
->mem_ctx
,
2112 get_session_info_system(),
2115 status
= WERR_PRINTER_DRIVER_IN_USE
;
2120 status
= winreg_get_driver(p
->mem_ctx
,
2121 get_session_info_system(),
2124 r
->in
.driver
, 3, &info_win2k
);
2125 if (W_ERROR_IS_OK(status
)) {
2126 /* if we get to here, we now have 2 driver info structures to remove */
2127 /* remove the Win2k driver first*/
2129 status
= winreg_del_driver(p
->mem_ctx
,
2130 get_session_info_system(),
2133 talloc_free(info_win2k
);
2135 /* this should not have failed---if it did, report to client */
2136 if (!W_ERROR_IS_OK(status
)) {
2142 status
= winreg_del_driver(p
->mem_ctx
,
2143 get_session_info_system(),
2153 /****************************************************************
2154 _spoolss_DeletePrinterDriverEx
2155 ****************************************************************/
2157 WERROR
_spoolss_DeletePrinterDriverEx(struct pipes_struct
*p
,
2158 struct spoolss_DeletePrinterDriverEx
*r
)
2160 struct spoolss_DriverInfo8
*info
= NULL
;
2161 struct spoolss_DriverInfo8
*info_win2k
= NULL
;
2166 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2167 and not a printer admin, then fail */
2169 if ( (p
->session_info
->utok
.uid
!= sec_initial_uid())
2170 && !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
)
2171 && !token_contains_name_in_list(
2172 uidtoname(p
->session_info
->utok
.uid
),
2173 p
->session_info
->info3
->base
.domain
.string
,
2175 p
->session_info
->security_token
, lp_printer_admin(-1)) )
2177 return WERR_ACCESS_DENIED
;
2180 /* check that we have a valid driver name first */
2181 if ((version
= get_version_id(r
->in
.architecture
)) == -1) {
2182 /* this is what NT returns */
2183 return WERR_INVALID_ENVIRONMENT
;
2186 if (r
->in
.delete_flags
& DPD_DELETE_SPECIFIC_VERSION
)
2187 version
= r
->in
.version
;
2189 status
= winreg_get_driver(p
->mem_ctx
,
2190 get_session_info_system(),
2196 if (!W_ERROR_IS_OK(status
)) {
2197 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2200 * if the client asked for a specific version,
2201 * or this is something other than Windows NT x86,
2205 if ( (r
->in
.delete_flags
& DPD_DELETE_SPECIFIC_VERSION
) || (version
!=2) )
2208 /* try for Win2k driver if "Windows NT x86" */
2211 status
= winreg_get_driver(info
,
2212 get_session_info_system(),
2217 if (!W_ERROR_IS_OK(status
)) {
2218 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2223 if (printer_driver_in_use(info
,
2224 get_session_info_system(),
2227 status
= WERR_PRINTER_DRIVER_IN_USE
;
2232 * we have a couple of cases to consider.
2233 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2234 * then the delete should fail if **any** files overlap with
2236 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2237 * non-overlapping files
2238 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2239 * is set, the do not delete any files
2240 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2243 delete_files
= r
->in
.delete_flags
& (DPD_DELETE_ALL_FILES
|DPD_DELETE_UNUSED_FILES
);
2245 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2248 (r
->in
.delete_flags
& DPD_DELETE_ALL_FILES
) &&
2249 printer_driver_files_in_use(info
,
2250 get_session_info_system(),
2253 /* no idea of the correct error here */
2254 status
= WERR_ACCESS_DENIED
;
2259 /* also check for W32X86/3 if necessary; maybe we already have? */
2261 if ( (version
== 2) && ((r
->in
.delete_flags
& DPD_DELETE_SPECIFIC_VERSION
) != DPD_DELETE_SPECIFIC_VERSION
) ) {
2262 status
= winreg_get_driver(info
,
2263 get_session_info_system(),
2266 r
->in
.driver
, 3, &info_win2k
);
2267 if (W_ERROR_IS_OK(status
)) {
2270 (r
->in
.delete_flags
& DPD_DELETE_ALL_FILES
) &&
2271 printer_driver_files_in_use(info
,
2272 get_session_info_system(),
2275 /* no idea of the correct error here */
2276 talloc_free(info_win2k
);
2277 status
= WERR_ACCESS_DENIED
;
2281 /* if we get to here, we now have 2 driver info structures to remove */
2282 /* remove the Win2k driver first*/
2284 status
= winreg_del_driver(info
,
2285 get_session_info_system(),
2290 /* this should not have failed---if it did, report to client */
2292 if (!W_ERROR_IS_OK(status
)) {
2297 * now delete any associated files if delete_files is
2298 * true. Even if this part failes, we return succes
2299 * because the driver doesn not exist any more
2302 delete_driver_files(get_session_info_system(),
2308 status
= winreg_del_driver(info
,
2309 get_session_info_system(),
2313 if (!W_ERROR_IS_OK(status
)) {
2318 * now delete any associated files if delete_files is
2319 * true. Even if this part failes, we return succes
2320 * because the driver doesn not exist any more
2323 delete_driver_files(get_session_info_system(), info
);
2332 /********************************************************************
2333 GetPrinterData on a printer server Handle.
2334 ********************************************************************/
2336 static WERROR
getprinterdata_printer_server(TALLOC_CTX
*mem_ctx
,
2338 enum winreg_Type
*type
,
2339 union spoolss_PrinterData
*data
)
2341 DEBUG(8,("getprinterdata_printer_server:%s\n", value
));
2343 if (!strcasecmp_m(value
, "W3SvcInstalled")) {
2349 if (!strcasecmp_m(value
, "BeepEnabled")) {
2355 if (!strcasecmp_m(value
, "EventLog")) {
2357 /* formally was 0x1b */
2362 if (!strcasecmp_m(value
, "NetPopup")) {
2368 if (!strcasecmp_m(value
, "MajorVersion")) {
2371 /* Windows NT 4.0 seems to not allow uploading of drivers
2372 to a server that reports 0x3 as the MajorVersion.
2373 need to investigate more how Win2k gets around this .
2376 if (RA_WINNT
== get_remote_arch()) {
2385 if (!strcasecmp_m(value
, "MinorVersion")) {
2392 * uint32_t size = 0x114
2393 * uint32_t major = 5
2394 * uint32_t minor = [0|1]
2395 * uint32_t build = [2195|2600]
2396 * extra unicode string = e.g. "Service Pack 3"
2398 if (!strcasecmp_m(value
, "OSVersion")) {
2400 enum ndr_err_code ndr_err
;
2401 struct spoolss_OSVersion os
;
2403 os
.major
= 5; /* Windows 2000 == 5.0 */
2405 os
.build
= 2195; /* build */
2406 os
.extra_string
= ""; /* leave extra string empty */
2408 ndr_err
= ndr_push_struct_blob(&blob
, mem_ctx
, &os
,
2409 (ndr_push_flags_fn_t
)ndr_push_spoolss_OSVersion
);
2410 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2411 return WERR_GENERAL_FAILURE
;
2415 data
->binary
= blob
;
2421 if (!strcasecmp_m(value
, "DefaultSpoolDirectory")) {
2424 data
->string
= talloc_strdup(mem_ctx
, "C:\\PRINTERS");
2425 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2430 if (!strcasecmp_m(value
, "Architecture")) {
2432 data
->string
= talloc_strdup(mem_ctx
,
2433 lp_parm_const_string(GLOBAL_SECTION_SNUM
, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86
));
2434 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2439 if (!strcasecmp_m(value
, "DsPresent")) {
2442 /* only show the publish check box if we are a
2443 member of a AD domain */
2445 if (lp_security() == SEC_ADS
) {
2453 if (!strcasecmp_m(value
, "DNSMachineName")) {
2454 const char *hostname
= get_mydnsfullname();
2457 return WERR_BADFILE
;
2461 data
->string
= talloc_strdup(mem_ctx
, hostname
);
2462 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2469 return WERR_INVALID_PARAM
;
2472 /****************************************************************
2473 _spoolss_GetPrinterData
2474 ****************************************************************/
2476 WERROR
_spoolss_GetPrinterData(struct pipes_struct
*p
,
2477 struct spoolss_GetPrinterData
*r
)
2479 struct spoolss_GetPrinterDataEx r2
;
2481 r2
.in
.handle
= r
->in
.handle
;
2482 r2
.in
.key_name
= "PrinterDriverData";
2483 r2
.in
.value_name
= r
->in
.value_name
;
2484 r2
.in
.offered
= r
->in
.offered
;
2485 r2
.out
.type
= r
->out
.type
;
2486 r2
.out
.data
= r
->out
.data
;
2487 r2
.out
.needed
= r
->out
.needed
;
2489 return _spoolss_GetPrinterDataEx(p
, &r2
);
2492 /*********************************************************
2493 Connect to the client machine.
2494 **********************************************************/
2496 static bool spoolss_connect_to_client(struct rpc_pipe_client
**pp_pipe
,
2497 struct sockaddr_storage
*client_ss
, const char *remote_machine
)
2500 struct cli_state
*the_cli
;
2501 struct sockaddr_storage rm_addr
;
2502 char addr
[INET6_ADDRSTRLEN
];
2504 if ( is_zero_addr(client_ss
) ) {
2505 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2507 if ( !resolve_name( remote_machine
, &rm_addr
, 0x20, false) ) {
2508 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine
));
2511 print_sockaddr(addr
, sizeof(addr
), &rm_addr
);
2513 rm_addr
= *client_ss
;
2514 print_sockaddr(addr
, sizeof(addr
), &rm_addr
);
2515 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2519 if (ismyaddr((struct sockaddr
*)(void *)&rm_addr
)) {
2520 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2525 /* setup the connection */
2526 ret
= cli_full_connection( &the_cli
, global_myname(), remote_machine
,
2527 &rm_addr
, 0, "IPC$", "IPC",
2531 0, lp_client_signing());
2533 if ( !NT_STATUS_IS_OK( ret
) ) {
2534 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2539 if ( the_cli
->protocol
!= PROTOCOL_NT1
) {
2540 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine
));
2541 cli_shutdown(the_cli
);
2546 * Ok - we have an anonymous connection to the IPC$ share.
2547 * Now start the NT Domain stuff :-).
2550 ret
= cli_rpc_pipe_open_noauth(the_cli
, &ndr_table_spoolss
.syntax_id
, pp_pipe
);
2551 if (!NT_STATUS_IS_OK(ret
)) {
2552 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2553 remote_machine
, nt_errstr(ret
)));
2554 cli_shutdown(the_cli
);
2561 /***************************************************************************
2562 Connect to the client.
2563 ****************************************************************************/
2565 static bool srv_spoolss_replyopenprinter(int snum
, const char *printer
,
2566 uint32_t localprinter
,
2567 enum winreg_Type type
,
2568 struct policy_handle
*handle
,
2569 struct notify_back_channel
**_chan
,
2570 struct sockaddr_storage
*client_ss
,
2571 struct messaging_context
*msg_ctx
)
2575 struct notify_back_channel
*chan
;
2577 for (chan
= back_channels
; chan
; chan
= chan
->next
) {
2578 if (memcmp(&chan
->client_address
, client_ss
,
2579 sizeof(struct sockaddr_storage
)) == 0) {
2585 * If it's the first connection, contact the client
2586 * and connect to the IPC$ share anonymously
2589 fstring unix_printer
;
2591 /* the +2 is to strip the leading 2 backslashs */
2592 fstrcpy(unix_printer
, printer
+ 2);
2594 chan
= talloc_zero(back_channels
, struct notify_back_channel
);
2598 chan
->client_address
= *client_ss
;
2600 if (!spoolss_connect_to_client(&chan
->cli_pipe
, client_ss
, unix_printer
)) {
2604 chan
->binding_handle
= chan
->cli_pipe
->binding_handle
;
2606 DLIST_ADD(back_channels
, chan
);
2608 messaging_register(msg_ctx
, NULL
, MSG_PRINTER_NOTIFY2
,
2609 receive_notify2_message_list
);
2610 /* Tell the connections db we're now interested in printer
2611 * notify messages. */
2612 serverid_register_msg_flags(messaging_server_id(msg_ctx
),
2613 true, FLAG_MSG_PRINT_NOTIFY
);
2617 * Tell the specific printing tdb we want messages for this printer
2618 * by registering our PID.
2621 if (!print_notify_register_pid(snum
)) {
2622 DEBUG(0, ("Failed to register our pid for printer %s\n",
2626 status
= dcerpc_spoolss_ReplyOpenPrinter(chan
->binding_handle
,
2635 if (!NT_STATUS_IS_OK(status
)) {
2636 DEBUG(5, ("dcerpc_spoolss_ReplyOpenPrinter returned [%s]\n", nt_errstr(status
)));
2637 result
= ntstatus_to_werror(status
);
2638 } else if (!W_ERROR_IS_OK(result
)) {
2639 DEBUG(5, ("ReplyOpenPrinter returned [%s]\n", win_errstr(result
)));
2642 chan
->active_connections
++;
2645 return (W_ERROR_IS_OK(result
));
2648 /****************************************************************
2649 ****************************************************************/
2651 static struct spoolss_NotifyOption
*dup_spoolss_NotifyOption(TALLOC_CTX
*mem_ctx
,
2652 const struct spoolss_NotifyOption
*r
)
2654 struct spoolss_NotifyOption
*option
;
2661 option
= talloc_zero(mem_ctx
, struct spoolss_NotifyOption
);
2668 if (!option
->count
) {
2672 option
->types
= talloc_zero_array(option
,
2673 struct spoolss_NotifyOptionType
, option
->count
);
2674 if (!option
->types
) {
2675 talloc_free(option
);
2679 for (i
=0; i
< option
->count
; i
++) {
2680 option
->types
[i
] = r
->types
[i
];
2682 if (option
->types
[i
].count
) {
2683 option
->types
[i
].fields
= talloc_zero_array(option
,
2684 union spoolss_Field
, option
->types
[i
].count
);
2685 if (!option
->types
[i
].fields
) {
2686 talloc_free(option
);
2689 for (k
=0; k
<option
->types
[i
].count
; k
++) {
2690 option
->types
[i
].fields
[k
] =
2691 r
->types
[i
].fields
[k
];
2699 /****************************************************************
2700 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2702 * before replying OK: status=0 a rpc call is made to the workstation
2703 * asking ReplyOpenPrinter
2705 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2706 * called from api_spoolss_rffpcnex
2707 ****************************************************************/
2709 WERROR
_spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct
*p
,
2710 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx
*r
)
2713 struct spoolss_NotifyOption
*option
= r
->in
.notify_options
;
2714 struct sockaddr_storage client_ss
;
2716 /* store the notify value in the printer struct */
2718 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
2721 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2722 "Invalid handle (%s:%u:%u).\n",
2723 OUR_HANDLE(r
->in
.handle
)));
2727 Printer
->notify
.flags
= r
->in
.flags
;
2728 Printer
->notify
.options
= r
->in
.options
;
2729 Printer
->notify
.printerlocal
= r
->in
.printer_local
;
2730 Printer
->notify
.msg_ctx
= p
->msg_ctx
;
2732 TALLOC_FREE(Printer
->notify
.option
);
2733 Printer
->notify
.option
= dup_spoolss_NotifyOption(Printer
, option
);
2735 fstrcpy(Printer
->notify
.localmachine
, r
->in
.local_machine
);
2737 /* Connect to the client machine and send a ReplyOpenPrinter */
2739 if ( Printer
->printer_type
== SPLHND_SERVER
)
2741 else if ( (Printer
->printer_type
== SPLHND_PRINTER
) &&
2742 !get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
) )
2745 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2746 "client_address is %s\n", p
->client_id
->addr
));
2748 if (!lp_print_notify_backchannel(snum
)) {
2749 DEBUG(10, ("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2750 "backchannel disabled\n"));
2751 return WERR_SERVER_UNAVAILABLE
;
2754 if (!interpret_string_addr(&client_ss
, p
->client_id
->addr
,
2756 return WERR_SERVER_UNAVAILABLE
;
2759 if(!srv_spoolss_replyopenprinter(snum
, Printer
->notify
.localmachine
,
2760 Printer
->notify
.printerlocal
, REG_SZ
,
2761 &Printer
->notify
.cli_hnd
,
2762 &Printer
->notify
.cli_chan
,
2763 &client_ss
, p
->msg_ctx
)) {
2764 return WERR_SERVER_UNAVAILABLE
;
2770 /*******************************************************************
2771 * fill a notify_info_data with the servername
2772 ********************************************************************/
2774 static void spoolss_notify_server_name(struct messaging_context
*msg_ctx
,
2776 struct spoolss_Notify
*data
,
2777 print_queue_struct
*queue
,
2778 struct spoolss_PrinterInfo2
*pinfo2
,
2779 TALLOC_CTX
*mem_ctx
)
2781 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->servername
);
2784 /*******************************************************************
2785 * fill a notify_info_data with the printername (not including the servername).
2786 ********************************************************************/
2788 static void spoolss_notify_printer_name(struct messaging_context
*msg_ctx
,
2790 struct spoolss_Notify
*data
,
2791 print_queue_struct
*queue
,
2792 struct spoolss_PrinterInfo2
*pinfo2
,
2793 TALLOC_CTX
*mem_ctx
)
2795 /* the notify name should not contain the \\server\ part */
2796 const char *p
= strrchr(pinfo2
->printername
, '\\');
2799 p
= pinfo2
->printername
;
2804 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
2807 /*******************************************************************
2808 * fill a notify_info_data with the servicename
2809 ********************************************************************/
2811 static void spoolss_notify_share_name(struct messaging_context
*msg_ctx
,
2813 struct spoolss_Notify
*data
,
2814 print_queue_struct
*queue
,
2815 struct spoolss_PrinterInfo2
*pinfo2
,
2816 TALLOC_CTX
*mem_ctx
)
2818 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, lp_servicename(snum
));
2821 /*******************************************************************
2822 * fill a notify_info_data with the port name
2823 ********************************************************************/
2825 static void spoolss_notify_port_name(struct messaging_context
*msg_ctx
,
2827 struct spoolss_Notify
*data
,
2828 print_queue_struct
*queue
,
2829 struct spoolss_PrinterInfo2
*pinfo2
,
2830 TALLOC_CTX
*mem_ctx
)
2832 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->portname
);
2835 /*******************************************************************
2836 * fill a notify_info_data with the printername
2837 * but it doesn't exist, have to see what to do
2838 ********************************************************************/
2840 static void spoolss_notify_driver_name(struct messaging_context
*msg_ctx
,
2842 struct spoolss_Notify
*data
,
2843 print_queue_struct
*queue
,
2844 struct spoolss_PrinterInfo2
*pinfo2
,
2845 TALLOC_CTX
*mem_ctx
)
2847 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->drivername
);
2850 /*******************************************************************
2851 * fill a notify_info_data with the comment
2852 ********************************************************************/
2854 static void spoolss_notify_comment(struct messaging_context
*msg_ctx
,
2856 struct spoolss_Notify
*data
,
2857 print_queue_struct
*queue
,
2858 struct spoolss_PrinterInfo2
*pinfo2
,
2859 TALLOC_CTX
*mem_ctx
)
2863 if (*pinfo2
->comment
== '\0') {
2864 p
= lp_comment(snum
);
2866 p
= pinfo2
->comment
;
2869 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
2872 /*******************************************************************
2873 * fill a notify_info_data with the comment
2874 * location = "Room 1, floor 2, building 3"
2875 ********************************************************************/
2877 static void spoolss_notify_location(struct messaging_context
*msg_ctx
,
2879 struct spoolss_Notify
*data
,
2880 print_queue_struct
*queue
,
2881 struct spoolss_PrinterInfo2
*pinfo2
,
2882 TALLOC_CTX
*mem_ctx
)
2884 const char *loc
= pinfo2
->location
;
2887 status
= printer_list_get_printer(mem_ctx
,
2892 if (NT_STATUS_IS_OK(status
)) {
2894 loc
= pinfo2
->location
;
2898 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, loc
);
2901 /*******************************************************************
2902 * fill a notify_info_data with the device mode
2903 * jfm:xxxx don't to it for know but that's a real problem !!!
2904 ********************************************************************/
2906 static void spoolss_notify_devmode(struct messaging_context
*msg_ctx
,
2908 struct spoolss_Notify
*data
,
2909 print_queue_struct
*queue
,
2910 struct spoolss_PrinterInfo2
*pinfo2
,
2911 TALLOC_CTX
*mem_ctx
)
2913 /* for a dummy implementation we have to zero the fields */
2914 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data
, NULL
);
2917 /*******************************************************************
2918 * fill a notify_info_data with the separator file name
2919 ********************************************************************/
2921 static void spoolss_notify_sepfile(struct messaging_context
*msg_ctx
,
2923 struct spoolss_Notify
*data
,
2924 print_queue_struct
*queue
,
2925 struct spoolss_PrinterInfo2
*pinfo2
,
2926 TALLOC_CTX
*mem_ctx
)
2928 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->sepfile
);
2931 /*******************************************************************
2932 * fill a notify_info_data with the print processor
2933 * jfm:xxxx return always winprint to indicate we don't do anything to it
2934 ********************************************************************/
2936 static void spoolss_notify_print_processor(struct messaging_context
*msg_ctx
,
2938 struct spoolss_Notify
*data
,
2939 print_queue_struct
*queue
,
2940 struct spoolss_PrinterInfo2
*pinfo2
,
2941 TALLOC_CTX
*mem_ctx
)
2943 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->printprocessor
);
2946 /*******************************************************************
2947 * fill a notify_info_data with the print processor options
2948 * jfm:xxxx send an empty string
2949 ********************************************************************/
2951 static void spoolss_notify_parameters(struct messaging_context
*msg_ctx
,
2953 struct spoolss_Notify
*data
,
2954 print_queue_struct
*queue
,
2955 struct spoolss_PrinterInfo2
*pinfo2
,
2956 TALLOC_CTX
*mem_ctx
)
2958 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->parameters
);
2961 /*******************************************************************
2962 * fill a notify_info_data with the data type
2963 * jfm:xxxx always send RAW as data type
2964 ********************************************************************/
2966 static void spoolss_notify_datatype(struct messaging_context
*msg_ctx
,
2968 struct spoolss_Notify
*data
,
2969 print_queue_struct
*queue
,
2970 struct spoolss_PrinterInfo2
*pinfo2
,
2971 TALLOC_CTX
*mem_ctx
)
2973 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->datatype
);
2976 /*******************************************************************
2977 * fill a notify_info_data with the security descriptor
2978 * jfm:xxxx send an null pointer to say no security desc
2979 * have to implement security before !
2980 ********************************************************************/
2982 static void spoolss_notify_security_desc(struct messaging_context
*msg_ctx
,
2984 struct spoolss_Notify
*data
,
2985 print_queue_struct
*queue
,
2986 struct spoolss_PrinterInfo2
*pinfo2
,
2987 TALLOC_CTX
*mem_ctx
)
2989 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data
, pinfo2
->secdesc
);
2992 /*******************************************************************
2993 * fill a notify_info_data with the attributes
2994 * jfm:xxxx a samba printer is always shared
2995 ********************************************************************/
2997 static void spoolss_notify_attributes(struct messaging_context
*msg_ctx
,
2999 struct spoolss_Notify
*data
,
3000 print_queue_struct
*queue
,
3001 struct spoolss_PrinterInfo2
*pinfo2
,
3002 TALLOC_CTX
*mem_ctx
)
3004 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->attributes
);
3007 /*******************************************************************
3008 * fill a notify_info_data with the priority
3009 ********************************************************************/
3011 static void spoolss_notify_priority(struct messaging_context
*msg_ctx
,
3013 struct spoolss_Notify
*data
,
3014 print_queue_struct
*queue
,
3015 struct spoolss_PrinterInfo2
*pinfo2
,
3016 TALLOC_CTX
*mem_ctx
)
3018 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->priority
);
3021 /*******************************************************************
3022 * fill a notify_info_data with the default priority
3023 ********************************************************************/
3025 static void spoolss_notify_default_priority(struct messaging_context
*msg_ctx
,
3027 struct spoolss_Notify
*data
,
3028 print_queue_struct
*queue
,
3029 struct spoolss_PrinterInfo2
*pinfo2
,
3030 TALLOC_CTX
*mem_ctx
)
3032 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->defaultpriority
);
3035 /*******************************************************************
3036 * fill a notify_info_data with the start time
3037 ********************************************************************/
3039 static void spoolss_notify_start_time(struct messaging_context
*msg_ctx
,
3041 struct spoolss_Notify
*data
,
3042 print_queue_struct
*queue
,
3043 struct spoolss_PrinterInfo2
*pinfo2
,
3044 TALLOC_CTX
*mem_ctx
)
3046 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->starttime
);
3049 /*******************************************************************
3050 * fill a notify_info_data with the until time
3051 ********************************************************************/
3053 static void spoolss_notify_until_time(struct messaging_context
*msg_ctx
,
3055 struct spoolss_Notify
*data
,
3056 print_queue_struct
*queue
,
3057 struct spoolss_PrinterInfo2
*pinfo2
,
3058 TALLOC_CTX
*mem_ctx
)
3060 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->untiltime
);
3063 /*******************************************************************
3064 * fill a notify_info_data with the status
3065 ********************************************************************/
3067 static void spoolss_notify_status(struct messaging_context
*msg_ctx
,
3069 struct spoolss_Notify
*data
,
3070 print_queue_struct
*queue
,
3071 struct spoolss_PrinterInfo2
*pinfo2
,
3072 TALLOC_CTX
*mem_ctx
)
3074 print_status_struct status
;
3076 print_queue_length(msg_ctx
, snum
, &status
);
3077 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, status
.status
);
3080 /*******************************************************************
3081 * fill a notify_info_data with the number of jobs queued
3082 ********************************************************************/
3084 static void spoolss_notify_cjobs(struct messaging_context
*msg_ctx
,
3086 struct spoolss_Notify
*data
,
3087 print_queue_struct
*queue
,
3088 struct spoolss_PrinterInfo2
*pinfo2
,
3089 TALLOC_CTX
*mem_ctx
)
3091 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3092 data
, print_queue_length(msg_ctx
, snum
, NULL
));
3095 /*******************************************************************
3096 * fill a notify_info_data with the average ppm
3097 ********************************************************************/
3099 static void spoolss_notify_average_ppm(struct messaging_context
*msg_ctx
,
3101 struct spoolss_Notify
*data
,
3102 print_queue_struct
*queue
,
3103 struct spoolss_PrinterInfo2
*pinfo2
,
3104 TALLOC_CTX
*mem_ctx
)
3106 /* always respond 8 pages per minutes */
3107 /* a little hard ! */
3108 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->averageppm
);
3111 /*******************************************************************
3112 * fill a notify_info_data with username
3113 ********************************************************************/
3115 static void spoolss_notify_username(struct messaging_context
*msg_ctx
,
3117 struct spoolss_Notify
*data
,
3118 print_queue_struct
*queue
,
3119 struct spoolss_PrinterInfo2
*pinfo2
,
3120 TALLOC_CTX
*mem_ctx
)
3122 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, queue
->fs_user
);
3125 /*******************************************************************
3126 * fill a notify_info_data with job status
3127 ********************************************************************/
3129 static void spoolss_notify_job_status(struct messaging_context
*msg_ctx
,
3131 struct spoolss_Notify
*data
,
3132 print_queue_struct
*queue
,
3133 struct spoolss_PrinterInfo2
*pinfo2
,
3134 TALLOC_CTX
*mem_ctx
)
3136 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, nt_printj_status(queue
->status
));
3139 /*******************************************************************
3140 * fill a notify_info_data with job name
3141 ********************************************************************/
3143 static void spoolss_notify_job_name(struct messaging_context
*msg_ctx
,
3145 struct spoolss_Notify
*data
,
3146 print_queue_struct
*queue
,
3147 struct spoolss_PrinterInfo2
*pinfo2
,
3148 TALLOC_CTX
*mem_ctx
)
3150 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, queue
->fs_file
);
3153 /*******************************************************************
3154 * fill a notify_info_data with job status
3155 ********************************************************************/
3157 static void spoolss_notify_job_status_string(struct messaging_context
*msg_ctx
,
3159 struct spoolss_Notify
*data
,
3160 print_queue_struct
*queue
,
3161 struct spoolss_PrinterInfo2
*pinfo2
,
3162 TALLOC_CTX
*mem_ctx
)
3165 * Now we're returning job status codes we just return a "" here. JRA.
3170 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3173 switch (queue
->status
) {
3178 p
= ""; /* NT provides the paused string */
3187 #endif /* NO LONGER NEEDED. */
3189 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
3192 /*******************************************************************
3193 * fill a notify_info_data with job time
3194 ********************************************************************/
3196 static void spoolss_notify_job_time(struct messaging_context
*msg_ctx
,
3198 struct spoolss_Notify
*data
,
3199 print_queue_struct
*queue
,
3200 struct spoolss_PrinterInfo2
*pinfo2
,
3201 TALLOC_CTX
*mem_ctx
)
3203 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, 0);
3206 /*******************************************************************
3207 * fill a notify_info_data with job size
3208 ********************************************************************/
3210 static void spoolss_notify_job_size(struct messaging_context
*msg_ctx
,
3212 struct spoolss_Notify
*data
,
3213 print_queue_struct
*queue
,
3214 struct spoolss_PrinterInfo2
*pinfo2
,
3215 TALLOC_CTX
*mem_ctx
)
3217 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->size
);
3220 /*******************************************************************
3221 * fill a notify_info_data with page info
3222 ********************************************************************/
3223 static void spoolss_notify_total_pages(struct messaging_context
*msg_ctx
,
3225 struct spoolss_Notify
*data
,
3226 print_queue_struct
*queue
,
3227 struct spoolss_PrinterInfo2
*pinfo2
,
3228 TALLOC_CTX
*mem_ctx
)
3230 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->page_count
);
3233 /*******************************************************************
3234 * fill a notify_info_data with pages printed info.
3235 ********************************************************************/
3236 static void spoolss_notify_pages_printed(struct messaging_context
*msg_ctx
,
3238 struct spoolss_Notify
*data
,
3239 print_queue_struct
*queue
,
3240 struct spoolss_PrinterInfo2
*pinfo2
,
3241 TALLOC_CTX
*mem_ctx
)
3243 /* Add code when back-end tracks this */
3244 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, 0);
3247 /*******************************************************************
3248 Fill a notify_info_data with job position.
3249 ********************************************************************/
3251 static void spoolss_notify_job_position(struct messaging_context
*msg_ctx
,
3253 struct spoolss_Notify
*data
,
3254 print_queue_struct
*queue
,
3255 struct spoolss_PrinterInfo2
*pinfo2
,
3256 TALLOC_CTX
*mem_ctx
)
3258 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->job
);
3261 /*******************************************************************
3262 Fill a notify_info_data with submitted time.
3263 ********************************************************************/
3265 static void spoolss_notify_submitted_time(struct messaging_context
*msg_ctx
,
3267 struct spoolss_Notify
*data
,
3268 print_queue_struct
*queue
,
3269 struct spoolss_PrinterInfo2
*pinfo2
,
3270 TALLOC_CTX
*mem_ctx
)
3272 data
->data
.string
.string
= NULL
;
3273 data
->data
.string
.size
= 0;
3275 init_systemtime_buffer(mem_ctx
, gmtime(&queue
->time
),
3276 &data
->data
.string
.string
,
3277 &data
->data
.string
.size
);
3281 struct s_notify_info_data_table
3283 enum spoolss_NotifyType type
;
3286 enum spoolss_NotifyTable variable_type
;
3287 void (*fn
) (struct messaging_context
*msg_ctx
,
3288 int snum
, struct spoolss_Notify
*data
,
3289 print_queue_struct
*queue
,
3290 struct spoolss_PrinterInfo2
*pinfo2
,
3291 TALLOC_CTX
*mem_ctx
);
3294 /* A table describing the various print notification constants and
3295 whether the notification data is a pointer to a variable sized
3296 buffer, a one value uint32_t or a two value uint32_t. */
3298 static const struct s_notify_info_data_table notify_info_data_table
[] =
3300 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SERVER_NAME
, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_server_name
},
3301 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRINTER_NAME
, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_printer_name
},
3302 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SHARE_NAME
, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_share_name
},
3303 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PORT_NAME
, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_port_name
},
3304 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DRIVER_NAME
, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_driver_name
},
3305 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_COMMENT
, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING
, spoolss_notify_comment
},
3306 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_LOCATION
, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING
, spoolss_notify_location
},
3307 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DEVMODE
, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE
, spoolss_notify_devmode
},
3308 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SEPFILE
, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING
, spoolss_notify_sepfile
},
3309 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR
, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING
, spoolss_notify_print_processor
},
3310 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PARAMETERS
, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING
, spoolss_notify_parameters
},
3311 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DATATYPE
, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING
, spoolss_notify_datatype
},
3312 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR
, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR
, spoolss_notify_security_desc
},
3313 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_ATTRIBUTES
, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD
, spoolss_notify_attributes
},
3314 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRIORITY
, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_priority
},
3315 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY
, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_default_priority
},
3316 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_START_TIME
, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_start_time
},
3317 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_UNTIL_TIME
, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_until_time
},
3318 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_STATUS
, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD
, spoolss_notify_status
},
3319 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_STATUS_STRING
, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING
, NULL
},
3320 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_CJOBS
, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD
, spoolss_notify_cjobs
},
3321 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_AVERAGE_PPM
, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD
, spoolss_notify_average_ppm
},
3322 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_TOTAL_PAGES
, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD
, NULL
},
3323 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PAGES_PRINTED
, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD
, NULL
},
3324 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_TOTAL_BYTES
, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD
, NULL
},
3325 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_BYTES_PRINTED
, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD
, NULL
},
3326 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRINTER_NAME
, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_printer_name
},
3327 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_MACHINE_NAME
, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_server_name
},
3328 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PORT_NAME
, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_port_name
},
3329 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_USER_NAME
, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_username
},
3330 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_NOTIFY_NAME
, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_username
},
3331 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DATATYPE
, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING
, spoolss_notify_datatype
},
3332 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRINT_PROCESSOR
, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING
, spoolss_notify_print_processor
},
3333 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PARAMETERS
, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING
, spoolss_notify_parameters
},
3334 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DRIVER_NAME
, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_driver_name
},
3335 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DEVMODE
, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE
, spoolss_notify_devmode
},
3336 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_STATUS
, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD
, spoolss_notify_job_status
},
3337 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_STATUS_STRING
, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING
, spoolss_notify_job_status_string
},
3338 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR
, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR
, NULL
},
3339 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DOCUMENT
, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING
, spoolss_notify_job_name
},
3340 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRIORITY
, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_priority
},
3341 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_POSITION
, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD
, spoolss_notify_job_position
},
3342 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_SUBMITTED
, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME
, spoolss_notify_submitted_time
},
3343 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_START_TIME
, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_start_time
},
3344 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_UNTIL_TIME
, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_until_time
},
3345 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TIME
, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_job_time
},
3346 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TOTAL_PAGES
, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD
, spoolss_notify_total_pages
},
3347 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PAGES_PRINTED
, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD
, spoolss_notify_pages_printed
},
3348 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TOTAL_BYTES
, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD
, spoolss_notify_job_size
},
3351 /*******************************************************************
3352 Return the variable_type of info_data structure.
3353 ********************************************************************/
3355 static enum spoolss_NotifyTable
variable_type_of_notify_info_data(enum spoolss_NotifyType type
,
3360 for (i
= 0; i
< ARRAY_SIZE(notify_info_data_table
); i
++) {
3361 if ( (notify_info_data_table
[i
].type
== type
) &&
3362 (notify_info_data_table
[i
].field
== field
) ) {
3363 return notify_info_data_table
[i
].variable_type
;
3367 DEBUG(5, ("invalid notify data type %d/%d\n", type
, field
));
3369 return (enum spoolss_NotifyTable
) 0;
3372 /****************************************************************************
3373 ****************************************************************************/
3375 static bool search_notify(enum spoolss_NotifyType type
,
3381 for (i
= 0; i
< ARRAY_SIZE(notify_info_data_table
); i
++) {
3382 if (notify_info_data_table
[i
].type
== type
&&
3383 notify_info_data_table
[i
].field
== field
&&
3384 notify_info_data_table
[i
].fn
!= NULL
) {
3393 /****************************************************************************
3394 ****************************************************************************/
3396 static void construct_info_data(struct spoolss_Notify
*info_data
,
3397 enum spoolss_NotifyType type
,
3398 uint16_t field
, int id
)
3400 info_data
->type
= type
;
3401 info_data
->field
.field
= field
;
3402 info_data
->variable_type
= variable_type_of_notify_info_data(type
, field
);
3403 info_data
->job_id
= id
;
3406 /*******************************************************************
3408 * fill a notify_info struct with info asked
3410 ********************************************************************/
3412 static bool construct_notify_printer_info(struct messaging_context
*msg_ctx
,
3413 struct printer_handle
*print_hnd
,
3414 struct spoolss_NotifyInfo
*info
,
3415 struct spoolss_PrinterInfo2
*pinfo2
,
3417 const struct spoolss_NotifyOptionType
*option_type
,
3419 TALLOC_CTX
*mem_ctx
)
3422 enum spoolss_NotifyType type
;
3425 struct spoolss_Notify
*current_data
;
3427 type
= option_type
->type
;
3429 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3430 (type
== PRINTER_NOTIFY_TYPE
? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3431 option_type
->count
, lp_servicename(snum
)));
3433 for(field_num
=0; field_num
< option_type
->count
; field_num
++) {
3434 field
= option_type
->fields
[field_num
].field
;
3436 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num
, type
, field
));
3438 if (!search_notify(type
, field
, &j
) )
3441 info
->notifies
= TALLOC_REALLOC_ARRAY(info
, info
->notifies
,
3442 struct spoolss_Notify
,
3444 if (info
->notifies
== NULL
) {
3445 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3449 current_data
= &info
->notifies
[info
->count
];
3451 construct_info_data(current_data
, type
, field
, id
);
3453 DEBUG(10, ("construct_notify_printer_info: "
3454 "calling [%s] snum=%d printername=[%s])\n",
3455 notify_info_data_table
[j
].name
, snum
,
3456 pinfo2
->printername
));
3458 notify_info_data_table
[j
].fn(msg_ctx
, snum
, current_data
,
3459 NULL
, pinfo2
, mem_ctx
);
3467 /*******************************************************************
3469 * fill a notify_info struct with info asked
3471 ********************************************************************/
3473 static bool construct_notify_jobs_info(struct messaging_context
*msg_ctx
,
3474 print_queue_struct
*queue
,
3475 struct spoolss_NotifyInfo
*info
,
3476 struct spoolss_PrinterInfo2
*pinfo2
,
3478 const struct spoolss_NotifyOptionType
*option_type
,
3480 TALLOC_CTX
*mem_ctx
)
3483 enum spoolss_NotifyType type
;
3485 struct spoolss_Notify
*current_data
;
3487 DEBUG(4,("construct_notify_jobs_info\n"));
3489 type
= option_type
->type
;
3491 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3492 (type
== PRINTER_NOTIFY_TYPE
? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3493 option_type
->count
));
3495 for(field_num
=0; field_num
<option_type
->count
; field_num
++) {
3496 field
= option_type
->fields
[field_num
].field
;
3498 if (!search_notify(type
, field
, &j
) )
3501 info
->notifies
= TALLOC_REALLOC_ARRAY(info
, info
->notifies
,
3502 struct spoolss_Notify
,
3504 if (info
->notifies
== NULL
) {
3505 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3509 current_data
=&(info
->notifies
[info
->count
]);
3511 construct_info_data(current_data
, type
, field
, id
);
3512 notify_info_data_table
[j
].fn(msg_ctx
, snum
, current_data
,
3513 queue
, pinfo2
, mem_ctx
);
3521 * JFM: The enumeration is not that simple, it's even non obvious.
3523 * let's take an example: I want to monitor the PRINTER SERVER for
3524 * the printer's name and the number of jobs currently queued.
3525 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3526 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3528 * I have 3 printers on the back of my server.
3530 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3533 * 1 printer 1 name 1
3534 * 2 printer 1 cjob 1
3535 * 3 printer 2 name 2
3536 * 4 printer 2 cjob 2
3537 * 5 printer 3 name 3
3538 * 6 printer 3 name 3
3540 * that's the print server case, the printer case is even worse.
3543 /*******************************************************************
3545 * enumerate all printers on the printserver
3546 * fill a notify_info struct with info asked
3548 ********************************************************************/
3550 static WERROR
printserver_notify_info(struct pipes_struct
*p
,
3551 struct policy_handle
*hnd
,
3552 struct spoolss_NotifyInfo
*info
,
3553 TALLOC_CTX
*mem_ctx
)
3556 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
3557 int n_services
=lp_numservices();
3559 struct spoolss_NotifyOption
*option
;
3560 struct spoolss_NotifyOptionType option_type
;
3561 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
3564 DEBUG(4,("printserver_notify_info\n"));
3569 option
= Printer
->notify
.option
;
3572 info
->notifies
= NULL
;
3575 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3576 sending a ffpcn() request first */
3581 for (i
=0; i
<option
->count
; i
++) {
3582 option_type
= option
->types
[i
];
3584 if (option_type
.type
!= PRINTER_NOTIFY_TYPE
)
3587 for (snum
= 0; snum
< n_services
; snum
++) {
3588 if (!lp_browseable(snum
) ||
3589 !lp_snum_ok(snum
) ||
3590 !lp_print_ok(snum
)) {
3591 continue; /* skip */
3594 /* Maybe we should use the SYSTEM session_info here... */
3595 result
= winreg_get_printer(mem_ctx
,
3596 get_session_info_system(),
3598 lp_servicename(snum
),
3600 if (!W_ERROR_IS_OK(result
)) {
3601 DEBUG(4, ("printserver_notify_info: "
3602 "Failed to get printer [%s]\n",
3603 lp_servicename(snum
)));
3608 construct_notify_printer_info(p
->msg_ctx
,
3614 TALLOC_FREE(pinfo2
);
3620 * Debugging information, don't delete.
3623 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3624 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info
->version
, info
->flags
, info
->count
));
3625 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3627 for (i
=0; i
<info
->count
; i
++) {
3628 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3629 i
, info
->data
[i
].type
, info
->data
[i
].field
, info
->data
[i
].reserved
,
3630 info
->data
[i
].id
, info
->data
[i
].size
, info
->data
[i
].enc_type
));
3637 /*******************************************************************
3639 * fill a notify_info struct with info asked
3641 ********************************************************************/
3643 static WERROR
printer_notify_info(struct pipes_struct
*p
,
3644 struct policy_handle
*hnd
,
3645 struct spoolss_NotifyInfo
*info
,
3646 TALLOC_CTX
*mem_ctx
)
3649 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
3652 struct spoolss_NotifyOption
*option
;
3653 struct spoolss_NotifyOptionType option_type
;
3655 print_queue_struct
*queue
=NULL
;
3656 print_status_struct status
;
3657 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
3660 DEBUG(4,("printer_notify_info\n"));
3665 option
= Printer
->notify
.option
;
3669 info
->notifies
= NULL
;
3672 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3673 sending a ffpcn() request first */
3678 if (!get_printer_snum(p
, hnd
, &snum
, NULL
)) {
3682 /* Maybe we should use the SYSTEM session_info here... */
3683 result
= winreg_get_printer(mem_ctx
,
3684 get_session_info_system(),
3686 lp_servicename(snum
), &pinfo2
);
3687 if (!W_ERROR_IS_OK(result
)) {
3691 for (i
=0; i
<option
->count
; i
++) {
3692 option_type
= option
->types
[i
];
3694 switch (option_type
.type
) {
3695 case PRINTER_NOTIFY_TYPE
:
3696 if (construct_notify_printer_info(p
->msg_ctx
,
3705 case JOB_NOTIFY_TYPE
:
3707 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
,
3710 for (j
=0; j
<count
; j
++) {
3711 construct_notify_jobs_info(p
->msg_ctx
,
3725 * Debugging information, don't delete.
3728 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3729 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3730 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3732 for (i=0; i<info->count; i++) {
3733 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3734 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3735 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3739 talloc_free(pinfo2
);
3743 /****************************************************************
3744 _spoolss_RouterRefreshPrinterChangeNotify
3745 ****************************************************************/
3747 WERROR
_spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct
*p
,
3748 struct spoolss_RouterRefreshPrinterChangeNotify
*r
)
3750 struct spoolss_NotifyInfo
*info
;
3752 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
3753 WERROR result
= WERR_BADFID
;
3755 /* we always have a spoolss_NotifyInfo struct */
3756 info
= talloc_zero(p
->mem_ctx
, struct spoolss_NotifyInfo
);
3758 result
= WERR_NOMEM
;
3762 *r
->out
.info
= info
;
3765 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3766 "Invalid handle (%s:%u:%u).\n",
3767 OUR_HANDLE(r
->in
.handle
)));
3771 DEBUG(4,("Printer type %x\n",Printer
->printer_type
));
3774 * We are now using the change value, and
3775 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3776 * I don't have a global notification system, I'm sending back all the
3777 * information even when _NOTHING_ has changed.
3780 /* We need to keep track of the change value to send back in
3781 RRPCN replies otherwise our updates are ignored. */
3783 Printer
->notify
.fnpcn
= true;
3785 if (Printer
->notify
.cli_chan
!= NULL
&&
3786 Printer
->notify
.cli_chan
->active_connections
> 0) {
3787 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3788 "Saving change value in request [%x]\n",
3790 Printer
->notify
.change
= r
->in
.change_low
;
3793 /* just ignore the spoolss_NotifyOption */
3795 switch (Printer
->printer_type
) {
3797 result
= printserver_notify_info(p
, r
->in
.handle
,
3801 case SPLHND_PRINTER
:
3802 result
= printer_notify_info(p
, r
->in
.handle
,
3807 Printer
->notify
.fnpcn
= false;
3813 /********************************************************************
3814 ********************************************************************/
3816 static WERROR
create_printername(TALLOC_CTX
*mem_ctx
,
3817 const char *servername
,
3818 const char *printername
,
3819 const char **printername_p
)
3821 /* FIXME: add lp_force_printername() */
3823 if (servername
== NULL
) {
3824 *printername_p
= talloc_strdup(mem_ctx
, printername
);
3825 W_ERROR_HAVE_NO_MEMORY(*printername_p
);
3829 if (servername
[0] == '\\' && servername
[1] == '\\') {
3833 *printername_p
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s", servername
, printername
);
3834 W_ERROR_HAVE_NO_MEMORY(*printername_p
);
3839 /********************************************************************
3840 ********************************************************************/
3842 static void compose_devicemode_devicename(struct spoolss_DeviceMode
*dm
,
3843 const char *printername
)
3849 dm
->devicename
= talloc_strndup(dm
, printername
,
3850 MIN(strlen(printername
), 31));
3853 /********************************************************************
3854 * construct_printer_info_0
3855 * fill a printer_info_0 struct
3856 ********************************************************************/
3858 static WERROR
construct_printer_info0(TALLOC_CTX
*mem_ctx
,
3859 const struct auth_serversupplied_info
*session_info
,
3860 struct messaging_context
*msg_ctx
,
3861 struct spoolss_PrinterInfo2
*info2
,
3862 const char *servername
,
3863 struct spoolss_PrinterInfo0
*r
,
3867 struct printer_session_counter
*session_counter
;
3868 struct timeval setuptime
;
3869 print_status_struct status
;
3872 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
3873 if (!W_ERROR_IS_OK(result
)) {
3878 r
->servername
= talloc_strdup(mem_ctx
, servername
);
3879 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
3881 r
->servername
= NULL
;
3884 count
= print_queue_length(msg_ctx
, snum
, &status
);
3886 /* check if we already have a counter for this printer */
3887 for (session_counter
= counter_list
; session_counter
; session_counter
= session_counter
->next
) {
3888 if (session_counter
->snum
== snum
)
3892 /* it's the first time, add it to the list */
3893 if (session_counter
== NULL
) {
3894 session_counter
= talloc_zero(counter_list
, struct printer_session_counter
);
3895 W_ERROR_HAVE_NO_MEMORY(session_counter
);
3896 session_counter
->snum
= snum
;
3897 session_counter
->counter
= 0;
3898 DLIST_ADD(counter_list
, session_counter
);
3902 session_counter
->counter
++;
3908 get_startup_time(&setuptime
);
3909 init_systemtime(&r
->time
, gmtime(&setuptime
.tv_sec
));
3912 * the global_counter should be stored in a TDB as it's common to all the clients
3913 * and should be zeroed on samba startup
3915 r
->global_counter
= session_counter
->counter
;
3917 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3918 SSVAL(&r
->version
, 0, 0x0005); /* NT 5 */
3919 SSVAL(&r
->version
, 2, 0x0893); /* build 2195 */
3920 r
->free_build
= SPOOLSS_RELEASE_BUILD
;
3922 r
->max_spooling
= 0;
3923 r
->session_counter
= session_counter
->counter
;
3924 r
->num_error_out_of_paper
= 0x0;
3925 r
->num_error_not_ready
= 0x0; /* number of print failure */
3927 r
->number_of_processors
= 0x1;
3928 r
->processor_type
= PROCESSOR_INTEL_PENTIUM
; /* 586 Pentium ? */
3929 r
->high_part_total_bytes
= 0x0;
3931 /* ChangeID in milliseconds*/
3932 winreg_printer_get_changeid(mem_ctx
, session_info
, msg_ctx
,
3933 info2
->sharename
, &r
->change_id
);
3935 r
->last_error
= WERR_OK
;
3936 r
->status
= nt_printq_status(status
.status
);
3937 r
->enumerate_network_printers
= 0x0;
3938 r
->c_setprinter
= 0x0;
3939 r
->processor_architecture
= PROCESSOR_ARCHITECTURE_INTEL
;
3940 r
->processor_level
= 0x6; /* 6 ???*/
3949 /********************************************************************
3950 * construct_printer_info1
3951 * fill a spoolss_PrinterInfo1 struct
3952 ********************************************************************/
3954 static WERROR
construct_printer_info1(TALLOC_CTX
*mem_ctx
,
3955 const struct spoolss_PrinterInfo2
*info2
,
3957 const char *servername
,
3958 struct spoolss_PrinterInfo1
*r
,
3965 if (info2
->comment
== NULL
|| info2
->comment
[0] == '\0') {
3966 r
->comment
= talloc_strdup(mem_ctx
, lp_comment(snum
));
3968 r
->comment
= talloc_strdup(mem_ctx
, info2
->comment
); /* saved comment */
3970 W_ERROR_HAVE_NO_MEMORY(r
->comment
);
3972 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->name
);
3973 if (!W_ERROR_IS_OK(result
)) {
3977 r
->description
= talloc_asprintf(mem_ctx
, "%s,%s,%s",
3981 W_ERROR_HAVE_NO_MEMORY(r
->description
);
3986 /********************************************************************
3987 * construct_printer_info2
3988 * fill a spoolss_PrinterInfo2 struct
3989 ********************************************************************/
3991 static WERROR
construct_printer_info2(TALLOC_CTX
*mem_ctx
,
3992 struct messaging_context
*msg_ctx
,
3993 const struct spoolss_PrinterInfo2
*info2
,
3994 const char *servername
,
3995 struct spoolss_PrinterInfo2
*r
,
3999 print_status_struct status
;
4002 count
= print_queue_length(msg_ctx
, snum
, &status
);
4005 r
->servername
= talloc_strdup(mem_ctx
, servername
);
4006 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
4008 r
->servername
= NULL
;
4011 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4012 if (!W_ERROR_IS_OK(result
)) {
4016 r
->sharename
= talloc_strdup(mem_ctx
, lp_servicename(snum
));
4017 W_ERROR_HAVE_NO_MEMORY(r
->sharename
);
4018 r
->portname
= talloc_strdup(mem_ctx
, info2
->portname
);
4019 W_ERROR_HAVE_NO_MEMORY(r
->portname
);
4020 r
->drivername
= talloc_strdup(mem_ctx
, info2
->drivername
);
4021 W_ERROR_HAVE_NO_MEMORY(r
->drivername
);
4023 if (info2
->comment
[0] == '\0') {
4024 r
->comment
= talloc_strdup(mem_ctx
, lp_comment(snum
));
4026 r
->comment
= talloc_strdup(mem_ctx
, info2
->comment
);
4028 W_ERROR_HAVE_NO_MEMORY(r
->comment
);
4030 r
->location
= talloc_strdup(mem_ctx
, info2
->location
);
4031 if (info2
->location
[0] == '\0') {
4032 const char *loc
= NULL
;
4035 nt_status
= printer_list_get_printer(mem_ctx
,
4040 if (NT_STATUS_IS_OK(nt_status
)) {
4042 r
->location
= talloc_strdup(mem_ctx
, loc
);
4046 W_ERROR_HAVE_NO_MEMORY(r
->location
);
4048 r
->sepfile
= talloc_strdup(mem_ctx
, info2
->sepfile
);
4049 W_ERROR_HAVE_NO_MEMORY(r
->sepfile
);
4050 r
->printprocessor
= talloc_strdup(mem_ctx
, info2
->printprocessor
);
4051 W_ERROR_HAVE_NO_MEMORY(r
->printprocessor
);
4052 r
->datatype
= talloc_strdup(mem_ctx
, info2
->datatype
);
4053 W_ERROR_HAVE_NO_MEMORY(r
->datatype
);
4054 r
->parameters
= talloc_strdup(mem_ctx
, info2
->parameters
);
4055 W_ERROR_HAVE_NO_MEMORY(r
->parameters
);
4057 r
->attributes
= info2
->attributes
;
4059 r
->priority
= info2
->priority
;
4060 r
->defaultpriority
= info2
->defaultpriority
;
4061 r
->starttime
= info2
->starttime
;
4062 r
->untiltime
= info2
->untiltime
;
4063 r
->status
= nt_printq_status(status
.status
);
4065 r
->averageppm
= info2
->averageppm
;
4067 copy_devicemode(mem_ctx
, info2
->devmode
, &r
->devmode
);
4069 DEBUG(8,("Returning NULL Devicemode!\n"));
4072 compose_devicemode_devicename(r
->devmode
, r
->printername
);
4076 if (info2
->secdesc
!= NULL
) {
4077 /* don't use talloc_steal() here unless you do a deep steal of all
4078 the SEC_DESC members */
4080 r
->secdesc
= dup_sec_desc(mem_ctx
, info2
->secdesc
);
4086 /********************************************************************
4087 * construct_printer_info3
4088 * fill a spoolss_PrinterInfo3 struct
4089 ********************************************************************/
4091 static WERROR
construct_printer_info3(TALLOC_CTX
*mem_ctx
,
4092 const struct spoolss_PrinterInfo2
*info2
,
4093 const char *servername
,
4094 struct spoolss_PrinterInfo3
*r
,
4097 /* These are the components of the SD we are returning. */
4099 if (info2
->secdesc
!= NULL
) {
4100 /* don't use talloc_steal() here unless you do a deep steal of all
4101 the SEC_DESC members */
4103 r
->secdesc
= dup_sec_desc(mem_ctx
, info2
->secdesc
);
4104 W_ERROR_HAVE_NO_MEMORY(r
->secdesc
);
4110 /********************************************************************
4111 * construct_printer_info4
4112 * fill a spoolss_PrinterInfo4 struct
4113 ********************************************************************/
4115 static WERROR
construct_printer_info4(TALLOC_CTX
*mem_ctx
,
4116 const struct spoolss_PrinterInfo2
*info2
,
4117 const char *servername
,
4118 struct spoolss_PrinterInfo4
*r
,
4123 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4124 if (!W_ERROR_IS_OK(result
)) {
4129 r
->servername
= talloc_strdup(mem_ctx
, servername
);
4130 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
4132 r
->servername
= NULL
;
4135 r
->attributes
= info2
->attributes
;
4140 /********************************************************************
4141 * construct_printer_info5
4142 * fill a spoolss_PrinterInfo5 struct
4143 ********************************************************************/
4145 static WERROR
construct_printer_info5(TALLOC_CTX
*mem_ctx
,
4146 const struct spoolss_PrinterInfo2
*info2
,
4147 const char *servername
,
4148 struct spoolss_PrinterInfo5
*r
,
4153 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4154 if (!W_ERROR_IS_OK(result
)) {
4158 r
->portname
= talloc_strdup(mem_ctx
, info2
->portname
);
4159 W_ERROR_HAVE_NO_MEMORY(r
->portname
);
4161 r
->attributes
= info2
->attributes
;
4163 /* these two are not used by NT+ according to MSDN */
4164 r
->device_not_selected_timeout
= 0x0; /* have seen 0x3a98 */
4165 r
->transmission_retry_timeout
= 0x0; /* have seen 0xafc8 */
4170 /********************************************************************
4171 * construct_printer_info_6
4172 * fill a spoolss_PrinterInfo6 struct
4173 ********************************************************************/
4175 static WERROR
construct_printer_info6(TALLOC_CTX
*mem_ctx
,
4176 struct messaging_context
*msg_ctx
,
4177 const struct spoolss_PrinterInfo2
*info2
,
4178 const char *servername
,
4179 struct spoolss_PrinterInfo6
*r
,
4182 print_status_struct status
;
4184 print_queue_length(msg_ctx
, snum
, &status
);
4186 r
->status
= nt_printq_status(status
.status
);
4191 /********************************************************************
4192 * construct_printer_info7
4193 * fill a spoolss_PrinterInfo7 struct
4194 ********************************************************************/
4196 static WERROR
construct_printer_info7(TALLOC_CTX
*mem_ctx
,
4197 struct messaging_context
*msg_ctx
,
4198 const char *servername
,
4199 struct spoolss_PrinterInfo7
*r
,
4202 struct auth_serversupplied_info
*session_info
;
4206 status
= make_session_info_system(mem_ctx
, &session_info
);
4207 if (!NT_STATUS_IS_OK(status
)) {
4208 DEBUG(0, ("construct_printer_info7: "
4209 "Could not create system session_info\n"));
4213 if (is_printer_published(mem_ctx
, session_info
, msg_ctx
,
4215 lp_servicename(snum
), &guid
, NULL
)) {
4216 r
->guid
= talloc_strdup_upper(mem_ctx
, GUID_string2(mem_ctx
, &guid
));
4217 r
->action
= DSPRINT_PUBLISH
;
4219 r
->guid
= talloc_strdup(mem_ctx
, "");
4220 r
->action
= DSPRINT_UNPUBLISH
;
4222 W_ERROR_HAVE_NO_MEMORY(r
->guid
);
4224 TALLOC_FREE(session_info
);
4228 /********************************************************************
4229 * construct_printer_info8
4230 * fill a spoolss_PrinterInfo8 struct
4231 ********************************************************************/
4233 static WERROR
construct_printer_info8(TALLOC_CTX
*mem_ctx
,
4234 const struct spoolss_PrinterInfo2
*info2
,
4235 const char *servername
,
4236 struct spoolss_DeviceModeInfo
*r
,
4240 const char *printername
;
4242 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &printername
);
4243 if (!W_ERROR_IS_OK(result
)) {
4247 copy_devicemode(mem_ctx
, info2
->devmode
, &r
->devmode
);
4249 DEBUG(8,("Returning NULL Devicemode!\n"));
4252 compose_devicemode_devicename(r
->devmode
, printername
);
4258 /********************************************************************
4259 ********************************************************************/
4261 static bool snum_is_shared_printer(int snum
)
4263 return (lp_browseable(snum
) && lp_snum_ok(snum
) && lp_print_ok(snum
));
4266 /********************************************************************
4267 Spoolss_enumprinters.
4268 ********************************************************************/
4270 static WERROR
enum_all_printers_info_level(TALLOC_CTX
*mem_ctx
,
4271 const struct auth_serversupplied_info
*session_info
,
4272 struct messaging_context
*msg_ctx
,
4273 const char *servername
,
4276 union spoolss_PrinterInfo
**info_p
,
4280 int n_services
= lp_numservices();
4281 union spoolss_PrinterInfo
*info
= NULL
;
4283 WERROR result
= WERR_OK
;
4288 for (snum
= 0; snum
< n_services
; snum
++) {
4290 const char *printer
;
4291 struct spoolss_PrinterInfo2
*info2
;
4293 if (!snum_is_shared_printer(snum
)) {
4297 printer
= lp_const_servicename(snum
);
4299 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4302 result
= winreg_create_printer(mem_ctx
,
4306 if (!W_ERROR_IS_OK(result
)) {
4310 info
= TALLOC_REALLOC_ARRAY(mem_ctx
, info
,
4311 union spoolss_PrinterInfo
,
4314 result
= WERR_NOMEM
;
4318 result
= winreg_get_printer(mem_ctx
, session_info
, msg_ctx
,
4320 if (!W_ERROR_IS_OK(result
)) {
4326 result
= construct_printer_info0(info
, session_info
,
4329 &info
[count
].info0
, snum
);
4332 result
= construct_printer_info1(info
, info2
, flags
,
4334 &info
[count
].info1
, snum
);
4337 result
= construct_printer_info2(info
, msg_ctx
, info2
,
4339 &info
[count
].info2
, snum
);
4342 result
= construct_printer_info4(info
, info2
,
4344 &info
[count
].info4
, snum
);
4347 result
= construct_printer_info5(info
, info2
,
4349 &info
[count
].info5
, snum
);
4353 result
= WERR_UNKNOWN_LEVEL
;
4357 if (!W_ERROR_IS_OK(result
)) {
4368 if (!W_ERROR_IS_OK(result
)) {
4378 /********************************************************************
4379 * handle enumeration of printers at level 0
4380 ********************************************************************/
4382 static WERROR
enumprinters_level0(TALLOC_CTX
*mem_ctx
,
4383 const struct auth_serversupplied_info
*session_info
,
4384 struct messaging_context
*msg_ctx
,
4386 const char *servername
,
4387 union spoolss_PrinterInfo
**info
,
4390 DEBUG(4,("enum_all_printers_info_0\n"));
4392 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4393 servername
, 0, flags
, info
, count
);
4397 /********************************************************************
4398 ********************************************************************/
4400 static WERROR
enum_all_printers_info_1(TALLOC_CTX
*mem_ctx
,
4401 const struct auth_serversupplied_info
*session_info
,
4402 struct messaging_context
*msg_ctx
,
4403 const char *servername
,
4405 union spoolss_PrinterInfo
**info
,
4408 DEBUG(4,("enum_all_printers_info_1\n"));
4410 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4411 servername
, 1, flags
, info
, count
);
4414 /********************************************************************
4415 enum_all_printers_info_1_local.
4416 *********************************************************************/
4418 static WERROR
enum_all_printers_info_1_local(TALLOC_CTX
*mem_ctx
,
4419 const struct auth_serversupplied_info
*session_info
,
4420 struct messaging_context
*msg_ctx
,
4421 const char *servername
,
4422 union spoolss_PrinterInfo
**info
,
4425 DEBUG(4,("enum_all_printers_info_1_local\n"));
4427 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4428 servername
, PRINTER_ENUM_ICON8
, info
, count
);
4431 /********************************************************************
4432 enum_all_printers_info_1_name.
4433 *********************************************************************/
4435 static WERROR
enum_all_printers_info_1_name(TALLOC_CTX
*mem_ctx
,
4436 const struct auth_serversupplied_info
*session_info
,
4437 struct messaging_context
*msg_ctx
,
4438 const char *servername
,
4439 union spoolss_PrinterInfo
**info
,
4442 const char *s
= servername
;
4444 DEBUG(4,("enum_all_printers_info_1_name\n"));
4446 if ((servername
[0] == '\\') && (servername
[1] == '\\')) {
4450 if (!is_myname_or_ipaddr(s
)) {
4451 return WERR_INVALID_NAME
;
4454 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4455 servername
, PRINTER_ENUM_ICON8
, info
, count
);
4458 /********************************************************************
4459 enum_all_printers_info_1_network.
4460 *********************************************************************/
4462 static WERROR
enum_all_printers_info_1_network(TALLOC_CTX
*mem_ctx
,
4463 const struct auth_serversupplied_info
*session_info
,
4464 struct messaging_context
*msg_ctx
,
4465 const char *servername
,
4466 union spoolss_PrinterInfo
**info
,
4469 const char *s
= servername
;
4471 DEBUG(4,("enum_all_printers_info_1_network\n"));
4473 /* If we respond to a enum_printers level 1 on our name with flags
4474 set to PRINTER_ENUM_REMOTE with a list of printers then these
4475 printers incorrectly appear in the APW browse list.
4476 Specifically the printers for the server appear at the workgroup
4477 level where all the other servers in the domain are
4478 listed. Windows responds to this call with a
4479 WERR_CAN_NOT_COMPLETE so we should do the same. */
4481 if (servername
[0] == '\\' && servername
[1] == '\\') {
4485 if (is_myname_or_ipaddr(s
)) {
4486 return WERR_CAN_NOT_COMPLETE
;
4489 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4490 servername
, PRINTER_ENUM_NAME
, info
, count
);
4493 /********************************************************************
4494 * api_spoolss_enumprinters
4496 * called from api_spoolss_enumprinters (see this to understand)
4497 ********************************************************************/
4499 static WERROR
enum_all_printers_info_2(TALLOC_CTX
*mem_ctx
,
4500 const struct auth_serversupplied_info
*session_info
,
4501 struct messaging_context
*msg_ctx
,
4502 const char *servername
,
4503 union spoolss_PrinterInfo
**info
,
4506 DEBUG(4,("enum_all_printers_info_2\n"));
4508 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4509 servername
, 2, 0, info
, count
);
4512 /********************************************************************
4513 * handle enumeration of printers at level 1
4514 ********************************************************************/
4516 static WERROR
enumprinters_level1(TALLOC_CTX
*mem_ctx
,
4517 const struct auth_serversupplied_info
*session_info
,
4518 struct messaging_context
*msg_ctx
,
4520 const char *servername
,
4521 union spoolss_PrinterInfo
**info
,
4524 /* Not all the flags are equals */
4526 if (flags
& PRINTER_ENUM_LOCAL
) {
4527 return enum_all_printers_info_1_local(mem_ctx
, session_info
,
4528 msg_ctx
, servername
, info
, count
);
4531 if (flags
& PRINTER_ENUM_NAME
) {
4532 return enum_all_printers_info_1_name(mem_ctx
, session_info
,
4533 msg_ctx
, servername
, info
,
4537 if (flags
& PRINTER_ENUM_NETWORK
) {
4538 return enum_all_printers_info_1_network(mem_ctx
, session_info
,
4539 msg_ctx
, servername
, info
,
4543 return WERR_OK
; /* NT4sp5 does that */
4546 /********************************************************************
4547 * handle enumeration of printers at level 2
4548 ********************************************************************/
4550 static WERROR
enumprinters_level2(TALLOC_CTX
*mem_ctx
,
4551 const struct auth_serversupplied_info
*session_info
,
4552 struct messaging_context
*msg_ctx
,
4554 const char *servername
,
4555 union spoolss_PrinterInfo
**info
,
4558 if (flags
& PRINTER_ENUM_LOCAL
) {
4560 return enum_all_printers_info_2(mem_ctx
, session_info
, msg_ctx
,
4565 if (flags
& PRINTER_ENUM_NAME
) {
4566 if (servername
&& !is_myname_or_ipaddr(canon_servername(servername
))) {
4567 return WERR_INVALID_NAME
;
4570 return enum_all_printers_info_2(mem_ctx
, session_info
, msg_ctx
,
4575 if (flags
& PRINTER_ENUM_REMOTE
) {
4576 return WERR_UNKNOWN_LEVEL
;
4582 /********************************************************************
4583 * handle enumeration of printers at level 4
4584 ********************************************************************/
4586 static WERROR
enumprinters_level4(TALLOC_CTX
*mem_ctx
,
4587 const struct auth_serversupplied_info
*session_info
,
4588 struct messaging_context
*msg_ctx
,
4590 const char *servername
,
4591 union spoolss_PrinterInfo
**info
,
4594 DEBUG(4,("enum_all_printers_info_4\n"));
4596 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4597 servername
, 4, flags
, info
, count
);
4601 /********************************************************************
4602 * handle enumeration of printers at level 5
4603 ********************************************************************/
4605 static WERROR
enumprinters_level5(TALLOC_CTX
*mem_ctx
,
4606 const struct auth_serversupplied_info
*session_info
,
4607 struct messaging_context
*msg_ctx
,
4609 const char *servername
,
4610 union spoolss_PrinterInfo
**info
,
4613 DEBUG(4,("enum_all_printers_info_5\n"));
4615 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4616 servername
, 5, flags
, info
, count
);
4619 /****************************************************************
4620 _spoolss_EnumPrinters
4621 ****************************************************************/
4623 WERROR
_spoolss_EnumPrinters(struct pipes_struct
*p
,
4624 struct spoolss_EnumPrinters
*r
)
4626 const struct auth_serversupplied_info
*session_info
= get_session_info_system();
4629 /* that's an [in out] buffer */
4631 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
4632 return WERR_INVALID_PARAM
;
4635 DEBUG(4,("_spoolss_EnumPrinters\n"));
4639 *r
->out
.info
= NULL
;
4643 * flags==PRINTER_ENUM_NAME
4644 * if name=="" then enumerates all printers
4645 * if name!="" then enumerate the printer
4646 * flags==PRINTER_ENUM_REMOTE
4647 * name is NULL, enumerate printers
4648 * Level 2: name!="" enumerates printers, name can't be NULL
4649 * Level 3: doesn't exist
4650 * Level 4: does a local registry lookup
4651 * Level 5: same as Level 2
4654 if (r
->in
.server
&& r
->in
.server
[0] == '\0') {
4655 r
->in
.server
= NULL
;
4658 switch (r
->in
.level
) {
4660 result
= enumprinters_level0(p
->mem_ctx
, session_info
,
4661 p
->msg_ctx
, r
->in
.flags
,
4663 r
->out
.info
, r
->out
.count
);
4666 result
= enumprinters_level1(p
->mem_ctx
, session_info
,
4667 p
->msg_ctx
, r
->in
.flags
,
4669 r
->out
.info
, r
->out
.count
);
4672 result
= enumprinters_level2(p
->mem_ctx
, session_info
,
4673 p
->msg_ctx
, r
->in
.flags
,
4675 r
->out
.info
, r
->out
.count
);
4678 result
= enumprinters_level4(p
->mem_ctx
, session_info
,
4679 p
->msg_ctx
, r
->in
.flags
,
4681 r
->out
.info
, r
->out
.count
);
4684 result
= enumprinters_level5(p
->mem_ctx
, session_info
,
4685 p
->msg_ctx
, r
->in
.flags
,
4687 r
->out
.info
, r
->out
.count
);
4690 return WERR_UNKNOWN_LEVEL
;
4693 if (!W_ERROR_IS_OK(result
)) {
4697 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
4698 spoolss_EnumPrinters
,
4699 *r
->out
.info
, r
->in
.level
,
4701 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
4702 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
4704 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
4707 /****************************************************************
4709 ****************************************************************/
4711 WERROR
_spoolss_GetPrinter(struct pipes_struct
*p
,
4712 struct spoolss_GetPrinter
*r
)
4714 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
4715 struct spoolss_PrinterInfo2
*info2
= NULL
;
4716 WERROR result
= WERR_OK
;
4719 /* that's an [in out] buffer */
4721 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
4722 return WERR_INVALID_PARAM
;
4727 if (Printer
== NULL
) {
4731 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
4735 result
= winreg_get_printer(p
->mem_ctx
,
4736 get_session_info_system(),
4738 lp_const_servicename(snum
),
4740 if (!W_ERROR_IS_OK(result
)) {
4744 switch (r
->in
.level
) {
4746 result
= construct_printer_info0(p
->mem_ctx
,
4747 get_session_info_system(),
4750 Printer
->servername
,
4751 &r
->out
.info
->info0
,
4755 result
= construct_printer_info1(p
->mem_ctx
, info2
,
4757 Printer
->servername
,
4758 &r
->out
.info
->info1
, snum
);
4761 result
= construct_printer_info2(p
->mem_ctx
, p
->msg_ctx
, info2
,
4762 Printer
->servername
,
4763 &r
->out
.info
->info2
, snum
);
4766 result
= construct_printer_info3(p
->mem_ctx
, info2
,
4767 Printer
->servername
,
4768 &r
->out
.info
->info3
, snum
);
4771 result
= construct_printer_info4(p
->mem_ctx
, info2
,
4772 Printer
->servername
,
4773 &r
->out
.info
->info4
, snum
);
4776 result
= construct_printer_info5(p
->mem_ctx
, info2
,
4777 Printer
->servername
,
4778 &r
->out
.info
->info5
, snum
);
4781 result
= construct_printer_info6(p
->mem_ctx
, p
->msg_ctx
, info2
,
4782 Printer
->servername
,
4783 &r
->out
.info
->info6
, snum
);
4786 result
= construct_printer_info7(p
->mem_ctx
, p
->msg_ctx
,
4787 Printer
->servername
,
4788 &r
->out
.info
->info7
, snum
);
4791 result
= construct_printer_info8(p
->mem_ctx
, info2
,
4792 Printer
->servername
,
4793 &r
->out
.info
->info8
, snum
);
4796 result
= WERR_UNKNOWN_LEVEL
;
4801 if (!W_ERROR_IS_OK(result
)) {
4802 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4803 r
->in
.level
, win_errstr(result
)));
4804 TALLOC_FREE(r
->out
.info
);
4808 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo
,
4809 r
->out
.info
, r
->in
.level
);
4810 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
4812 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
4815 /********************************************************************
4816 ********************************************************************/
4818 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4820 if (in && strlen(in)) { \
4821 out = talloc_strdup(mem_ctx, in); \
4823 out = talloc_strdup(mem_ctx, ""); \
4825 W_ERROR_HAVE_NO_MEMORY(out); \
4828 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4830 if (in && strlen(in)) { \
4831 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4833 out = talloc_strdup(mem_ctx, ""); \
4835 W_ERROR_HAVE_NO_MEMORY(out); \
4838 static WERROR
string_array_from_driver_info(TALLOC_CTX
*mem_ctx
,
4839 const char **string_array
,
4840 const char ***presult
,
4841 const char *cservername
,
4845 int i
, num_strings
= 0;
4846 const char **array
= NULL
;
4848 if (string_array
== NULL
) {
4849 return WERR_INVALID_PARAMETER
;
4852 for (i
=0; string_array
[i
] && string_array
[i
][0] != '\0'; i
++) {
4853 const char *str
= NULL
;
4855 if (cservername
== NULL
|| arch
== NULL
) {
4856 FILL_DRIVER_STRING(mem_ctx
, string_array
[i
], str
);
4858 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
, arch
, version
, string_array
[i
], str
);
4861 if (!add_string_to_array(mem_ctx
, str
, &array
, &num_strings
)) {
4868 ADD_TO_ARRAY(mem_ctx
, const char *, NULL
,
4869 &array
, &num_strings
);
4879 /********************************************************************
4880 * fill a spoolss_DriverInfo1 struct
4881 ********************************************************************/
4883 static WERROR
fill_printer_driver_info1(TALLOC_CTX
*mem_ctx
,
4884 struct spoolss_DriverInfo1
*r
,
4885 const struct spoolss_DriverInfo8
*driver
,
4886 const char *servername
)
4888 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4889 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4894 /********************************************************************
4895 * fill a spoolss_DriverInfo2 struct
4896 ********************************************************************/
4898 static WERROR
fill_printer_driver_info2(TALLOC_CTX
*mem_ctx
,
4899 struct spoolss_DriverInfo2
*r
,
4900 const struct spoolss_DriverInfo8
*driver
,
4901 const char *servername
)
4904 const char *cservername
= canon_servername(servername
);
4906 r
->version
= driver
->version
;
4908 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4909 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4910 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
4911 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
4913 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4914 driver
->architecture
,
4916 driver
->driver_path
,
4919 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4920 driver
->architecture
,
4925 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4926 driver
->architecture
,
4928 driver
->config_file
,
4934 /********************************************************************
4935 * fill a spoolss_DriverInfo3 struct
4936 ********************************************************************/
4938 static WERROR
fill_printer_driver_info3(TALLOC_CTX
*mem_ctx
,
4939 struct spoolss_DriverInfo3
*r
,
4940 const struct spoolss_DriverInfo8
*driver
,
4941 const char *servername
)
4943 const char *cservername
= canon_servername(servername
);
4945 r
->version
= driver
->version
;
4947 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4948 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4949 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
4950 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
4952 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4953 driver
->architecture
,
4955 driver
->driver_path
,
4958 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4959 driver
->architecture
,
4964 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4965 driver
->architecture
,
4967 driver
->config_file
,
4970 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4971 driver
->architecture
,
4976 FILL_DRIVER_STRING(mem_ctx
,
4977 driver
->monitor_name
,
4980 FILL_DRIVER_STRING(mem_ctx
,
4981 driver
->default_datatype
,
4982 r
->default_datatype
);
4984 return string_array_from_driver_info(mem_ctx
,
4985 driver
->dependent_files
,
4986 &r
->dependent_files
,
4988 driver
->architecture
,
4992 /********************************************************************
4993 * fill a spoolss_DriverInfo4 struct
4994 ********************************************************************/
4996 static WERROR
fill_printer_driver_info4(TALLOC_CTX
*mem_ctx
,
4997 struct spoolss_DriverInfo4
*r
,
4998 const struct spoolss_DriverInfo8
*driver
,
4999 const char *servername
)
5001 const char *cservername
= canon_servername(servername
);
5004 r
->version
= driver
->version
;
5006 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5007 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5008 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5009 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5011 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5012 driver
->architecture
,
5014 driver
->driver_path
,
5017 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5018 driver
->architecture
,
5023 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5024 driver
->architecture
,
5026 driver
->config_file
,
5029 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5030 driver
->architecture
,
5035 result
= string_array_from_driver_info(mem_ctx
,
5036 driver
->dependent_files
,
5037 &r
->dependent_files
,
5039 driver
->architecture
,
5041 if (!W_ERROR_IS_OK(result
)) {
5045 FILL_DRIVER_STRING(mem_ctx
,
5046 driver
->monitor_name
,
5049 FILL_DRIVER_STRING(mem_ctx
,
5050 driver
->default_datatype
,
5051 r
->default_datatype
);
5054 result
= string_array_from_driver_info(mem_ctx
,
5055 driver
->previous_names
,
5062 /********************************************************************
5063 * fill a spoolss_DriverInfo5 struct
5064 ********************************************************************/
5066 static WERROR
fill_printer_driver_info5(TALLOC_CTX
*mem_ctx
,
5067 struct spoolss_DriverInfo5
*r
,
5068 const struct spoolss_DriverInfo8
*driver
,
5069 const char *servername
)
5071 const char *cservername
= canon_servername(servername
);
5073 r
->version
= driver
->version
;
5075 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5076 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5077 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5078 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5080 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5081 driver
->architecture
,
5083 driver
->driver_path
,
5086 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5087 driver
->architecture
,
5092 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5093 driver
->architecture
,
5095 driver
->config_file
,
5098 r
->driver_attributes
= 0;
5099 r
->config_version
= 0;
5100 r
->driver_version
= 0;
5104 /********************************************************************
5105 * fill a spoolss_DriverInfo6 struct
5106 ********************************************************************/
5108 static WERROR
fill_printer_driver_info6(TALLOC_CTX
*mem_ctx
,
5109 struct spoolss_DriverInfo6
*r
,
5110 const struct spoolss_DriverInfo8
*driver
,
5111 const char *servername
)
5113 const char *cservername
= canon_servername(servername
);
5116 r
->version
= driver
->version
;
5118 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5119 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5120 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5121 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5123 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5124 driver
->architecture
,
5126 driver
->driver_path
,
5129 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5130 driver
->architecture
,
5135 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5136 driver
->architecture
,
5138 driver
->config_file
,
5141 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5142 driver
->architecture
,
5147 FILL_DRIVER_STRING(mem_ctx
,
5148 driver
->monitor_name
,
5151 FILL_DRIVER_STRING(mem_ctx
,
5152 driver
->default_datatype
,
5153 r
->default_datatype
);
5155 result
= string_array_from_driver_info(mem_ctx
,
5156 driver
->dependent_files
,
5157 &r
->dependent_files
,
5159 driver
->architecture
,
5161 if (!W_ERROR_IS_OK(result
)) {
5165 result
= string_array_from_driver_info(mem_ctx
,
5166 driver
->previous_names
,
5169 if (!W_ERROR_IS_OK(result
)) {
5173 r
->driver_date
= driver
->driver_date
;
5174 r
->driver_version
= driver
->driver_version
;
5176 FILL_DRIVER_STRING(mem_ctx
,
5177 driver
->manufacturer_name
,
5178 r
->manufacturer_name
);
5179 FILL_DRIVER_STRING(mem_ctx
,
5180 driver
->manufacturer_url
,
5181 r
->manufacturer_url
);
5182 FILL_DRIVER_STRING(mem_ctx
,
5183 driver
->hardware_id
,
5185 FILL_DRIVER_STRING(mem_ctx
,
5192 /********************************************************************
5193 * fill a spoolss_DriverInfo8 struct
5194 ********************************************************************/
5196 static WERROR
fill_printer_driver_info8(TALLOC_CTX
*mem_ctx
,
5197 struct spoolss_DriverInfo8
*r
,
5198 const struct spoolss_DriverInfo8
*driver
,
5199 const char *servername
)
5201 const char *cservername
= canon_servername(servername
);
5204 r
->version
= driver
->version
;
5206 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5207 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5208 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5209 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5211 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5212 driver
->architecture
,
5214 driver
->driver_path
,
5217 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5218 driver
->architecture
,
5223 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5224 driver
->architecture
,
5226 driver
->config_file
,
5229 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5230 driver
->architecture
,
5235 FILL_DRIVER_STRING(mem_ctx
,
5236 driver
->monitor_name
,
5239 FILL_DRIVER_STRING(mem_ctx
,
5240 driver
->default_datatype
,
5241 r
->default_datatype
);
5243 result
= string_array_from_driver_info(mem_ctx
,
5244 driver
->dependent_files
,
5245 &r
->dependent_files
,
5247 driver
->architecture
,
5249 if (!W_ERROR_IS_OK(result
)) {
5253 result
= string_array_from_driver_info(mem_ctx
,
5254 driver
->previous_names
,
5257 if (!W_ERROR_IS_OK(result
)) {
5261 r
->driver_date
= driver
->driver_date
;
5262 r
->driver_version
= driver
->driver_version
;
5264 FILL_DRIVER_STRING(mem_ctx
,
5265 driver
->manufacturer_name
,
5266 r
->manufacturer_name
);
5267 FILL_DRIVER_STRING(mem_ctx
,
5268 driver
->manufacturer_url
,
5269 r
->manufacturer_url
);
5270 FILL_DRIVER_STRING(mem_ctx
,
5271 driver
->hardware_id
,
5273 FILL_DRIVER_STRING(mem_ctx
,
5277 FILL_DRIVER_STRING(mem_ctx
,
5278 driver
->print_processor
,
5279 r
->print_processor
);
5280 FILL_DRIVER_STRING(mem_ctx
,
5281 driver
->vendor_setup
,
5284 result
= string_array_from_driver_info(mem_ctx
,
5285 driver
->color_profiles
,
5288 if (!W_ERROR_IS_OK(result
)) {
5292 FILL_DRIVER_STRING(mem_ctx
,
5296 r
->printer_driver_attributes
= driver
->printer_driver_attributes
;
5298 result
= string_array_from_driver_info(mem_ctx
,
5299 driver
->core_driver_dependencies
,
5300 &r
->core_driver_dependencies
,
5302 if (!W_ERROR_IS_OK(result
)) {
5306 r
->min_inbox_driver_ver_date
= driver
->min_inbox_driver_ver_date
;
5307 r
->min_inbox_driver_ver_version
= driver
->min_inbox_driver_ver_version
;
5312 #if 0 /* disabled until marshalling issues are resolved - gd */
5313 /********************************************************************
5314 ********************************************************************/
5316 static WERROR
fill_spoolss_DriverFileInfo(TALLOC_CTX
*mem_ctx
,
5317 struct spoolss_DriverFileInfo
*r
,
5318 const char *cservername
,
5319 const char *file_name
,
5320 enum spoolss_DriverFileType file_type
,
5321 uint32_t file_version
)
5323 r
->file_name
= talloc_asprintf(mem_ctx
, "\\\\%s%s",
5324 cservername
, file_name
);
5325 W_ERROR_HAVE_NO_MEMORY(r
->file_name
);
5326 r
->file_type
= file_type
;
5327 r
->file_version
= file_version
;
5332 /********************************************************************
5333 ********************************************************************/
5335 static WERROR
spoolss_DriverFileInfo_from_driver(TALLOC_CTX
*mem_ctx
,
5336 const struct spoolss_DriverInfo8
*driver
,
5337 const char *cservername
,
5338 struct spoolss_DriverFileInfo
**info_p
,
5341 struct spoolss_DriverFileInfo
*info
= NULL
;
5349 if (strlen(driver
->driver_path
)) {
5350 info
= TALLOC_REALLOC_ARRAY(mem_ctx
, info
,
5351 struct spoolss_DriverFileInfo
,
5353 W_ERROR_HAVE_NO_MEMORY(info
);
5354 result
= fill_spoolss_DriverFileInfo(info
,
5357 driver
->driver_path
,
5358 SPOOLSS_DRIVER_FILE_TYPE_RENDERING
,
5360 W_ERROR_NOT_OK_RETURN(result
);
5364 if (strlen(driver
->config_file
)) {
5365 info
= TALLOC_REALLOC_ARRAY(mem_ctx
, info
,
5366 struct spoolss_DriverFileInfo
,
5368 W_ERROR_HAVE_NO_MEMORY(info
);
5369 result
= fill_spoolss_DriverFileInfo(info
,
5372 driver
->config_file
,
5373 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION
,
5375 W_ERROR_NOT_OK_RETURN(result
);
5379 if (strlen(driver
->data_file
)) {
5380 info
= TALLOC_REALLOC_ARRAY(mem_ctx
, info
,
5381 struct spoolss_DriverFileInfo
,
5383 W_ERROR_HAVE_NO_MEMORY(info
);
5384 result
= fill_spoolss_DriverFileInfo(info
,
5388 SPOOLSS_DRIVER_FILE_TYPE_DATA
,
5390 W_ERROR_NOT_OK_RETURN(result
);
5394 if (strlen(driver
->help_file
)) {
5395 info
= TALLOC_REALLOC_ARRAY(mem_ctx
, info
,
5396 struct spoolss_DriverFileInfo
,
5398 W_ERROR_HAVE_NO_MEMORY(info
);
5399 result
= fill_spoolss_DriverFileInfo(info
,
5403 SPOOLSS_DRIVER_FILE_TYPE_HELP
,
5405 W_ERROR_NOT_OK_RETURN(result
);
5409 for (i
=0; driver
->dependent_files
[i
] && driver
->dependent_files
[i
][0] != '\0'; i
++) {
5410 info
= TALLOC_REALLOC_ARRAY(mem_ctx
, info
,
5411 struct spoolss_DriverFileInfo
,
5413 W_ERROR_HAVE_NO_MEMORY(info
);
5414 result
= fill_spoolss_DriverFileInfo(info
,
5417 driver
->dependent_files
[i
],
5418 SPOOLSS_DRIVER_FILE_TYPE_OTHER
,
5420 W_ERROR_NOT_OK_RETURN(result
);
5430 /********************************************************************
5431 * fill a spoolss_DriverInfo101 struct
5432 ********************************************************************/
5434 static WERROR
fill_printer_driver_info101(TALLOC_CTX
*mem_ctx
,
5435 struct spoolss_DriverInfo101
*r
,
5436 const struct spoolss_DriverInfo8
*driver
,
5437 const char *servername
)
5439 const char *cservername
= canon_servername(servername
);
5442 r
->version
= driver
->version
;
5444 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5445 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5446 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5447 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5449 result
= spoolss_DriverFileInfo_from_driver(mem_ctx
, driver
,
5453 if (!W_ERROR_IS_OK(result
)) {
5457 FILL_DRIVER_STRING(mem_ctx
,
5458 driver
->monitor_name
,
5461 FILL_DRIVER_STRING(mem_ctx
,
5462 driver
->default_datatype
,
5463 r
->default_datatype
);
5465 result
= string_array_from_driver_info(mem_ctx
,
5466 driver
->previous_names
,
5469 if (!W_ERROR_IS_OK(result
)) {
5473 r
->driver_date
= driver
->driver_date
;
5474 r
->driver_version
= driver
->driver_version
;
5476 FILL_DRIVER_STRING(mem_ctx
,
5477 driver
->manufacturer_name
,
5478 r
->manufacturer_name
);
5479 FILL_DRIVER_STRING(mem_ctx
,
5480 driver
->manufacturer_url
,
5481 r
->manufacturer_url
);
5482 FILL_DRIVER_STRING(mem_ctx
,
5483 driver
->hardware_id
,
5485 FILL_DRIVER_STRING(mem_ctx
,
5492 /********************************************************************
5493 ********************************************************************/
5495 static WERROR
construct_printer_driver_info_level(TALLOC_CTX
*mem_ctx
,
5496 const struct auth_serversupplied_info
*session_info
,
5497 struct messaging_context
*msg_ctx
,
5499 union spoolss_DriverInfo
*r
,
5501 const char *servername
,
5502 const char *architecture
,
5505 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
5506 struct spoolss_DriverInfo8
*driver
;
5510 return WERR_UNKNOWN_LEVEL
;
5513 result
= winreg_get_printer(mem_ctx
,
5516 lp_const_servicename(snum
),
5519 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5520 win_errstr(result
)));
5522 if (!W_ERROR_IS_OK(result
)) {
5523 return WERR_INVALID_PRINTER_NAME
;
5526 result
= winreg_get_driver(mem_ctx
, session_info
, msg_ctx
,
5528 pinfo2
->drivername
, version
, &driver
);
5530 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5531 win_errstr(result
)));
5533 if (!W_ERROR_IS_OK(result
)) {
5535 * Is this a W2k client ?
5539 talloc_free(pinfo2
);
5540 return WERR_UNKNOWN_PRINTER_DRIVER
;
5543 /* Yes - try again with a WinNT driver. */
5545 result
= winreg_get_driver(mem_ctx
, session_info
, msg_ctx
,
5549 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5550 win_errstr(result
)));
5551 if (!W_ERROR_IS_OK(result
)) {
5552 talloc_free(pinfo2
);
5553 return WERR_UNKNOWN_PRINTER_DRIVER
;
5559 result
= fill_printer_driver_info1(mem_ctx
, &r
->info1
, driver
, servername
);
5562 result
= fill_printer_driver_info2(mem_ctx
, &r
->info2
, driver
, servername
);
5565 result
= fill_printer_driver_info3(mem_ctx
, &r
->info3
, driver
, servername
);
5568 result
= fill_printer_driver_info4(mem_ctx
, &r
->info4
, driver
, servername
);
5571 result
= fill_printer_driver_info5(mem_ctx
, &r
->info5
, driver
, servername
);
5574 result
= fill_printer_driver_info6(mem_ctx
, &r
->info6
, driver
, servername
);
5577 result
= fill_printer_driver_info8(mem_ctx
, &r
->info8
, driver
, servername
);
5579 #if 0 /* disabled until marshalling issues are resolved - gd */
5581 result
= fill_printer_driver_info101(mem_ctx
, &r
->info101
, driver
, servername
);
5585 result
= WERR_UNKNOWN_LEVEL
;
5589 talloc_free(pinfo2
);
5590 talloc_free(driver
);
5595 /****************************************************************
5596 _spoolss_GetPrinterDriver2
5597 ****************************************************************/
5599 WERROR
_spoolss_GetPrinterDriver2(struct pipes_struct
*p
,
5600 struct spoolss_GetPrinterDriver2
*r
)
5602 struct printer_handle
*printer
;
5607 /* that's an [in out] buffer */
5609 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
5610 return WERR_INVALID_PARAM
;
5613 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5615 if (!(printer
= find_printer_index_by_hnd(p
, r
->in
.handle
))) {
5616 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5617 return WERR_INVALID_PRINTER_NAME
;
5621 *r
->out
.server_major_version
= 0;
5622 *r
->out
.server_minor_version
= 0;
5624 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5628 result
= construct_printer_driver_info_level(p
->mem_ctx
,
5629 get_session_info_system(),
5631 r
->in
.level
, r
->out
.info
,
5632 snum
, printer
->servername
,
5634 r
->in
.client_major_version
);
5635 if (!W_ERROR_IS_OK(result
)) {
5636 TALLOC_FREE(r
->out
.info
);
5640 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_DriverInfo
,
5641 r
->out
.info
, r
->in
.level
);
5642 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
5644 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
5648 /****************************************************************
5649 _spoolss_StartPagePrinter
5650 ****************************************************************/
5652 WERROR
_spoolss_StartPagePrinter(struct pipes_struct
*p
,
5653 struct spoolss_StartPagePrinter
*r
)
5655 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5658 DEBUG(3,("_spoolss_StartPagePrinter: "
5659 "Error in startpageprinter printer handle\n"));
5663 Printer
->page_started
= true;
5667 /****************************************************************
5668 _spoolss_EndPagePrinter
5669 ****************************************************************/
5671 WERROR
_spoolss_EndPagePrinter(struct pipes_struct
*p
,
5672 struct spoolss_EndPagePrinter
*r
)
5676 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5679 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5680 OUR_HANDLE(r
->in
.handle
)));
5684 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5687 Printer
->page_started
= false;
5688 print_job_endpage(p
->msg_ctx
, snum
, Printer
->jobid
);
5693 /****************************************************************
5694 _spoolss_StartDocPrinter
5695 ****************************************************************/
5697 WERROR
_spoolss_StartDocPrinter(struct pipes_struct
*p
,
5698 struct spoolss_StartDocPrinter
*r
)
5700 struct spoolss_DocumentInfo1
*info_1
;
5702 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5706 DEBUG(2,("_spoolss_StartDocPrinter: "
5707 "Invalid handle (%s:%u:%u)\n",
5708 OUR_HANDLE(r
->in
.handle
)));
5712 if (Printer
->jobid
) {
5713 DEBUG(2, ("_spoolss_StartDocPrinter: "
5714 "StartDocPrinter called twice! "
5715 "(existing jobid = %d)\n", Printer
->jobid
));
5716 return WERR_INVALID_HANDLE
;
5719 if (r
->in
.level
!= 1) {
5720 return WERR_UNKNOWN_LEVEL
;
5723 info_1
= r
->in
.info
.info1
;
5726 * a nice thing with NT is it doesn't listen to what you tell it.
5727 * when asked to send _only_ RAW datas, it tries to send datas
5730 * So I add checks like in NT Server ...
5733 if (info_1
->datatype
) {
5734 if (strcmp(info_1
->datatype
, "RAW") != 0) {
5736 return WERR_INVALID_DATATYPE
;
5740 /* get the share number of the printer */
5741 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5745 werr
= print_job_start(p
->session_info
,
5749 info_1
->document_name
,
5750 info_1
->output_file
,
5754 /* An error occured in print_job_start() so return an appropriate
5757 if (!W_ERROR_IS_OK(werr
)) {
5761 Printer
->document_started
= true;
5762 *r
->out
.job_id
= Printer
->jobid
;
5767 /****************************************************************
5768 _spoolss_EndDocPrinter
5769 ****************************************************************/
5771 WERROR
_spoolss_EndDocPrinter(struct pipes_struct
*p
,
5772 struct spoolss_EndDocPrinter
*r
)
5774 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5779 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5780 OUR_HANDLE(r
->in
.handle
)));
5784 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5788 Printer
->document_started
= false;
5789 status
= print_job_end(p
->msg_ctx
, snum
, Printer
->jobid
, NORMAL_CLOSE
);
5790 if (!NT_STATUS_IS_OK(status
)) {
5791 DEBUG(2, ("_spoolss_EndDocPrinter: "
5792 "print_job_end failed [%s]\n",
5793 nt_errstr(status
)));
5797 return ntstatus_to_werror(status
);
5800 /****************************************************************
5801 _spoolss_WritePrinter
5802 ****************************************************************/
5804 WERROR
_spoolss_WritePrinter(struct pipes_struct
*p
,
5805 struct spoolss_WritePrinter
*r
)
5807 ssize_t buffer_written
;
5809 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5812 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5813 OUR_HANDLE(r
->in
.handle
)));
5814 *r
->out
.num_written
= r
->in
._data_size
;
5818 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5821 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5822 buffer_written
= print_job_write(server_event_context(),p
->msg_ctx
,
5823 snum
, Printer
->jobid
,
5824 (const char *)r
->in
.data
.data
,
5825 (size_t)r
->in
._data_size
);
5826 if (buffer_written
== (ssize_t
)-1) {
5827 *r
->out
.num_written
= 0;
5828 if (errno
== ENOSPC
)
5829 return WERR_NO_SPOOL_SPACE
;
5831 return WERR_ACCESS_DENIED
;
5834 *r
->out
.num_written
= r
->in
._data_size
;
5839 /********************************************************************
5840 * api_spoolss_getprinter
5841 * called from the spoolss dispatcher
5843 ********************************************************************/
5845 static WERROR
control_printer(struct policy_handle
*handle
, uint32_t command
,
5846 struct pipes_struct
*p
)
5848 const struct auth_serversupplied_info
*session_info
= p
->session_info
;
5850 WERROR errcode
= WERR_BADFUNC
;
5851 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
5854 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5855 OUR_HANDLE(handle
)));
5859 if (!get_printer_snum(p
, handle
, &snum
, NULL
))
5863 case SPOOLSS_PRINTER_CONTROL_PAUSE
:
5864 errcode
= print_queue_pause(session_info
, p
->msg_ctx
, snum
);
5866 case SPOOLSS_PRINTER_CONTROL_RESUME
:
5867 case SPOOLSS_PRINTER_CONTROL_UNPAUSE
:
5868 errcode
= print_queue_resume(session_info
, p
->msg_ctx
, snum
);
5870 case SPOOLSS_PRINTER_CONTROL_PURGE
:
5871 errcode
= print_queue_purge(session_info
, p
->msg_ctx
, snum
);
5874 return WERR_UNKNOWN_LEVEL
;
5881 /****************************************************************
5882 _spoolss_AbortPrinter
5883 * From MSDN: "Deletes printer's spool file if printer is configured
5885 ****************************************************************/
5887 WERROR
_spoolss_AbortPrinter(struct pipes_struct
*p
,
5888 struct spoolss_AbortPrinter
*r
)
5890 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5892 WERROR errcode
= WERR_OK
;
5895 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5896 OUR_HANDLE(r
->in
.handle
)));
5900 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5903 if (!Printer
->document_started
) {
5904 return WERR_SPL_NO_STARTDOC
;
5907 errcode
= print_job_delete(p
->session_info
,
5915 /********************************************************************
5916 * called by spoolss_api_setprinter
5917 * when updating a printer description
5918 ********************************************************************/
5920 static WERROR
update_printer_sec(struct policy_handle
*handle
,
5921 struct pipes_struct
*p
,
5922 struct sec_desc_buf
*secdesc_ctr
)
5924 struct spoolss_security_descriptor
*new_secdesc
= NULL
;
5925 struct spoolss_security_descriptor
*old_secdesc
= NULL
;
5926 const char *printer
;
5930 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
5932 if (!Printer
|| !get_printer_snum(p
, handle
, &snum
, NULL
)) {
5933 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5934 OUR_HANDLE(handle
)));
5936 result
= WERR_BADFID
;
5940 if (secdesc_ctr
== NULL
) {
5941 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5942 result
= WERR_INVALID_PARAM
;
5945 printer
= lp_const_servicename(snum
);
5947 /* Check the user has permissions to change the security
5948 descriptor. By experimentation with two NT machines, the user
5949 requires Full Access to the printer to change security
5952 if ( Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
5953 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5954 result
= WERR_ACCESS_DENIED
;
5958 /* NT seems to like setting the security descriptor even though
5959 nothing may have actually changed. */
5960 result
= winreg_get_printer_secdesc(p
->mem_ctx
,
5961 get_session_info_system(),
5965 if (!W_ERROR_IS_OK(result
)) {
5966 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5967 result
= WERR_BADFID
;
5971 if (DEBUGLEVEL
>= 10) {
5972 struct security_acl
*the_acl
;
5975 the_acl
= old_secdesc
->dacl
;
5976 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5977 printer
, the_acl
->num_aces
));
5979 for (i
= 0; i
< the_acl
->num_aces
; i
++) {
5980 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5981 &the_acl
->aces
[i
].trustee
),
5982 the_acl
->aces
[i
].access_mask
));
5985 the_acl
= secdesc_ctr
->sd
->dacl
;
5988 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5989 printer
, the_acl
->num_aces
));
5991 for (i
= 0; i
< the_acl
->num_aces
; i
++) {
5992 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5993 &the_acl
->aces
[i
].trustee
),
5994 the_acl
->aces
[i
].access_mask
));
5997 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
6001 new_secdesc
= sec_desc_merge(p
->mem_ctx
, secdesc_ctr
->sd
, old_secdesc
);
6002 if (new_secdesc
== NULL
) {
6003 result
= WERR_NOMEM
;
6007 if (security_descriptor_equal(new_secdesc
, old_secdesc
)) {
6012 result
= winreg_set_printer_secdesc(p
->mem_ctx
,
6013 get_session_info_system(),
6022 /********************************************************************
6023 Canonicalize printer info from a client
6024 ********************************************************************/
6026 static bool check_printer_ok(TALLOC_CTX
*mem_ctx
,
6027 struct spoolss_SetPrinterInfo2
*info2
,
6030 fstring printername
;
6033 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
6034 "portname=%s drivername=%s comment=%s location=%s\n",
6035 info2
->servername
, info2
->printername
, info2
->sharename
,
6036 info2
->portname
, info2
->drivername
, info2
->comment
,
6039 /* we force some elements to "correct" values */
6040 info2
->servername
= talloc_asprintf(mem_ctx
, "\\\\%s", global_myname());
6041 if (info2
->servername
== NULL
) {
6044 info2
->sharename
= talloc_strdup(mem_ctx
, lp_const_servicename(snum
));
6045 if (info2
->sharename
== NULL
) {
6049 /* check to see if we allow printername != sharename */
6050 if (lp_force_printername(snum
)) {
6051 info2
->printername
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
6052 global_myname(), info2
->sharename
);
6054 /* make sure printername is in \\server\printername format */
6055 fstrcpy(printername
, info2
->printername
);
6057 if ( printername
[0] == '\\' && printername
[1] == '\\' ) {
6058 if ( (p
= strchr_m( &printername
[2], '\\' )) != NULL
)
6062 info2
->printername
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
6063 global_myname(), p
);
6065 if (info2
->printername
== NULL
) {
6069 info2
->attributes
|= PRINTER_ATTRIBUTE_SAMBA
;
6070 info2
->attributes
&= ~PRINTER_ATTRIBUTE_NOT_SAMBA
;
6075 /****************************************************************************
6076 ****************************************************************************/
6078 static WERROR
add_port_hook(TALLOC_CTX
*ctx
, struct security_token
*token
, const char *portname
, const char *uri
)
6080 char *cmd
= lp_addport_cmd();
6081 char *command
= NULL
;
6083 bool is_print_op
= false;
6086 return WERR_ACCESS_DENIED
;
6089 command
= talloc_asprintf(ctx
,
6090 "%s \"%s\" \"%s\"", cmd
, portname
, uri
);
6096 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
6098 DEBUG(10,("Running [%s]\n", command
));
6100 /********* BEGIN SePrintOperatorPrivilege **********/
6105 ret
= smbrun(command
, NULL
);
6110 /********* END SePrintOperatorPrivilege **********/
6112 DEBUGADD(10,("returned [%d]\n", ret
));
6114 TALLOC_FREE(command
);
6117 return WERR_ACCESS_DENIED
;
6123 /****************************************************************************
6124 ****************************************************************************/
6126 static bool add_printer_hook(TALLOC_CTX
*ctx
, struct security_token
*token
,
6127 struct spoolss_SetPrinterInfo2
*info2
,
6128 const char *remote_machine
,
6129 struct messaging_context
*msg_ctx
)
6131 char *cmd
= lp_addprinter_cmd();
6133 char *command
= NULL
;
6137 bool is_print_op
= false;
6139 if (!remote_machine
) {
6143 command
= talloc_asprintf(ctx
,
6144 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6145 cmd
, info2
->printername
, info2
->sharename
,
6146 info2
->portname
, info2
->drivername
,
6147 info2
->location
, info2
->comment
, remote_machine
);
6153 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
6155 DEBUG(10,("Running [%s]\n", command
));
6157 /********* BEGIN SePrintOperatorPrivilege **********/
6162 if ( (ret
= smbrun(command
, &fd
)) == 0 ) {
6163 /* Tell everyone we updated smb.conf. */
6164 message_send_all(msg_ctx
, MSG_SMB_CONF_UPDATED
, NULL
, 0, NULL
);
6170 /********* END SePrintOperatorPrivilege **********/
6172 DEBUGADD(10,("returned [%d]\n", ret
));
6174 TALLOC_FREE(command
);
6182 /* reload our services immediately */
6184 reload_services(msg_ctx
, -1, false);
6188 /* Get lines and convert them back to dos-codepage */
6189 qlines
= fd_lines_load(fd
, &numlines
, 0, NULL
);
6190 DEBUGADD(10,("Lines returned = [%d]\n", numlines
));
6193 /* Set the portname to what the script says the portname should be. */
6194 /* but don't require anything to be return from the script exit a good error code */
6197 /* Set the portname to what the script says the portname should be. */
6198 info2
->portname
= talloc_strdup(ctx
, qlines
[0]);
6199 DEBUGADD(6,("Line[0] = [%s]\n", qlines
[0]));
6202 TALLOC_FREE(qlines
);
6206 static WERROR
update_dsspooler(TALLOC_CTX
*mem_ctx
,
6207 const struct auth_serversupplied_info
*session_info
,
6208 struct messaging_context
*msg_ctx
,
6210 struct spoolss_SetPrinterInfo2
*printer
,
6211 struct spoolss_PrinterInfo2
*old_printer
)
6213 bool force_update
= (old_printer
== NULL
);
6214 const char *dnsdomname
;
6215 const char *longname
;
6216 const char *uncname
;
6217 const char *spooling
;
6219 WERROR result
= WERR_OK
;
6221 if (force_update
|| !strequal(printer
->drivername
, old_printer
->drivername
)) {
6222 push_reg_sz(mem_ctx
, &buffer
, printer
->drivername
);
6223 winreg_set_printer_dataex(mem_ctx
,
6227 SPOOL_DSSPOOLER_KEY
,
6228 SPOOL_REG_DRIVERNAME
,
6233 if (!force_update
) {
6234 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6235 printer
->drivername
));
6237 notify_printer_driver(server_event_context(), msg_ctx
,
6238 snum
, printer
->drivername
?
6239 printer
->drivername
: "");
6243 if (force_update
|| !strequal(printer
->comment
, old_printer
->comment
)) {
6244 push_reg_sz(mem_ctx
, &buffer
, printer
->comment
);
6245 winreg_set_printer_dataex(mem_ctx
,
6249 SPOOL_DSSPOOLER_KEY
,
6250 SPOOL_REG_DESCRIPTION
,
6255 if (!force_update
) {
6256 notify_printer_comment(server_event_context(), msg_ctx
,
6257 snum
, printer
->comment
?
6258 printer
->comment
: "");
6262 if (force_update
|| !strequal(printer
->sharename
, old_printer
->sharename
)) {
6263 push_reg_sz(mem_ctx
, &buffer
, printer
->sharename
);
6264 winreg_set_printer_dataex(mem_ctx
,
6268 SPOOL_DSSPOOLER_KEY
,
6269 SPOOL_REG_PRINTSHARENAME
,
6274 if (!force_update
) {
6275 notify_printer_sharename(server_event_context(),
6277 snum
, printer
->sharename
?
6278 printer
->sharename
: "");
6282 if (force_update
|| !strequal(printer
->printername
, old_printer
->printername
)) {
6285 p
= strrchr(printer
->printername
, '\\' );
6289 p
= printer
->printername
;
6292 push_reg_sz(mem_ctx
, &buffer
, p
);
6293 winreg_set_printer_dataex(mem_ctx
,
6297 SPOOL_DSSPOOLER_KEY
,
6298 SPOOL_REG_PRINTERNAME
,
6303 if (!force_update
) {
6304 notify_printer_printername(server_event_context(),
6305 msg_ctx
, snum
, p
? p
: "");
6309 if (force_update
|| !strequal(printer
->portname
, old_printer
->portname
)) {
6310 push_reg_sz(mem_ctx
, &buffer
, printer
->portname
);
6311 winreg_set_printer_dataex(mem_ctx
,
6315 SPOOL_DSSPOOLER_KEY
,
6321 if (!force_update
) {
6322 notify_printer_port(server_event_context(),
6323 msg_ctx
, snum
, printer
->portname
?
6324 printer
->portname
: "");
6328 if (force_update
|| !strequal(printer
->location
, old_printer
->location
)) {
6329 push_reg_sz(mem_ctx
, &buffer
, printer
->location
);
6330 winreg_set_printer_dataex(mem_ctx
,
6334 SPOOL_DSSPOOLER_KEY
,
6340 if (!force_update
) {
6341 notify_printer_location(server_event_context(),
6344 printer
->location
: "");
6348 if (force_update
|| !strequal(printer
->sepfile
, old_printer
->sepfile
)) {
6349 push_reg_sz(mem_ctx
, &buffer
, printer
->sepfile
);
6350 winreg_set_printer_dataex(mem_ctx
,
6354 SPOOL_DSSPOOLER_KEY
,
6355 SPOOL_REG_PRINTSEPARATORFILE
,
6360 if (!force_update
) {
6361 notify_printer_sepfile(server_event_context(),
6364 printer
->sepfile
: "");
6368 if (force_update
|| printer
->starttime
!= old_printer
->starttime
) {
6369 buffer
= data_blob_talloc(mem_ctx
, NULL
, 4);
6370 SIVAL(buffer
.data
, 0, printer
->starttime
);
6371 winreg_set_printer_dataex(mem_ctx
,
6375 SPOOL_DSSPOOLER_KEY
,
6376 SPOOL_REG_PRINTSTARTTIME
,
6382 if (force_update
|| printer
->untiltime
!= old_printer
->untiltime
) {
6383 buffer
= data_blob_talloc(mem_ctx
, NULL
, 4);
6384 SIVAL(buffer
.data
, 0, printer
->untiltime
);
6385 winreg_set_printer_dataex(mem_ctx
,
6389 SPOOL_DSSPOOLER_KEY
,
6390 SPOOL_REG_PRINTENDTIME
,
6396 if (force_update
|| printer
->priority
!= old_printer
->priority
) {
6397 buffer
= data_blob_talloc(mem_ctx
, NULL
, 4);
6398 SIVAL(buffer
.data
, 0, printer
->priority
);
6399 winreg_set_printer_dataex(mem_ctx
,
6403 SPOOL_DSSPOOLER_KEY
,
6410 if (force_update
|| printer
->attributes
!= old_printer
->attributes
) {
6411 buffer
= data_blob_talloc(mem_ctx
, NULL
, 4);
6412 SIVAL(buffer
.data
, 0, (printer
->attributes
&
6413 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS
));
6414 winreg_set_printer_dataex(mem_ctx
,
6418 SPOOL_DSSPOOLER_KEY
,
6419 SPOOL_REG_PRINTKEEPPRINTEDJOBS
,
6424 switch (printer
->attributes
& 0x3) {
6426 spooling
= SPOOL_REGVAL_PRINTWHILESPOOLING
;
6429 spooling
= SPOOL_REGVAL_PRINTAFTERSPOOLED
;
6432 spooling
= SPOOL_REGVAL_PRINTDIRECT
;
6435 spooling
= "unknown";
6437 push_reg_sz(mem_ctx
, &buffer
, spooling
);
6438 winreg_set_printer_dataex(mem_ctx
,
6442 SPOOL_DSSPOOLER_KEY
,
6443 SPOOL_REG_PRINTSPOOLING
,
6449 push_reg_sz(mem_ctx
, &buffer
, global_myname());
6450 winreg_set_printer_dataex(mem_ctx
,
6454 SPOOL_DSSPOOLER_KEY
,
6455 SPOOL_REG_SHORTSERVERNAME
,
6460 dnsdomname
= get_mydnsfullname();
6461 if (dnsdomname
!= NULL
&& dnsdomname
[0] != '\0') {
6462 longname
= talloc_strdup(mem_ctx
, dnsdomname
);
6464 longname
= talloc_strdup(mem_ctx
, global_myname());
6466 if (longname
== NULL
) {
6467 result
= WERR_NOMEM
;
6471 push_reg_sz(mem_ctx
, &buffer
, longname
);
6472 winreg_set_printer_dataex(mem_ctx
,
6476 SPOOL_DSSPOOLER_KEY
,
6477 SPOOL_REG_SERVERNAME
,
6482 uncname
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
6483 global_myname(), printer
->sharename
);
6484 push_reg_sz(mem_ctx
, &buffer
, uncname
);
6485 winreg_set_printer_dataex(mem_ctx
,
6489 SPOOL_DSSPOOLER_KEY
,
6499 /********************************************************************
6500 * Called by spoolss_api_setprinter
6501 * when updating a printer description.
6502 ********************************************************************/
6504 static WERROR
update_printer(struct pipes_struct
*p
,
6505 struct policy_handle
*handle
,
6506 struct spoolss_SetPrinterInfoCtr
*info_ctr
,
6507 struct spoolss_DeviceMode
*devmode
)
6509 uint32_t printer_mask
= SPOOLSS_PRINTER_INFO_ALL
;
6510 struct spoolss_SetPrinterInfo2
*printer
= info_ctr
->info
.info2
;
6511 struct spoolss_PrinterInfo2
*old_printer
;
6512 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6514 WERROR result
= WERR_OK
;
6515 TALLOC_CTX
*tmp_ctx
;
6517 DEBUG(8,("update_printer\n"));
6519 tmp_ctx
= talloc_new(p
->mem_ctx
);
6520 if (tmp_ctx
== NULL
) {
6525 result
= WERR_BADFID
;
6529 if (!get_printer_snum(p
, handle
, &snum
, NULL
)) {
6530 result
= WERR_BADFID
;
6534 result
= winreg_get_printer(tmp_ctx
,
6535 get_session_info_system(),
6537 lp_const_servicename(snum
),
6539 if (!W_ERROR_IS_OK(result
)) {
6540 result
= WERR_BADFID
;
6544 /* Do sanity check on the requested changes for Samba */
6545 if (!check_printer_ok(tmp_ctx
, printer
, snum
)) {
6546 result
= WERR_INVALID_PARAM
;
6550 /* FIXME!!! If the driver has changed we really should verify that
6551 it is installed before doing much else --jerry */
6553 /* Check calling user has permission to update printer description */
6554 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
6555 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6556 result
= WERR_ACCESS_DENIED
;
6560 /* Call addprinter hook */
6561 /* Check changes to see if this is really needed */
6563 if (*lp_addprinter_cmd() &&
6564 (!strequal(printer
->drivername
, old_printer
->drivername
) ||
6565 !strequal(printer
->comment
, old_printer
->comment
) ||
6566 !strequal(printer
->portname
, old_printer
->portname
) ||
6567 !strequal(printer
->location
, old_printer
->location
)) )
6569 /* add_printer_hook() will call reload_services() */
6570 if (!add_printer_hook(tmp_ctx
, p
->session_info
->security_token
,
6571 printer
, p
->client_id
->addr
,
6573 result
= WERR_ACCESS_DENIED
;
6578 update_dsspooler(tmp_ctx
,
6579 get_session_info_system(),
6585 printer_mask
&= ~SPOOLSS_PRINTER_INFO_SECDESC
;
6587 if (devmode
== NULL
) {
6588 printer_mask
&= ~SPOOLSS_PRINTER_INFO_DEVMODE
;
6590 result
= winreg_update_printer(tmp_ctx
,
6591 get_session_info_system(),
6600 talloc_free(tmp_ctx
);
6605 /****************************************************************************
6606 ****************************************************************************/
6607 static WERROR
publish_or_unpublish_printer(struct pipes_struct
*p
,
6608 struct policy_handle
*handle
,
6609 struct spoolss_SetPrinterInfo7
*info7
)
6612 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
6615 struct printer_handle
*Printer
;
6617 if ( lp_security() != SEC_ADS
) {
6618 return WERR_UNKNOWN_LEVEL
;
6621 Printer
= find_printer_index_by_hnd(p
, handle
);
6623 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7
->action
));
6628 if (!get_printer_snum(p
, handle
, &snum
, NULL
))
6631 result
= winreg_get_printer(p
->mem_ctx
,
6632 get_session_info_system(),
6634 lp_servicename(snum
),
6636 if (!W_ERROR_IS_OK(result
)) {
6640 nt_printer_publish(pinfo2
,
6641 get_session_info_system(),
6646 TALLOC_FREE(pinfo2
);
6649 return WERR_UNKNOWN_LEVEL
;
6653 /********************************************************************
6654 ********************************************************************/
6656 static WERROR
update_printer_devmode(struct pipes_struct
*p
,
6657 struct policy_handle
*handle
,
6658 struct spoolss_DeviceMode
*devmode
)
6661 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6662 uint32_t info2_mask
= SPOOLSS_PRINTER_INFO_DEVMODE
;
6664 DEBUG(8,("update_printer_devmode\n"));
6670 if (!get_printer_snum(p
, handle
, &snum
, NULL
)) {
6674 /* Check calling user has permission to update printer description */
6675 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
6676 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6677 return WERR_ACCESS_DENIED
;
6680 return winreg_update_printer(p
->mem_ctx
,
6681 get_session_info_system(),
6683 lp_const_servicename(snum
),
6691 /****************************************************************
6693 ****************************************************************/
6695 WERROR
_spoolss_SetPrinter(struct pipes_struct
*p
,
6696 struct spoolss_SetPrinter
*r
)
6700 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
6703 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6704 OUR_HANDLE(r
->in
.handle
)));
6708 /* check the level */
6709 switch (r
->in
.info_ctr
->level
) {
6711 return control_printer(r
->in
.handle
, r
->in
.command
, p
);
6713 result
= update_printer(p
, r
->in
.handle
,
6715 r
->in
.devmode_ctr
->devmode
);
6716 if (!W_ERROR_IS_OK(result
))
6718 if (r
->in
.secdesc_ctr
->sd
)
6719 result
= update_printer_sec(r
->in
.handle
, p
,
6723 return update_printer_sec(r
->in
.handle
, p
,
6726 return publish_or_unpublish_printer(p
, r
->in
.handle
,
6727 r
->in
.info_ctr
->info
.info7
);
6729 return update_printer_devmode(p
, r
->in
.handle
,
6730 r
->in
.devmode_ctr
->devmode
);
6732 return WERR_UNKNOWN_LEVEL
;
6736 /****************************************************************
6737 _spoolss_FindClosePrinterNotify
6738 ****************************************************************/
6740 WERROR
_spoolss_FindClosePrinterNotify(struct pipes_struct
*p
,
6741 struct spoolss_FindClosePrinterNotify
*r
)
6743 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
6746 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6747 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r
->in
.handle
)));
6751 if (Printer
->notify
.cli_chan
!= NULL
&&
6752 Printer
->notify
.cli_chan
->active_connections
> 0) {
6755 if (Printer
->printer_type
== SPLHND_PRINTER
) {
6756 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
6761 srv_spoolss_replycloseprinter(snum
, Printer
);
6764 Printer
->notify
.flags
=0;
6765 Printer
->notify
.options
=0;
6766 Printer
->notify
.localmachine
[0]='\0';
6767 Printer
->notify
.printerlocal
=0;
6768 TALLOC_FREE(Printer
->notify
.option
);
6773 /****************************************************************
6775 ****************************************************************/
6777 WERROR
_spoolss_AddJob(struct pipes_struct
*p
,
6778 struct spoolss_AddJob
*r
)
6780 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
6781 return WERR_INVALID_PARAM
;
6784 /* this is what a NT server returns for AddJob. AddJob must fail on
6785 * non-local printers */
6787 if (r
->in
.level
!= 1) {
6788 return WERR_UNKNOWN_LEVEL
;
6791 return WERR_INVALID_PARAM
;
6794 /****************************************************************************
6796 ****************************************************************************/
6798 static WERROR
fill_job_info1(TALLOC_CTX
*mem_ctx
,
6799 struct spoolss_JobInfo1
*r
,
6800 const print_queue_struct
*queue
,
6801 int position
, int snum
,
6802 struct spoolss_PrinterInfo2
*pinfo2
)
6806 t
= gmtime(&queue
->time
);
6808 r
->job_id
= queue
->job
;
6810 r
->printer_name
= talloc_strdup(mem_ctx
, lp_servicename(snum
));
6811 W_ERROR_HAVE_NO_MEMORY(r
->printer_name
);
6812 r
->server_name
= talloc_strdup(mem_ctx
, pinfo2
->servername
);
6813 W_ERROR_HAVE_NO_MEMORY(r
->server_name
);
6814 r
->user_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
6815 W_ERROR_HAVE_NO_MEMORY(r
->user_name
);
6816 r
->document_name
= talloc_strdup(mem_ctx
, queue
->fs_file
);
6817 W_ERROR_HAVE_NO_MEMORY(r
->document_name
);
6818 r
->data_type
= talloc_strdup(mem_ctx
, "RAW");
6819 W_ERROR_HAVE_NO_MEMORY(r
->data_type
);
6820 r
->text_status
= talloc_strdup(mem_ctx
, "");
6821 W_ERROR_HAVE_NO_MEMORY(r
->text_status
);
6823 r
->status
= nt_printj_status(queue
->status
);
6824 r
->priority
= queue
->priority
;
6825 r
->position
= position
;
6826 r
->total_pages
= queue
->page_count
;
6827 r
->pages_printed
= 0; /* ??? */
6829 init_systemtime(&r
->submitted
, t
);
6834 /****************************************************************************
6836 ****************************************************************************/
6838 static WERROR
fill_job_info2(TALLOC_CTX
*mem_ctx
,
6839 struct spoolss_JobInfo2
*r
,
6840 const print_queue_struct
*queue
,
6841 int position
, int snum
,
6842 struct spoolss_PrinterInfo2
*pinfo2
,
6843 struct spoolss_DeviceMode
*devmode
)
6847 t
= gmtime(&queue
->time
);
6849 r
->job_id
= queue
->job
;
6851 r
->printer_name
= talloc_strdup(mem_ctx
, lp_servicename(snum
));
6852 W_ERROR_HAVE_NO_MEMORY(r
->printer_name
);
6853 r
->server_name
= talloc_strdup(mem_ctx
, pinfo2
->servername
);
6854 W_ERROR_HAVE_NO_MEMORY(r
->server_name
);
6855 r
->user_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
6856 W_ERROR_HAVE_NO_MEMORY(r
->user_name
);
6857 r
->document_name
= talloc_strdup(mem_ctx
, queue
->fs_file
);
6858 W_ERROR_HAVE_NO_MEMORY(r
->document_name
);
6859 r
->notify_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
6860 W_ERROR_HAVE_NO_MEMORY(r
->notify_name
);
6861 r
->data_type
= talloc_strdup(mem_ctx
, "RAW");
6862 W_ERROR_HAVE_NO_MEMORY(r
->data_type
);
6863 r
->print_processor
= talloc_strdup(mem_ctx
, "winprint");
6864 W_ERROR_HAVE_NO_MEMORY(r
->print_processor
);
6865 r
->parameters
= talloc_strdup(mem_ctx
, "");
6866 W_ERROR_HAVE_NO_MEMORY(r
->parameters
);
6867 r
->driver_name
= talloc_strdup(mem_ctx
, pinfo2
->drivername
);
6868 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
6870 r
->devmode
= devmode
;
6872 r
->text_status
= talloc_strdup(mem_ctx
, "");
6873 W_ERROR_HAVE_NO_MEMORY(r
->text_status
);
6877 r
->status
= nt_printj_status(queue
->status
);
6878 r
->priority
= queue
->priority
;
6879 r
->position
= position
;
6882 r
->total_pages
= queue
->page_count
;
6883 r
->size
= queue
->size
;
6884 init_systemtime(&r
->submitted
, t
);
6886 r
->pages_printed
= 0; /* ??? */
6891 /****************************************************************************
6893 ****************************************************************************/
6895 static WERROR
fill_job_info3(TALLOC_CTX
*mem_ctx
,
6896 struct spoolss_JobInfo3
*r
,
6897 const print_queue_struct
*queue
,
6898 const print_queue_struct
*next_queue
,
6899 int position
, int snum
,
6900 struct spoolss_PrinterInfo2
*pinfo2
)
6902 r
->job_id
= queue
->job
;
6905 r
->next_job_id
= next_queue
->job
;
6912 /****************************************************************************
6913 Enumjobs at level 1.
6914 ****************************************************************************/
6916 static WERROR
enumjobs_level1(TALLOC_CTX
*mem_ctx
,
6917 const print_queue_struct
*queue
,
6918 uint32_t num_queues
, int snum
,
6919 struct spoolss_PrinterInfo2
*pinfo2
,
6920 union spoolss_JobInfo
**info_p
,
6923 union spoolss_JobInfo
*info
;
6925 WERROR result
= WERR_OK
;
6927 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_JobInfo
, num_queues
);
6928 W_ERROR_HAVE_NO_MEMORY(info
);
6930 *count
= num_queues
;
6932 for (i
=0; i
<*count
; i
++) {
6933 result
= fill_job_info1(info
,
6939 if (!W_ERROR_IS_OK(result
)) {
6945 if (!W_ERROR_IS_OK(result
)) {
6956 /****************************************************************************
6957 Enumjobs at level 2.
6958 ****************************************************************************/
6960 static WERROR
enumjobs_level2(TALLOC_CTX
*mem_ctx
,
6961 const print_queue_struct
*queue
,
6962 uint32_t num_queues
, int snum
,
6963 struct spoolss_PrinterInfo2
*pinfo2
,
6964 union spoolss_JobInfo
**info_p
,
6967 union spoolss_JobInfo
*info
;
6969 WERROR result
= WERR_OK
;
6971 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_JobInfo
, num_queues
);
6972 W_ERROR_HAVE_NO_MEMORY(info
);
6974 *count
= num_queues
;
6976 for (i
=0; i
<*count
; i
++) {
6977 struct spoolss_DeviceMode
*devmode
;
6979 result
= spoolss_create_default_devmode(info
,
6980 pinfo2
->printername
,
6982 if (!W_ERROR_IS_OK(result
)) {
6983 DEBUG(3, ("Can't proceed w/o a devmode!"));
6987 result
= fill_job_info2(info
,
6994 if (!W_ERROR_IS_OK(result
)) {
7000 if (!W_ERROR_IS_OK(result
)) {
7011 /****************************************************************************
7012 Enumjobs at level 3.
7013 ****************************************************************************/
7015 static WERROR
enumjobs_level3(TALLOC_CTX
*mem_ctx
,
7016 const print_queue_struct
*queue
,
7017 uint32_t num_queues
, int snum
,
7018 struct spoolss_PrinterInfo2
*pinfo2
,
7019 union spoolss_JobInfo
**info_p
,
7022 union spoolss_JobInfo
*info
;
7024 WERROR result
= WERR_OK
;
7026 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7027 W_ERROR_HAVE_NO_MEMORY(info
);
7029 *count
= num_queues
;
7031 for (i
=0; i
<*count
; i
++) {
7032 const print_queue_struct
*next_queue
= NULL
;
7035 next_queue
= &queue
[i
+1];
7038 result
= fill_job_info3(info
,
7045 if (!W_ERROR_IS_OK(result
)) {
7051 if (!W_ERROR_IS_OK(result
)) {
7062 /****************************************************************
7064 ****************************************************************/
7066 WERROR
_spoolss_EnumJobs(struct pipes_struct
*p
,
7067 struct spoolss_EnumJobs
*r
)
7070 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
7072 print_status_struct prt_status
;
7073 print_queue_struct
*queue
= NULL
;
7076 /* that's an [in out] buffer */
7078 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7079 return WERR_INVALID_PARAM
;
7082 DEBUG(4,("_spoolss_EnumJobs\n"));
7086 *r
->out
.info
= NULL
;
7088 /* lookup the printer snum and tdb entry */
7090 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7094 result
= winreg_get_printer(p
->mem_ctx
,
7095 get_session_info_system(),
7097 lp_const_servicename(snum
),
7099 if (!W_ERROR_IS_OK(result
)) {
7103 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
, &prt_status
);
7104 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7105 count
, prt_status
.status
, prt_status
.message
));
7109 TALLOC_FREE(pinfo2
);
7113 switch (r
->in
.level
) {
7115 result
= enumjobs_level1(p
->mem_ctx
, queue
, count
, snum
,
7116 pinfo2
, r
->out
.info
, r
->out
.count
);
7119 result
= enumjobs_level2(p
->mem_ctx
, queue
, count
, snum
,
7120 pinfo2
, r
->out
.info
, r
->out
.count
);
7123 result
= enumjobs_level3(p
->mem_ctx
, queue
, count
, snum
,
7124 pinfo2
, r
->out
.info
, r
->out
.count
);
7127 result
= WERR_UNKNOWN_LEVEL
;
7132 TALLOC_FREE(pinfo2
);
7134 if (!W_ERROR_IS_OK(result
)) {
7138 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7140 *r
->out
.info
, r
->in
.level
,
7142 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7143 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7145 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7148 /****************************************************************
7149 _spoolss_ScheduleJob
7150 ****************************************************************/
7152 WERROR
_spoolss_ScheduleJob(struct pipes_struct
*p
,
7153 struct spoolss_ScheduleJob
*r
)
7158 /****************************************************************
7159 ****************************************************************/
7161 static WERROR
spoolss_setjob_1(TALLOC_CTX
*mem_ctx
,
7162 struct messaging_context
*msg_ctx
,
7163 const char *printer_name
,
7165 struct spoolss_SetJobInfo1
*r
)
7169 if (!print_job_get_name(mem_ctx
, printer_name
, job_id
, &old_doc_name
)) {
7173 if (strequal(old_doc_name
, r
->document_name
)) {
7177 if (!print_job_set_name(server_event_context(), msg_ctx
,
7178 printer_name
, job_id
, r
->document_name
)) {
7185 /****************************************************************
7187 ****************************************************************/
7189 WERROR
_spoolss_SetJob(struct pipes_struct
*p
,
7190 struct spoolss_SetJob
*r
)
7192 const struct auth_serversupplied_info
*session_info
= p
->session_info
;
7194 WERROR errcode
= WERR_BADFUNC
;
7196 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7200 if (!print_job_exists(lp_const_servicename(snum
), r
->in
.job_id
)) {
7201 return WERR_INVALID_PRINTER_NAME
;
7204 switch (r
->in
.command
) {
7205 case SPOOLSS_JOB_CONTROL_CANCEL
:
7206 case SPOOLSS_JOB_CONTROL_DELETE
:
7207 errcode
= print_job_delete(session_info
, p
->msg_ctx
,
7208 snum
, r
->in
.job_id
);
7209 if (W_ERROR_EQUAL(errcode
, WERR_PRINTER_HAS_JOBS_QUEUED
)) {
7213 case SPOOLSS_JOB_CONTROL_PAUSE
:
7214 if (print_job_pause(session_info
, p
->msg_ctx
,
7215 snum
, r
->in
.job_id
, &errcode
)) {
7219 case SPOOLSS_JOB_CONTROL_RESTART
:
7220 case SPOOLSS_JOB_CONTROL_RESUME
:
7221 if (print_job_resume(session_info
, p
->msg_ctx
,
7222 snum
, r
->in
.job_id
, &errcode
)) {
7230 return WERR_UNKNOWN_LEVEL
;
7233 if (!W_ERROR_IS_OK(errcode
)) {
7237 if (r
->in
.ctr
== NULL
) {
7241 switch (r
->in
.ctr
->level
) {
7243 errcode
= spoolss_setjob_1(p
->mem_ctx
, p
->msg_ctx
,
7244 lp_const_servicename(snum
),
7246 r
->in
.ctr
->info
.info1
);
7252 return WERR_UNKNOWN_LEVEL
;
7258 /****************************************************************************
7259 Enumerates all printer drivers by level and architecture.
7260 ****************************************************************************/
7262 static WERROR
enumprinterdrivers_level_by_architecture(TALLOC_CTX
*mem_ctx
,
7263 const struct auth_serversupplied_info
*session_info
,
7264 struct messaging_context
*msg_ctx
,
7265 const char *servername
,
7266 const char *architecture
,
7268 union spoolss_DriverInfo
**info_p
,
7273 struct spoolss_DriverInfo8
*driver
;
7274 union spoolss_DriverInfo
*info
= NULL
;
7276 WERROR result
= WERR_OK
;
7277 uint32_t num_drivers
;
7278 const char **drivers
;
7283 for (version
=0; version
<DRIVER_MAX_VERSION
; version
++) {
7284 result
= winreg_get_driver_list(mem_ctx
, session_info
, msg_ctx
,
7285 architecture
, version
,
7286 &num_drivers
, &drivers
);
7287 if (!W_ERROR_IS_OK(result
)) {
7290 DEBUG(4, ("we have:[%d] drivers in environment"
7291 " [%s] and version [%d]\n",
7292 num_drivers
, architecture
, version
));
7294 if (num_drivers
!= 0) {
7295 info
= TALLOC_REALLOC_ARRAY(mem_ctx
, info
,
7296 union spoolss_DriverInfo
,
7297 count
+ num_drivers
);
7299 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7300 "failed to enlarge driver info buffer!\n"));
7301 result
= WERR_NOMEM
;
7306 for (i
= 0; i
< num_drivers
; i
++) {
7307 DEBUG(5, ("\tdriver: [%s]\n", drivers
[i
]));
7309 result
= winreg_get_driver(mem_ctx
, session_info
,
7311 architecture
, drivers
[i
],
7313 if (!W_ERROR_IS_OK(result
)) {
7319 result
= fill_printer_driver_info1(info
, &info
[count
+i
].info1
,
7320 driver
, servername
);
7323 result
= fill_printer_driver_info2(info
, &info
[count
+i
].info2
,
7324 driver
, servername
);
7327 result
= fill_printer_driver_info3(info
, &info
[count
+i
].info3
,
7328 driver
, servername
);
7331 result
= fill_printer_driver_info4(info
, &info
[count
+i
].info4
,
7332 driver
, servername
);
7335 result
= fill_printer_driver_info5(info
, &info
[count
+i
].info5
,
7336 driver
, servername
);
7339 result
= fill_printer_driver_info6(info
, &info
[count
+i
].info6
,
7340 driver
, servername
);
7343 result
= fill_printer_driver_info8(info
, &info
[count
+i
].info8
,
7344 driver
, servername
);
7347 result
= WERR_UNKNOWN_LEVEL
;
7351 TALLOC_FREE(driver
);
7353 if (!W_ERROR_IS_OK(result
)) {
7358 count
+= num_drivers
;
7359 TALLOC_FREE(drivers
);
7363 TALLOC_FREE(drivers
);
7365 if (!W_ERROR_IS_OK(result
)) {
7376 /****************************************************************************
7377 Enumerates all printer drivers by level.
7378 ****************************************************************************/
7380 static WERROR
enumprinterdrivers_level(TALLOC_CTX
*mem_ctx
,
7381 const struct auth_serversupplied_info
*session_info
,
7382 struct messaging_context
*msg_ctx
,
7383 const char *servername
,
7384 const char *architecture
,
7386 union spoolss_DriverInfo
**info_p
,
7390 WERROR result
= WERR_OK
;
7392 if (strequal(architecture
, SPOOLSS_ARCHITECTURE_ALL
)) {
7394 for (a
=0; archi_table
[a
].long_archi
!= NULL
; a
++) {
7396 union spoolss_DriverInfo
*info
= NULL
;
7399 result
= enumprinterdrivers_level_by_architecture(mem_ctx
,
7403 archi_table
[a
].long_archi
,
7407 if (!W_ERROR_IS_OK(result
)) {
7411 for (i
=0; i
< count
; i
++) {
7412 ADD_TO_ARRAY(mem_ctx
, union spoolss_DriverInfo
,
7413 info
[i
], info_p
, count_p
);
7420 return enumprinterdrivers_level_by_architecture(mem_ctx
,
7430 /****************************************************************
7431 _spoolss_EnumPrinterDrivers
7432 ****************************************************************/
7434 WERROR
_spoolss_EnumPrinterDrivers(struct pipes_struct
*p
,
7435 struct spoolss_EnumPrinterDrivers
*r
)
7437 const char *cservername
;
7440 /* that's an [in out] buffer */
7442 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7443 return WERR_INVALID_PARAM
;
7446 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7450 *r
->out
.info
= NULL
;
7452 cservername
= canon_servername(r
->in
.server
);
7454 if (!is_myname_or_ipaddr(cservername
)) {
7455 return WERR_UNKNOWN_PRINTER_DRIVER
;
7458 result
= enumprinterdrivers_level(p
->mem_ctx
,
7459 get_session_info_system(),
7466 if (!W_ERROR_IS_OK(result
)) {
7470 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7471 spoolss_EnumPrinterDrivers
,
7472 *r
->out
.info
, r
->in
.level
,
7474 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7475 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7477 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7480 /****************************************************************
7482 ****************************************************************/
7484 WERROR
_spoolss_EnumForms(struct pipes_struct
*p
,
7485 struct spoolss_EnumForms
*r
)
7491 *r
->out
.info
= NULL
;
7493 /* that's an [in out] buffer */
7495 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0) ) {
7496 return WERR_INVALID_PARAM
;
7499 DEBUG(4,("_spoolss_EnumForms\n"));
7500 DEBUGADD(5,("Offered buffer size [%d]\n", r
->in
.offered
));
7501 DEBUGADD(5,("Info level [%d]\n", r
->in
.level
));
7503 switch (r
->in
.level
) {
7505 result
= winreg_printer_enumforms1(p
->mem_ctx
,
7506 get_session_info_system(),
7512 result
= WERR_UNKNOWN_LEVEL
;
7516 if (!W_ERROR_IS_OK(result
)) {
7520 if (*r
->out
.count
== 0) {
7521 return WERR_NO_MORE_ITEMS
;
7524 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7526 *r
->out
.info
, r
->in
.level
,
7528 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7529 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7531 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7534 /****************************************************************
7536 ****************************************************************/
7538 WERROR
_spoolss_GetForm(struct pipes_struct
*p
,
7539 struct spoolss_GetForm
*r
)
7543 /* that's an [in out] buffer */
7545 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7546 return WERR_INVALID_PARAM
;
7549 DEBUG(4,("_spoolss_GetForm\n"));
7550 DEBUGADD(5,("Offered buffer size [%d]\n", r
->in
.offered
));
7551 DEBUGADD(5,("Info level [%d]\n", r
->in
.level
));
7553 switch (r
->in
.level
) {
7555 result
= winreg_printer_getform1(p
->mem_ctx
,
7556 get_session_info_system(),
7559 &r
->out
.info
->info1
);
7562 result
= WERR_UNKNOWN_LEVEL
;
7566 if (!W_ERROR_IS_OK(result
)) {
7567 TALLOC_FREE(r
->out
.info
);
7571 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_FormInfo
,
7572 r
->out
.info
, r
->in
.level
);
7573 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
7575 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7578 /****************************************************************************
7579 ****************************************************************************/
7581 static WERROR
fill_port_1(TALLOC_CTX
*mem_ctx
,
7582 struct spoolss_PortInfo1
*r
,
7585 r
->port_name
= talloc_strdup(mem_ctx
, name
);
7586 W_ERROR_HAVE_NO_MEMORY(r
->port_name
);
7591 /****************************************************************************
7592 TODO: This probably needs distinguish between TCP/IP and Local ports
7594 ****************************************************************************/
7596 static WERROR
fill_port_2(TALLOC_CTX
*mem_ctx
,
7597 struct spoolss_PortInfo2
*r
,
7600 r
->port_name
= talloc_strdup(mem_ctx
, name
);
7601 W_ERROR_HAVE_NO_MEMORY(r
->port_name
);
7603 r
->monitor_name
= talloc_strdup(mem_ctx
, "Local Monitor");
7604 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
7606 r
->description
= talloc_strdup(mem_ctx
, SPL_LOCAL_PORT
);
7607 W_ERROR_HAVE_NO_MEMORY(r
->description
);
7609 r
->port_type
= SPOOLSS_PORT_TYPE_WRITE
;
7616 /****************************************************************************
7617 wrapper around the enumer ports command
7618 ****************************************************************************/
7620 static WERROR
enumports_hook(TALLOC_CTX
*ctx
, int *count
, char ***lines
)
7622 char *cmd
= lp_enumports_cmd();
7623 char **qlines
= NULL
;
7624 char *command
= NULL
;
7632 /* if no hook then just fill in the default port */
7635 if (!(qlines
= TALLOC_ARRAY( NULL
, char*, 2 ))) {
7638 if (!(qlines
[0] = talloc_strdup(qlines
, SAMBA_PRINTER_PORT_NAME
))) {
7639 TALLOC_FREE(qlines
);
7646 /* we have a valid enumport command */
7648 command
= talloc_asprintf(ctx
, "%s \"%d\"", cmd
, 1);
7653 DEBUG(10,("Running [%s]\n", command
));
7654 ret
= smbrun(command
, &fd
);
7655 DEBUG(10,("Returned [%d]\n", ret
));
7656 TALLOC_FREE(command
);
7661 return WERR_ACCESS_DENIED
;
7665 qlines
= fd_lines_load(fd
, &numlines
, 0, NULL
);
7666 DEBUGADD(10,("Lines returned = [%d]\n", numlines
));
7676 /****************************************************************************
7678 ****************************************************************************/
7680 static WERROR
enumports_level_1(TALLOC_CTX
*mem_ctx
,
7681 union spoolss_PortInfo
**info_p
,
7684 union spoolss_PortInfo
*info
= NULL
;
7686 WERROR result
= WERR_OK
;
7687 char **qlines
= NULL
;
7690 result
= enumports_hook(talloc_tos(), &numlines
, &qlines
);
7691 if (!W_ERROR_IS_OK(result
)) {
7696 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_PortInfo
, numlines
);
7698 DEBUG(10,("Returning WERR_NOMEM\n"));
7699 result
= WERR_NOMEM
;
7703 for (i
=0; i
<numlines
; i
++) {
7704 DEBUG(6,("Filling port number [%d] with port [%s]\n", i
, qlines
[i
]));
7705 result
= fill_port_1(info
, &info
[i
].info1
, qlines
[i
]);
7706 if (!W_ERROR_IS_OK(result
)) {
7711 TALLOC_FREE(qlines
);
7714 if (!W_ERROR_IS_OK(result
)) {
7716 TALLOC_FREE(qlines
);
7728 /****************************************************************************
7730 ****************************************************************************/
7732 static WERROR
enumports_level_2(TALLOC_CTX
*mem_ctx
,
7733 union spoolss_PortInfo
**info_p
,
7736 union spoolss_PortInfo
*info
= NULL
;
7738 WERROR result
= WERR_OK
;
7739 char **qlines
= NULL
;
7742 result
= enumports_hook(talloc_tos(), &numlines
, &qlines
);
7743 if (!W_ERROR_IS_OK(result
)) {
7748 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_PortInfo
, numlines
);
7750 DEBUG(10,("Returning WERR_NOMEM\n"));
7751 result
= WERR_NOMEM
;
7755 for (i
=0; i
<numlines
; i
++) {
7756 DEBUG(6,("Filling port number [%d] with port [%s]\n", i
, qlines
[i
]));
7757 result
= fill_port_2(info
, &info
[i
].info2
, qlines
[i
]);
7758 if (!W_ERROR_IS_OK(result
)) {
7763 TALLOC_FREE(qlines
);
7766 if (!W_ERROR_IS_OK(result
)) {
7768 TALLOC_FREE(qlines
);
7780 /****************************************************************
7782 ****************************************************************/
7784 WERROR
_spoolss_EnumPorts(struct pipes_struct
*p
,
7785 struct spoolss_EnumPorts
*r
)
7789 /* that's an [in out] buffer */
7791 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7792 return WERR_INVALID_PARAM
;
7795 DEBUG(4,("_spoolss_EnumPorts\n"));
7799 *r
->out
.info
= NULL
;
7801 switch (r
->in
.level
) {
7803 result
= enumports_level_1(p
->mem_ctx
, r
->out
.info
,
7807 result
= enumports_level_2(p
->mem_ctx
, r
->out
.info
,
7811 return WERR_UNKNOWN_LEVEL
;
7814 if (!W_ERROR_IS_OK(result
)) {
7818 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7820 *r
->out
.info
, r
->in
.level
,
7822 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7823 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7825 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7828 /****************************************************************************
7829 ****************************************************************************/
7831 static WERROR
spoolss_addprinterex_level_2(struct pipes_struct
*p
,
7833 struct spoolss_SetPrinterInfoCtr
*info_ctr
,
7834 struct spoolss_DeviceMode
*devmode
,
7835 struct security_descriptor
*secdesc
,
7836 struct spoolss_UserLevelCtr
*user_ctr
,
7837 struct policy_handle
*handle
)
7839 struct spoolss_SetPrinterInfo2
*info2
= info_ctr
->info
.info2
;
7840 uint32_t info2_mask
= SPOOLSS_PRINTER_INFO_ALL
;
7842 WERROR err
= WERR_OK
;
7844 /* samba does not have a concept of local, non-shared printers yet, so
7845 * make sure we always setup sharename - gd */
7846 if ((info2
->sharename
== NULL
|| info2
->sharename
[0] == '\0') &&
7847 (info2
->printername
!= NULL
&& info2
->printername
[0] != '\0')) {
7848 DEBUG(5, ("spoolss_addprinterex_level_2: "
7849 "no sharename has been set, setting printername %s as sharename\n",
7850 info2
->printername
));
7851 info2
->sharename
= info2
->printername
;
7854 /* check to see if the printer already exists */
7855 if ((snum
= print_queue_snum(info2
->sharename
)) != -1) {
7856 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7858 return WERR_PRINTER_ALREADY_EXISTS
;
7861 if (!lp_force_printername(GLOBAL_SECTION_SNUM
)) {
7862 if ((snum
= print_queue_snum(info2
->printername
)) != -1) {
7863 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7864 info2
->printername
));
7865 return WERR_PRINTER_ALREADY_EXISTS
;
7869 /* validate printer info struct */
7870 if (!info2
->printername
|| strlen(info2
->printername
) == 0) {
7871 return WERR_INVALID_PRINTER_NAME
;
7873 if (!info2
->portname
|| strlen(info2
->portname
) == 0) {
7874 return WERR_UNKNOWN_PORT
;
7876 if (!info2
->drivername
|| strlen(info2
->drivername
) == 0) {
7877 return WERR_UNKNOWN_PRINTER_DRIVER
;
7879 if (!info2
->printprocessor
|| strlen(info2
->printprocessor
) == 0) {
7880 return WERR_UNKNOWN_PRINTPROCESSOR
;
7883 /* FIXME!!! smbd should check to see if the driver is installed before
7884 trying to add a printer like this --jerry */
7886 if (*lp_addprinter_cmd() ) {
7887 if ( !add_printer_hook(p
->mem_ctx
, p
->session_info
->security_token
,
7888 info2
, p
->client_id
->addr
,
7890 return WERR_ACCESS_DENIED
;
7893 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no "
7894 "smb.conf parameter \"addprinter command\" is defined. This "
7895 "parameter must exist for this call to succeed\n",
7896 info2
->sharename
));
7899 if ((snum
= print_queue_snum(info2
->sharename
)) == -1) {
7900 return WERR_ACCESS_DENIED
;
7903 /* you must be a printer admin to add a new printer */
7904 if (!print_access_check(p
->session_info
,
7907 PRINTER_ACCESS_ADMINISTER
)) {
7908 return WERR_ACCESS_DENIED
;
7912 * Do sanity check on the requested changes for Samba.
7915 if (!check_printer_ok(p
->mem_ctx
, info2
, snum
)) {
7916 return WERR_INVALID_PARAM
;
7919 if (devmode
== NULL
) {
7920 info2_mask
= ~SPOOLSS_PRINTER_INFO_DEVMODE
;
7923 update_dsspooler(p
->mem_ctx
,
7924 get_session_info_system(),
7930 err
= winreg_update_printer(p
->mem_ctx
,
7931 get_session_info_system(),
7938 if (!W_ERROR_IS_OK(err
)) {
7942 err
= open_printer_hnd(p
, handle
, info2
->printername
, PRINTER_ACCESS_ADMINISTER
);
7943 if (!W_ERROR_IS_OK(err
)) {
7944 /* Handle open failed - remove addition. */
7945 ZERO_STRUCTP(handle
);
7952 /****************************************************************
7953 _spoolss_AddPrinterEx
7954 ****************************************************************/
7956 WERROR
_spoolss_AddPrinterEx(struct pipes_struct
*p
,
7957 struct spoolss_AddPrinterEx
*r
)
7959 switch (r
->in
.info_ctr
->level
) {
7961 /* we don't handle yet */
7962 /* but I know what to do ... */
7963 return WERR_UNKNOWN_LEVEL
;
7965 return spoolss_addprinterex_level_2(p
, r
->in
.server
,
7967 r
->in
.devmode_ctr
->devmode
,
7968 r
->in
.secdesc_ctr
->sd
,
7969 r
->in
.userlevel_ctr
,
7972 return WERR_UNKNOWN_LEVEL
;
7976 /****************************************************************
7978 ****************************************************************/
7980 WERROR
_spoolss_AddPrinter(struct pipes_struct
*p
,
7981 struct spoolss_AddPrinter
*r
)
7983 struct spoolss_AddPrinterEx a
;
7984 struct spoolss_UserLevelCtr userlevel_ctr
;
7986 ZERO_STRUCT(userlevel_ctr
);
7988 userlevel_ctr
.level
= 1;
7990 a
.in
.server
= r
->in
.server
;
7991 a
.in
.info_ctr
= r
->in
.info_ctr
;
7992 a
.in
.devmode_ctr
= r
->in
.devmode_ctr
;
7993 a
.in
.secdesc_ctr
= r
->in
.secdesc_ctr
;
7994 a
.in
.userlevel_ctr
= &userlevel_ctr
;
7995 a
.out
.handle
= r
->out
.handle
;
7997 return _spoolss_AddPrinterEx(p
, &a
);
8000 /****************************************************************
8001 _spoolss_AddPrinterDriverEx
8002 ****************************************************************/
8004 WERROR
_spoolss_AddPrinterDriverEx(struct pipes_struct
*p
,
8005 struct spoolss_AddPrinterDriverEx
*r
)
8007 WERROR err
= WERR_OK
;
8008 const char *driver_name
= NULL
;
8013 case NDR_SPOOLSS_ADDPRINTERDRIVER
:
8014 fn
= "_spoolss_AddPrinterDriver";
8016 case NDR_SPOOLSS_ADDPRINTERDRIVEREX
:
8017 fn
= "_spoolss_AddPrinterDriverEx";
8020 return WERR_INVALID_PARAM
;
8024 * we only support the semantics of AddPrinterDriver()
8025 * i.e. only copy files that are newer than existing ones
8028 if (r
->in
.flags
== 0) {
8029 return WERR_INVALID_PARAM
;
8032 if (r
->in
.flags
!= APD_COPY_NEW_FILES
) {
8033 return WERR_ACCESS_DENIED
;
8037 if (r
->in
.info_ctr
->level
!= 3 && r
->in
.info_ctr
->level
!= 6) {
8038 /* Clever hack from Martin Zielinski <mz@seh.de>
8039 * to allow downgrade from level 8 (Vista).
8041 DEBUG(0,("%s: level %d not yet implemented\n", fn
,
8042 r
->in
.info_ctr
->level
));
8043 return WERR_UNKNOWN_LEVEL
;
8046 DEBUG(5,("Cleaning driver's information\n"));
8047 err
= clean_up_driver_struct(p
->mem_ctx
, p
->session_info
, r
->in
.info_ctr
);
8048 if (!W_ERROR_IS_OK(err
))
8051 DEBUG(5,("Moving driver to final destination\n"));
8052 err
= move_driver_to_download_area(p
->session_info
, r
->in
.info_ctr
);
8053 if (!W_ERROR_IS_OK(err
)) {
8057 err
= winreg_add_driver(p
->mem_ctx
,
8058 get_session_info_system(),
8063 if (!W_ERROR_IS_OK(err
)) {
8068 * I think this is where he DrvUpgradePrinter() hook would be
8069 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8070 * server. Right now, we just need to send ourselves a message
8071 * to update each printer bound to this driver. --jerry
8074 if (!srv_spoolss_drv_upgrade_printer(driver_name
, p
->msg_ctx
)) {
8075 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8083 /****************************************************************
8084 _spoolss_AddPrinterDriver
8085 ****************************************************************/
8087 WERROR
_spoolss_AddPrinterDriver(struct pipes_struct
*p
,
8088 struct spoolss_AddPrinterDriver
*r
)
8090 struct spoolss_AddPrinterDriverEx a
;
8092 switch (r
->in
.info_ctr
->level
) {
8099 return WERR_UNKNOWN_LEVEL
;
8102 a
.in
.servername
= r
->in
.servername
;
8103 a
.in
.info_ctr
= r
->in
.info_ctr
;
8104 a
.in
.flags
= APD_COPY_NEW_FILES
;
8106 return _spoolss_AddPrinterDriverEx(p
, &a
);
8109 /****************************************************************************
8110 ****************************************************************************/
8112 struct _spoolss_paths
{
8118 enum { SPOOLSS_DRIVER_PATH
, SPOOLSS_PRTPROCS_PATH
};
8120 static const struct _spoolss_paths spoolss_paths
[]= {
8121 { SPOOLSS_DRIVER_PATH
, "print$", "DRIVERS" },
8122 { SPOOLSS_PRTPROCS_PATH
, "prnproc$", "PRTPROCS" }
8125 static WERROR
compose_spoolss_server_path(TALLOC_CTX
*mem_ctx
,
8126 const char *servername
,
8127 const char *environment
,
8131 const char *pservername
= NULL
;
8132 const char *long_archi
= SPOOLSS_ARCHITECTURE_NT_X86
;
8133 const char *short_archi
;
8137 /* environment may be empty */
8138 if (environment
&& strlen(environment
)) {
8139 long_archi
= environment
;
8142 /* servername may be empty */
8143 if (servername
&& strlen(servername
)) {
8144 pservername
= canon_servername(servername
);
8146 if (!is_myname_or_ipaddr(pservername
)) {
8147 return WERR_INVALID_PARAM
;
8151 if (!(short_archi
= get_short_archi(long_archi
))) {
8152 return WERR_INVALID_ENVIRONMENT
;
8155 switch (component
) {
8156 case SPOOLSS_PRTPROCS_PATH
:
8157 case SPOOLSS_DRIVER_PATH
:
8159 *path
= talloc_asprintf(mem_ctx
,
8162 spoolss_paths
[component
].share
,
8165 *path
= talloc_asprintf(mem_ctx
, "%s\\%s\\%s",
8166 SPOOLSS_DEFAULT_SERVER_PATH
,
8167 spoolss_paths
[component
].dir
,
8172 return WERR_INVALID_PARAM
;
8182 /****************************************************************************
8183 ****************************************************************************/
8185 static WERROR
getprinterdriverdir_level_1(TALLOC_CTX
*mem_ctx
,
8186 const char *servername
,
8187 const char *environment
,
8188 struct spoolss_DriverDirectoryInfo1
*r
)
8193 werr
= compose_spoolss_server_path(mem_ctx
,
8196 SPOOLSS_DRIVER_PATH
,
8198 if (!W_ERROR_IS_OK(werr
)) {
8202 DEBUG(4,("printer driver directory: [%s]\n", path
));
8204 r
->directory_name
= path
;
8209 /****************************************************************
8210 _spoolss_GetPrinterDriverDirectory
8211 ****************************************************************/
8213 WERROR
_spoolss_GetPrinterDriverDirectory(struct pipes_struct
*p
,
8214 struct spoolss_GetPrinterDriverDirectory
*r
)
8218 /* that's an [in out] buffer */
8220 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8221 return WERR_INVALID_PARAM
;
8224 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8229 /* r->in.level is ignored */
8231 werror
= getprinterdriverdir_level_1(p
->mem_ctx
,
8234 &r
->out
.info
->info1
);
8235 if (!W_ERROR_IS_OK(werror
)) {
8236 TALLOC_FREE(r
->out
.info
);
8240 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo
,
8241 r
->out
.info
, r
->in
.level
);
8242 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
8244 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8247 /****************************************************************
8248 _spoolss_EnumPrinterData
8249 ****************************************************************/
8251 WERROR
_spoolss_EnumPrinterData(struct pipes_struct
*p
,
8252 struct spoolss_EnumPrinterData
*r
)
8255 struct spoolss_EnumPrinterDataEx r2
;
8257 struct spoolss_PrinterEnumValues
*info
, *val
= NULL
;
8260 r2
.in
.handle
= r
->in
.handle
;
8261 r2
.in
.key_name
= "PrinterDriverData";
8263 r2
.out
.count
= &count
;
8264 r2
.out
.info
= &info
;
8265 r2
.out
.needed
= &needed
;
8267 result
= _spoolss_EnumPrinterDataEx(p
, &r2
);
8268 if (W_ERROR_EQUAL(result
, WERR_MORE_DATA
)) {
8269 r2
.in
.offered
= needed
;
8270 result
= _spoolss_EnumPrinterDataEx(p
, &r2
);
8272 if (!W_ERROR_IS_OK(result
)) {
8277 * The NT machine wants to know the biggest size of value and data
8279 * cf: MSDN EnumPrinterData remark section
8282 if (!r
->in
.value_offered
&& !r
->in
.data_offered
) {
8283 uint32_t biggest_valuesize
= 0;
8284 uint32_t biggest_datasize
= 0;
8287 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8289 for (i
=0; i
<count
; i
++) {
8291 name_length
= strlen(info
[i
].value_name
);
8292 if (strlen(info
[i
].value_name
) > biggest_valuesize
) {
8293 biggest_valuesize
= name_length
;
8296 if (info
[i
].data_length
> biggest_datasize
) {
8297 biggest_datasize
= info
[i
].data_length
;
8300 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize
,
8304 /* the value is an UNICODE string but real_value_size is the length
8305 in bytes including the trailing 0 */
8307 *r
->out
.value_needed
= 2 * (1 + biggest_valuesize
);
8308 *r
->out
.data_needed
= biggest_datasize
;
8310 DEBUG(6,("final values: [%d], [%d]\n",
8311 *r
->out
.value_needed
, *r
->out
.data_needed
));
8316 if (r
->in
.enum_index
< count
) {
8317 val
= &info
[r
->in
.enum_index
];
8321 /* out_value should default to "" or else NT4 has
8322 problems unmarshalling the response */
8324 if (r
->in
.value_offered
) {
8325 *r
->out
.value_needed
= 1;
8326 r
->out
.value_name
= talloc_strdup(r
, "");
8327 if (!r
->out
.value_name
) {
8331 r
->out
.value_name
= NULL
;
8332 *r
->out
.value_needed
= 0;
8335 /* the data is counted in bytes */
8337 *r
->out
.data_needed
= r
->in
.data_offered
;
8339 result
= WERR_NO_MORE_ITEMS
;
8343 * - counted in bytes in the request
8344 * - counted in UNICODE chars in the max reply
8345 * - counted in bytes in the real size
8347 * take a pause *before* coding not *during* coding
8351 if (r
->in
.value_offered
) {
8352 r
->out
.value_name
= talloc_strdup(r
, val
->value_name
);
8353 if (!r
->out
.value_name
) {
8356 *r
->out
.value_needed
= val
->value_name_len
;
8358 r
->out
.value_name
= NULL
;
8359 *r
->out
.value_needed
= 0;
8364 *r
->out
.type
= val
->type
;
8366 /* data - counted in bytes */
8369 * See the section "Dynamically Typed Query Parameters"
8373 if (r
->out
.data
&& val
->data
&& val
->data
->data
&&
8374 val
->data_length
&& r
->in
.data_offered
) {
8375 memcpy(r
->out
.data
, val
->data
->data
,
8376 MIN(val
->data_length
,r
->in
.data_offered
));
8379 *r
->out
.data_needed
= val
->data_length
;
8387 /****************************************************************
8388 _spoolss_SetPrinterData
8389 ****************************************************************/
8391 WERROR
_spoolss_SetPrinterData(struct pipes_struct
*p
,
8392 struct spoolss_SetPrinterData
*r
)
8394 struct spoolss_SetPrinterDataEx r2
;
8396 r2
.in
.handle
= r
->in
.handle
;
8397 r2
.in
.key_name
= "PrinterDriverData";
8398 r2
.in
.value_name
= r
->in
.value_name
;
8399 r2
.in
.type
= r
->in
.type
;
8400 r2
.in
.data
= r
->in
.data
;
8401 r2
.in
.offered
= r
->in
.offered
;
8403 return _spoolss_SetPrinterDataEx(p
, &r2
);
8406 /****************************************************************
8407 _spoolss_ResetPrinter
8408 ****************************************************************/
8410 WERROR
_spoolss_ResetPrinter(struct pipes_struct
*p
,
8411 struct spoolss_ResetPrinter
*r
)
8413 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8416 DEBUG(5,("_spoolss_ResetPrinter\n"));
8419 * All we do is to check to see if the handle and queue is valid.
8420 * This call really doesn't mean anything to us because we only
8421 * support RAW printing. --jerry
8425 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8426 OUR_HANDLE(r
->in
.handle
)));
8430 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
8434 /* blindly return success */
8438 /****************************************************************
8439 _spoolss_DeletePrinterData
8440 ****************************************************************/
8442 WERROR
_spoolss_DeletePrinterData(struct pipes_struct
*p
,
8443 struct spoolss_DeletePrinterData
*r
)
8445 struct spoolss_DeletePrinterDataEx r2
;
8447 r2
.in
.handle
= r
->in
.handle
;
8448 r2
.in
.key_name
= "PrinterDriverData";
8449 r2
.in
.value_name
= r
->in
.value_name
;
8451 return _spoolss_DeletePrinterDataEx(p
, &r2
);
8454 /****************************************************************
8456 ****************************************************************/
8458 WERROR
_spoolss_AddForm(struct pipes_struct
*p
,
8459 struct spoolss_AddForm
*r
)
8461 struct spoolss_AddFormInfo1
*form
= r
->in
.info
.info1
;
8463 WERROR status
= WERR_OK
;
8465 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8467 DEBUG(5,("_spoolss_AddForm\n"));
8470 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8471 OUR_HANDLE(r
->in
.handle
)));
8475 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8476 and not a printer admin, then fail */
8478 if ((p
->session_info
->utok
.uid
!= sec_initial_uid()) &&
8479 !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
) &&
8480 !token_contains_name_in_list(uidtoname(p
->session_info
->utok
.uid
),
8481 p
->session_info
->info3
->base
.domain
.string
,
8483 p
->session_info
->security_token
,
8484 lp_printer_admin(snum
))) {
8485 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8486 return WERR_ACCESS_DENIED
;
8489 switch (form
->flags
) {
8490 case SPOOLSS_FORM_USER
:
8491 case SPOOLSS_FORM_BUILTIN
:
8492 case SPOOLSS_FORM_PRINTER
:
8495 return WERR_INVALID_PARAM
;
8498 status
= winreg_printer_addform1(p
->mem_ctx
,
8499 get_session_info_system(),
8502 if (!W_ERROR_IS_OK(status
)) {
8507 * ChangeID must always be set if this is a printer
8509 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8510 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8514 status
= winreg_printer_update_changeid(p
->mem_ctx
,
8515 get_session_info_system(),
8517 lp_const_servicename(snum
));
8518 if (!W_ERROR_IS_OK(status
)) {
8526 /****************************************************************
8528 ****************************************************************/
8530 WERROR
_spoolss_DeleteForm(struct pipes_struct
*p
,
8531 struct spoolss_DeleteForm
*r
)
8533 const char *form_name
= r
->in
.form_name
;
8534 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8536 WERROR status
= WERR_OK
;
8538 DEBUG(5,("_spoolss_DeleteForm\n"));
8541 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8542 OUR_HANDLE(r
->in
.handle
)));
8546 if ((p
->session_info
->utok
.uid
!= sec_initial_uid()) &&
8547 !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
) &&
8548 !token_contains_name_in_list(uidtoname(p
->session_info
->utok
.uid
),
8549 p
->session_info
->info3
->base
.domain
.string
,
8551 p
->session_info
->security_token
,
8552 lp_printer_admin(snum
))) {
8553 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8554 return WERR_ACCESS_DENIED
;
8557 status
= winreg_printer_deleteform1(p
->mem_ctx
,
8558 get_session_info_system(),
8561 if (!W_ERROR_IS_OK(status
)) {
8566 * ChangeID must always be set if this is a printer
8568 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8569 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8573 status
= winreg_printer_update_changeid(p
->mem_ctx
,
8574 get_session_info_system(),
8576 lp_const_servicename(snum
));
8577 if (!W_ERROR_IS_OK(status
)) {
8585 /****************************************************************
8587 ****************************************************************/
8589 WERROR
_spoolss_SetForm(struct pipes_struct
*p
,
8590 struct spoolss_SetForm
*r
)
8592 struct spoolss_AddFormInfo1
*form
= r
->in
.info
.info1
;
8593 const char *form_name
= r
->in
.form_name
;
8595 WERROR status
= WERR_OK
;
8597 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8599 DEBUG(5,("_spoolss_SetForm\n"));
8602 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8603 OUR_HANDLE(r
->in
.handle
)));
8607 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8608 and not a printer admin, then fail */
8610 if ((p
->session_info
->utok
.uid
!= sec_initial_uid()) &&
8611 !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
) &&
8612 !token_contains_name_in_list(uidtoname(p
->session_info
->utok
.uid
),
8613 p
->session_info
->info3
->base
.domain
.string
,
8615 p
->session_info
->security_token
,
8616 lp_printer_admin(snum
))) {
8617 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8618 return WERR_ACCESS_DENIED
;
8621 status
= winreg_printer_setform1(p
->mem_ctx
,
8622 get_session_info_system(),
8626 if (!W_ERROR_IS_OK(status
)) {
8631 * ChangeID must always be set if this is a printer
8633 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8634 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8638 status
= winreg_printer_update_changeid(p
->mem_ctx
,
8639 get_session_info_system(),
8641 lp_const_servicename(snum
));
8642 if (!W_ERROR_IS_OK(status
)) {
8650 /****************************************************************************
8651 fill_print_processor1
8652 ****************************************************************************/
8654 static WERROR
fill_print_processor1(TALLOC_CTX
*mem_ctx
,
8655 struct spoolss_PrintProcessorInfo1
*r
,
8656 const char *print_processor_name
)
8658 r
->print_processor_name
= talloc_strdup(mem_ctx
, print_processor_name
);
8659 W_ERROR_HAVE_NO_MEMORY(r
->print_processor_name
);
8664 /****************************************************************************
8665 enumprintprocessors level 1.
8666 ****************************************************************************/
8668 static WERROR
enumprintprocessors_level_1(TALLOC_CTX
*mem_ctx
,
8669 union spoolss_PrintProcessorInfo
**info_p
,
8672 union spoolss_PrintProcessorInfo
*info
;
8675 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_PrintProcessorInfo
, 1);
8676 W_ERROR_HAVE_NO_MEMORY(info
);
8680 result
= fill_print_processor1(info
, &info
[0].info1
, "winprint");
8681 if (!W_ERROR_IS_OK(result
)) {
8686 if (!W_ERROR_IS_OK(result
)) {
8697 /****************************************************************
8698 _spoolss_EnumPrintProcessors
8699 ****************************************************************/
8701 WERROR
_spoolss_EnumPrintProcessors(struct pipes_struct
*p
,
8702 struct spoolss_EnumPrintProcessors
*r
)
8706 /* that's an [in out] buffer */
8708 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8709 return WERR_INVALID_PARAM
;
8712 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8715 * Enumerate the print processors ...
8717 * Just reply with "winprint", to keep NT happy
8718 * and I can use my nice printer checker.
8723 *r
->out
.info
= NULL
;
8725 if (!get_short_archi(r
->in
.environment
)) {
8726 return WERR_INVALID_ENVIRONMENT
;
8729 switch (r
->in
.level
) {
8731 result
= enumprintprocessors_level_1(p
->mem_ctx
, r
->out
.info
,
8735 return WERR_UNKNOWN_LEVEL
;
8738 if (!W_ERROR_IS_OK(result
)) {
8742 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
8743 spoolss_EnumPrintProcessors
,
8744 *r
->out
.info
, r
->in
.level
,
8746 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
8747 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
8749 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8752 /****************************************************************************
8753 fill_printprocdatatype1
8754 ****************************************************************************/
8756 static WERROR
fill_printprocdatatype1(TALLOC_CTX
*mem_ctx
,
8757 struct spoolss_PrintProcDataTypesInfo1
*r
,
8758 const char *name_array
)
8760 r
->name_array
= talloc_strdup(mem_ctx
, name_array
);
8761 W_ERROR_HAVE_NO_MEMORY(r
->name_array
);
8766 /****************************************************************************
8767 enumprintprocdatatypes level 1.
8768 ****************************************************************************/
8770 static WERROR
enumprintprocdatatypes_level_1(TALLOC_CTX
*mem_ctx
,
8771 union spoolss_PrintProcDataTypesInfo
**info_p
,
8775 union spoolss_PrintProcDataTypesInfo
*info
;
8777 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_PrintProcDataTypesInfo
, 1);
8778 W_ERROR_HAVE_NO_MEMORY(info
);
8782 result
= fill_printprocdatatype1(info
, &info
[0].info1
, "RAW");
8783 if (!W_ERROR_IS_OK(result
)) {
8788 if (!W_ERROR_IS_OK(result
)) {
8799 /****************************************************************
8800 _spoolss_EnumPrintProcDataTypes
8801 ****************************************************************/
8803 WERROR
_spoolss_EnumPrintProcDataTypes(struct pipes_struct
*p
,
8804 struct spoolss_EnumPrintProcDataTypes
*r
)
8808 /* that's an [in out] buffer */
8810 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8811 return WERR_INVALID_PARAM
;
8814 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8818 *r
->out
.info
= NULL
;
8820 if (r
->in
.print_processor_name
== NULL
||
8821 !strequal(r
->in
.print_processor_name
, "winprint")) {
8822 return WERR_UNKNOWN_PRINTPROCESSOR
;
8825 switch (r
->in
.level
) {
8827 result
= enumprintprocdatatypes_level_1(p
->mem_ctx
, r
->out
.info
,
8831 return WERR_UNKNOWN_LEVEL
;
8834 if (!W_ERROR_IS_OK(result
)) {
8838 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
8839 spoolss_EnumPrintProcDataTypes
,
8840 *r
->out
.info
, r
->in
.level
,
8842 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
8843 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
8845 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8848 /****************************************************************************
8850 ****************************************************************************/
8852 static WERROR
fill_monitor_1(TALLOC_CTX
*mem_ctx
,
8853 struct spoolss_MonitorInfo1
*r
,
8854 const char *monitor_name
)
8856 r
->monitor_name
= talloc_strdup(mem_ctx
, monitor_name
);
8857 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
8862 /****************************************************************************
8864 ****************************************************************************/
8866 static WERROR
fill_monitor_2(TALLOC_CTX
*mem_ctx
,
8867 struct spoolss_MonitorInfo2
*r
,
8868 const char *monitor_name
,
8869 const char *environment
,
8870 const char *dll_name
)
8872 r
->monitor_name
= talloc_strdup(mem_ctx
, monitor_name
);
8873 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
8874 r
->environment
= talloc_strdup(mem_ctx
, environment
);
8875 W_ERROR_HAVE_NO_MEMORY(r
->environment
);
8876 r
->dll_name
= talloc_strdup(mem_ctx
, dll_name
);
8877 W_ERROR_HAVE_NO_MEMORY(r
->dll_name
);
8882 /****************************************************************************
8883 enumprintmonitors level 1.
8884 ****************************************************************************/
8886 static WERROR
enumprintmonitors_level_1(TALLOC_CTX
*mem_ctx
,
8887 union spoolss_MonitorInfo
**info_p
,
8890 union spoolss_MonitorInfo
*info
;
8891 WERROR result
= WERR_OK
;
8893 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_MonitorInfo
, 2);
8894 W_ERROR_HAVE_NO_MEMORY(info
);
8898 result
= fill_monitor_1(info
, &info
[0].info1
,
8900 if (!W_ERROR_IS_OK(result
)) {
8904 result
= fill_monitor_1(info
, &info
[1].info1
,
8906 if (!W_ERROR_IS_OK(result
)) {
8911 if (!W_ERROR_IS_OK(result
)) {
8922 /****************************************************************************
8923 enumprintmonitors level 2.
8924 ****************************************************************************/
8926 static WERROR
enumprintmonitors_level_2(TALLOC_CTX
*mem_ctx
,
8927 union spoolss_MonitorInfo
**info_p
,
8930 union spoolss_MonitorInfo
*info
;
8931 WERROR result
= WERR_OK
;
8933 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_MonitorInfo
, 2);
8934 W_ERROR_HAVE_NO_MEMORY(info
);
8938 result
= fill_monitor_2(info
, &info
[0].info2
,
8940 "Windows NT X86", /* FIXME */
8942 if (!W_ERROR_IS_OK(result
)) {
8946 result
= fill_monitor_2(info
, &info
[1].info2
,
8948 "Windows NT X86", /* FIXME */
8950 if (!W_ERROR_IS_OK(result
)) {
8955 if (!W_ERROR_IS_OK(result
)) {
8966 /****************************************************************
8967 _spoolss_EnumMonitors
8968 ****************************************************************/
8970 WERROR
_spoolss_EnumMonitors(struct pipes_struct
*p
,
8971 struct spoolss_EnumMonitors
*r
)
8975 /* that's an [in out] buffer */
8977 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8978 return WERR_INVALID_PARAM
;
8981 DEBUG(5,("_spoolss_EnumMonitors\n"));
8984 * Enumerate the print monitors ...
8986 * Just reply with "Local Port", to keep NT happy
8987 * and I can use my nice printer checker.
8992 *r
->out
.info
= NULL
;
8994 switch (r
->in
.level
) {
8996 result
= enumprintmonitors_level_1(p
->mem_ctx
, r
->out
.info
,
9000 result
= enumprintmonitors_level_2(p
->mem_ctx
, r
->out
.info
,
9004 return WERR_UNKNOWN_LEVEL
;
9007 if (!W_ERROR_IS_OK(result
)) {
9011 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
9012 spoolss_EnumMonitors
,
9013 *r
->out
.info
, r
->in
.level
,
9015 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9016 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
9018 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9021 /****************************************************************************
9022 ****************************************************************************/
9024 static WERROR
getjob_level_1(TALLOC_CTX
*mem_ctx
,
9025 const print_queue_struct
*queue
,
9026 int count
, int snum
,
9027 struct spoolss_PrinterInfo2
*pinfo2
,
9029 struct spoolss_JobInfo1
*r
)
9034 for (i
=0; i
<count
; i
++) {
9035 if (queue
[i
].job
== (int)jobid
) {
9041 if (found
== false) {
9042 /* NT treats not found as bad param... yet another bad choice */
9043 return WERR_INVALID_PARAM
;
9046 return fill_job_info1(mem_ctx
,
9054 /****************************************************************************
9055 ****************************************************************************/
9057 static WERROR
getjob_level_2(TALLOC_CTX
*mem_ctx
,
9058 const print_queue_struct
*queue
,
9059 int count
, int snum
,
9060 struct spoolss_PrinterInfo2
*pinfo2
,
9062 struct spoolss_JobInfo2
*r
)
9066 struct spoolss_DeviceMode
*devmode
;
9069 for (i
=0; i
<count
; i
++) {
9070 if (queue
[i
].job
== (int)jobid
) {
9076 if (found
== false) {
9077 /* NT treats not found as bad param... yet another bad
9079 return WERR_INVALID_PARAM
;
9083 * if the print job does not have a DEVMODE associated with it,
9084 * just use the one for the printer. A NULL devicemode is not
9085 * a failure condition
9088 devmode
= print_job_devmode(lp_const_servicename(snum
), jobid
);
9090 result
= spoolss_create_default_devmode(mem_ctx
,
9091 pinfo2
->printername
,
9093 if (!W_ERROR_IS_OK(result
)) {
9094 DEBUG(3, ("Can't proceed w/o a devmode!"));
9099 return fill_job_info2(mem_ctx
,
9108 /****************************************************************
9110 ****************************************************************/
9112 WERROR
_spoolss_GetJob(struct pipes_struct
*p
,
9113 struct spoolss_GetJob
*r
)
9115 WERROR result
= WERR_OK
;
9116 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
9119 print_queue_struct
*queue
= NULL
;
9120 print_status_struct prt_status
;
9122 /* that's an [in out] buffer */
9124 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9125 return WERR_INVALID_PARAM
;
9128 DEBUG(5,("_spoolss_GetJob\n"));
9132 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9136 result
= winreg_get_printer(p
->mem_ctx
,
9137 get_session_info_system(),
9139 lp_const_servicename(snum
),
9141 if (!W_ERROR_IS_OK(result
)) {
9145 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
, &prt_status
);
9147 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9148 count
, prt_status
.status
, prt_status
.message
));
9150 switch (r
->in
.level
) {
9152 result
= getjob_level_1(p
->mem_ctx
,
9153 queue
, count
, snum
, pinfo2
,
9154 r
->in
.job_id
, &r
->out
.info
->info1
);
9157 result
= getjob_level_2(p
->mem_ctx
,
9158 queue
, count
, snum
, pinfo2
,
9159 r
->in
.job_id
, &r
->out
.info
->info2
);
9162 result
= WERR_UNKNOWN_LEVEL
;
9167 TALLOC_FREE(pinfo2
);
9169 if (!W_ERROR_IS_OK(result
)) {
9170 TALLOC_FREE(r
->out
.info
);
9174 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_JobInfo
, r
->out
.info
,
9176 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
9178 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9181 /****************************************************************
9182 _spoolss_GetPrinterDataEx
9183 ****************************************************************/
9185 WERROR
_spoolss_GetPrinterDataEx(struct pipes_struct
*p
,
9186 struct spoolss_GetPrinterDataEx
*r
)
9189 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9190 const char *printer
;
9192 WERROR result
= WERR_OK
;
9194 enum winreg_Type val_type
;
9199 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9201 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9202 r
->in
.key_name
, r
->in
.value_name
));
9204 /* in case of problem, return some default values */
9207 *r
->out
.type
= REG_NONE
;
9210 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9211 OUR_HANDLE(r
->in
.handle
)));
9212 result
= WERR_BADFID
;
9216 /* Is the handle to a printer or to the server? */
9218 if (Printer
->printer_type
== SPLHND_SERVER
) {
9220 union spoolss_PrinterData data
;
9222 result
= getprinterdata_printer_server(p
->mem_ctx
,
9226 if (!W_ERROR_IS_OK(result
)) {
9230 result
= push_spoolss_PrinterData(p
->mem_ctx
, &blob
,
9231 *r
->out
.type
, &data
);
9232 if (!W_ERROR_IS_OK(result
)) {
9236 *r
->out
.needed
= blob
.length
;
9238 if (r
->in
.offered
>= *r
->out
.needed
) {
9239 memcpy(r
->out
.data
, blob
.data
, blob
.length
);
9242 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
9245 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9248 printer
= lp_const_servicename(snum
);
9250 /* check to see if the keyname is valid */
9251 if (!strlen(r
->in
.key_name
)) {
9252 return WERR_INVALID_PARAM
;
9255 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9256 if (strequal(r
->in
.key_name
, SPOOL_PRINTERDATA_KEY
) &&
9257 strequal(r
->in
.value_name
, "ChangeId")) {
9258 *r
->out
.type
= REG_DWORD
;
9260 if (r
->in
.offered
>= *r
->out
.needed
) {
9261 uint32_t changeid
= 0;
9263 result
= winreg_printer_get_changeid(p
->mem_ctx
,
9264 get_session_info_system(),
9268 if (!W_ERROR_IS_OK(result
)) {
9272 SIVAL(r
->out
.data
, 0, changeid
);
9278 result
= winreg_get_printer_dataex(p
->mem_ctx
,
9279 get_session_info_system(),
9287 if (!W_ERROR_IS_OK(result
)) {
9291 *r
->out
.needed
= val_size
;
9292 *r
->out
.type
= val_type
;
9294 if (r
->in
.offered
>= *r
->out
.needed
) {
9295 memcpy(r
->out
.data
, val_data
, val_size
);
9299 /* retain type when returning WERR_MORE_DATA */
9300 r
->out
.data
= SPOOLSS_BUFFER_OK(r
->out
.data
, r
->out
.data
);
9302 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
9305 /****************************************************************
9306 _spoolss_SetPrinterDataEx
9307 ****************************************************************/
9309 WERROR
_spoolss_SetPrinterDataEx(struct pipes_struct
*p
,
9310 struct spoolss_SetPrinterDataEx
*r
)
9312 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
9314 WERROR result
= WERR_OK
;
9315 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9318 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9320 /* From MSDN documentation of SetPrinterDataEx: pass request to
9321 SetPrinterData if key is "PrinterDriverData" */
9324 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9325 OUR_HANDLE(r
->in
.handle
)));
9329 if (Printer
->printer_type
== SPLHND_SERVER
) {
9330 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9331 "Not implemented for server handles yet\n"));
9332 return WERR_INVALID_PARAM
;
9335 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9340 * Access check : NT returns "access denied" if you make a
9341 * SetPrinterData call without the necessary privildge.
9342 * we were originally returning OK if nothing changed
9343 * which made Win2k issue **a lot** of SetPrinterData
9344 * when connecting to a printer --jerry
9347 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9348 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9349 "change denied by handle access permissions\n"));
9350 return WERR_ACCESS_DENIED
;
9353 result
= winreg_get_printer(Printer
,
9354 get_session_info_system(),
9356 lp_servicename(snum
),
9358 if (!W_ERROR_IS_OK(result
)) {
9362 /* check for OID in valuename */
9364 oid_string
= strchr(r
->in
.value_name
, ',');
9370 /* save the registry data */
9372 result
= winreg_set_printer_dataex(p
->mem_ctx
,
9373 get_session_info_system(),
9382 if (W_ERROR_IS_OK(result
)) {
9383 /* save the OID if one was specified */
9385 char *str
= talloc_asprintf(p
->mem_ctx
, "%s\\%s",
9386 r
->in
.key_name
, SPOOL_OID_KEY
);
9388 result
= WERR_NOMEM
;
9393 * I'm not checking the status here on purpose. Don't know
9394 * if this is right, but I'm returning the status from the
9395 * previous set_printer_dataex() call. I have no idea if
9396 * this is right. --jerry
9398 winreg_set_printer_dataex(p
->mem_ctx
,
9399 get_session_info_system(),
9405 (uint8_t *) oid_string
,
9406 strlen(oid_string
) + 1);
9409 result
= winreg_printer_update_changeid(p
->mem_ctx
,
9410 get_session_info_system(),
9412 lp_const_servicename(snum
));
9417 talloc_free(pinfo2
);
9421 /****************************************************************
9422 _spoolss_DeletePrinterDataEx
9423 ****************************************************************/
9425 WERROR
_spoolss_DeletePrinterDataEx(struct pipes_struct
*p
,
9426 struct spoolss_DeletePrinterDataEx
*r
)
9428 const char *printer
;
9430 WERROR status
= WERR_OK
;
9431 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9433 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9436 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9437 "Invalid handle (%s:%u:%u).\n",
9438 OUR_HANDLE(r
->in
.handle
)));
9442 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9443 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9444 "printer properties change denied by handle\n"));
9445 return WERR_ACCESS_DENIED
;
9448 if (!r
->in
.value_name
|| !r
->in
.key_name
) {
9452 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9455 printer
= lp_const_servicename(snum
);
9457 status
= winreg_delete_printer_dataex(p
->mem_ctx
,
9458 get_session_info_system(),
9463 if (W_ERROR_IS_OK(status
)) {
9464 status
= winreg_printer_update_changeid(p
->mem_ctx
,
9465 get_session_info_system(),
9473 /****************************************************************
9474 _spoolss_EnumPrinterKey
9475 ****************************************************************/
9477 WERROR
_spoolss_EnumPrinterKey(struct pipes_struct
*p
,
9478 struct spoolss_EnumPrinterKey
*r
)
9481 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9483 WERROR result
= WERR_BADFILE
;
9484 const char **array
= NULL
;
9487 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9490 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9491 OUR_HANDLE(r
->in
.handle
)));
9495 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9499 result
= winreg_enum_printer_key(p
->mem_ctx
,
9500 get_session_info_system(),
9502 lp_const_servicename(snum
),
9506 if (!W_ERROR_IS_OK(result
)) {
9510 if (!push_reg_multi_sz(p
->mem_ctx
, &blob
, array
)) {
9511 result
= WERR_NOMEM
;
9515 *r
->out
._ndr_size
= r
->in
.offered
/ 2;
9516 *r
->out
.needed
= blob
.length
;
9518 if (r
->in
.offered
< *r
->out
.needed
) {
9519 result
= WERR_MORE_DATA
;
9522 r
->out
.key_buffer
->string_array
= array
;
9526 if (!W_ERROR_IS_OK(result
)) {
9528 if (!W_ERROR_EQUAL(result
, WERR_MORE_DATA
)) {
9536 /****************************************************************
9537 _spoolss_DeletePrinterKey
9538 ****************************************************************/
9540 WERROR
_spoolss_DeletePrinterKey(struct pipes_struct
*p
,
9541 struct spoolss_DeletePrinterKey
*r
)
9543 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9546 const char *printer
;
9548 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9551 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9552 OUR_HANDLE(r
->in
.handle
)));
9556 /* if keyname == NULL, return error */
9557 if ( !r
->in
.key_name
)
9558 return WERR_INVALID_PARAM
;
9560 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9564 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9565 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9566 "printer properties change denied by handle\n"));
9567 return WERR_ACCESS_DENIED
;
9570 printer
= lp_const_servicename(snum
);
9572 /* delete the key and all subkeys */
9573 status
= winreg_delete_printer_key(p
->mem_ctx
,
9574 get_session_info_system(),
9578 if (W_ERROR_IS_OK(status
)) {
9579 status
= winreg_printer_update_changeid(p
->mem_ctx
,
9580 get_session_info_system(),
9588 /****************************************************************
9589 _spoolss_EnumPrinterDataEx
9590 ****************************************************************/
9592 WERROR
_spoolss_EnumPrinterDataEx(struct pipes_struct
*p
,
9593 struct spoolss_EnumPrinterDataEx
*r
)
9596 struct spoolss_PrinterEnumValues
*info
= NULL
;
9597 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9601 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9605 *r
->out
.info
= NULL
;
9608 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9609 OUR_HANDLE(r
->in
.handle
)));
9614 * first check for a keyname of NULL or "". Win2k seems to send
9615 * this a lot and we should send back WERR_INVALID_PARAM
9616 * no need to spend time looking up the printer in this case.
9620 if (!strlen(r
->in
.key_name
)) {
9621 result
= WERR_INVALID_PARAM
;
9625 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9629 /* now look for a match on the key name */
9630 result
= winreg_enum_printer_dataex(p
->mem_ctx
,
9631 get_session_info_system(),
9633 lp_const_servicename(snum
),
9637 if (!W_ERROR_IS_OK(result
)) {
9641 #if 0 /* FIXME - gd */
9642 /* housekeeping information in the reply */
9644 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9645 * the hand marshalled container size is a multiple
9646 * of 4 bytes for RPC alignment.
9650 needed
+= 4-(needed
% 4);
9653 *r
->out
.count
= count
;
9654 *r
->out
.info
= info
;
9657 if (!W_ERROR_IS_OK(result
)) {
9661 *r
->out
.needed
= SPOOLSS_BUFFER_ARRAY(p
->mem_ctx
,
9662 spoolss_EnumPrinterDataEx
,
9665 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9666 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, *r
->out
.count
);
9668 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
9671 /****************************************************************************
9672 ****************************************************************************/
9674 static WERROR
getprintprocessordirectory_level_1(TALLOC_CTX
*mem_ctx
,
9675 const char *servername
,
9676 const char *environment
,
9677 struct spoolss_PrintProcessorDirectoryInfo1
*r
)
9682 werr
= compose_spoolss_server_path(mem_ctx
,
9685 SPOOLSS_PRTPROCS_PATH
,
9687 if (!W_ERROR_IS_OK(werr
)) {
9691 DEBUG(4,("print processor directory: [%s]\n", path
));
9693 r
->directory_name
= path
;
9698 /****************************************************************
9699 _spoolss_GetPrintProcessorDirectory
9700 ****************************************************************/
9702 WERROR
_spoolss_GetPrintProcessorDirectory(struct pipes_struct
*p
,
9703 struct spoolss_GetPrintProcessorDirectory
*r
)
9706 char *prnproc_share
= NULL
;
9707 bool prnproc_share_exists
= false;
9710 /* that's an [in out] buffer */
9712 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9713 return WERR_INVALID_PARAM
;
9716 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9721 /* r->in.level is ignored */
9723 /* We always should reply with a local print processor directory so that
9724 * users are not forced to have a [prnproc$] share on the Samba spoolss
9725 * server, if users decide to do so, lets announce it though - Guenther */
9727 snum
= find_service(talloc_tos(), "prnproc$", &prnproc_share
);
9728 if (!prnproc_share
) {
9732 prnproc_share_exists
= true;
9735 result
= getprintprocessordirectory_level_1(p
->mem_ctx
,
9736 prnproc_share_exists
? r
->in
.server
: NULL
,
9738 &r
->out
.info
->info1
);
9739 if (!W_ERROR_IS_OK(result
)) {
9740 TALLOC_FREE(r
->out
.info
);
9744 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo
,
9745 r
->out
.info
, r
->in
.level
);
9746 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
9748 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9751 /*******************************************************************
9752 ********************************************************************/
9754 static bool push_monitorui_buf(TALLOC_CTX
*mem_ctx
, DATA_BLOB
*buf
,
9755 const char *dllname
)
9757 enum ndr_err_code ndr_err
;
9758 struct spoolss_MonitorUi ui
;
9760 ui
.dll_name
= dllname
;
9762 ndr_err
= ndr_push_struct_blob(buf
, mem_ctx
, &ui
,
9763 (ndr_push_flags_fn_t
)ndr_push_spoolss_MonitorUi
);
9764 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
9765 NDR_PRINT_DEBUG(spoolss_MonitorUi
, &ui
);
9767 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
9770 /*******************************************************************
9771 Streams the monitor UI DLL name in UNICODE
9772 *******************************************************************/
9774 static WERROR
xcvtcp_monitorui(TALLOC_CTX
*mem_ctx
,
9775 struct security_token
*token
, DATA_BLOB
*in
,
9776 DATA_BLOB
*out
, uint32_t *needed
)
9778 const char *dllname
= "tcpmonui.dll";
9780 *needed
= (strlen(dllname
)+1) * 2;
9782 if (out
->length
< *needed
) {
9783 return WERR_INSUFFICIENT_BUFFER
;
9786 if (!push_monitorui_buf(mem_ctx
, out
, dllname
)) {
9793 /*******************************************************************
9794 ********************************************************************/
9796 static bool pull_port_data_1(TALLOC_CTX
*mem_ctx
,
9797 struct spoolss_PortData1
*port1
,
9798 const DATA_BLOB
*buf
)
9800 enum ndr_err_code ndr_err
;
9801 ndr_err
= ndr_pull_struct_blob(buf
, mem_ctx
, port1
,
9802 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_PortData1
);
9803 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
9804 NDR_PRINT_DEBUG(spoolss_PortData1
, port1
);
9806 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
9809 /*******************************************************************
9810 ********************************************************************/
9812 static bool pull_port_data_2(TALLOC_CTX
*mem_ctx
,
9813 struct spoolss_PortData2
*port2
,
9814 const DATA_BLOB
*buf
)
9816 enum ndr_err_code ndr_err
;
9817 ndr_err
= ndr_pull_struct_blob(buf
, mem_ctx
, port2
,
9818 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_PortData2
);
9819 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
9820 NDR_PRINT_DEBUG(spoolss_PortData2
, port2
);
9822 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
9825 /*******************************************************************
9826 Create a new TCP/IP port
9827 *******************************************************************/
9829 static WERROR
xcvtcp_addport(TALLOC_CTX
*mem_ctx
,
9830 struct security_token
*token
, DATA_BLOB
*in
,
9831 DATA_BLOB
*out
, uint32_t *needed
)
9833 struct spoolss_PortData1 port1
;
9834 struct spoolss_PortData2 port2
;
9835 char *device_uri
= NULL
;
9838 const char *portname
;
9839 const char *hostaddress
;
9841 uint32_t port_number
;
9844 /* peek for spoolss_PortData version */
9846 if (!in
|| (in
->length
< (128 + 4))) {
9847 return WERR_GENERAL_FAILURE
;
9850 version
= IVAL(in
->data
, 128);
9856 if (!pull_port_data_1(mem_ctx
, &port1
, in
)) {
9860 portname
= port1
.portname
;
9861 hostaddress
= port1
.hostaddress
;
9862 queue
= port1
.queue
;
9863 protocol
= port1
.protocol
;
9864 port_number
= port1
.port_number
;
9870 if (!pull_port_data_2(mem_ctx
, &port2
, in
)) {
9874 portname
= port2
.portname
;
9875 hostaddress
= port2
.hostaddress
;
9876 queue
= port2
.queue
;
9877 protocol
= port2
.protocol
;
9878 port_number
= port2
.port_number
;
9882 DEBUG(1,("xcvtcp_addport: "
9883 "unknown version of port_data: %d\n", version
));
9884 return WERR_UNKNOWN_PORT
;
9887 /* create the device URI and call the add_port_hook() */
9890 case PROTOCOL_RAWTCP_TYPE
:
9891 device_uri
= talloc_asprintf(mem_ctx
,
9892 "socket://%s:%d/", hostaddress
,
9896 case PROTOCOL_LPR_TYPE
:
9897 device_uri
= talloc_asprintf(mem_ctx
,
9898 "lpr://%s/%s", hostaddress
, queue
);
9902 return WERR_UNKNOWN_PORT
;
9909 return add_port_hook(mem_ctx
, token
, portname
, device_uri
);
9912 /*******************************************************************
9913 *******************************************************************/
9915 struct xcv_api_table xcvtcp_cmds
[] = {
9916 { "MonitorUI", xcvtcp_monitorui
},
9917 { "AddPort", xcvtcp_addport
},
9921 static WERROR
process_xcvtcp_command(TALLOC_CTX
*mem_ctx
,
9922 struct security_token
*token
, const char *command
,
9929 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command
));
9931 for ( i
=0; xcvtcp_cmds
[i
].name
; i
++ ) {
9932 if ( strcmp( command
, xcvtcp_cmds
[i
].name
) == 0 )
9933 return xcvtcp_cmds
[i
].fn(mem_ctx
, token
, inbuf
, outbuf
, needed
);
9936 return WERR_BADFUNC
;
9939 /*******************************************************************
9940 *******************************************************************/
9941 #if 0 /* don't support management using the "Local Port" monitor */
9943 static WERROR
xcvlocal_monitorui(TALLOC_CTX
*mem_ctx
,
9944 struct security_token
*token
, DATA_BLOB
*in
,
9945 DATA_BLOB
*out
, uint32_t *needed
)
9947 const char *dllname
= "localui.dll";
9949 *needed
= (strlen(dllname
)+1) * 2;
9951 if (out
->length
< *needed
) {
9952 return WERR_INSUFFICIENT_BUFFER
;
9955 if (!push_monitorui_buf(mem_ctx
, out
, dllname
)) {
9962 /*******************************************************************
9963 *******************************************************************/
9965 struct xcv_api_table xcvlocal_cmds
[] = {
9966 { "MonitorUI", xcvlocal_monitorui
},
9970 struct xcv_api_table xcvlocal_cmds
[] = {
9977 /*******************************************************************
9978 *******************************************************************/
9980 static WERROR
process_xcvlocal_command(TALLOC_CTX
*mem_ctx
,
9981 struct security_token
*token
, const char *command
,
9982 DATA_BLOB
*inbuf
, DATA_BLOB
*outbuf
,
9987 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command
));
9989 for ( i
=0; xcvlocal_cmds
[i
].name
; i
++ ) {
9990 if ( strcmp( command
, xcvlocal_cmds
[i
].name
) == 0 )
9991 return xcvlocal_cmds
[i
].fn(mem_ctx
, token
, inbuf
, outbuf
, needed
);
9993 return WERR_BADFUNC
;
9996 /****************************************************************
9998 ****************************************************************/
10000 WERROR
_spoolss_XcvData(struct pipes_struct
*p
,
10001 struct spoolss_XcvData
*r
)
10003 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
10004 DATA_BLOB out_data
= data_blob_null
;
10008 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
10009 OUR_HANDLE(r
->in
.handle
)));
10010 return WERR_BADFID
;
10013 /* Has to be a handle to the TCP/IP port monitor */
10015 if ( !(Printer
->printer_type
& (SPLHND_PORTMON_LOCAL
|SPLHND_PORTMON_TCP
)) ) {
10016 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
10017 return WERR_BADFID
;
10020 /* requires administrative access to the server */
10022 if ( !(Printer
->access_granted
& SERVER_ACCESS_ADMINISTER
) ) {
10023 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
10024 return WERR_ACCESS_DENIED
;
10027 /* Allocate the outgoing buffer */
10029 if (r
->in
.out_data_size
) {
10030 out_data
= data_blob_talloc_zero(p
->mem_ctx
, r
->in
.out_data_size
);
10031 if (out_data
.data
== NULL
) {
10036 switch ( Printer
->printer_type
) {
10037 case SPLHND_PORTMON_TCP
:
10038 werror
= process_xcvtcp_command(p
->mem_ctx
,
10039 p
->session_info
->security_token
,
10040 r
->in
.function_name
,
10041 &r
->in
.in_data
, &out_data
,
10044 case SPLHND_PORTMON_LOCAL
:
10045 werror
= process_xcvlocal_command(p
->mem_ctx
,
10046 p
->session_info
->security_token
,
10047 r
->in
.function_name
,
10048 &r
->in
.in_data
, &out_data
,
10052 werror
= WERR_INVALID_PRINT_MONITOR
;
10055 if (!W_ERROR_IS_OK(werror
)) {
10059 *r
->out
.status_code
= 0;
10061 if (r
->out
.out_data
&& out_data
.data
&& r
->in
.out_data_size
&& out_data
.length
) {
10062 memcpy(r
->out
.out_data
, out_data
.data
,
10063 MIN(r
->in
.out_data_size
, out_data
.length
));
10069 /****************************************************************
10070 _spoolss_AddPrintProcessor
10071 ****************************************************************/
10073 WERROR
_spoolss_AddPrintProcessor(struct pipes_struct
*p
,
10074 struct spoolss_AddPrintProcessor
*r
)
10076 /* for now, just indicate success and ignore the add. We'll
10077 automatically set the winprint processor for printer
10078 entries later. Used to debug the LexMark Optra S 1855 PCL
10084 /****************************************************************
10086 ****************************************************************/
10088 WERROR
_spoolss_AddPort(struct pipes_struct
*p
,
10089 struct spoolss_AddPort
*r
)
10091 /* do what w2k3 does */
10093 return WERR_NOT_SUPPORTED
;
10096 /****************************************************************
10097 _spoolss_GetPrinterDriver
10098 ****************************************************************/
10100 WERROR
_spoolss_GetPrinterDriver(struct pipes_struct
*p
,
10101 struct spoolss_GetPrinterDriver
*r
)
10103 p
->rng_fault_state
= true;
10104 return WERR_NOT_SUPPORTED
;
10107 /****************************************************************
10108 _spoolss_ReadPrinter
10109 ****************************************************************/
10111 WERROR
_spoolss_ReadPrinter(struct pipes_struct
*p
,
10112 struct spoolss_ReadPrinter
*r
)
10114 p
->rng_fault_state
= true;
10115 return WERR_NOT_SUPPORTED
;
10118 /****************************************************************
10119 _spoolss_WaitForPrinterChange
10120 ****************************************************************/
10122 WERROR
_spoolss_WaitForPrinterChange(struct pipes_struct
*p
,
10123 struct spoolss_WaitForPrinterChange
*r
)
10125 p
->rng_fault_state
= true;
10126 return WERR_NOT_SUPPORTED
;
10129 /****************************************************************
10130 _spoolss_ConfigurePort
10131 ****************************************************************/
10133 WERROR
_spoolss_ConfigurePort(struct pipes_struct
*p
,
10134 struct spoolss_ConfigurePort
*r
)
10136 p
->rng_fault_state
= true;
10137 return WERR_NOT_SUPPORTED
;
10140 /****************************************************************
10141 _spoolss_DeletePort
10142 ****************************************************************/
10144 WERROR
_spoolss_DeletePort(struct pipes_struct
*p
,
10145 struct spoolss_DeletePort
*r
)
10147 p
->rng_fault_state
= true;
10148 return WERR_NOT_SUPPORTED
;
10151 /****************************************************************
10152 _spoolss_CreatePrinterIC
10153 ****************************************************************/
10155 WERROR
_spoolss_CreatePrinterIC(struct pipes_struct
*p
,
10156 struct spoolss_CreatePrinterIC
*r
)
10158 p
->rng_fault_state
= true;
10159 return WERR_NOT_SUPPORTED
;
10162 /****************************************************************
10163 _spoolss_PlayGDIScriptOnPrinterIC
10164 ****************************************************************/
10166 WERROR
_spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct
*p
,
10167 struct spoolss_PlayGDIScriptOnPrinterIC
*r
)
10169 p
->rng_fault_state
= true;
10170 return WERR_NOT_SUPPORTED
;
10173 /****************************************************************
10174 _spoolss_DeletePrinterIC
10175 ****************************************************************/
10177 WERROR
_spoolss_DeletePrinterIC(struct pipes_struct
*p
,
10178 struct spoolss_DeletePrinterIC
*r
)
10180 p
->rng_fault_state
= true;
10181 return WERR_NOT_SUPPORTED
;
10184 /****************************************************************
10185 _spoolss_AddPrinterConnection
10186 ****************************************************************/
10188 WERROR
_spoolss_AddPrinterConnection(struct pipes_struct
*p
,
10189 struct spoolss_AddPrinterConnection
*r
)
10191 p
->rng_fault_state
= true;
10192 return WERR_NOT_SUPPORTED
;
10195 /****************************************************************
10196 _spoolss_DeletePrinterConnection
10197 ****************************************************************/
10199 WERROR
_spoolss_DeletePrinterConnection(struct pipes_struct
*p
,
10200 struct spoolss_DeletePrinterConnection
*r
)
10202 p
->rng_fault_state
= true;
10203 return WERR_NOT_SUPPORTED
;
10206 /****************************************************************
10207 _spoolss_PrinterMessageBox
10208 ****************************************************************/
10210 WERROR
_spoolss_PrinterMessageBox(struct pipes_struct
*p
,
10211 struct spoolss_PrinterMessageBox
*r
)
10213 p
->rng_fault_state
= true;
10214 return WERR_NOT_SUPPORTED
;
10217 /****************************************************************
10218 _spoolss_AddMonitor
10219 ****************************************************************/
10221 WERROR
_spoolss_AddMonitor(struct pipes_struct
*p
,
10222 struct spoolss_AddMonitor
*r
)
10224 p
->rng_fault_state
= true;
10225 return WERR_NOT_SUPPORTED
;
10228 /****************************************************************
10229 _spoolss_DeleteMonitor
10230 ****************************************************************/
10232 WERROR
_spoolss_DeleteMonitor(struct pipes_struct
*p
,
10233 struct spoolss_DeleteMonitor
*r
)
10235 p
->rng_fault_state
= true;
10236 return WERR_NOT_SUPPORTED
;
10239 /****************************************************************
10240 _spoolss_DeletePrintProcessor
10241 ****************************************************************/
10243 WERROR
_spoolss_DeletePrintProcessor(struct pipes_struct
*p
,
10244 struct spoolss_DeletePrintProcessor
*r
)
10246 p
->rng_fault_state
= true;
10247 return WERR_NOT_SUPPORTED
;
10250 /****************************************************************
10251 _spoolss_AddPrintProvidor
10252 ****************************************************************/
10254 WERROR
_spoolss_AddPrintProvidor(struct pipes_struct
*p
,
10255 struct spoolss_AddPrintProvidor
*r
)
10257 p
->rng_fault_state
= true;
10258 return WERR_NOT_SUPPORTED
;
10261 /****************************************************************
10262 _spoolss_DeletePrintProvidor
10263 ****************************************************************/
10265 WERROR
_spoolss_DeletePrintProvidor(struct pipes_struct
*p
,
10266 struct spoolss_DeletePrintProvidor
*r
)
10268 p
->rng_fault_state
= true;
10269 return WERR_NOT_SUPPORTED
;
10272 /****************************************************************
10273 _spoolss_FindFirstPrinterChangeNotification
10274 ****************************************************************/
10276 WERROR
_spoolss_FindFirstPrinterChangeNotification(struct pipes_struct
*p
,
10277 struct spoolss_FindFirstPrinterChangeNotification
*r
)
10279 p
->rng_fault_state
= true;
10280 return WERR_NOT_SUPPORTED
;
10283 /****************************************************************
10284 _spoolss_FindNextPrinterChangeNotification
10285 ****************************************************************/
10287 WERROR
_spoolss_FindNextPrinterChangeNotification(struct pipes_struct
*p
,
10288 struct spoolss_FindNextPrinterChangeNotification
*r
)
10290 p
->rng_fault_state
= true;
10291 return WERR_NOT_SUPPORTED
;
10294 /****************************************************************
10295 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10296 ****************************************************************/
10298 WERROR
_spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct
*p
,
10299 struct spoolss_RouterFindFirstPrinterChangeNotificationOld
*r
)
10301 p
->rng_fault_state
= true;
10302 return WERR_NOT_SUPPORTED
;
10305 /****************************************************************
10306 _spoolss_ReplyOpenPrinter
10307 ****************************************************************/
10309 WERROR
_spoolss_ReplyOpenPrinter(struct pipes_struct
*p
,
10310 struct spoolss_ReplyOpenPrinter
*r
)
10312 p
->rng_fault_state
= true;
10313 return WERR_NOT_SUPPORTED
;
10316 /****************************************************************
10317 _spoolss_RouterReplyPrinter
10318 ****************************************************************/
10320 WERROR
_spoolss_RouterReplyPrinter(struct pipes_struct
*p
,
10321 struct spoolss_RouterReplyPrinter
*r
)
10323 p
->rng_fault_state
= true;
10324 return WERR_NOT_SUPPORTED
;
10327 /****************************************************************
10328 _spoolss_ReplyClosePrinter
10329 ****************************************************************/
10331 WERROR
_spoolss_ReplyClosePrinter(struct pipes_struct
*p
,
10332 struct spoolss_ReplyClosePrinter
*r
)
10334 p
->rng_fault_state
= true;
10335 return WERR_NOT_SUPPORTED
;
10338 /****************************************************************
10340 ****************************************************************/
10342 WERROR
_spoolss_AddPortEx(struct pipes_struct
*p
,
10343 struct spoolss_AddPortEx
*r
)
10345 p
->rng_fault_state
= true;
10346 return WERR_NOT_SUPPORTED
;
10349 /****************************************************************
10350 _spoolss_RouterFindFirstPrinterChangeNotification
10351 ****************************************************************/
10353 WERROR
_spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct
*p
,
10354 struct spoolss_RouterFindFirstPrinterChangeNotification
*r
)
10356 p
->rng_fault_state
= true;
10357 return WERR_NOT_SUPPORTED
;
10360 /****************************************************************
10361 _spoolss_SpoolerInit
10362 ****************************************************************/
10364 WERROR
_spoolss_SpoolerInit(struct pipes_struct
*p
,
10365 struct spoolss_SpoolerInit
*r
)
10367 p
->rng_fault_state
= true;
10368 return WERR_NOT_SUPPORTED
;
10371 /****************************************************************
10372 _spoolss_ResetPrinterEx
10373 ****************************************************************/
10375 WERROR
_spoolss_ResetPrinterEx(struct pipes_struct
*p
,
10376 struct spoolss_ResetPrinterEx
*r
)
10378 p
->rng_fault_state
= true;
10379 return WERR_NOT_SUPPORTED
;
10382 /****************************************************************
10383 _spoolss_RouterReplyPrinterEx
10384 ****************************************************************/
10386 WERROR
_spoolss_RouterReplyPrinterEx(struct pipes_struct
*p
,
10387 struct spoolss_RouterReplyPrinterEx
*r
)
10389 p
->rng_fault_state
= true;
10390 return WERR_NOT_SUPPORTED
;
10393 /****************************************************************
10395 ****************************************************************/
10397 WERROR
_spoolss_44(struct pipes_struct
*p
,
10398 struct spoolss_44
*r
)
10400 p
->rng_fault_state
= true;
10401 return WERR_NOT_SUPPORTED
;
10404 /****************************************************************
10406 ****************************************************************/
10408 WERROR
_spoolss_SetPort(struct pipes_struct
*p
,
10409 struct spoolss_SetPort
*r
)
10411 p
->rng_fault_state
= true;
10412 return WERR_NOT_SUPPORTED
;
10415 /****************************************************************
10417 ****************************************************************/
10419 WERROR
_spoolss_4a(struct pipes_struct
*p
,
10420 struct spoolss_4a
*r
)
10422 p
->rng_fault_state
= true;
10423 return WERR_NOT_SUPPORTED
;
10426 /****************************************************************
10428 ****************************************************************/
10430 WERROR
_spoolss_4b(struct pipes_struct
*p
,
10431 struct spoolss_4b
*r
)
10433 p
->rng_fault_state
= true;
10434 return WERR_NOT_SUPPORTED
;
10437 /****************************************************************
10439 ****************************************************************/
10441 WERROR
_spoolss_4c(struct pipes_struct
*p
,
10442 struct spoolss_4c
*r
)
10444 p
->rng_fault_state
= true;
10445 return WERR_NOT_SUPPORTED
;
10448 /****************************************************************
10450 ****************************************************************/
10452 WERROR
_spoolss_53(struct pipes_struct
*p
,
10453 struct spoolss_53
*r
)
10455 p
->rng_fault_state
= true;
10456 return WERR_NOT_SUPPORTED
;
10459 /****************************************************************
10460 _spoolss_AddPerMachineConnection
10461 ****************************************************************/
10463 WERROR
_spoolss_AddPerMachineConnection(struct pipes_struct
*p
,
10464 struct spoolss_AddPerMachineConnection
*r
)
10466 p
->rng_fault_state
= true;
10467 return WERR_NOT_SUPPORTED
;
10470 /****************************************************************
10471 _spoolss_DeletePerMachineConnection
10472 ****************************************************************/
10474 WERROR
_spoolss_DeletePerMachineConnection(struct pipes_struct
*p
,
10475 struct spoolss_DeletePerMachineConnection
*r
)
10477 p
->rng_fault_state
= true;
10478 return WERR_NOT_SUPPORTED
;
10481 /****************************************************************
10482 _spoolss_EnumPerMachineConnections
10483 ****************************************************************/
10485 WERROR
_spoolss_EnumPerMachineConnections(struct pipes_struct
*p
,
10486 struct spoolss_EnumPerMachineConnections
*r
)
10488 p
->rng_fault_state
= true;
10489 return WERR_NOT_SUPPORTED
;
10492 /****************************************************************
10494 ****************************************************************/
10496 WERROR
_spoolss_5a(struct pipes_struct
*p
,
10497 struct spoolss_5a
*r
)
10499 p
->rng_fault_state
= true;
10500 return WERR_NOT_SUPPORTED
;
10503 /****************************************************************
10505 ****************************************************************/
10507 WERROR
_spoolss_5b(struct pipes_struct
*p
,
10508 struct spoolss_5b
*r
)
10510 p
->rng_fault_state
= true;
10511 return WERR_NOT_SUPPORTED
;
10514 /****************************************************************
10516 ****************************************************************/
10518 WERROR
_spoolss_5c(struct pipes_struct
*p
,
10519 struct spoolss_5c
*r
)
10521 p
->rng_fault_state
= true;
10522 return WERR_NOT_SUPPORTED
;
10525 /****************************************************************
10527 ****************************************************************/
10529 WERROR
_spoolss_5d(struct pipes_struct
*p
,
10530 struct spoolss_5d
*r
)
10532 p
->rng_fault_state
= true;
10533 return WERR_NOT_SUPPORTED
;
10536 /****************************************************************
10538 ****************************************************************/
10540 WERROR
_spoolss_5e(struct pipes_struct
*p
,
10541 struct spoolss_5e
*r
)
10543 p
->rng_fault_state
= true;
10544 return WERR_NOT_SUPPORTED
;
10547 /****************************************************************
10549 ****************************************************************/
10551 WERROR
_spoolss_5f(struct pipes_struct
*p
,
10552 struct spoolss_5f
*r
)
10554 p
->rng_fault_state
= true;
10555 return WERR_NOT_SUPPORTED
;
10558 /****************************************************************
10560 ****************************************************************/
10562 WERROR
_spoolss_60(struct pipes_struct
*p
,
10563 struct spoolss_60
*r
)
10565 p
->rng_fault_state
= true;
10566 return WERR_NOT_SUPPORTED
;
10569 /****************************************************************
10571 ****************************************************************/
10573 WERROR
_spoolss_61(struct pipes_struct
*p
,
10574 struct spoolss_61
*r
)
10576 p
->rng_fault_state
= true;
10577 return WERR_NOT_SUPPORTED
;
10580 /****************************************************************
10582 ****************************************************************/
10584 WERROR
_spoolss_62(struct pipes_struct
*p
,
10585 struct spoolss_62
*r
)
10587 p
->rng_fault_state
= true;
10588 return WERR_NOT_SUPPORTED
;
10591 /****************************************************************
10593 ****************************************************************/
10595 WERROR
_spoolss_63(struct pipes_struct
*p
,
10596 struct spoolss_63
*r
)
10598 p
->rng_fault_state
= true;
10599 return WERR_NOT_SUPPORTED
;
10602 /****************************************************************
10604 ****************************************************************/
10606 WERROR
_spoolss_64(struct pipes_struct
*p
,
10607 struct spoolss_64
*r
)
10609 p
->rng_fault_state
= true;
10610 return WERR_NOT_SUPPORTED
;
10613 /****************************************************************
10615 ****************************************************************/
10617 WERROR
_spoolss_65(struct pipes_struct
*p
,
10618 struct spoolss_65
*r
)
10620 p
->rng_fault_state
= true;
10621 return WERR_NOT_SUPPORTED
;
10624 /****************************************************************
10625 _spoolss_GetCorePrinterDrivers
10626 ****************************************************************/
10628 WERROR
_spoolss_GetCorePrinterDrivers(struct pipes_struct
*p
,
10629 struct spoolss_GetCorePrinterDrivers
*r
)
10631 p
->rng_fault_state
= true;
10632 return WERR_NOT_SUPPORTED
;
10635 /****************************************************************
10637 ****************************************************************/
10639 WERROR
_spoolss_67(struct pipes_struct
*p
,
10640 struct spoolss_67
*r
)
10642 p
->rng_fault_state
= true;
10643 return WERR_NOT_SUPPORTED
;
10646 /****************************************************************
10647 _spoolss_GetPrinterDriverPackagePath
10648 ****************************************************************/
10650 WERROR
_spoolss_GetPrinterDriverPackagePath(struct pipes_struct
*p
,
10651 struct spoolss_GetPrinterDriverPackagePath
*r
)
10653 p
->rng_fault_state
= true;
10654 return WERR_NOT_SUPPORTED
;
10657 /****************************************************************
10659 ****************************************************************/
10661 WERROR
_spoolss_69(struct pipes_struct
*p
,
10662 struct spoolss_69
*r
)
10664 p
->rng_fault_state
= true;
10665 return WERR_NOT_SUPPORTED
;
10668 /****************************************************************
10670 ****************************************************************/
10672 WERROR
_spoolss_6a(struct pipes_struct
*p
,
10673 struct spoolss_6a
*r
)
10675 p
->rng_fault_state
= true;
10676 return WERR_NOT_SUPPORTED
;
10679 /****************************************************************
10681 ****************************************************************/
10683 WERROR
_spoolss_6b(struct pipes_struct
*p
,
10684 struct spoolss_6b
*r
)
10686 p
->rng_fault_state
= true;
10687 return WERR_NOT_SUPPORTED
;
10690 /****************************************************************
10692 ****************************************************************/
10694 WERROR
_spoolss_6c(struct pipes_struct
*p
,
10695 struct spoolss_6c
*r
)
10697 p
->rng_fault_state
= true;
10698 return WERR_NOT_SUPPORTED
;
10701 /****************************************************************
10703 ****************************************************************/
10705 WERROR
_spoolss_6d(struct pipes_struct
*p
,
10706 struct spoolss_6d
*r
)
10708 p
->rng_fault_state
= true;
10709 return WERR_NOT_SUPPORTED
;